Skip to content

Commit 9ba841e

Browse files
author
Sankar Tanguturi
committed
- Added new Unittests for VMware support.
1 parent 415c45a commit 9ba841e

File tree

3 files changed

+176
-0
lines changed

3 files changed

+176
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[NETWORK]
2+
NETWORKING = yes
3+
BOOTPROTO = dhcp
4+
HOSTNAME = myhost1
5+
DOMAINNAME = eng.vmware.com
6+
7+
[NIC-CONFIG]
8+
NICS = NIC1,NIC2
9+
10+
[NIC1]
11+
MACADDR = 00:50:56:a6:8c:08
12+
ONBOOT = yes
13+
IPv4_MODE = BACKWARDS_COMPATIBLE
14+
BOOTPROTO = dhcp
15+
16+
[NIC2]
17+
MACADDR = 00:50:56:a6:5a:de
18+
ONBOOT = yes
19+
IPv4_MODE = BACKWARDS_COMPATIBLE
20+
BOOTPROTO = dhcp
21+
22+
# some random comment
23+
24+
[PASSWORD]
25+
# secret
26+
-PASS = c2VjcmV0Cg==
27+
28+
[DNS]
29+
DNSFROMDHCP=yes
30+
SUFFIX|1 = eng.vmware.com
31+
32+
[DATETIME]
33+
TIMEZONE = Africa/Abidjan
34+
UTC = yes
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
[NETWORK]
2+
NETWORKING = yes
3+
BOOTPROTO = dhcp
4+
HOSTNAME = myhost1
5+
DOMAINNAME = eng.vmware.com
6+
7+
[NIC-CONFIG]
8+
NICS = NIC1,NIC2
9+
10+
[NIC1]
11+
MACADDR = 00:50:56:a6:8c:08
12+
ONBOOT = yes
13+
IPv4_MODE = BACKWARDS_COMPATIBLE
14+
BOOTPROTO = static
15+
IPADDR = 10.20.87.154
16+
NETMASK = 255.255.252.0
17+
GATEWAY = 10.20.87.253, 10.20.87.105
18+
IPv6ADDR|1 = fc00:10:20:87::154
19+
IPv6NETMASK|1 = 64
20+
IPv6GATEWAY|1 = fc00:10:20:87::253
21+
[NIC2]
22+
MACADDR = 00:50:56:a6:ef:7d
23+
ONBOOT = yes
24+
IPv4_MODE = BACKWARDS_COMPATIBLE
25+
BOOTPROTO = static
26+
IPADDR = 192.168.6.102
27+
NETMASK = 255.255.0.0
28+
GATEWAY = 192.168.0.10
29+
30+
[DNS]
31+
DNSFROMDHCP=no
32+
SUFFIX|1 = eng.vmware.com
33+
SUFFIX|2 = proxy.vmware.com
34+
NAMESERVER|1 = 10.20.145.1
35+
NAMESERVER|2 = 10.20.145.2
36+
37+
[DATETIME]
38+
TIMEZONE = Africa/Abidjan
39+
UTC = yes
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# vi: ts=4 expandtab
2+
#
3+
# Copyright (C) 2015 Canonical Ltd.
4+
# Copyright (C) 2016 VMware INC.
5+
#
6+
# Author: Sankar Tanguturi <stanguturi@vmware.com>
7+
#
8+
# This program is free software: you can redistribute it and/or modify
9+
# it under the terms of the GNU General Public License version 3, as
10+
# published by the Free Software Foundation.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU General Public License
18+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
20+
import logging
21+
import sys
22+
import unittest
23+
24+
from cloudinit.sources.helpers.vmware.imc.boot_proto import BootProtoEnum
25+
from cloudinit.sources.helpers.vmware.imc.config import Config
26+
from cloudinit.sources.helpers.vmware.imc.config_file import ConfigFile
27+
28+
logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)
29+
logger = logging.getLogger(__name__)
30+
31+
32+
class TestVmwareConfigFile(unittest.TestCase):
33+
34+
def test_utility_methods(self):
35+
cf = ConfigFile("tests/data/vmware/cust-dhcp-2nic.cfg")
36+
37+
cf.clear()
38+
39+
self.assertEqual(0, cf.size(), "clear size")
40+
41+
cf._insertKey(" PASSWORD|-PASS ", " foo ")
42+
cf._insertKey("BAR", " ")
43+
44+
self.assertEqual(2, cf.size(), "insert size")
45+
self.assertEqual('foo', cf["PASSWORD|-PASS"], "password")
46+
self.assertTrue("PASSWORD|-PASS" in cf, "hasPassword")
47+
self.assertFalse(cf.should_keep_current_value("PASSWORD|-PASS"),
48+
"keepPassword")
49+
self.assertFalse(cf.should_remove_current_value("PASSWORD|-PASS"),
50+
"removePassword")
51+
self.assertFalse("FOO" in cf, "hasFoo")
52+
self.assertTrue(cf.should_keep_current_value("FOO"), "keepFoo")
53+
self.assertFalse(cf.should_remove_current_value("FOO"), "removeFoo")
54+
self.assertTrue("BAR" in cf, "hasBar")
55+
self.assertFalse(cf.should_keep_current_value("BAR"), "keepBar")
56+
self.assertTrue(cf.should_remove_current_value("BAR"), "removeBar")
57+
58+
def test_configfile_static_2nics(self):
59+
cf = ConfigFile("tests/data/vmware/cust-static-2nic.cfg")
60+
61+
conf = Config(cf)
62+
63+
self.assertEqual('myhost1', conf.host_name, "hostName")
64+
self.assertEqual('Africa/Abidjan', conf.timezone, "tz")
65+
self.assertTrue(conf.utc, "utc")
66+
67+
self.assertEqual(['10.20.145.1', '10.20.145.2'],
68+
conf.name_servers,
69+
"dns")
70+
self.assertEqual(['eng.vmware.com', 'proxy.vmware.com'],
71+
conf.dns_suffixes,
72+
"suffixes")
73+
74+
nics = conf.nics
75+
ipv40 = nics[0].staticIpv4
76+
77+
self.assertEqual(2, len(nics), "nics")
78+
self.assertEqual('NIC1', nics[0].name, "nic0")
79+
self.assertEqual('00:50:56:a6:8c:08', nics[0].mac, "mac0")
80+
self.assertEqual(BootProtoEnum.STATIC, nics[0].bootProto, "bootproto0")
81+
self.assertEqual('10.20.87.154', ipv40[0].ip, "ipv4Addr0")
82+
self.assertEqual('255.255.252.0', ipv40[0].netmask, "ipv4Mask0")
83+
self.assertEqual(2, len(ipv40[0].gateways), "ipv4Gw0")
84+
self.assertEqual('10.20.87.253', ipv40[0].gateways[0], "ipv4Gw0_0")
85+
self.assertEqual('10.20.87.105', ipv40[0].gateways[1], "ipv4Gw0_1")
86+
87+
self.assertEqual(1, len(nics[0].staticIpv6), "ipv6Cnt0")
88+
self.assertEqual('fc00:10:20:87::154',
89+
nics[0].staticIpv6[0].ip,
90+
"ipv6Addr0")
91+
92+
self.assertEqual('NIC2', nics[1].name, "nic1")
93+
self.assertTrue(not nics[1].staticIpv6, "ipv61 dhcp")
94+
95+
def test_config_file_dhcp_2nics(self):
96+
cf = ConfigFile("tests/data/vmware/cust-dhcp-2nic.cfg")
97+
98+
conf = Config(cf)
99+
nics = conf.nics
100+
self.assertEqual(2, len(nics), "nics")
101+
self.assertEqual('NIC1', nics[0].name, "nic0")
102+
self.assertEqual('00:50:56:a6:8c:08', nics[0].mac, "mac0")
103+
self.assertEqual(BootProtoEnum.DHCP, nics[0].bootProto, "bootproto0")

0 commit comments

Comments
 (0)