]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Treat case when pid is None
authorGary Kotton <gkotton@redhat.com>
Wed, 7 Nov 2012 05:46:08 +0000 (05:46 +0000)
committerGary Kotton <gkotton@redhat.com>
Wed, 7 Nov 2012 06:08:13 +0000 (06:08 +0000)
Fixes bug 1077651

Change-Id: Id80d923d36a0339eee860e8cf37aacc6866fc6bc

quantum/agent/linux/dhcp.py
quantum/tests/unit/test_linux_dhcp.py

index 304e2ce4594df2306879b7ddfc2e21c4554cdc9b..e1586befddce7988e37f61b8d306dabc0a5ae834 100644 (file)
@@ -167,6 +167,9 @@ class DhcpLocalProcess(DhcpBase):
     @property
     def active(self):
         pid = self.pid
+        if pid is None:
+            return False
+
         cmd = ['cat', '/proc/%s/cmdline' % pid]
         try:
             return self.network.id in utils.execute(cmd, self.root_helper)
index 1042e96435b0284978b3ae27378b1a2b19d78d33..12065b2bbbf5424ab9e5e4edb862a3c9005b176d 100644 (file)
@@ -230,6 +230,14 @@ class TestDhcpLocalProcess(TestBase):
             self.execute.assert_called_once_with(['cat', '/proc/4/cmdline'],
                                                  'sudo')
 
+    def test_active_none(self):
+        dummy_cmd_line = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
+        self.execute.return_value = (dummy_cmd_line, '')
+        with mock.patch.object(LocalChild, 'pid') as pid:
+            pid.__get__ = mock.Mock(return_value=None)
+            lp = LocalChild(self.conf, FakeV4Network())
+            self.assertFalse(lp.active)
+
     def test_active_cmd_mismatch(self):
         dummy_cmd_line = 'bbbbbbbb-bbbb-bbbb-aaaa-aaaaaaaaaaaa'
         self.execute.return_value = (dummy_cmd_line, '')