Sorting out redundancy
some new unit testing
stupid bug in CsCmdLine refactor


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/f43de838
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/f43de838
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/f43de838

Branch: refs/heads/feature/systemvm-persistent-config
Commit: f43de838766ae390d316b0b49052b9fe00865f21
Parents: e23c59e
Author: Ian Southam <[email protected]>
Authored: Thu Dec 11 18:16:49 2014 +0100
Committer: wilderrodrigues <[email protected]>
Committed: Wed Feb 4 18:41:09 2015 +0100

----------------------------------------------------------------------
 .../debian/config/opt/cloud/bin/cs/CsAddress.py | 14 ++++++++++++--
 .../debian/config/opt/cloud/bin/cs/CsDatabag.py | 20 +++++++++++++++-----
 .../config/opt/cloud/bin/cs/CsRedundant.py      | 12 +++++++++---
 .../debian/config/opt/cloud/bin/master.py       |  9 +++++----
 .../config/opt/cloud/bin/set_redundant.py       |  2 +-
 systemvm/test/python/TestCsInterface.py         |  3 +++
 6 files changed, 45 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f43de838/systemvm/patches/debian/config/opt/cloud/bin/cs/CsAddress.py
----------------------------------------------------------------------
diff --git a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsAddress.py 
b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsAddress.py
index 83f6262..2e2a117 100644
--- a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsAddress.py
+++ b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsAddress.py
@@ -47,7 +47,7 @@ class CsAddress(CsDataBag):
 
     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():
             if ip.is_guest():
@@ -199,6 +199,11 @@ class CsInterface:
             return True
         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):
         pprint(self.address)
 
@@ -294,7 +299,7 @@ class CsIP:
             if " DOWN " in i:
                 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
-                if self.config.cmdline().is_redundant() and self.needs_vrrp():
+                if self.config.cmdline().is_redundant() and self.is_public():
                     pass
                 else:
                     CsHelper.execute(cmd2)
@@ -448,6 +453,11 @@ class CsIP:
             return True
         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):
         return str(self.address['cidr'])
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f43de838/systemvm/patches/debian/config/opt/cloud/bin/cs/CsDatabag.py
----------------------------------------------------------------------
diff --git a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsDatabag.py 
b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsDatabag.py
index bbc4de7..2b28430 100644
--- a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsDatabag.py
+++ b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsDatabag.py
@@ -52,16 +52,26 @@ class CsCmdLine(CsDataBag):
     """ Get cmdline config parameters """
 
     def idata(self):
-        if "config" in self.dbag:
-            return self.dbag['config']
-        else:
-            return {}
+        if "config" not in self.dbag:
+            self.dbag['config'] = {}
+        return self.dbag['config']
+
+    def get_priority(self):
+        if "router_pr" in self.idata():
+            return self.idata()['router_pr']
+        return 99
 
     def is_redundant(self):
         if "redundant_router" in self.idata():
             return self.idata()['redundant_router'] == "true"
         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):
         if "guestgw" in self.idata():
             return self.idata()['guestgw']
@@ -95,7 +105,7 @@ class CsCmdLine(CsDataBag):
             return "unknown"
 
     def get_domain(self):
-        if "domain" in self.config:
+        if "domain" in self.idata();
             return self.idata()['domain']
         else:
             return "cloudnine.internal"

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f43de838/systemvm/patches/debian/config/opt/cloud/bin/cs/CsRedundant.py
----------------------------------------------------------------------
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 4fae8c7..f12f8fa 100644
--- a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsRedundant.py
+++ b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsRedundant.py
@@ -88,7 +88,7 @@ class CsRedundant(object):
         # keepalived configuration
         file = CsFile("/etc/keepalived/keepalived.conf")
         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.greplace("[RROUTER_BIN_PATH]", self.CS_ROUTER_DIR)
         file.section("virtual_ipaddress {", "}", self._collect_ips())
