Skip to content

Commit bdda01d

Browse files
Ian Southamwilderrodrigues
authored andcommitted
Countless bug fixes, mostly do do with VR redundancy
Also added some new unit tests and adjusted the code to make them work
1 parent 553bf21 commit bdda01d

File tree

14 files changed

+136
-68
lines changed

14 files changed

+136
-68
lines changed

systemvm/patches/debian/config/opt/cloud/bin/configure.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -530,13 +530,11 @@ def processStaticNatRule(self, rule):
530530

531531

532532
def main(argv):
533-
config = CsConfig(False)
533+
config = CsConfig()
534534
logging.basicConfig(filename=config.get_logger(),
535535
level=config.get_level(),
536536
format=config.get_format())
537-
config.set_cl()
538537
config.set_address()
539-
cl = config.get_cmdline()
540538

541539
# IP configuration
542540
config.address().compare()

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

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from CsRoute import CsRoute
2727
from CsRule import CsRule
2828

29-
VRRP_TYPES = ['guest', 'public']
29+
VRRP_TYPES = ['guest']
3030

3131

3232
class CsAddress(CsDataBag):
@@ -42,38 +42,37 @@ def get_ips(self):
4242
if dev == "id":
4343
continue
4444
for ip in self.dbag[dev]:
45-
ret.append(CsInterface(ip))
45+
ret.append(CsInterface(ip, self.config))
4646
return ret
4747

48-
def get_guest_ip(self):
48+
def get_guest_if(self):
4949
"""
50-
Return the ip of the first guest interface
51-
For use with routers not vpcrouters
50+
Return CsIp object for the first guest interface
5251
"""
5352
for ip in self.get_ips():
5453
if ip.is_guest():
55-
return ip.get_ip()
54+
return ip
5655
return None
5756

58-
def get_guest_gateway(self):
57+
def get_guest_ip(self):
5958
"""
60-
Return the gateway of the first guest interface
59+
Return the ip of the first guest interface
6160
For use with routers not vpcrouters
6261
"""
63-
for ip in self.get_ips():
64-
if ip.is_guest():
65-
return ip.get_gateway()
62+
ip = self.get_guest_if()
63+
if ip:
64+
return ip.get_ip()
6665
return None
6766

6867
def get_guest_netmask(self):
6968
"""
70-
Return the gateway of the first guest interface
69+
Return the netmask of the first guest interface
7170
For use with routers not vpcrouters
7271
"""
73-
for ip in self.get_ips():
74-
if ip.is_guest():
75-
return ip.get_netmask()
76-
return None
72+
ip = self.get_guest_if()
73+
if ip:
74+
return ip.get_netmask()
75+
return "255.255.255.0"
7776

7877
def needs_vrrp(self, o):
7978
"""
@@ -144,8 +143,9 @@ def add_netstats(self, address):
144143

145144
class CsInterface:
146145
""" Hold one single ip """
147-
def __init__(self, o):
146+
def __init__(self, o, config):
148147
self.address = o
148+
self.config = config
149149

150150
def get_ip(self):
151151
return self.get_attr("public_ip")
@@ -154,7 +154,17 @@ def get_netmask(self):
154154
return self.get_attr("netmask")
155155

156156
def get_gateway(self):
157-
return self.get_attr("gateway")
157+
if self.config.is_vpc():
158+
return self.get_attr("gateway")
159+
else:
160+
return self.config.cmdline().get_guest_gw()
161+
162+
def get_gateway_cidr(self):
163+
return "%s/%s" % (self.get_gateway(), self.get_size())
164+
165+
def get_size(self):
166+
""" Return the network size in bits (24, 16, 8 etc) """
167+
return self.get_attr("size")
158168

159169
def get_device(self):
160170
return self.get_attr("device")
@@ -205,7 +215,7 @@ def __init__(self, dev, config):
205215
self.tableNo = dev[3]
206216
self.table = "Table_%s" % dev
207217
self.fw = config.get_fw()
208-
self.cl = config.get_cmdline()
218+
self.cl = config.cmdline()
209219

210220
def configure_rp(self):
211221
"""
@@ -250,7 +260,7 @@ def __init__(self, dev, config):
250260
self.address = {}
251261
self.list()
252262
self.fw = config.get_fw()
253-
self.cl = config.get_cmdline()
263+
self.cl = config.cmdline()
254264
self.config = config
255265

256266
def setAddress(self, address):
@@ -284,7 +294,7 @@ def check_is_up(self):
284294
if " DOWN " in i:
285295
cmd2 = "ip link set %s up" % self.getDevice()
286296
# Do not change the state of ips on a redundant router that are managed by vrrp or CsRedundant
287-
if self.cl.is_redundant() and self.needs_vrrp():
297+
if self.config.cmdline().is_redundant() and self.needs_vrrp():
288298
pass
289299
else:
290300
CsHelper.execute(cmd2)
@@ -412,7 +422,7 @@ def post_config_change(self, method):
412422

