Treat case when pid is None

Fixes bug 1077651

Change-Id: Id80d923d36a0339eee860e8cf37aacc6866fc6bc
This commit is contained in:
Gary Kotton 2012-11-07 05:46:08 +00:00
parent cf79fd37a4
commit 7d906f303b
2 changed files with 11 additions and 0 deletions

View 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)

View 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, '')