Merge ~pengpengs/cloud-init:fix/vmware-gosc-fail-with-staticIP-and-no-gateway into cloud-init:master

Proposed by Pengpeng Sun
Status: Merged
Approved by: Scott Moser
Approved revision: efc50d39435f46af475899b954ee263bfde0c315
Merge reported by: Server Team CI bot
Merged at revision: not available
Proposed branch: ~pengpengs/cloud-init:fix/vmware-gosc-fail-with-staticIP-and-no-gateway
Merge into: cloud-init:master
Diff against target: 149 lines (+116/-1)
2 files modified
cloudinit/sources/helpers/vmware/imc/config_nic.py (+1/-1)
tests/unittests/test_vmware_config_file.py (+115/-0)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Approve
Scott Moser Approve
Review via email: mp+353303@code.launchpad.net

Commit message

VMWare: Fix a network config bug in vm with static IPv4 and no gateway.

The issue is when customize a VM with static IPv4 and without gateway, it
will still extend route list and will loop a gateways list which is None.
This fix is to make sure when no gateway is here, it will not extend route
list.

LP: #1766538

To post a comment you must log in.
Revision history for this message
Scott Moser (smoser) wrote :

Pengpeng,

This looks good, thank you.

I put together at test that shows failure.

Could you please incorporate it into your merge proposal?

I hope that it adds a fairly easy way to test the conversion.
You do not *have* to add any additional tests, but anything you
wanted to add would be greately appreciated.

Then I think we can get this merged.

Thanks.

Revision history for this message
Pengpeng Sun (pengpengs) wrote :

Hi Scott,

Thanks for your quick reply.
As you might know, this is the first time I submit code change to cloud-init. What's the test failure you mentioned? I just ran 'tox' after code change locally, any other testing needed?

Thanks,
pengpeng

Revision history for this message
Scott Moser (smoser) wrote :

PengPeng,
I'm for being confusing. I apparently failed to put a link to a pastebin.

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

The test that I added there 'test_primary_nic_without_gateway' demonstrates the failure that you have fixed.

Revision history for this message
Pengpeng Sun (pengpengs) wrote :

Scott,

Thanks for adding the test, I read it in pastebin. Now I know how to add a test according to code change.
One thing, my fix is to address failure when non primary nic without gateway, I'm writing tests but get 'pycodestyle: commands failed' when run tox, I will try to fix it and amend my commit.

Thanks,
Pengpeng

82646d6... by Pengpeng Sun

Merge branch 'fix/vmware-gosc-fail-with-staticIP-and-no-gateway' of ssh://git.launchpad.net/~pengpengs/cloud-init into fix/vmware-gosc-fail-with-staticIP-and-no-gateway

14b0155... by Pengpeng Sun

Merge branch 'fix/vmware-gosc-fail-with-staticIP-and-no-gateway' of ssh://git.launchpad.net/~pengpengs/cloud-init into fix/vmware-gosc-fail-with-staticIP-and-no-gateway

Revision history for this message
Pengpeng Sun (pengpengs) wrote :

Scott,
Please help to double-check my merge request, from the latest Diff I can see the test has been added.
tox gave me 'congratulations :)'.

But I pushed twice, one to ssh://git.launchpad.net/~pengpengs/cloud-init fix/vmware-gosc-fail-with-staticIP-and-no-gateway, the second to fix/vmware-gosc-fail-with-staticIP-and-no-gateway.
What's the right way to update this merge?

anyway, please let me know if there are any changes needed.

Thanks,
Pengpeng

Revision history for this message
Scott Moser (smoser) wrote :

Hi,

Thanks. This looks great.
The way you pushed is fine. Generally, launchpad will figure things out and it did correctly here.

One other thing I would like to see is adding a "negative" test for this path.

Add a test named "test_non_primary_nic_with_gateway", and just adjust the config and result as they should be.

Then we'll make sure that we don't accidently break the common case where we *do* have a gateway.

Thanks.
Scott

review: Approve
Revision history for this message
Scott Moser (smoser) wrote :

I accidently hit 'Approve', but meant to hit 'needs fixing'.

Please add the test, and *then* i will approve.

Thanks for your patience, and contributions to cloud-init.

review: Needs Fixing
efc50d3... by Pengpeng Sun

Merge branch 'fix/vmware-gosc-fail-with-staticIP-and-no-gateway' of ssh://git.launchpad.net/~pengpengs/cloud-init into fix/vmware-gosc-fail-with-staticIP-and-no-gateway

Revision history for this message
Pengpeng Sun (pengpengs) wrote :

Hi Scott,

I added 2 more tests "test_non_primary_nic_with_gateway" and "test_a_primary_nic_with_gateway".
The first one is to test a *non* primary nic have a gateway, the second one is to test a primary nic have a gateway. Please help to review them.
tox gave me all pass.
Thanks again for your help on test.

Best regards,
Pengpeng

