Merge ~kurt-easygo/cloud-init:fix-network-state-dhcp into cloud-init:master

Proposed by Kurt Stieger
Status: Merged
Approved by: Ryan Harper
Approved revision: bde69680d50f0d2fe5c04014ea1527ed7d5b501f
Merge reported by: Server Team CI bot
Merged at revision: not available
Proposed branch: ~kurt-easygo/cloud-init:fix-network-state-dhcp
Merge into: cloud-init:master
Diff against target: 94 lines (+63/-2)
2 files modified
cloudinit/net/network_state.py (+2/-2)
tests/unittests/test_net.py (+61/-0)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Approve
Review via email: mp+363732@code.launchpad.net

Commit message

net: append type:dhcp[46] only if dhcp[46] is True in v2 netconfig

When providing netplan configuration to cloud-init, the internal
network state would enable DHCP if the 'dhcp' key was present in
the source config. In netplan, dhcp[46] is a boolean and the
value of the boolean should control whether DHCP is enabled rather
than the presence of the key. This issue leaded to inconsistant
sysconfig/network-scripts on fedora. 'BOOTPROTO' was always 'dhcp',
even if the address config was static.

After this change a dhcp subnet is added only if the 'dhcp' setting
in source cfg dict is True.

LP: #1818032

To post a comment you must log in.
Revision history for this message
Ryan Harper (raharper) wrote :

Hi,
Thank you for contributing to cloud-init.

To contribute, you must sign the Canonical Contributor License Agreement
(CLA) [1].

If you have already signed it as an individual, your Launchpad user will
be listed in the contributor-agreement-canonical launchpad group [2].
Unfortunately there is no easy way to check if an organization or company
you are doing work for has signed. If you are unsure or have questions,
email <email address hidden> or ping rharper in #cloud-init channel
via freenode.

For information on how to sign, please see the HACKING document [3].

Thanks again, and please feel free to reach out with any questions.


[1] http://www.canonical.com/contributors
[2] https://launchpad.net/~contributor-agreement-canonical/+members
[3] http://cloudinit.readthedocs.io/en/latest/topics/hacking.html

Revision history for this message
Kurt Stieger (kurt-easygo) wrote :

Hi Ryan,
I signed the Agreement a few minutes ago. Don't know how long it takes
until I am listed on the contributor list.
Thank you for testing and verifying my change.

Greetings,
Kurt

On Thu, 28 Feb 2019 at 18:54 Ryan Harper <email address hidden> wrote:

> Hi,
> Thank you for contributing to cloud-init.
>
> To contribute, you must sign the Canonical Contributor License Agreement
> (CLA) [1].
>
> If you have already signed it as an individual, your Launchpad user will
> be listed in the contributor-agreement-canonical launchpad group [2].
> Unfortunately there is no easy way to check if an organization or company
> you are doing work for has signed. If you are unsure or have questions,
> email <email address hidden> or ping rharper in #cloud-init channel
> via freenode.
>
> For information on how to sign, please see the HACKING document [3].
>
> Thanks again, and please feel free to reach out with any questions.
>
> –
> [1] http://www.canonical.com/contributors
> [2] https://launchpad.net/~contributor-agreement-canonical/+members
> [3] http://cloudinit.readthedocs.io/en/latest/topics/hacking.html
> --
>
> https://code.launchpad.net/~kurt-easygo/cloud-init/+git/cloud-init/+merge/363732
> You are the owner of ~kurt-easygo/cloud-init:fix-network-state-dhcp.
>
--
Beste Grüße,

Kurt Stieger
Hinterwaldnerstraße 26/8
A-6020 Innsbruck

Revision history for this message
Ryan Harper (raharper) wrote :

Thanks.

I've added a unittest for this scenario, if you'd like to apply that to your branch and update.

http://paste.ubuntu.com/p/xGH5CgWFGM/

After you do, I'll have our CI run against this and if it checks out OK, and LP has updated your CLA status, we can accept.

Thanks again for the contribution.

bde6968... by Kurt Stieger

ADD: unitest for fix-network-state-dhcp
     thanks to rharper

Revision history for this message
Kurt Stieger (kurt-easygo) wrote :

Thanks.
Patch already applied and committed.

/Kurt

On Thu, 28 Feb 2019 at 21:04 Ryan Harper <email address hidden> wrote:

> Thanks.
>
> I've added a unittest for this scenario, if you'd like to apply that to
> your branch and update.
>
> http://paste.ubuntu.com/p/xGH5CgWFGM/
>
> After you do, I'll have our CI run against this and if it checks out OK,
> and LP has updated your CLA status, we can accept.
>
> Thanks again for the contribution.
> --
>
> https://code.launchpad.net/~kurt-easygo/cloud-init/+git/cloud-init/+merge/363732
> You are the owner of ~kurt-easygo/cloud-init:fix-network-state-dhcp.
>
--
Beste Grüße,

