Browse Source

[2172] use netstat instead of route on openBSD

Jelte Jansen 12 years ago
parent
commit
db05d3bab1

+ 6 - 12
src/lib/python/isc/sysinfo/sysinfo.py

@@ -303,6 +303,12 @@ class SysInfoBSD(SysInfoPOSIX):
         except (subprocess.CalledProcessError, OSError):
             self._net_connections = 'Warning: "netstat -an" command failed.\n'
 
+        try:
+            s = subprocess.check_output(['netstat', '-nr'])
+            self._net_routing_table = s.decode('utf-8')
+        except (subprocess.CalledProcessError, OSError):
+            self._net_connections = 'Warning: "netstat -nr" command failed.\n'
+
 class SysInfoOpenBSD(SysInfoBSD):
     """OpenBSD implementation of the SysInfo class.
     See the SysInfo class documentation for more information.
@@ -345,12 +351,6 @@ class SysInfoOpenBSD(SysInfoBSD):
         except (subprocess.CalledProcessError, OSError):
             pass
 
-        try:
-            s = subprocess.check_output(['route', '-n', 'show'])
-            self._net_routing_table = s.decode('utf-8')
-        except (subprocess.CalledProcessError, OSError):
-            self._net_routing_table = 'Warning: "route -n show" command failed.\n'
-
 class SysInfoFreeBSDOSX(SysInfoBSD):
     """Shared code for the FreeBSD and OS X implementations of the SysInfo
     class. See the SysInfo class documentation for more information.
@@ -381,12 +381,6 @@ class SysInfoFreeBSDOSX(SysInfoBSD):
         except (subprocess.CalledProcessError, OSError):
             pass
 
-        try:
-            s = subprocess.check_output(['netstat', '-nr'])
-            self._net_routing_table = s.decode('utf-8')
-        except (subprocess.CalledProcessError, OSError):
-            self._net_connections = 'Warning: "netstat -nr" command failed.\n'
-
 class SysInfoFreeBSD(SysInfoFreeBSDOSX):
     """FreeBSD implementation of the SysInfo class.
     See the SysInfo class documentation for more information.

+ 2 - 4
src/lib/python/isc/sysinfo/tests/sysinfo_test.py

@@ -138,6 +138,8 @@ def _my_bsd_subprocess_check_output(command):
         return b'osuxbrcc1g9VgaF4yf3FrtfodrfATrbSnjhqhuQSAs8=\n'
     elif command == ['netstat', '-an']:
         return b'Z+w0lwa02/T+5+EIio84rrst/Dtizoz/aL9Im7J7ESA=\n'
+    elif command == ['netstat', '-nr']:
+        return b'XfizswwNA9NkXz6K36ZExpjV08Y5IXkHI8jjDSV+5Nc=\n'
     else:
         return None
 
@@ -151,8 +153,6 @@ def _my_openbsd_subprocess_check_output(command):
         return b' procs    memory       page                    disks    traps          cpu\n r b w    avm     fre  flt  re  pi  po  fr  sr wd0 cd0  int   sys   cs us sy id\n 0 0 0   121212  123456   47   0   0   0   0   0   2   0    2    80   14  0  1 99\n'
     elif command == ['swapctl', '-s', '-k']:
         return b'total: 553507 1K-blocks allocated, 2 used, 553505 available'
-    elif command == ['route', '-n', 'show']:
-        return b'XfizswwNA9NkXz6K36ZExpjV08Y5IXkHI8jjDSV+5Nc=\n'
     else:
         bsd_output = _my_bsd_subprocess_check_output(command)
         if bsd_output is not None:
@@ -178,8 +178,6 @@ def _my_freebsd_osx_subprocess_check_output(command):
         return bytes('{ sec = ' + str(int(time.time() - 76632)) + ', usec = 0 }\n', 'utf-8')
     elif command == ['sysctl', '-n', 'vm.loadavg']:
         return b'{ 0.2 0.4 0.6 }\n'
-    elif command == ['netstat', '-nr']:
-        return b'XfizswwNA9NkXz6K36ZExpjV08Y5IXkHI8jjDSV+5Nc=\n'
     else:
         return _my_bsd_subprocess_check_output(command)