diff options
author | James Falcon <therealfalcon@gmail.com> | 2021-09-17 13:04:07 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-17 13:04:07 -0500 |
commit | 612e39087aee3b1242765e7c4f463f54a6ebd723 (patch) | |
tree | 27112d8462d1f414c61717a7500dc264ab96c2ac /cloudinit/net/tests | |
parent | cb82a4508a4c56c3814fa633166d944762071bcf (diff) | |
download | vyos-cloud-init-612e39087aee3b1242765e7c4f463f54a6ebd723.tar.gz vyos-cloud-init-612e39087aee3b1242765e7c4f463f54a6ebd723.zip |
Add connectivity_url to Oracle's EphemeralDHCPv4 (#988)
Add connectivity_url to Oracle's EphemeralDHCPv4
On bionic, when trying to bring up the EphemeralDHCPv4, it's possible
that we already have a route defined, which will result in an error when
trying to add the DHCP route. Use the connectivity_url to check if we
can reach the metadata service, and if so, skip the EphemeralDHCPv4.
The has_url_connectivity function has also been modified to take
a dict of kwargs to send to readurl.
LP: #1939603
Diffstat (limited to 'cloudinit/net/tests')
-rw-r--r-- | cloudinit/net/tests/test_dhcp.py | 8 | ||||
-rw-r--r-- | cloudinit/net/tests/test_init.py | 20 |
2 files changed, 19 insertions, 9 deletions
diff --git a/cloudinit/net/tests/test_dhcp.py b/cloudinit/net/tests/test_dhcp.py index 5ae048e2..28b4ecf7 100644 --- a/cloudinit/net/tests/test_dhcp.py +++ b/cloudinit/net/tests/test_dhcp.py @@ -617,7 +617,9 @@ class TestEphemeralDhcpNoNetworkSetup(HttprettyTestCase): url = 'http://example.org/index.html' httpretty.register_uri(httpretty.GET, url) - with net.dhcp.EphemeralDHCPv4(connectivity_url=url) as lease: + with net.dhcp.EphemeralDHCPv4( + connectivity_url_data={'url': url}, + ) as lease: self.assertIsNone(lease) # Ensure that no teardown happens: m_dhcp.assert_not_called() @@ -635,7 +637,9 @@ class TestEphemeralDhcpNoNetworkSetup(HttprettyTestCase): m_subp.return_value = ('', '') httpretty.register_uri(httpretty.GET, url, body={}, status=404) - with net.dhcp.EphemeralDHCPv4(connectivity_url=url) as lease: + with net.dhcp.EphemeralDHCPv4( + connectivity_url_data={'url': url}, + ) as lease: self.assertEqual(fake_lease, lease) # Ensure that dhcp discovery occurs m_dhcp.called_once_with() diff --git a/cloudinit/net/tests/test_init.py b/cloudinit/net/tests/test_init.py index ad9c90ff..f9102f7b 100644 --- a/cloudinit/net/tests/test_init.py +++ b/cloudinit/net/tests/test_init.py @@ -622,11 +622,14 @@ class TestEphemeralIPV4Network(CiTestCase): params = { 'interface': 'eth0', 'ip': '192.168.2.2', 'prefix_or_mask': '255.255.255.0', 'broadcast': '192.168.2.255', - 'connectivity_url': 'http://example.org/index.html'} + 'connectivity_url_data': {'url': 'http://example.org/index.html'} + } with net.EphemeralIPv4Network(**params): - self.assertEqual([mock.call('http://example.org/index.html', - timeout=5)], m_readurl.call_args_list) + self.assertEqual( + [mock.call(url='http://example.org/index.html', timeout=5)], + m_readurl.call_args_list + ) # Ensure that no teardown happens: m_subp.assert_has_calls([]) @@ -850,25 +853,28 @@ class TestHasURLConnectivity(HttprettyTestCase): def test_url_timeout_on_connectivity_check(self, m_readurl): """A timeout of 5 seconds is provided when reading a url.""" self.assertTrue( - net.has_url_connectivity(self.url), 'Expected True on url connect') + net.has_url_connectivity({'url': self.url}), + 'Expected True on url connect') def test_true_on_url_connectivity_success(self): httpretty.register_uri(httpretty.GET, self.url) self.assertTrue( - net.has_url_connectivity(self.url), 'Expected True on url connect') + net.has_url_connectivity({'url': self.url}), + 'Expected True on url connect') @mock.patch('requests.Session.request') def test_true_on_url_connectivity_timeout(self, m_request): """A timeout raised accessing the url will return False.""" m_request.side_effect = requests.Timeout('Fake Connection Timeout') self.assertFalse( - net.has_url_connectivity(self.url), + net.has_url_connectivity({'url': self.url}), 'Expected False on url timeout') def test_true_on_url_connectivity_failure(self): httpretty.register_uri(httpretty.GET, self.url, body={}, status=404) self.assertFalse( - net.has_url_connectivity(self.url), 'Expected False on url fail') + net.has_url_connectivity({'url': self.url}), + 'Expected False on url fail') def _mk_v1_phys(mac, name, driver, device_id): |