413423
if self.get_type() == "public" and self.config.is_vpc():
414424
if self.address["source_nat"]:
415-
vpccidr = self.cl.get_vpccidr()
425+
vpccidr = self.config.cmdline().get_vpccidr()
416426
self.fw.append(["filter", "", "-A FORWARD -s %s ! -d %s -j ACCEPT" % (vpccidr, vpccidr)])
417427
self.fw.append(["nat", "", "-A POSTROUTING -j SNAT -o %s --to-source %s" % (self.dev, self.address['public_ip'])])
418428
# route.flush()

systemvm/patches/debian/config/opt/cloud/bin/cs/CsConfig.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,25 @@ class CsConfig(object):
2828
__LOG_FILE = "/var/log/cloud.log"
2929
__LOG_LEVEL = "DEBUG"
3030
__LOG_FORMAT = "%(asctime)s %(levelname)-8s %(message)s"
31+
cl = None
3132

32-
def __init__(self, load=False):
33-
if load:
34-
self_set_cl()
35-
self_set_address()
33+
def __init__(self):
3634
self.fw = []
3735

38-
def set_cl(self):
39-
self.cl = CsCmdLine("cmdline")
40-
41-
def address(self):
42-
return self.ips
43-
4436
def set_address(self):
4537
self.ips = CsAddress("ips", self)
4638

47-
def get_cmdline(self):
48-
return self.cl
39+
@classmethod
40+
def get_cmdline_instance(cls):
41+
if cls.cl is None:
42+
cls.cl = CsCmdLine("cmdline")
43+
return cls.cl
44+
45+
def cmdline(self):
46+
return self.get_cmdline_instance()
47+
48+
def address(self):
49+
return self.ips
4950

5051
def get_fw(self):
5152
return self.fw
@@ -66,7 +67,7 @@ def get_domain(self):
6667
return self.cl.get_domain()
6768

6869
def get_dns(self):
69-
return self.get_cmdline().get_dns()
70+
return self.cmdline().get_dns()
7071

7172
def get_format(self):
7273
return self.__LOG_FORMAT

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

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def __init__(self, key, config=None):
2828
self.dbag = self.db.getDataBag()
2929
if config:
3030
self.fw = config.get_fw()
31-
self.cl = config.get_cmdline()
31+
self.cl = config.cmdline()
3232
self.config = config
3333

3434
def dump(self):
@@ -51,46 +51,64 @@ def save(self):
5151
class CsCmdLine(CsDataBag):
5252
""" Get cmdline config parameters """
5353

54+
def idata(self):
55+
if "config" in self.dbag:
56+
return self.dbag['config']
57+
else:
58+
return {}
59+
5460
def is_redundant(self):
55-
if "redundant_router" in self.dbag['config']:
56-
return self.dbag['config']['redundant_router'] == "true"
61+
if "redundant_router" in self.idata():
62+
return self.idata()['redundant_router'] == "true"
5763
return False
5864

65+
def get_guest_gw(self):
66+
if "guestgw" in self.idata():
67+
return self.idata()['guestgw']
68+
else:
69+
return "1.2.3.4"
70+
71+
def get_guest_gw_cidr(self):
72+
if "guestgw" in self.idata():
73+
return "%s/%s" % (self.idata()['guestgw'], self.idata()['guestcidrsize'])
74+
else:
75+
return "1.2.3.4/8"
76+
5977
def get_name(self):
60-
if "name" in self.dbag['config']:
61-
return self.dbag['config']['name']
78+
if "name" in self.idata():
79+
return self.idata()['name']
6280
else:
6381
return "unloved-router"
6482

6583
def get_dns(self):
6684
dns = []
6785
names = "dns1 dns2"
6886
for name in names:
69-
if name in self.dbag['config']:
70-
dns.append(self.dbag['config'][name])
87+
if name in self.idata():
88+
dns.append(self.idata()[name])
7189
return dns
7290

7391
def get_type(self):
74-
if "type" in self.dbag['config']:
75-
return self.dbag['config']['type']
92+
if "type" in self.idata():
93+
return self.idata()['type']
7694
else:
7795
return "unknown"
7896

7997
def get_domain(self):
80-
if "domain" in self.dbag['config']:
81-
return self.dbag['config']['domain']
98+
if "domain" in self.config:
99+
return self.idata()['domain']
82100
else:
83101
return "cloudnine.internal"
84102

85103
def get_vpccidr(self):
86-
if "vpccidr" in self.dbag['config']:
87-
return self.dbag['config']['vpccidr']
104+
if "vpccidr" in self.idata():
105+
return self.idata()['vpccidr']
88106
else:
89107
return "unknown"
90108

91109
def is_master(self):
92110
if not self.is_redundant():
93111
return False
94-
if "redundant_master" in self.dbag['config']:
95-
return self.dbag['config']['redundant_master'] == "true"
112+
if "redundant_master" in self.idata():
113+
return self.idata()['redundant_master'] == "true"
96114
return False

systemvm/patches/debian/config/opt/cloud/bin/cs/CsDhcp.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def process(self):
5454
CsHelper.hup_dnsmasq("dnsmasq", "dnsmasq")
5555

