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
diff --git a/cloudinit/net/network_state.py b/cloudinit/net/network_state.py
index f76e508..539b76d 100644
--- a/cloudinit/net/network_state.py
+++ b/cloudinit/net/network_state.py
@@ -706,9 +706,9 @@ class NetworkStateInterpreter(object):
706 """Common ipconfig extraction from v2 to v1 subnets array."""706 """Common ipconfig extraction from v2 to v1 subnets array."""
707707
708 subnets = []708 subnets = []
709 if 'dhcp4' in cfg:709 if cfg.get('dhcp4'):
710 subnets.append({'type': 'dhcp4'})710 subnets.append({'type': 'dhcp4'})
711 if 'dhcp6' in cfg:711 if cfg.get('dhcp6'):
712 self.use_ipv6 = True712 self.use_ipv6 = True
713 subnets.append({'type': 'dhcp6'})713 subnets.append({'type': 'dhcp6'})
714714
diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
index f001ae5..e3b9e02 100644
--- a/tests/unittests/test_net.py
+++ b/tests/unittests/test_net.py
@@ -406,6 +406,23 @@ network:
406 - maas406 - maas
407"""407"""
408408
409NETPLAN_DHCP_FALSE = """
410version: 2
411ethernets:
412 ens3:
413 match:
414 macaddress: 52:54:00:ab:cd:ef
415 dhcp4: false
416 dhcp6: false
417 addresses:
418 - 192.168.42.100/24
419 - 2001:db8::100/32
420 gateway4: 192.168.42.1
421 gateway6: 2001:db8::1
422 nameservers:
423 search: [example.com]
424 addresses: [192.168.42.53, 1.1.1.1]
425"""
409426
410# Examples (and expected outputs for various renderers).427# Examples (and expected outputs for various renderers).
411OS_SAMPLES = [428OS_SAMPLES = [
@@ -2590,6 +2607,50 @@ USERCTL=no
2590 config = sysconfig.ConfigObj(nm_cfg)2607 config = sysconfig.ConfigObj(nm_cfg)
2591 self.assertIn('ifcfg-rh', config['main']['plugins'])2608 self.assertIn('ifcfg-rh', config['main']['plugins'])
25922609
2610 def test_netplan_dhcp_false_disable_dhcp_in_state(self):
2611 """netplan config with dhcp[46]: False should not add dhcp in state"""
2612 net_config = yaml.load(NETPLAN_DHCP_FALSE)
2613 ns = network_state.parse_net_config_data(net_config,
2614 skip_broken=False)
2615
2616 dhcp_found = [snet for iface in ns.iter_interfaces()
2617 for snet in iface['subnets'] if 'dhcp' in snet['type']]
2618
2619 self.assertEqual([], dhcp_found)
2620
2621 def test_netplan_dhcp_false_no_dhcp_in_sysconfig(self):
2622 """netplan cfg with dhcp[46]: False should not have bootproto=dhcp"""
2623
2624 entry = {
2625 'yaml': NETPLAN_DHCP_FALSE,
2626 'expected_sysconfig': {
2627 'ifcfg-ens3': textwrap.dedent("""\
2628 BOOTPROTO=none
2629 DEFROUTE=yes
2630 DEVICE=ens3
2631 DNS1=192.168.42.53
2632 DNS2=1.1.1.1
2633 DOMAIN=example.com
2634 GATEWAY=192.168.42.1
2635 HWADDR=52:54:00:ab:cd:ef
2636 IPADDR=192.168.42.100
2637 IPV6ADDR=2001:db8::100/32
2638 IPV6INIT=yes
2639 IPV6_DEFAULTGW=2001:db8::1
2640 NETMASK=255.255.255.0
2641 NM_CONTROLLED=no
2642 ONBOOT=yes
2643 STARTMODE=auto
2644 TYPE=Ethernet
2645 USERCTL=no
2646 """),
2647 }
2648 }
2649
2650 found = self._render_and_read(network_config=yaml.load(entry['yaml']))
2651 self._compare_files_to_expected(entry['expected_sysconfig'], found)
2652 self._assert_headers(found)
2653
25932654
2594class TestOpenSuseSysConfigRendering(CiTestCase):2655class TestOpenSuseSysConfigRendering(CiTestCase):
25952656

Subscribers

People subscribed via source and target branches