summaryrefslogtreecommitdiff
path: root/tests/unittests/test_datasource/test_scaleway.py
diff options
context:
space:
mode:
authorLouis Bouchard <bouchard.louis@gmail.com>2020-01-29 16:55:09 +0100
committerGitHub <noreply@github.com>2020-01-29 10:55:09 -0500
commit9e3ac98097ed1c7f49ec8975a40aec7229231aae (patch)
tree5311ad18aca51d5413b6d75d3179798ab0f4f3fb /tests/unittests/test_datasource/test_scaleway.py
parent88b09643787c55b700cfadc25bbe0ddbfe0368e6 (diff)
downloadvyos-cloud-init-9e3ac98097ed1c7f49ec8975a40aec7229231aae.tar.gz
vyos-cloud-init-9e3ac98097ed1c7f49ec8975a40aec7229231aae.zip
Scaleway: Fix DatasourceScaleway to avoid backtrace (#128)
Make sure network_config is created when self._network_config is unset. Co-authored-by: Scott Moser <smoser@brickies.net>
Diffstat (limited to 'tests/unittests/test_datasource/test_scaleway.py')
-rw-r--r--tests/unittests/test_datasource/test_scaleway.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/unittests/test_datasource/test_scaleway.py b/tests/unittests/test_datasource/test_scaleway.py
index f96bf0a2..1b4dd0ad 100644
--- a/tests/unittests/test_datasource/test_scaleway.py
+++ b/tests/unittests/test_datasource/test_scaleway.py
@@ -7,6 +7,7 @@ import requests
from cloudinit import helpers
from cloudinit import settings
+from cloudinit import sources
from cloudinit.sources import DataSourceScaleway
from cloudinit.tests.helpers import mock, HttprettyTestCase, CiTestCase
@@ -403,3 +404,51 @@ class TestDataSourceScaleway(HttprettyTestCase):
netcfg = self.datasource.network_config
self.assertEqual(netcfg, '0xdeadbeef')
+
+ @mock.patch('cloudinit.sources.DataSourceScaleway.net.find_fallback_nic')
+ @mock.patch('cloudinit.util.get_cmdline')
+ def test_network_config_unset(self, m_get_cmdline, fallback_nic):
+ """
+ _network_config will be set to sources.UNSET after the first boot.
+ Make sure it behave correctly.
+ """
+ m_get_cmdline.return_value = 'scaleway'
+ fallback_nic.return_value = 'ens2'
+ self.datasource.metadata['ipv6'] = None
+ self.datasource._network_config = sources.UNSET
+
+ resp = {'version': 1,
+ 'config': [{
+ 'type': 'physical',
+ 'name': 'ens2',
+ 'subnets': [{'type': 'dhcp4'}]}]
+ }
+
+ netcfg = self.datasource.network_config
+ self.assertEqual(netcfg, resp)
+
+ @mock.patch('cloudinit.sources.DataSourceScaleway.LOG.warning')
+ @mock.patch('cloudinit.sources.DataSourceScaleway.net.find_fallback_nic')
+ @mock.patch('cloudinit.util.get_cmdline')
+ def test_network_config_cached_none(self, m_get_cmdline, fallback_nic,
+ logwarning):
+ """
+ network_config() should return config data if cached data is None
+ rather than sources.UNSET
+ """
+ m_get_cmdline.return_value = 'scaleway'
+ fallback_nic.return_value = 'ens2'
+ self.datasource.metadata['ipv6'] = None
+ self.datasource._network_config = None
+
+ resp = {'version': 1,
+ 'config': [{
+ 'type': 'physical',
+ 'name': 'ens2',
+ 'subnets': [{'type': 'dhcp4'}]}]
+ }
+
+ netcfg = self.datasource.network_config
+ self.assertEqual(netcfg, resp)
+ logwarning.assert_called_with('Found None as cached _network_config. '
+ 'Resetting to %s', sources.UNSET)