diff options
author | Scott Moser <smoser@brickies.net> | 2017-11-19 16:27:06 -0700 |
---|---|---|
committer | Chad Smith <chad.smith@canonical.com> | 2017-11-19 16:27:06 -0700 |
commit | d3a0958c09c73a78fda6e922b749a1b98036e984 (patch) | |
tree | 14f2466eff08f9b145ec1990c96c37d2e81a8166 /cloudinit/net/tests | |
parent | d90318b21d0379e24337bcb92a0a90ebfa359c35 (diff) | |
download | vyos-cloud-init-d3a0958c09c73a78fda6e922b749a1b98036e984.tar.gz vyos-cloud-init-d3a0958c09c73a78fda6e922b749a1b98036e984.zip |
EC2: Kill dhclient process used in sandbox dhclient.
dhclient runs, obtains a address and then backgrounds itself.
cloud-init did not take care to kill it after it was done with it.
After it has run and created the leases, we can kill it.
LP: #1732964
Diffstat (limited to 'cloudinit/net/tests')
-rw-r--r-- | cloudinit/net/tests/test_dhcp.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/cloudinit/net/tests/test_dhcp.py b/cloudinit/net/tests/test_dhcp.py index 1c1f504a..3d8e15c0 100644 --- a/cloudinit/net/tests/test_dhcp.py +++ b/cloudinit/net/tests/test_dhcp.py @@ -2,6 +2,7 @@ import mock import os +import signal from textwrap import dedent from cloudinit.net.dhcp import ( @@ -114,8 +115,9 @@ class TestDHCPDiscoveryClean(CiTestCase): self.assertEqual('eth9', call[0][1]) self.assertIn('/var/tmp/cloud-init/cloud-init-dhcp-', call[0][2]) + @mock.patch('cloudinit.net.dhcp.os.kill') @mock.patch('cloudinit.net.dhcp.util.subp') - def test_dhcp_discovery_run_in_sandbox(self, m_subp): + def test_dhcp_discovery_run_in_sandbox(self, m_subp, m_kill): """dhcp_discovery brings up the interface and runs dhclient. It also returns the parsed dhcp.leases file generated in the sandbox. @@ -134,6 +136,10 @@ class TestDHCPDiscoveryClean(CiTestCase): """) lease_file = os.path.join(tmpdir, 'dhcp.leases') write_file(lease_file, lease_content) + pid_file = os.path.join(tmpdir, 'dhclient.pid') + my_pid = 1 + write_file(pid_file, "%d\n" % my_pid) + self.assertItemsEqual( [{'interface': 'eth9', 'fixed-address': '192.168.2.74', 'subnet-mask': '255.255.255.0', 'routers': '192.168.2.1'}], @@ -149,6 +155,7 @@ class TestDHCPDiscoveryClean(CiTestCase): [os.path.join(tmpdir, 'dhclient'), '-1', '-v', '-lf', lease_file, '-pf', os.path.join(tmpdir, 'dhclient.pid'), 'eth9', '-sf', '/bin/true'], capture=True)]) + m_kill.assert_has_calls([mock.call(my_pid, signal.SIGKILL)]) class TestSystemdParseLeases(CiTestCase): |