← Back to team overview

cloud-init-dev team mailing list archive

[Merge] ~mgerdts/cloud-init:lp1765801 into cloud-init:master

 

Mike Gerdts has proposed merging ~mgerdts/cloud-init:lp1765801 into cloud-init:master with ~mgerdts/cloud-init:update_metadata as a prerequisite.

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/350375
-- 
Your team cloud-init commiters is requested to review the proposed merge of ~mgerdts/cloud-init:lp1765801 into cloud-init:master.
diff --git a/cloudinit/sources/DataSourceSmartOS.py b/cloudinit/sources/DataSourceSmartOS.py
index f92e8b5..ed4bc18 100644
--- a/cloudinit/sources/DataSourceSmartOS.py
+++ b/cloudinit/sources/DataSourceSmartOS.py
@@ -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"))
 
diff --git a/cloudinit/sources/__init__.py b/cloudinit/sources/__init__.py
index 16be569..f424316 100644
--- a/cloudinit/sources/__init__.py
+++ b/cloudinit/sources/__init__.py
@@ -103,14 +103,14 @@ class DataSource(object):
     url_timeout = 10    # timeout for each metadata url read attempt
     url_retries = 5     # number of times to retry url upon 404
 
-    # The datasource defines a set of supported EventTypes during which
+    # The datasource defines a list of supported EventTypes during which
     # the datasource can react to changes in metadata and regenerate
     # network configuration on metadata changes.
     # A datasource which supports writing network config on each system boot
-    # would call update_events['network'].add(EventType.BOOT).
+    # would set update_events = {'network': [EventType.BOOT]}
 
     # Default: generate network config on new instance id (first boot).
-    update_events = {'network': {EventType.BOOT_NEW_INSTANCE}}
+    update_events = {'network': [EventType.BOOT_NEW_INSTANCE]}
 
     # N-tuple listing default values for any metadata-related class
     # attributes cached on an instance by a process_data runs. These attribute
@@ -475,8 +475,8 @@ class DataSource(object):
             for update_scope, update_events in self.update_events.items():
                 if event in update_events:
                     if not supported_events.get(update_scope):
-                        supported_events[update_scope] = set()
-                    supported_events[update_scope].add(event)
+                        supported_events[update_scope] = []
+                    supported_events[update_scope].append(event)
         for scope, matched_events in supported_events.items():
             LOG.debug(
                 "Update datasource metadata and %s config due to events: %s",
@@ -490,8 +490,6 @@ class DataSource(object):
             result = self.get_data()
             if result:
                 return True
-        LOG.debug("Datasource %s not updated for events: %s", self,
-                  ', '.join(source_event_types))
         return False
 
     def check_instance_id(self, sys_cfg):
diff --git a/cloudinit/sources/tests/test_init.py b/cloudinit/sources/tests/test_init.py
index 762ec17..dcd221b 100644
--- a/cloudinit/sources/tests/test_init.py
+++ b/cloudinit/sources/tests/test_init.py
@@ -429,9 +429,8 @@ class TestDataSource(CiTestCase):
 
     def test_update_metadata_only_acts_on_supported_update_events(self):
         """update_metadata won't get_data on unsupported update events."""
-        self.datasource.update_events['network'].discard(EventType.BOOT)
         self.assertEqual(
-            {'network': {EventType.BOOT_NEW_INSTANCE}},
+            {'network': [EventType.BOOT_NEW_INSTANCE]},
             self.datasource.update_events)
 
         def fake_get_data():

Follow ups