BIND 10 trac2172, updated. db05d3bab1a3ef3bdfe2cd10c453cc4b6ca7e421 [2172] use netstat instead of route on openBSD

BIND 10 source code commits bind10-changes at lists.isc.org
Mon Aug 13 12:27:52 UTC 2012


The branch, trac2172 has been updated
       via  db05d3bab1a3ef3bdfe2cd10c453cc4b6ca7e421 (commit)
       via  ffc684f617ecb3967bc544da507e718bb1709d65 (commit)
       via  be7f08f05aa29fda91f4b214d660d3bfea12ba45 (commit)
      from  97ad12066c71c308e0411b66a16e1ad272d5733f (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit db05d3bab1a3ef3bdfe2cd10c453cc4b6ca7e421
Author: Jelte Jansen <jelte at isc.org>
Date:   Mon Aug 13 14:27:37 2012 +0200

    [2172] use netstat instead of route on openBSD

commit ffc684f617ecb3967bc544da507e718bb1709d65
Author: Jelte Jansen <jelte at isc.org>
Date:   Mon Aug 13 14:26:40 2012 +0200

    [2172] only use 'distro' value on linux

commit be7f08f05aa29fda91f4b214d660d3bfea12ba45
Author: Jelte Jansen <jelte at isc.org>
Date:   Mon Aug 13 14:26:00 2012 +0200

    [2172] set mem_info to None in OSX before overwriting

-----------------------------------------------------------------------

Summary of changes:
 src/lib/python/isc/sysinfo/sysinfo.py            |   38 ++++++++++++----------
 src/lib/python/isc/sysinfo/tests/sysinfo_test.py |   30 +++--------------
 2 files changed, 25 insertions(+), 43 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/python/isc/sysinfo/sysinfo.py b/src/lib/python/isc/sysinfo/sysinfo.py
index c323814..97b9e59 100644
--- a/src/lib/python/isc/sysinfo/sysinfo.py
+++ b/src/lib/python/isc/sysinfo/sysinfo.py
@@ -36,16 +36,20 @@ class SysInfo:
         self._loadavg = None
         self._mem_total = None
         self._mem_free = None
-        self._mem_cached = None
-        self._mem_buffers = None
         self._mem_swap_total = None
         self._mem_swap_free = None
-        self._platform_distro = 'Unknown'
         self._net_interfaces = 'Unknown\n'
         self._net_routing_table = 'Unknown\n'
         self._net_stats = 'Unknown\n'
         self._net_connections = 'Unknown\n'
 
+        # The following are Linux speicific, and should eventually be removed
+        # from this level; for now we simply default to None (so they won't
+        # be printed)
+        self._platform_distro = None
+        self._mem_cached = None
+        self._mem_buffers = None
+
     def get_num_processors(self):
         """Returns the number of processors. This is the number of
         hyperthreads when hyper-threading is enabled.
@@ -77,7 +81,12 @@ class SysInfo:
         return self._platform_is_smp
 
     def get_platform_distro(self):
-        """Returns the name of the OS distribution in use."""
+        """Returns the name of the OS distribution in use.
+
+        Note: the concept of 'distribution' is Linux specific.  This shouldn't
+        be at this level.
+
+        """
         return self._platform_distro
 
     def get_uptime(self):
@@ -276,8 +285,6 @@ class SysInfoBSD(SysInfoPOSIX):
         except (subprocess.CalledProcessError, OSError):
             pass
 
-        self._platform_distro = self._platform_name + ' ' + self._platform_version
-
         try:
             s = subprocess.check_output(['ifconfig'])
             self._net_interfaces = s.decode('utf-8')
@@ -296,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.
@@ -338,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.
@@ -374,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.
@@ -425,6 +426,7 @@ class SysInfoOSX(SysInfoFreeBSDOSX):
         # was read. However, on OSX, physmem is not necessarily the correct
         # value. But since it does not fail and does work on most BSD's, it's
         # left in the base class and overwritten here
+        self._mem_total = None
         try:
             s = subprocess.check_output(['sysctl', '-n', 'hw.memsize'])
             self._mem_total = int(s.decode('utf-8').strip())
diff --git a/src/lib/python/isc/sysinfo/tests/sysinfo_test.py b/src/lib/python/isc/sysinfo/tests/sysinfo_test.py
index 01a78d4..0add036 100644
--- a/src/lib/python/isc/sysinfo/tests/sysinfo_test.py
+++ b/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)
 
@@ -261,7 +259,7 @@ class SysInfoTest(unittest.TestCase):
         self.assertEqual(None, s.get_mem_buffers())
         self.assertEqual(None, s.get_mem_swap_total())
         self.assertEqual(None, s.get_mem_swap_free())
-        self.assertEqual('Unknown', s.get_platform_distro())
+        self.assertEqual(None, s.get_platform_distro())
         self.assertEqual('Unknown\n', s.get_net_interfaces())
         self.assertEqual('Unknown\n', s.get_net_routing_table())
         self.assertEqual('Unknown\n', s.get_net_stats())
@@ -290,7 +288,7 @@ class SysInfoTest(unittest.TestCase):
         self.assertEqual(None, s.get_mem_buffers())
         self.assertEqual(None, s.get_mem_swap_total())
         self.assertEqual(None, s.get_mem_swap_free())
-        self.assertEqual('Unknown', s.get_platform_distro())
+        self.assertEqual(None, s.get_platform_distro())
         self.assertEqual('Unknown\n', s.get_net_interfaces())
         self.assertEqual('Unknown\n', s.get_net_routing_table())
         self.assertEqual('Unknown\n', s.get_net_stats())
@@ -338,6 +336,7 @@ class SysInfoTest(unittest.TestCase):
         self.assertLess(abs(76632 - s.get_uptime()), 4)
         self.assertEqual(None, s.get_mem_cached())
         self.assertEqual(None, s.get_mem_buffers())
+        self.assertEqual(None, s.get_platform_distro())
 
         # These test that the corresponding tools are being called (and
         # no further processing is done on this data). Please see the
@@ -371,13 +370,6 @@ class SysInfoTest(unittest.TestCase):
         self.assertEqual(566791168, s.get_mem_swap_total())
         self.assertEqual(566789120, s.get_mem_swap_free())
 
-        # Try new regex assertion (which replaced the deprecated
-        # assertRegexpMatches. If it is not available, use the old one
-        try:
-            self.assertRegex(s.get_platform_distro(), '^OpenBSD\s+.*')
-        except AttributeError:
-            self.assertRegexpMatches(s.get_platform_distro(), '^OpenBSD\s+.*')
-
     def test_sysinfo_freebsd(self):
         """Tests the FreeBSD implementation of SysInfo. Note that this
         tests deep into the implementation, and not just the
@@ -401,12 +393,6 @@ class SysInfoTest(unittest.TestCase):
         self.assertEqual(543214321 - (343434 * 1024), s.get_mem_free())
         self.assertEqual(1037533184, s.get_mem_swap_total())
         self.assertEqual(1037533184, s.get_mem_swap_free())
-        # Try new regex assertion (which replaced the deprecated
-        # assertRegexpMatches. If it is not available, use the old one
-        try:
-            self.assertRegex(s.get_platform_distro(), '^FreeBSD\s+.*')
-        except AttributeError:
-            self.assertRegexpMatches(s.get_platform_distro(), '^FreeBSD\s+.*')
 
     def test_sysinfo_osx(self):
         """Tests the OS X implementation of SysInfo. Note that this
@@ -431,12 +417,6 @@ class SysInfoTest(unittest.TestCase):
         self.assertEqual((23456 * 4096), s.get_mem_free())
         self.assertEqual(18874368.0, s.get_mem_swap_total())
         self.assertEqual(1075988.48, s.get_mem_swap_free())
-        # Try new regex assertion (which replaced the deprecated
-        # assertRegexpMatches. If it is not available, use the old one
-        try:
-            self.assertRegex(s.get_platform_distro(), '^Darwin\s+.*')
-        except AttributeError:
-            self.assertRegexpMatches(s.get_platform_distro(), '^Darwin\s+.*')
 
 if __name__ == "__main__":
     unittest.main()



More information about the bind10-changes mailing list