Skip to content

Commit ca2ff29

Browse files
Ian Southamwilderrodrigues
authored andcommitted
Added some tests that test stuff
Specifically checking whether certain ip addresses get added and deleted Also a rudementary test for the guest network ip Much more to do!!
1 parent 92aca76 commit ca2ff29

File tree

4 files changed

+55
-11
lines changed

4 files changed

+55
-11
lines changed

systemvm/patches/debian/config/opt/cloud/bin/configure.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,8 @@ def __init__(self, device):
339339
for dev in dbag:
340340
if dev == "id":
341341
continue
342+
if len(dbag[dev]) == 0:
343+
continue
342344
if dev == device:
343345
self.data = dbag[dev][0]
344346

systemvm/patches/debian/config/opt/cloud/bin/cs_guestnetwork.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ def merge(dbag, gn):
55
for dev in dbag:
66
if dev == "id":
77
continue
8+
if len(dbag[dev]) == 0:
9+
continue
810
if dbag[dev][0]['device'] == gn['device']:
911
dbag[dev].remove(dbag[dev][0])
1012
if gn['add']:
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{"add":true,
2+
"mac_address":"02:00:56:36:00:02",
3+
"device":"eth3",
4+
"router_guest_ip":"172.16.1.1",
5+
"router_guest_gateway":"172.16.1.0",
6+
"router_guest_netmask":"255.255.255.0",
7+
"cidr":"24",
8+
"dns":"8.8.8.8,8.8.8.4",
9+
"domain_name":"devcloud.local",
10+
"type":"guestnetwork"}

test/systemvm/test_update_config.py

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import json
2424
import random
2525
import datetime
26+
from envassert import file, process, package, user, group, port, cron, detect, ip
27+
import copy
2628

2729
try:
2830
from . import SystemVMTestCase, has_line, print_doc
@@ -47,7 +49,8 @@ class UpdateConfigTestCase(SystemVMTestCase):
4749
"netmask": "255.255.255.0",
4850
"vif_mac_address": "06:cb:aa:00:00:03",
4951
"nic_dev_id": 1,
50-
"new_nic": False
52+
"new_nic": False,
53+
"nw_type": "public"
5154
}
5255
],
5356
"type": "ips"
@@ -60,7 +63,6 @@ def update_config(self, config):
6063
with hide("everything"):
6164
result = run("python /opt/cloud/bin/update_config.py update_config_test.json",
6265
timeout=600, warn_only=True)
63-
print result
6466
assert result.succeeded, 'update_config.py ran without errors'
6567
assert result.find("Convergence is achieved") >= 0, 'update_config.py should report convergence'
6668

@@ -90,30 +92,58 @@ def test_basic_config(self):
9092

9193
@attr(tags=["systemvm"], required_hardware="true")
9294
def test_various_random_ip_addresses(self):
95+
buffer = []
9396
r = random.Random()
9497
r.seed()
9598
for i in range(0, 10):
99+
ip_address = {}
96100
# todo need to know what kind of configurations are valid!
97101
config = deep_copy(self.basic_config)
98102
ip_address = deep_copy(self.basic_config["ip_address"][0])
99-
ip_address["public_ip"] = "10.0.2.%d" % (i + 103,)
103+
ip_address["public_ip"] = "10.0.2.%d" % (i + 103)
100104
ip_address["source_nat"] = r.choice((True, False))
101-
ip_address["add"] = r.choice((True, False))
105+
ip_address["add"] = True
102106
ip_address["one_to_one_nat"] = r.choice((True, False))
103107
ip_address["first_i_p"] = r.choice((True, False))
104-
ip_address["nic_dev_id"] = r.choice((2, 3))
105-
if ip_address["nic_dev_id"] > 0:
106-
ip_address["new_nic"] = True
107-
else:
108-
ip_address["new_nic"] = False
108+
ip_address["nic_dev_id"] = 3
109109
config["ip_address"].append(ip_address)
110110
# runs a bunch of times adding an IP address each time
111111
self.update_config(config)
112+
ip_address["add"] = False
113+
buffer.append(copy.deepcopy(ip_address))
112114
self.check_no_errors()
113115
self.clear_log()
114-
# run again with just the basic config; this should remove the IP addresses?
115-
self.update_config(self.basic_config)
116+
assert ip.has_ip("%s/24" % ip_address["public_ip"], "eth%s" % ip_address["nic_dev_id"])
117+
# Now delete all the IPs we just made
118+
for ips in buffer:
119+
config = copy.deepcopy(self.basic_config)
120+
config["ip_address"].append(ips)
121+
self.update_config(config)
122+
assert ip.has_ip("%s/24" % ips["public_ip"], "eth%s" % ips["nic_dev_id"]) is False
116123

124+
def test_create_guest_network(self):
125+
config = { "add":True,
126+
"mac_address":"02:00:56:36:00:02",
127+
"device":"eth4",
128+
"router_guest_ip":"172.16.1.1",
129+
"router_guest_gateway":"172.16.1.0",
130+
"router_guest_netmask":"255.255.255.0",
131+
"cidr":"24",
132+
"dns":"8.8.8.8,8.8.8.4",
133+
"domain_name":"devcloud.local",
134+
"type":"guestnetwork"
135+
}
136+
self.update_config(config)
137+
assert ip.has_ip("172.16.1.1/24", "eth4")
138+
assert process.is_up("apache2") is True
139+
assert process.is_up("dnsmasq") is True
140+
assert port.is_listening(80)
141+
assert port.is_listening(53)
142+
assert port.is_listening(53)
143+
assert port.is_listening(67)
144+
config['add'] = False
145+
self.update_config(config)
146+
assert ip.has_ip("172.16.1.1/24", "eth4") is False
117147

118148
if __name__ == '__main__':
119149
import unittest

0 commit comments

Comments
 (0)