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
diff --git a/cloudinit/sources/helpers/vmware/imc/config_nic.py b/cloudinit/sources/helpers/vmware/imc/config_nic.py
index 3ef8c62..e1890e2 100644
--- a/cloudinit/sources/helpers/vmware/imc/config_nic.py
+++ b/cloudinit/sources/helpers/vmware/imc/config_nic.py
@@ -164,7 +164,7 @@ class NicConfigurator(object):
164 return ([subnet], route_list)164 return ([subnet], route_list)
165165
166 # Add routes if there is no primary nic166 # Add routes if there is no primary nic
167 if not self._primaryNic:167 if not self._primaryNic and v4.gateways:
168 route_list.extend(self.gen_ipv4_route(nic,168 route_list.extend(self.gen_ipv4_route(nic,
169 v4.gateways,169 v4.gateways,
170 v4.netmask))170 v4.netmask))
diff --git a/tests/unittests/test_vmware_config_file.py b/tests/unittests/test_vmware_config_file.py
index 036f687..602dedb 100644
--- a/tests/unittests/test_vmware_config_file.py
+++ b/tests/unittests/test_vmware_config_file.py
@@ -2,11 +2,15 @@
2# Copyright (C) 2016 VMware INC.2# Copyright (C) 2016 VMware INC.
3#3#
4# Author: Sankar Tanguturi <stanguturi@vmware.com>4# Author: Sankar Tanguturi <stanguturi@vmware.com>
5# Pengpeng Sun <pengpengs@vmware.com>
5#6#
6# This file is part of cloud-init. See LICENSE file for license information.7# This file is part of cloud-init. See LICENSE file for license information.
78
8import logging9import logging
10import os
9import sys11import sys
12import tempfile
13import textwrap
1014
11from cloudinit.sources.DataSourceOVF import get_network_config_from_conf15from cloudinit.sources.DataSourceOVF import get_network_config_from_conf
12from cloudinit.sources.DataSourceOVF import read_vmware_imc16from cloudinit.sources.DataSourceOVF import read_vmware_imc
@@ -343,4 +347,115 @@ class TestVmwareConfigFile(CiTestCase):
343 conf = Config(cf)347 conf = Config(cf)
344 self.assertEqual("test-script", conf.custom_script_name)348 self.assertEqual("test-script", conf.custom_script_name)
345349
350
351class TestVmwareNetConfig(CiTestCase):
352 """Test conversion of vmware config to cloud-init config."""
353
354 def _get_NicConfigurator(self, text):
355 fp = None
356 try:
357 with tempfile.NamedTemporaryFile(mode="w", dir=self.tmp_dir(),
358 delete=False) as fp:
359 fp.write(text)
360 fp.close()
361 cfg = Config(ConfigFile(fp.name))
362 return NicConfigurator(cfg.nics, use_system_devices=False)
363 finally:
364 if fp:
365 os.unlink(fp.name)
366
367 def test_non_primary_nic_without_gateway(self):
368 """A non primary nic set is not required to have a gateway."""
369 config = textwrap.dedent("""\
370 [NETWORK]
371 NETWORKING = yes
372 BOOTPROTO = dhcp
373 HOSTNAME = myhost1
374 DOMAINNAME = eng.vmware.com
375
376 [NIC-CONFIG]
377 NICS = NIC1
378
379 [NIC1]
380 MACADDR = 00:50:56:a6:8c:08
381 ONBOOT = yes
382 IPv4_MODE = BACKWARDS_COMPATIBLE
383 BOOTPROTO = static
384 IPADDR = 10.20.87.154
385 NETMASK = 255.255.252.0
386 """)
387 nc = self._get_NicConfigurator(config)
388 self.assertEqual(
389 [{'type': 'physical', 'name': 'NIC1',
390 'mac_address': '00:50:56:a6:8c:08',
391 'subnets': [
392 {'control': 'auto', 'type': 'static',
393 'address': '10.20.87.154', 'netmask': '255.255.252.0'}]}],
394 nc.generate())
395
396 def test_non_primary_nic_with_gateway(self):
397 """A non primary nic set can have a gateway."""
398 config = textwrap.dedent("""\
399 [NETWORK]
400 NETWORKING = yes
401 BOOTPROTO = dhcp
402 HOSTNAME = myhost1
403 DOMAINNAME = eng.vmware.com
404
405 [NIC-CONFIG]
406 NICS = NIC1
407
408 [NIC1]
409 MACADDR = 00:50:56:a6:8c:08
410 ONBOOT = yes
411 IPv4_MODE = BACKWARDS_COMPATIBLE
412 BOOTPROTO = static
413 IPADDR = 10.20.87.154
414 NETMASK = 255.255.252.0
415 GATEWAY = 10.20.87.253
416 """)
417 nc = self._get_NicConfigurator(config)
418 self.assertEqual(
419 [{'type': 'physical', 'name': 'NIC1',
420 'mac_address': '00:50:56:a6:8c:08',
421 'subnets': [
422 {'control': 'auto', 'type': 'static',
423 'address': '10.20.87.154', 'netmask': '255.255.252.0'}]},
424 {'type': 'route', 'destination': '10.20.84.0/22',
425 'gateway': '10.20.87.253', 'metric': 10000}],
426 nc.generate())
427
428 def test_a_primary_nic_with_gateway(self):
429 """A primary nic set can have a gateway."""
430 config = textwrap.dedent("""\
431 [NETWORK]
432 NETWORKING = yes
433 BOOTPROTO = dhcp
434 HOSTNAME = myhost1
435 DOMAINNAME = eng.vmware.com
436
437 [NIC-CONFIG]
438 NICS = NIC1
439
440 [NIC1]
441 MACADDR = 00:50:56:a6:8c:08
442 ONBOOT = yes
443 IPv4_MODE = BACKWARDS_COMPATIBLE
444 BOOTPROTO = static
445 IPADDR = 10.20.87.154
446 NETMASK = 255.255.252.0
447 PRIMARY = true
448 GATEWAY = 10.20.87.253
449 """)
450 nc = self._get_NicConfigurator(config)
451 self.assertEqual(
452 [{'type': 'physical', 'name': 'NIC1',
453 'mac_address': '00:50:56:a6:8c:08',
454 'subnets': [
455 {'control': 'auto', 'type': 'static',
456 'address': '10.20.87.154', 'netmask': '255.255.252.0',
457 'gateway': '10.20.87.253'}]}],
458 nc.generate())
459
460
346# vi: ts=4 expandtab461# vi: ts=4 expandtab

Subscribers

People subscribed via source and target branches