← Back to team overview

cloud-init-dev team mailing list archive

[Merge] ~louis/cloud-init:fix_scaleway_datasource_backtrace into cloud-init:master

 

Louis Bouchard has proposed merging ~louis/cloud-init:fix_scaleway_datasource_backtrace into cloud-init:master.

Requested reviews:
  cloud-init Commiters (cloud-init-dev)

For more details, see:
https://code.launchpad.net/~louis/cloud-init/+git/cloud-init/+merge/377090
-- 
Your team cloud-init Commiters is requested to review the proposed merge of ~louis/cloud-init:fix_scaleway_datasource_backtrace into cloud-init:master.
diff --git a/cloudinit/sources/DataSourceScaleway.py b/cloudinit/sources/DataSourceScaleway.py
index b573b38..efc6ef3 100644
--- a/cloudinit/sources/DataSourceScaleway.py
+++ b/cloudinit/sources/DataSourceScaleway.py
@@ -227,7 +227,7 @@ class DataSourceScaleway(sources.DataSource):
         Configure networking according to data received from the
         metadata API.
         """
-        if self._network_config:
+        if self._network_config and self._network_config != sources.UNSET:
             return self._network_config
 
         if self._fallback_interface is None:
diff --git a/tests/unittests/test_datasource/test_scaleway.py b/tests/unittests/test_datasource/test_scaleway.py
index f96bf0a..23bb54c 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,25 @@ 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 run.
+        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)

Follow ups