Mike Gerdts has proposed merging ~mgerdts/cloud-init:lp1765801.1 into 
cloud-init:master.

Commit message:
DataSourceSmartOS: reconfigure network on each boot

In typical cases, SmartOS does not use DHCP for network configuration.  As such,
if the network configuration changes that is reflected in metadata and will be
picked up during the next boot.

LP: #1765801
Joyent: OS-6902 cloud-init should be able to reconfigure network on each boot

Requested reviews:
  cloud-init Commiters (cloud-init-dev)
Related bugs:
  Bug #1765801 in cloud-init: "network should be optionally reconfigured on 
every boot"
  https://bugs.launchpad.net/cloud-init/+bug/1765801

For more details, see:
https://code.launchpad.net/~mgerdts/cloud-init/+git/cloud-init/+merge/374989
-- 
Your team cloud-init Commiters is requested to review the proposed merge of 
~mgerdts/cloud-init:lp1765801.1 into cloud-init:master.
diff --git a/cloudinit/sources/DataSourceSmartOS.py b/cloudinit/sources/DataSourceSmartOS.py
index 32b57cd..cf67650 100644
--- a/cloudinit/sources/DataSourceSmartOS.py
+++ b/cloudinit/sources/DataSourceSmartOS.py
@@ -1,5 +1,5 @@
 # Copyright (C) 2013 Canonical Ltd.
-# Copyright (c) 2018, Joyent, Inc.
+# Copyright 2019 Joyent, Inc.
 #
 # Author: Ben Howard <[email protected]>
 #
@@ -34,6 +34,7 @@ from cloudinit import log as logging
 from cloudinit import serial
 from cloudinit import sources
 from cloudinit import util
+from cloudinit.event import EventType
 
 LOG = logging.getLogger(__name__)
 
@@ -178,6 +179,7 @@ class DataSourceSmartOS(sources.DataSource):
         self.metadata = {}
         self.network_data = None
         self._network_config = None
+        self.update_events['network'].add(EventType.BOOT)
 
         self.script_base_d = os.path.join(self.paths.get_cpath("scripts"))
 
@@ -319,6 +321,10 @@ class DataSourceSmartOS(sources.DataSource):
 
     @property
     def network_config(self):
+        # sources.clear_cached_data() may set _network_config to '_unset'.
+        if self._network_config == sources.UNSET:
+            self._network_config = None
+
         if self._network_config is None:
             if self.network_data is not None:
                 self._network_config = (
diff --git a/tests/unittests/test_datasource/test_smartos.py b/tests/unittests/test_datasource/test_smartos.py
index 42ac697..d5b1c29 100644
--- a/tests/unittests/test_datasource/test_smartos.py
+++ b/tests/unittests/test_datasource/test_smartos.py
@@ -1,5 +1,5 @@
 # Copyright (C) 2013 Canonical Ltd.
-# Copyright (c) 2018, Joyent, Inc.
+# Copyright 2019 Joyent, Inc.
 #
 # Author: Ben Howard <[email protected]>
 #
@@ -31,6 +31,7 @@ from cloudinit.sources.DataSourceSmartOS import (
     convert_smartos_network_data as convert_net,
     SMARTOS_ENV_KVM, SERIAL_DEVICE, get_smartos_environ,
     identify_file)
+from cloudinit.event import EventType
 
 import six
 
@@ -653,6 +654,12 @@ class TestSmartOSDataSource(FilesystemMockingTestCase):
         self.assertEqual(dsrc.device_name_to_device('FOO'),
                          mydscfg['disk_aliases']['FOO'])
 
+    def test_reconfig_network_on_boot(self):
+        # Test to ensure that network is configured from metadata on each boot
+        dsrc = self._get_ds(mockdata=MOCK_RETURNS)
+        self.assertSetEqual(set([EventType.BOOT_NEW_INSTANCE, EventType.BOOT]),
+                            dsrc.update_events['network'])
+
 
 class TestIdentifyFile(CiTestCase):
     """Test the 'identify_file' utility."""
_______________________________________________
Mailing list: https://launchpad.net/~cloud-init-dev
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~cloud-init-dev
More help   : https://help.launchpad.net/ListHelp

Reply via email to