From 45642b83821ce0ecd6d4cddb76a77a2481e54d9a Mon Sep 17 00:00:00 2001 From: Wilder Rodrigues Date: Thu, 8 Oct 2015 14:19:26 +0200 Subject: [PATCH] CLOUDSTACK-8934 - Add default gateway when the public interface is up again --- .../config/opt/cloud/bin/cs/CsAddress.py | 8 +++--- .../config/opt/cloud/bin/cs/CsRedundant.py | 21 +++++++++++---- .../debian/config/opt/cloud/bin/ian.py | 27 ------------------- .../component/test_vpc_redundant.py | 5 ++-- 4 files changed, 23 insertions(+), 38 deletions(-) delete mode 100644 systemvm/patches/debian/config/opt/cloud/bin/ian.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 78ccb3a1fef..074a63f5823 100755 --- a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsAddress.py +++ b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsAddress.py @@ -155,7 +155,7 @@ class CsInterface: return self.get_attr("netmask") def get_gateway(self): - if self.config.is_vpc(): + if self.config.is_vpc() or self.config.cmdline().is_redundant(): return self.get_attr("gateway") else: return self.config.cmdline().get_guest_gw() @@ -308,7 +308,7 @@ class CsIP: if not self.config.is_vpc(): self.setup_router_control() - if self.config.is_vpc(): + if self.config.is_vpc() or self.cl.is_redundant(): # The code looks redundant here, but we actually have to cater for routers and # VPC routers in a different manner. Please do not remove this block otherwise # The VPC default route will be broken. @@ -329,10 +329,10 @@ class CsIP: cmd2 = "ip link set %s up" % self.getDevice() # If redundant do not bring up public interfaces # master.py and keepalived deal with tham - if self.config.cmdline().is_redundant() and not self.is_public(): + if self.cl.is_redundant() and not self.is_public(): CsHelper.execute(cmd2) # if not redundant bring everything up - if not self.config.cmdline().is_redundant(): + if not self.cl.is_redundant(): CsHelper.execute(cmd2) def set_mark(self): 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 0f71673e307..abe997c36fc 100755 --- a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsRedundant.py +++ b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsRedundant.py @@ -37,6 +37,7 @@ from CsFile import CsFile from CsProcess import CsProcess from CsApp import CsPasswdSvc from CsAddress import CsDevice +from CsRoute import CsRoute import socket from time import sleep @@ -267,16 +268,26 @@ class CsRedundant(object): ads = [o for o in self.address.get_ips() if o.is_public()] dev = '' + route = CsRoute() for o in ads: if dev == o.get_device(): continue - cmd2 = "ip link set %s up" % o.get_device() - if CsDevice(o.get_device(), self.config).waitfordevice(): + dev = o.get_device() + logging.info("Will proceed configuring device ==> %s" % dev) + cmd2 = "ip link set %s up" % dev + if CsDevice(dev, self.config).waitfordevice(): CsHelper.execute(cmd2) - dev = o.get_device() - logging.info("Bringing public interface %s up" % o.get_device()) + logging.info("Bringing public interface %s up" % dev) + + try: + gateway = o.get_gateway() + logging.info("Adding gateway ==> %s to device ==> %s" % (gateway, dev)) + route.add_defaultroute(gateway) + except: + logging.error("ERROR getting gateway from device %s" % dev) + else: - logging.error("Device %s was not ready could not bring it up" % o.get_device()) + logging.error("Device %s was not ready could not bring it up" % dev) # ip route add default via $gw table Table_$dev proto static cmd = "%s -C %s" % (self.CONNTRACKD_BIN, self.CONNTRACKD_CONF) diff --git a/systemvm/patches/debian/config/opt/cloud/bin/ian.py b/systemvm/patches/debian/config/opt/cloud/bin/ian.py deleted file mode 100644 index 186c5942b32..00000000000 --- a/systemvm/patches/debian/config/opt/cloud/bin/ian.py +++ /dev/null @@ -1,27 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. - -from cs.CsGuestNetwork import CsGuestNetwork -import merge - -merge.DataBag.DPATH = "." -csguestnetwork = CsGuestNetwork({}, {}) -csguestnetwork.guest = True -csguestnetwork.set_dns("1.1.1.1,2.2.2.2") -csguestnetwork.set_router("3.3.3.3") -dns = csguestnetwork.get_dns() -print dns diff --git a/test/integration/component/test_vpc_redundant.py b/test/integration/component/test_vpc_redundant.py index 11fabf697c8..6f82aece9ec 100644 --- a/test/integration/component/test_vpc_redundant.py +++ b/test/integration/component/test_vpc_redundant.py @@ -462,7 +462,8 @@ class TestVPCRedundancy(cloudstackTestCase): self.check_master_status(2) self.add_nat_rules() self.do_vpc_test(False) - + time.sleep(30) + self.stop_router_by_type("MASTER") # wait for the backup router to transit to master state time.sleep(30) @@ -476,7 +477,7 @@ class TestVPCRedundancy(cloudstackTestCase): self.start_routers() self.add_nat_rules() - time.sleep(45) + time.sleep(30) self.check_master_status(2) self.do_vpc_test(False)