3
# Copyright (C) 2015 Canonical Ltd.
4
# Copyright (C) 2016 VMware INC.
6
# Author: Sankar Tanguturi <stanguturi@vmware.com>
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.
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.
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/>.
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
28
logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)
29
logger = logging.getLogger(__name__)
32
class TestVmwareConfigFile(unittest.TestCase):
34
def test_utility_methods(self):
35
cf = ConfigFile("tests/data/vmware/cust-dhcp-2nic.cfg")
39
self.assertEqual(0, len(cf), "clear size")
41
cf._insertKey(" PASSWORD|-PASS ", " foo ")
42
cf._insertKey("BAR", " ")
44
self.assertEqual(2, len(cf), "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"),
49
self.assertFalse(cf.should_remove_current_value("PASSWORD|-PASS"),
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")
58
def test_configfile_static_2nics(self):
59
cf = ConfigFile("tests/data/vmware/cust-static-2nic.cfg")
63
self.assertEqual('myhost1', conf.host_name, "hostName")
64
self.assertEqual('Africa/Abidjan', conf.timezone, "tz")
65
self.assertTrue(conf.utc, "utc")
67
self.assertEqual(['10.20.145.1', '10.20.145.2'],
70
self.assertEqual(['eng.vmware.com', 'proxy.vmware.com'],
75
ipv40 = nics[0].staticIpv4
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")
87
self.assertEqual(1, len(nics[0].staticIpv6), "ipv6Cnt0")
88
self.assertEqual('fc00:10:20:87::154',
89
nics[0].staticIpv6[0].ip,
92
self.assertEqual('NIC2', nics[1].name, "nic1")
93
self.assertTrue(not nics[1].staticIpv6, "ipv61 dhcp")
95
def test_config_file_dhcp_2nics(self):
96
cf = ConfigFile("tests/data/vmware/cust-dhcp-2nic.cfg")
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")