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

Proposed by Mike Gerdts
Status: Needs review
Proposed branch: ~mgerdts/cloud-init:lp1765801
Merge into: cloud-init:master
Prerequisite: ~mgerdts/cloud-init:update_metadata
Diff against target: 86 lines (+15/-6)
3 files modified
cloudinit/sources/DataSourceSmartOS.py (+7/-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
Ryan Harper Pending
Review via email: mp+374987@code.launchpad.net

This proposal supersedes 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 : Posted in a previous version of this proposal

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) : Posted in a previous version of this proposal
Revision history for this message
Chad Smith (chad.smith) : Posted in a previous version of this proposal
Revision history for this message
Chad Smith (chad.smith) wrote : Posted in a previous version of this proposal

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

Revision history for this message
Mike Gerdts (mgerdts) wrote : Posted in a previous version of this proposal

I've looked high and low for what is setting ds._network_config = sources.UNSET and have come up empty. I gave up when I realized that DataSourceAzure follows a similar pattern.

I'm also not sure about what the proper way to allow an instance to say "hands off on future reboots". Is apply_network_config the right approach?

Revision history for this message
Mike Gerdts (mgerdts) wrote : Posted in a previous version of this proposal

Upon further experimentation, I don't think that adding (per-datasource) apply_network_config is needed. Setting it can cause a previously working instance to no longer be reachable over the net.

Better is:

network: {config: disabled}

This allows a working config to persist in /etc/netplan/50-cloud-init.yaml while not making further changes on subsequent boots.

Revision history for this message
Ryan Harper (raharper) wrote : Posted in a previous version of this proposal

I see a merge conflict in the diff below, I think a rebase should resolve this.

review: Needs Fixing
Revision history for this message
Mike Gerdts (mgerdts) wrote : Posted in a previous version of this proposal

As I asked in IRC on September 25:

[10:27:07] <mgerdts> I rebased an old branch, made some changes, force pushed, then resubmitted a merge request. The diff shows conflicts that don't really exist, seemingly related to the 13 month old version that was previously there. Would it be easier if I just submitted a fresh merge request rather than trying to make this one happy?
[10:27:09] <mgerdts> https://code.launchpad.net/~mgerdts/cloud-init/+git/cloud-init/+merge/373171

I have once again rebased it and force pushed. The diff below still shows the conflict. `git show` in my workspace does not show the conflict. My question from September 25 remains.

Revision history for this message
Mike Gerdts (mgerdts) wrote :

I created a fresh merge proposal from a new branch. It does not show the conflicts.

https://code.launchpad.net/~mgerdts/cloud-init/+git/cloud-init/+merge/374989

Unmerged commits

caff922... 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
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 @@
1# Copyright (C) 2013 Canonical Ltd.1# Copyright (C) 2013 Canonical Ltd.
2# Copyright (c) 2018, Joyent, Inc.2# Copyright 2019 Joyent, Inc.
3#3#
4# Author: Ben Howard <ben.howard@canonical.com>4# Author: Ben Howard <ben.howard@canonical.com>
5#5#
@@ -34,6 +34,7 @@ from cloudinit import log as logging
34from cloudinit import serial34from cloudinit import serial
35from cloudinit import sources35from cloudinit import sources
36from cloudinit import util36from cloudinit import util
37from cloudinit.event import EventType
3738
38LOG = logging.getLogger(__name__)39LOG = logging.getLogger(__name__)
3940
@@ -178,6 +179,7 @@ class DataSourceSmartOS(sources.DataSource):
178 self.metadata = {}179 self.metadata = {}
179 self.network_data = None180 self.network_data = None
180 self._network_config = None181 self._network_config = None
182 self.update_events['network'].add(EventType.BOOT)
181183
182 self.script_base_d = os.path.join(self.paths.get_cpath("scripts"))184 self.script_base_d = os.path.join(self.paths.get_cpath("scripts"))
183185
@@ -319,6 +321,10 @@ class DataSourceSmartOS(sources.DataSource):
319321
320 @property322 @property
321 def network_config(self):323 def network_config(self):
324 # sources.clear_cached_data() may set _network_config to '_unset'.
325 if self._network_config == sources.UNSET:
326 self._network_config = None
327
322 if self._network_config is None:328 if self._network_config is None:
323 if self.network_data is not None:329 if self.network_data is not None:
324 self._network_config = (330 self._network_config = (
diff --git a/cloudinit/sources/tests/test_init.py b/cloudinit/sources/tests/test_init.py
index 4154a5f..9698261 100644
--- a/cloudinit/sources/tests/test_init.py
+++ b/cloudinit/sources/tests/test_init.py
@@ -543,11 +543,7 @@ class TestDataSource(CiTestCase):
543 """update_metadata won't get_data on unsupported update events."""543 """update_metadata won't get_data on unsupported update events."""
544 self.datasource.update_events['network'].discard(EventType.BOOT)544 self.datasource.update_events['network'].discard(EventType.BOOT)
545 self.assertEqual(545 self.assertEqual(
546<<<<<<< cloudinit/sources/tests/test_init.py
547 {'network': set([EventType.BOOT_NEW_INSTANCE])},546 {'network': set([EventType.BOOT_NEW_INSTANCE])},
548=======
549 {'network': {EventType.BOOT_NEW_INSTANCE}},
550>>>>>>> cloudinit/sources/tests/test_init.py
551 self.datasource.update_events)547 self.datasource.update_events)
552548
553 def fake_get_data():549 def fake_get_data():
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 @@
1# Copyright (C) 2013 Canonical Ltd.1# Copyright (C) 2013 Canonical Ltd.
2# Copyright (c) 2018, Joyent, Inc.2# Copyright 2019 Joyent, Inc.
3#3#
4# Author: Ben Howard <ben.howard@canonical.com>4# Author: Ben Howard <ben.howard@canonical.com>
5#5#
@@ -31,6 +31,7 @@ from cloudinit.sources.DataSourceSmartOS import (
31 convert_smartos_network_data as convert_net,31 convert_smartos_network_data as convert_net,
32 SMARTOS_ENV_KVM, SERIAL_DEVICE, get_smartos_environ,32 SMARTOS_ENV_KVM, SERIAL_DEVICE, get_smartos_environ,
33 identify_file)33 identify_file)
34from cloudinit.event import EventType
3435
35import six36import six
3637
@@ -653,6 +654,12 @@ class TestSmartOSDataSource(FilesystemMockingTestCase):
653 self.assertEqual(dsrc.device_name_to_device('FOO'),654 self.assertEqual(dsrc.device_name_to_device('FOO'),
654 mydscfg['disk_aliases']['FOO'])655 mydscfg['disk_aliases']['FOO'])
655656
657 def test_reconfig_network_on_boot(self):
658 # Test to ensure that network is configured from metadata on each boot
659 dsrc = self._get_ds(mockdata=MOCK_RETURNS)
660 self.assertSetEqual(set([EventType.BOOT_NEW_INSTANCE, EventType.BOOT]),
661 dsrc.update_events['network'])
662
656663
657class TestIdentifyFile(CiTestCase):664class TestIdentifyFile(CiTestCase):
658 """Test the 'identify_file' utility."""665 """Test the 'identify_file' utility."""

Subscribers

People subscribed via source and target branches