Revision history for this message
Scott Moser (smoser) :
review: Approve
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/sources/helpers/vmware/imc/config_nic.py b/cloudinit/sources/helpers/vmware/imc/config_nic.py
2index 3ef8c62..e1890e2 100644
3--- a/cloudinit/sources/helpers/vmware/imc/config_nic.py
4+++ b/cloudinit/sources/helpers/vmware/imc/config_nic.py
5@@ -164,7 +164,7 @@ class NicConfigurator(object):
6 return ([subnet], route_list)
7
8 # Add routes if there is no primary nic
9- if not self._primaryNic:
10+ if not self._primaryNic and v4.gateways:
11 route_list.extend(self.gen_ipv4_route(nic,
12 v4.gateways,
13 v4.netmask))
14diff --git a/tests/unittests/test_vmware_config_file.py b/tests/unittests/test_vmware_config_file.py
15index 036f687..602dedb 100644
16--- a/tests/unittests/test_vmware_config_file.py
17+++ b/tests/unittests/test_vmware_config_file.py
18@@ -2,11 +2,15 @@
19 # Copyright (C) 2016 VMware INC.
20 #
21 # Author: Sankar Tanguturi <stanguturi@vmware.com>
22+# Pengpeng Sun <pengpengs@vmware.com>
23 #
24 # This file is part of cloud-init. See LICENSE file for license information.
25
26 import logging
27+import os
28 import sys
29+import tempfile
30+import textwrap
31
32 from cloudinit.sources.DataSourceOVF import get_network_config_from_conf
33 from cloudinit.sources.DataSourceOVF import read_vmware_imc
34@@ -343,4 +347,115 @@ class TestVmwareConfigFile(CiTestCase):
35 conf = Config(cf)
36 self.assertEqual("test-script", conf.custom_script_name)
37
38+
39+class TestVmwareNetConfig(CiTestCase):
40+ """Test conversion of vmware config to cloud-init config."""
41+
42+ def _get_NicConfigurator(self, text):
43+ fp = None
44+ try:
45+ with tempfile.NamedTemporaryFile(mode="w", dir=self.tmp_dir(),
46+ delete=False) as fp:
47+ fp.write(text)
48+ fp.close()
49+ cfg = Config(ConfigFile(fp.name))
50+ return NicConfigurator(cfg.nics, use_system_devices=False)
51+ finally:
52+ if fp:
53+ os.unlink(fp.name)
54+
55+ def test_non_primary_nic_without_gateway(self):
56+ """A non primary nic set is not required to have a gateway."""
57+ config = textwrap.dedent("""\
58+ [NETWORK]
59+ NETWORKING = yes
60+ BOOTPROTO = dhcp
61+ HOSTNAME = myhost1
62+ DOMAINNAME = eng.vmware.com
63+
64+ [NIC-CONFIG]
65+ NICS = NIC1
66+
67+ [NIC1]
68+ MACADDR = 00:50:56:a6:8c:08
69+ ONBOOT = yes
70+ IPv4_MODE = BACKWARDS_COMPATIBLE
71+ BOOTPROTO = static
72+ IPADDR = 10.20.87.154
73+ NETMASK = 255.255.252.0
74+ """)
75+ nc = self._get_NicConfigurator(config)
76+ self.assertEqual(
77+ [{'type': 'physical', 'name': 'NIC1',
78+ 'mac_address': '00:50:56:a6:8c:08',
79+ 'subnets': [
80+ {'control': 'auto', 'type': 'static',
81+ 'address': '10.20.87.154', 'netmask': '255.255.252.0'}]}],
82+ nc.generate())
83+
84+ def test_non_primary_nic_with_gateway(self):
85+ """A non primary nic set can have a gateway."""
86+ config = textwrap.dedent("""\
87+ [NETWORK]
88+ NETWORKING = yes
89+ BOOTPROTO = dhcp
90+ HOSTNAME = myhost1
91+ DOMAINNAME = eng.vmware.com
92+
93+ [NIC-CONFIG]
94+ NICS = NIC1
95+
96+ [NIC1]
97+ MACADDR = 00:50:56:a6:8c:08
98+ ONBOOT = yes
99+ IPv4_MODE = BACKWARDS_COMPATIBLE
100+ BOOTPROTO = static
101+ IPADDR = 10.20.87.154
102+ NETMASK = 255.255.252.0
103+ GATEWAY = 10.20.87.253
104+ """)
105+ nc = self._get_NicConfigurator(config)
106+ self.assertEqual(
107+ [{'type': 'physical', 'name': 'NIC1',
108+ 'mac_address': '00:50:56:a6:8c:08',
109+ 'subnets': [
110+ {'control': 'auto', 'type': 'static',
111+ 'address': '10.20.87.154', 'netmask': '255.255.252.0'}]},
112+ {'type': 'route', 'destination': '10.20.84.0/22',
113+ 'gateway': '10.20.87.253', 'metric': 10000}],
114+ nc.generate())
115+
116+ def test_a_primary_nic_with_gateway(self):
117+ """A primary nic set can have a gateway."""
118+ config = textwrap.dedent("""\
119+ [NETWORK]
120+ NETWORKING = yes
121+ BOOTPROTO = dhcp
122+ HOSTNAME = myhost1
123+ DOMAINNAME = eng.vmware.com
124+
125+ [NIC-CONFIG]
126+ NICS = NIC1
127+
128+ [NIC1]
129+ MACADDR = 00:50:56:a6:8c:08
130+ ONBOOT = yes
131+ IPv4_MODE = BACKWARDS_COMPATIBLE
132+ BOOTPROTO = static
133+ IPADDR = 10.20.87.154
134+ NETMASK = 255.255.252.0
135+ PRIMARY = true
136+ GATEWAY = 10.20.87.253
137+ """)
138+ nc = self._get_NicConfigurator(config)
139+ self.assertEqual(
140+ [{'type': 'physical', 'name': 'NIC1',
141+ 'mac_address': '00:50:56:a6:8c:08',
142+ 'subnets': [
143+ {'control': 'auto', 'type': 'static',
144+ 'address': '10.20.87.154', 'netmask': '255.255.252.0',
145+ 'gateway': '10.20.87.253'}]}],
146+ nc.generate())
147+
148+
149 # vi: ts=4 expandtab

Subscribers

People subscribed via source and target branches