Skip to content

Commit 919660d

Browse files
committed
Merge pull request #1472 from remibergsma/47_fix_static_router_master_change
Apply static routes on change to master stateRefactored static routes for private gateways so they also get loaded when the router switches to master state. Otherwise they're lost and connections drop after fail over. * pr/1472: apply static routes on change to master state Signed-off-by: Will Stevens <[email protected]>
2 parents 309a60e + b9feb39 commit 919660d

File tree

3 files changed

+50
-24
lines changed

3 files changed

+50
-24
lines changed

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

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
from cs.CsLoadBalancer import CsLoadBalancer
4343
from cs.CsConfig import CsConfig
4444
from cs.CsProcess import CsProcess
45+
from cs.CsStaticRoutes import CsStaticRoutes
4546

4647

4748
class CsPassword(CsDataBag):
@@ -74,27 +75,6 @@ def __update(self, vm_ip, password):
7475
logging.debug("Update password server result ==> %s" % result)
7576

7677

77-
class CsStaticRoutes(CsDataBag):
78-
79-
def process(self):
80-
logging.debug("Processing CsStaticRoutes file ==> %s" % self.dbag)
81-
for item in self.dbag:
82-
if item == "id":
83-
continue
84-
self.__update(self.dbag[item])
85-
86-
def __update(self, route):
87-
if route['revoke']:
88-
command = "ip route del %s via %s" % (route['network'], route['gateway'])
89-
result = CsHelper.execute(command)
90-
else:
91-
command = "ip route show | grep %s | awk '{print $1, $3}'" % route['network']
92-
result = CsHelper.execute(command)
93-
if not result:
94-
route_command = "ip route add %s via %s" % (route['network'], route['gateway'])
95-
result = CsHelper.execute(route_command)
96-
97-
9878
class CsAcl(CsDataBag):
9979
"""
10080
Deal with Network acls

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
from CsApp import CsPasswdSvc
3939
from CsAddress import CsDevice
4040
from CsRoute import CsRoute
41+
from CsStaticRoutes import CsStaticRoutes
4142
import socket
4243
from time import sleep
4344

@@ -303,9 +304,9 @@ def set_master(self):
303304
continue
304305
dev = interface.get_device()
305306
logging.info("Will proceed configuring device ==> %s" % dev)
306-
cmd2 = "ip link set %s up" % dev
307+
cmd = "ip link set %s up" % dev
307308
if CsDevice(dev, self.config).waitfordevice():
308-
CsHelper.execute(cmd2)
309+
CsHelper.execute(cmd)
309310
logging.info("Bringing public interface %s up" % dev)
310311

311312
try:
@@ -318,7 +319,10 @@ def set_master(self):
318319
else:
319320
logging.error("Device %s was not ready could not bring it up" % dev)
320321

321-
# ip route add default via $gw table Table_$dev proto static
322+
logging.debug("Configuring static routes")
323+
static_routes = CsStaticRoutes("staticroutes", self.config)
324+
static_routes.process()
325+
322326
cmd = "%s -C %s" % (self.CONNTRACKD_BIN, self.CONNTRACKD_CONF)
323327
CsHelper.execute("%s -c" % cmd)
324328
CsHelper.execute("%s -f" % cmd)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/python
2+
# -- coding: utf-8 --
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
20+
from CsDatabag import CsDataBag
21+
from CsRedundant import *
22+
23+
24+
class CsStaticRoutes(CsDataBag):
25+
26+
def process(self):
27+
logging.debug("Processing CsStaticRoutes file ==> %s" % self.dbag)
28+
for item in self.dbag:
29+
if item == "id":
30+
continue
31+
self.__update(self.dbag[item])
32+
33+
def __update(self, route):
34+
if route['revoke']:
35+
command = "ip route del %s via %s" % (route['network'], route['gateway'])
36+
CsHelper.execute(command)
37+
else:
38+
command = "ip route show | grep %s | awk '{print $1, $3}'" % route['network']
39+
result = CsHelper.execute(command)
40+
if not result:
41+
route_command = "ip route add %s via %s" % (route['network'], route['gateway'])
42+
CsHelper.execute(route_command)

0 commit comments

Comments
 (0)