diff mbox series

[09/10] Added code to check if the proc/net/if_inet6 file exists while loading IPv6 addresses in the IPv6Addresses class

Message ID 20230601192928.809434-9-ashelat@redhat.com
State New
Headers show
Series [01/10] rteval: Use f-strings in rtevalclient.py | expand

Commit Message

Anubhav Shelat June 1, 2023, 7:29 p.m. UTC
Signed-off-by: Anubhav Shelat <ashelat@redhat.com>
---
 rteval/sysinfo/newnet.py | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)
diff mbox series

Patch

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 '''