mirror of https://github.com/apache/cloudstack.git
Merge pull request #908 from ekholabs/fix/rVPC_routes_CLOUDSTACK-8915
CLOUDSTACK-8915 - Cannot SSH into VMs deployed Redundant VPC routersIn order to reproduce the problem, I did the following * Create a Redundant VPC * Add a tier * Add a new VM to the tier * Add an ACL, open port 22 and associate the ACL with the tier * Acquire a pub IP * Add a PF rule to port 22 towards the VM * Try to SSH to the VM through the Pub IP It failed with "No route to host". This PR contains the following: * Fix for the keepalived (vrrp) configuration; * Refactor the default router code for both isolated and [r]VPC routers * Revert CsRedundant changes * Add default route tests * Add logging to tests - so we see what's happening during test execution. * pr/908: CLOUDSTACK-8915 - Making sure cleanup resources passes CLOUDSTACK-8915 - Fix the assertion used for the default routes test CLOUDSTACK-8915 - Copy the conntrackd configuration every time _redundant_on() function is called CLOUDSTACK-8915 - This test is still under construction CLOUDSTACK-8915 - Adding logging to tests CLOUDSTACK-8915 - Improve routers tests CLOUDSTACK-8915 - Reverting changes from commit id1a02773b55CLOUDSTACK-8915 - Reverting changes from commit id18dbc0c4cbCLOUDSTACK-8915 - VRRP needs a cidr in order to work properly CLOUDSTACK-8915 - Rearrenging a bit the default route code in order to make it more clear CLOUDSTACK-8915 - Add the default route only on address that have not been configured yet. Signed-off-by: Remi Bergsma <github@remi.nl>
This commit is contained in:
commit
ca9e934e96
|
|
@ -663,7 +663,7 @@ class CsForwardingRules(CsDataBag):
|
|||
elif rule["type"] == "staticnat":
|
||||
self.processStaticNatRule(rule)
|
||||
|
||||
#return the VR guest interface ipo
|
||||
#return the VR guest interface ip
|
||||
def getGuestIp(self):
|
||||
ipr = []
|
||||
ipAddr = None
|
||||
|
|
|
|||
|
|
@ -112,9 +112,6 @@ class CsAddress(CsDataBag):
|
|||
return False
|
||||
|
||||
def process(self):
|
||||
route = CsRoute()
|
||||
found_defaultroute = False
|
||||
|
||||
for dev in self.dbag:
|
||||
if dev == "id":
|
||||
continue
|
||||
|
|
@ -123,42 +120,21 @@ class CsAddress(CsDataBag):
|
|||
for address in self.dbag[dev]:
|
||||
#check if link is up
|
||||
if not self.check_if_link_up(dev):
|
||||
cmd="ip link set %s up"%dev
|
||||
cmd="ip link set %s up" % dev
|
||||
CsHelper.execute(cmd)
|
||||
|
||||
gateway = str(address["gateway"])
|
||||
network = str(address["network"])
|
||||
|
||||
ip.setAddress(address)
|
||||
|
||||
if ip.configured():
|
||||
logging.info(
|
||||
"Address %s on device %s already configured", ip.ip(), dev)
|
||||
|
||||
ip.post_configure()
|
||||
|
||||
ip.post_configure(address)
|
||||
else:
|
||||
logging.info(
|
||||
"Address %s on device %s not configured", ip.ip(), dev)
|
||||
if CsDevice(dev, self.config).waitfordevice():
|
||||
ip.configure()
|
||||
|
||||
route.add_route(dev, network)
|
||||
|
||||
# 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.
|
||||
if address["nw_type"] == "public" and not found_defaultroute:
|
||||
if not route.defaultroute_exists():
|
||||
if route.add_defaultroute(gateway):
|
||||
found_defaultroute = True
|
||||
|
||||
# once we start processing public ip's we need to verify there
|
||||
# is a default route and add if needed
|
||||
if not route.defaultroute_exists():
|
||||
cmdline = self.config.cmdline()
|
||||
if(cmdline.get_gateway()):
|
||||
route.add_defaultroute(cmdline.get_gateway())
|
||||
ip.configure(address)
|
||||
|
||||
|
||||
class CsInterface:
|
||||
|
|
@ -307,28 +283,43 @@ class CsIP:
|
|||
def getAddress(self):
|
||||
return self.address
|
||||
|
||||
def configure(self):
|
||||
def configure(self, address):
|
||||
logging.info(
|
||||
"Configuring address %s on device %s", self.ip(), self.dev)
|
||||
cmd = "ip addr add dev %s %s brd +" % (self.dev, self.ip())
|
||||
subprocess.call(cmd, shell=True)
|
||||
self.post_configure()
|
||||
self.post_configure(address)
|
||||
|
||||
def post_configure(self):
|
||||
def post_configure(self, address):
|
||||
""" The steps that must be done after a device is configured """
|
||||
route = CsRoute()
|
||||
if not self.get_type() in ["control"]:
|
||||
route = CsRoute()
|
||||
route.add_table(self.dev)
|
||||
|
||||
CsRule(self.dev).addMark()
|
||||
self.check_is_up()
|
||||
self.set_mark()
|
||||
self.arpPing()
|
||||
|
||||
CsRpsrfs(self.dev).enable()
|
||||
self.post_config_change("add")
|
||||
|
||||
'''For isolated/redundant and dhcpsrvr routers, call this method after the post_config is complete '''
|
||||
if not self.config.is_vpc():
|
||||
self.setup_router_control()
|
||||
|
||||
if self.config.is_vpc():
|
||||
# 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.
|
||||
if self.get_type() in ["public"]:
|
||||
gateway = str(address["gateway"])
|
||||
route.add_defaultroute(gateway)
|
||||
else:
|
||||
# once we start processing public ip's we need to verify there
|
||||
# is a default route and add if needed
|
||||
if(self.cl.get_gateway()):
|
||||
route.add_defaultroute(self.cl.get_gateway())
|
||||
|
||||
def check_is_up(self):
|
||||
""" Ensure device is up """
|
||||
|
|
@ -543,19 +534,20 @@ class CsIP:
|
|||
CsDevice(self.dev, self.config).configure_rp()
|
||||
|
||||
logging.error(
|
||||
"Not able to setup sourcenat for a regular router yet")
|
||||
"Not able to setup source-nat for a regular router yet")
|
||||
dns = CsDnsmasq(self)
|
||||
dns.add_firewall_rules()
|
||||
app = CsApache(self)
|
||||
app.setup()
|
||||
|
||||
cmdline = self.config.cmdline()
|
||||
# If redundant then this is dealt with by the master backup functions
|
||||
if self.get_type() in ["guest"] and not self.config.cl.is_redundant():
|
||||
if self.get_type() in ["guest"] and not cmdline.is_redundant():
|
||||
pwdsvc = CsPasswdSvc(self.address['public_ip']).start()
|
||||
|
||||
if self.get_type() == "public" and self.config.is_vpc():
|
||||
if self.address["source_nat"]:
|
||||
vpccidr = self.config.cmdline().get_vpccidr()
|
||||
vpccidr = cmdline.get_vpccidr()
|
||||
self.fw.append(
|
||||
["filter", "", "-A FORWARD -s %s ! -d %s -j ACCEPT" % (vpccidr, vpccidr)])
|
||||
self.fw.append(
|
||||
|
|
@ -567,7 +559,15 @@ class CsIP:
|
|||
for i in CsHelper.execute(cmd):
|
||||
vals = i.lstrip().split()
|
||||
if (vals[0] == 'inet'):
|
||||
self.iplist[vals[1]] = self.dev
|
||||
|
||||
cidr = vals[1]
|
||||
for ip, device in self.iplist.iteritems():
|
||||
logging.info(
|
||||
"Iterating over the existing IPs. CIDR to be configured ==> %s, existing IP ==> %s on device ==> %s",
|
||||
cidr, ip, device)
|
||||
|
||||
if cidr[0] != ip[0] and device != self.dev:
|
||||
self.iplist[cidr] = self.dev
|
||||
|
||||
def configured(self):
|
||||
if self.address['cidr'] in self.iplist.keys():
|
||||
|
|
@ -635,8 +635,13 @@ class CsIP:
|
|||
interface = CsInterface(bag, self.config)
|
||||
if not self.config.cl.is_redundant():
|
||||
return False
|
||||
|
||||
rip = ip.split('/')[0]
|
||||
logging.info("Checking if cidr is a gateway for rVPC. IP ==> %s / device ==> %s", ip, self.dev)
|
||||
|
||||
gw = interface.get_gateway()
|
||||
logging.info("Interface has the following gateway ==> %s", gw)
|
||||
|
||||
if bag['nw_type'] == "guest" and rip == gw:
|
||||
return True
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -213,12 +213,7 @@ def copy_if_needed(src, dest):
|
|||
"""
|
||||
if os.path.isfile(dest):
|
||||
return
|
||||
try:
|
||||
shutil.copy2(src, dest)
|
||||
except IOError:
|
||||
logging.Error("Could not copy %s to %s" % (src, dest))
|
||||
else:
|
||||
logging.info("Copied %s to %s" % (src, dest))
|
||||
copy(src, dest)
|
||||
|
||||
def copy(src, dest):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -96,12 +96,15 @@ class CsRedundant(object):
|
|||
d = s.replace(".templ", "")
|
||||
CsHelper.copy_if_needed(
|
||||
"%s/%s" % (self.CS_TEMPLATES_DIR, s), "%s/%s" % (self.CS_ROUTER_DIR, d))
|
||||
CsHelper.copy(
|
||||
|
||||
CsHelper.copy_if_needed(
|
||||
"%s/%s" % (self.CS_TEMPLATES_DIR, "keepalived.conf.templ"), self.KEEPALIVED_CONF)
|
||||
CsHelper.copy_if_needed(
|
||||
"%s/%s" % (self.CS_TEMPLATES_DIR, "conntrackd.conf.templ"), self.CONNTRACKD_CONF)
|
||||
CsHelper.copy_if_needed(
|
||||
"%s/%s" % (self.CS_TEMPLATES_DIR, "checkrouter.sh.templ"), "/opt/cloud/bin/checkrouter.sh")
|
||||
#The file is always copied so the RVR doesn't't get the wrong config.
|
||||
#Concerning the r-VPC, the configuration will be applied in a different manner
|
||||
CsHelper.copy(
|
||||
"%s/%s" % (self.CS_TEMPLATES_DIR, "conntrackd.conf.templ"), self.CONNTRACKD_CONF)
|
||||
|
||||
CsHelper.execute(
|
||||
'sed -i "s/--exec\ \$DAEMON;/--exec\ \$DAEMON\ --\ --vrrp;/g" /etc/init.d/keepalived')
|
||||
|
|
@ -261,8 +264,19 @@ class CsRedundant(object):
|
|||
|
||||
self.set_lock()
|
||||
logging.debug("Setting router to master")
|
||||
self.address.process()
|
||||
logging.info("added default routes")
|
||||
|
||||
ads = [o for o in self.address.get_ips() if o.is_public()]
|
||||
dev = ''
|
||||
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():
|
||||
CsHelper.execute(cmd2)
|
||||
dev = o.get_device()
|
||||
logging.info("Bringing public interface %s up" % o.get_device())
|
||||
else:
|
||||
logging.error("Device %s was not ready could not bring it up" % o.get_device())
|
||||
|
||||
# ip route add default via $gw table Table_$dev proto static
|
||||
cmd = "%s -C %s" % (self.CONNTRACKD_BIN, self.CONNTRACKD_CONF)
|
||||
|
|
@ -310,7 +324,7 @@ class CsRedundant(object):
|
|||
if(cmdline.get_type()=='router'):
|
||||
str = " %s brd %s dev %s\n" % (cmdline.get_guest_gw(), o.get_broadcast(), o.get_device())
|
||||
else:
|
||||
str = " %s brd %s dev %s\n" % (o.get_ip(), o.get_broadcast(), o.get_device())
|
||||
str = " %s brd %s dev %s\n" % (o.get_gateway_cidr(), o.get_broadcast(), o.get_device())
|
||||
lines.append(str)
|
||||
self.check_is_up(o.get_device())
|
||||
return lines
|
||||
|
|
|
|||
|
|
@ -71,13 +71,16 @@ class CsRoute:
|
|||
:param str gateway
|
||||
:return: bool
|
||||
"""
|
||||
if gateway is not None:
|
||||
if not gateway:
|
||||
raise Exception("Gateway cannot be None.")
|
||||
|
||||
if self.defaultroute_exists():
|
||||
return False
|
||||
else:
|
||||
cmd = "default via " + gateway
|
||||
logging.info("Adding default route")
|
||||
self.set_route(cmd)
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def defaultroute_exists(self):
|
||||
""" Return True if a default route is present
|
||||
|
|
|
|||
|
|
@ -230,21 +230,19 @@ class TestVPCIpTablesPolicies(cloudstackTestCase):
|
|||
admin=True,
|
||||
domainid=cls.domain.id)
|
||||
|
||||
cls._cleanup = [cls.account]
|
||||
|
||||
cls.service_offering = ServiceOffering.create(
|
||||
cls.apiclient,
|
||||
cls.services["service_offering"])
|
||||
|
||||
cls._cleanup.append(cls.service_offering)
|
||||
|
||||
cls.logger = logging.getLogger('TestVPCIpTablesPolicies')
|
||||
cls.stream_handler = logging.StreamHandler()
|
||||
cls.logger.setLevel(logging.DEBUG)
|
||||
cls.logger.addHandler(cls.stream_handler)
|
||||
|
||||
cls.entity_manager = EntityManager(cls.apiclient, cls.services, cls.service_offering, cls.account, cls.zone, cls._cleanup, cls.logger)
|
||||
cls.entity_manager = EntityManager(cls.apiclient, cls.services, cls.service_offering, cls.account, cls.zone, cls.logger)
|
||||
|
||||
cls._cleanup = [cls.service_offering, cls.account]
|
||||
return
|
||||
|
||||
@classmethod
|
||||
|
|
@ -274,6 +272,16 @@ class TestVPCIpTablesPolicies(cloudstackTestCase):
|
|||
account=self.account.name,
|
||||
domainid=self.account.domainid)
|
||||
|
||||
self.cleanup = [self.vpc, self.vpc_off]
|
||||
self.entity_manager.set_cleanup(self.cleanup)
|
||||
return
|
||||
|
||||
def tearDown(self):
|
||||
try:
|
||||
self.entity_manager.destroy_routers()
|
||||
cleanup_resources(self.apiclient, self.cleanup)
|
||||
except Exception as e:
|
||||
raise Exception("Warning: Exception during cleanup : %s" % e)
|
||||
return
|
||||
|
||||
@attr(tags=["advanced", "intervlan"], required_hardware="true")
|
||||
|
|
@ -361,21 +369,18 @@ class TestRouterIpTablesPolicies(cloudstackTestCase):
|
|||
admin=True,
|
||||
domainid=cls.domain.id)
|
||||
|
||||
cls._cleanup = [cls.account]
|
||||
|
||||
cls.service_offering = ServiceOffering.create(
|
||||
cls.apiclient,
|
||||
cls.services["service_offering"])
|
||||
|
||||
cls._cleanup.append(cls.service_offering)
|
||||
|
||||
cls.logger = logging.getLogger('TestRouterIpTablesPolicies')
|
||||
cls.stream_handler = logging.StreamHandler()
|
||||
cls.logger.setLevel(logging.DEBUG)
|
||||
cls.logger.addHandler(cls.stream_handler)
|
||||
|
||||
cls.entity_manager = EntityManager(cls.apiclient, cls.services, cls.service_offering, cls.account, cls.zone, cls._cleanup, cls.logger)
|
||||
cls.entity_manager = EntityManager(cls.apiclient, cls.services, cls.service_offering, cls.account, cls.zone, cls.logger)
|
||||
|
||||
cls._cleanup = [cls.service_offering, cls.account]
|
||||
return
|
||||
|
||||
@classmethod
|
||||
|
|
@ -386,6 +391,18 @@ class TestRouterIpTablesPolicies(cloudstackTestCase):
|
|||
raise Exception("Warning: Exception during cleanup : %s" % e)
|
||||
return
|
||||
|
||||
def setUp(self):
|
||||
self.cleanup = []
|
||||
self.entity_manager.set_cleanup(self.cleanup)
|
||||
return
|
||||
|
||||
def tearDown(self):
|
||||
try:
|
||||
cleanup_resources(self.apiclient, self.cleanup)
|
||||
except Exception as e:
|
||||
raise Exception("Warning: Exception during cleanup : %s" % e)
|
||||
return
|
||||
|
||||
@attr(tags=["advanced", "intervlan"], required_hardware="true")
|
||||
def test_02_routervm_iptables_policies(self):
|
||||
""" Test iptables default INPUT/FORWARD policy on RouterVM """
|
||||
|
|
@ -442,18 +459,21 @@ class TestRouterIpTablesPolicies(cloudstackTestCase):
|
|||
|
||||
class EntityManager(object):
|
||||
|
||||
def __init__(self, apiclient, services, service_offering, account, zone, cleanup, logger):
|
||||
def __init__(self, apiclient, services, service_offering, account, zone, logger):
|
||||
self.apiclient = apiclient
|
||||
self.services = services
|
||||
self.service_offering = service_offering
|
||||
self.account = account
|
||||
self.zone = zone
|
||||
self.cleanup = cleanup
|
||||
self.logger = logger
|
||||
|
||||
self.cleanup = []
|
||||
self.networks = []
|
||||
self.routers = []
|
||||
self.ips = []
|
||||
|
||||
def set_cleanup(self, cleanup):
|
||||
self.cleanup = cleanup
|
||||
|
||||
def add_nat_rules(self, vpc_id):
|
||||
for o in self.networks:
|
||||
|
|
@ -514,7 +534,6 @@ class EntityManager(object):
|
|||
conservemode=False)
|
||||
|
||||
nw_off.update(self.apiclient, state='Enabled')
|
||||
self.cleanup.append(nw_off)
|
||||
self.logger.debug('Created and Enabled NetworkOffering')
|
||||
|
||||
self.services["network"]["name"] = "NETWORK-" + str(gateway)
|
||||
|
|
@ -528,13 +547,18 @@ class EntityManager(object):
|
|||
zoneid=self.zone.id,
|
||||
gateway=gateway,
|
||||
vpcid=vpc_id)
|
||||
|
||||
self.logger.debug("Created network with ID: %s" % obj_network.id)
|
||||
except Exception, e:
|
||||
raise Exception('Unable to create a Network with offering=%s because of %s ' % (net_offerring, e))
|
||||
|
||||
o = networkO(obj_network)
|
||||
o.add_vm(self.deployvm_in_network(obj_network))
|
||||
|
||||
vm1 = self.deployvm_in_network(obj_network)
|
||||
self.cleanup.insert(1, obj_network)
|
||||
self.cleanup.insert(2, nw_off)
|
||||
|
||||
o.add_vm(vm1)
|
||||
self.networks.append(o)
|
||||
return o
|
||||
|
||||
|
|
@ -548,7 +572,9 @@ class EntityManager(object):
|
|||
domainid=self.account.domainid,
|
||||
serviceofferingid=self.service_offering.id,
|
||||
networkids=[str(network.id)])
|
||||
|
||||
self.logger.debug('Created VM=%s in network=%s' % (vm.id, network.name))
|
||||
self.cleanup.insert(0, vm)
|
||||
return vm
|
||||
except:
|
||||
raise Exception('Unable to create VM in a Network=%s' % network.name)
|
||||
|
|
@ -562,6 +588,8 @@ class EntityManager(object):
|
|||
accountid=self.account.name,
|
||||
domainid=self.account.domainid,
|
||||
serviceofferingid=self.service_offering.id)
|
||||
|
||||
self.cleanup.insert(0, vm)
|
||||
self.logger.debug('Created VM=%s' % vm.id)
|
||||
return vm
|
||||
except:
|
||||
|
|
@ -590,22 +618,23 @@ class EntityManager(object):
|
|||
|
||||
return self.routers
|
||||
|
||||
def stop_router(self):
|
||||
def stop_router(self, router):
|
||||
self.logger.debug('Stopping router')
|
||||
for router in self.routers:
|
||||
cmd = stopRouter.stopRouterCmd()
|
||||
cmd.id = router.id
|
||||
self.apiclient.stopRouter(cmd)
|
||||
cmd = stopRouter.stopRouterCmd()
|
||||
cmd.id = router.id
|
||||
self.apiclient.stopRouter(cmd)
|
||||
|
||||
def destroy_router(self):
|
||||
self.logger.debug('Destroying router')
|
||||
def destroy_routers(self):
|
||||
self.logger.debug('Destroying routers')
|
||||
for router in self.routers:
|
||||
self.stop_router(router)
|
||||
cmd = destroyRouter.destroyRouterCmd()
|
||||
cmd.id = router.id
|
||||
self.apiclient.destroyRouter(cmd)
|
||||
self.routers = []
|
||||
|
||||
def start_router(self):
|
||||
self.logger.debug('Starting router')
|
||||
def start_routers(self):
|
||||
self.logger.debug('Starting routers')
|
||||
for router in self.routers:
|
||||
cmd = startRouter.startRouterCmd()
|
||||
cmd.id = router.id
|
||||
|
|
|
|||
|
|
@ -0,0 +1,725 @@
|
|||
# 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.
|
||||
|
||||
# Import Local Modules
|
||||
from nose.plugins.attrib import attr
|
||||
from marvin.cloudstackTestCase import cloudstackTestCase
|
||||
from marvin.cloudstackAPI import (stopVirtualMachine,
|
||||
stopRouter,
|
||||
startRouter)
|
||||
from marvin.lib.utils import (cleanup_resources,
|
||||
get_process_status)
|
||||
from marvin.lib.base import (ServiceOffering,
|
||||
VirtualMachine,
|
||||
Account,
|
||||
LoadBalancerRule,
|
||||
FireWallRule,
|
||||
NATRule)
|
||||
from marvin.lib.common import (get_zone,
|
||||
get_template,
|
||||
get_domain,
|
||||
list_virtual_machines,
|
||||
list_networks,
|
||||
list_configurations,
|
||||
list_routers,
|
||||
list_nat_rules,
|
||||
list_publicIP,
|
||||
list_lb_rules,
|
||||
list_firewall_rules,
|
||||
list_hosts)
|
||||
|
||||
# Import System modules
|
||||
import time
|
||||
import logging
|
||||
|
||||
class TestCreatePFOnStoppedRouter(cloudstackTestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
|
||||
cls.testClient = super(TestCreatePFOnStoppedRouter, cls).getClsTestClient()
|
||||
cls.api_client = cls.testClient.getApiClient()
|
||||
|
||||
cls.services = cls.testClient.getParsedTestDataConfig()
|
||||
# Get Zone, Domain and templates
|
||||
cls.domain = get_domain(cls.api_client)
|
||||
cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
|
||||
cls.services['mode'] = cls.zone.networktype
|
||||
template = get_template(
|
||||
cls.api_client,
|
||||
cls.zone.id,
|
||||
cls.services["ostype"]
|
||||
)
|
||||
cls.services["virtual_machine"]["zoneid"] = cls.zone.id
|
||||
|
||||
# Create an account, network, VM and IP addresses
|
||||
cls.account = Account.create(
|
||||
cls.api_client,
|
||||
cls.services["account"],
|
||||
admin=True,
|
||||
domainid=cls.domain.id
|
||||
)
|
||||
cls.service_offering = ServiceOffering.create(
|
||||
cls.api_client,
|
||||
cls.services["service_offering"]
|
||||
)
|
||||
cls.vm_1 = VirtualMachine.create(
|
||||
cls.api_client,
|
||||
cls.services["virtual_machine"],
|
||||
templateid=template.id,
|
||||
accountid=cls.account.name,
|
||||
domainid=cls.account.domainid,
|
||||
serviceofferingid=cls.service_offering.id
|
||||
)
|
||||
cls._cleanup = [
|
||||
cls.account,
|
||||
cls.service_offering
|
||||
]
|
||||
|
||||
cls.logger = logging.getLogger('TestCreatePFOnStoppedRouter')
|
||||
cls.stream_handler = logging.StreamHandler()
|
||||
cls.logger.setLevel(logging.DEBUG)
|
||||
cls.logger.addHandler(cls.stream_handler)
|
||||
|
||||
return
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
try:
|
||||
cls.api_client = super(
|
||||
TestCreatePFOnStoppedRouter,
|
||||
cls).getClsTestClient().getApiClient()
|
||||
# Clean up, terminate the created resources
|
||||
cleanup_resources(cls.api_client, cls._cleanup)
|
||||
|
||||
except Exception as e:
|
||||
raise Exception("Warning: Exception during cleanup : %s" % e)
|
||||
return
|
||||
|
||||
def setUp(self):
|
||||
self.apiclient = self.testClient.getApiClient()
|
||||
self.cleanup = []
|
||||
return
|
||||
|
||||
def tearDown(self):
|
||||
try:
|
||||
# Clean up, terminate the created resources
|
||||
cleanup_resources(self.apiclient, self.cleanup)
|
||||
except Exception as e:
|
||||
raise Exception("Warning: Exception during cleanup : %s" % e)
|
||||
return
|
||||
|
||||
|
||||
@attr(tags=["advanced", "advancedns"], required_hardware="true")
|
||||
def test_01_CreatePFOnStoppedRouter(self):
|
||||
"""Stop existing router, add a PF rule and check we can access the VM """
|
||||
|
||||
# Get router details associated for that account
|
||||
routers = list_routers(
|
||||
self.apiclient,
|
||||
account=self.account.name,
|
||||
domainid=self.account.domainid
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
isinstance(routers, list),
|
||||
True,
|
||||
"Check for list routers response return valid data"
|
||||
)
|
||||
self.assertNotEqual(
|
||||
len(routers),
|
||||
0,
|
||||
"Check list router response"
|
||||
)
|
||||
router = routers[0]
|
||||
|
||||
self.logger.debug("Stopping router ID: %s" % router.id)
|
||||
|
||||
# Stop the router
|
||||
cmd = stopRouter.stopRouterCmd()
|
||||
cmd.id = router.id
|
||||
self.apiclient.stopRouter(cmd)
|
||||
|
||||
routers = list_routers(
|
||||
self.apiclient,
|
||||
account=self.account.name,
|
||||
domainid=self.account.domainid
|
||||
)
|
||||
self.assertEqual(
|
||||
isinstance(routers, list),
|
||||
True,
|
||||
"Check for list routers response return valid data"
|
||||
)
|
||||
router = routers[0]
|
||||
|
||||
self.assertEqual(
|
||||
router.state,
|
||||
'Stopped',
|
||||
"Check list router response for router state"
|
||||
)
|
||||
|
||||
public_ips = list_publicIP(
|
||||
self.apiclient,
|
||||
account=self.account.name,
|
||||
domainid=self.account.domainid,
|
||||
zoneid=self.zone.id
|
||||
)
|
||||
self.assertEqual(
|
||||
isinstance(public_ips, list),
|
||||
True,
|
||||
"Check for list public IPs response return valid data"
|
||||
)
|
||||
|
||||
public_ip = public_ips[0]
|
||||
|
||||
# Open up firewall port for SSH
|
||||
FireWallRule.create(
|
||||
self.apiclient,
|
||||
ipaddressid=public_ip.id,
|
||||
protocol=self.services["natrule"]["protocol"],
|
||||
cidrlist=['0.0.0.0/0'],
|
||||
startport=self.services["natrule"]["publicport"],
|
||||
endport=self.services["natrule"]["publicport"]
|
||||
)
|
||||
|
||||
self.logger.debug("Creating NAT rule for VM ID: %s" % self.vm_1.id)
|
||||
# Create NAT rule
|
||||
nat_rule = NATRule.create(
|
||||
self.apiclient,
|
||||
self.vm_1,
|
||||
self.services["natrule"],
|
||||
public_ip.id
|
||||
)
|
||||
|
||||
self.logger.debug("Starting router ID: %s" % router.id)
|
||||
# Start the router
|
||||
cmd = startRouter.startRouterCmd()
|
||||
cmd.id = router.id
|
||||
self.apiclient.startRouter(cmd)
|
||||
|
||||
routers = list_routers(
|
||||
self.apiclient,
|
||||
account=self.account.name,
|
||||
domainid=self.account.domainid,
|
||||
zoneid=self.zone.id
|
||||
)
|
||||
self.assertEqual(
|
||||
isinstance(routers, list),
|
||||
True,
|
||||
"Check for list routers response return valid data"
|
||||
)
|
||||
router = routers[0]
|
||||
|
||||
self.assertEqual(
|
||||
router.state,
|
||||
'Running',
|
||||
"Check list router response for router state"
|
||||
)
|
||||
# NAT Rule should be in Active state after router start
|
||||
nat_rules = list_nat_rules(
|
||||
self.apiclient,
|
||||
id=nat_rule.id
|
||||
)
|
||||
self.assertEqual(
|
||||
isinstance(nat_rules, list),
|
||||
True,
|
||||
"Check for list NAT rules response return valid data"
|
||||
)
|
||||
self.assertEqual(
|
||||
nat_rules[0].state,
|
||||
'Active',
|
||||
"Check list port forwarding rules"
|
||||
)
|
||||
try:
|
||||
|
||||
self.logger.debug("SSH into VM with ID: %s" % nat_rule.ipaddress)
|
||||
|
||||
self.vm_1.get_ssh_client(
|
||||
ipaddress=nat_rule.ipaddress,
|
||||
port=self.services["natrule"]["publicport"])
|
||||
except Exception as e:
|
||||
self.fail(
|
||||
"SSH Access failed for %s: %s" %
|
||||
(nat_rule.ipaddress, e)
|
||||
)
|
||||
return
|
||||
|
||||
|
||||
class TestCreateLBOnStoppedRouter(cloudstackTestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
|
||||
cls.testClient = super(TestCreateLBOnStoppedRouter, cls).getClsTestClient()
|
||||
cls.api_client = cls.testClient.getApiClient()
|
||||
|
||||
cls.services = cls.testClient.getParsedTestDataConfig()
|
||||
# Get Zone, Domain and templates
|
||||
cls.domain = get_domain(cls.api_client)
|
||||
cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
|
||||
cls.services['mode'] = cls.zone.networktype
|
||||
template = get_template(
|
||||
cls.api_client,
|
||||
cls.zone.id,
|
||||
cls.services["ostype"]
|
||||
)
|
||||
cls.services["virtual_machine"]["zoneid"] = cls.zone.id
|
||||
|
||||
# Create an account, network, VM and IP addresses
|
||||
cls.account = Account.create(
|
||||
cls.api_client,
|
||||
cls.services["account"],
|
||||
admin=True,
|
||||
domainid=cls.domain.id
|
||||
)
|
||||
cls.service_offering = ServiceOffering.create(
|
||||
cls.api_client,
|
||||
cls.services["service_offering"]
|
||||
)
|
||||
cls.vm_1 = VirtualMachine.create(
|
||||
cls.api_client,
|
||||
cls.services["virtual_machine"],
|
||||
templateid=template.id,
|
||||
accountid=cls.account.name,
|
||||
domainid=cls.account.domainid,
|
||||
serviceofferingid=cls.service_offering.id
|
||||
)
|
||||
cls._cleanup = [
|
||||
cls.account,
|
||||
cls.service_offering
|
||||
]
|
||||
|
||||
cls.logger = logging.getLogger('TestCreateLBOnStoppedRouter')
|
||||
cls.stream_handler = logging.StreamHandler()
|
||||
cls.logger.setLevel(logging.DEBUG)
|
||||
cls.logger.addHandler(cls.stream_handler)
|
||||
|
||||
return
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
try:
|
||||
cls.api_client = super(
|
||||
TestCreateLBOnStoppedRouter,
|
||||
cls).getClsTestClient().getApiClient()
|
||||
# Clean up, terminate the created resources
|
||||
cleanup_resources(cls.api_client, cls._cleanup)
|
||||
|
||||
except Exception as e:
|
||||
raise Exception("Warning: Exception during cleanup : %s" % e)
|
||||
return
|
||||
|
||||
def setUp(self):
|
||||
self.apiclient = self.testClient.getApiClient()
|
||||
self.cleanup = []
|
||||
return
|
||||
|
||||
def tearDown(self):
|
||||
try:
|
||||
cleanup_resources(self.apiclient, self.cleanup)
|
||||
except Exception as e:
|
||||
raise Exception("Warning: Exception during cleanup : %s" % e)
|
||||
return
|
||||
|
||||
@attr(tags=["advanced", "advancedns"], required_hardware="true")
|
||||
def test_01_CreateLBOnStoppedRouter(self):
|
||||
"""Stop existing Router, add LB rule and check we can reach the VM"""
|
||||
|
||||
# Get router details associated for that account
|
||||
routers = list_routers(
|
||||
self.apiclient,
|
||||
account=self.account.name,
|
||||
domainid=self.account.domainid
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
isinstance(routers, list),
|
||||
True,
|
||||
"Check for list routers response return valid data"
|
||||
)
|
||||
|
||||
self.assertNotEqual(
|
||||
len(routers),
|
||||
0,
|
||||
"Check list router response"
|
||||
)
|
||||
|
||||
router = routers[0]
|
||||
|
||||
self.logger.debug("Stopping router with ID: %s" % router.id)
|
||||
# Stop the router
|
||||
cmd = stopRouter.stopRouterCmd()
|
||||
cmd.id = router.id
|
||||
self.apiclient.stopRouter(cmd)
|
||||
|
||||
routers = list_routers(
|
||||
self.apiclient,
|
||||
account=self.account.name,
|
||||
domainid=self.account.domainid
|
||||
)
|
||||
self.assertEqual(
|
||||
isinstance(routers, list),
|
||||
True,
|
||||
"Check for list routers response return valid data"
|
||||
)
|
||||
router = routers[0]
|
||||
|
||||
self.assertEqual(
|
||||
router.state,
|
||||
'Stopped',
|
||||
"Check list router response for router state"
|
||||
)
|
||||
|
||||
public_ips = list_publicIP(
|
||||
self.apiclient,
|
||||
account=self.account.name,
|
||||
domainid=self.account.domainid
|
||||
)
|
||||
self.assertEqual(
|
||||
isinstance(public_ips, list),
|
||||
True,
|
||||
"Check for list public IPs response return valid data"
|
||||
)
|
||||
public_ip = public_ips[0]
|
||||
|
||||
# Open up firewall port for SSH
|
||||
FireWallRule.create(
|
||||
self.apiclient,
|
||||
ipaddressid=public_ip.id,
|
||||
protocol=self.services["lbrule"]["protocol"],
|
||||
cidrlist=['0.0.0.0/0'],
|
||||
startport=self.services["lbrule"]["publicport"],
|
||||
endport=self.services["lbrule"]["publicport"]
|
||||
)
|
||||
self.logger.debug("Creating LB rule for public IP: %s" % public_ip.id)
|
||||
# Create Load Balancer rule and assign VMs to rule
|
||||
lb_rule = LoadBalancerRule.create(
|
||||
self.apiclient,
|
||||
self.services["lbrule"],
|
||||
public_ip.id,
|
||||
accountid=self.account.name
|
||||
)
|
||||
self.logger.debug("Assigning VM %s to LB rule: %s" % (
|
||||
self.vm_1.id,
|
||||
lb_rule.id
|
||||
))
|
||||
lb_rule.assign(self.apiclient, [self.vm_1])
|
||||
|
||||
# Start the router
|
||||
cmd = startRouter.startRouterCmd()
|
||||
cmd.id = router.id
|
||||
self.apiclient.startRouter(cmd)
|
||||
|
||||
routers = list_routers(
|
||||
self.apiclient,
|
||||
account=self.account.name,
|
||||
domainid=self.account.domainid
|
||||
)
|
||||
self.assertEqual(
|
||||
isinstance(routers, list),
|
||||
True,
|
||||
"Check for list routers response return valid data"
|
||||
)
|
||||
router = routers[0]
|
||||
|
||||
self.assertEqual(
|
||||
router.state,
|
||||
'Running',
|
||||
"Check list router response for router state"
|
||||
)
|
||||
# After router start, LB RUle should be in Active state
|
||||
lb_rules = list_lb_rules(
|
||||
self.apiclient,
|
||||
id=lb_rule.id
|
||||
)
|
||||
self.assertEqual(
|
||||
isinstance(lb_rules, list),
|
||||
True,
|
||||
"Check for list LB rules response return valid data"
|
||||
)
|
||||
self.assertEqual(
|
||||
lb_rules[0].state,
|
||||
'Active',
|
||||
"Check list load balancing rules"
|
||||
)
|
||||
self.assertEqual(
|
||||
lb_rules[0].publicport,
|
||||
str(self.services["lbrule"]["publicport"]),
|
||||
"Check list load balancing rules"
|
||||
)
|
||||
|
||||
try:
|
||||
self.logger.debug("SSH into VM with IP: %s" % public_ip.ipaddress)
|
||||
self.vm_1.ssh_port = self.services["lbrule"]["publicport"]
|
||||
self.vm_1.get_ssh_client(public_ip.ipaddress)
|
||||
except Exception as e:
|
||||
self.fail(
|
||||
"SSH Access failed for %s: %s" %
|
||||
(self.vm_1.ipaddress, e)
|
||||
)
|
||||
return
|
||||
|
||||
|
||||
class TestCreateFWOnStoppedRouter(cloudstackTestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
|
||||
cls.testClient = super(TestCreateFWOnStoppedRouter, cls).getClsTestClient()
|
||||
cls.api_client = cls.testClient.getApiClient()
|
||||
|
||||
cls.services = cls.testClient.getParsedTestDataConfig()
|
||||
# Get Zone, Domain and templates
|
||||
cls.domain = get_domain(cls.api_client)
|
||||
cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
|
||||
cls.services['mode'] = cls.zone.networktype
|
||||
template = get_template(
|
||||
cls.api_client,
|
||||
cls.zone.id,
|
||||
cls.services["ostype"]
|
||||
)
|
||||
cls.services["virtual_machine"]["zoneid"] = cls.zone.id
|
||||
|
||||
# Create an account, network, VM and IP addresses
|
||||
cls.account = Account.create(
|
||||
cls.api_client,
|
||||
cls.services["account"],
|
||||
domainid=cls.domain.id
|
||||
)
|
||||
cls.service_offering = ServiceOffering.create(
|
||||
cls.api_client,
|
||||
cls.services["service_offering"]
|
||||
)
|
||||
cls.vm_1 = VirtualMachine.create(
|
||||
cls.api_client,
|
||||
cls.services["virtual_machine"],
|
||||
templateid=template.id,
|
||||
accountid=cls.account.name,
|
||||
domainid=cls.account.domainid,
|
||||
serviceofferingid=cls.service_offering.id
|
||||
)
|
||||
cls._cleanup = [
|
||||
cls.account,
|
||||
cls.service_offering
|
||||
]
|
||||
|
||||
cls.logger = logging.getLogger('TestCreateFWOnStoppedRouter')
|
||||
cls.stream_handler = logging.StreamHandler()
|
||||
cls.logger.setLevel(logging.DEBUG)
|
||||
cls.logger.addHandler(cls.stream_handler)
|
||||
|
||||
return
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
try:
|
||||
cls.api_client = super(
|
||||
TestCreateFWOnStoppedRouter,
|
||||
cls).getClsTestClient().getApiClient()
|
||||
# Clean up, terminate the created templates
|
||||
cleanup_resources(cls.api_client, cls._cleanup)
|
||||
|
||||
except Exception as e:
|
||||
raise Exception("Warning: Exception during cleanup : %s" % e)
|
||||
return
|
||||
|
||||
def tearDown(self):
|
||||
try:
|
||||
cleanup_resources(self.apiclient, self.cleanup)
|
||||
except Exception as e:
|
||||
raise Exception("Warning: Exception during cleanup : %s" % e)
|
||||
return
|
||||
|
||||
def setUp(self):
|
||||
self.apiclient = self.testClient.getApiClient()
|
||||
self.hypervisor = self.testClient.getHypervisorInfo()
|
||||
self.cleanup = []
|
||||
return
|
||||
|
||||
@attr(tags=["advanced", "advancedns"], required_hardware="true")
|
||||
def test_01_CreateFWOnStoppedRouter(self):
|
||||
"""Stop existing Router, create Firewall rules and check that the rules are applied to the router"""
|
||||
|
||||
# Get the router details associated with account
|
||||
routers = list_routers(
|
||||
self.apiclient,
|
||||
account=self.account.name,
|
||||
domainid=self.account.domainid
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
isinstance(routers, list),
|
||||
True,
|
||||
"Check for list routers response return valid data"
|
||||
)
|
||||
|
||||
self.assertNotEqual(
|
||||
len(routers),
|
||||
0,
|
||||
"Check list router response"
|
||||
)
|
||||
|
||||
router = routers[0]
|
||||
|
||||
self.logger.debug("Stopping the router: %s" % router.id)
|
||||
# Stop the router
|
||||
cmd = stopRouter.stopRouterCmd()
|
||||
cmd.id = router.id
|
||||
self.apiclient.stopRouter(cmd)
|
||||
|
||||
routers = list_routers(
|
||||
self.apiclient,
|
||||
account=self.account.name,
|
||||
domainid=self.account.domainid
|
||||
)
|
||||
self.assertEqual(
|
||||
isinstance(routers, list),
|
||||
True,
|
||||
"Check for list routers response return valid data"
|
||||
)
|
||||
router = routers[0]
|
||||
|
||||
self.assertEqual(
|
||||
router.state,
|
||||
'Stopped',
|
||||
"Check list router response for router state"
|
||||
)
|
||||
|
||||
public_ips = list_publicIP(
|
||||
self.apiclient,
|
||||
account=self.account.name,
|
||||
domainid=self.account.domainid
|
||||
)
|
||||
self.assertEqual(
|
||||
isinstance(public_ips, list),
|
||||
True,
|
||||
"Check for list public IP response return valid data"
|
||||
)
|
||||
public_ip = public_ips[0]
|
||||
|
||||
# Create Firewall rule with configurations from settings file
|
||||
fw_rule = FireWallRule.create(
|
||||
self.apiclient,
|
||||
ipaddressid=public_ip.id,
|
||||
protocol='TCP',
|
||||
cidrlist=[self.services["fwrule"]["cidr"]],
|
||||
startport=self.services["fwrule"]["startport"],
|
||||
endport=self.services["fwrule"]["endport"]
|
||||
)
|
||||
self.logger.debug("Created firewall rule: %s" % fw_rule.id)
|
||||
|
||||
self.logger.debug("Starting the router: %s" % router.id)
|
||||
# Start the router
|
||||
cmd = startRouter.startRouterCmd()
|
||||
cmd.id = router.id
|
||||
self.apiclient.startRouter(cmd)
|
||||
|
||||
routers = list_routers(
|
||||
self.apiclient,
|
||||
account=self.account.name,
|
||||
domainid=self.account.domainid
|
||||
)
|
||||
self.assertEqual(
|
||||
isinstance(routers, list),
|
||||
True,
|
||||
"Check for list routers response return valid data"
|
||||
)
|
||||
|
||||
router = routers[0]
|
||||
|
||||
self.assertEqual(
|
||||
router.state,
|
||||
'Running',
|
||||
"Check list router response for router state"
|
||||
)
|
||||
# After Router start, FW rule should be in Active state
|
||||
fw_rules = list_firewall_rules(
|
||||
self.apiclient,
|
||||
id=fw_rule.id,
|
||||
)
|
||||
self.assertEqual(
|
||||
isinstance(fw_rules, list),
|
||||
True,
|
||||
"Check for list FW rules response return valid data"
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
fw_rules[0].state,
|
||||
'Active',
|
||||
"Check list load balancing rules"
|
||||
)
|
||||
self.assertEqual(
|
||||
fw_rules[0].startport,
|
||||
str(self.services["fwrule"]["startport"]),
|
||||
"Check start port of firewall rule"
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
fw_rules[0].endport,
|
||||
str(self.services["fwrule"]["endport"]),
|
||||
"Check end port of firewall rule"
|
||||
)
|
||||
# For DNS and DHCP check 'dnsmasq' process status
|
||||
if (self.hypervisor.lower() == 'vmware'
|
||||
or self.hypervisor.lower() == 'hyperv'):
|
||||
result = get_process_status(
|
||||
self.apiclient.connection.mgtSvr,
|
||||
22,
|
||||
self.apiclient.connection.user,
|
||||
self.apiclient.connection.passwd,
|
||||
router.linklocalip,
|
||||
'iptables -t nat -L',
|
||||
hypervisor=self.hypervisor
|
||||
)
|
||||
else:
|
||||
hosts = list_hosts(
|
||||
self.apiclient,
|
||||
id=router.hostid,
|
||||
)
|
||||
self.assertEqual(
|
||||
isinstance(hosts, list),
|
||||
True,
|
||||
"Check for list hosts response return valid data"
|
||||
)
|
||||
host = hosts[0]
|
||||
host.user = self.services["configurableData"]["host"]["username"]
|
||||
host.passwd = self.services["configurableData"]["host"]["password"]
|
||||
try:
|
||||
result = get_process_status(
|
||||
host.ipaddress,
|
||||
22,
|
||||
host.user,
|
||||
host.passwd,
|
||||
router.linklocalip,
|
||||
'iptables -t nat -L'
|
||||
)
|
||||
except KeyError:
|
||||
self.skipTest(
|
||||
"Provide a marvin config file with host\
|
||||
credentials to run %s" %
|
||||
self._testMethodName)
|
||||
|
||||
self.logger.debug("iptables -t nat -L: %s" % result)
|
||||
self.logger.debug("Public IP: %s" % public_ip.ipaddress)
|
||||
res = str(result)
|
||||
self.assertEqual(
|
||||
res.count(str(public_ip.ipaddress)),
|
||||
1,
|
||||
"Check public IP address"
|
||||
)
|
||||
|
||||
return
|
||||
|
|
@ -22,6 +22,7 @@ from nose.plugins.attrib import attr
|
|||
from marvin.cloudstackTestCase import cloudstackTestCase
|
||||
from marvin.lib.base import (stopRouter,
|
||||
startRouter,
|
||||
destroyRouter,
|
||||
Account,
|
||||
VpcOffering,
|
||||
VPC,
|
||||
|
|
@ -41,7 +42,7 @@ from marvin.lib.utils import cleanup_resources
|
|||
import socket
|
||||
import time
|
||||
import inspect
|
||||
|
||||
import logging
|
||||
|
||||
class Services:
|
||||
"""Test VPC network services - Port Forwarding Rules Test Data Class.
|
||||
|
|
@ -215,6 +216,12 @@ class TestVPCRedundancy(cloudstackTestCase):
|
|||
cls.api_client,
|
||||
cls.services["service_offering"])
|
||||
cls._cleanup = [cls.service_offering]
|
||||
|
||||
cls.logger = logging.getLogger('TestVPCRedundancy')
|
||||
cls.stream_handler = logging.StreamHandler()
|
||||
cls.logger.setLevel(logging.DEBUG)
|
||||
cls.logger.addHandler(cls.stream_handler)
|
||||
|
||||
return
|
||||
|
||||
@classmethod
|
||||
|
|
@ -236,16 +243,15 @@ class TestVPCRedundancy(cloudstackTestCase):
|
|||
admin=True,
|
||||
domainid=self.domain.id)
|
||||
|
||||
self.cleanup = [self.account]
|
||||
self.debug("Creating a VPC offering..")
|
||||
self.logger.debug("Creating a VPC offering..")
|
||||
self.vpc_off = VpcOffering.create(
|
||||
self.apiclient,
|
||||
self.services["vpc_offering"])
|
||||
|
||||
self.debug("Enabling the VPC offering created")
|
||||
self.logger.debug("Enabling the VPC offering created")
|
||||
self.vpc_off.update(self.apiclient, state='Enabled')
|
||||
|
||||
self.debug("Creating a VPC network in the account: %s" % self.account.name)
|
||||
self.logger.debug("Creating a VPC network in the account: %s" % self.account.name)
|
||||
self.services["vpc"]["cidr"] = '10.1.1.1/16'
|
||||
self.vpc = VPC.create(
|
||||
self.apiclient,
|
||||
|
|
@ -254,13 +260,17 @@ class TestVPCRedundancy(cloudstackTestCase):
|
|||
zoneid=self.zone.id,
|
||||
account=self.account.name,
|
||||
domainid=self.account.domainid)
|
||||
|
||||
self.cleanup = [self.vpc, self.vpc_off, self.account]
|
||||
return
|
||||
|
||||
def tearDown(self):
|
||||
try:
|
||||
cleanup_resources(self.apiclient, self.cleanup)
|
||||
#Stop/Destroy the routers so we are able to remove the networks. Issue CLOUDSTACK-8935
|
||||
self.destroy_routers()
|
||||
cleanup_resources(self.api_client, self.cleanup)
|
||||
except Exception as e:
|
||||
self.debug("Warning: Exception during cleanup : %s" % e)
|
||||
raise Exception("Warning: Exception during cleanup : %s" % e)
|
||||
return
|
||||
|
||||
def query_routers(self, count=2, showall=False):
|
||||
|
|
@ -287,32 +297,43 @@ class TestVPCRedundancy(cloudstackTestCase):
|
|||
cnts[vals.index(router.redundantstate)] += 1
|
||||
if cnts[vals.index('MASTER')] != 1:
|
||||
self.fail("No Master or too many master routers found %s" % cnts[vals.index('MASTER')])
|
||||
# if cnts[vals.index('UNKNOWN')] > 0:
|
||||
# self.fail("Router has unknown status")
|
||||
|
||||
def stop_router(self, type):
|
||||
def stop_router(self, router):
|
||||
self.logger.debug('Stopping router %s' % router.id)
|
||||
cmd = stopRouter.stopRouterCmd()
|
||||
cmd.id = router.id
|
||||
self.apiclient.stopRouter(cmd)
|
||||
|
||||
def stop_router_by_type(self, type):
|
||||
self.check_master_status(2)
|
||||
self.debug('Stopping %s router' % type)
|
||||
self.logger.debug('Stopping %s router' % type)
|
||||
for router in self.routers:
|
||||
if router.redundantstate == type:
|
||||
cmd = stopRouter.stopRouterCmd()
|
||||
cmd.id = router.id
|
||||
self.apiclient.stopRouter(cmd)
|
||||
self.stop_router(router)
|
||||
|
||||
def start_router(self):
|
||||
self.check_master_status(2, showall=True)
|
||||
self.debug('Starting stopped routers')
|
||||
def destroy_routers(self):
|
||||
self.logger.debug('Destroying routers')
|
||||
for router in self.routers:
|
||||
self.debug('Router %s has state %s' % (router.id, router.state))
|
||||
self.stop_router(router)
|
||||
cmd = destroyRouter.destroyRouterCmd()
|
||||
cmd.id = router.id
|
||||
self.apiclient.destroyRouter(cmd)
|
||||
self.routers = []
|
||||
|
||||
def start_routers(self):
|
||||
self.check_master_status(2, showall=True)
|
||||
self.logger.debug('Starting stopped routers')
|
||||
for router in self.routers:
|
||||
self.logger.debug('Router %s has state %s' % (router.id, router.state))
|
||||
if router.state == "Stopped":
|
||||
self.debug('Starting stopped router %s' % router.id)
|
||||
self.logger.debug('Starting stopped router %s' % router.id)
|
||||
cmd = startRouter.startRouterCmd()
|
||||
cmd.id = router.id
|
||||
self.apiclient.startRouter(cmd)
|
||||
|
||||
def create_network(self, net_offerring, gateway='10.1.1.1', vpc=None):
|
||||
try:
|
||||
self.debug('Create NetworkOffering')
|
||||
self.logger.debug('Create NetworkOffering')
|
||||
net_offerring["name"] = "NET_OFF-" + str(gateway)
|
||||
nw_off = NetworkOffering.create(
|
||||
self.apiclient,
|
||||
|
|
@ -320,11 +341,11 @@ class TestVPCRedundancy(cloudstackTestCase):
|
|||
conservemode=False)
|
||||
|
||||
nw_off.update(self.apiclient, state='Enabled')
|
||||
self._cleanup.append(nw_off)
|
||||
self.debug('Created and Enabled NetworkOffering')
|
||||
|
||||
self.logger.debug('Created and Enabled NetworkOffering')
|
||||
|
||||
self.services["network"]["name"] = "NETWORK-" + str(gateway)
|
||||
self.debug('Adding Network=%s' % self.services["network"])
|
||||
self.logger.debug('Adding Network=%s' % self.services["network"])
|
||||
obj_network = Network.create(
|
||||
self.apiclient,
|
||||
self.services["network"],
|
||||
|
|
@ -335,17 +356,24 @@ class TestVPCRedundancy(cloudstackTestCase):
|
|||
gateway=gateway,
|
||||
vpcid=vpc.id if vpc else self.vpc.id
|
||||
)
|
||||
self.debug("Created network with ID: %s" % obj_network.id)
|
||||
|
||||
self.logger.debug("Created network with ID: %s" % obj_network.id)
|
||||
except Exception, e:
|
||||
self.fail('Unable to create a Network with offering=%s because of %s ' % (net_offerring, e))
|
||||
o = networkO(obj_network)
|
||||
o.add_vm(self.deployvm_in_network(obj_network))
|
||||
o.add_vm(self.deployvm_in_network(obj_network))
|
||||
|
||||
vm1 = self.deployvm_in_network(obj_network)
|
||||
vm2 = self.deployvm_in_network(obj_network)
|
||||
self.cleanup.insert(2, obj_network)
|
||||
self.cleanup.insert(3, nw_off)
|
||||
|
||||
o.add_vm(vm1)
|
||||
o.add_vm(vm2)
|
||||
return o
|
||||
|
||||
def deployvm_in_network(self, network, host_id=None):
|
||||
try:
|
||||
self.debug('Creating VM in network=%s' % network.name)
|
||||
self.logger.debug('Creating VM in network=%s' % network.name)
|
||||
vm = VirtualMachine.create(
|
||||
self.apiclient,
|
||||
self.services["virtual_machine"],
|
||||
|
|
@ -355,13 +383,15 @@ class TestVPCRedundancy(cloudstackTestCase):
|
|||
networkids=[str(network.id)],
|
||||
hostid=host_id
|
||||
)
|
||||
self.debug('Created VM=%s in network=%s' % (vm.id, network.name))
|
||||
|
||||
self.logger.debug('Created VM=%s in network=%s' % (vm.id, network.name))
|
||||
self.cleanup.insert(0, vm)
|
||||
return vm
|
||||
except:
|
||||
self.fail('Unable to create VM in a Network=%s' % network.name)
|
||||
|
||||
def acquire_publicip(self, network):
|
||||
self.debug("Associating public IP for network: %s" % network.name)
|
||||
self.logger.debug("Associating public IP for network: %s" % network.name)
|
||||
public_ip = PublicIPAddress.create(
|
||||
self.apiclient,
|
||||
accountid=self.account.name,
|
||||
|
|
@ -370,14 +400,14 @@ class TestVPCRedundancy(cloudstackTestCase):
|
|||
networkid=network.id,
|
||||
vpcid=self.vpc.id
|
||||
)
|
||||
self.debug("Associated %s with network %s" % (
|
||||
self.logger.debug("Associated %s with network %s" % (
|
||||
public_ip.ipaddress.ipaddress,
|
||||
network.id
|
||||
))
|
||||
return public_ip
|
||||
|
||||
def create_natrule(self, vm, public_ip, network, services=None):
|
||||
self.debug("Creating NAT rule in network for vm with public IP")
|
||||
self.logger.debug("Creating NAT rule in network for vm with public IP")
|
||||
if not services:
|
||||
services = self.services["natrule"]
|
||||
nat_rule = NATRule.create(
|
||||
|
|
@ -389,18 +419,19 @@ class TestVPCRedundancy(cloudstackTestCase):
|
|||
networkid=network.id,
|
||||
vpcid=self.vpc.id)
|
||||
|
||||
self.debug("Adding NetworkACL rules to make NAT rule accessible")
|
||||
self.logger.debug("Adding NetworkACL rules to make NAT rule accessible")
|
||||
nwacl_nat = NetworkACL.create(
|
||||
self.apiclient,
|
||||
networkid=network.id,
|
||||
services=services,
|
||||
traffictype='Ingress'
|
||||
)
|
||||
self.debug('nwacl_nat=%s' % nwacl_nat.__dict__)
|
||||
self.logger.debug('nwacl_nat=%s' % nwacl_nat.__dict__)
|
||||
|
||||
return nat_rule
|
||||
|
||||
def check_ssh_into_vm(self, vm, public_ip, expectFail=False, retries=20):
|
||||
self.debug("Checking if we can SSH into VM=%s on public_ip=%s (%r)" %
|
||||
def check_ssh_into_vm(self, vm, public_ip, expectFail=False, retries=5):
|
||||
self.logger.debug("Checking if we can SSH into VM=%s on public_ip=%s (%r)" %
|
||||
(vm.name, public_ip.ipaddress.ipaddress, expectFail))
|
||||
vm.ssh_client = None
|
||||
try:
|
||||
|
|
@ -412,40 +443,55 @@ class TestVPCRedundancy(cloudstackTestCase):
|
|||
self.fail("SSH into VM=%s on public_ip=%s is successful (Not Expected)" %
|
||||
(vm.name, public_ip.ipaddress.ipaddress))
|
||||
else:
|
||||
self.debug("SSH into VM=%s on public_ip=%s is successful" %
|
||||
self.logger.debug("SSH into VM=%s on public_ip=%s is successful" %
|
||||
(vm.name, public_ip.ipaddress.ipaddress))
|
||||
except:
|
||||
if expectFail:
|
||||
self.debug("Failed to SSH into VM - %s (Expected)" % (public_ip.ipaddress.ipaddress))
|
||||
self.logger.debug("Failed to SSH into VM - %s (Expected)" % (public_ip.ipaddress.ipaddress))
|
||||
else:
|
||||
self.fail("Failed to SSH into VM - %s" % (public_ip.ipaddress.ipaddress))
|
||||
|
||||
@attr(tags=["advanced", "intervlan"], required_hardware="true")
|
||||
def test_01a_create_redundant_VPC(self):
|
||||
""" Create a redundant vpc with two networks with two vms in each network """
|
||||
self.debug("Starting est 1a")
|
||||
def test_01_create_redundant_VPC_2tiers_4VMs_4IPs_4PF_ACL(self):
|
||||
""" Create a redundant VPC with two networks with two VMs in each network """
|
||||
self.logger.debug("Starting test_01_create_redundant_VPC_2tiers_4VMs_4IPs_4PF_ACL")
|
||||
self.query_routers()
|
||||
self.networks.append(self.create_network(self.services["network_offering"], "10.1.1.1"))
|
||||
self.networks.append(self.create_network(self.services["network_offering_no_lb"], "10.1.2.1"))
|
||||
time.sleep(30)
|
||||
self.check_master_status(2)
|
||||
self.add_nat_rules()
|
||||
self.do_vpc_test(False)
|
||||
|
||||
self.stop_router("MASTER")
|
||||
self.stop_router_by_type("MASTER")
|
||||
# wait for the backup router to transit to master state
|
||||
time.sleep(30)
|
||||
self.check_master_status(1)
|
||||
self.do_vpc_test(False)
|
||||
|
||||
self.delete_nat_rules()
|
||||
time.sleep(45)
|
||||
self.check_master_status(1)
|
||||
self.do_vpc_test(True)
|
||||
|
||||
self.start_router()
|
||||
self.start_routers()
|
||||
self.add_nat_rules()
|
||||
time.sleep(45)
|
||||
self.check_master_status(2)
|
||||
self.do_vpc_test(False)
|
||||
|
||||
@attr(tags=["advanced", "intervlan"], required_hardware="true")
|
||||
def test_02_redundant_VPC_default_routes(self):
|
||||
""" Create a redundant VPC with two networks with two VMs in each network and check default routes"""
|
||||
self.logger.debug("Starting test_02_redundant_VPC_default_routes")
|
||||
self.query_routers()
|
||||
self.networks.append(self.create_network(self.services["network_offering"], "10.1.1.1"))
|
||||
self.networks.append(self.create_network(self.services["network_offering_no_lb"], "10.1.2.1"))
|
||||
time.sleep(30)
|
||||
self.check_master_status(2)
|
||||
self.add_nat_rules()
|
||||
self.do_default_routes_test()
|
||||
|
||||
def delete_nat_rules(self):
|
||||
for o in self.networks:
|
||||
for vm in o.get_vms():
|
||||
|
|
@ -470,6 +516,35 @@ class TestVPCRedundancy(cloudstackTestCase):
|
|||
for vm in o.get_vms():
|
||||
self.check_ssh_into_vm(vm.get_vm(), vm.get_ip(), expectFail=expectFail, retries=retries)
|
||||
|
||||
def do_default_routes_test(self):
|
||||
for o in self.networks:
|
||||
for vmObj in o.get_vms():
|
||||
ssh_command = "ping -c 3 8.8.8.8"
|
||||
|
||||
# Should be able to SSH VM
|
||||
result = 'failed'
|
||||
try:
|
||||
vm = vmObj.get_vm()
|
||||
public_ip = vmObj.get_ip()
|
||||
self.logger.debug("SSH into VM: %s" % public_ip.ipaddress.ipaddress)
|
||||
|
||||
ssh = vm.get_ssh_client(ipaddress=public_ip.ipaddress.ipaddress)
|
||||
|
||||
self.logger.debug("Ping to google.com from VM")
|
||||
result = str(ssh.execute(ssh_command))
|
||||
|
||||
self.logger.debug("SSH result: %s; COUNT is ==> %s" % (result, result.count("3 packets received")))
|
||||
except Exception as e:
|
||||
self.fail("SSH Access failed for %s: %s" % \
|
||||
(vmObj.get_ip(), e)
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
result.count("3 packets received"),
|
||||
1,
|
||||
"Ping to outside world from VM should be successful"
|
||||
)
|
||||
|
||||
|
||||
class networkO(object):
|
||||
def __init__(self, net):
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ from marvin.lib.utils import cleanup_resources
|
|||
import socket
|
||||
import time
|
||||
import inspect
|
||||
|
||||
import logging
|
||||
|
||||
class Services:
|
||||
"""Test VPC network services - Port Forwarding Rules Test Data Class.
|
||||
|
|
@ -197,6 +197,12 @@ class TestVPCNics(cloudstackTestCase):
|
|||
cls.api_client,
|
||||
cls.services["service_offering"])
|
||||
cls._cleanup = [cls.service_offering]
|
||||
|
||||
cls.logger = logging.getLogger('TestVPCNics')
|
||||
cls.stream_handler = logging.StreamHandler()
|
||||
cls.logger.setLevel(logging.DEBUG)
|
||||
cls.logger.addHandler(cls.stream_handler)
|
||||
|
||||
return
|
||||
|
||||
@classmethod
|
||||
|
|
@ -218,16 +224,15 @@ class TestVPCNics(cloudstackTestCase):
|
|||
admin=True,
|
||||
domainid=self.domain.id)
|
||||
|
||||
self.cleanup = [self.account]
|
||||
self.debug("Creating a VPC offering..")
|
||||
self.logger.debug("Creating a VPC offering..")
|
||||
self.vpc_off = VpcOffering.create(
|
||||
self.apiclient,
|
||||
self.services["vpc_offering"])
|
||||
|
||||
self.debug("Enabling the VPC offering created")
|
||||
self.logger.debug("Enabling the VPC offering created")
|
||||
self.vpc_off.update(self.apiclient, state='Enabled')
|
||||
|
||||
self.debug("Creating a VPC network in the account: %s" % self.account.name)
|
||||
self.logger.debug("Creating a VPC network in the account: %s" % self.account.name)
|
||||
self.services["vpc"]["cidr"] = '10.1.1.1/16'
|
||||
self.vpc = VPC.create(
|
||||
self.apiclient,
|
||||
|
|
@ -236,13 +241,16 @@ class TestVPCNics(cloudstackTestCase):
|
|||
zoneid=self.zone.id,
|
||||
account=self.account.name,
|
||||
domainid=self.account.domainid)
|
||||
|
||||
self.cleanup = [self.vpc, self.vpc_off, self.account]
|
||||
return
|
||||
|
||||
def tearDown(self):
|
||||
try:
|
||||
self.destroy_routers()
|
||||
cleanup_resources(self.apiclient, self.cleanup)
|
||||
except Exception as e:
|
||||
self.debug("Warning: Exception during cleanup : %s" % e)
|
||||
self.logger.debug("Warning: Exception during cleanup : %s" % e)
|
||||
return
|
||||
|
||||
def query_routers(self):
|
||||
|
|
@ -255,23 +263,24 @@ class TestVPCNics(cloudstackTestCase):
|
|||
isinstance(self.routers, list), True,
|
||||
"Check for list routers response return valid data")
|
||||
|
||||
def stop_router(self):
|
||||
self.debug('Stopping router')
|
||||
for router in self.routers:
|
||||
cmd = stopRouter.stopRouterCmd()
|
||||
cmd.id = router.id
|
||||
self.apiclient.stopRouter(cmd)
|
||||
def stop_router(self, router):
|
||||
self.logger.debug('Stopping router')
|
||||
cmd = stopRouter.stopRouterCmd()
|
||||
cmd.id = router.id
|
||||
self.apiclient.stopRouter(cmd)
|
||||
|
||||
def destroy_router(self):
|
||||
self.debug('Stopping router')
|
||||
def destroy_routers(self):
|
||||
self.logger.debug('Destroying routers')
|
||||
for router in self.routers:
|
||||
self.stop_router(router)
|
||||
cmd = destroyRouter.destroyRouterCmd()
|
||||
cmd.id = router.id
|
||||
self.apiclient.destroyRouter(cmd)
|
||||
self.routers = []
|
||||
|
||||
def create_network(self, net_offerring, gateway='10.1.1.1', vpc=None):
|
||||
try:
|
||||
self.debug('Create NetworkOffering')
|
||||
self.logger.debug('Create NetworkOffering')
|
||||
net_offerring["name"] = "NET_OFF-" + str(gateway)
|
||||
nw_off = NetworkOffering.create(
|
||||
self.apiclient,
|
||||
|
|
@ -279,11 +288,10 @@ class TestVPCNics(cloudstackTestCase):
|
|||
conservemode=False)
|
||||
|
||||
nw_off.update(self.apiclient, state='Enabled')
|
||||
self._cleanup.append(nw_off)
|
||||
self.debug('Created and Enabled NetworkOffering')
|
||||
self.logger.debug('Created and Enabled NetworkOffering')
|
||||
|
||||
self.services["network"]["name"] = "NETWORK-" + str(gateway)
|
||||
self.debug('Adding Network=%s' % self.services["network"])
|
||||
self.logger.debug('Adding Network=%s' % self.services["network"])
|
||||
obj_network = Network.create(
|
||||
self.apiclient,
|
||||
self.services["network"],
|
||||
|
|
@ -294,16 +302,24 @@ class TestVPCNics(cloudstackTestCase):
|
|||
gateway=gateway,
|
||||
vpcid=vpc.id if vpc else self.vpc.id
|
||||
)
|
||||
self.debug("Created network with ID: %s" % obj_network.id)
|
||||
|
||||
|
||||
self.logger.debug("Created network with ID: %s" % obj_network.id)
|
||||
except Exception, e:
|
||||
self.fail('Unable to create a Network with offering=%s because of %s ' % (net_offerring, e))
|
||||
o = networkO(obj_network)
|
||||
o.add_vm(self.deployvm_in_network(obj_network))
|
||||
|
||||
vm1 = self.deployvm_in_network(obj_network)
|
||||
|
||||
self.cleanup.insert(1, obj_network)
|
||||
self.cleanup.insert(2, nw_off)
|
||||
|
||||
o.add_vm(vm1)
|
||||
return o
|
||||
|
||||
def deployvm_in_network(self, network):
|
||||
try:
|
||||
self.debug('Creating VM in network=%s' % network.name)
|
||||
self.logger.debug('Creating VM in network=%s' % network.name)
|
||||
vm = VirtualMachine.create(
|
||||
self.apiclient,
|
||||
self.services["virtual_machine"],
|
||||
|
|
@ -312,13 +328,15 @@ class TestVPCNics(cloudstackTestCase):
|
|||
serviceofferingid=self.service_offering.id,
|
||||
networkids=[str(network.id)]
|
||||
)
|
||||
self.debug('Created VM=%s in network=%s' % (vm.id, network.name))
|
||||
|
||||
self.logger.debug('Created VM=%s in network=%s' % (vm.id, network.name))
|
||||
self.cleanup.insert(0, vm)
|
||||
return vm
|
||||
except:
|
||||
self.fail('Unable to create VM in a Network=%s' % network.name)
|
||||
|
||||
def acquire_publicip(self, network):
|
||||
self.debug("Associating public IP for network: %s" % network.name)
|
||||
self.logger.debug("Associating public IP for network: %s" % network.name)
|
||||
public_ip = PublicIPAddress.create(
|
||||
self.apiclient,
|
||||
accountid=self.account.name,
|
||||
|
|
@ -327,14 +345,14 @@ class TestVPCNics(cloudstackTestCase):
|
|||
networkid=network.id,
|
||||
vpcid=self.vpc.id
|
||||
)
|
||||
self.debug("Associated %s with network %s" % (
|
||||
self.logger.debug("Associated %s with network %s" % (
|
||||
public_ip.ipaddress.ipaddress,
|
||||
network.id
|
||||
))
|
||||
return public_ip
|
||||
|
||||
def create_natrule(self, vm, public_ip, network, services=None):
|
||||
self.debug("Creating NAT rule in network for vm with public IP")
|
||||
self.logger.debug("Creating NAT rule in network for vm with public IP")
|
||||
if not services:
|
||||
services = self.services["natrule"]
|
||||
nat_rule = NATRule.create(
|
||||
|
|
@ -346,31 +364,20 @@ class TestVPCNics(cloudstackTestCase):
|
|||
networkid=network.id,
|
||||
vpcid=self.vpc.id)
|
||||
|
||||
self.debug("Adding NetworkACL rules to make NAT rule accessible")
|
||||
self.logger.debug("Adding NetworkACL rules to make NAT rule accessible")
|
||||
nwacl_nat = NetworkACL.create(
|
||||
self.apiclient,
|
||||
networkid=network.id,
|
||||
services=services,
|
||||
traffictype='Ingress'
|
||||
)
|
||||
self.debug('nwacl_nat=%s' % nwacl_nat.__dict__)
|
||||
self.logger.debug('nwacl_nat=%s' % nwacl_nat.__dict__)
|
||||
return nat_rule
|
||||
|
||||
def check_ssh_into_vm(self, vm, public_ip):
|
||||
self.debug("Checking if we can SSH into VM=%s on public_ip=%s" %
|
||||
(vm.name, public_ip.ipaddress.ipaddress))
|
||||
vm.ssh_client = None
|
||||
try:
|
||||
vm.get_ssh_client(ipaddress=public_ip.ipaddress.ipaddress)
|
||||
self.debug("SSH into VM=%s on public_ip=%s is successful" %
|
||||
(vm.name, public_ip.ipaddress.ipaddress))
|
||||
except:
|
||||
self.fail("Failed to SSH into VM - %s" % (public_ip.ipaddress.ipaddress))
|
||||
|
||||
@attr(tags=["advanced", "intervlan"], required_hardware="true")
|
||||
def test_01_VPC_nics_after_destroy(self):
|
||||
""" Create a vpc with two networks with two vms in each network """
|
||||
self.debug("Starting test 1")
|
||||
""" Create a VPC with two networks with one VM in each network and test nics after destroy"""
|
||||
self.logger.debug("Starting test_01_VPC_nics_after_destroy")
|
||||
self.query_routers()
|
||||
|
||||
net1 = self.create_network(self.services["network_offering"], "10.1.1.1")
|
||||
|
|
@ -380,15 +387,31 @@ class TestVPCNics(cloudstackTestCase):
|
|||
self.networks.append(net2)
|
||||
|
||||
self.add_nat_rules()
|
||||
self.do_vpc_test()
|
||||
self.check_ssh_into_vm()
|
||||
|
||||
self.stop_router()
|
||||
self.destroy_router()
|
||||
self.destroy_routers()
|
||||
time.sleep(30)
|
||||
|
||||
net1.add_vm(self.deployvm_in_network(net1.get_net()))
|
||||
self.query_routers()
|
||||
|
||||
self.add_nat_rules()
|
||||
self.do_vpc_test()
|
||||
self.check_ssh_into_vm()
|
||||
|
||||
@attr(tags=["advanced", "intervlan"], required_hardware="true")
|
||||
def test_02_VPC_default_routes(self):
|
||||
""" Create a VPC with two networks with one VM in each network and test default routes"""
|
||||
self.logger.debug("Starting test_02_VPC_default_routes")
|
||||
self.query_routers()
|
||||
|
||||
net1 = self.create_network(self.services["network_offering"], "10.1.1.1")
|
||||
net2 = self.create_network(self.services["network_offering_no_lb"], "10.1.2.1")
|
||||
|
||||
self.networks.append(net1)
|
||||
self.networks.append(net2)
|
||||
|
||||
self.add_nat_rules()
|
||||
self.do_default_routes_test()
|
||||
|
||||
def delete_nat_rules(self):
|
||||
for o in self.networks:
|
||||
|
|
@ -406,10 +429,52 @@ class TestVPCNics(cloudstackTestCase):
|
|||
vm.set_nat(self.create_natrule(vm.get_vm(), vm.get_ip(), o.get_net()))
|
||||
time.sleep(5)
|
||||
|
||||
def do_vpc_test(self):
|
||||
def check_ssh_into_vm(self):
|
||||
for o in self.networks:
|
||||
for vm in o.get_vms():
|
||||
self.check_ssh_into_vm(vm.get_vm(), vm.get_ip())
|
||||
try:
|
||||
virtual_machine = vm.get_vm()
|
||||
virtual_machine.ssh_client = None
|
||||
|
||||
public_ip = vm.get_ip()
|
||||
|
||||
self.logger.debug("Checking if we can SSH into VM=%s on public_ip=%s" %
|
||||
(virtual_machine.name, public_ip.ipaddress.ipaddress))
|
||||
|
||||
virtual_machine.get_ssh_client(ipaddress=public_ip.ipaddress.ipaddress)
|
||||
self.logger.debug("SSH into VM=%s on public_ip=%s is successful" %
|
||||
(virtual_machine.name, public_ip.ipaddress.ipaddress))
|
||||
except:
|
||||
self.fail("Failed to SSH into VM - %s" % (public_ip.ipaddress.ipaddress))
|
||||
|
||||
def do_default_routes_test(self):
|
||||
for o in self.networks:
|
||||
for vmObj in o.get_vms():
|
||||
ssh_command = "ping -c 3 8.8.8.8"
|
||||
|
||||
# Should be able to SSH VM
|
||||
result = 'failed'
|
||||
try:
|
||||
vm = vmObj.get_vm()
|
||||
public_ip = vmObj.get_ip()
|
||||
self.logger.debug("SSH into VM: %s" % public_ip.ipaddress.ipaddress)
|
||||
|
||||
ssh = vm.get_ssh_client(ipaddress=public_ip.ipaddress.ipaddress)
|
||||
|
||||
self.logger.debug("Ping to google.com from VM")
|
||||
result = str(ssh.execute(ssh_command))
|
||||
|
||||
self.logger.debug("SSH result: %s; COUNT is ==> %s" % (result, result.count("3 packets received")))
|
||||
except Exception as e:
|
||||
self.fail("SSH Access failed for %s: %s" % \
|
||||
(vmObj.get_ip(), e)
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
result.count("3 packets received"),
|
||||
1,
|
||||
"Ping to outside world from VM should be successful"
|
||||
)
|
||||
|
||||
|
||||
class networkO(object):
|
||||
|
|
|
|||
Loading…
Reference in New Issue