From 7d906f303bc6c17623b8b92a578c450d17e08291 Mon Sep 17 00:00:00 2001 From: Gary Kotton Date: Wed, 7 Nov 2012 05:46:08 +0000 Subject: [PATCH] Treat case when pid is None Fixes bug 1077651 Change-Id: Id80d923d36a0339eee860e8cf37aacc6866fc6bc --- quantum/agent/linux/dhcp.py | 3 +++ quantum/tests/unit/test_linux_dhcp.py | 8 ++++++++ 2 files changed, 11 insertions(+) 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, '')