rteval/SOURCES/Added-code-to-check-if-the-...

58 lines
2.3 KiB
Diff

From 0ba98b12775b5394aab2205df29d93439d625cc3 Mon Sep 17 00:00:00 2001
From: Anubhav Shelat <ashelat@redhat.com>
Date: Thu, 1 Jun 2023 16:27:35 -0400
Subject: [PATCH] Added code to check if the proc/net/if_inet6 file exists
while loading IPv6 addresses in the IPv6Addresses class
Added code to check if the proc/net/if_inet6 file exists while loading IPv6 addresses in the IPv6Addresses class. If it doesn't, then the system has IPv6 disabled, and that chunk of code is passed.
Signed-off-by: Anubhav Shelat <ashelat@redhat.com>
Signed-off-by: John Kacur <jkacur@redhat.com>
---
rteval/sysinfo/newnet.py | 28 ++++++++++++++++------------
1 file changed, 16 insertions(+), 12 deletions(-)
diff --git a/rteval/sysinfo/newnet.py b/rteval/sysinfo/newnet.py
index 63417d9e59f1..2911400ceb6c 100644
--- a/rteval/sysinfo/newnet.py
+++ b/rteval/sysinfo/newnet.py
@@ -72,19 +72,23 @@ class IPv6Addresses():
and a list of ipv6addresses
'''
MYP = '/proc/net/if_inet6'
- with open(MYP, 'r') as f:
- mystr = f.readline().strip()
- while len(mystr) > 0:
- ipv6addr , _, _, _, _, intf = mystr.split()
- ipv6addr = compress_iv6(ipv6addr)
- if intf == 'lo':
- mystr = f.readline().strip()
- continue
- if intf not in self.data:
- self.data[intf] = [ipv6addr]
- else:
- self.data[intf].append(ipv6addr)
+ try:
+ with open(MYP, 'r') as f:
mystr = f.readline().strip()
+ while len(mystr) > 0:
+ ipv6addr , _, _, _, _, intf = mystr.split()
+ ipv6addr = compress_iv6(ipv6addr)
+ if intf == 'lo':
+ mystr = f.readline().strip()
+ continue
+ if intf not in self.data:
+ self.data[intf] = [ipv6addr]
+ else:
+ self.data[intf].append(ipv6addr)
+ mystr = f.readline().strip()
+ # if IPv6 is disabled, the if_net6 files does not exist, so we can pass
+ except FileNotFoundError:
+ pass
class IPv4Addresses():
''' Obtains a list of IPv4 addresses from the proc file system '''
--
2.31.1