mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Sorting out redundancy
some new unit testing stupid bug in CsCmdLine refactor
This commit is contained in:
parent
014b47f6e6
commit
406af7e855
@ -47,7 +47,7 @@ class CsAddress(CsDataBag):
|
|||||||
|
|
||||||
def get_guest_if(self):
|
def get_guest_if(self):
|
||||||
"""
|
"""
|
||||||
Return CsIp object for the first guest interface
|
Return CsInterface object for the first guest interface
|
||||||
"""
|
"""
|
||||||
for ip in self.get_ips():
|
for ip in self.get_ips():
|
||||||
if ip.is_guest():
|
if ip.is_guest():
|
||||||
@ -199,6 +199,11 @@ class CsInterface:
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def is_public(self):
|
||||||
|
if "nw_type" in self.address and self.address['nw_type'] in ['public']:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def to_str(self):
|
def to_str(self):
|
||||||
pprint(self.address)
|
pprint(self.address)
|
||||||
|
|
||||||
@ -294,7 +299,7 @@ class CsIP:
|
|||||||
if " DOWN " in i:
|
if " DOWN " in i:
|
||||||
cmd2 = "ip link set %s up" % self.getDevice()
|
cmd2 = "ip link set %s up" % self.getDevice()
|
||||||
# Do not change the state of ips on a redundant router that are managed by vrrp or CsRedundant
|
# Do not change the state of ips on a redundant router that are managed by vrrp or CsRedundant
|
||||||
if self.config.cmdline().is_redundant() and self.needs_vrrp():
|
if self.config.cmdline().is_redundant() and self.is_public():
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
CsHelper.execute(cmd2)
|
CsHelper.execute(cmd2)
|
||||||
@ -448,6 +453,11 @@ class CsIP:
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def is_public(self):
|
||||||
|
if "nw_type" in self.address and self.address['nw_type'] in ['public']:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def ip(self):
|
def ip(self):
|
||||||
return str(self.address['cidr'])
|
return str(self.address['cidr'])
|
||||||
|
|
||||||
|
|||||||
@ -52,16 +52,26 @@ class CsCmdLine(CsDataBag):
|
|||||||
""" Get cmdline config parameters """
|
""" Get cmdline config parameters """
|
||||||
|
|
||||||
def idata(self):
|
def idata(self):
|
||||||
if "config" in self.dbag:
|
if "config" not in self.dbag:
|
||||||
return self.dbag['config']
|
self.dbag['config'] = {}
|
||||||
else:
|
return self.dbag['config']
|
||||||
return {}
|
|
||||||
|
def get_priority(self):
|
||||||
|
if "router_pr" in self.idata():
|
||||||
|
return self.idata()['router_pr']
|
||||||
|
return 99
|
||||||
|
|
||||||
def is_redundant(self):
|
def is_redundant(self):
|
||||||
if "redundant_router" in self.idata():
|
if "redundant_router" in self.idata():
|
||||||
return self.idata()['redundant_router'] == "true"
|
return self.idata()['redundant_router'] == "true"
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def set_redundant(self, val="true"):
|
||||||
|
self.idata()['redundant_router'] = val
|
||||||
|
|
||||||
|
def set_guest_gw(self, val):
|
||||||
|
self.idata()['guestgw'] = val
|
||||||
|
|
||||||
def get_guest_gw(self):
|
def get_guest_gw(self):
|
||||||
if "guestgw" in self.idata():
|
if "guestgw" in self.idata():
|
||||||
return self.idata()['guestgw']
|
return self.idata()['guestgw']
|
||||||
@ -95,7 +105,7 @@ class CsCmdLine(CsDataBag):
|
|||||||
return "unknown"
|
return "unknown"
|
||||||
|
|
||||||
def get_domain(self):
|
def get_domain(self):
|
||||||
if "domain" in self.config:
|
if "domain" in self.idata();
|
||||||
return self.idata()['domain']
|
return self.idata()['domain']
|
||||||
else:
|
else:
|
||||||
return "cloudnine.internal"
|
return "cloudnine.internal"
|
||||||
|
|||||||
@ -88,7 +88,7 @@ class CsRedundant(object):
|
|||||||
# keepalived configuration
|
# keepalived configuration
|
||||||
file = CsFile("/etc/keepalived/keepalived.conf")
|
file = CsFile("/etc/keepalived/keepalived.conf")
|
||||||
file.search(" router_id ", " router_id %s" % self.cl.get_name())
|
file.search(" router_id ", " router_id %s" % self.cl.get_name())
|
||||||
file.search(" priority ", " priority %s" % 20)
|
file.search(" priority ", " priority %s" % self.cl.get_priority())
|
||||||
file.search(" weight ", " weight %s" % 2)
|
file.search(" weight ", " weight %s" % 2)
|
||||||
file.greplace("[RROUTER_BIN_PATH]", self.CS_ROUTER_DIR)
|
file.greplace("[RROUTER_BIN_PATH]", self.CS_ROUTER_DIR)
|
||||||
file.section("virtual_ipaddress {", "}", self._collect_ips())
|
file.section("virtual_ipaddress {", "}", self._collect_ips())
|
||||||
@ -146,11 +146,13 @@ class CsRedundant(object):
|
|||||||
if not self.cl.is_redundant():
|
if not self.cl.is_redundant():
|
||||||
logging.error("Set backup called on non-redundant router")
|
logging.error("Set backup called on non-redundant router")
|
||||||
return
|
return
|
||||||
|
"""
|
||||||
if not self.cl.is_master():
|
if not self.cl.is_master():
|
||||||
logging.error("Set backup called on node that is already backup")
|
logging.error("Set backup called on node that is already backup")
|
||||||
return
|
return
|
||||||
|
"""
|
||||||
logging.info("Router switched to backup mode")
|
logging.info("Router switched to backup mode")
|
||||||
ads = [o for o in self.address.get_ips() if o.needs_vrrp()]
|
ads = [o for o in self.address.get_ips() if o.is_public()]
|
||||||
for o in ads:
|
for o in ads:
|
||||||
CsHelper.execute("ifconfig %s down" % o.get_device())
|
CsHelper.execute("ifconfig %s down" % o.get_device())
|
||||||
cmd = "%s -C %s" % (self.CONNTRACKD_BIN, self.CONNTRACKD_CONFIG)
|
cmd = "%s -C %s" % (self.CONNTRACKD_BIN, self.CONNTRACKD_CONFIG)
|
||||||
@ -160,6 +162,7 @@ class CsRedundant(object):
|
|||||||
CsHelper.service("cloud-passwd-srvr", "stop")
|
CsHelper.service("cloud-passwd-srvr", "stop")
|
||||||
CsHelper.service("dnsmasq", "stop")
|
CsHelper.service("dnsmasq", "stop")
|
||||||
self.cl.dbag['config']['redundant_master'] = "false"
|
self.cl.dbag['config']['redundant_master'] = "false"
|
||||||
|
CsHelper.service("keepalived", "restart")
|
||||||
self.cl.save()
|
self.cl.save()
|
||||||
|
|
||||||
def set_master(self):
|
def set_master(self):
|
||||||
@ -167,10 +170,12 @@ class CsRedundant(object):
|
|||||||
if not self.cl.is_redundant():
|
if not self.cl.is_redundant():
|
||||||
logging.error("Set master called on non-redundant router")
|
logging.error("Set master called on non-redundant router")
|
||||||
return
|
return
|
||||||
|
"""
|
||||||
if self.cl.is_master():
|
if self.cl.is_master():
|
||||||
logging.error("Set master called on master node")
|
logging.error("Set master called on master node")
|
||||||
return
|
return
|
||||||
ads = [o for o in self.address.get_ips() if o.needs_vrrp()]
|
"""
|
||||||
|
ads = [o for o in self.address.get_ips() if o.is_public()]
|
||||||
for o in ads:
|
for o in ads:
|
||||||
# cmd2 = "ip link set %s up" % self.getDevice()
|
# cmd2 = "ip link set %s up" % self.getDevice()
|
||||||
CsHelper.execute("ifconfig %s down" % o.get_device())
|
CsHelper.execute("ifconfig %s down" % o.get_device())
|
||||||
@ -189,6 +194,7 @@ class CsRedundant(object):
|
|||||||
CsHelper.service("dnsmasq", "restart")
|
CsHelper.service("dnsmasq", "restart")
|
||||||
self.cl.dbag['config']['redundant_master'] = "true"
|
self.cl.dbag['config']['redundant_master'] = "true"
|
||||||
self.cl.save()
|
self.cl.save()
|
||||||
|
CsHelper.service("keepalived", "restart")
|
||||||
logging.info("Router switched to master mode")
|
logging.info("Router switched to master mode")
|
||||||
|
|
||||||
def _collect_ignore_ips(self):
|
def _collect_ignore_ips(self):
|
||||||
|
|||||||
@ -21,6 +21,7 @@ from cs.CsRedundant import CsRedundant
|
|||||||
from cs.CsDatabag import CsCmdLine
|
from cs.CsDatabag import CsCmdLine
|
||||||
from cs.CsAddress import CsAddress
|
from cs.CsAddress import CsAddress
|
||||||
from cs.CsConfig import CsConfig
|
from cs.CsConfig import CsConfig
|
||||||
|
import logging
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
parser = OptionParser()
|
parser = OptionParser()
|
||||||
@ -35,15 +36,15 @@ parser.add_option("-f", "--fault",
|
|||||||
help="Notify Fault")
|
help="Notify Fault")
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
|
|
||||||
config = CsConfig(False)
|
config = CsConfig()
|
||||||
logging.basicConfig(filename=config.get_logger(),
|
logging.basicConfig(filename=config.get_logger(),
|
||||||
level=config.get_level(),
|
level=config.get_level(),
|
||||||
format=config.get_format())
|
format=config.get_format())
|
||||||
config.set_cl()
|
config.cmdline()
|
||||||
cl = CsCmdLine("cmdline", config)
|
cl = CsCmdLine("cmdline", config)
|
||||||
|
|
||||||
address = CsAddress("ips")
|
config.set_address()
|
||||||
red = CsRedundant(config, address)
|
red = CsRedundant(config)
|
||||||
|
|
||||||
if options.master:
|
if options.master:
|
||||||
red.set_master()
|
red.set_master()
|
||||||
|
|||||||
@ -33,7 +33,7 @@ parser.add_option("-d", "--disable",
|
|||||||
|
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
|
|
||||||
config = CsConfig(False)
|
config = CsConfig()
|
||||||
logging.basicConfig(filename=config.get_logger(),
|
logging.basicConfig(filename=config.get_logger(),
|
||||||
level=config.get_level(),
|
level=config.get_level(),
|
||||||
format=config.get_format())
|
format=config.get_format())
|
||||||
|
|||||||
@ -17,5 +17,8 @@ class TestCsInterface(unittest.TestCase):
|
|||||||
def test_get_gateway(self):
|
def test_get_gateway(self):
|
||||||
self.assertTrue(self.csinterface.get_gateway() == "1.2.3.4")
|
self.assertTrue(self.csinterface.get_gateway() == "1.2.3.4")
|
||||||
|
|
||||||
|
def test_is_public(self):
|
||||||
|
self.assertTrue(self.csinterface.is_public() is False)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user