Kurt Stieger
Hinterwaldnerstraße 26/8
A-6020 Innsbruck

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

PASSED: Continuous integration, rev:bde69680d50f0d2fe5c04014ea1527ed7d5b501f
https://jenkins.ubuntu.com/server/job/cloud-init-ci/606/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/606/rebuild

review: Approve (continuous-integration)
Revision history for this message
Kurt Stieger (kurt-easygo) wrote :

> PASSED: Continuous integration, rev:bde69680d50f0d2fe5c04014ea1527ed7d5b501f
> https://jenkins.ubuntu.com/server/job/cloud-init-ci/606/
> Executed test runs:
> SUCCESS: Checkout
> SUCCESS: Unit & Style Tests
> SUCCESS: Ubuntu LTS: Build
> SUCCESS: Ubuntu LTS: Integration
> IN_PROGRESS: Declarative: Post Actions
>
> Click here to trigger a rebuild:
> https://jenkins.ubuntu.com/server/job/cloud-init-ci/606/rebuild

Is there additional work from my side necessary? CI looks fine.

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/cloudinit/net/network_state.py b/cloudinit/net/network_state.py
2index f76e508..539b76d 100644
3--- a/cloudinit/net/network_state.py
4+++ b/cloudinit/net/network_state.py
5@@ -706,9 +706,9 @@ class NetworkStateInterpreter(object):
6 """Common ipconfig extraction from v2 to v1 subnets array."""
7
8 subnets = []
9- if 'dhcp4' in cfg:
10+ if cfg.get('dhcp4'):
11 subnets.append({'type': 'dhcp4'})
12- if 'dhcp6' in cfg:
13+ if cfg.get('dhcp6'):
14 self.use_ipv6 = True
15 subnets.append({'type': 'dhcp6'})
16
17diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
18index f001ae5..e3b9e02 100644
19--- a/tests/unittests/test_net.py
20+++ b/tests/unittests/test_net.py
21@@ -406,6 +406,23 @@ network:
22 - maas
23 """
24
25+NETPLAN_DHCP_FALSE = """
26+version: 2
27+ethernets:
28+ ens3:
29+ match:
30+ macaddress: 52:54:00:ab:cd:ef
31+ dhcp4: false
32+ dhcp6: false
33+ addresses:
34+ - 192.168.42.100/24
35+ - 2001:db8::100/32
36+ gateway4: 192.168.42.1
37+ gateway6: 2001:db8::1
38+ nameservers:
39+ search: [example.com]
40+ addresses: [192.168.42.53, 1.1.1.1]
41+"""
42
43 # Examples (and expected outputs for various renderers).
44 OS_SAMPLES = [
45@@ -2590,6 +2607,50 @@ USERCTL=no
46 config = sysconfig.ConfigObj(nm_cfg)
47 self.assertIn('ifcfg-rh', config['main']['plugins'])
48
49+ def test_netplan_dhcp_false_disable_dhcp_in_state(self):
50+ """netplan config with dhcp[46]: False should not add dhcp in state"""
51+ net_config = yaml.load(NETPLAN_DHCP_FALSE)
52+ ns = network_state.parse_net_config_data(net_config,
53+ skip_broken=False)
54+
55+ dhcp_found = [snet for iface in ns.iter_interfaces()
56+ for snet in iface['subnets'] if 'dhcp' in snet['type']]
57+
58+ self.assertEqual([], dhcp_found)
59+
60+ def test_netplan_dhcp_false_no_dhcp_in_sysconfig(self):
61+ """netplan cfg with dhcp[46]: False should not have bootproto=dhcp"""
62+
63+ entry = {
64+ 'yaml': NETPLAN_DHCP_FALSE,
65+ 'expected_sysconfig': {
66+ 'ifcfg-ens3': textwrap.dedent("""\
67+ BOOTPROTO=none
68+ DEFROUTE=yes
69+ DEVICE=ens3
70+ DNS1=192.168.42.53
71+ DNS2=1.1.1.1
72+ DOMAIN=example.com
73+ GATEWAY=192.168.42.1
74+ HWADDR=52:54:00:ab:cd:ef
75+ IPADDR=192.168.42.100
76+ IPV6ADDR=2001:db8::100/32
77+ IPV6INIT=yes
78+ IPV6_DEFAULTGW=2001:db8::1
79+ NETMASK=255.255.255.0
80+ NM_CONTROLLED=no
81+ ONBOOT=yes
82+ STARTMODE=auto
83+ TYPE=Ethernet
84+ USERCTL=no
85+ """),
86+ }
87+ }
88+
89+ found = self._render_and_read(network_config=yaml.load(entry['yaml']))
90+ self._compare_files_to_expected(entry['expected_sysconfig'], found)
91+ self._assert_headers(found)
92+
93
94 class TestOpenSuseSysConfigRendering(CiTestCase):
95

Subscribers

People subscribed via source and target branches