Merge ~mgerdts/cloud-init:update_metadata into cloud-init:master

Proposed by Mike Gerdts
Status: Rejected
Rejected by: Scott Moser
Proposed branch: ~mgerdts/cloud-init:update_metadata
Merge into: cloud-init:master
Diff against target: 57 lines (+9/-6)
2 files modified
cloudinit/sources/__init__.py (+7/-5)
cloudinit/sources/tests/test_init.py (+2/-1)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Needs Fixing
Scott Moser Approve
Review via email: mp+350374@code.launchpad.net

Commit message

update_metadata re-config on every boot comments and tests not quite right

The comment in update_metadata() that explains how a datasource should
enable network reconfig on every boot presumes that
EventType.BOOT_NEW_INSTANCE is a subset of EventType.BOOT. That's not
the case, and as such a datasource that needs to configure networking
when it is a new instance and every boot needs to include both event
types.

To make the situation above easier to debug, update_metadata() now
logs when it returns false.

To make it so that datasources do not need to test before appending to
the update_events['network'], it is changed from a list to a set.

test_update_metadata_only_acts_on_supported_update_events is updated
to allow datasources to support EventType.BOOT.

To post a comment you must log in.
Revision history for this message
Scott Moser (smoser) wrote :

that looks good. thanks.

review: Approve
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

FAILED: Autolanding.
More details in the following jenkins job:
https://jenkins.ubuntu.com/server/job/cloud-init-autoland-test/11/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    FAILED: MAAS Compatability Testing

review: Needs Fixing (continuous-integration)
~mgerdts/cloud-init:update_metadata updated
b7b135b... by Mike Gerdts

fix python 2.6

Revision history for this message
Scott Moser (smoser) wrote :

I fixed the last 2.6 issue and pushed an MP up at
 https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/351355

We'll just move this over there.

Unmerged commits

b7b135b... by Mike Gerdts

fix python 2.6

7f602de... by Mike Gerdts

update_metadata re-config on every boot comments and tests not quite right

The comment in update_metadata() that explains how a datasource should enable
network reconfig on every boot presumes that EventType.BOOT_NEW_INSTANCE is a
subset of EventType.BOOT. That's not the case, and as such a datasource that
needs to configure networking when it is a new instance and every boot needs to
include both event types.

To make the situation above easier to debug, update_metadata() now logs when it
returns false.

To make it so that datasources do not need to test before appending to
the update_events['network'], it is changed from a list to a set.

test_update_metadata_only_acts_on_supported_update_events is updated to allow
datasources to support EventType.BOOT.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/cloudinit/sources/__init__.py b/cloudinit/sources/__init__.py
index f424316..06e613f 100644
--- a/cloudinit/sources/__init__.py
+++ b/cloudinit/sources/__init__.py
@@ -103,14 +103,14 @@ class DataSource(object):
103 url_timeout = 10 # timeout for each metadata url read attempt103 url_timeout = 10 # timeout for each metadata url read attempt
104 url_retries = 5 # number of times to retry url upon 404104 url_retries = 5 # number of times to retry url upon 404
105105
106 # The datasource defines a list of supported EventTypes during which106 # The datasource defines a set of supported EventTypes during which
107 # the datasource can react to changes in metadata and regenerate107 # the datasource can react to changes in metadata and regenerate
108 # network configuration on metadata changes.108 # network configuration on metadata changes.
109 # A datasource which supports writing network config on each system boot109 # A datasource which supports writing network config on each system boot
110 # would set update_events = {'network': [EventType.BOOT]}110 # would call update_events['network'].add(EventType.BOOT).
111111
112 # Default: generate network config on new instance id (first boot).112 # Default: generate network config on new instance id (first boot).
113 update_events = {'network': [EventType.BOOT_NEW_INSTANCE]}113 update_events = {'network': set([EventType.BOOT_NEW_INSTANCE])}
114114
115 # N-tuple listing default values for any metadata-related class115 # N-tuple listing default values for any metadata-related class
116 # attributes cached on an instance by a process_data runs. These attribute116 # attributes cached on an instance by a process_data runs. These attribute
@@ -475,8 +475,8 @@ class DataSource(object):
475 for update_scope, update_events in self.update_events.items():475 for update_scope, update_events in self.update_events.items():
476 if event in update_events:476 if event in update_events:
477 if not supported_events.get(update_scope):477 if not supported_events.get(update_scope):
478 supported_events[update_scope] = []478 supported_events[update_scope] = set()
479 supported_events[update_scope].append(event)479 supported_events[update_scope].add(event)
480 for scope, matched_events in supported_events.items():480 for scope, matched_events in supported_events.items():
481 LOG.debug(481 LOG.debug(
482 "Update datasource metadata and %s config due to events: %s",482 "Update datasource metadata and %s config due to events: %s",
@@ -490,6 +490,8 @@ class DataSource(object):
490 result = self.get_data()490 result = self.get_data()
491 if result:491 if result:
492 return True492 return True
493 LOG.debug("Datasource %s not updated for events: %s", self,
494 ', '.join(source_event_types))
493 return False495 return False
494496
495 def check_instance_id(self, sys_cfg):497 def check_instance_id(self, sys_cfg):
diff --git a/cloudinit/sources/tests/test_init.py b/cloudinit/sources/tests/test_init.py
index dcd221b..762ec17 100644
--- a/cloudinit/sources/tests/test_init.py
+++ b/cloudinit/sources/tests/test_init.py
@@ -429,8 +429,9 @@ class TestDataSource(CiTestCase):
429429
430 def test_update_metadata_only_acts_on_supported_update_events(self):430 def test_update_metadata_only_acts_on_supported_update_events(self):
431 """update_metadata won't get_data on unsupported update events."""431 """update_metadata won't get_data on unsupported update events."""
432 self.datasource.update_events['network'].discard(EventType.BOOT)
432 self.assertEqual(433 self.assertEqual(
433 {'network': [EventType.BOOT_NEW_INSTANCE]},434 {'network': {EventType.BOOT_NEW_INSTANCE}},
434 self.datasource.update_events)435 self.datasource.update_events)
435436
436 def fake_get_data():437 def fake_get_data():

Subscribers

People subscribed via source and target branches