@@ -146,11 +146,13 @@ class CsRedundant(object):
         if not self.cl.is_redundant():
             logging.error("Set backup called on non-redundant router")
             return
+        """ 
         if not self.cl.is_master():
             logging.error("Set backup called on node that is already backup")
             return
+        """
         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:
             CsHelper.execute("ifconfig %s down" % o.get_device())
         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("dnsmasq", "stop")
         self.cl.dbag['config']['redundant_master'] = "false"
+        CsHelper.service("keepalived", "restart")
         self.cl.save()
 
     def set_master(self):
@@ -167,10 +170,12 @@ class CsRedundant(object):
         if not self.cl.is_redundant():
             logging.error("Set master called on non-redundant router")
             return
+        """
         if self.cl.is_master():
             logging.error("Set master called on master node")
             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:
             # cmd2 = "ip link set %s up" % self.getDevice()
             CsHelper.execute("ifconfig %s down" % o.get_device())
@@ -189,6 +194,7 @@ class CsRedundant(object):
         CsHelper.service("dnsmasq", "restart")
         self.cl.dbag['config']['redundant_master'] = "true"
         self.cl.save()
+        CsHelper.service("keepalived", "restart")
         logging.info("Router switched to master mode")
 
     def _collect_ignore_ips(self):

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f43de838/systemvm/patches/debian/config/opt/cloud/bin/master.py
----------------------------------------------------------------------
diff --git a/systemvm/patches/debian/config/opt/cloud/bin/master.py 
b/systemvm/patches/debian/config/opt/cloud/bin/master.py
index ff8e92b..cea1142 100755
--- a/systemvm/patches/debian/config/opt/cloud/bin/master.py
+++ b/systemvm/patches/debian/config/opt/cloud/bin/master.py
@@ -21,6 +21,7 @@ from cs.CsRedundant import CsRedundant
 from cs.CsDatabag import CsCmdLine
 from cs.CsAddress import CsAddress
 from cs.CsConfig import CsConfig
+import logging
 from optparse import OptionParser
 
 parser = OptionParser()
@@ -35,15 +36,15 @@ parser.add_option("-f", "--fault",
                   help="Notify Fault")
 (options, args) = parser.parse_args()
 
-config = CsConfig(False)
+config = CsConfig()
 logging.basicConfig(filename=config.get_logger(),
                     level=config.get_level(),
                     format=config.get_format())
-config.set_cl()
+config.cmdline()
 cl = CsCmdLine("cmdline", config)
 
-address = CsAddress("ips")
-red = CsRedundant(config, address)
+config.set_address()
+red = CsRedundant(config)
 
 if options.master:
     red.set_master()

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f43de838/systemvm/patches/debian/config/opt/cloud/bin/set_redundant.py
----------------------------------------------------------------------
diff --git a/systemvm/patches/debian/config/opt/cloud/bin/set_redundant.py 
b/systemvm/patches/debian/config/opt/cloud/bin/set_redundant.py
index 8aae6d2..328eedd 100755
--- a/systemvm/patches/debian/config/opt/cloud/bin/set_redundant.py
+++ b/systemvm/patches/debian/config/opt/cloud/bin/set_redundant.py
@@ -33,7 +33,7 @@ parser.add_option("-d", "--disable",
 
 (options, args) = parser.parse_args()
 
-config = CsConfig(False)
+config = CsConfig()
 logging.basicConfig(filename=config.get_logger(),
                     level=config.get_level(),
                     format=config.get_format())

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f43de838/systemvm/test/python/TestCsInterface.py
----------------------------------------------------------------------
diff --git a/systemvm/test/python/TestCsInterface.py 
b/systemvm/test/python/TestCsInterface.py
index c50b03f..faa088d 100644
--- a/systemvm/test/python/TestCsInterface.py
+++ b/systemvm/test/python/TestCsInterface.py
@@ -17,5 +17,8 @@ class TestCsInterface(unittest.TestCase):
     def test_get_gateway(self):
         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__':
     unittest.main()

Reply via email to