You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ed...@apache.org on 2013/05/15 09:41:49 UTC
[06/50] [abbrv] Marvin IP cleared tests for various cloudstack
components
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/894413e3/test/integration/component/test_vpc_vms_deployment.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_vpc_vms_deployment.py b/test/integration/component/test_vpc_vms_deployment.py
new file mode 100644
index 0000000..b3a05d4
--- /dev/null
+++ b/test/integration/component/test_vpc_vms_deployment.py
@@ -0,0 +1,2458 @@
+# 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.
+
+""" Component tests VM deployment in VPC network functionality
+"""
+#Import Local Modules
+import marvin
+from nose.plugins.attrib import attr
+from marvin.cloudstackTestCase import *
+from marvin.cloudstackAPI import *
+from marvin.integration.lib.utils import *
+from marvin.integration.lib.base import *
+from marvin.integration.lib.common import *
+from marvin.remoteSSHClient import remoteSSHClient
+import datetime
+
+
+class Services:
+ """Test VM deployment in VPC network services
+ """
+
+ 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,
+ },
+ "network_offering": {
+ "name": 'VPC Network offering',
+ "displaytext": 'VPC Network off',
+ "guestiptype": 'Isolated',
+ "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,Lb,UserData,StaticNat,NetworkACL',
+ "traffictype": 'GUEST',
+ "availability": 'Optional',
+ "useVpc": 'on',
+ "serviceProviderList": {
+ "Dhcp": 'VpcVirtualRouter',
+ "Dns": 'VpcVirtualRouter',
+ "SourceNat": 'VpcVirtualRouter',
+ "PortForwarding": 'VpcVirtualRouter',
+ "Lb": 'VpcVirtualRouter',
+ "UserData": 'VpcVirtualRouter',
+ "StaticNat": 'VpcVirtualRouter',
+ "NetworkACL": 'VpcVirtualRouter'
+ },
+ },
+ "network_offering_no_lb": {
+ "name": 'VPC Network offering',
+ "displaytext": 'VPC Network off',
+ "guestiptype": 'Isolated',
+ "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,UserData,StaticNat,NetworkACL',
+ "traffictype": 'GUEST',
+ "availability": 'Optional',
+ "useVpc": 'on',
+ "serviceProviderList": {
+ "Dhcp": 'VpcVirtualRouter',
+ "Dns": 'VpcVirtualRouter',
+ "SourceNat": 'VpcVirtualRouter',
+ "PortForwarding": 'VpcVirtualRouter',
+ "UserData": 'VpcVirtualRouter',
+ "StaticNat": 'VpcVirtualRouter',
+ "NetworkACL": 'VpcVirtualRouter'
+ },
+ },
+ "vpc_offering": {
+ "name": 'VPC off',
+ "displaytext": 'VPC off',
+ "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,Lb,UserData,StaticNat',
+ },
+ "vpc": {
+ "name": "TestVPC",
+ "displaytext": "TestVPC",
+ "cidr": '10.0.0.1/24'
+ },
+ "network": {
+ "name": "Test Network",
+ "displaytext": "Test Network",
+ "netmask": '255.255.255.0',
+ "limit": 5,
+ # Max networks allowed as per hypervisor
+ # Xenserver -> 5, VMWare -> 9
+ },
+ "lbrule": {
+ "name": "SSH",
+ "alg": "leastconn",
+ # Algorithm used for load balancing
+ "privateport": 22,
+ "publicport": 2222,
+ "openfirewall": False,
+ "startport": 22,
+ "endport": 2222,
+ "protocol": "TCP",
+ "cidrlist": '0.0.0.0/0',
+ },
+ "natrule": {
+ "privateport": 22,
+ "publicport": 22,
+ "startport": 22,
+ "endport": 22,
+ "protocol": "TCP",
+ "cidrlist": '0.0.0.0/0',
+ },
+ "fw_rule": {
+ "startport": 1,
+ "endport": 6000,
+ "cidr": '0.0.0.0/0',
+ # Any network (For creating FW rule)
+ "protocol": "TCP"
+ },
+ "http_rule": {
+ "startport": 80,
+ "endport": 80,
+ "cidrlist": '0.0.0.0/0',
+ "protocol": "ICMP"
+ },
+ "virtual_machine": {
+ "displayname": "Test VM",
+ "username": "root",
+ "password": "password",
+ "ssh_port": 22,
+ "hypervisor": 'XenServer',
+ # Hypervisor type should be same as
+ # hypervisor type of cluster
+ "privateport": 22,
+ "publicport": 22,
+ "protocol": 'TCP',
+ },
+ "ostype": 'CentOS 5.3 (64-bit)',
+ # Cent OS 5.3 (64 bit)
+ "sleep": 60,
+ "timeout": 10,
+ "mode": 'advanced'
+ }
+
+
+class TestVMDeployVPC(cloudstackTestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ cls.api_client = super(
+ TestVMDeployVPC,
+ 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.vpc_off = VpcOffering.create(
+ cls.api_client,
+ cls.services["vpc_offering"]
+ )
+ cls.vpc_off.update(cls.api_client, state='Enabled')
+ cls._cleanup = [
+ cls.service_offering,
+ cls.vpc_off
+ ]
+ 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 = [self.account]
+ return
+
+ def tearDown(self):
+ try:
+ #Clean up, terminate the created network offerings
+ cleanup_resources(self.apiclient, self.cleanup)
+ wait_for_cleanup(self.apiclient, [
+ "network.gc.interval",
+ "network.gc.wait"])
+
+ except Exception as e:
+ raise Exception("Warning: Exception during cleanup : %s" % e)
+ return
+
+ def validate_vpc_offering(self, vpc_offering):
+ """Validates the VPC offering"""
+
+ self.debug("Check if the VPC offering is created successfully?")
+ vpc_offs = VpcOffering.list(
+ self.apiclient,
+ id=vpc_offering.id
+ )
+ self.assertEqual(
+ isinstance(vpc_offs, list),
+ True,
+ "List VPC offerings should return a valid list"
+ )
+ self.assertEqual(
+ vpc_offering.name,
+ vpc_offs[0].name,
+ "Name of the VPC offering should match with listVPCOff data"
+ )
+ self.debug(
+ "VPC offering is created successfully - %s" %
+ vpc_offering.name)
+ return
+
+ def validate_vpc_network(self, network, state=None):
+ """Validates the VPC network"""
+
+ self.debug("Check if the VPC network is created successfully?")
+ vpc_networks = VPC.list(
+ self.apiclient,
+ id=network.id
+ )
+ self.assertEqual(
+ isinstance(vpc_networks, list),
+ True,
+ "List VPC network should return a valid list"
+ )
+ self.assertEqual(
+ network.name,
+ vpc_networks[0].name,
+ "Name of the VPC network should match with listVPC data"
+ )
+ if state:
+ self.assertEqual(
+ vpc_networks[0].state,
+ state,
+ "VPC state should be '%s'" % state
+ )
+ self.debug("VPC network validated - %s" % network.name)
+ return
+
+ @attr(tags=["advanced", "intervlan"])
+ def test_01_deploy_vms_in_network(self):
+ """ Test deploy VMs in VPC networks
+ """
+
+ # Validate the following
+ # 1. Create a VPC with cidr - 10.1.1.1/16
+ # 2. Create a network offering with guest type=Isolated that has all
+ # the supported Services(Vpn,dhcpdns,UserData, SourceNat,Static NAT
+ # and PF,LB,NetworkAcl ) provided by VPCVR and conserver mode is ON
+ # 3. Create a network - N1 using the network offering created in step2
+ # as part of this VPC.
+ # 4. Create a network - N2 using a network offering similar to the one
+ # created in step2 but without Lb services enabled,as part of VPC
+ # 5. Create a network - N3 using the network offering similar to one
+ # created in step2 but without Lb services , as part of this VPC
+ # 6. Deploy few vms in all the 3 networks
+ # Steps:
+ # 1. Delete the 1st network
+ # 2. Vms that are part of other network should still be accessible
+ # and in "Running" state.
+
+ self.debug("Creating a VPC offering..")
+ vpc_off = VpcOffering.create(
+ self.apiclient,
+ self.services["vpc_offering"]
+ )
+
+ self._cleanup.append(vpc_off)
+ self.validate_vpc_offering(vpc_off)
+
+ self.debug("Enabling the VPC offering created")
+ vpc_off.update(self.apiclient, state='Enabled')
+
+ self.debug("creating a VPC network in the account: %s" %
+ self.account.account.name)
+ self.services["vpc"]["cidr"] = '10.1.1.1/16'
+ vpc = VPC.create(
+ self.apiclient,
+ self.services["vpc"],
+ vpcofferingid=vpc_off.id,
+ zoneid=self.zone.id,
+ account=self.account.account.name,
+ domainid=self.account.account.domainid
+ )
+ self.validate_vpc_network(vpc)
+
+ nw_off = NetworkOffering.create(
+ self.apiclient,
+ self.services["network_offering"],
+ conservemode=False
+ )
+ # Enable Network offering
+ nw_off.update(self.apiclient, state='Enabled')
+ self._cleanup.append(nw_off)
+
+ # Creating network using the network offering created
+ self.debug("Creating network with network offering: %s" % nw_off.id)
+ network_1 = Network.create(
+ self.apiclient,
+ self.services["network"],
+ accountid=self.account.account.name,
+ domainid=self.account.account.domainid,
+ networkofferingid=nw_off.id,
+ zoneid=self.zone.id,
+ gateway='10.1.1.1',
+ vpcid=vpc.id
+ )
+ self.debug("Created network with ID: %s" % network_1.id)
+
+ nw_off_no_lb = NetworkOffering.create(
+ self.apiclient,
+ self.services["network_offering_no_lb"],
+ conservemode=False
+ )
+ # Enable Network offering
+ nw_off_no_lb.update(self.apiclient, state='Enabled')
+ self._cleanup.append(nw_off)
+
+ # Creating network using the network offering created
+ self.debug("Creating network with network offering: %s" %
+ nw_off_no_lb.id)
+ network_2 = Network.create(
+ self.apiclient,
+ self.services["network"],
+ accountid=self.account.account.name,
+ domainid=self.account.account.domainid,
+ networkofferingid=nw_off_no_lb.id,
+ zoneid=self.zone.id,
+ gateway='10.1.2.1',
+ vpcid=vpc.id
+ )
+ self.debug("Created network with ID: %s" % network_2.id)
+
+ # Creating network using the network offering created
+ self.debug("Creating network with network offering: %s" %
+ nw_off_no_lb.id)
+ network_3 = Network.create(
+ self.apiclient,
+ self.services["network"],
+ accountid=self.account.account.name,
+ domainid=self.account.account.domainid,
+ networkofferingid=nw_off_no_lb.id,
+ zoneid=self.zone.id,
+ gateway='10.1.3.1',
+ vpcid=vpc.id
+ )
+ self.debug("Created network with ID: %s" % network_3.id)
+
+ self.debug("deploying VMs in network: %s" % network_1.name)
+ # Spawn an instance in that network
+ vm_1 = 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_1.id)]
+ )
+ self.debug("Deployed VM in network: %s" % network_1.id)
+
+ self.debug("deploying VMs in network: %s" % network_2.name)
+ # 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_2.id)]
+ )
+ self.debug("Deployed VM in network: %s" % network_2.id)
+
+ self.debug("deploying VMs in network: %s" % network_3.name)
+ vm_3 = 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_3.id)]
+ )
+ self.debug("Deployed VM in network: %s" % network_3.id)
+
+ self.debug("Check if deployed VMs are in running state?")
+ vms = VirtualMachine.list(
+ self.apiclient,
+ account=self.account.account.name,
+ domainid=self.account.account.domainid,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(vms, list),
+ True,
+ "List VMs should return a valid response"
+ )
+ for vm in vms:
+ self.debug("VM name: %s, VM state: %s" % (vm.name, vm.state))
+ self.assertEqual(
+ vm.state,
+ "Running",
+ "Vm state should be running for each VM deployed"
+ )
+ self.debug("Deleting the virtual machine in network1: %s" %
+ network_1.name)
+ try:
+ vm_1.delete(self.apiclient)
+ except Exception as e:
+ raise Exception("Failed to delete Virtual machine: %s" % e)
+
+ # Wait for expunge interval to cleanup VM
+ wait_for_cleanup(self.apiclient, ["expunge.delay", "expunge.interval"])
+
+ # wait for network.gc to ensure that routers are deleted
+ wait_for_cleanup(
+ self.apiclient,
+ ["network.gc.interval", "network.gc.wait"]
+ )
+
+ self.debug("Deleting the network: %s" % network_1.name)
+ try:
+ network_1.delete(self.apiclient)
+ except Exception as e:
+ self.fail("Failed to deleted network: %s" % e)
+
+ self.debug("After deleting first network other VMs" +
+ "should still be accessible")
+
+ vms = VirtualMachine.list(
+ self.apiclient,
+ account=self.account.account.name,
+ domainid=self.account.account.domainid,
+ state="Running",
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(vms, list),
+ True,
+ "List VMs should return a valid response"
+ )
+ self.assertEqual(
+ len(vms),
+ 2,
+ "Only 2 VMs should be in running state as first nw is deleted"
+ )
+
+ for vm in vms:
+ self.debug("VM name: %s, VM state: %s" % (vm.name, vm.state))
+ self.assertEqual(
+ vm.state,
+ "Running",
+ "Vm state should be running for each VM deployed"
+ )
+ return
+
+ @attr(tags=["advanced", "intervlan"])
+ def test_02_deploy_vms_delete_network(self):
+ """ Test deploy VMs in VPC networks and delete one of the network
+ """
+
+ # Validate the following
+ # 1. Create a VPC with cidr - 10.1.1.1/16
+ # 2. Create a network offering with guest type=Isolated that has all
+ # the supported Services(Vpn,dhcpdns,UserData, SourceNat,Static NAT
+ # and PF,LB,NetworkAcl ) provided by VPCVR and conserver mode is ON
+ # 3. Create a network - N1 using the network offering created in step2
+ # as part of this VPC.
+ # 4. Create a network - N2 using a network offering similar to the one
+ # created in step2 but without Lb services enabled,as part of VPC
+ # 5. Create a network - N3 using the network offering similar to one
+ # created in step2 but without Lb services , as part of this VPC
+ # 6. Deploy few vms in all the 3 networks
+ # Steps:
+ # 1. Delete the 2nd network
+ # 2. Vms that are part of other network should still be accessible
+ # and in "Running" state.
+
+ self.debug("Creating a VPC offering..")
+ vpc_off = VpcOffering.create(
+ self.apiclient,
+ self.services["vpc_offering"]
+ )
+
+ self._cleanup.append(vpc_off)
+ self.validate_vpc_offering(vpc_off)
+
+ self.debug("Enabling the VPC offering created")
+ vpc_off.update(self.apiclient, state='Enabled')
+
+ self.debug("creating a VPC network in the account: %s" %
+ self.account.account.name)
+ self.services["vpc"]["cidr"] = '10.1.1.1/16'
+ vpc = VPC.create(
+ self.apiclient,
+ self.services["vpc"],
+ vpcofferingid=vpc_off.id,
+ zoneid=self.zone.id,
+ account=self.account.account.name,
+ domainid=self.account.account.domainid
+ )
+ self.validate_vpc_network(vpc)
+
+ nw_off = NetworkOffering.create(
+ self.apiclient,
+ self.services["network_offering"],
+ conservemode=False
+ )
+ # Enable Network offering
+ nw_off.update(self.apiclient, state='Enabled')
+ self._cleanup.append(nw_off)
+
+ # Creating network using the network offering created
+ self.debug("Creating network with network offering: %s" % nw_off.id)
+ network_1 = Network.create(
+ self.apiclient,
+ self.services["network"],
+ accountid=self.account.account.name,
+ domainid=self.account.account.domainid,
+ networkofferingid=nw_off.id,
+ zoneid=self.zone.id,
+ gateway='10.1.1.1',
+ vpcid=vpc.id
+ )
+ self.debug("Created network with ID: %s" % network_1.id)
+
+ nw_off_no_lb = NetworkOffering.create(
+ self.apiclient,
+ self.services["network_offering_no_lb"],
+ conservemode=False
+ )
+ # Enable Network offering
+ nw_off_no_lb.update(self.apiclient, state='Enabled')
+ self._cleanup.append(nw_off)
+
+ # Creating network using the network offering created
+ self.debug("Creating network with network offering: %s" %
+ nw_off_no_lb.id)
+ network_2 = Network.create(
+ self.apiclient,
+ self.services["network"],
+ accountid=self.account.account.name,
+ domainid=self.account.account.domainid,
+ networkofferingid=nw_off_no_lb.id,
+ zoneid=self.zone.id,
+ gateway='10.1.2.1',
+ vpcid=vpc.id
+ )
+ self.debug("Created network with ID: %s" % network_2.id)
+
+ # Creating network using the network offering created
+ self.debug("Creating network with network offering: %s" %
+ nw_off_no_lb.id)
+ network_3 = Network.create(
+ self.apiclient,
+ self.services["network"],
+ accountid=self.account.account.name,
+ domainid=self.account.account.domainid,
+ networkofferingid=nw_off_no_lb.id,
+ zoneid=self.zone.id,
+ gateway='10.1.3.1',
+ vpcid=vpc.id
+ )
+ self.debug("Created network with ID: %s" % network_3.id)
+
+ self.debug("deploying VMs in network: %s" % network_1.name)
+ # Spawn an instance in that network
+ vm_1 = 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_1.id)]
+ )
+ self.debug("Deployed VM in network: %s" % network_1.id)
+
+ self.debug("deploying VMs in network: %s" % network_2.name)
+ # 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_2.id)]
+ )
+ self.debug("Deployed VM in network: %s" % network_2.id)
+
+ self.debug("deploying VMs in network: %s" % network_3.name)
+ vm_3 = 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_3.id)]
+ )
+ self.debug("Deployed VM in network: %s" % network_3.id)
+
+ self.debug("Check if deployed VMs are in running state?")
+ vms = VirtualMachine.list(
+ self.apiclient,
+ account=self.account.account.name,
+ domainid=self.account.account.domainid,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(vms, list),
+ True,
+ "List VMs should return a valid response"
+ )
+ for vm in vms:
+ self.debug("VM name: %s, VM state: %s" % (vm.name, vm.state))
+ self.assertEqual(
+ vm.state,
+ "Running",
+ "Vm state should be running for each VM deployed"
+ )
+ self.debug("Finding the VPC virtual router for network: %s" %
+ network_2.name)
+ routers = Router.list(
+ self.apiclient,
+ networkid=network_2.id,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(routers, list),
+ True,
+ "List routers should retirn a valid router for network2"
+ )
+ router = routers[0]
+
+ self.debug("Deleting the virtual machine in network1: %s" %
+ network_2.name)
+ try:
+ vm_2.delete(self.apiclient)
+ except Exception as e:
+ raise Exception("Failed to delete Virtual machine: %s" % e)
+
+ # Wait for expunge interval to cleanup VM
+ wait_for_cleanup(self.apiclient, ["expunge.delay", "expunge.interval"])
+
+ # wait for network.gc to ensure that routers are deleted
+ wait_for_cleanup(
+ self.apiclient,
+ ["network.gc.interval", "network.gc.wait"]
+ )
+
+ self.debug("Deleting the network: %s" % network_2.name)
+ try:
+ network_2.delete(self.apiclient)
+ except Exception as e:
+ self.fail("Failed to deleted network: %s" % e)
+
+ self.debug("Restarting the VPCVR: %s" % router.name)
+ cmd = rebootRouter.rebootRouterCmd()
+ cmd.id = router.id
+ self.apiclient.rebootRouter(cmd)
+
+ self.debug("Check status of router after reboot")
+ routers = Router.list(
+ self.apiclient,
+ id=router.id,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(routers, list),
+ True,
+ "List routers should retirn a valid router for network2"
+ )
+ router = routers[0]
+ self.assertEqual(
+ router.state,
+ "Running",
+ "Router state should be running after reboot"
+ )
+
+ self.debug("After deleting first network other VMs" +
+ "should still be accessible")
+
+ vms = VirtualMachine.list(
+ self.apiclient,
+ account=self.account.account.name,
+ domainid=self.account.account.domainid,
+ state="Running",
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(vms, list),
+ True,
+ "List VMs should return a valid response"
+ )
+ self.assertEqual(
+ len(vms),
+ 2,
+ "Only 2 VMs should be in running state as first nw is deleted"
+ )
+
+ for vm in vms:
+ self.debug("VM name: %s, VM state: %s" % (vm.name, vm.state))
+ self.assertEqual(
+ vm.state,
+ "Running",
+ "Vm state should be running for each VM deployed"
+ )
+ return
+
+ @attr(tags=["advanced", "intervlan"])
+ def test_03_deploy_vms_delete_add_network(self):
+ """ Test deploy VMs, delete one of the network and add another one
+ """
+
+ # Validate the following
+ # 1. Create a VPC with cidr - 10.1.1.1/16
+ # 2. Create a network offering with guest type=Isolated that has all
+ # the supported Services(Vpn,dhcpdns,UserData, SourceNat,Static NAT
+ # and PF,LB,NetworkAcl ) provided by VPCVR and conserver mode is ON
+ # 3. Create a network - N1 using the network offering created in step2
+ # as part of this VPC.
+ # 4. Create a network - N2 using a network offering similar to the one
+ # created in step2 but without Lb services enabled,as part of VPC
+ # 5. Create a network - N3 using the network offering similar to one
+ # created in step2 but without Lb services , as part of this VPC
+ # 6. Deploy few vms in all the 3 networks
+ # Steps:
+ # 1. Delete the 1st network
+ # 2. Add another network in VPC and deploy VM in that network
+ # 2. Vms that are part of other network should still be accessible
+ # and in "Running" state.
+
+ self.debug("Creating a VPC offering..")
+ vpc_off = VpcOffering.create(
+ self.apiclient,
+ self.services["vpc_offering"]
+ )
+
+ self._cleanup.append(vpc_off)
+ self.validate_vpc_offering(vpc_off)
+
+ self.debug("Enabling the VPC offering created")
+ vpc_off.update(self.apiclient, state='Enabled')
+
+ self.debug("creating a VPC network in the account: %s" %
+ self.account.account.name)
+ self.services["vpc"]["cidr"] = '10.1.1.1/16'
+ vpc = VPC.create(
+ self.apiclient,
+ self.services["vpc"],
+ vpcofferingid=vpc_off.id,
+ zoneid=self.zone.id,
+ account=self.account.account.name,
+ domainid=self.account.account.domainid
+ )
+ self.validate_vpc_network(vpc)
+
+ nw_off = NetworkOffering.create(
+ self.apiclient,
+ self.services["network_offering"],
+ conservemode=False
+ )
+ # Enable Network offering
+ nw_off.update(self.apiclient, state='Enabled')
+ self._cleanup.append(nw_off)
+
+ # Creating network using the network offering created
+ self.debug("Creating network with network offering: %s" % nw_off.id)
+ network_1 = Network.create(
+ self.apiclient,
+ self.services["network"],
+ accountid=self.account.account.name,
+ domainid=self.account.account.domainid,
+ networkofferingid=nw_off.id,
+ zoneid=self.zone.id,
+ gateway='10.1.1.1',
+ vpcid=vpc.id
+ )
+ self.debug("Created network with ID: %s" % network_1.id)
+
+ nw_off_no_lb = NetworkOffering.create(
+ self.apiclient,
+ self.services["network_offering_no_lb"],
+ conservemode=False
+ )
+ # Enable Network offering
+ nw_off_no_lb.update(self.apiclient, state='Enabled')
+ self._cleanup.append(nw_off)
+
+ # Creating network using the network offering created
+ self.debug("Creating network with network offering: %s" %
+ nw_off_no_lb.id)
+ network_2 = Network.create(
+ self.apiclient,
+ self.services["network"],
+ accountid=self.account.account.name,
+ domainid=self.account.account.domainid,
+ networkofferingid=nw_off_no_lb.id,
+ zoneid=self.zone.id,
+ gateway='10.1.2.1',
+ vpcid=vpc.id
+ )
+ self.debug("Created network with ID: %s" % network_2.id)
+
+ # Creating network using the network offering created
+ self.debug("Creating network with network offering: %s" %
+ nw_off_no_lb.id)
+ network_3 = Network.create(
+ self.apiclient,
+ self.services["network"],
+ accountid=self.account.account.name,
+ domainid=self.account.account.domainid,
+ networkofferingid=nw_off_no_lb.id,
+ zoneid=self.zone.id,
+ gateway='10.1.3.1',
+ vpcid=vpc.id
+ )
+ self.debug("Created network with ID: %s" % network_3.id)
+
+ self.debug("deploying VMs in network: %s" % network_1.name)
+ # Spawn an instance in that network
+ vm_1 = 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_1.id)]
+ )
+ self.debug("Deployed VM in network: %s" % network_1.id)
+
+ self.debug("deploying VMs in network: %s" % network_2.name)
+ # 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_2.id)]
+ )
+ self.debug("Deployed VM in network: %s" % network_2.id)
+
+ self.debug("deploying VMs in network: %s" % network_3.name)
+ vm_3 = 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_3.id)]
+ )
+ self.debug("Deployed VM in network: %s" % network_3.id)
+
+ self.debug("Check if deployed VMs are in running state?")
+ vms = VirtualMachine.list(
+ self.apiclient,
+ account=self.account.account.name,
+ domainid=self.account.account.domainid,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(vms, list),
+ True,
+ "List VMs should return a valid response"
+ )
+ for vm in vms:
+ self.debug("VM name: %s, VM state: %s" % (vm.name, vm.state))
+ self.assertEqual(
+ vm.state,
+ "Running",
+ "Vm state should be running for each VM deployed"
+ )
+ self.debug("Finding the VPC virtual router for network: %s" %
+ network_2.name)
+ routers = Router.list(
+ self.apiclient,
+ networkid=network_2.id,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(routers, list),
+ True,
+ "List routers should retirn a valid router for network2"
+ )
+ router = routers[0]
+
+ self.debug("Deleting the virtual machine in network1: %s" %
+ network_1.name)
+ try:
+ vm_1.delete(self.apiclient)
+ except Exception as e:
+ raise Exception("Failed to delete Virtual machine: %s" % e)
+
+ # Wait for expunge interval to cleanup VM
+ wait_for_cleanup(self.apiclient, ["expunge.delay", "expunge.interval"])
+
+ # wait for network.gc to ensure that routers are deleted
+ wait_for_cleanup(
+ self.apiclient,
+ ["network.gc.interval", "network.gc.wait"]
+ )
+
+ self.debug("Deleting the network: %s" % network_1.name)
+ try:
+ network_1.delete(self.apiclient)
+ except Exception as e:
+ self.fail("Failed to deleted network: %s" % e)
+
+ self.debug("Check if the network is deleted or not?")
+ networks = Network.list(
+ self.apiclient,
+ id=network_1.id,
+ listall=True
+ )
+
+ self.assertEqual(
+ networks,
+ None,
+ "ListNetwork response should be empty as network is deleted"
+ )
+
+ self.debug("Create a new netowrk in VPC: %s" % vpc.name)
+ # Creating network using the network offering created
+ self.debug("Creating network with network offering: %s" % nw_off.id)
+
+ network_4 = Network.create(
+ self.apiclient,
+ self.services["network"],
+ accountid=self.account.account.name,
+ domainid=self.account.account.domainid,
+ networkofferingid=nw_off.id,
+ zoneid=self.zone.id,
+ gateway='10.1.4.1',
+ vpcid=vpc.id
+ )
+
+ self.debug("deploying VMs in network: %s" % network_4.name)
+ # Spawn an instance in that network
+ vm_4 = 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_4.id)]
+ )
+ self.debug("Deployed VM in network: %s" % network_4.id)
+
+ self.debug("After deleting first network other VMs" +
+ "should still be accessible")
+ vms = VirtualMachine.list(
+ self.apiclient,
+ account=self.account.account.name,
+ domainid=self.account.account.domainid,
+ state="Running",
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(vms, list),
+ True,
+ "List VMs should return a valid response"
+ )
+ self.assertEqual(
+ len(vms),
+ 3,
+ "Only 2 VMs should be in running state as first nw is deleted"
+ )
+
+ for vm in vms:
+ self.debug("VM name: %s, VM state: %s" % (vm.name, vm.state))
+ self.assertEqual(
+ vm.state,
+ "Running",
+ "Vm state should be running for each VM deployed"
+ )
+ return
+
+ @attr(tags=["advanced", "intervlan"])
+ def test_04_deploy_vms_delete_add_network_noLb(self):
+ """ Test deploy VMs, delete one network without LB and add another one
+ """
+
+ # Validate the following
+ # 1. Create a VPC with cidr - 10.1.1.1/16
+ # 2. Create a network offering with guest type=Isolated that has all
+ # the supported Services(Vpn,dhcpdns,UserData, SourceNat,Static NAT
+ # and PF,LB,NetworkAcl ) provided by VPCVR and conserver mode is ON
+ # 3. Create a network - N1 using the network offering created in step2
+ # as part of this VPC.
+ # 4. Create a network - N2 using a network offering similar to the one
+ # created in step2 but without Lb services enabled,as part of VPC
+ # 5. Create a network - N3 using the network offering similar to one
+ # created in step2 but without Lb services , as part of this VPC
+ # 6. Deploy few vms in all the 3 networks
+ # Steps:
+ # 1. Delete the 2nd network
+ # 2. Add another network in VPC and deploy VM in that network
+ # 2. Vms that are part of other network should still be accessible
+ # and in "Running" state.
+
+ self.debug("Creating a VPC offering..")
+ vpc_off = VpcOffering.create(
+ self.apiclient,
+ self.services["vpc_offering"]
+ )
+
+ self._cleanup.append(vpc_off)
+ self.validate_vpc_offering(vpc_off)
+
+ self.debug("Enabling the VPC offering created")
+ vpc_off.update(self.apiclient, state='Enabled')
+
+ self.debug("creating a VPC network in the account: %s" %
+ self.account.account.name)
+ self.services["vpc"]["cidr"] = '10.1.1.1/16'
+ vpc = VPC.create(
+ self.apiclient,
+ self.services["vpc"],
+ vpcofferingid=vpc_off.id,
+ zoneid=self.zone.id,
+ account=self.account.account.name,
+ domainid=self.account.account.domainid
+ )
+ self.validate_vpc_network(vpc)
+
+ nw_off = NetworkOffering.create(
+ self.apiclient,
+ self.services["network_offering"],
+ conservemode=False
+ )
+ # Enable Network offering
+ nw_off.update(self.apiclient, state='Enabled')
+ self._cleanup.append(nw_off)
+
+ # Creating network using the network offering created
+ self.debug("Creating network with network offering: %s" % nw_off.id)
+ network_1 = Network.create(
+ self.apiclient,
+ self.services["network"],
+ accountid=self.account.account.name,
+ domainid=self.account.account.domainid,
+ networkofferingid=nw_off.id,
+ zoneid=self.zone.id,
+ gateway='10.1.1.1',
+ vpcid=vpc.id
+ )
+ self.debug("Created network with ID: %s" % network_1.id)
+
+ nw_off_no_lb = NetworkOffering.create(
+ self.apiclient,
+ self.services["network_offering_no_lb"],
+ conservemode=False
+ )
+ # Enable Network offering
+ nw_off_no_lb.update(self.apiclient, state='Enabled')
+ self._cleanup.append(nw_off)
+
+ # Creating network using the network offering created
+ self.debug("Creating network with network offering: %s" %
+ nw_off_no_lb.id)
+ network_2 = Network.create(
+ self.apiclient,
+ self.services["network"],
+ accountid=self.account.account.name,
+ domainid=self.account.account.domainid,
+ networkofferingid=nw_off_no_lb.id,
+ zoneid=self.zone.id,
+ gateway='10.1.2.1',
+ vpcid=vpc.id
+ )
+ self.debug("Created network with ID: %s" % network_2.id)
+
+ # Creating network using the network offering created
+ self.debug("Creating network with network offering: %s" %
+ nw_off_no_lb.id)
+ network_3 = Network.create(
+ self.apiclient,
+ self.services["network"],
+ accountid=self.account.account.name,
+ domainid=self.account.account.domainid,
+ networkofferingid=nw_off_no_lb.id,
+ zoneid=self.zone.id,
+ gateway='10.1.3.1',
+ vpcid=vpc.id
+ )
+ self.debug("Created network with ID: %s" % network_3.id)
+
+ self.debug("deploying VMs in network: %s" % network_1.name)
+ # Spawn an instance in that network
+ vm_1 = 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_1.id)]
+ )
+ self.debug("Deployed VM in network: %s" % network_1.id)
+
+ self.debug("deploying VMs in network: %s" % network_2.name)
+ # 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_2.id)]
+ )
+ self.debug("Deployed VM in network: %s" % network_2.id)
+
+ self.debug("deploying VMs in network: %s" % network_3.name)
+ vm_3 = 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_3.id)]
+ )
+ self.debug("Deployed VM in network: %s" % network_3.id)
+
+ self.debug("Check if deployed VMs are in running state?")
+ vms = VirtualMachine.list(
+ self.apiclient,
+ account=self.account.account.name,
+ domainid=self.account.account.domainid,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(vms, list),
+ True,
+ "List VMs should return a valid response"
+ )
+ for vm in vms:
+ self.debug("VM name: %s, VM state: %s" % (vm.name, vm.state))
+ self.assertEqual(
+ vm.state,
+ "Running",
+ "Vm state should be running for each VM deployed"
+ )
+ self.debug("Finding the VPC virtual router for network: %s" %
+ network_2.name)
+
+ routers = Router.list(
+ self.apiclient,
+ networkid=network_2.id,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(routers, list),
+ True,
+ "List routers should retirn a valid router for network2"
+ )
+ router = routers[0]
+
+ self.debug("Deleting the virtual machine in network1: %s" %
+ network_1.name)
+ try:
+ vm_1.delete(self.apiclient)
+ except Exception as e:
+ raise Exception("Failed to delete Virtual machine: %s" % e)
+
+ # Wait for expunge interval to cleanup VM
+ wait_for_cleanup(self.apiclient, ["expunge.delay", "expunge.interval"])
+
+ # wait for network.gc to ensure that routers are deleted
+ wait_for_cleanup(
+ self.apiclient,
+ ["network.gc.interval", "network.gc.wait"]
+ )
+
+ self.debug("Deleting the network: %s" % network_1.name)
+ try:
+ network_1.delete(self.apiclient)
+ except Exception as e:
+ self.fail("Failed to deleted network: %s" % e)
+
+ self.debug("Check if the network is deleted or not?")
+ networks = Network.list(
+ self.apiclient,
+ id=network_1.id,
+ listall=True
+ )
+
+ self.assertEqual(
+ networks,
+ None,
+ "ListNetwork response should be empty as network is deleted"
+ )
+
+ self.debug("Create a new netowrk in VPC: %s" % vpc.name)
+ # Creating network using the network offering created
+ self.debug("Creating network with network offering: %s" %
+ nw_off_no_lb.id)
+
+ network_4 = Network.create(
+ self.apiclient,
+ self.services["network"],
+ accountid=self.account.account.name,
+ domainid=self.account.account.domainid,
+ networkofferingid=nw_off_no_lb.id,
+ zoneid=self.zone.id,
+ gateway='10.1.4.1',
+ vpcid=vpc.id
+ )
+
+ self.debug("deploying VMs in network: %s" % network_4.name)
+ # Spawn an instance in that network
+ vm_4 = 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_4.id)]
+ )
+ self.debug("Deployed VM in network: %s" % network_4.id)
+
+ self.debug("Restarting the VPCVR: %s" % router.name)
+ cmd = rebootRouter.rebootRouterCmd()
+ cmd.id = router.id
+ self.apiclient.rebootRouter(cmd)
+
+ self.debug("Check status of router after reboot")
+ routers = Router.list(
+ self.apiclient,
+ id=router.id,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(routers, list),
+ True,
+ "List routers should retirn a valid router for network2"
+ )
+ router = routers[0]
+ self.assertEqual(
+ router.state,
+ "Running",
+ "Router state should be running after reboot"
+ )
+
+ self.debug("After deleting first network other VMs" +
+ "should still be accessible")
+ vms = VirtualMachine.list(
+ self.apiclient,
+ account=self.account.account.name,
+ domainid=self.account.account.domainid,
+ state="Running",
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(vms, list),
+ True,
+ "List VMs should return a valid response"
+ )
+ self.assertEqual(
+ len(vms),
+ 3,
+ "Only 2 VMs should be in running state as first nw is deleted"
+ )
+
+ for vm in vms:
+ self.debug("VM name: %s, VM state: %s" % (vm.name, vm.state))
+ self.assertEqual(
+ vm.state,
+ "Running",
+ "Vm state should be running for each VM deployed"
+ )
+ return
+
+ @attr(tags=["advanced", "intervlan"])
+ def test_05_create_network_max_limit(self):
+ """ Test create networks in VPC upto maximum limit for hypervisor
+ """
+
+ # Validate the following
+ # 1. Create a VPC and add maximum # of supported networks to the VPC.
+ # 2. Deploy Vms in each of these networks.
+
+ self.debug("Creating a VPC offering..")
+ vpc_off = VpcOffering.create(
+ self.apiclient,
+ self.services["vpc_offering"]
+ )
+
+ self._cleanup.append(vpc_off)
+ self.validate_vpc_offering(vpc_off)
+
+ self.debug("Enabling the VPC offering created")
+ vpc_off.update(self.apiclient, state='Enabled')
+
+ self.debug("creating a VPC network in the account: %s" %
+ self.account.account.name)
+ self.services["vpc"]["cidr"] = '10.1.1.1/16'
+ vpc = VPC.create(
+ self.apiclient,
+ self.services["vpc"],
+ vpcofferingid=vpc_off.id,
+ zoneid=self.zone.id,
+ account=self.account.account.name,
+ domainid=self.account.account.domainid
+ )
+ self.validate_vpc_network(vpc)
+
+ nw_off = NetworkOffering.create(
+ self.apiclient,
+ self.services["network_offering"],
+ conservemode=False
+ )
+ # Enable Network offering
+ nw_off.update(self.apiclient, state='Enabled')
+ self._cleanup.append(nw_off)
+
+ # Empty list to store all of the network and VM elements
+ networks = []
+ vms = []
+
+ # Creating network using the network offering created
+ self.debug("Creating network with network offering: %s" % nw_off.id)
+ network_1 = Network.create(
+ self.apiclient,
+ self.services["network"],
+ accountid=self.account.account.name,
+ domainid=self.account.account.domainid,
+ networkofferingid=nw_off.id,
+ zoneid=self.zone.id,
+ gateway='10.1.0.1',
+ vpcid=vpc.id
+ )
+ self.debug("Created network with ID: %s" % network_1.id)
+
+ nw_off_no_lb = NetworkOffering.create(
+ self.apiclient,
+ self.services["network_offering_no_lb"],
+ conservemode=False
+ )
+ # Enable Network offering
+ nw_off_no_lb.update(self.apiclient, state='Enabled')
+ self._cleanup.append(nw_off)
+
+ configs = Configurations.list(
+ self.apiclient,
+ name='vpc.max.networks',
+ listall=True
+ )
+ if not isinstance(configs, list):
+ raise Exception("Failed to find max network allowed for VPC")
+
+ self.services["network"]["limit"] = int(configs[0].value)
+
+ # Create networks till max limit of hypervisor
+ for i in range(self.services["network"]["limit"] - 1):
+ # Creating network using the network offering created
+ self.debug("Creating network with network offering: %s" %
+ nw_off_no_lb.id)
+ gateway = '10.1.' + str(i + 1) + '.1'
+ self.debug("Gateway for new network: %s" % gateway)
+
+ network = Network.create(
+ self.apiclient,
+ self.services["network"],
+ accountid=self.account.account.name,
+ domainid=self.account.account.domainid,
+ networkofferingid=nw_off_no_lb.id,
+ zoneid=self.zone.id,
+ gateway=gateway,
+ vpcid=vpc.id
+ )
+ self.debug("Created network with ID: %s" % network.id)
+ networks.append(network)
+
+ self.debug(
+ "Trying to create one more network than limit in VPC: %s" % vpc.name)
+ gateway = '10.1.' + str(self.services["network"]["limit"]) + '.1'
+
+ with self.assertRaises(Exception):
+ Network.create(
+ self.apiclient,
+ self.services["network"],
+ accountid=self.account.account.name,
+ domainid=self.account.account.domainid,
+ networkofferingid=nw_off_no_lb.id,
+ zoneid=self.zone.id,
+ gateway=gateway,
+ vpcid=vpc.id
+ )
+
+ self.debug("Deleting one of the existing networks")
+ try:
+ network_1.delete(self.apiclient)
+ except Exception as e:
+ self.fail("Failed to delete network: %s - %s" %
+ (network_1.name, e))
+
+ self.debug("Creating a new network in VPC: %s" % vpc.name)
+ network = Network.create(
+ self.apiclient,
+ self.services["network"],
+ accountid=self.account.account.name,
+ domainid=self.account.account.domainid,
+ networkofferingid=nw_off.id,
+ zoneid=self.zone.id,
+ gateway=gateway,
+ vpcid=vpc.id
+ )
+ self.debug("Created a new network: %s" % network.name)
+ networks.append(network)
+
+ self.debug("Deploying VMs in each of the networks created in VPC")
+ for network in networks:
+ self.debug("deploying VMs in network: %s" % network.name)
+ # Spawn an instance in that network
+ vm = 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.append(vm)
+
+ self.debug("Check if VM deployed successfully or not?")
+ list_vms = VirtualMachine.list(
+ self.apiclient,
+ id=vm.id,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(list_vms, list),
+ True,
+ "List VMs should return a valid response"
+ )
+ self.assertEqual(
+ list_vms[0].state,
+ "Running",
+ "Vm should be in running state"
+ )
+ return
+
+ @attr(tags=["advanced", "intervlan"])
+ def test_06_delete_network_vm_running(self):
+ """ Test delete network having running instances in VPC
+ """
+
+ # Validate the following
+ # 1. Create a VPC with cidr - 10.1.1.1/16
+ # 2. Add network1(10.1.1.1/24) and network2(10.1.2.1/24) to this VPC.
+ # 3. Deploy vm1 and vm2 in network1 and vm3 and vm4 in network2.
+ # 4. Attempt to delete network1. Delete network should fail.
+ # 5. Destroy all Vms in network1 & wait for the Vms to get expunged
+ # 6. Attempt to delete network1. Delete network shall succeed
+
+ self.debug("Creating a VPC offering..")
+ vpc_off = VpcOffering.create(
+ self.apiclient,
+ self.services["vpc_offering"]
+ )
+
+ self._cleanup.append(vpc_off)
+ self.validate_vpc_offering(vpc_off)
+
+ self.debug("Enabling the VPC offering created")
+ vpc_off.update(self.apiclient, state='Enabled')
+
+ self.debug("creating a VPC network in the account: %s" %
+ self.account.account.name)
+ self.services["vpc"]["cidr"] = '10.1.1.1/16'
+ vpc = VPC.create(
+ self.apiclient,
+ self.services["vpc"],
+ vpcofferingid=vpc_off.id,
+ zoneid=self.zone.id,
+ account=self.account.account.name,
+ domainid=self.account.account.domainid
+ )
+ self.validate_vpc_network(vpc)
+
+ nw_off = NetworkOffering.create(
+ self.apiclient,
+ self.services["network_offering"],
+ conservemode=False
+ )
+ # Enable Network offering
+ nw_off.update(self.apiclient, state='Enabled')
+ self._cleanup.append(nw_off)
+
+ # Creating network using the network offering created
+ self.debug("Creating network with network offering: %s" % nw_off.id)
+ network_1 = Network.create(
+ self.apiclient,
+ self.services["network"],
+ accountid=self.account.account.name,
+ domainid=self.account.account.domainid,
+ networkofferingid=nw_off.id,
+ zoneid=self.zone.id,
+ gateway='10.1.1.1',
+ vpcid=vpc.id
+ )
+ self.debug("Created network with ID: %s" % network_1.id)
+
+ nw_off_no_lb = NetworkOffering.create(
+ self.apiclient,
+ self.services["network_offering_no_lb"],
+ conservemode=False
+ )
+ # Enable Network offering
+ nw_off_no_lb.update(self.apiclient, state='Enabled')
+ self._cleanup.append(nw_off)
+
+ # Creating network using the network offering created
+ self.debug("Creating network with network offering: %s" %
+ nw_off_no_lb.id)
+ network_2 = Network.create(
+ self.apiclient,
+ self.services["network"],
+ accountid=self.account.account.name,
+ domainid=self.account.account.domainid,
+ networkofferingid=nw_off_no_lb.id,
+ zoneid=self.zone.id,
+ gateway='10.1.2.1',
+ vpcid=vpc.id
+ )
+ self.debug("Created network with ID: %s" % network_2.id)
+
+ self.debug("deploying VMs in network: %s" % network_1.name)
+ # Spawn an instance in that network
+ vm_1 = 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_1.id)]
+ )
+ self.debug("Deployed VM in network: %s" % network_1.id)
+ 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_1.id)]
+ )
+ self.debug("Deployed another VM in network: %s" % network_1.id)
+
+ self.debug("deploying VMs in network: %s" % network_2.name)
+ # Spawn an instance in that network
+ vm_3 = 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_2.id)]
+ )
+ self.debug("Deployed VM in network: %s" % network_2.id)
+ vm_4 = 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_2.id)]
+ )
+ self.debug("Deployed VM in network: %s" % network_2.id)
+
+ self.debug("Check if deployed VMs are in running state?")
+ vms = VirtualMachine.list(
+ self.apiclient,
+ account=self.account.account.name,
+ domainid=self.account.account.domainid,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(vms, list),
+ True,
+ "List VMs should return a valid response"
+ )
+ for vm in vms:
+ self.debug("VM name: %s, VM state: %s" % (vm.name, vm.state))
+ self.assertEqual(
+ vm.state,
+ "Running",
+ "Vm state should be running for each VM deployed"
+ )
+ self.debug("Trying to delete network: %s" % network_1.name)
+ with self.assertRaises(Exception):
+ network_1.delete(self.apiclient)
+ self.debug("Delete netwpork failed as there are running instances")
+
+ self.debug("Destroying all the instances in network1: %s" %
+ network_1.name)
+ try:
+ vm_1.delete(self.apiclient)
+ vm_2.delete(self.apiclient)
+ except Exception as e:
+ self.fail("Failed to destroy virtual machines - %s" % e)
+
+ # Wait for expunge interval to cleanup VM
+ wait_for_cleanup(self.apiclient, ["expunge.delay", "expunge.interval"])
+
+ # wait for network.gc to ensure that routers are deleted
+ wait_for_cleanup(
+ self.apiclient,
+ ["network.gc.interval", "network.gc.wait"]
+ )
+
+ self.debug("List virtual machines to ensure that VMs are expunged")
+ vms = VirtualMachine.list(
+ self.apiclient,
+ account=self.account.account.name,
+ domainid=self.account.account.domainid,
+ networkid=network_1.id,
+ listall=True
+ )
+ self.assertEqual(
+ vms,
+ None,
+ "List Vms shall return an empty response"
+ )
+ self.debug("Trying to delete network again now (should succeed)..")
+ try:
+ network_1.delete(self.apiclient)
+ except Exception as e:
+ self.fail("Failed to delete network: %s, %s" % (network_1.name, e))
+
+ self.debug("Destroying all the instances in network1: %s" %
+ network_2.name)
+ try:
+ vm_3.delete(self.apiclient)
+ vm_4.delete(self.apiclient)
+ except Exception as e:
+ self.fail("Failed to destroy virtual machines - %s" % e)
+
+ # Wait for expunge interval to cleanup VM
+ wait_for_cleanup(self.apiclient, ["expunge.delay", "expunge.interval"])
+
+ # wait for network.gc to ensure that routers are deleted
+ wait_for_cleanup(
+ self.apiclient,
+ ["network.gc.interval", "network.gc.wait"])
+
+ self.debug("List virtual machines to ensure that VMs are expunged")
+ vms = VirtualMachine.list(
+ self.apiclient,
+ account=self.account.account.name,
+ domainid=self.account.account.domainid,
+ networkid=network_2.id,
+ listall=True
+ )
+ self.assertEqual(
+ vms,
+ None,
+ "List Vms shall return an empty response"
+ )
+ self.debug("Trying to delete network again now (should succeed)..")
+ try:
+ network_2.delete(self.apiclient)
+ except Exception as e:
+ self.fail("Failed to delete network: %s, %s" % (network_2.name, e))
+
+ self.debug("Virtual router should be in running state")
+ routers = Router.list(
+ self.apiclient,
+ account=self.account.account.name,
+ domainid=self.account.account.domainid,
+ listall=True
+ )
+ self.assertEqual(
+ isinstance(routers, list),
+ True,
+ "List routers shall not return an emptty response"
+ )
+ for router in routers:
+ self.assertEqual(
+ router.state,
+ "Running",
+ "Router state should be running"
+ )
+ return
+
+ @attr(tags=["advanced", "intervlan"])
+ @unittest.skip("Not tested")
+ def test_07_delete_network_with_rules(self):
+ """ Test delete network that has PF/staticNat/LB rules/Network Acl
+ """
+
+ # Validate the following
+ # 1. Create a VPC with cidr - 10.1.1.1/16
+ # 2. Add network1(10.1.1.1/24) and network2(10.1.2.1/24) to this VPC.
+ # 3. Deploy vm1 and vm2 in network1 and vm3 and vm4 in network2.
+ # 4. Create a PF /Static Nat/LB rule for vms in network1.
+ # 5. Create a PF /Static Nat/LB rule for vms in network2.
+ # 6. Create ingress network ACL for allowing all the above rules from
+ # public ip range on network1 and network2.
+ # 7. Create egress network ACL for network1 and network2 to access
+ # google.com.
+ # 8. Create a private gateway for this VPC and add a static route to
+ # this gateway
+ # 9. Create a VPN gateway for this VPC and add a static route to this
+ # gateway.
+ # 10. Make sure that all the PF,LB, Static NAT rules work as expected
+ # 11. Make sure that we are able to access google from all user Vms
+ # 12. Make sure that the newly added private gateway's and VPN
+ # gateway's static routes work as expected.
+ # Steps:
+ # 1. Delete the 1st network.
+ # 2. Delete account
+ # Validations:
+ # 1. As part of network deletion all the resources attached with
+ # network should get deleted. All other VMs and rules shall work as
+ # expected
+ # 2. All the resources associated with account should be deleted
+
+ # Remove account from cleanup list, we will delete it at end of test
+ self.cleanup = []
+
+ self.debug("Creating a VPC offering..")
+ vpc_off = VpcOffering.create(
+ self.apiclient,
+ self.services["vpc_offering"]
+ )
+
+ self._cleanup.append(vpc_off)
+ self.validate_vpc_offering(vpc_off)
+
+ self.debug("Enabling the VPC offering created")
+ vpc_off.update(self.apiclient, state='Enabled')
+
+ self.debug("creating a VPC network in the account: %s" %
+ self.account.account.name)
+ self.services["vpc"]["cidr"] = '10.1.1.1/16'
+ vpc = VPC.create(
+ self.apiclient,
+ self.services["vpc"],
+ vpcofferingid=vpc_off.id,
+ zoneid=self.zone.id,
+ account=self.account.account.name,
+ domainid=self.account.account.domainid
+ )
+ self.validate_vpc_network(vpc)
+
+ nw_off = NetworkOffering.create(
+ self.apiclient,
+ self.services["network_offering"],
+ conservemode=False
+ )
+ # Enable Network offering
+ nw_off.update(self.apiclient, state='Enabled')
+ self._cleanup.append(nw_off)
+
+ # Creating network using the network offering created
+ self.debug("Creating network with network offering: %s" % nw_off.id)
+ network_1 = Network.create(
+ self.apiclient,
+ self.services["network"],
+ accountid=self.account.account.name,
+ domainid=self.account.account.domainid,
+ networkofferingid=nw_off.id,
+ zoneid=self.zone.id,
+ gateway='10.1.1.1',
+ vpcid=vpc.id
+ )
+ self.debug("Created network with ID: %s" % network_1.id)
+
+ nw_off_no_lb = NetworkOffering.create(
+ self.apiclient,
+ self.services["network_offering_no_lb"],
+ conservemode=False
+ )
+ # Enable Network offering
+ nw_off_no_lb.update(self.apiclient, state='Enabled')
+ self._cleanup.append(nw_off)
+
+ # Creating network using the network offering created
+ self.debug("Creating network with network offering: %s" %
+ nw_off_no_lb.id)
+ network_2 = Network.create(
+ self.apiclient,
+ self.services["network"],
+ accountid=self.account.account.name,
+ domainid=self.account.account.domainid,
+ networkofferingid=nw_off_no_lb.id,
+ zoneid=self.zone.id,
+ gateway='10.1.2.1',
+ vpcid=vpc.id
+ )
+ self.debug("Created network with ID: %s" % network_2.id)
+
+ self.debug("deploying VMs in network: %s" % network_1.name)
+ # Spawn an instance in that network
+ vm_1 = 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_1.id)]
+ )
+ self.debug("Deployed VM in network: %s" % network_1.id)
+ 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_1.id)]
+ )
+ self.debug("Deployed another VM in network: %s" % network_1.id)
+
+ self.debug("deploying VMs in network: %s" % network_2.name)
+ # Spawn an instance in that network
+ vm_3 = 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_2.id)]
+
<TRUNCATED>