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
1diff --git a/cloudinit/sources/__init__.py b/cloudinit/sources/__init__.py
2index f424316..06e613f 100644
3--- a/cloudinit/sources/__init__.py
4+++ b/cloudinit/sources/__init__.py
5@@ -103,14 +103,14 @@ class DataSource(object):
6 url_timeout = 10 # timeout for each metadata url read attempt
7 url_retries = 5 # number of times to retry url upon 404
8
9- # The datasource defines a list of supported EventTypes during which
10+ # The datasource defines a set of supported EventTypes during which
11 # the datasource can react to changes in metadata and regenerate
12 # network configuration on metadata changes.
13 # A datasource which supports writing network config on each system boot
14- # would set update_events = {'network': [EventType.BOOT]}
15+ # would call update_events['network'].add(EventType.BOOT).
16
17 # Default: generate network config on new instance id (first boot).
18- update_events = {'network': [EventType.BOOT_NEW_INSTANCE]}
19+ update_events = {'network': set([EventType.BOOT_NEW_INSTANCE])}
20
21 # N-tuple listing default values for any metadata-related class
22 # attributes cached on an instance by a process_data runs. These attribute
23@@ -475,8 +475,8 @@ class DataSource(object):
24 for update_scope, update_events in self.update_events.items():
25 if event in update_events:
26 if not supported_events.get(update_scope):
27- supported_events[update_scope] = []
28- supported_events[update_scope].append(event)
29+ supported_events[update_scope] = set()
30+ supported_events[update_scope].add(event)
31 for scope, matched_events in supported_events.items():
32 LOG.debug(
33 "Update datasource metadata and %s config due to events: %s",
34@@ -490,6 +490,8 @@ class DataSource(object):
35 result = self.get_data()
36 if result:
37 return True
38+ LOG.debug("Datasource %s not updated for events: %s", self,
39+ ', '.join(source_event_types))
40 return False
41
42 def check_instance_id(self, sys_cfg):
43diff --git a/cloudinit/sources/tests/test_init.py b/cloudinit/sources/tests/test_init.py
44index dcd221b..762ec17 100644
45--- a/cloudinit/sources/tests/test_init.py
46+++ b/cloudinit/sources/tests/test_init.py
47@@ -429,8 +429,9 @@ class TestDataSource(CiTestCase):
48
49 def test_update_metadata_only_acts_on_supported_update_events(self):
50 """update_metadata won't get_data on unsupported update events."""
51+ self.datasource.update_events['network'].discard(EventType.BOOT)
52 self.assertEqual(
53- {'network': [EventType.BOOT_NEW_INSTANCE]},
54+ {'network': {EventType.BOOT_NEW_INSTANCE}},
55 self.datasource.update_events)
56
57 def fake_get_data():

Subscribers

People subscribed via source and target branches