From 9d73879061363327b4a5c7ace10c53d81fc041f1 Mon Sep 17 00:00:00 2001 From: Ian Southam Date: Tue, 12 Aug 2014 16:16:07 +0200 Subject: [PATCH] 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! --- .../debian/config/opt/cloud/bin/configure.py | 31 +++++++++++++++++-- test/systemvm/test_update_config.py | 24 +++++++++++--- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/systemvm/patches/debian/config/opt/cloud/bin/configure.py b/systemvm/patches/debian/config/opt/cloud/bin/configure.py index e4c23e57a88..f7b14081d71 100755 --- a/systemvm/patches/debian/config/opt/cloud/bin/configure.py +++ b/systemvm/patches/debian/config/opt/cloud/bin/configure.py @@ -246,7 +246,7 @@ class CsProcess(object): class CsApp: def __init__(self, ip): self.dev = ip.getDevice() - self.ip = ip.getAddress()['public_ip'] + self.ip = ip.get_ip_address() self.domain = "domain.local" self.type = ip.get_type() if self.type == "guest": @@ -272,6 +272,13 @@ class CsPasswdSvc(CsApp): class CsApache(CsApp): """ Set up Apache """ + def remove(self): + file = "/etc/apache2/conf.d/vhost%s.conf" % self.dev + if os.path.isfile(file): + os.remove(file) + CsHelper().service("apache2", "restart") + + def setup(self): CsHelper().copy_if_needed("/etc/apache2/vhostexample.conf", "/etc/apache2/conf.d/vhost%s.conf" % self.dev) @@ -547,6 +554,15 @@ class CsIP: return self.address['nw_type'] return "unknown" + def get_ip_address(self): + """ + Return ip address if known + """ + if "public_ip" in self.address: + return self.address['public_ip'] + return "unknown" + + def post_config_change(self, method): route = CsRoute(self.dev) route.routeTable() @@ -598,10 +614,21 @@ class CsIP: # Delete any ips that are configured but not in the bag def compare(self, bag): - if len(self.iplist) > 0 and not self.dev in bag.keys(): + if len(self.iplist) > 0 and (not self.dev in bag.keys() or len(bag[self.dev]) == 0): + print "Gets here" # Remove all IPs on this device logging.info("Will remove all configured addresses on device %s", self.dev) self.delete("all") + app = CsApache(self) + app.remove() + + # This condition should not really happen but did :) + # It means an apache file got orphaned after a guest network address was deleted + if len(self.iplist) == 0 and (not self.dev in bag.keys() or len(bag[self.dev]) == 0): + print self.dev + app = CsApache(self) + app.remove() + for ip in self.iplist: found = False if self.dev in bag.keys(): diff --git a/test/systemvm/test_update_config.py b/test/systemvm/test_update_config.py index b39339433f2..f8c1a6c2464 100644 --- a/test/systemvm/test_update_config.py +++ b/test/systemvm/test_update_config.py @@ -135,17 +135,33 @@ class UpdateConfigTestCase(SystemVMTestCase): "domain_name":"devcloud.local", "type":"guestnetwork" } + self.guest_network(config) + config = { "add":True, + "mac_address":"02:00:56:36:00:02", + "device":"eth4", + "router_guest_ip":"172.16.2.1", + "router_guest_gateway":"172.16.2.0", + "router_guest_netmask":"255.255.255.0", + "cidr":"24", + "dns":"8.8.8.8,8.8.8.4", + "domain_name":"devcloud2.local", + "type":"guestnetwork" + } + self.guest_network(config) + + def guest_network(self,config): self.update_config(config) - assert ip.has_ip("172.16.1.1/24", "eth4") - assert process.is_up("apache2") is True - assert process.is_up("dnsmasq") is True + assert ip.has_ip("%s/%s" % (config['router_guest_ip'], config['cidr']), config['device']) + assert process.is_up("apache2"), "Apache2 should be running after adding a guest network" + assert process.is_up("dnsmasq"), "Dnsmasq should be running after adding a guest network" assert port.is_listening(80) assert port.is_listening(53) assert port.is_listening(53) assert port.is_listening(67) config['add'] = False self.update_config(config) - assert ip.has_ip("172.16.1.1/24", "eth4") is False + assert not ip.has_ip("%s/%s" % (config['router_guest_ip'], config['cidr']), config['device']) + if __name__ == '__main__': import unittest