Skip to content

Commit 9d73879

Browse files
Ian Southamwilderrodrigues
authored andcommitted
Fixed test (assert in guest check was wrong way around)
Also found condition inw hich apache would be miscobfigured and failed to run (I love tests!!) Fixed configure.py to cover this case Added a test to provoke this case!
1 parent d2e3b23 commit 9d73879

2 files changed

Lines changed: 49 additions & 6 deletions

File tree

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def find(self):
246246
class CsApp:
247247
def __init__(self, ip):
248248
self.dev = ip.getDevice()
249-
self.ip = ip.getAddress()['public_ip']
249+
self.ip = ip.get_ip_address()
250250
self.domain = "domain.local"
251251
self.type = ip.get_type()
252252
if self.type == "guest":
@@ -272,6 +272,13 @@ def setup(self):
272272
class CsApache(CsApp):
273273
""" Set up Apache """
274274

275+
def remove(self):
276+
file = "/etc/apache2/conf.d/vhost%s.conf" % self.dev
277+
if os.path.isfile(file):
278+
os.remove(file)
279+
CsHelper().service("apache2", "restart")
280+
281+
275282
def setup(self):
276283
CsHelper().copy_if_needed("/etc/apache2/vhostexample.conf",
277284
"/etc/apache2/conf.d/vhost%s.conf" % self.dev)
@@ -547,6 +554,15 @@ def get_type(self):
547554
return self.address['nw_type']
548555
return "unknown"
549556

557+
def get_ip_address(self):
558+
"""
559+
Return ip address if known
560+
"""
561+
if "public_ip" in self.address:
562+
return self.address['public_ip']
563+
return "unknown"
564+
565+
550566
def post_config_change(self, method):
551567
route = CsRoute(self.dev)
552568
route.routeTable()
@@ -598,10 +614,21 @@ def arpPing(self):
598614

599615
# Delete any ips that are configured but not in the bag
600616
def compare(self, bag):
601-
if len(self.iplist) > 0 and not self.dev in bag.keys():
617+
if len(self.iplist) > 0 and (not self.dev in bag.keys() or len(bag[self.dev]) == 0):
618+
print "Gets here"
602619
# Remove all IPs on this device
603620
logging.info("Will remove all configured addresses on device %s", self.dev)
604621
self.delete("all")
622+
app = CsApache(self)
623+
app.remove()
624+
625+
# This condition should not really happen but did :)
626+
# It means an apache file got orphaned after a guest network address was deleted
627+
if len(self.iplist) == 0 and (not self.dev in bag.keys() or len(bag[self.dev]) == 0):
628+
print self.dev
629+
app = CsApache(self)
630+
app.remove()
631+
605632
for ip in self.iplist:
606633
found = False
607634
if self.dev in bag.keys():

test/systemvm/test_update_config.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,33 @@ def test_create_guest_network(self):
135135
"domain_name":"devcloud.local",
136136
"type":"guestnetwork"
137137
}
138+
self.guest_network(config)
139+
config = { "add":True,
140+
"mac_address":"02:00:56:36:00:02",
141+
"device":"eth4",
142+
"router_guest_ip":"172.16.2.1",
143+
"router_guest_gateway":"172.16.2.0",
144+
"router_guest_netmask":"255.255.255.0",
145+
"cidr":"24",
146+
"dns":"8.8.8.8,8.8.8.4",
147+
"domain_name":"devcloud2.local",
148+
"type":"guestnetwork"
149+
}
150+
self.guest_network(config)
151+
152+
def guest_network(self,config):
138153
self.update_config(config)
139-
assert ip.has_ip("172.16.1.1/24", "eth4")
140-
assert process.is_up("apache2") is True
141-
assert process.is_up("dnsmasq") is True
154+
assert ip.has_ip("%s/%s" % (config['router_guest_ip'], config['cidr']), config['device'])
155+
assert process.is_up("apache2"), "Apache2 should be running after adding a guest network"
156+
assert process.is_up("dnsmasq"), "Dnsmasq should be running after adding a guest network"
142157
assert port.is_listening(80)
143158
assert port.is_listening(53)
144159
assert port.is_listening(53)
145160
assert port.is_listening(67)
146161
config['add'] = False
147162
self.update_config(config)
148-
assert ip.has_ip("172.16.1.1/24", "eth4") is False
163+
assert not ip.has_ip("%s/%s" % (config['router_guest_ip'], config['cidr']), config['device'])
164+
149165

150166
if __name__ == '__main__':
151167
import unittest

0 commit comments

Comments
 (0)