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

Proposed by Mike Gerdts
Status: Superseded
Proposed branch: ~mgerdts/cloud-init:lp1765801
Merge into: cloud-init:master
Prerequisite: ~mgerdts/cloud-init:update_metadata
Diff against target: 90 lines (+19/-6)
3 files modified
cloudinit/sources/DataSourceSmartOS.py (+11/-1)
cloudinit/sources/tests/test_init.py (+0/-4)
tests/unittests/test_datasource/test_smartos.py (+8/-1)
Reviewer Review Type Date Requested Status
Chad Smith Pending
Review via email: mp+350375@code.launchpad.net

This proposal has been superseded by a proposal from 2019-09-25.

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

To post a comment you must log in.
Revision history for this message
Chad Smith (chad.smith) wrote :

Thanks for the branch Mike, just a request for unit test or an additional assert on the SmartOs datasource update_events attribute as well as what seems to be a git rebase required on your branch.

Revision history for this message
Mike Gerdts (mgerdts) :
Revision history for this message
Chad Smith (chad.smith) :
Revision history for this message
Chad Smith (chad.smith) wrote :

Hi Mike,

  Marking this 'Work in progress' for the time being so it doesn't sit in my 'needs review' column.

When you get a chance to push your changes and want a review, please just set this branch back to 'Needs review' and we'll take care of it.

thanks again,
Chad

Unmerged commits

2c9f342... by Mike Gerdts

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/cloudinit/sources/DataSourceSmartOS.py b/cloudinit/sources/DataSourceSmartOS.py
2index 32b57cd..844647e 100644
3--- a/cloudinit/sources/DataSourceSmartOS.py
4+++ b/cloudinit/sources/DataSourceSmartOS.py
5@@ -1,5 +1,5 @@
6 # Copyright (C) 2013 Canonical Ltd.
7-# Copyright (c) 2018, Joyent, Inc.
8+# Copyright 2019 Joyent, Inc.
9 #
10 # Author: Ben Howard <ben.howard@canonical.com>
11 #
12@@ -34,6 +34,7 @@ from cloudinit import log as logging
13 from cloudinit import serial
14 from cloudinit import sources
15 from cloudinit import util
16+from cloudinit.event import EventType
17
18 LOG = logging.getLogger(__name__)
19
20@@ -178,6 +179,7 @@ class DataSourceSmartOS(sources.DataSource):
21 self.metadata = {}
22 self.network_data = None
23 self._network_config = None
24+ self.update_events['network'].add(EventType.BOOT)
25
26 self.script_base_d = os.path.join(self.paths.get_cpath("scripts"))
27
28@@ -319,6 +321,14 @@ class DataSourceSmartOS(sources.DataSource):
29
30 @property
31 def network_config(self):
32+ if util.is_false(self.ds_cfg.get('apply_network_config', True)):
33+ self._network_config = None
34+ return self._network_config
35+
36+ # Something unhelpfully sets _network_config to '_unset' sometimes.
37+ if self._network_config == sources.UNSET:
38+ self._network_config = None
39+
40 if self._network_config is None:
41 if self.network_data is not None:
42 self._network_config = (
43diff --git a/cloudinit/sources/tests/test_init.py b/cloudinit/sources/tests/test_init.py
44index b80a5b8..6378e98 100644
45--- a/cloudinit/sources/tests/test_init.py
46+++ b/cloudinit/sources/tests/test_init.py
47@@ -545,11 +545,7 @@ class TestDataSource(CiTestCase):
48 """update_metadata won't get_data on unsupported update events."""
49 self.datasource.update_events['network'].discard(EventType.BOOT)
50 self.assertEqual(
51-<<<<<<< cloudinit/sources/tests/test_init.py
52 {'network': set([EventType.BOOT_NEW_INSTANCE])},
53-=======
54- {'network': {EventType.BOOT_NEW_INSTANCE}},
55->>>>>>> cloudinit/sources/tests/test_init.py
56 self.datasource.update_events)
57
58 def fake_get_data():
59diff --git a/tests/unittests/test_datasource/test_smartos.py b/tests/unittests/test_datasource/test_smartos.py
60index 42ac697..d5b1c29 100644
61--- a/tests/unittests/test_datasource/test_smartos.py
62+++ b/tests/unittests/test_datasource/test_smartos.py
63@@ -1,5 +1,5 @@
64 # Copyright (C) 2013 Canonical Ltd.
65-# Copyright (c) 2018, Joyent, Inc.
66+# Copyright 2019 Joyent, Inc.
67 #
68 # Author: Ben Howard <ben.howard@canonical.com>
69 #
70@@ -31,6 +31,7 @@ from cloudinit.sources.DataSourceSmartOS import (
71 convert_smartos_network_data as convert_net,
72 SMARTOS_ENV_KVM, SERIAL_DEVICE, get_smartos_environ,
73 identify_file)
74+from cloudinit.event import EventType
75
76 import six
77
78@@ -653,6 +654,12 @@ class TestSmartOSDataSource(FilesystemMockingTestCase):
79 self.assertEqual(dsrc.device_name_to_device('FOO'),
80 mydscfg['disk_aliases']['FOO'])
81
82+ def test_reconfig_network_on_boot(self):
83+ # Test to ensure that network is configured from metadata on each boot
84+ dsrc = self._get_ds(mockdata=MOCK_RETURNS)
85+ self.assertSetEqual(set([EventType.BOOT_NEW_INSTANCE, EventType.BOOT]),
86+ dsrc.update_events['network'])
87+
88
89 class TestIdentifyFile(CiTestCase):
90 """Test the 'identify_file' utility."""

Subscribers

People subscribed via source and target branches