5656
def configure_server(self):
57-
#self.conf.addeq("dhcp-hostsfile=%s" % DHCP_HOSTS)
57+
# self.conf.addeq("dhcp-hostsfile=%s" % DHCP_HOSTS)
5858
for i in self.devinfo:
5959
if not i['dnsmasq']:
6060
continue
@@ -137,9 +137,9 @@ def write_hosts(self):
137137
def add(self, entry):
138138
self.add_host(entry['ipv4_adress'], entry['host_name'])
139139
if self.cloud.search("%s," % entry['mac_address'],
140-
"%s,%s,%s,infinite" % (entry['mac_address'],
141-
entry['ipv4_adress'],
142-
entry['host_name'])):
140+
"%s,%s,%s,infinite" % (entry['mac_address'],
141+
entry['ipv4_adress'],
142+
entry['host_name'])):
143143
self.changed.append({'mac': entry['mac_address'],
144144
'ip4': entry['ipv4_adress'],
145145
'host': entry['host_name']})

systemvm/patches/debian/config/opt/cloud/bin/cs/CsFile.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ def section(self, start, end, content):
101101
if line.strip() == start:
102102
sind = index + 1
103103
found = True
104+
if sind == -1:
105+
content.insert(0, start + "\n")
106+
content.append(end + "\n")
104107
self.new_config[sind:eind] = content
105108

106109
def greplace(self, search, replace):

systemvm/patches/debian/config/opt/cloud/bin/cs/CsHelper.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ def is_mounted(name):
3838

3939
def mount_tmpfs(name):
4040
if not is_mounted(name):
41-
print "Mounting it"
4241
execute("mount tmpfs %s -t tmpfs" % name)
4342

4443

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class CsRedundant(object):
5454
CONNTRACKD_CONFIG = "/etc/conntrackd/conntrackd.conf"
5555

5656
def __init__(self, config):
57-
self.cl = config.get_cmdline()
57+
self.cl = config.cmdline()
5858
self.address = config.address()
5959

6060
def set(self):
@@ -95,10 +95,16 @@ def _redundant_on(self):
9595
file.commit()
9696

9797
# conntrackd configuration
98-
control = self.address.get_control_if()
98+
guest = self.address.get_guest_if()
9999
connt = CsFile("/etc/conntrackd/conntrackd.conf")
100-
connt.search("[\s\t]IPv4_interface ", "\t\tIPv4_interface %s" % control.get_ip())
101-
connt.search("[\s\t]Interface ", "\t\tInterface %s" % control.get_device())
100+
connt.section("Multicast {", "}", [
101+
"IPv4_address 225.0.0.50\n",
102+
"Group 3780\n",
103+
"IPv4_interface %s\n" % guest.get_ip(),
104+
"Interface %s\n" % guest.get_device(),
105+
"SndSocketBuffer 1249280\n",
106+
"RcvSocketBuffer 1249280\n",
107+
"Checksum on\n"])
102108
connt.section("Address Ignore {", "}", self._collect_ignore_ips())
103109
connt.commit()
104110
if connt.is_changed():
@@ -209,6 +215,6 @@ def _collect_ips(self):
209215
lines = []
210216
for o in self.address.get_ips():
211217
if o.needs_vrrp():
212-
str = " %s brd %s dev %s\n" % (o.get_cidr(), o.get_broadcast(), o.get_ip())
218+
str = " %s brd %s dev %s\n" % (o.get_gateway_cidr(), o.get_broadcast(), o.get_device())
213219
lines.append(str)
214220
return lines

systemvm/patches/debian/config/opt/cloud/bin/cs_ip.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def merge(dbag, ip):
3232
ip['device'] = 'eth' + str(ip['nic_dev_id'])
3333
ip['broadcast'] = str(ipo.broadcast)
3434
ip['cidr'] = str(ipo.ip) + '/' + str(ipo.prefixlen)
35+
ip['size'] = str(ipo.prefixlen)
3536
ip['network'] = str(ipo.network) + '/' + str(ipo.prefixlen)
3637
if 'nw_type' not in ip.keys():
3738
ip['nw_type'] = 'public'

systemvm/test/python/TestCsAddress.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,19 @@ class TestCsAddress(unittest.TestCase):
77

88
def setUp(self):
99
merge.DataBag.DPATH = "."
10+
self.csaddress = CsAddress("ips", {})
1011

1112
def test_needs_vrrp(self):
12-
csaddress = CsAddress("ips", {})
13-
self.assertTrue(csaddress.needs_vrrp({"nw_type": "public"}))
13+
self.assertTrue(self.csaddress.needs_vrrp({"nw_type": "guest"}))
14+
15+
def test_get_guest_if(self):
16+
self.assertTrue(self.csaddress.get_guest_if() is None)
17+
18+
def test_get_guest_ip(self):
19+
self.assertTrue(self.csaddress.get_guest_ip() is None)
20+
21+
def test_get_guest_netmask(self):
22+
self.assertTrue(self.csaddress.get_guest_netmask() == "255.255.255.0")
1423

1524
if __name__ == '__main__':
1625
unittest.main()

0 commit comments

Comments
 (0)