From b4920aa028e75c64160988113ac268e5ea5ae69e Mon Sep 17 00:00:00 2001 From: Wilder Rodrigues Date: Wed, 14 Oct 2015 14:24:11 +0200 Subject: [PATCH] CLOUDSTACK-8952 - Do not restart conntrackd unless it's needed - With the keepalived fixed they should not be needed anymore. So first reducing them drasticaly - I am now making a backup of the template file, write to the template file and compare it with the existing configuration - The template file is recovered afer the process - I also check if the process is running - I fixed a bug in the compare method - I am now updating the configuration variable once the file content is flushed to disk --- .../debian/config/opt/cloud/bin/cs/CsFile.py | 7 ++++++- .../config/opt/cloud/bin/cs/CsLoadBalancer.py | 8 ++++---- .../debian/config/opt/cloud/bin/cs/CsRedundant.py | 13 +++++++------ test/integration/component/test_vpc_redundant.py | 7 +------ 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsFile.py b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsFile.py index 319b48e2f06..7829c0a99e7 100755 --- a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsFile.py +++ b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsFile.py @@ -64,6 +64,9 @@ class CsFile: handle.write(line) handle.close() logging.info("Wrote edited file %s" % self.filename) + self.config = list(self.new_config) + logging.info("Updated file in-cache configuration") + def dump(self): for line in self.new_config: @@ -160,4 +163,6 @@ class CsFile: def compare(self, o): - return (isinstance(o, self.__class__) and set(self.config) == set(o.new_config)) + result = (isinstance(o, self.__class__) and set(self.config) == set(o.config)) + logging.debug("Comparison of CsFiles content is ==> %s" % result) + return result diff --git a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsLoadBalancer.py b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsLoadBalancer.py index a288eac2c49..76f1ccad0b3 100755 --- a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsLoadBalancer.py +++ b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsLoadBalancer.py @@ -17,7 +17,6 @@ import logging import os.path import re -import shutil from cs.CsDatabag import CsDataBag from CsProcess import CsProcess from CsFile import CsFile @@ -37,13 +36,14 @@ class CsLoadBalancer(CsDataBag): return config = self.dbag['config'][0]['configuration'] file1 = CsFile(HAPROXY_CONF_T) - file2 = CsFile(HAPROXY_CONF_P) file1.empty() for x in config: [file1.append(w, -1) for w in x.split('\n')] + + file1.commit() + file2 = CsFile(HAPROXY_CONF_P) if not file2.compare(file1): - file1.commit() - shutil.copy2(HAPROXY_CONF_T, HAPROXY_CONF_P) + CsHelper.copy(HAPROXY_CONF_T, HAPROXY_CONF_P) proc = CsProcess(['/var/run/haproxy.pid']) if not proc.find(): diff --git a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsRedundant.py b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsRedundant.py index 5361c330fc8..5dec749d271 100755 --- a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsRedundant.py +++ b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsRedundant.py @@ -131,9 +131,9 @@ class CsRedundant(object): CsHelper.copy(conntrackd_template_conf, conntrackd_temp_bkp) - connt = CsFile(conntrackd_template_conf) + conntrackd_tmpl = CsFile(conntrackd_template_conf) if guest is not None: - connt.section("Multicast {", "}", [ + conntrackd_tmpl.section("Multicast {", "}", [ "IPv4_address 225.0.0.50\n", "Group 3780\n", "IPv4_interface %s\n" % guest.get_ip(), @@ -141,14 +141,15 @@ class CsRedundant(object): "SndSocketBuffer 1249280\n", "RcvSocketBuffer 1249280\n", "Checksum on\n"]) - connt.section("Address Ignore {", "}", self._collect_ignore_ips()) - connt.commit() + conntrackd_tmpl.section("Address Ignore {", "}", self._collect_ignore_ips()) + conntrackd_tmpl.commit() conntrackd_conf = CsFile(self.CONNTRACKD_CONF) - if not connt.compare(conntrackd_conf): + is_equals = conntrackd_tmpl.compare(conntrackd_conf) + proc = CsProcess(['/etc/conntrackd/conntrackd.conf']) + if not proc.find() or not is_equals: CsHelper.copy(conntrackd_template_conf, self.CONNTRACKD_CONF) - proc = CsProcess(['/etc/conntrackd/conntrackd.conf']) CsHelper.service("conntrackd", "restart") # Restore the template file and remove the backup. diff --git a/test/integration/component/test_vpc_redundant.py b/test/integration/component/test_vpc_redundant.py index 6f82aece9ec..c158c208b1a 100644 --- a/test/integration/component/test_vpc_redundant.py +++ b/test/integration/component/test_vpc_redundant.py @@ -458,26 +458,22 @@ class TestVPCRedundancy(cloudstackTestCase): self.query_routers() self.networks.append(self.create_network(self.services["network_offering"], "10.1.1.1")) self.networks.append(self.create_network(self.services["network_offering_no_lb"], "10.1.2.1")) - time.sleep(30) self.check_master_status(2) self.add_nat_rules() self.do_vpc_test(False) - time.sleep(30) self.stop_router_by_type("MASTER") # wait for the backup router to transit to master state - time.sleep(30) + time.sleep(10) self.check_master_status(1) self.do_vpc_test(False) self.delete_nat_rules() - time.sleep(45) self.check_master_status(1) self.do_vpc_test(True) self.start_routers() self.add_nat_rules() - time.sleep(30) self.check_master_status(2) self.do_vpc_test(False) @@ -488,7 +484,6 @@ class TestVPCRedundancy(cloudstackTestCase): self.query_routers() self.networks.append(self.create_network(self.services["network_offering"], "10.1.1.1")) self.networks.append(self.create_network(self.services["network_offering_no_lb"], "10.1.2.1")) - time.sleep(30) self.check_master_status(2) self.add_nat_rules() self.do_default_routes_test()