You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by pr...@apache.org on 2013/05/16 20:21:40 UTC
[15/68] [abbrv] Marvin IP cleared tests for various cloudstack
components
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/894413e3/test/integration/component/test_redundant_router.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_redundant_router.py b/test/integration/component/test_redundant_router.py
new file mode 100644
index 0000000..c24a58a
--- /dev/null
+++ b/test/integration/component/test_redundant_router.py
@@ -0,0 +1,5581 @@
+# 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 random import random
+import marvin
+from nose.plugins.attrib import attr
+from marvin.integration.lib.base import *
+from marvin.integration.lib.utils import *
+from marvin.integration.lib.common import *
+
+#Import Local Modules
+from marvin.cloudstackTestCase import *
+from marvin.cloudstackAPI import *
+from marvin import remoteSSHClient
+
+
+class Services:
+ """Test Services for customer defects
+ """
+
+ def __init__(self):
+ self.services = {
+ "account": {
+ "email": "test@test.com",
+ "firstname": "Test",
+ "lastname": "User",
+ "username": "test",
+ # Random characters are appended for unique
+ # username
+ "password": "password",
+ },
+ "service_offering": {
+ "name": "Tiny Instance",
+ "displaytext": "Tiny Instance",
+ "cpunumber": 1,
+ "cpuspeed": 100,
+ "memory": 128,
+ },
+ "disk_offering": {
+ "displaytext": "Small",
+ "name": "Small",
+ "disksize": 1
+ },
+ "virtual_machine": {
+ "displayname": "Test VM",
+ "username": "root",
+ "password": "password",
+ "ssh_port": 22,
+ "hypervisor": 'XenServer',
+ "privateport": 22,
+ "publicport": 22,
+ "protocol": 'TCP',
+ },
+ "volume": {
+ "diskname": "APP Data Volume",
+ "size": 1,
+ # in GBs
+ "diskdevice": "/dev/xvdb",
+ # Data Disk
+ },
+ "static_nat": {
+ "startport": 22,
+ "endport": 22,
+ "protocol": "TCP"
+ },
+ "network_offering": {
+ "name": 'Network offering-RVR services',
+ "displaytext": 'Network off-RVR services',
+ "guestiptype": 'Isolated',
+ "supportedservices": 'Vpn,Dhcp,Dns,SourceNat,PortForwarding,Firewall,Lb,UserData,StaticNat',
+ "traffictype": 'GUEST',
+ "availability": 'Optional',
+ "serviceProviderList": {
+ "Vpn": 'VirtualRouter',
+ "Dhcp": 'VirtualRouter',
+ "Dns": 'VirtualRouter',
+ "SourceNat": 'VirtualRouter',
+ "PortForwarding": 'VirtualRouter',
+ "Firewall": 'VirtualRouter',
+ "Lb": 'VirtualRouter',
+ "UserData": 'VirtualRouter',
+ "StaticNat": 'VirtualRouter',
+ },
+ "servicecapabilitylist": {
+ "SourceNat": {
+ "SupportedSourceNatTypes": "peraccount",
+ "RedundantRouter": 'true',
+ },
+ "lb": {
+ "SupportedLbIsolation": "dedicated"
+ },
+ },
+ },
+ "host": {
+ "username": "root",
+ "password": "password",
+ "publicport": 22,
+ },
+ "network": {
+ "name": "Test Network",
+ "displaytext": "Test Network",
+ },
+ "lbrule": {
+ "name": "SSH",
+ "alg": "roundrobin",
+ # Algorithm used for load balancing
+ "privateport": 22,
+ "publicport": 22,
+ "openfirewall": True,
+ },
+ "natrule": {
+ "privateport": 22,
+ "publicport": 22,
+ "protocol": "TCP"
+ },
+ "natrule_221": {
+ "privateport": 22,
+ "publicport": 221,
+ "protocol": "TCP"
+ },
+ "fw_rule": {
+ "startport": 1,
+ "endport": 6000,
+ "cidr": '55.55.0.0/11',
+ # Any network (For creating FW rule)
+ "protocol": 'TCP',
+ },
+ "ostype": 'CentOS 5.3 (64-bit)',
+ "sleep": 60,
+ "mode": 'advanced',
+ # Networking mode, Advanced, Basic
+ }
+
+
+class TestCreateRvRNetworkOffering(cloudstackTestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ cls.api_client = super(
+ TestCreateRvRNetworkOffering,
+ cls
+ ).getClsTestClient().getApiClient()
+ cls.services = Services().services
+ # Get Zone, Domain and templates
+ cls.domain = get_domain(cls.api_client, cls.services)
+ cls.zone = get_zone(cls.api_client, cls.services)
+ cls._cleanup = []
+ return
+
+ @classmethod
+ def tearDownClass(cls):
+ try:
+ #Cleanup resources used
+ 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.dbclient = self.testClient.getDbConnection()
+ self.cleanup = []
+ return
+
+ def tearDown(self):
+ try:
+ #Clean up, terminate the created network offerings
+ cleanup_resources(self.apiclient, self.cleanup)
+ except Exception as e:
+ raise Exception("Warning: Exception during cleanup : %s" % e)
+ return
+
+ @attr(tags=["advanced", "advancedns", "ssh"])
+ def test_createRvRNetworkOffering(self):
+ """Test create RvR supported network offering
+ """
+
+ # Steps to validate
+ # 1. create a network offering
+ # - all services by VirtualRouter
+ # - enable RedundantRouter servicecapability
+ # 2. enable the network offering
+ # Validate the following
+ # 1. Redundant Router offering should be created successfully and
+ # listed in listNetworkOfferings response
+
+ self.debug("Creating network offering with redundant VR capability")
+ try:
+ network_offering = NetworkOffering.create(
+ self.apiclient,
+ self.services["network_offering"],
+ conservemode=True
+ )
+ except Exception as e:
+ self.fail("Create network offering failed! - %s" % e)
+
+ self.debug("Enabling network offering - %s" % network_offering.name)
+ # Enable Network offering
+ network_offering.update(self.apiclient, state='Enabled')
+ self.cleanup.append(network_offering)
+
+ self.debug("Checking if the network offering created successfully?")
+ network_offs = NetworkOffering.list(
+ self.apiclient,
+ id=network_offering.id,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(network_offs, list),
+ True,
+ "List network offering should not return empty response"
+ )
+ self.assertEqual(
+ len(network_offs),
+ 1,
+ "List network off should have newly created network off"
+ )
+ return
+
+
+class TestCreateRvRNetwork(cloudstackTestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ cls.api_client = super(
+ TestCreateRvRNetwork,
+ cls
+ ).getClsTestClient().getApiClient()
+ cls.services = Services().services
+ # Get Zone, Domain and templates
+ cls.domain = get_domain(cls.api_client, cls.services)
+ cls.zone = get_zone(cls.api_client, cls.services)
+ cls.template = get_template(
+ cls.api_client,
+ cls.zone.id,
+ cls.services["ostype"]
+ )
+ cls.services["virtual_machine"]["zoneid"] = cls.zone.id
+ cls.services["virtual_machine"]["template"] = cls.template.id
+
+ cls.service_offering = ServiceOffering.create(
+ cls.api_client,
+ cls.services["service_offering"]
+ )
+ cls.network_offering = NetworkOffering.create(
+ cls.api_client,
+ cls.services["network_offering"],
+ conservemode=True
+ )
+ # Enable Network offering
+ cls.network_offering.update(cls.api_client, state='Enabled')
+
+ cls._cleanup = [
+ cls.service_offering,
+ cls.network_offering,
+ ]
+ return
+
+ @classmethod
+ def tearDownClass(cls):
+ try:
+ #Cleanup resources used
+ 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.dbclient = self.testClient.getDbConnection()
+ self.account = Account.create(
+ self.apiclient,
+ self.services["account"],
+ admin=True,
+ domainid=self.domain.id
+ )
+ self.cleanup = []
+ return
+
+ def tearDown(self):
+ try:
+ self.account.delete(self.apiclient)
+ interval = list_configurations(
+ self.apiclient,
+ name='account.cleanup.interval'
+ )
+ # Sleep to ensure that all resources are deleted
+ time.sleep(int(interval[0].value) * 2)
+ #Clean up, terminate the created network offerings
+ cleanup_resources(self.apiclient, self.cleanup)
+ except Exception as e:
+ raise Exception("Warning: Exception during cleanup : %s" % e)
+ return
+
+ @attr(tags=["advanced", "advancedns", "ssh"])
+ def test_createRvRNetwork(self):
+ """Test create network with redundant routers
+ """
+
+ # Validate the following:
+ # 1. listNetworkOfferings shows created offering
+ # 2. listNetworks should show created network in Allocated state
+ # 3. returns no Running routers in the network
+ # 4. listVirtualmachines shows VM in Running state
+ # 5. returns 2 routers
+ # - same public IP
+ # - same MAC address of public NIC
+ # - different guestip address
+ # - redundant state (MASTER or BACKUP)
+ # - same gateway for the public traffic
+ # 6. all routers, networks and user VMs are cleaned up
+
+ # Creating network using the network offering created
+ self.debug("Creating network with network offering: %s" %
+ self.network_offering.id)
+ network = Network.create(
+ self.apiclient,
+ self.services["network"],
+ accountid=self.account.account.name,
+ domainid=self.account.account.domainid,
+ networkofferingid=self.network_offering.id,
+ zoneid=self.zone.id
+ )
+ self.debug("Created network with ID: %s" % network.id)
+
+ networks = Network.list(
+ self.apiclient,
+ id=network.id,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(networks, list),
+ True,
+ "List networks should return a valid response for created network"
+ )
+ nw_response = networks[0]
+
+ self.debug("Network state: %s" % nw_response.state)
+ self.assertEqual(
+ nw_response.state,
+ "Allocated",
+ "The network should be in allocated state after creation"
+ )
+
+ self.debug("Listing routers for network: %s" % network.name)
+ routers = Router.list(
+ self.apiclient,
+ networkid=network.id,
+ listall=True
+ )
+ self.assertEqual(
+ routers,
+ None,
+ "Routers should not be spawned when network is in allocated state"
+ )
+
+ self.debug("Deploying VM in account: %s" % self.account.account.name)
+
+ # Spawn an instance in that network
+ virtual_machine = VirtualMachine.create(
+ self.apiclient,
+ self.services["virtual_machine"],
+ accountid=self.account.account.name,
+ domainid=self.account.account.domainid,
+ serviceofferingid=self.service_offering.id,
+ networkids=[str(network.id)]
+ )
+ self.debug("Deployed VM in network: %s" % network.id)
+
+ self.debug("Listing routers for network: %s" % network.name)
+ routers = Router.list(
+ self.apiclient,
+ networkid=network.id,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(routers, list),
+ True,
+ "list router should return Master and backup routers"
+ )
+ self.assertEqual(
+ len(routers),
+ 2,
+ "Length of the list router should be 2 (Backup & master)"
+ )
+
+ if routers[0].redundantstate == 'MASTER':
+ master_router = routers[0]
+ backup_router = routers[1]
+ else:
+ master_router = routers[1]
+ backup_router = routers[0]
+
+ self.debug("Redundant states: %s, %s" % (
+ master_router.redundantstate,
+ backup_router.redundantstate
+ ))
+ self.assertEqual(
+ master_router.publicip,
+ backup_router.publicip,
+ "Public Ip should be same for both(MASTER & BACKUP)"
+ )
+ self.assertEqual(
+ master_router.redundantstate,
+ "MASTER",
+ "Redundant state of router should be MASTER"
+ )
+ self.assertEqual(
+ backup_router.redundantstate,
+ "BACKUP",
+ "Redundant state of router should be BACKUP"
+ )
+ self.assertNotEqual(
+ master_router.guestipaddress,
+ backup_router.guestipaddress,
+ "Both (MASTER & BACKUP) routers should not have same guest IP"
+ )
+
+ self.assertNotEqual(
+ master_router.guestmacaddress,
+ backup_router.guestmacaddress,
+ "Both (MASTER & BACKUP) routers should not have same guestMAC"
+ )
+ return
+
+
+class TestCreateRvRNetworkNonDefaultGuestCidr(cloudstackTestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ cls.api_client = super(
+ TestCreateRvRNetworkNonDefaultGuestCidr,
+ cls
+ ).getClsTestClient().getApiClient()
+ cls.services = Services().services
+ # Get Zone, Domain and templates
+ cls.domain = get_domain(cls.api_client, cls.services)
+ cls.zone = get_zone(cls.api_client, cls.services)
+ cls.template = get_template(
+ cls.api_client,
+ cls.zone.id,
+ cls.services["ostype"]
+ )
+ cls.services["virtual_machine"]["zoneid"] = cls.zone.id
+ cls.services["virtual_machine"]["template"] = cls.template.id
+
+ cls.service_offering = ServiceOffering.create(
+ cls.api_client,
+ cls.services["service_offering"]
+ )
+ cls.network_offering = NetworkOffering.create(
+ cls.api_client,
+ cls.services["network_offering"],
+ conservemode=True
+ )
+ # Enable Network offering
+ cls.network_offering.update(cls.api_client, state='Enabled')
+
+ cls._cleanup = [
+ cls.service_offering,
+ cls.network_offering,
+ ]
+ return
+
+ @classmethod
+ def tearDownClass(cls):
+ try:
+ #Cleanup resources used
+ 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.dbclient = self.testClient.getDbConnection()
+ self.account = Account.create(
+ self.apiclient,
+ self.services["account"],
+ admin=True,
+ domainid=self.domain.id
+ )
+ self.cleanup = []
+ return
+
+ def tearDown(self):
+ try:
+ self.account.delete(self.apiclient)
+ interval = list_configurations(
+ self.apiclient,
+ name='account.cleanup.interval'
+ )
+ # Sleep to ensure that all resources are deleted
+ time.sleep(int(interval[0].value) * 2)
+ #Clean up, terminate the created network offerings
+ cleanup_resources(self.apiclient, self.cleanup)
+ except Exception as e:
+ raise Exception("Warning: Exception during cleanup : %s" % e)
+ return
+
+ @attr(tags=["advanced", "advancedns", "ssh"])
+ def test_createRvRNetwork(self):
+ """Test create network with redundant routers
+ """
+
+ # Validate the following:
+ # 1. listNetworkOfferings shows created offering
+ # 2. listNetworks should show created network in Allocated state
+ # - gw = 192.168.2.1 and cidr = 192.168.2.0/23
+ # 3. returns no Running routers in the network
+ # 4. listVirtualmachines shows VM in Running state
+ # 5. returns 2 routers
+ # - same public IP
+ # - same MAC address of public NIC
+ # - different guestip address
+ # - redundant state (MASTER or BACKUP)
+ # - same gateway for the public traffic
+ # 6. all routers, networks and user VMs are cleaned up
+
+ # Creating network using the network offering created
+ self.debug("Creating network with network offering: %s" %
+ self.network_offering.id)
+ network = Network.create(
+ self.apiclient,
+ self.services["network"],
+ accountid=self.account.account.name,
+ domainid=self.account.account.domainid,
+ networkofferingid=self.network_offering.id,
+ zoneid=self.zone.id,
+ guestcidr=' 192.168.2.0/23'
+ )
+ self.debug("Created network with ID: %s" % network.id)
+
+ networks = Network.list(
+ self.apiclient,
+ id=network.id,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(networks, list),
+ True,
+ "List networks should return a valid response for created network"
+ )
+ nw_response = networks[0]
+
+ self.debug("Network state: %s" % nw_response.state)
+ self.assertEqual(
+ nw_response.state,
+ "Allocated",
+ "The network should be in allocated state after creation"
+ )
+ self.assertEqual(
+ nw_response.gateway,
+ '192.168.2.1',
+ "The gateway should be 192.168.2.1"
+ )
+ self.assertEqual(
+ nw_response.cidr,
+ '192.168.2.0/23',
+ "Guest cidr should be 192.168.2.0/23"
+ )
+
+ self.debug("Listing routers for network: %s" % network.name)
+ routers = Router.list(
+ self.apiclient,
+ networkid=network.id,
+ listall=True
+ )
+ self.assertEqual(
+ routers,
+ None,
+ "Routers should not be spawned when network is in allocated state"
+ )
+
+ self.debug("Deploying VM in account: %s" % self.account.account.name)
+
+ # Spawn an instance in that network
+ virtual_machine = VirtualMachine.create(
+ self.apiclient,
+ self.services["virtual_machine"],
+ accountid=self.account.account.name,
+ domainid=self.account.account.domainid,
+ serviceofferingid=self.service_offering.id,
+ networkids=[str(network.id)]
+ )
+ self.debug("Deployed VM in network: %s" % network.id)
+
+ self.debug("Listing routers for network: %s" % network.name)
+ routers = Router.list(
+ self.apiclient,
+ networkid=network.id,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(routers, list),
+ True,
+ "list router should return Master and backup routers"
+ )
+ self.assertEqual(
+ len(routers),
+ 2,
+ "Length of the list router should be 2 (Backup & master)"
+ )
+
+ if routers[0].redundantstate == 'MASTER':
+ master_router = routers[0]
+ backup_router = routers[1]
+ else:
+ master_router = routers[1]
+ backup_router = routers[0]
+
+ self.assertEqual(
+ master_router.publicip,
+ backup_router.publicip,
+ "Public Ip should be same for both(MASTER & BACKUP)"
+ )
+ self.assertEqual(
+ master_router.redundantstate,
+ "MASTER",
+ "Redundant state of router should be MASTER"
+ )
+ self.assertEqual(
+ backup_router.redundantstate,
+ "BACKUP",
+ "Redundant state of router should be BACKUP"
+ )
+ self.assertNotEqual(
+ master_router.guestipaddress,
+ backup_router.guestipaddress,
+ "Both (MASTER & BACKUP) routers should not have same guest IP"
+ )
+
+ self.assertNotEqual(
+ master_router.guestmacaddress,
+ backup_router.guestmacaddress,
+ "Both (MASTER & BACKUP) routers should not have same guestMAC"
+ )
+ return
+
+
+class TestRVRInternals(cloudstackTestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ cls.api_client = super(
+ TestRVRInternals,
+ cls
+ ).getClsTestClient().getApiClient()
+ cls.services = Services().services
+ # Get Zone, Domain and templates
+ cls.domain = get_domain(cls.api_client, cls.services)
+ cls.zone = get_zone(cls.api_client, cls.services)
+ cls.template = get_template(
+ cls.api_client,
+ cls.zone.id,
+ cls.services["ostype"]
+ )
+ cls.services["virtual_machine"]["zoneid"] = cls.zone.id
+ cls.services["virtual_machine"]["template"] = cls.template.id
+
+ cls.service_offering = ServiceOffering.create(
+ cls.api_client,
+ cls.services["service_offering"]
+ )
+ cls.network_offering = NetworkOffering.create(
+ cls.api_client,
+ cls.services["network_offering"],
+ conservemode=True
+ )
+ # Enable Network offering
+ cls.network_offering.update(cls.api_client, state='Enabled')
+
+ cls._cleanup = [
+ cls.service_offering,
+ cls.network_offering,
+ ]
+ return
+
+ @classmethod
+ def tearDownClass(cls):
+ try:
+ #Cleanup resources used
+ 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.dbclient = self.testClient.getDbConnection()
+ self.account = Account.create(
+ self.apiclient,
+ self.services["account"],
+ admin=True,
+ domainid=self.domain.id
+ )
+ self.cleanup = []
+ return
+
+ def tearDown(self):
+ try:
+ self.account.delete(self.apiclient)
+ interval = list_configurations(
+ self.apiclient,
+ name='account.cleanup.interval'
+ )
+ # Sleep to ensure that all resources are deleted
+ time.sleep(int(interval[0].value) * 2)
+ #Clean up, terminate the created network offerings
+ cleanup_resources(self.apiclient, self.cleanup)
+ except Exception as e:
+ raise Exception("Warning: Exception during cleanup : %s" % e)
+ return
+
+ @attr(tags=["advanced", "advancedns", "ssh"])
+ def test_redundantVR_internals(self):
+ """Test redundant router internals
+ """
+
+ # Steps to validate
+ # 1. createNetwork using network offering for redundant virtual router
+ # 2. listRouters in above network
+ # 3. deployVM in above user account in the created network
+ # 4. login to both Redundant Routers
+ # 5. login to user VM
+ # 6. delete user account
+ # Validate the following:
+ # 1. listNetworks lists network in Allocated state
+ # 2. listRouters lists no routers created yet
+ # 3. listRouters returns Master and Backup routers
+ # 4. ssh in to both routers and verify:
+ # - MASTER router has eth2 with public Ip address
+ # - BACKUP router has only guest eth0 and link local eth1
+ # - Broadcast on MASTER eth2 is non-zero (0.0.0.0)
+ # - execute checkrouter.sh in router home and check if it is status
+ # "MASTER|BACKUP" as returned by the listRouters API
+ # 5. DNS of the user VM is set to RedundantRouter Gateway
+ # (/etc/resolv.conf)
+ # Check that the default gateway for the guest is the rvr gateway
+ # and not the guestIp of either of the RvRs
+
+ # Creating network using the network offering created
+ self.debug("Creating network with network offering: %s" %
+ self.network_offering.id)
+ network = Network.create(
+ self.apiclient,
+ self.services["network"],
+ accountid=self.account.account.name,
+ domainid=self.account.account.domainid,
+ networkofferingid=self.network_offering.id,
+ zoneid=self.zone.id
+ )
+ self.debug("Created network with ID: %s" % network.id)
+
+ networks = Network.list(
+ self.apiclient,
+ id=network.id,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(networks, list),
+ True,
+ "List networks should return a valid response for created network"
+ )
+ nw_response = networks[0]
+
+ self.debug("Network state: %s" % nw_response.state)
+ self.assertEqual(
+ nw_response.state,
+ "Allocated",
+ "The network should be in allocated state after creation"
+ )
+
+ self.debug("Listing routers for network: %s" % network.name)
+ routers = Router.list(
+ self.apiclient,
+ networkid=network.id,
+ listall=True
+ )
+ self.assertEqual(
+ routers,
+ None,
+ "Routers should not be spawned when network is in allocated state"
+ )
+
+ self.debug("Deploying VM in account: %s" % self.account.account.name)
+
+ # Spawn an instance in that network
+ virtual_machine = VirtualMachine.create(
+ self.apiclient,
+ self.services["virtual_machine"],
+ accountid=self.account.account.name,
+ domainid=self.account.account.domainid,
+ serviceofferingid=self.service_offering.id,
+ networkids=[str(network.id)]
+ )
+ self.debug("Deployed VM in network: %s" % network.id)
+
+ self.debug("Listing routers for network: %s" % network.name)
+ routers = Router.list(
+ self.apiclient,
+ networkid=network.id,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(routers, list),
+ True,
+ "list router should return Master and backup routers"
+ )
+ self.assertEqual(
+ len(routers),
+ 2,
+ "Length of the list router should be 2 (Backup & master)"
+ )
+
+ if routers[0].redundantstate == 'MASTER':
+ master_router = routers[0]
+ backup_router = routers[1]
+ else:
+ master_router = routers[1]
+ backup_router = routers[0]
+
+ self.debug("Fetching the host details for double hop into router")
+
+ hosts = Host.list(
+ self.apiclient,
+ id=master_router.hostid,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(hosts, list),
+ True,
+ "List hosts should return a valid list"
+ )
+ master_host = hosts[0]
+ self.debug("Host for master router: %s" % master_host.name)
+ self.debug("Host for master router: %s" % master_host.ipaddress)
+
+ hosts = Host.list(
+ self.apiclient,
+ id=backup_router.hostid,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(hosts, list),
+ True,
+ "List hosts should return a valid list"
+ )
+ backup_host = hosts[0]
+ self.debug("Host for backup router: %s" % backup_host.name)
+ self.debug("Host for backup router: %s" % backup_host.ipaddress)
+ self.debug(master_router.linklocalip)
+
+ # Check eth2 port for master router
+ if self.apiclient.hypervisor.lower() == 'vmware':
+ result = get_process_status(
+ self.apiclient.connection.mgtSvr,
+ 22,
+ self.apiclient.connection.user,
+ self.apiclient.connection.passwd,
+ master_router.linklocalip,
+ 'ifconfig eth2',
+ hypervisor=self.apiclient.hypervisor
+ )
+ else:
+ result = get_process_status(
+ host.ipaddress,
+ self.services['host']["publicport"],
+ self.services['host']["username"],
+ self.services['host']["password"],
+ master_router.linklocalip,
+ 'ifconfig eth2'
+ )
+
+ res = str(result)
+
+ self.debug("Command 'ifconfig eth2': %s" % result)
+ self.debug("Router's public Ip: %s" % master_router.publicip)
+ self.assertEqual(
+ res.count(master_router.publicip),
+ 1,
+ "master router should have the public IP configured"
+ )
+ self.assertEqual(
+ result.count('Bcast:0.0.0.0'),
+ 0,
+ "Broadcast address of eth2 should not be 0.0.0.0"
+ )
+
+ # Check eth2 port for backup router
+ if self.apiclient.hypervisor.lower() == 'vmware':
+ result = get_process_status(
+ self.apiclient.connection.mgtSvr,
+ 22,
+ self.apiclient.connection.user,
+ self.apiclient.connction.passwd,
+ backup_router.linklocalip,
+ 'ifconfig eth2',
+ hypervisor=self.apiclient.hypervisor
+ )
+ else:
+ result = get_process_status(
+ host.ipaddress,
+ self.services['host']["publicport"],
+ self.services['host']["username"],
+ self.services['host']["password"],
+ backup_router.linklocalip,
+ 'ifconfig eth2'
+ )
+ res = str(result)
+
+ self.debug("Command 'ifconfig eth2': %s" % result)
+ self.assertEqual(
+ res.count('Bcast:0.0.0.0'),
+ 1,
+ "backup router should NOT have the public IP configured"
+ )
+ vms = VirtualMachine.list(
+ self.apiclient,
+ id=virtual_machine.id,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(vms, list),
+ True,
+ "List VMs should not return empty response"
+ )
+ vm = vms[0]
+
+ self.assertNotEqual(
+ vm.nic[0].gateway,
+ master_router.publicip,
+ "The gateway of user VM should be same as master router"
+ )
+
+ self.assertNotEqual(
+ vm.nic[0].gateway,
+ backup_router.publicip,
+ "The gateway of user VM should be same as backup router"
+ )
+
+ return
+
+
+class TestRedundancy(cloudstackTestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ cls.api_client = super(
+ TestRedundancy,
+ cls
+ ).getClsTestClient().getApiClient()
+ cls.services = Services().services
+ # Get Zone, Domain and templates
+ cls.domain = get_domain(cls.api_client, cls.services)
+ cls.zone = get_zone(cls.api_client, cls.services)
+ cls.template = get_template(
+ cls.api_client,
+ cls.zone.id,
+ cls.services["ostype"]
+ )
+ cls.services["virtual_machine"]["zoneid"] = cls.zone.id
+ cls.services["virtual_machine"]["template"] = cls.template.id
+
+ cls.service_offering = ServiceOffering.create(
+ cls.api_client,
+ cls.services["service_offering"]
+ )
+ cls.network_offering = NetworkOffering.create(
+ cls.api_client,
+ cls.services["network_offering"],
+ conservemode=True
+ )
+ # Enable Network offering
+ cls.network_offering.update(cls.api_client, state='Enabled')
+
+ cls._cleanup = [
+ cls.service_offering,
+ cls.network_offering,
+ ]
+ return
+
+ @classmethod
+ def tearDownClass(cls):
+ try:
+ #Cleanup resources used
+ 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.dbclient = self.testClient.getDbConnection()
+ self.account = Account.create(
+ self.apiclient,
+ self.services["account"],
+ admin=True,
+ domainid=self.domain.id
+ )
+ # Creating network using the network offering created
+ self.debug("Creating network with network offering: %s" %
+ self.network_offering.id)
+ self.network = Network.create(
+ self.apiclient,
+ self.services["network"],
+ accountid=self.account.account.name,
+ domainid=self.account.account.domainid,
+ networkofferingid=self.network_offering.id,
+ zoneid=self.zone.id
+ )
+ self.debug("Created network with ID: %s" % self.network.id)
+ self.debug("Deploying VM in account: %s" % self.account.account.name)
+
+ # Spawn an instance in that network
+ self.virtual_machine = VirtualMachine.create(
+ self.apiclient,
+ self.services["virtual_machine"],
+ accountid=self.account.account.name,
+ domainid=self.account.account.domainid,
+ serviceofferingid=self.service_offering.id,
+ networkids=[str(self.network.id)]
+ )
+ self.debug("Deployed VM in network: %s" % self.network.id)
+ self.cleanup = []
+ return
+
+ def tearDown(self):
+ try:
+ self.account.delete(self.apiclient)
+ interval = list_configurations(
+ self.apiclient,
+ name='account.cleanup.interval'
+ )
+ # Sleep to ensure that all resources are deleted
+ time.sleep(int(interval[0].value) * 2)
+ #Clean up, terminate the created network offerings
+ cleanup_resources(self.apiclient, self.cleanup)
+ except Exception as e:
+ raise Exception("Warning: Exception during cleanup : %s" % e)
+ return
+
+ @attr(tags=["advanced", "advancedns", "ssh"])
+ def test_stopMasterRvR(self):
+ """Test stop MASTER RVR
+ """
+
+ # Steps to validate
+ # 1. createNetwork using network offering for redundant virtual router
+ # listNetworks returns the allocated network
+ # 2. listRouters in above network. Lists no routers in the created
+ # network
+ # 3. deployVM in above user account in the created network. VM is
+ # successfully Running
+ # 4. listRouters that has redundantstate=MASTER. only one router is
+ # returned with redundantstate = MASTER for this network
+ # 5. stopRouter that is Master. Router goes to stopped state
+ # successfully
+ # 6. listRouters in the account and in the network. Lists old MASTER
+ # router in redundantstate=UNKNOWN, and the old BACKUP router as
+ # new MASTER
+ # 7. start the stopped router. Stopped rvr starts up successfully and
+ # is in Running state
+ # 8. listRouters in the account and in the network. Router shows up as
+ # BACKUP and NOT MASTER, should have only one BACKUP and one MASTER
+ # at the end, public IP of the SourceNAT should remain same after
+ # reboot
+ # 9. delete the account
+
+ self.debug("Listing routers for network: %s" % self.network.name)
+ routers = Router.list(
+ self.apiclient,
+ networkid=self.network.id,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(routers, list),
+ True,
+ "list router should return Master and backup routers"
+ )
+ self.assertEqual(
+ len(routers),
+ 2,
+ "Length of the list router should be 2 (Backup & master)"
+ )
+
+ if routers[0].redundantstate == 'MASTER':
+ master_router = routers[0]
+ backup_router = routers[1]
+ else:
+ master_router = routers[1]
+ backup_router = routers[0]
+
+ self.debug("Stopping the MASTER router")
+ try:
+ cmd = stopRouter.stopRouter(cmd)
+ cmd.id = master_router.id
+ self.apiclient.stopRouter(cmd)
+ except Exception as e:
+ self.fail("Failed to stop master router: %s" % e)
+
+ self.debug("Listing routers for network: %s" % self.network.name)
+ routers = Router.list(
+ self.apiclient,
+ networkid=self.network.id,
+ id=master_router.id,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(routers, list),
+ True,
+ "list router should return Master and backup routers"
+ )
+ self.assertEqual(
+ routers[0].redundantstate,
+ 'UNKNOWN',
+ "Redundant state of the router should be UNKNOWN"
+ )
+
+ self.debug("Listing routers for network: %s" % self.network.name)
+ routers = Router.list(
+ self.apiclient,
+ networkid=self.network.id,
+ id=backup_router.id,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(routers, list),
+ True,
+ "list router should return Master and backup routers"
+ )
+ self.assertEqual(
+ routers[0].redundantstate,
+ 'MASTER',
+ "Redundant state of the router should be MASTER"
+ )
+
+ self.debug("Starting the old MASTER router")
+ try:
+ cmd = startRouter.startRouter(cmd)
+ cmd.id = master_router.id
+ self.apiclient.startRouter(cmd)
+ self.debug("old MASTER router started")
+ except Exception as e:
+ self.fail("Failed to stop master router: %s" % e)
+
+ self.debug("Listing routers for network: %s" % self.network.name)
+ routers = Router.list(
+ self.apiclient,
+ networkid=self.network.id,
+ id=master_router.id,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(routers, list),
+ True,
+ "list router should return backup router"
+ )
+ self.assertEqual(
+ routers[0].redundantstate,
+ 'BACKUP',
+ "Redundant state of the router should be BACKUP"
+ )
+ self.assertEqual(
+ master_router.publicip,
+ routers[0].publicip,
+ "Public IP should be same after reboot"
+ )
+ return
+
+ @attr(tags=["advanced", "advancedns", "ssh"])
+ def test_stopBackupRvR(self):
+ """Test stop BACKUP RVR
+ """
+
+ # Steps to validate
+ # 1. createNetwork using network offering for redundant virtual router
+ # listNetworks returns the allocated network
+ # 2. listRouters in above network. Lists no routers in the created
+ # network
+ # 3. deployVM in above user account in the created network. VM is
+ # successfully Running
+ # 4. listRouters that has redundantstate=MASTER. only one router is
+ # returned with redundantstate = MASTER for this network
+ # 5. stopRouter that is BACKUP. Router goes to stopped state
+ # successfully
+ # 6. listRouters in the account and in the network. Lists old MASTER
+ # router in redundantstate=UNKNOWN
+ # 7. start the stopped router. Stopped rvr starts up successfully and
+ # is in Running state
+ # 8. listRouters in the account and in the network. Router shows up as
+ # BACKUP and NOT MASTER, should have only one BACKUP and one MASTER
+ # at the end, public IP of the SourceNAT should remain same after
+ # reboot
+ # 9. delete the account
+
+ self.debug("Listing routers for network: %s" % self.network.name)
+ routers = Router.list(
+ self.apiclient,
+ networkid=self.network.id,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(routers, list),
+ True,
+ "list router should return Master and backup routers"
+ )
+ self.assertEqual(
+ len(routers),
+ 2,
+ "Length of the list router should be 2 (Backup & master)"
+ )
+
+ if routers[0].redundantstate == 'MASTER':
+ master_router = routers[0]
+ backup_router = routers[1]
+ else:
+ master_router = routers[1]
+ backup_router = routers[0]
+
+ self.debug("Stopping the BACKUP router")
+ try:
+ cmd = stopRouter.stopRouter(cmd)
+ cmd.id = backup_router.id
+ self.apiclient.stopRouter(cmd)
+ except Exception as e:
+ self.fail("Failed to stop backup router: %s" % e)
+
+ self.debug("Listing routers for network: %s" % self.network.name)
+ routers = Router.list(
+ self.apiclient,
+ networkid=self.network.id,
+ id=backup_router.id,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(routers, list),
+ True,
+ "list router should return Master and backup routers"
+ )
+ self.assertEqual(
+ routers[0].redundantstate,
+ 'UNKNOWN',
+ "Redundant state of the router should be UNKNOWN"
+ )
+
+ self.debug("Listing routers for network: %s" % self.network.name)
+ routers = Router.list(
+ self.apiclient,
+ networkid=self.network.id,
+ id=master_router.id,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(routers, list),
+ True,
+ "list router should return Master and backup routers"
+ )
+ self.assertEqual(
+ routers[0].redundantstate,
+ 'MASTER',
+ "Redundant state of the router should be MASTER"
+ )
+
+ self.debug("Starting the old BACKUP router")
+ try:
+ cmd = startRouter.startRouter(cmd)
+ cmd.id = backup_router.id
+ self.apiclient.startRouter(cmd)
+ self.debug("old BACKUP router started")
+ except Exception as e:
+ self.fail("Failed to stop master router: %s" % e)
+
+ self.debug("Listing routers for network: %s" % self.network.name)
+ routers = Router.list(
+ self.apiclient,
+ networkid=self.network.id,
+ id=backup_router.id,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(routers, list),
+ True,
+ "list router should return backup router"
+ )
+ self.assertEqual(
+ routers[0].redundantstate,
+ 'BACKUP',
+ "Redundant state of the router should be BACKUP"
+ )
+ self.assertEqual(
+ backup_router.publicip,
+ routers[0].publicip,
+ "Public IP should be same after reboot"
+ )
+ return
+
+ @attr(tags=["advanced", "advancedns", "ssh"])
+ def test_rebootMasterRvR(self):
+ """Test reboot master RVR
+ """
+
+ # Steps to validate
+ # 1. createNetwork using network offering for redundant virtual router
+ # listNetworks returns the allocated network
+ # 2. listRouters in above network. Lists no routers in the created
+ # network
+ # 3. deployVM in above user account in the created network. VM is
+ # successfully Running
+ # 4. listRouters that has redundantstate=MASTER. only one router is
+ # returned with redundantstate = MASTER for this network
+ # 5. reboot router that is MASTER. Router reboots state
+ # successfully
+ # 6. lists old MASTER router in redundantstate=BACKUP and the old
+ # BACKUP router as new MASTER + public IP of the SourceNAT should
+ # remain same after the reboot
+
+ self.debug("Listing routers for network: %s" % self.network.name)
+ routers = Router.list(
+ self.apiclient,
+ networkid=self.network.id,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(routers, list),
+ True,
+ "list router should return Master and backup routers"
+ )
+ self.assertEqual(
+ len(routers),
+ 2,
+ "Length of the list router should be 2 (Backup & master)"
+ )
+
+ if routers[0].redundantstate == 'MASTER':
+ master_router = routers[0]
+ backup_router = routers[1]
+ else:
+ master_router = routers[1]
+ backup_router = routers[0]
+
+ self.debug("Rebooting the master router")
+ try:
+ cmd = rebootRouter.rebootRouter(cmd)
+ cmd.id = master_router.id
+ self.apiclient.rebootRouter(cmd)
+ except Exception as e:
+ self.fail("Failed to reboot MASTER router: %s" % e)
+
+ self.debug("Listing routers for network: %s" % self.network.name)
+ routers = Router.list(
+ self.apiclient,
+ networkid=self.network.id,
+ id=master_router.id,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(routers, list),
+ True,
+ "list router should return Master and backup routers"
+ )
+ self.assertEqual(
+ routers[0].redundantstate,
+ 'BACKUP',
+ "Redundant state of the router should be BACKUP"
+ )
+
+ self.debug("Listing routers for network: %s" % self.network.name)
+ routers = Router.list(
+ self.apiclient,
+ networkid=self.network.id,
+ id=backup_router.id,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(routers, list),
+ True,
+ "list router should return Master and backup routers"
+ )
+ self.assertEqual(
+ routers[0].redundantstate,
+ 'MASTER',
+ "Redundant state of the router should be MASTER"
+ )
+ self.assertEqual(
+ master_router.publicip,
+ routers[0].publicip,
+ "Public IP should be same after reboot"
+ )
+ return
+
+ @attr(tags=["advanced", "advancedns", "ssh"])
+ def test_rebootBackupRvR(self):
+ """Test reboot backup RVR
+ """
+
+ # Steps to validate
+ # 1. createNetwork using network offering for redundant virtual router
+ # listNetworks returns the allocated network
+ # 2. listRouters in above network. Lists no routers in the created
+ # network
+ # 3. deployVM in above user account in the created network. VM is
+ # successfully Running
+ # 4. listRouters that has redundantstate=MASTER. only one router is
+ # returned with redundantstate = MASTER for this network
+ # 5. reboot router that is BACKUP. Router reboots state
+ # successfully
+ # 6. lists old BACKUP router in redundantstate=BACKUP, and the old
+ # MASTER router is still MASTER+ public IP of the SourceNAT should
+ # remain same after the reboot
+
+ self.debug("Listing routers for network: %s" % self.network.name)
+ routers = Router.list(
+ self.apiclient,
+ networkid=self.network.id,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(routers, list),
+ True,
+ "list router should return Master and backup routers"
+ )
+ self.assertEqual(
+ len(routers),
+ 2,
+ "Length of the list router should be 2 (Backup & master)"
+ )
+
+ if routers[0].redundantstate == 'MASTER':
+ master_router = routers[0]
+ backup_router = routers[1]
+ else:
+ master_router = routers[1]
+ backup_router = routers[0]
+
+ self.debug("Rebooting the backuo router")
+ try:
+ cmd = rebootRouter.rebootRouter(cmd)
+ cmd.id = backup_router.id
+ self.apiclient.rebootRouter(cmd)
+ except Exception as e:
+ self.fail("Failed to reboot BACKUP router: %s" % e)
+
+ self.debug("Listing routers for network: %s" % self.network.name)
+ routers = Router.list(
+ self.apiclient,
+ networkid=self.network.id,
+ id=backup_router.id,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(routers, list),
+ True,
+ "list router should return Master and backup routers"
+ )
+ self.assertEqual(
+ routers[0].redundantstate,
+ 'BACKUP',
+ "Redundant state of the router should be BACKUP"
+ )
+
+ self.debug("Listing routers for network: %s" % self.network.name)
+ routers = Router.list(
+ self.apiclient,
+ networkid=self.network.id,
+ id=master_router.id,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(routers, list),
+ True,
+ "list router should return Master and backup routers"
+ )
+ self.assertEqual(
+ routers[0].redundantstate,
+ 'MASTER',
+ "Redundant state of the router should be MASTER"
+ )
+ self.assertEqual(
+ master_router.publicip,
+ routers[0].publicip,
+ "Public IP should be same after reboot"
+ )
+ return
+
+ @attr(tags=["advanced", "advancedns", "ssh"])
+ def test_stopBackupRvR_startInstance(self):
+ """Test stop backup RVR and start instance
+ """
+
+ # Steps to validate
+ # 1. createNetwork using network offering for redundant virtual router
+ # listNetworks returns the allocated network
+ # 2. listRouters in above network. Lists no routers in the created
+ # network
+ # 3. deployVM in above user account in the created network. VM is
+ # successfully Running
+ # 4. listRouters that has redundantstate=MASTER. only one router is
+ # returned with redundantstate = MASTER for this network
+ # 5. stop router that is BACKUP.
+ # 6. listRouters in the account and in the network
+ # 7. deployVM in the user account in the created network
+ # 8. listRouters in the account and in the network
+ # 9. delete the account
+
+ self.debug("Listing routers for network: %s" % self.network.name)
+ routers = Router.list(
+ self.apiclient,
+ networkid=self.network.id,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(routers, list),
+ True,
+ "list router should return Master and backup routers"
+ )
+ self.assertEqual(
+ len(routers),
+ 2,
+ "Length of the list router should be 2 (Backup & master)"
+ )
+
+ if routers[0].redundantstate == 'MASTER':
+ master_router = routers[0]
+ backup_router = routers[1]
+ else:
+ master_router = routers[1]
+ backup_router = routers[0]
+
+ self.debug("Stopping the backup router")
+ try:
+ cmd = stopRouter.stopRouter(cmd)
+ cmd.id = backup_router.id
+ self.apiclient.stopRouter(cmd)
+ except Exception as e:
+ self.fail("Failed to stop BACKUP router: %s" % e)
+
+ self.debug("Listing routers for network: %s" % self.network.name)
+ routers = Router.list(
+ self.apiclient,
+ networkid=self.network.id,
+ id=backup_router.id,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(routers, list),
+ True,
+ "list router should return Master and backup routers"
+ )
+ self.assertEqual(
+ routers[0].redundantstate,
+ 'UNKNOWN',
+ "Redundant state of the router should be UNKNOWN"
+ )
+
+ # Spawn an instance in that network
+ vm_2 = VirtualMachine.create(
+ self.apiclient,
+ self.services["virtual_machine"],
+ accountid=self.account.account.name,
+ domainid=self.account.account.domainid,
+ serviceofferingid=self.service_offering.id,
+ networkids=[str(network.id)]
+ )
+ self.debug("Deployed VM in network: %s" % network.id)
+
+ vms = VirtualMachine.list(
+ self.apiclient,
+ id=vm_2.id,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(vms, list),
+ True,
+ "List Vms should return a valid list"
+ )
+ vm = vms[0]
+ self.assertEqual(
+ vm.state,
+ "Running",
+ "Vm should be in running state after deployment"
+ )
+
+ self.debug("Listing routers for network: %s" % self.network.name)
+ routers = Router.list(
+ self.apiclient,
+ networkid=self.network.id,
+ id=backup_router.id,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(routers, list),
+ True,
+ "list router should return Master and backup routers"
+ )
+ self.assertEqual(
+ routers[0].redundantstate,
+ 'BACKUP',
+ "Redundant state of the router should be BACKUP"
+ )
+ return
+
+
+class TestApplyAndDeleteNetworkRulesOnRvR(cloudstackTestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ cls.api_client = super(
+ TestApplyAndDeleteNetworkRulesOnRvR,
+ cls
+ ).getClsTestClient().getApiClient()
+ cls.services = Services().services
+ # Get Zone, Domain and templates
+ cls.domain = get_domain(cls.api_client, cls.services)
+ cls.zone = get_zone(cls.api_client, cls.services)
+ cls.template = get_template(
+ cls.api_client,
+ cls.zone.id,
+ cls.services["ostype"]
+ )
+ cls.services["virtual_machine"]["zoneid"] = cls.zone.id
+ cls.services["virtual_machine"]["template"] = cls.template.id
+
+ cls.service_offering = ServiceOffering.create(
+ cls.api_client,
+ cls.services["service_offering"]
+ )
+ cls.network_offering = NetworkOffering.create(
+ cls.api_client,
+ cls.services["network_offering"],
+ conservemode=True
+ )
+ # Enable Network offering
+ cls.network_offering.update(cls.api_client, state='Enabled')
+
+ cls._cleanup = [
+ cls.service_offering,
+ cls.network_offering,
+ ]
+ return
+
+ @classmethod
+ def tearDownClass(cls):
+ try:
+ #Cleanup resources used
+ 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.dbclient = self.testClient.getDbConnection()
+ self.account = Account.create(
+ self.apiclient,
+ self.services["account"],
+ admin=True,
+ domainid=self.domain.id
+ )
+ self.cleanup = []
+ return
+
+ def tearDown(self):
+ try:
+ self.account.delete(self.apiclient)
+ interval = list_configurations(
+ self.apiclient,
+ name='account.cleanup.interval'
+ )
+ # Sleep to ensure that all resources are deleted
+ time.sleep(int(interval[0].value) * 2)
+ #Clean up, terminate the created network offerings
+ cleanup_resources(self.apiclient, self.cleanup)
+ except Exception as e:
+ raise Exception("Warning: Exception during cleanup : %s" % e)
+ return
+
+ @attr(tags=["advanced", "advancedns", "ssh"])
+ def test_apply_and__delete_NetworkRulesOnRvR(self):
+ """Test apply and delete network rules on redundant router
+ """
+
+ # Steps to validate
+ # 1. listNetworks should show the created network in allocated state
+ # 2. listRouters returns no running routers
+ # 3. VMs should be deployed and in Running state
+ # 4. should list MASTER and BACKUP routers
+ # 5. listPublicIpAddresses for networkid should show acquired IP
+ # 6. listRemoteAccessVpns for the network associated should show the
+ # VPN created
+ # 7. listRemoteAccessVpns for the network associated should return
+ # empty response
+
+ # Creating network using the network offering created
+ self.debug("Creating network with network offering: %s" %
+ self.network_offering.id)
+ network = Network.create(
+ self.apiclient,
+ self.services["network"],
+ accountid=self.account.account.name,
+ domainid=self.account.account.domainid,
+ networkofferingid=self.network_offering.id,
+ zoneid=self.zone.id
+ )
+ self.debug("Created network with ID: %s" % network.id)
+
+ networks = Network.list(
+ self.apiclient,
+ id=network.id,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(networks, list),
+ True,
+ "List networks should return a valid response for created network"
+ )
+ nw_response = networks[0]
+
+ self.debug("Network state: %s" % nw_response.state)
+ self.assertEqual(
+ nw_response.state,
+ "Allocated",
+ "The network should be in allocated state after creation"
+ )
+
+ self.debug("Listing routers for network: %s" % network.name)
+ routers = Router.list(
+ self.apiclient,
+ networkid=network.id,
+ listall=True
+ )
+ self.assertEqual(
+ routers,
+ None,
+ "Routers should not be spawned when network is in allocated state"
+ )
+
+ self.debug("Deploying VM in account: %s" % self.account.account.name)
+
+ # Spawn an instance in that network
+ virtual_machine = VirtualMachine.create(
+ self.apiclient,
+ self.services["virtual_machine"],
+ accountid=self.account.account.name,
+ domainid=self.account.account.domainid,
+ serviceofferingid=self.service_offering.id,
+ networkids=[str(network.id)]
+ )
+ self.debug("Deployed VM in network: %s" % network.id)
+
+ vms = VirtualMachine.list(
+ self.apiclient,
+ id=virtual_machine.id,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(vms, list),
+ True,
+ "List Vms should return a valid list"
+ )
+ vm = vms[0]
+ self.assertEqual(
+ vm.state,
+ "Running",
+ "Vm should be in running state after deployment"
+ )
+
+ self.debug("Listing routers for network: %s" % network.name)
+ routers = Router.list(
+ self.apiclient,
+ networkid=network.id,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(routers, list),
+ True,
+ "list router should return Master and backup routers"
+ )
+ self.assertEqual(
+ len(routers),
+ 2,
+ "Length of the list router should be 2 (Backup & master)"
+ )
+
+ self.debug("Associating public IP for network: %s" % network.name)
+ public_ip = PublicIPAddress.create(
+ self.apiclient,
+ accountid=self.account.account.name,
+ zoneid=self.zone.id,
+ domainid=self.account.account.domainid,
+ networkid=network.id
+ )
+ self.debug("Associated %s with network %s" % (
+ public_ip.ipaddress.ipaddress,
+ network.id
+ ))
+ self.debug("Enabling static NAT for IP: %s" %
+ public_ip.ipaddress.ipaddress)
+ try:
+ static_nat = StaticNATRule.create(
+ self.apiclient,
+ self.services["fw_rule"],
+ ipaddressid=public_ip.ipaddress.id
+ )
+ self.debug("Static NAT enabled for IP: %s" %
+ public_ip.ipaddress.ipaddress)
+ static_nat.enable(
+ self.apiclient,
+ ipaddressid=public_ip.ipaddress.id,
+ virtualmachineid=virtual_machine.id
+ )
+ except Exception as e:
+ self.fail("Failed to enable static NAT on IP: %s - %s" % (
+ public_ip.ipaddress.ipaddress, e))
+
+ public_ips = PublicIPAddress.list(
+ self.apiclient,
+ networkid=network.id,
+ listall=True,
+ isstaticnat=True
+ )
+ self.assertEqual(
+ isinstance(public_ips, list),
+ True,
+ "List public Ip for network should list the Ip addr"
+ )
+ self.assertEqual(
+ public_ips[0].ipaddress,
+ public_ip.ipaddress.ipaddress,
+ "List public Ip for network should list the Ip addr"
+ )
+
+ self.debug("creating a FW rule on IP: %s" %
+ public_ip.ipaddress.ipaddress)
+ fw_rule = FireWallRule.create(
+ self.apiclient,
+ ipaddressid=public_ip.ipaddress.id,
+ protocol='TCP',
+ cidrlist=[self.services["fw_rule"]["cidr"]],
+ startport=self.services["fw_rule"]["startport"],
+ endport=self.services["fw_rule"]["endport"]
+ )
+ self.debug("Created a firewall rule on 22 port of IP: %s" %
+ public_ip.ipaddress.ipaddress)
+
+ self.debug("Trying to SSH into the virtual machine")
+ try:
+ virtual_machine.get_ssh_client(
+ ipaddress=public_ip.ipaddress.ipaddress)
+ self.debug("SSH to guest VM succeeded")
+ except Exception as e:
+ self.fail("SSH to guest VM failed: %s" % e)
+
+ self.debug("Associating public IP for network: %s" % network.name)
+ public_ip_2 = PublicIPAddress.create(
+ self.apiclient,
+ accountid=self.account.account.name,
+ zoneid=self.zone.id,
+ domainid=self.account.account.domainid,
+ networkid=network.id
+ )
+ self.debug("Associated %s with network %s" % (
+ public_ip_2.ipaddress.ipaddress,
+ network.id
+ ))
+
+ nat_rule = NATRule.create(
+ self.apiclient,
+ virtual_machine,
+ self.services["natrule_221"],
+ ipaddressid=public_ip_2.ipaddress.id,
+ openfirewall=True
+ )
+
+ self.debug("Trying to SSH into the virtual machine")
+ try:
+ virtual_machine.get_ssh_client(
+ ipaddress=public_ip_2.ipaddress.ipaddress,
+ reconnect=True,
+ port=self.services["natrule_221"]["publicport"]
+ )
+ self.debug("SSH to guest VM succeeded")
+ except Exception as e:
+ self.fail("SSH to guest VM failed: %s" % e)
+
+ self.debug("Associating public IP for network: %s" % network.name)
+ public_ip_3 = PublicIPAddress.create(
+ self.apiclient,
+ accountid=self.account.account.name,
+ zoneid=self.zone.id,
+ domainid=self.account.account.domainid,
+ networkid=network.id
+ )
+ self.debug("Associated %s with network %s" % (
+ public_ip_3.ipaddress.ipaddress,
+ network.id
+ ))
+
+ self.debug("Creating LB rule for IP address: %s" %
+ public_ip_3.ipaddress.ipaddress)
+
+ lb_rule = LoadBalancerRule.create(
+ self.apiclient,
+ self.services["lbrule"],
+ ipaddressid=public_ip_3.ipaddress.id,
+ accountid=self.account.account.name,
+ networkid=network.id
+ )
+
+ self.debug("Adding %s to the LB rule %s" % (
+ virtual_machine.name,
+ lb_rule.name
+ ))
+ lb_rule.assign(self.apiclient, [virtual_machine])
+
+ self.debug("Trying to SSH into the virtual machine")
+ try:
+ virtual_machine.get_ssh_client(
+ ipaddress=public_ip_3.ipaddress.ipaddress,
+ reconnect=True,
+ port=self.services["lbrule"]["publicport"]
+ )
+ self.debug("SSH to guest VM succeeded")
+ except Exception as e:
+ self.fail("SSH to guest VM failed: %s" % e)
+ return
+
+
+class TestEnableVPNOverRvR(cloudstackTestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ cls.api_client = super(
+ TestEnableVPNOverRvR,
+ cls
+ ).getClsTestClient().getApiClient()
+ cls.services = Services().services
+ # Get Zone, Domain and templates
+ cls.domain = get_domain(cls.api_client, cls.services)
+ cls.zone = get_zone(cls.api_client, cls.services)
+ cls.template = get_template(
+ cls.api_client,
+ cls.zone.id,
+ cls.services["ostype"]
+ )
+ cls.services["virtual_machine"]["zoneid"] = cls.zone.id
+ cls.services["virtual_machine"]["template"] = cls.template.id
+
+ cls.service_offering = ServiceOffering.create(
+ cls.api_client,
+ cls.services["service_offering"]
+ )
+ cls.network_offering = NetworkOffering.create(
+ cls.api_client,
+ cls.services["network_offering"],
+ conservemode=True
+ )
+ # Enable Network offering
+ cls.network_offering.update(cls.api_client, state='Enabled')
+
+ cls._cleanup = [
+ cls.service_offering,
+ cls.network_offering,
+ ]
+ return
+
+ @classmethod
+ def tearDownClass(cls):
+ try:
+ #Cleanup resources used
+ 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.dbclient = self.testClient.getDbConnection()
+ self.account = Account.create(
+ self.apiclient,
+ self.services["account"],
+ admin=True,
+ domainid=self.domain.id
+ )
+ self.cleanup = []
+ return
+
+ def tearDown(self):
+ try:
+ self.account.delete(self.apiclient)
+ interval = list_configurations(
+ self.apiclient,
+ name='account.cleanup.interval'
+ )
+ # Sleep to ensure that all resources are deleted
+ time.sleep(int(interval[0].value) * 2)
+ #Clean up, terminate the created network offerings
+ cleanup_resources(self.apiclient, self.cleanup)
+ except Exception as e:
+ raise Exception("Warning: Exception during cleanup : %s" % e)
+ return
+
+ @attr(tags=["advanced", "advancedns", "ssh"])
+ def test_enableVPNOverRvR(self):
+ """Test redundant router internals
+ """
+
+ # Steps to validate
+ # 1. listNetworks should show the created network in allocated state
+ # 2. listRouters returns no running routers
+ # 3. VMs should be deployed and in Running state
+ # 4. should list MASTER and BACKUP routers
+ # 5. listPublicIpAddresses for networkid should show acquired IP addr
+ # 6. listRemoteAccessVpns for the network associated should show VPN
+ # created
+ # 7. listRemoteAccessVpns for the network associated should return
+ # empty response
+
+ # Creating network using the network offering created
+ self.debug("Creating network with network offering: %s" %
+ self.network_offering.id)
+ network = Network.create(
+ self.apiclient,
+ self.services["network"],
+ accountid=self.account.account.name,
+ domainid=self.account.account.domainid,
+ networkofferingid=self.network_offering.id,
+ zoneid=self.zone.id
+ )
+ self.debug("Created network with ID: %s" % network.id)
+
+ networks = Network.list(
+ self.apiclient,
+ id=network.id,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(networks, list),
+ True,
+ "List networks should return a valid response for created network"
+ )
+ nw_response = networks[0]
+
+ self.debug("Network state: %s" % nw_response.state)
+ self.assertEqual(
+ nw_response.state,
+ "Allocated",
+ "Th
<TRUNCATED>