Skip to content

Commit 406af7e

Browse files
Ian Southamwilderrodrigues
authored andcommitted
Sorting out redundancy
some new unit testing stupid bug in CsCmdLine refactor
1 parent 014b47f commit 406af7e

6 files changed

Lines changed: 45 additions & 15 deletions

File tree

‎systemvm/patches/debian/config/opt/cloud/bin/cs/CsAddress.py‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def get_ips(self):
4747

4848
def get_guest_if(self):
4949
"""
50-
Return CsIp object for the first guest interface
50+
Return CsInterface object for the first guest interface
5151
"""
5252
for ip in self.get_ips():
5353
if ip.is_guest():
@@ -199,6 +199,11 @@ def is_guest(self):
199199
return True
200200
return False
201201

202+
def is_public(self):
203+
if "nw_type" in self.address and self.address['nw_type'] in ['public']:
204+
return True
205+
return False
206+
202207
def to_str(self):
203208
pprint(self.address)
204209

@@ -294,7 +299,7 @@ def check_is_up(self):
294299
if " DOWN " in i:
295300
cmd2 = "ip link set %s up" % self.getDevice()
296301
# Do not change the state of ips on a redundant router that are managed by vrrp or CsRedundant
297-
if self.config.cmdline().is_redundant() and self.needs_vrrp():
302+
if self.config.cmdline().is_redundant() and self.is_public():
298303
pass
299304
else:
300305
CsHelper.execute(cmd2)
@@ -448,6 +453,11 @@ def needs_vrrp(self):
448453
return True
449454
return False
450455

456+
def is_public(self):
457+
if "nw_type" in self.address and self.address['nw_type'] in ['public']:
458+
return True
459+
return False
460+
451461
def ip(self):
452462
return str(self.address['cidr'])
453463

‎systemvm/patches/debian/config/opt/cloud/bin/cs/CsDatabag.py‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,26 @@ class CsCmdLine(CsDataBag):
5252
""" Get cmdline config parameters """
5353

5454
def idata(self):
55-
if "config" in self.dbag:
56-
return self.dbag['config']
57-
else:
58-
return {}
55+
if "config" not in self.dbag:
56+
self.dbag['config'] = {}
57+
return self.dbag['config']
58+
59+
def get_priority(self):
60+
if "router_pr" in self.idata():
61+
return self.idata()['router_pr']
62+
return 99
5963

6064
def is_redundant(self):
6165
if "redundant_router" in self.idata():
6266
return self.idata()['redundant_router'] == "true"
6367
return False
6468

69+
def set_redundant(self, val="true"):
70+
self.idata()['redundant_router'] = val
71+
72+
def set_guest_gw(self, val):
73+
self.idata()['guestgw'] = val
74+
6575
def get_guest_gw(self):
6676
if "guestgw" in self.idata():
6777
return self.idata()['guestgw']
@@ -95,7 +105,7 @@ def get_type(self):
95105
return "unknown"
96106

97107
def get_domain(self):
98-
if "domain" in self.config:
108+
if "domain" in self.idata();
99109
return self.idata()['domain']
100110
else:
101111
return "cloudnine.internal"

‎systemvm/patches/debian/config/opt/cloud/bin/cs/CsRedundant.py‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def _redundant_on(self):
8888
# keepalived configuration
8989
file = CsFile("/etc/keepalived/keepalived.conf")
9090
file.search(" router_id ", " router_id %s" % self.cl.get_name())
91-
file.search(" priority ", " priority %s" % 20)
91+
file.search(" priority ", " priority %s" % self.cl.get_priority())
9292
file.search(" weight ", " weight %s" % 2)
9393
file.greplace("[RROUTER_BIN_PATH]", self.CS_ROUTER_DIR)
9494
file.section("virtual_ipaddress {", "}", self._collect_ips())
@@ -146,11 +146,13 @@ def set_backup(self):
146146
if not self.cl.is_redundant():
147147
logging.error("Set backup called on non-redundant router")
148148
return
149+
"""
149150
if not self.cl.is_master():
150151
logging.error("Set backup called on node that is already backup")
151152
return
153+
"""
152154
logging.info("Router switched to backup mode")
153-
ads = [o for o in self.address.get_ips() if o.needs_vrrp()]
155+
ads = [o for o in self.address.get_ips() if o.is_public()]
154156
for o in ads:
155157
CsHelper.execute("ifconfig %s down" % o.get_device())
156158
cmd = "%s -C %s" % (self.CONNTRACKD_BIN, self.CONNTRACKD_CONFIG)
@@ -160,17 +162,20 @@ def set_backup(self):
160162
CsHelper.service("cloud-passwd-srvr", "stop")
161163
CsHelper.service("dnsmasq", "stop")
162164
self.cl.dbag['config']['redundant_master'] = "false"
165+
CsHelper.service("keepalived", "restart")
163166
self.cl.save()
164167

165168
def set_master(self):
166169
""" Set the current router to master """
167170
if not self.cl.is_redundant():
168171
logging.error("Set master called on non-redundant router")
169172
return
173+
"""
170174
if self.cl.is_master():
171175
logging.error("Set master called on master node")
172176
return
173-
ads = [o for o in self.address.get_ips() if o.needs_vrrp()]
177+
"""
178+
ads = [o for o in self.address.get_ips() if o.is_public()]
174179
for o in ads:
175180
# cmd2 = "ip link set %s up" % self.getDevice()
176181
CsHelper.execute("ifconfig %s down" % o.get_device())
@@ -189,6 +194,7 @@ def set_master(self):
189194
CsHelper.service("dnsmasq", "restart")
190195
self.cl.dbag['config']['redundant_master'] = "true"
191196
self.cl.save()
197+
CsHelper.service("keepalived", "restart")
192198
logging.info("Router switched to master mode")
193199

194200
def _collect_ignore_ips(self):

‎systemvm/patches/debian/config/opt/cloud/bin/master.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from cs.CsDatabag import CsCmdLine
2222
from cs.CsAddress import CsAddress
2323
from cs.CsConfig import CsConfig
24+
import logging
2425
from optparse import OptionParser
2526

2627
parser = OptionParser()
@@ -35,15 +36,15 @@
3536
help="Notify Fault")
3637
(options, args) = parser.parse_args()
3738

38-
config = CsConfig(False)
39+
config = CsConfig()
3940
logging.basicConfig(filename=config.get_logger(),
4041
level=config.get_level(),
4142
format=config.get_format())
42-
config.set_cl()
43+
config.cmdline()
4344
cl = CsCmdLine("cmdline", config)
4445

45-
address = CsAddress("ips")
46-
red = CsRedundant(config, address)
46+
config.set_address()
47+
red = CsRedundant(config)
4748

4849
if options.master:
4950
red.set_master()

‎systemvm/patches/debian/config/opt/cloud/bin/set_redundant.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
(options, args) = parser.parse_args()
3535

36-
config = CsConfig(False)
36+
config = CsConfig()
3737
logging.basicConfig(filename=config.get_logger(),
3838
level=config.get_level(),
3939
format=config.get_format())

‎systemvm/test/python/TestCsInterface.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,8 @@ def setUp(self):
1717
def test_get_gateway(self):
1818
self.assertTrue(self.csinterface.get_gateway() == "1.2.3.4")
1919

20+
def test_is_public(self):
21+
self.assertTrue(self.csinterface.is_public() is False)
22+
2023
if __name__ == '__main__':
2124
unittest.main()

0 commit comments

Comments
 (0)