diff --git a/quantum/agent/linux/dhcp.py b/quantum/agent/linux/dhcp.py index 304e2ce459..e1586befdd 100644 --- a/quantum/agent/linux/dhcp.py +++ b/quantum/agent/linux/dhcp.py @@ -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) diff --git a/quantum/tests/unit/test_linux_dhcp.py b/quantum/tests/unit/test_linux_dhcp.py index 1042e96435..12065b2bbb 100644 --- a/quantum/tests/unit/test_linux_dhcp.py +++ b/quantum/tests/unit/test_linux_dhcp.py @@ -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, '')