CLOUDSTACK-8952 - Make sure we restart dnsmasq if the configuration file changes

- It was working before because the Routers were restarting about 10 times for each operation
     e.g. adding a VM to a network ot acquiring a new IP.
   - Adding stat_rules of internal LB to iptables
     We needed one extra rule in the INPUT chain
This commit is contained in:
Wilder Rodrigues 2015-10-15 12:44:54 +02:00
parent d762dc8579
commit 1886c4a1b3
3 changed files with 21 additions and 7 deletions

View File

@ -36,22 +36,26 @@ class CsDhcp(CsDataBag):
self.preseed()
self.cloud = CsFile(DHCP_HOSTS)
self.conf = CsFile(CLOUD_CONF)
length = len(self.conf)
for item in self.dbag:
if item == "id":
continue
self.add(self.dbag[item])
self.write_hosts()
if self.cloud.is_changed():
self.delete_leases()
self.configure_server()
self.conf.commit()
self.cloud.commit()
if self.conf.is_changed():
if self.conf.is_changed() or self.cloud.is_changed():
CsHelper.service("dnsmasq", "restart")
elif self.cloud.is_changed():
CsHelper.hup_dnsmasq("dnsmasq", "dnsmasq")
self.conf.commit()
self.cloud.commit()
def configure_server(self):
# self.conf.addeq("dhcp-hostsfile=%s" % DHCP_HOSTS)
for i in self.devinfo:
@ -131,8 +135,8 @@ class CsDhcp(CsDataBag):
file.repopulate()
for ip in self.hosts:
file.add("%s\t%s" % (ip, self.hosts[ip]))
file.commit()
if file.is_changed():
file.commit()
logging.info("Updated hosts file")
else:
logging.debug("Hosts file unchanged")

View File

@ -55,13 +55,15 @@ class CsLoadBalancer(CsDataBag):
add_rules = self.dbag['config'][0]['add_rules']
remove_rules = self.dbag['config'][0]['remove_rules']
self._configure_firewall(add_rules, remove_rules)
stat_rules = self.dbag['config'][0]['stat_rules']
self._configure_firewall(add_rules, remove_rules, stat_rules)
def _configure_firewall(self, add_rules, remove_rules):
def _configure_firewall(self, add_rules, remove_rules, stat_rules):
firewall = self.config.get_fw()
logging.debug("CsLoadBalancer:: configuring firewall. Add rules ==> %s" % add_rules)
logging.debug("CsLoadBalancer:: configuring firewall. Remove rules ==> %s" % remove_rules)
logging.debug("CsLoadBalancer:: configuring firewall. Stat rules ==> %s" % stat_rules)
for rules in add_rules:
path = rules.split(':')
@ -74,3 +76,9 @@ class CsLoadBalancer(CsDataBag):
ip = path[0]
port = path[1]
firewall.append(["filter", "", "-D INPUT -p tcp -m tcp -d %s --dport %s -m state --state NEW -j ACCEPT" % (ip, port)])
for rules in stat_rules:
path = rules.split(':')
ip = path[0]
port = path[1]
firewall.append(["filter", "", "-A INPUT -p tcp -m tcp -d %s --dport %s -m state --state NEW -j ACCEPT" % (ip, port)])

View File

@ -458,6 +458,7 @@ 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(10)
self.check_master_status(2)
self.add_nat_rules()
self.do_vpc_test(False)
@ -484,6 +485,7 @@ 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(10)
self.check_master_status(2)
self.add_nat_rules()
self.do_default_routes_test()