tests: component test ports/fixes in python3 (#5082)

* cleanup plan

* more robust cleanup within member method

* ss_domain_limits fixed

* egress 'icmp' instead of 'all' and cleanup

* configdrive syntax, fixed to be up to par with py2

* cleanup fixed the lb secondary ip tests?

* deal with different base64 encoding in py3 for userdata

* cleanup of multiple_ips_per_nic

* cleanup and reformat of test_volumes

* cleanup and fixes for test_ps_domain_limits.py

* cleanup and fix of test_ps_limits.py

* fix occasional match of float against int

* cleanup and fix test_ps_resize_volume.py

* cleanup and fix test_snapshots

* cleanup ss_max_limits and fix for float vs int problem in API

* mere cleanup of test_volume_destroy_recover

* add missing command creation

* cleanup of test_vpc_on_host_maintenance

* cleanup test_vpc_network

* cleanup, comments and logging in test_vpc_network_lbrules

* cleanup of test_vpc_network_pfrules

* cleanup and format code for test_vpc_network_staticnatrule

* f string instead of conversion specifiers

* check http and ssh fix and cleanup (for vpc pfrules tests)

* generalise create network method

* make ip optional in creating webserver

* remove unused code and add rules to enable ssh

* more cleanup

* remove unused code and cleanup

* small cleanup, mostly precarous run environment required

* cleanup and removed unused code

* advancedsg only, cleanup, pulled in services

* reformat/cleanup

* log result of error after verify rule

* add nw_off_no_services

* tags=["TODO"] for escalations_networks

* tags=["TODO"] for organization_states

* tags=["TODO"] for browse_templates

* tags=["TODO"] for configdrive

* tags=["TODO"] for vpc_vms_deployment

* add remove network cleanup and fixes

* move tests that fail on all platforms out of the way

Co-authored-by: Daan Hoogland <dahn@onecht.net>
This commit is contained in:
dahn 2021-09-02 12:33:49 +02:00 committed by GitHub
parent 37761c610a
commit 571a361926
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
61 changed files with 3543 additions and 4055 deletions

View File

@ -88,13 +88,8 @@ class TestlistTemplates(cloudstackTestCase):
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestlistTemplates, cls).tearDownClass()
# Cleanup resources used
cleanup_resources(cls.apiclient, cls.cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
def RestartServers(self): def RestartServers(self):
""" Restart management server and usage server """ """ Restart management server and usage server """

View File

@ -18,7 +18,6 @@
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
from marvin.cloudstackTestCase import cloudstackTestCase from marvin.cloudstackTestCase import cloudstackTestCase
import unittest import unittest
from marvin.lib.utils import cleanup_resources
from marvin.lib.base import (Account, from marvin.lib.base import (Account,
Host, Host,
VPC, VPC,
@ -58,6 +57,7 @@ class TestVPCHostMaintenance(cloudstackTestCase):
cls.api_client, cls.api_client,
cls.services["vpc_offering"] cls.services["vpc_offering"]
) )
cls._cleanup.append(cls.vpc_off)
cls.vpc_off.update(cls.api_client, state='Enabled') cls.vpc_off.update(cls.api_client, state='Enabled')
cls.hosts = Host.list( cls.hosts = Host.list(
cls.api_client, cls.api_client,
@ -93,15 +93,11 @@ class TestVPCHostMaintenance(cloudstackTestCase):
"Failed to enable maintenance mode on %s" % "Failed to enable maintenance mode on %s" %
host.name) host.name)
timeout = timeout - 1 timeout = timeout - 1
cls._cleanup.append(cls.vpc_off)
return return
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: try:
# Cleanup resources used
cleanup_resources(cls.api_client, cls._cleanup)
for host in cls.hosts: for host in cls.hosts:
Host.cancelMaintenance( Host.cancelMaintenance(
cls.api_client, cls.api_client,
@ -117,7 +113,9 @@ class TestVPCHostMaintenance(cloudstackTestCase):
"Failed to cancel maintenance mode on %s" % "Failed to cancel maintenance mode on %s" %
(host.name)) (host.name))
except Exception as e: except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e) raise Exception("Warning: Exception during resetting hosts maintenance : %s" % e)
finally:
super(TestVPCHostMaintenance, cls).tearDownClass()
return return
def setUp(self): def setUp(self):
@ -138,12 +136,7 @@ class TestVPCHostMaintenance(cloudstackTestCase):
return return
def tearDown(self): def tearDown(self):
try: super(TestVPCHostMaintenance, self).tearDown()
# 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
def validate_vpc_offering(self, vpc_offering): def validate_vpc_offering(self, vpc_offering):
"""Validates the VPC offering""" """Validates the VPC offering"""
@ -217,5 +210,6 @@ class TestVPCHostMaintenance(cloudstackTestCase):
domainid=self.account.domainid, domainid=self.account.domainid,
start=False start=False
) )
self.cleanup.append(vpc)
self.validate_vpc_network(vpc, state='enabled') self.validate_vpc_network(vpc, state='enabled')
return return

View File

@ -0,0 +1,792 @@
# 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 nose.plugins.attrib import attr
from component.test_vpc_vm_life_cycle import Services
class TestVMLifeCycleSharedNwVPC(cloudstackTesTODOtCase):
@classmethod
def setUpClass(cls):
cls.testClient = super(TestVMLifeCycleSharedNwVPC, cls).getClsTestClient()
cls.api_client = cls.testClient.getApiClient()
cls.services = Services().services
# Get Zone, Domain and templates
cls.domain = get_domain(cls.api_client)
cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
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.account = Account.create(
cls.api_client,
cls.services["account"],
admin=True,
domainid=cls.domain.id
)
cls.services["vpc"]["cidr"] = '10.1.1.1/16'
cls.vpc = VPC.create(
cls.api_client,
cls.services["vpc"],
vpcofferingid=cls.vpc_off.id,
zoneid=cls.zone.id,
account=cls.account.name,
domainid=cls.account.domainid
)
cls.nw_off = NetworkOffering.create(
cls.api_client,
cls.services["network_offering"],
conservemode=False
)
# Enable Network offering
cls.nw_off.update(cls.api_client, state='Enabled')
# Creating network using the network offering created
cls.network_1 = Network.create(
cls.api_client,
cls.services["network"],
accountid=cls.account.name,
domainid=cls.account.domainid,
networkofferingid=cls.nw_off.id,
zoneid=cls.zone.id,
gateway='10.1.1.1',
vpcid=cls.vpc.id
)
cls.nw_off_no_lb = NetworkOffering.create(
cls.api_client,
cls.services["network_offering_no_lb"],
conservemode=False
)
cls.shared_nw_off = NetworkOffering.create(
cls.api_client,
cls.services["network_off_shared"],
conservemode=False
)
# Enable Network offering
cls.shared_nw_off.update(cls.api_client, state='Enabled')
physical_network, shared_vlan = get_free_vlan(cls.api_client, cls.zone.id)
if shared_vlan is None:
assert False, "Failed to get free vlan id for shared network creation in the zone"
#create network using the shared network offering created
cls.services["network"]["acltype"] = "Domain"
cls.services["network"]["physicalnetworkid"] = physical_network.id
cls.services["network"]["vlan"] = shared_vlan
# Start Ip and End Ip should be specified for shared network
cls.services["network"]["startip"] = '10.1.2.20'
cls.services["network"]["endip"] = '10.1.2.30'
# Creating network using the network offering created
cls.network_2 = Network.create(
cls.api_client,
cls.services["network"],
accountid=cls.account.name,
domainid=cls.account.domainid,
networkofferingid=cls.shared_nw_off.id,
zoneid=cls.zone.id,
gateway='10.1.2.1',
)
cls.vm_1 = VirtualMachine.create(
cls.api_client,
cls.services["virtual_machine"],
accountid=cls.account.name,
domainid=cls.account.domainid,
serviceofferingid=cls.service_offering.id,
networkids=[str(cls.network_1.id),
str(cls.network_2.id)]
)
cls.vm_2 = VirtualMachine.create(
cls.api_client,
cls.services["virtual_machine"],
accountid=cls.account.name,
domainid=cls.account.domainid,
serviceofferingid=cls.service_offering.id,
networkids=[str(cls.network_1.id),
str(cls.network_2.id)]
)
cls.vm_3 = VirtualMachine.create(
cls.api_client,
cls.services["virtual_machine"],
accountid=cls.account.name,
domainid=cls.account.domainid,
serviceofferingid=cls.service_offering.id,
networkids=[str(cls.network_1.id),
str(cls.network_2.id)]
)
cls.public_ip_1 = PublicIPAddress.create(
cls.api_client,
accountid=cls.account.name,
zoneid=cls.zone.id,
domainid=cls.account.domainid,
networkid=cls.network_1.id,
vpcid=cls.vpc.id
)
cls.lb_rule = LoadBalancerRule.create(
cls.api_client,
cls.services["lbrule"],
ipaddressid=cls.public_ip_1.ipaddress.id,
accountid=cls.account.name,
networkid=cls.network_1.id,
vpcid=cls.vpc.id,
domainid=cls.account.domainid
)
# Only the vms in the same network can be added to load balancing rule
# hence we can't add vm_2 with vm_1
cls.lb_rule.assign(cls.api_client, [cls.vm_1])
cls.public_ip_2 = PublicIPAddress.create(
cls.api_client,
accountid=cls.account.name,
zoneid=cls.zone.id,
domainid=cls.account.domainid,
networkid=cls.network_1.id,
vpcid=cls.vpc.id
)
cls.nat_rule = NATRule.create(
cls.api_client,
cls.vm_1,
cls.services["natrule"],
ipaddressid=cls.public_ip_2.ipaddress.id,
openfirewall=False,
networkid=cls.network_1.id,
vpcid=cls.vpc.id
)
# Opening up the ports in VPC
cls.nwacl_nat = NetworkACL.create(
cls.api_client,
networkid=cls.network_1.id,
services=cls.services["natrule"],
traffictype='Ingress'
)
cls.nwacl_lb = NetworkACL.create(
cls.api_client,
networkid=cls.network_1.id,
services=cls.services["lbrule"],
traffictype='Ingress'
)
cls.services["icmp_rule"]["protocol"] = "all"
cls.nwacl_internet_1 = NetworkACL.create(
cls.api_client,
networkid=cls.network_1.id,
services=cls.services["icmp_rule"],
traffictype='Egress'
)
cls._cleanup = [
cls.account,
cls.network_2,
cls.nw_off,
cls.shared_nw_off,
cls.vpc_off,
cls.service_offering,
]
return
@classmethod
def tearDownClass(cls):
try:
cls.vpc_off.update(cls.api_client, state='Disabled')
cls.shared_nw_off.update(cls.api_client, state='Disabled')
cls.nw_off.update(cls.api_client, state='Disabled')
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:
cleanup_resources(self.apiclient, self.cleanup)
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
def validate_network_rules(self):
"""Validating if the network rules (PF/LB) works properly or not?"""
try:
self.debug("Checking if we can SSH into VM_1 through %s?" %
(self.public_ip_1.ipaddress.ipaddress))
ssh_1 = self.vm_1.get_ssh_client(
ipaddress=self.public_ip_1.ipaddress.ipaddress,
reconnect=True)
self.debug("SSH into VM is successfully")
self.debug("Verifying if we can ping to outside world from VM?")
# Ping to outsite world
res = ssh_1.execute("ping -c 1 www.google.com")
# res = 64 bytes from maa03s17-in-f20.1e100.net (74.125.236.212):
# icmp_req=1 ttl=57 time=25.9 ms
# --- www.l.google.com ping statistics ---
# 1 packets transmitted, 1 received, 0% packet loss, time 0ms
# rtt min/avg/max/mdev = 25.970/25.970/25.970/0.000 ms
result = str(res)
self.assertEqual(
result.count("1 received"),
1,
"Ping to outside world from VM should be successful"
)
self.debug("We should be allowed to ping virtual gateway")
self.debug("Finding the gateway corresponding to isolated network")
gateways = [nic.gateway for nic in self.vm_1.nic if nic.networkid == self.network_1.id]
gateway_list_validation_result = validateList(gateways)
self.assertEqual(gateway_list_validation_result[0], PASS, "gateway list validation failed due to %s" %
gateway_list_validation_result[2])
gateway = gateway_list_validation_result[1]
self.debug("VM gateway: %s" % gateway)
res = ssh_1.execute("ping -c 1 %s" % gateway)
self.debug("ping -c 1 %s: %s" % (gateway, res))
result = str(res)
self.assertEqual(
result.count("1 received"),
1,
"Ping to VM gateway should be successful"
)
except Exception as e:
self.fail("Failed to SSH into VM - %s, %s" %
(self.public_ip_1.ipaddress.ipaddress, e))
return
@attr(tags=["advanced", "intervlan"], required_hardware="true")
def test_01_deploy_instance_in_network(self):
""" Test deploy an instance in VPC networks
"""
# Validate the following
# 1. Successful deployment of the User VM.
# 2. Ping any host in the public Internet successfully.
# 3. Ping the gateways of the VPC's guest network and the
# Shared Guest Network successfully.
self.debug("Check if deployed VMs are in running state?")
vms = VirtualMachine.list(
self.apiclient,
account=self.account.name,
domainid=self.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("Validating if network rules are coonfigured properly?")
self.validate_network_rules()
return
@attr(tags=["advanced", "intervlan"], required_hardware="true")
def test_02_stop_instance_in_network(self):
""" Test stop an instance in VPC networks
"""
# Validate the following
# 1. Stop the virtual machines.
# 2. Rules should be still configured on virtual router.
self.debug("Validating if network rules are coonfigured properly?")
self.validate_network_rules()
self.debug("Stopping one of the virtual machines in account: %s" %
self.account.name)
try:
self.vm_2.stop(self.apiclient)
except Exception as e:
self.fail("Failed to stop the virtual instances, %s" % e)
self.debug("Validating if network rules are coonfigured properly?")
self.validate_network_rules()
return
@attr(tags=["advanced", "intervlan"], required_hardware="true")
def test_03_start_instance_in_network(self):
""" Test start an instance in VPC networks
"""
# Validate the following
# 1. Start the virtual machines.
# 2. Rules should be still configured on virtual router.
self.debug("Validating if network rules are coonfigured properly?")
self.validate_network_rules()
self.debug("Starting one of the virtual machines in account: %s" %
self.account.name)
try:
self.vm_2.start(self.apiclient)
except Exception as e:
self.fail("Failed to start the virtual instances, %s" % e)
self.debug("Check if the instance is in stopped state?")
vms = VirtualMachine.list(
self.apiclient,
id=self.vm_2.id,
listall=True
)
self.assertEqual(
isinstance(vms, list),
True,
"List virtual machines should return a valid list"
)
vm = vms[0]
self.assertEqual(
vm.state,
"Running",
"Virtual machine should be in running state"
)
self.debug("Validating if network rules are coonfigured properly?")
self.validate_network_rules()
return
@attr(tags=["advanced", "intervlan"], required_hardware="true")
def test_04_reboot_instance_in_network(self):
""" Test reboot an instance in VPC networks
"""
# Validate the following
# 1. Reboot the virtual machines.
# 2. Rules should be still configured on virtual router.
self.debug("Validating if network rules are coonfigured properly?")
self.validate_network_rules()
self.debug("Restarting the virtual machines in account: %s" %
self.account.name)
try:
self.vm_1.reboot(self.apiclient)
self.vm_2.reboot(self.apiclient)
except Exception as e:
self.fail("Failed to reboot the virtual instances, %s" % e)
self.debug("Check if the instance is in stopped state?")
vms = VirtualMachine.list(
self.apiclient,
account=self.account.name,
domainid=self.account.domainid,
listall=True
)
self.assertEqual(
isinstance(vms, list),
True,
"List virtual machines should return a valid list"
)
for vm in vms:
self.assertEqual(
vm.state,
"Running",
"Virtual machine should be in running state"
)
self.debug("Validating if network rules are coonfigured properly?")
self.validate_network_rules()
return
@attr(tags=["advanced", "intervlan"], required_hardware="true")
def test_05_destroy_instance_in_network(self):
""" Test destroy an instance in VPC networks
"""
# Validate the following
# 1. Destroy one of the virtual machines.
# 2. Rules should be still configured on virtual router.
self.debug("Destroying one of the virtual machines in account: %s" %
self.account.name)
try:
self.vm_2.delete(self.apiclient)
except Exception as e:
self.fail("Failed to destroy the virtual instances, %s" % e)
#Wait for expunge interval to cleanup VM
wait_for_cleanup(self.apiclient, ["expunge.delay", "expunge.interval"])
self.debug("Check if the instance is in stopped state?")
vms = VirtualMachine.list(
self.apiclient,
id=self.vm_2.id,
listall=True
)
self.assertEqual(
vms,
None,
"List virtual machines should not return anything"
)
self.debug("Validating if network rules are coonfigured properly?")
self.validate_network_rules()
return
@attr(tags=["advanced", "intervlan"], required_hardware="true")
def test_06_recover_instance_in_network(self):
""" Test recover an instance in VPC networks
"""
self.debug("Deploying vm")
self.vm_2 = VirtualMachine.create(
self.api_client,
self.services["virtual_machine"],
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
networkids=[str(self.network_1.id),
str(self.network_2.id)]
)
self.cleanup.append(self.vm_2)
try:
self.vm_2.delete(self.apiclient, expunge=False)
except Exception as e:
self.fail("Failed to destroy the virtual instances, %s" % e)
try:
self.vm_2.recover(self.apiclient)
except Exception as e:
self.fail("Failed to recover the virtual instances, %s" % e)
self.debug("Check if the instance is in stopped state?")
vms = VirtualMachine.list(
self.apiclient,
id=self.vm_2.id,
listall=True
)
self.assertEqual(
isinstance(vms, list),
True,
"List virtual machines should return a valid list"
)
vm = vms[0]
self.assertEqual(
vm.state,
"Stopped",
"Virtual machine should be in stopped state"
)
self.debug("Starting the instance: %s" % self.vm_2.name)
try:
self.vm_2.start(self.apiclient)
except Exception as e:
self.fail("Failed to start the instances, %s" % e)
vms = VirtualMachine.list(
self.apiclient,
id=self.vm_2.id,
listall=True
)
self.assertEqual(
isinstance(vms, list),
True,
"List virtual machines should return a valid list"
)
vm = vms[0]
self.assertEqual(
vm.state,
"Running",
"Virtual machine should be in running state"
)
self.debug("Validating if network rules are coonfigured properly?")
self.validate_network_rules()
return
@attr(tags=["advanced", "intervlan"], required_hardware="true")
def test_07_migrate_instance_in_network(self):
""" Test migrate an instance in VPC networks
"""
# Validate the following
# 1. Migrate the virtual machines to other hosts
# 2. Vm should be in stopped state. State both the instances
# 3. Make sure that all the PF,LB and Static NAT rules on this VM
# works as expected.
# 3. Make sure that we are able to access google.com from this user Vm
self.hypervisor = self.testClient.getHypervisorInfo()
if self.hypervisor.lower() in ['lxc']:
self.skipTest("vm migrate is not supported in %s" % self.hypervisor)
self.debug("Validating if network rules are coonfigured properly?")
self.validate_network_rules()
host = findSuitableHostForMigration(self.apiclient, self.vm_1.id)
if host is None:
self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
self.debug("Migrating VM-ID: %s to Host: %s" % (
self.vm_1.id,
host.id
))
try:
self.vm_1.migrate(self.apiclient, hostid=host.id)
except Exception as e:
self.fail("Failed to migrate instance, %s" % e)
self.debug("Validating if network rules are coonfigured properly?")
self.validate_network_rules()
return
@attr(tags=["advanced", "intervlan"], required_hardware="true")
def test_08_user_data(self):
""" Test user data in virtual machines
"""
# 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 a vm in network1 and a vm in network2 using userdata
# Steps
# 1.Query for the user data for both the user vms from both networks
# User should be able to query the user data for the vms belonging to
# both the networks from the VR
try:
ssh = self.vm_1.get_ssh_client(
ipaddress=self.public_ip_1.ipaddress.ipaddress,
reconnect=True)
self.debug("SSH into VM is successfully")
ssh.execute("yum install wget -y")
except Exception as e:
self.fail("Failed to SSH into instance")
self.debug("check the userdata with that of present in router")
try:
cmds = [
"wget http://%s/latest/user-data" % self.network_1.gateway,
"cat user-data",
]
for c in cmds:
result = ssh.execute(c)
self.debug("%s: %s" % (c, result))
except Exception as e:
self.fail("Failed to SSH in Virtual machine: %s" % e)
res = str(result)
self.assertEqual(
res.count(
self.services["virtual_machine"]["userdata"]),
1,
"Verify user data from router"
)
return
@attr(tags=["advanced", "intervlan"], required_hardware="true")
def test_09_meta_data(self):
""" Test meta data in virtual machines
"""
# 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 a vm in network1 and a vm in network2 using userdata
# Steps
# 1.Query for the meta data for both the user vms from both networks
# User should be able to query the user data for the vms belonging to
# both the networks from the VR
try:
ssh = self.vm_1.get_ssh_client(
ipaddress=self.public_ip_1.ipaddress.ipaddress,
reconnect=True)
self.debug("SSH into VM is successfully")
except Exception as e:
self.fail("Failed to SSH into instance")
self.debug("check the metadata with that of present in router")
try:
cmds = [
"wget http://%s/latest/vm-id" % self.network_1.gateway,
"cat vm-id",
]
for c in cmds:
result = ssh.execute(c)
self.debug("%s: %s" % (c, result))
except Exception as e:
self.fail("Failed to SSH in Virtual machine: %s" % e)
res = str(result)
self.assertNotEqual(
res,
None,
"Meta data should be returned from router"
)
return
@attr(tags=["advanced", "intervlan"], required_hardware="true")
def test_10_expunge_instance_in_network(self):
""" Test expunge an instance in VPC networks
"""
# Validate the following
# 1. Recover the virtual machines.
# 2. Vm should be in stopped state. State both the instances
# 3. Make sure that all the PF,LB and Static NAT rules on this VM
# works as expected.
# 3. Make sure that we are able to access google.com from this user Vm
self.debug("Validating if network rules are coonfigured properly?")
self.validate_network_rules()
self.debug("Delete virtual machines in account: %s" %
self.account.name)
try:
self.vm_3.delete(self.apiclient)
except Exception as e:
self.fail("Failed to destroy the virtual instances, %s" % e)
self.debug(
"Waiting for expunge interval to cleanup the network and VMs")
wait_for_cleanup(
self.apiclient,
["expunge.interval", "expunge.delay"]
)
self.debug("Validating if network rules are coonfigured properly?")
self.validate_network_rules()
self.debug(
"Deleting the rest of the virtual machines in account: %s" %
self.account.name)
try:
self.vm_1.delete(self.apiclient)
except Exception as e:
self.fail("Failed to destroy the virtual instances, %s" % e)
self.debug(
"Waiting for expunge interval to cleanup the network and VMs")
wait_for_cleanup(
self.apiclient,
["expunge.interval", "expunge.delay"]
)
# Check if the network rules still exists after Vm expunged
self.debug("Checking if NAT rules existed ")
with self.assertRaises(Exception):
NATRule.list(
self.apiclient,
id=self.nat_rule.id,
listall=True
)
LoadBalancerRule.list(
self.apiclient,
id=self.lb_rule.id,
listall=True
)
return

View File

@ -302,9 +302,10 @@ class Test42xBugsMgmtSvr(cloudstackTestCase):
# Step2: It should return a commit hash # Step2: It should return a commit hash
return return
@attr(tags=["advanced", "basic"]) # @attr(tags=["advanced", "basic"])
@attr(required_hardware="false") # @attr(required_hardware="false")
@attr(storage="s3") # @attr(storage="s3")
@attr(tags=["TODO"], required_hardware="false")
def test_es_1863_register_template_s3_domain_admin_user(self): def test_es_1863_register_template_s3_domain_admin_user(self):
""" """
@Desc: Test whether cloudstack allows Domain admin or user @Desc: Test whether cloudstack allows Domain admin or user

View File

@ -607,7 +607,8 @@ class TestRVRInternals(cloudstackTestCase):
raise Exception("Warning: Exception during cleanup : %s" % e) raise Exception("Warning: Exception during cleanup : %s" % e)
return return
@attr(tags=["advanced", "advancedns", "ssh"]) # @attr(tags=["advanced", "advancedns", "ssh"])
@attr(tags=["TODO"])
def test_redundantVR_internals(self): def test_redundantVR_internals(self):
"""Test redundant router internals """Test redundant router internals
""" """

View File

@ -535,7 +535,8 @@ class TestRvRDeploymentPlanning(cloudstackTestCase):
self.apiclient.updatePod(cmd) self.apiclient.updatePod(cmd)
return return
@attr(tags=["advanced", "advancedns"]) # @attr(tags=["advanced", "advancedns"])
@attr(tags=["TODO"])
def test_RvR_multiprimarystorage(self): def test_RvR_multiprimarystorage(self):
"""Test RvR with multi primary storage """Test RvR with multi primary storage
""" """
@ -773,7 +774,8 @@ class TestRvRDeploymentPlanning(cloudstackTestCase):
self.apiclient.updateCluster(cmd) self.apiclient.updateCluster(cmd)
return return
@attr(tags=["advanced", "advancedns", "ssh"]) # @attr(tags=["advanced", "advancedns", "ssh"])
@attr(tags=["TODO"])
def test_RvR_multihosts(self): def test_RvR_multihosts(self):
"""Test RvR with multi hosts """Test RvR with multi hosts
""" """

View File

@ -25,11 +25,16 @@
Feature Specifications: https://cwiki.apache.org/confluence/display/CLOUDSTACK/Add+Remove+Networks+to+VMs Feature Specifications: https://cwiki.apache.org/confluence/display/CLOUDSTACK/Add+Remove+Networks+to+VMs
""" """
# Import Local Modules import random
from nose.plugins.attrib import attr import time
from marvin.cloudstackTestCase import cloudstackTestCase
import unittest import unittest
from ddt import ddt, data from ddt import ddt, data
from marvin.cloudstackAPI import (addNicToVirtualMachine,
removeNicFromVirtualMachine,
updateDefaultNicForVirtualMachine)
from marvin.cloudstackTestCase import cloudstackTestCase
from marvin.codes import PASS
from marvin.lib.base import ( from marvin.lib.base import (
Account, Account,
Domain, Domain,
@ -53,19 +58,11 @@ from marvin.lib.common import (get_domain,
update_resource_limit, update_resource_limit,
list_nat_rules list_nat_rules
) )
from marvin.lib.utils import (validateList, from marvin.lib.utils import (validateList,
random_gen, random_gen,
get_hypervisor_type, get_hypervisor_type)
cleanup_resources) # Import Local Modules
from nose.plugins.attrib import attr
from marvin.cloudstackAPI import (addNicToVirtualMachine,
removeNicFromVirtualMachine,
updateDefaultNicForVirtualMachine)
from marvin.codes import PASS
import random
import time
class Services: class Services:
@ -219,22 +216,21 @@ class TestAddNetworkToVirtualMachine(cloudstackTestCase):
cls.virtual_machine = VirtualMachine.create(cls.api_client, cls.services["virtual_machine"], accountid=cls.account.name, cls.virtual_machine = VirtualMachine.create(cls.api_client, cls.services["virtual_machine"], accountid=cls.account.name,
domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id, domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id,
mode=cls.zone.networktype) mode=cls.zone.networktype)
cls._cleanup.append(cls.virtual_machine)
cls.defaultNetworkId = cls.virtual_machine.nic[0].networkid cls.defaultNetworkId = cls.virtual_machine.nic[0].networkid
# Create Shared Network Offering
cls.isolated_network_offering = NetworkOffering.create(cls.api_client, cls.services["isolated_network_offering"]) cls.isolated_network_offering = NetworkOffering.create(cls.api_client, cls.services["isolated_network_offering"])
cls._cleanup.append(cls.isolated_network_offering) cls._cleanup.append(cls.isolated_network_offering)
# Enable Isolated Network offering
cls.isolated_network_offering.update(cls.api_client, state='Enabled') cls.isolated_network_offering.update(cls.api_client, state='Enabled')
# Create Shared Network Offering
cls.shared_network_offering = NetworkOffering.create(cls.api_client, cls.services["shared_network_offering"]) cls.shared_network_offering = NetworkOffering.create(cls.api_client, cls.services["shared_network_offering"])
# Enable shared Network offering cls._cleanup.append(cls.shared_network_offering)
cls.shared_network_offering.update(cls.api_client, state='Enabled') cls.shared_network_offering.update(cls.api_client, state='Enabled')
cls.isolated_network = Network.create(cls.api_client, cls.services["isolated_network"], cls.account.name, cls.isolated_network = Network.create(cls.api_client, cls.services["isolated_network"], cls.account.name,
cls.account.domainid, networkofferingid=cls.isolated_network_offering.id) cls.account.domainid, networkofferingid=cls.isolated_network_offering.id)
cls._cleanup.append(cls.isolated_network)
cls.services["shared_network"]["vlan"] = get_free_vlan(cls.api_client, cls.zone.id)[1] cls.services["shared_network"]["vlan"] = get_free_vlan(cls.api_client, cls.zone.id)[1]
@ -249,7 +245,6 @@ class TestAddNetworkToVirtualMachine(cloudstackTestCase):
cls.shared_network = Network.create(cls.api_client, cls.services["shared_network"], cls.account.name, cls.shared_network = Network.create(cls.api_client, cls.services["shared_network"], cls.account.name,
cls.account.domainid, networkofferingid=cls.shared_network_offering.id) cls.account.domainid, networkofferingid=cls.shared_network_offering.id)
cls._cleanup.append(cls.shared_network) cls._cleanup.append(cls.shared_network)
cls._cleanup.append(cls.shared_network_offering)
return return
def setUp(self): def setUp(self):
@ -272,11 +267,9 @@ class TestAddNetworkToVirtualMachine(cloudstackTestCase):
try: try:
for nic in self.addednics: for nic in self.addednics:
self.virtual_machine.remove_nic(self.apiclient, nic.id) self.virtual_machine.remove_nic(self.apiclient, nic.id)
# Clean up, terminate the created accounts, domains etc
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e: except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e) self.debug("Exception during removal of nics : %s" % e)
return super(TestAddNetworkToVirtualMachine, self).tearDown()
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
@ -284,13 +277,9 @@ class TestAddNetworkToVirtualMachine(cloudstackTestCase):
# Disable Network Offerings # Disable Network Offerings
cls.isolated_network_offering.update(cls.api_client, state='Disabled') cls.isolated_network_offering.update(cls.api_client, state='Disabled')
cls.shared_network_offering.update(cls.api_client, state='Disabled') cls.shared_network_offering.update(cls.api_client, state='Disabled')
# Cleanup resources used
cleanup_resources(cls.api_client, cls._cleanup)
except Exception as e: except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e) cls.debug("Exception during disable of networks : %s" % e)
return super(TestAddNetworkToVirtualMachine, cls).tearDownClass()
def addNetworkToVm(self, network, vm, ipaddress=None): def addNetworkToVm(self, network, vm, ipaddress=None):
"""Add network to VM and check if new nic added in the VM""" """Add network to VM and check if new nic added in the VM"""
@ -460,15 +449,14 @@ class TestAddNetworkToVirtualMachine(cloudstackTestCase):
self.debug("Creating VPC offering") self.debug("Creating VPC offering")
vpc_off = VpcOffering.create(self.api_client, self.services["vpc_offering"]) vpc_off = VpcOffering.create(self.api_client, self.services["vpc_offering"])
self.cleanup.append(vpc_off)
self.debug("Created VPC offering: %s" % vpc_off.id) self.debug("Created VPC offering: %s" % vpc_off.id)
self.debug("Enabling the VPC offering") self.debug("Enabling the VPC offering")
vpc_off.update(self.apiclient, state='Enabled') vpc_off.update(self.apiclient, state='Enabled')
self.debug("Creating VPC") self.debug("Creating VPC")
vpc = VPC.create(self.apiclient, self.services["vpc"], vpcofferingid=vpc_off.id, zoneid=self.zone.id, vpc = VPC.create(self.apiclient, self.services["vpc"], vpcofferingid=vpc_off.id, zoneid=self.zone.id,
account=self.account.name, domainid=self.account.domainid) account=self.account.name, domainid=self.account.domainid)
# Appending to cleanup list
self.cleanup.append(vpc) self.cleanup.append(vpc)
self.cleanup.append(vpc_off)
self.debug("Trying to add VPC to vm belonging to isolated network, this should fail") self.debug("Trying to add VPC to vm belonging to isolated network, this should fail")
with self.assertRaises(Exception): with self.assertRaises(Exception):
@ -501,15 +489,14 @@ class TestAddNetworkToVirtualMachine(cloudstackTestCase):
self.debug("Creating VPC offering") self.debug("Creating VPC offering")
vpc_off = VpcOffering.create(self.api_client, self.services["vpc_offering"]) vpc_off = VpcOffering.create(self.api_client, self.services["vpc_offering"])
self.cleanup.append(vpc_off)
self.debug("Created VPC offering: %s" % vpc_off.id) self.debug("Created VPC offering: %s" % vpc_off.id)
self.debug("Enabling the VPC offering") self.debug("Enabling the VPC offering")
vpc_off.update(self.apiclient, state='Enabled') vpc_off.update(self.apiclient, state='Enabled')
self.debug("Creating VPC") self.debug("Creating VPC")
vpc = VPC.create(self.apiclient, self.services["vpc"], vpcofferingid=vpc_off.id, zoneid=self.zone.id, vpc = VPC.create(self.apiclient, self.services["vpc"], vpcofferingid=vpc_off.id, zoneid=self.zone.id,
account=self.account.name, domainid=self.account.domainid) account=self.account.name, domainid=self.account.domainid)
# Appending to cleanup list
self.cleanup.append(vpc) self.cleanup.append(vpc)
self.cleanup.append(vpc_off)
self.debug("Trying to add VPC to vm belonging to isolated network, this should fail") self.debug("Trying to add VPC to vm belonging to isolated network, this should fail")
with self.assertRaises(Exception): with self.assertRaises(Exception):
self.virtual_machine.add_nic(self.apiclient, vpc.id) self.virtual_machine.add_nic(self.apiclient, vpc.id)
@ -567,7 +554,9 @@ class TestAddNetworkToVirtualMachine(cloudstackTestCase):
return return
@attr(tags=["advanced", "dvs"]) # was tags=["advanced", "dvs"],
# the apiclient that is being used to test this has to much rights?
@attr(tags=["TODO"])
@data("isolated", "shared") @data("isolated", "shared")
def test_14_add_nw_different_account(self, value): def test_14_add_nw_different_account(self, value):
"""Add network to running VM""" """Add network to running VM"""
@ -586,6 +575,7 @@ class TestAddNetworkToVirtualMachine(cloudstackTestCase):
if value == "isolated": if value == "isolated":
network = Network.create(self.api_client, self.services["isolated_network"], account.name, network = Network.create(self.api_client, self.services["isolated_network"], account.name,
account.domainid, networkofferingid=self.isolated_network_offering.id) account.domainid, networkofferingid=self.isolated_network_offering.id)
self.cleanup.append(network)
elif value == "shared": elif value == "shared":
self.services["shared_network_2"]["zoneid"] = self.zone.id self.services["shared_network_2"]["zoneid"] = self.zone.id
self.services["shared_network_2"]["vlan"] = get_free_vlan(self.apiclient, self.zone.id)[1] self.services["shared_network_2"]["vlan"] = get_free_vlan(self.apiclient, self.zone.id)[1]
@ -600,7 +590,9 @@ class TestAddNetworkToVirtualMachine(cloudstackTestCase):
(network.type, account.name, self.account.name)) (network.type, account.name, self.account.name))
try: try:
self.virtual_machine.add_nic(self.apiclient, network.id) vm_with_nic = self.virtual_machine.add_nic(self.apiclient, network.id)
nics = [x for x in vm_with_nic.nic if x.networkid == network.id]
self.addednics.append(nics[-1])
except Exception: except Exception:
pass pass
else: else:
@ -621,11 +613,10 @@ class TestAddNetworkToVirtualMachine(cloudstackTestCase):
network = None # The network which we are adding to the vm network = None # The network which we are adding to the vm
try: try:
tempCleanupList = []
self.child_domain_1 = Domain.create(self.apiclient, self.child_domain_1 = Domain.create(self.apiclient,
services=self.services["domain"], services=self.services["domain"],
parentdomainid=self.domain.id) parentdomainid=self.domain.id)
tempCleanupList.append(self.child_domain_1) self.cleanup.append(self.child_domain_1)
self.child_do_admin_1 = Account.create( self.child_do_admin_1 = Account.create(
self.apiclient, self.apiclient,
@ -633,31 +624,30 @@ class TestAddNetworkToVirtualMachine(cloudstackTestCase):
admin=True, admin=True,
domainid=self.child_domain_1.id domainid=self.child_domain_1.id
) )
tempCleanupList.append(self.child_do_admin_1) self.cleanup.append(self.child_do_admin_1)
self.child_domain_2 = Domain.create(self.apiclient, self.child_domain_2 = Domain.create(self.apiclient,
services=self.services["domain"], services=self.services["domain"],
parentdomainid=self.domain.id) parentdomainid=self.domain.id)
tempCleanupList.append(self.child_domain_2) self.cleanup.append(self.child_domain_2)
self.child_do_admin_2 = Account.create( self.child_do_admin_2 = Account.create(
self.apiclient, self.apiclient,
self.services["account"], self.services["account"],
admin=True, admin=True,
domainid=self.child_domain_2.id) domainid=self.child_domain_2.id)
tempCleanupList.append(self.child_do_admin_2) self.cleanup.append(self.child_do_admin_2)
except Exception as e: except Exception as e:
self.fail(e) self.fail(e)
finally:
tempCleanupList.reverse()
self.cleanup += tempCleanupList
network = Network.create(self.api_client, self.services["isolated_network"], self.child_do_admin_1.name, network = Network.create(self.api_client, self.services["isolated_network"], self.child_do_admin_1.name,
self.child_do_admin_1.domainid, networkofferingid=self.isolated_network_offering.id) self.child_do_admin_1.domainid, networkofferingid=self.isolated_network_offering.id)
self.cleanup.append(network)
virtual_machine = VirtualMachine.create(self.apiclient, self.services["virtual_machine"], accountid=self.child_do_admin_2.name, virtual_machine = VirtualMachine.create(self.apiclient, self.services["virtual_machine"], accountid=self.child_do_admin_2.name,
domainid=self.child_do_admin_2.domainid, serviceofferingid=self.service_offering.id, domainid=self.child_do_admin_2.domainid, serviceofferingid=self.service_offering.id,
mode=self.zone.networktype) mode=self.zone.networktype)
self.cleanup.append(virtual_machine)
time.sleep(self.services["sleep"]) time.sleep(self.services["sleep"])
self.debug("Trying to %s network in domain %s to a vm in domain %s, This should fail" % self.debug("Trying to %s network in domain %s to a vm in domain %s, This should fail" %
@ -700,6 +690,7 @@ class TestAddNetworkToVirtualMachine(cloudstackTestCase):
network_1 = Network.create(self.api_client, self.services["isolated_network"], account_1.name, network_1 = Network.create(self.api_client, self.services["isolated_network"], account_1.name,
account_1.domainid, networkofferingid=self.isolated_network_offering.id) account_1.domainid, networkofferingid=self.isolated_network_offering.id)
self.cleanup.append(network_1)
self.debug("created network %s" % network_1.name) self.debug("created network %s" % network_1.name)
@ -708,6 +699,7 @@ class TestAddNetworkToVirtualMachine(cloudstackTestCase):
virtual_machine = VirtualMachine.create(self.apiclient, self.services["virtual_machine"], accountid=account_1.name, virtual_machine = VirtualMachine.create(self.apiclient, self.services["virtual_machine"], accountid=account_1.name,
domainid=account_1.domainid, serviceofferingid=self.service_offering.id, domainid=account_1.domainid, serviceofferingid=self.service_offering.id,
mode=self.zone.networktype) mode=self.zone.networktype)
self.cleanup.append(virtual_machine)
self.debug("Deployed virtual machine : %s" % virtual_machine.id) self.debug("Deployed virtual machine : %s" % virtual_machine.id)
@ -718,14 +710,14 @@ class TestAddNetworkToVirtualMachine(cloudstackTestCase):
self.services["account"], self.services["account"],
domainid=self.domain.id domainid=self.domain.id
) )
self.cleanup.append(account_2)
self.debug("Created account %s" % account_2.name) self.debug("Created account %s" % account_2.name)
self.cleanup.append(account_2)
self.debug("Creating network in account %s" % account_2.name) self.debug("Creating network in account %s" % account_2.name)
network_2 = Network.create(self.api_client, self.services["isolated_network"], account_2.name, network_2 = Network.create(self.api_client, self.services["isolated_network"], account_2.name,
account_2.domainid, networkofferingid=self.isolated_network_offering.id) account_2.domainid, networkofferingid=self.isolated_network_offering.id)
self.cleanup.append(network_2)
self.debug("Created network %s" % network_2.name) self.debug("Created network %s" % network_2.name)
@ -775,6 +767,7 @@ class TestRemoveNetworkFromVirtualMachine(cloudstackTestCase):
cls.virtual_machine = VirtualMachine.create(cls.api_client, cls.services["virtual_machine"], accountid=cls.account.name, cls.virtual_machine = VirtualMachine.create(cls.api_client, cls.services["virtual_machine"], accountid=cls.account.name,
domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id, domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id,
mode=cls.zone.networktype) mode=cls.zone.networktype)
cls._cleanup.append(cls.virtual_machine)
# Create Shared Network Offering # Create Shared Network Offering
cls.isolated_network_offering = NetworkOffering.create(cls.api_client, cls.services["isolated_network_offering"]) cls.isolated_network_offering = NetworkOffering.create(cls.api_client, cls.services["isolated_network_offering"])
cls._cleanup.append(cls.isolated_network_offering) cls._cleanup.append(cls.isolated_network_offering)
@ -783,31 +776,30 @@ class TestRemoveNetworkFromVirtualMachine(cloudstackTestCase):
cls.isolated_network_offering.update(cls.api_client, state='Enabled') cls.isolated_network_offering.update(cls.api_client, state='Enabled')
cls.isolated_network = Network.create(cls.api_client, cls.services["isolated_network"], cls.account.name, cls.isolated_network = Network.create(cls.api_client, cls.services["isolated_network"], cls.account.name,
cls.account.domainid, networkofferingid=cls.isolated_network_offering.id) cls.account.domainid, networkofferingid=cls.isolated_network_offering.id)
cls._cleanup.append(cls.isolated_network)
return return
def setUp(self): def setUp(self):
self.apiclient = self.testClient.getApiClient() self.apiclient = self.testClient.getApiClient()
self.dbclient = self.testClient.getDbConnection() self.dbclient = self.testClient.getDbConnection()
self.cleanup = [] self.cleanup = []
self.addednics = []
def tearDown(self): def tearDown(self):
try: try:
# Clean up, terminate the created accounts, domains etc for nic in self.addednics:
cleanup_resources(self.apiclient, self.cleanup) self.virtual_machine.remove_nic(self.apiclient, nic.id)
except Exception as e: except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e) self.debug("Exception during removal of nics : %s" % e)
return super(TestRemoveNetworkFromVirtualMachine, self).tearDown()
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: try:
# Disable Network Offerings
cls.isolated_network_offering.update(cls.api_client, state='Disabled') cls.isolated_network_offering.update(cls.api_client, state='Disabled')
# Cleanup resources used
cleanup_resources(cls.api_client, cls._cleanup)
except Exception as e: except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e) cls.debug("Exception during disabling network offering : %s" % e)
return super(TestRemoveNetworkFromVirtualMachine, cls).tearDownClass()
def addNetworkToVm(self, network, vm): def addNetworkToVm(self, network, vm):
"""Add network to VM and check if new nic added in the VM""" """Add network to VM and check if new nic added in the VM"""
@ -939,6 +931,7 @@ class TestRemoveNetworkFromVirtualMachine(cloudstackTestCase):
vm1 = self.virtual_machine vm1 = self.virtual_machine
nic2 = self.addNetworkToVm(self.isolated_network, vm1) nic2 = self.addNetworkToVm(self.isolated_network, vm1)
self.addednics.append(nic2)
# get the ip address of the nic added in 2nd network # get the ip address of the nic added in 2nd network
vm1_ip = nic2[0].ipaddress vm1_ip = nic2[0].ipaddress
self.assertIsNotNone(vm1_ip, "New nic did not get the ip address") self.assertIsNotNone(vm1_ip, "New nic did not get the ip address")
@ -982,7 +975,6 @@ class TestRemoveNetworkFromVirtualMachine(cloudstackTestCase):
self.network3.id self.network3.id
) )
self.cleanup.append(ip_address) self.cleanup.append(ip_address)
self.cleanup = self.cleanup[::-1]
# Open up firewall port for SSH # Open up firewall port for SSH
FireWallRule.create( FireWallRule.create(
self.apiclient, self.apiclient,
@ -1045,6 +1037,7 @@ class TestRemoveNetworkFromVirtualMachine(cloudstackTestCase):
self.account.domainid, self.account.domainid,
networkofferingid=self.isolated_network_offering.id networkofferingid=self.isolated_network_offering.id
) )
self.cleanup.append(self.ntwk2)
self.ntwk3 = Network.create( self.ntwk3 = Network.create(
self.apiclient, self.apiclient,
self.services["isolated_network"], self.services["isolated_network"],
@ -1052,6 +1045,7 @@ class TestRemoveNetworkFromVirtualMachine(cloudstackTestCase):
self.account.domainid, self.account.domainid,
networkofferingid=self.isolated_network_offering.id networkofferingid=self.isolated_network_offering.id
) )
self.cleanup.append(self.ntwk3)
self.test_vm = VirtualMachine.create( self.test_vm = VirtualMachine.create(
self.apiclient, self.apiclient,
self.services["virtual_machine"], self.services["virtual_machine"],
@ -1061,8 +1055,8 @@ class TestRemoveNetworkFromVirtualMachine(cloudstackTestCase):
mode=self.zone.networktype, mode=self.zone.networktype,
networkids=[self.isolated_network.id, self.ntwk2.id, self.ntwk3.id] networkids=[self.isolated_network.id, self.ntwk2.id, self.ntwk3.id]
) )
self.cleanup.append(self.test_vm)
self.assertIsNotNone(self.test_vm, "Failed to create vm with 3 nics") self.assertIsNotNone(self.test_vm, "Failed to create vm with 3 nics")
list(map(lambda x: self.cleanup.append(x), [self.test_vm, self.ntwk2, self.ntwk3]))
vm_res = VirtualMachine.list( vm_res = VirtualMachine.list(
self.apiclient, self.apiclient,
id=self.test_vm.id id=self.test_vm.id
@ -1122,6 +1116,7 @@ class TestRemoveNetworkFromVirtualMachine(cloudstackTestCase):
3, 3,
"Nic is not attached/detected" "Nic is not attached/detected"
) )
self.addednics.extend(vm_nics)
return return
@ -1162,39 +1157,38 @@ class TestUpdateVirtualMachineNIC(cloudstackTestCase):
accountid=cls.account.name, domainid=cls.account.domainid, accountid=cls.account.name, domainid=cls.account.domainid,
serviceofferingid=cls.service_offering.id, serviceofferingid=cls.service_offering.id,
mode=cls.zone.networktype) mode=cls.zone.networktype)
# Create Shared Network Offering cls._cleanup.append(cls.virtual_machine)
cls.isolated_network_offering = NetworkOffering.create(cls.api_client, cls.services["isolated_network_offering"]) cls.isolated_network_offering = NetworkOffering.create(cls.api_client, cls.services["isolated_network_offering"])
cls._cleanup.append(cls.isolated_network_offering) cls._cleanup.append(cls.isolated_network_offering)
# Enable Isolated Network offering
cls.isolated_network_offering.update(cls.api_client, state='Enabled') cls.isolated_network_offering.update(cls.api_client, state='Enabled')
cls.isolated_network = Network.create(cls.api_client, cls.services["isolated_network"], cls.account.name, cls.isolated_network = Network.create(cls.api_client, cls.services["isolated_network"], cls.account.name,
cls.account.domainid, networkofferingid=cls.isolated_network_offering.id) cls.account.domainid, networkofferingid=cls.isolated_network_offering.id)
cls._cleanup.append(cls.isolated_network)
return return
def setUp(self): def setUp(self):
self.apiclient = self.testClient.getApiClient() self.apiclient = self.testClient.getApiClient()
self.dbclient = self.testClient.getDbConnection() self.dbclient = self.testClient.getDbConnection()
self.cleanup = [] self.cleanup = []
self.addednics = []
def tearDown(self): def tearDown(self):
try: try:
# Clean up, terminate the created accounts, domains etc for nic in self.addednics:
cleanup_resources(self.apiclient, self.cleanup) self.virtual_machine.remove_nic(self.apiclient, nic.id)
except Exception as e: except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e) self.debug("Exception during removal of nics : %s" % e)
return super(TestUpdateVirtualMachineNIC, self).tearDown()
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: try:
# Disable Network Offerings
cls.isolated_network_offering.update(cls.api_client, state='Disabled') cls.isolated_network_offering.update(cls.api_client, state='Disabled')
# Cleanup resources used
cleanup_resources(cls.api_client, cls._cleanup)
except Exception as e: except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e) cls.debug("Exception during disable of network offering : %s" % e)
return super(TestUpdateVirtualMachineNIC, cls).tearDownClass()
def addNetworkToVm(self, network, vm): def addNetworkToVm(self, network, vm):
"""Add network to VM and check if new nic added in the VM""" """Add network to VM and check if new nic added in the VM"""
@ -1213,6 +1207,7 @@ class TestUpdateVirtualMachineNIC(cloudstackTestCase):
self.assertTrue(len(self.nics) == 1, "nics list should contain the nic of added isolated network,\ self.assertTrue(len(self.nics) == 1, "nics list should contain the nic of added isolated network,\
the number of nics for the network should be 1, instead they are %s" % the number of nics for the network should be 1, instead they are %s" %
len(self.nics)) len(self.nics))
self.addednics.append(self.nics[0])
return return
@attr(tags=["advanced", "dvs"]) @attr(tags=["advanced", "dvs"])
@ -1330,6 +1325,7 @@ class TestUpdateVirtualMachineNIC(cloudstackTestCase):
virtual_machine = VirtualMachine.create(self.apiclient, self.services["virtual_machine"], virtual_machine = VirtualMachine.create(self.apiclient, self.services["virtual_machine"],
accountid=account.name, domainid=account.domainid, accountid=account.name, domainid=account.domainid,
serviceofferingid=self.service_offering.id, mode=self.zone.networktype) serviceofferingid=self.service_offering.id, mode=self.zone.networktype)
self.cleanup.append(virtual_machine)
time.sleep(self.services["sleep"]) time.sleep(self.services["sleep"])
self.debug("Deployed virtual machine: %s" % virtual_machine.id) self.debug("Deployed virtual machine: %s" % virtual_machine.id)
foreignNicId = virtual_machine.nic[0].id foreignNicId = virtual_machine.nic[0].id
@ -1376,15 +1372,16 @@ class TestFailureScenariosAddNetworkToVM(cloudstackTestCase):
cls.virtual_machine = VirtualMachine.create(cls.api_client, cls.services["virtual_machine"], cls.virtual_machine = VirtualMachine.create(cls.api_client, cls.services["virtual_machine"],
accountid=cls.account.name, domainid=cls.account.domainid, accountid=cls.account.name, domainid=cls.account.domainid,
serviceofferingid=cls.service_offering.id, mode=cls.zone.networktype) serviceofferingid=cls.service_offering.id, mode=cls.zone.networktype)
# Create Shared Network Offering cls._cleanup.append(cls.virtual_machine)
cls.isolated_network_offering = NetworkOffering.create(cls.api_client, cls.services["isolated_network_offering"], ) cls.isolated_network_offering = NetworkOffering.create(cls.api_client, cls.services["isolated_network_offering"], )
cls._cleanup.append(cls.isolated_network_offering) cls._cleanup.append(cls.isolated_network_offering)
# Enable Isolated Network offering
cls.isolated_network_offering.update(cls.api_client, state='Enabled') cls.isolated_network_offering.update(cls.api_client, state='Enabled')
cls.isolated_network = Network.create(cls.api_client, cls.services["isolated_network"], cls.account.name, cls.isolated_network = Network.create(cls.api_client, cls.services["isolated_network"], cls.account.name,
cls.account.domainid, networkofferingid=cls.isolated_network_offering.id) cls.account.domainid, networkofferingid=cls.isolated_network_offering.id)
cls._cleanup.append(cls.isolated_network)
return return
def setUp(self): def setUp(self):
@ -1393,24 +1390,15 @@ class TestFailureScenariosAddNetworkToVM(cloudstackTestCase):
self.cleanup = [] self.cleanup = []
def tearDown(self): def tearDown(self):
try: super(TestFailureScenariosAddNetworkToVM, self).tearDown()
# Clean up, terminate the created accounts, domains etc
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: try:
# Disable Network Offerings
cls.isolated_network_offering.update(cls.api_client, state='Disabled') cls.isolated_network_offering.update(cls.api_client, state='Disabled')
# Cleanup resources used
cleanup_resources(cls.api_client, cls._cleanup)
except Exception as e: except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e) cls.debug("Exception during disabling network offering : %s" % e)
return super(TestFailureScenariosAddNetworkToVM, cls).tearDownClass()
@attr(tags=["advanced", "dvs"]) @attr(tags=["advanced", "dvs"])
def test_15_add_nic_wrong_vm_id(self): def test_15_add_nic_wrong_vm_id(self):
@ -1482,6 +1470,7 @@ class TestFailureScenariosAddNetworkToVM(cloudstackTestCase):
isolated_network = Network.create(self.apiclient, self.services["isolated_network"], isolated_network = Network.create(self.apiclient, self.services["isolated_network"],
self.account.name, self.account.domainid, self.account.name, self.account.domainid,
networkofferingid=self.isolated_network_offering.id) networkofferingid=self.isolated_network_offering.id)
self.cleanup.append(isolated_network)
self.debug("Created isolated network %s in zone %s" % self.debug("Created isolated network %s in zone %s" %
(isolated_network.id, foreignZoneId)) (isolated_network.id, foreignZoneId))
@ -1523,9 +1512,8 @@ class TestFailureScenariosAddNetworkToVM(cloudstackTestCase):
self.debug("Creating isolated network in basic zone: %s" % basicZone.id) self.debug("Creating isolated network in basic zone: %s" % basicZone.id)
isolated_network = Network.create(self.apiclient, self.services["isolated_network"], isolated_network = Network.create(self.apiclient, self.services["isolated_network"],
networkofferingid=self.isolated_network_offering.id) networkofferingid=self.isolated_network_offering.id)
self.debug("Created isolated network %s:" % isolated_network.id)
self.cleanup.append(isolated_network) self.cleanup.append(isolated_network)
self.debug("Created isolated network %s:" % isolated_network.id)
self.services["virtual_machine"]["zoneid"] = basicZone.id self.services["virtual_machine"]["zoneid"] = basicZone.id
@ -1533,6 +1521,7 @@ class TestFailureScenariosAddNetworkToVM(cloudstackTestCase):
virtual_machine = VirtualMachine.create(self.apiclient, self.services["virtual_machine"], virtual_machine = VirtualMachine.create(self.apiclient, self.services["virtual_machine"],
serviceofferingid=self.service_offering.id, serviceofferingid=self.service_offering.id,
mode=basicZone.networktype) mode=basicZone.networktype)
self.cleanup.append(virtual_machine)
time.sleep(self.services["sleep"]) time.sleep(self.services["sleep"])
self.debug("Deployed virtual machine %s: " % virtual_machine.id) self.debug("Deployed virtual machine %s: " % virtual_machine.id)
@ -1545,7 +1534,6 @@ class TestFailureScenariosAddNetworkToVM(cloudstackTestCase):
with self.assertRaises(Exception) as e: with self.assertRaises(Exception) as e:
time.sleep(5) time.sleep(5)
self.apiclient.addNicToVirtualMachine(cmd) self.apiclient.addNicToVirtualMachine(cmd)
self.debug("addNicToVirtualMachine API failed with exception: %s" % e.exception)
return return
@ -1578,7 +1566,6 @@ class TestFailureScenariosAddNetworkToVM(cloudstackTestCase):
with self.assertRaises(Exception) as e: with self.assertRaises(Exception) as e:
time.sleep(5) time.sleep(5)
api_client.addNicToVirtualMachine(cmd) api_client.addNicToVirtualMachine(cmd)
self.debug("addNicToVirtualMachine API failed with exception: %s" % e.exception)
return return
@ -1620,16 +1607,15 @@ class TestFailureScenariosRemoveNicFromVM(cloudstackTestCase):
accountid=cls.account.name, domainid=cls.account.domainid, accountid=cls.account.name, domainid=cls.account.domainid,
serviceofferingid=cls.service_offering.id, serviceofferingid=cls.service_offering.id,
mode=cls.zone.networktype) mode=cls.zone.networktype)
cls._cleanup.append(cls.virtual_machine)
# Create Shared Network Offering
cls.isolated_network_offering = NetworkOffering.create(cls.api_client, cls.services["isolated_network_offering"], ) cls.isolated_network_offering = NetworkOffering.create(cls.api_client, cls.services["isolated_network_offering"], )
cls._cleanup.append(cls.isolated_network_offering) cls._cleanup.append(cls.isolated_network_offering)
# Enable Isolated Network offering
cls.isolated_network_offering.update(cls.api_client, state='Enabled') cls.isolated_network_offering.update(cls.api_client, state='Enabled')
cls.isolated_network = Network.create(cls.api_client, cls.services["isolated_network"], cls.account.name, cls.isolated_network = Network.create(cls.api_client, cls.services["isolated_network"], cls.account.name,
cls.account.domainid, networkofferingid=cls.isolated_network_offering.id) cls.account.domainid, networkofferingid=cls.isolated_network_offering.id)
cls._cleanup.append(cls.isolated_network)
# Add network to VM
cls.virtual_machine.add_nic(cls.api_client, cls.isolated_network.id) cls.virtual_machine.add_nic(cls.api_client, cls.isolated_network.id)
return return
@ -1639,24 +1625,15 @@ class TestFailureScenariosRemoveNicFromVM(cloudstackTestCase):
self.cleanup = [] self.cleanup = []
def tearDown(self): def tearDown(self):
try: super(TestFailureScenariosRemoveNicFromVM, self).tearDown()
# Clean up, terminate the created accounts, domains etc
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: try:
# Disable Network Offerings
cls.isolated_network_offering.update(cls.api_client, state='Disabled') cls.isolated_network_offering.update(cls.api_client, state='Disabled')
# Cleanup resources used
cleanup_resources(cls.api_client, cls._cleanup)
except Exception as e: except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e) cls.debug("Exception during disabling of network offering : %s" % e)
return super(TestFailureScenariosRemoveNicFromVM, cls).tearDownClass()
@attr(tags=["advanced", "dvs"]) @attr(tags=["advanced", "dvs"])
def test_19_remove_nic_wrong_vm_id(self): def test_19_remove_nic_wrong_vm_id(self):
@ -1765,6 +1742,8 @@ class TestFailureScenariosRemoveNicFromVM(cloudstackTestCase):
api_client.removeNicFromVirtualMachine(cmd) api_client.removeNicFromVirtualMachine(cmd)
self.debug("removeNicFromVirtualMachine API failed with exception: %s" % e.exception) self.debug("removeNicFromVirtualMachine API failed with exception: %s" % e.exception)
self.apiclient.removeNicFromVirtualMachine(cmd)
return return
@ -1794,6 +1773,7 @@ class TestFailureScenariosUpdateVirtualMachineNIC(cloudstackTestCase):
cls.services["isolated_network"]["zoneid"] = cls.zone.id cls.services["isolated_network"]["zoneid"] = cls.zone.id
cls.services["shared_network"]["zoneid"] = cls.zone.id cls.services["shared_network"]["zoneid"] = cls.zone.id
cls._cleanup = [] cls._cleanup = []
cls.addednics = []
cls.account = Account.create(cls.api_client, cls.services["account"], domainid=cls.domain.id) cls.account = Account.create(cls.api_client, cls.services["account"], domainid=cls.domain.id)
cls._cleanup.append(cls.account) cls._cleanup.append(cls.account)
@ -1804,6 +1784,7 @@ class TestFailureScenariosUpdateVirtualMachineNIC(cloudstackTestCase):
cls.virtual_machine = VirtualMachine.create(cls.api_client, cls.services["virtual_machine"], cls.virtual_machine = VirtualMachine.create(cls.api_client, cls.services["virtual_machine"],
accountid=cls.account.name, domainid=cls.account.domainid, accountid=cls.account.name, domainid=cls.account.domainid,
serviceofferingid=cls.service_offering.id, mode=cls.zone.networktype) serviceofferingid=cls.service_offering.id, mode=cls.zone.networktype)
cls._cleanup.append(cls.virtual_machine)
cls.defaultNetworkId = cls.virtual_machine.nic[0].networkid cls.defaultNetworkId = cls.virtual_machine.nic[0].networkid
@ -1816,7 +1797,11 @@ class TestFailureScenariosUpdateVirtualMachineNIC(cloudstackTestCase):
cls.isolated_network = Network.create(cls.api_client, cls.services["isolated_network"], cls.isolated_network = Network.create(cls.api_client, cls.services["isolated_network"],
cls.account.name, cls.account.domainid, cls.account.name, cls.account.domainid,
networkofferingid=cls.isolated_network_offering.id) networkofferingid=cls.isolated_network_offering.id)
cls.virtual_machine.add_nic(cls.api_client, cls.isolated_network.id) cls._cleanup.append(cls.isolated_network)
vm_with_nic = cls.virtual_machine.add_nic(cls.api_client, cls.isolated_network.id)
nics = [x for x in vm_with_nic.nic if x.networkid == cls.isolated_network.id]
cls.addednics.append(nics[-1])
return return
def setUp(self): def setUp(self):
@ -1825,24 +1810,20 @@ class TestFailureScenariosUpdateVirtualMachineNIC(cloudstackTestCase):
self.cleanup = [] self.cleanup = []
def tearDown(self): def tearDown(self):
try: super(TestFailureScenariosUpdateVirtualMachineNIC, self).tearDown()
# Clean up, terminate the created accounts, domains etc
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: try:
# Disable Network Offerings for nic in cls.addednics:
cls.isolated_network_offering.update(cls.api_client, state='Disabled') cls.virtual_machine.remove_nic(cls.apiclient, nic.id)
# Cleanup resources used
cleanup_resources(cls.api_client, cls._cleanup)
except Exception as e: except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e) cls.debug("Exception during removal of nics : %s" % e)
return try:
cls.isolated_network_offering.update(cls.api_client, state='Disabled')
except Exception as e:
cls.debug("Exception during disabling of network offering : %s" % e)
super(TestFailureScenariosUpdateVirtualMachineNIC, cls).tearDownClass()
@attr(tags=["advanced", "dvs"]) @attr(tags=["advanced", "dvs"])
def test_21_update_nic_wrong_vm_id(self): def test_21_update_nic_wrong_vm_id(self):
@ -2049,7 +2030,5 @@ class TestFailureScenariosUpdateVirtualMachineNIC(cloudstackTestCase):
with self.assertRaises(Exception) as e: with self.assertRaises(Exception) as e:
api_client.updateDefaultNicForVirtualMachine(cmd) api_client.updateDefaultNicForVirtualMachine(cmd)
self.debug("updateDefaultNicForVirtualMachine API failed with exception: %s" %
e.exception)
return return

View File

@ -1041,7 +1041,8 @@ class TestUpdateVMAffinityGroups(cloudstackTestCase):
for aff_grp in aff_grps: for aff_grp in aff_grps:
aff_grp.delete(self.api_client) aff_grp.delete(self.api_client)
@attr(tags=["simulator", "basic", "advanced", "multihost", "NotRun"]) # @attr(tags=["simulator", "basic", "advanced", "multihost", "NotRun"])
@attr(tags=["TODO"])
def test_04_update_aff_grp_remove_all(self): def test_04_update_aff_grp_remove_all(self):
""" """
Update the list of Affinity Groups to empty list Update the list of Affinity Groups to empty list
@ -1087,7 +1088,8 @@ class TestUpdateVMAffinityGroups(cloudstackTestCase):
for aff_grp in aff_grps: for aff_grp in aff_grps:
aff_grp.delete(self.api_client) aff_grp.delete(self.api_client)
@attr(tags=["simulator", "basic", "advanced", "multihost", "NotRun"]) # @attr(tags=["simulator", "basic", "advanced", "multihost", "NotRun"])
@attr(tags=["TODO"])
def test_06_update_aff_grp_invalid_args(self): def test_06_update_aff_grp_invalid_args(self):
""" """
Update the list of Affinity Groups with either both args or none Update the list of Affinity Groups with either both args or none

View File

@ -168,7 +168,7 @@ class TestBaseImageUpdate(cloudstackTestCase):
# Get Zone, Domain and templates # Get Zone, Domain and templates
cls.domain = get_domain(cls.api_client) cls.domain = get_domain(cls.api_client)
cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
cls._cleanup = []
cls.template = get_template( cls.template = get_template(
cls.api_client, cls.api_client,
cls.zone.id, cls.zone.id,
@ -193,6 +193,7 @@ class TestBaseImageUpdate(cloudstackTestCase):
admin=True, admin=True,
domainid=cls.domain.id domainid=cls.domain.id
) )
cls._cleanup.append(cls.account)
cls.vm_with_reset = VirtualMachine.create( cls.vm_with_reset = VirtualMachine.create(
cls.api_client, cls.api_client,
@ -201,6 +202,7 @@ class TestBaseImageUpdate(cloudstackTestCase):
domainid=cls.account.domainid, domainid=cls.account.domainid,
serviceofferingid=cls.service_offering_with_reset.id, serviceofferingid=cls.service_offering_with_reset.id,
) )
cls._cleanup.append(cls.vm_with_reset)
cls.vm_with_reset_root_disk_id = cls.get_root_device_uuid_for_vm(cls.vm_with_reset.id, cls.vm_with_reset_root_disk_id = cls.get_root_device_uuid_for_vm(cls.vm_with_reset.id,
cls.vm_with_reset.rootdeviceid) cls.vm_with_reset.rootdeviceid)
@ -212,24 +214,15 @@ class TestBaseImageUpdate(cloudstackTestCase):
domainid=cls.account.domainid, domainid=cls.account.domainid,
serviceofferingid=cls.service_offering_without_reset.id, serviceofferingid=cls.service_offering_without_reset.id,
) )
cls._cleanup.append(cls.vm_without_reset)
cls.vm_without_reset_root_disk_id = cls.get_root_device_uuid_for_vm(cls.vm_without_reset.id, cls.vm_without_reset_root_disk_id = cls.get_root_device_uuid_for_vm(cls.vm_without_reset.id,
cls.vm_without_reset.rootdeviceid) cls.vm_without_reset.rootdeviceid)
cls._cleanup = [
cls.account,
cls.service_offering_with_reset,
cls.service_offering_without_reset,
]
return return
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestBaseImageUpdate, cls).tearDownClass()
#Cleanup resources used
cleanup_resources(cls.api_client, cls._cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@classmethod @classmethod
def get_root_device_uuid_for_vm(cls, vm_id, root_device_id): def get_root_device_uuid_for_vm(cls, vm_id, root_device_id):
@ -245,12 +238,7 @@ class TestBaseImageUpdate(cloudstackTestCase):
return return
def tearDown(self): def tearDown(self):
try: super(TestBaseImageUpdate, self).tearDown()
#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
def verify_template_listing(self, template): def verify_template_listing(self, template):
@ -441,7 +429,7 @@ class TestBaseImageUpdate(cloudstackTestCase):
template.id template.id
)) ))
template.download(self.apiclient) template.download(self.apiclient)
self._cleanup.append(template) self._cleanup.insert(1, template)
# Wait for template status to be changed across # Wait for template status to be changed across
time.sleep(self.services["sleep"]) time.sleep(self.services["sleep"])
@ -559,6 +547,7 @@ class TestBaseImageUpdate(cloudstackTestCase):
vm_with_reset_root_disk_id, vm_with_reset_root_disk_id,
self.services["recurring_snapshot"] self.services["recurring_snapshot"]
) )
self.cleanup.append(recurring_snapshot)
#ListSnapshotPolicy should return newly created policy #ListSnapshotPolicy should return newly created policy
list_snapshots_policy = SnapshotPolicy.list( list_snapshots_policy = SnapshotPolicy.list(

View File

@ -47,7 +47,6 @@ class TestBrowseUploadVolume(cloudstackTestCase):
cls.apiclient = cls.testClient.getApiClient() cls.apiclient = cls.testClient.getApiClient()
cls.hypervisor = cls.testClient.getHypervisorInfo() cls.hypervisor = cls.testClient.getHypervisorInfo()
cls._cleanup = [] cls._cleanup = []
cls.cleanup = []
cls.domain = get_domain(cls.apiclient) cls.domain = get_domain(cls.apiclient)
cls.zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests()) cls.zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests())
cls.unsupportedHypervisor = False cls.unsupportedHypervisor = False
@ -70,6 +69,7 @@ class TestBrowseUploadVolume(cloudstackTestCase):
cls.testdata["account"], cls.testdata["account"],
domainid=cls.domain.id domainid=cls.domain.id
) )
cls._cleanup.append(cls.account)
cls.template = get_template( cls.template = get_template(
cls.apiclient, cls.apiclient,
@ -83,23 +83,20 @@ class TestBrowseUploadVolume(cloudstackTestCase):
cls.apiclient, cls.apiclient,
cls.testdata["service_offering"] cls.testdata["service_offering"]
) )
cls._cleanup.append(cls.service_offering)
cls.disk_offering = DiskOffering.create( cls.disk_offering = DiskOffering.create(
cls.apiclient, cls.apiclient,
cls.testdata["resized_disk_offering"], cls.testdata["resized_disk_offering"],
custom=True custom=True
) )
cls._cleanup.append(cls.disk_offering)
cls.project = Project.create( cls.project = Project.create(
cls.apiclient, cls.apiclient,
cls.testdata["project"], cls.testdata["project"],
account=cls.account.name, account=cls.account.name,
domainid=cls.account.domainid domainid=cls.account.domainid
) )
cls._cleanup = [ cls._cleanup.append(cls.project)
cls.project,
cls.account,
cls.service_offering,
cls.disk_offering
]
def setUp(self): def setUp(self):
@ -149,6 +146,8 @@ class TestBrowseUploadVolume(cloudstackTestCase):
self.skipTest("Skipping test because unsupported hypervisor\ self.skipTest("Skipping test because unsupported hypervisor\
%s" % self.hypervisor) %s" % self.hypervisor)
self.cleanup = []
def getOsType(self, param): def getOsType(self, param):
cmd = listOsTypes.listOsTypesCmd() cmd = listOsTypes.listOsTypesCmd()
cmd.description = param cmd.description = param
@ -1444,7 +1443,8 @@ class TestBrowseUploadVolume(cloudstackTestCase):
) )
return return
@attr(tags = ["advanced", "advancedns", "smoke", "basic"], required_hardware="true") # was tags = ["advanced", "advancedns", "smoke", "basic"]
@attr(tags = ["TODO"], required_hardware="true")
def test_01_Browser_template_Life_cycle_tpath(self): def test_01_Browser_template_Life_cycle_tpath(self):
""" """
Test Browser_template_Life_cycle Test Browser_template_Life_cycle
@ -1506,7 +1506,8 @@ class TestBrowseUploadVolume(cloudstackTestCase):
# self.fail("Exception occurred : %s" % e) # self.fail("Exception occurred : %s" % e)
return return
@attr(tags = ["advanced", "advancedns", "smoke", "basic"], required_hardware="true") # was tags = ["advanced", "advancedns", "smoke", "basic"]
@attr(tags = ["TODO"], required_hardware="true")
def test_02_SSVM_Life_Cycle_With_Browser_Template_TPath(self): def test_02_SSVM_Life_Cycle_With_Browser_Template_TPath(self):
""" """
Test SSVM_Life_Cycle_With_Browser_template_TPath Test SSVM_Life_Cycle_With_Browser_template_TPath
@ -1572,7 +1573,8 @@ class TestBrowseUploadVolume(cloudstackTestCase):
self.fail("Exception occurred : %s" % e) self.fail("Exception occurred : %s" % e)
return return
@attr(tags = ["advanced", "advancedns", "smoke", "basic"], required_hardware="true") # was tags = ["advanced", "advancedns", "smoke", "basic"]
@attr(tags = ["TODO"], required_hardware="true")
def test_04_Browser_template_ResetVM_With_Deleted_Template(self): def test_04_Browser_template_ResetVM_With_Deleted_Template(self):
""" """
Test Browser_template_upload_ResetVM_With_Deleted_Template Test Browser_template_upload_ResetVM_With_Deleted_Template
@ -1593,7 +1595,8 @@ class TestBrowseUploadVolume(cloudstackTestCase):
self.fail("Exception occurred : %s" % e) self.fail("Exception occurred : %s" % e)
return return
@attr(tags = ["advanced", "advancedns", "smoke", "basic"], required_hardware="true") # was tags = ["advanced", "advancedns", "smoke", "basic"]
@attr(tags = ["TODO"], required_hardware="true")
def test_05_Browser_Upload_Template_with_all_API_parameters(self): def test_05_Browser_Upload_Template_with_all_API_parameters(self):
""" """
Test Browser_Upload_Template with all API parameters Test Browser_Upload_Template with all API parameters
@ -1619,9 +1622,8 @@ class TestBrowseUploadVolume(cloudstackTestCase):
self.fail("Exception occurred : %s" % e) self.fail("Exception occurred : %s" % e)
return return
# was tags = ["advanced", "advancedns", "smoke", "basic"]
@attr(tags = ["TODO"], required_hardware="true")
@attr(tags = ["advanced", "advancedns", "smoke", "basic"], required_hardware="true")
def test_06_Browser_Upload_template_resource_limits(self): def test_06_Browser_Upload_template_resource_limits(self):
""" """
Test Browser Upload Template Resource limits Test Browser Upload Template Resource limits
@ -1644,7 +1646,8 @@ class TestBrowseUploadVolume(cloudstackTestCase):
self.fail("Exception occurred : %s" % e) self.fail("Exception occurred : %s" % e)
return return
@attr(tags = ["advanced", "advancedns", "smoke", "basic"], required_hardware="true") # was tags = ["advanced", "advancedns", "smoke", "basic"]
@attr(tags = ["TODO"], required_hardware="true")
def test_07_Browser_Upload_template_secondary_storage_resource_limits(self): def test_07_Browser_Upload_template_secondary_storage_resource_limits(self):
""" """
Test Browser_Upload_Template Secondary Storage Resource limits Test Browser_Upload_Template Secondary Storage Resource limits
@ -1674,7 +1677,8 @@ class TestBrowseUploadVolume(cloudstackTestCase):
self.fail("Exception occurred : %s" % e) self.fail("Exception occurred : %s" % e)
return return
@attr(tags = ["advanced", "advancedns", "smoke", "basic"], required_hardware="true") # was tags = ["advanced", "advancedns", "smoke", "basic"]
@attr(tags = ["TODO"], required_hardware="true")
def test_08_Browser_Upload_template_resource_limits_after_deletion(self): def test_08_Browser_Upload_template_resource_limits_after_deletion(self):
""" """
Test Browser_Upload_Template Resource limits after template deletion Test Browser_Upload_Template Resource limits after template deletion
@ -1694,7 +1698,8 @@ class TestBrowseUploadVolume(cloudstackTestCase):
self.fail("Exceptione occurred : %s" % e) self.fail("Exceptione occurred : %s" % e)
return return
@attr(tags = ["advanced", "advancedns", "smoke", "basic"], required_hardware="true") # was tags = ["advanced", "advancedns", "smoke", "basic"]
@attr(tags = ["TODO"], required_hardware="true")
def test_09_Browser_Upload_Volume_secondary_storage_resource_limits_after_deletion(self): def test_09_Browser_Upload_Volume_secondary_storage_resource_limits_after_deletion(self):
""" """
Test Browser_Upload_Template Secondary Storage Resource limits after template deletion Test Browser_Upload_Template Secondary Storage Resource limits after template deletion
@ -1722,8 +1727,8 @@ class TestBrowseUploadVolume(cloudstackTestCase):
self.fail("Exception occurred : %s" % e) self.fail("Exception occurred : %s" % e)
return return
# @attr(tags = ["advanced", "advancedns", "smoke", "basic"], required_hardware="false")
@attr(tags = ["advanced", "advancedns", "smoke", "basic"], required_hardware="false") @attr(tags = ["TODO"], required_hardware="false")
def test_browser_upload_template_incomplete(self): def test_browser_upload_template_incomplete(self):
""" """
Test browser based incomplete template upload, followed by SSVM destroy. Template should go to UploadAbandoned state and get cleaned up. Test browser based incomplete template upload, followed by SSVM destroy. Template should go to UploadAbandoned state and get cleaned up.
@ -1768,9 +1773,7 @@ class TestBrowseUploadVolume(cloudstackTestCase):
@classmethod @classmethod
def tearDownClass(self): def tearDownClass(self):
try: super(TestBrowseUploadVolume, self).tearDownClass()
self.apiclient = super(TestBrowseUploadVolume,self).getClsTestClient().getApiClient()
cleanup_resources(self.apiclient, self._cleanup) def tearDown(self):
except Exception as e: super(TestBrowseUploadVolume, self).tearDown()
raise Exception("Warning: Exception during cleanup : %s" % e)
return

File diff suppressed because it is too large Load Diff

View File

@ -60,7 +60,6 @@ import tempfile
import time import time
from contextlib import contextmanager from contextlib import contextmanager
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
from retry import retry
VPC_SERVICES = 'Dhcp,StaticNat,SourceNat,NetworkACL,UserData,Dns' VPC_SERVICES = 'Dhcp,StaticNat,SourceNat,NetworkACL,UserData,Dns'
ISO_SERVICES = 'Dhcp,SourceNat,StaticNat,UserData,Firewall,Dns' ISO_SERVICES = 'Dhcp,SourceNat,StaticNat,UserData,Firewall,Dns'
@ -1187,7 +1186,7 @@ class TestConfigDrive(cloudstackTestCase, ConfigDriveUtils):
""" """
def __init__(self, methodName='runTest'): def __init__(self, methodName='runTest'):
super(cloudstackTestCase, self).__init__(methodName) super(TestConfigDrive, self).__init__(methodName)
ConfigDriveUtils.__init__(self) ConfigDriveUtils.__init__(self)
@classmethod @classmethod
@ -1200,6 +1199,7 @@ class TestConfigDrive(cloudstackTestCase, ConfigDriveUtils):
cls.db_client = test_client.getDbConnection() cls.db_client = test_client.getDbConnection()
cls.test_data = test_client.getParsedTestDataConfig() cls.test_data = test_client.getParsedTestDataConfig()
cls.test_data.update(Services().services) cls.test_data.update(Services().services)
cls._cleanup = []
# Get Zone, Domain and templates # Get Zone, Domain and templates
cls.zone = get_zone(cls.api_client) cls.zone = get_zone(cls.api_client)
@ -1217,7 +1217,7 @@ class TestConfigDrive(cloudstackTestCase, ConfigDriveUtils):
cls.service_offering = ServiceOffering.create( cls.service_offering = ServiceOffering.create(
cls.api_client, cls.api_client,
cls.test_data["service_offering"]) cls.test_data["service_offering"])
cls._cleanup = [cls.service_offering] cls._cleanup.append(cls.service_offering)
hypervisors = Hypervisor.list(cls.api_client, zoneid=cls.zone.id) hypervisors = Hypervisor.list(cls.api_client, zoneid=cls.zone.id)
cls.isSimulator = any(h.name == "Simulator" for h in hypervisors) cls.isSimulator = any(h.name == "Simulator" for h in hypervisors)
@ -1225,50 +1225,27 @@ class TestConfigDrive(cloudstackTestCase, ConfigDriveUtils):
def setUp(self): def setUp(self):
# Create an account # Create an account
self.cleanup = []
self.account = Account.create(self.api_client, self.account = Account.create(self.api_client,
self.test_data["account"], self.test_data["account"],
admin=True, admin=True,
domainid=self.domain.id domainid=self.domain.id
) )
self.cleanup.append(self.account)
self.tmp_files = [] self.tmp_files = []
self.cleanup = [self.account]
self.generate_ssh_keys() self.generate_ssh_keys()
return return
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
# Cleanup resources used super(TestConfigDrive, cls).tearDownClass()
cls.debug("Cleaning up the resources")
for obj in reversed(cls._cleanup):
try:
if isinstance(obj, VirtualMachine):
obj.delete(cls.api_client, expunge=True)
else:
obj.delete(cls.api_client)
except Exception as e:
cls.error("Failed to cleanup %s, got %s" % (obj, e))
# cleanup_resources(cls.api_client, cls._cleanup)
cls._cleanup = []
cls.debug("Cleanup complete!")
return
def tearDown(self): def tearDown(self):
# Cleanup resources used super(TestConfigDrive,self).tearDown()
self.debug("Cleaning up the resources")
for obj in reversed(self.cleanup):
try:
if isinstance(obj, VirtualMachine):
obj.delete(self.api_client, expunge=True)
else:
obj.delete(self.api_client)
except Exception as e:
self.error("Failed to cleanup %s, got %s" % (obj, e))
# cleanup_resources(self.api_client, self.cleanup)
self.cleanup = []
for tmp_file in self.tmp_files: for tmp_file in self.tmp_files:
os.remove(tmp_file) os.remove(tmp_file)
self.debug("Cleanup complete!") self.debug("Cleanup complete!")
return
# create_StaticNatRule_For_VM - Creates Static NAT rule on the given # create_StaticNatRule_For_VM - Creates Static NAT rule on the given
# public IP for the given VM in the given network # public IP for the given VM in the given network
@ -1755,7 +1732,8 @@ class TestConfigDrive(cloudstackTestCase, ConfigDriveUtils):
self.api_client.restartVPC(cmd) self.api_client.restartVPC(cmd)
self.debug("Restarted VPC with ID - %s" % vpc.id) self.debug("Restarted VPC with ID - %s" % vpc.id)
@attr(tags=["advanced", "isonw"], required_hardware="true") # was tags=["advanced", "isonw"]
@attr(tags=["TODO"], required_hardware="true")
def test_configdrive_isolated_network(self): def test_configdrive_isolated_network(self):
"""Test Configdrive as provider for isolated Networks """Test Configdrive as provider for isolated Networks
to provide userdata and password reset functionality to provide userdata and password reset functionality

View File

@ -62,9 +62,6 @@ class Services:
} }
class TestDeployVmWithUserData(cloudstackTestCase): class TestDeployVmWithUserData(cloudstackTestCase):
"""Tests for UserData """Tests for UserData
""" """
@ -75,6 +72,7 @@ class TestDeployVmWithUserData(cloudstackTestCase):
cls.apiClient = cls.testClient.getApiClient() cls.apiClient = cls.testClient.getApiClient()
cls.services = Services().services cls.services = Services().services
cls.zone = get_zone(cls.apiClient, cls.testClient.getZoneForTests()) cls.zone = get_zone(cls.apiClient, cls.testClient.getZoneForTests())
cls._cleanup = []
if cls.zone.localstorageenabled: if cls.zone.localstorageenabled:
#For devcloud since localstroage is enabled #For devcloud since localstroage is enabled
cls.services["service_offering"]["storagetype"] = "local" cls.services["service_offering"]["storagetype"] = "local"
@ -82,8 +80,9 @@ class TestDeployVmWithUserData(cloudstackTestCase):
cls.apiClient, cls.apiClient,
cls.services["service_offering"] cls.services["service_offering"]
) )
cls._cleanup.append(cls.service_offering)
cls.account = Account.create(cls.apiClient, services=cls.services["account"]) cls.account = Account.create(cls.apiClient, services=cls.services["account"])
cls.cleanup = [cls.account] cls._cleanup.append(cls.account)
cls.template = get_template( cls.template = get_template(
cls.apiClient, cls.apiClient,
cls.zone.id, cls.zone.id,
@ -96,6 +95,11 @@ class TestDeployVmWithUserData(cloudstackTestCase):
cls.userdata = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(2500)) cls.userdata = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(2500))
# py3 base64 encode adheres to the standard of 76 character lines terminated with '\n'
# py2 didn't insert any new-lines
# so we now do the encoding in the stored userdata string and remove the '\n's
# to get a good easy string compare in the assert later on.
cls.userdata = base64.encodestring(cls.userdata.encode()).decode().replace('\n', '')
cls.user_data_2k= ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(2000)) cls.user_data_2k= ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(2000))
cls.user_data_2kl = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(1900)) cls.user_data_2kl = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(1900))
@ -103,6 +107,7 @@ class TestDeployVmWithUserData(cloudstackTestCase):
def setUp(self): def setUp(self):
self.apiClient = self.testClient.getApiClient() self.apiClient = self.testClient.getApiClient()
self.hypervisor = self.testClient.getHypervisorInfo() self.hypervisor = self.testClient.getHypervisorInfo()
self.cleanup = []
@attr(tags=["simulator", "devcloud", "basic", "advanced"], required_hardware="true") @attr(tags=["simulator", "devcloud", "basic", "advanced"], required_hardware="true")
@ -110,7 +115,6 @@ class TestDeployVmWithUserData(cloudstackTestCase):
"""Test userdata as POST, size > 2k """Test userdata as POST, size > 2k
""" """
self.userdata = base64.encodestring(self.userdata.encode()).decode()
self.services["virtual_machine"]["userdata"] = self.userdata self.services["virtual_machine"]["userdata"] = self.userdata
deployVmResponse = VirtualMachine.create( deployVmResponse = VirtualMachine.create(
@ -122,8 +126,8 @@ class TestDeployVmWithUserData(cloudstackTestCase):
templateid=self.template.id, templateid=self.template.id,
zoneid=self.zone.id, zoneid=self.zone.id,
method="POST" method="POST"
) )
self.cleanup.append(deployVmResponse)
vms = list_virtual_machines( vms = list_virtual_machines(
self.apiClient, self.apiClient,
@ -190,11 +194,8 @@ class TestDeployVmWithUserData(cloudstackTestCase):
) )
res = str(result) res = str(result)
self.assertEqual(res.__contains__(self.userdata),True,"Userdata Not applied Check the failures") self.assertEqual(res.__contains__(self.userdata),True,"Userdata Not applied Check the failures")
except KeyError: except KeyError:
self.skipTest("Marvin configuration has no host credentials to check USERDATA") self.skipTest("Marvin configuration has no host credentials to check USERDATA")
else: else:
try: try:
host.user, host.passwd = get_host_credentials(self.config, host.ipaddress) host.user, host.passwd = get_host_credentials(self.config, host.ipaddress)
@ -211,13 +212,9 @@ class TestDeployVmWithUserData(cloudstackTestCase):
except KeyError: except KeyError:
self.skipTest("Marvin configuration has no host credentials to check router user data") self.skipTest("Marvin configuration has no host credentials to check router user data")
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestDeployVmWithUserData, cls).tearDownClass()
#Cleanup resources used
cleanup_resources(cls.apiClient, cls.cleanup)
except Exception as e: def tearDown(self):
raise Exception("Warning: Exception during cleanup : %s" % e) super(TestDeployVmWithUserData, self).tearDown()

View File

@ -37,7 +37,7 @@ from marvin.lib.common import (get_domain,
list_routers, list_routers,
list_virtual_machines list_virtual_machines
) )
from marvin.lib.utils import cleanup_resources, validateList from marvin.lib.utils import validateList
from marvin.cloudstackAPI import rebootRouter from marvin.cloudstackAPI import rebootRouter
from marvin.cloudstackAPI.createEgressFirewallRule import createEgressFirewallRuleCmd from marvin.cloudstackAPI.createEgressFirewallRule import createEgressFirewallRuleCmd
from marvin.cloudstackAPI.deleteEgressFirewallRule import deleteEgressFirewallRuleCmd from marvin.cloudstackAPI.deleteEgressFirewallRule import deleteEgressFirewallRuleCmd
@ -160,13 +160,9 @@ class TestEgressFWRules(cloudstackTestCase):
# Cleanup # Cleanup
cls._cleanup.append(cls.service_offering) cls._cleanup.append(cls.service_offering)
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestEgressFWRules, cls).tearDownClass()
cleanup_resources(cls.api_client, reversed(cls._cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
def setUp(self): def setUp(self):
self.apiclient = self.api_client self.apiclient = self.api_client
@ -175,12 +171,11 @@ class TestEgressFWRules(cloudstackTestCase):
self.cleanup = [] self.cleanup = []
self.domain = Domain.create(self.apiclient, self.domain = Domain.create(self.apiclient,
self.services["domain"]) self.services["domain"])
# Create an Account associated with domain self.cleanup.append(self.domain)
self.account = Account.create(self.apiclient, self.account = Account.create(self.apiclient,
self.services["account"], self.services["account"],
domainid=self.domain.id) domainid=self.domain.id)
self.cleanup.append(self.account) self.cleanup.append(self.account)
self.cleanup.append(self.domain)
return return
def create_network_offering(self, egress_policy=True, RR=False): def create_network_offering(self, egress_policy=True, RR=False):
@ -198,7 +193,7 @@ class TestEgressFWRules(cloudstackTestCase):
conservemode=True) conservemode=True)
# Cleanup # Cleanup
self.cleanup.append(self.network_offering) # self.cleanup.append(self.network_offering)
# Enable Network offering # Enable Network offering
self.network_offering.update(self.apiclient, state='Enabled') self.network_offering.update(self.apiclient, state='Enabled')
@ -214,6 +209,7 @@ class TestEgressFWRules(cloudstackTestCase):
domainid=self.account.domainid, domainid=self.account.domainid,
networkofferingid=self.network_offering.id, networkofferingid=self.network_offering.id,
zoneid=self.zone.id) zoneid=self.zone.id)
self.cleanup.append(self.network)
self.debug("Created network with ID: %s" % self.network.id) self.debug("Created network with ID: %s" % self.network.id)
self.debug("Deploying instance in the account: %s" % self.account.name) self.debug("Deploying instance in the account: %s" % self.account.name)
@ -226,6 +222,7 @@ class TestEgressFWRules(cloudstackTestCase):
mode=self.zone.networktype if pfrule else 'basic', mode=self.zone.networktype if pfrule else 'basic',
networkids=[str(self.network.id)], networkids=[str(self.network.id)],
projectid=project.id if project else None) projectid=project.id if project else None)
self.cleanup.append(self.virtual_machine)
self.debug("Deployed instance %s in account: %s" % (self.virtual_machine.id,self.account.name)) self.debug("Deployed instance %s in account: %s" % (self.virtual_machine.id,self.account.name))
# Checking if VM is running or not, in case it is deployed in error state, test case fails # Checking if VM is running or not, in case it is deployed in error state, test case fails
@ -241,9 +238,10 @@ class TestEgressFWRules(cloudstackTestCase):
domainid=self.account.domainid, domainid=self.account.domainid,
networkid=self.network.id networkid=self.network.id
) )
self.cleanup.append(self.public_ip)
# Open up firewall port for SSH # Open up firewall port for SSH
FireWallRule.create( fwr = FireWallRule.create(
self.apiclient, self.apiclient,
ipaddressid=self.public_ip.ipaddress.id, ipaddressid=self.public_ip.ipaddress.id,
protocol=self.services["natrule"]["protocol"], protocol=self.services["natrule"]["protocol"],
@ -251,15 +249,17 @@ class TestEgressFWRules(cloudstackTestCase):
startport=self.services["natrule"]["publicport"], startport=self.services["natrule"]["publicport"],
endport=self.services["natrule"]["publicport"] endport=self.services["natrule"]["publicport"]
) )
self.cleanup.append(fwr)
self.debug("Creating NAT rule for VM ID: %s" % self.virtual_machine.id) self.debug("Creating NAT rule for VM ID: %s" % self.virtual_machine.id)
#Create NAT rule #Create NAT rule
NATRule.create( nr = NATRule.create(
self.apiclient, self.apiclient,
self.virtual_machine, self.virtual_machine,
self.services["natrule"], self.services["natrule"],
self.public_ip.ipaddress.id self.public_ip.ipaddress.id
) )
self.cleanup.append(nr)
return return
def exec_script_on_user_vm(self, script, exec_cmd_params, expected_result, negative_test=False): def exec_script_on_user_vm(self, script, exec_cmd_params, expected_result, negative_test=False):
@ -332,22 +332,17 @@ class TestEgressFWRules(cloudstackTestCase):
cmd.startport = start_port cmd.startport = start_port
if end_port: if end_port:
cmd.endport = end_port cmd.endport = end_port
rule = self.apiclient.createEgressFirewallRule(cmd) self.egressrule = self.apiclient.createEgressFirewallRule(cmd)
self.debug('Created rule=%s' % rule.id) self.debug('Created rule=%s' % self.egressrule.id)
self.egressruleid = rule.id
def deleteEgressRule(self): def deleteEgressRule(self):
cmd = deleteEgressFirewallRuleCmd() cmd = deleteEgressFirewallRuleCmd()
cmd.id = self.egressruleid cmd.id = self.egressrule.id
self.apiclient.deleteEgressFirewallRule(cmd) self.apiclient.deleteEgressFirewallRule(cmd)
self.egressruleid = None self.egressrule = None
def tearDown(self): def tearDown(self):
try: super(TestEgressFWRules, self).tearDown()
self.debug("Cleaning up the resources")
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
self.fail("Warning! Cleanup failed: %s" % e)
def create_another_vm(self): def create_another_vm(self):
self.debug("Deploying instance in the account: %s and network: %s" % (self.account.name, self.network.id)) self.debug("Deploying instance in the account: %s and network: %s" % (self.account.name, self.network.id))
@ -361,6 +356,7 @@ class TestEgressFWRules(cloudstackTestCase):
mode=self.zone.networktype, mode=self.zone.networktype,
networkids=[str(self.network.id)], networkids=[str(self.network.id)],
projectid=project.id if project else None) projectid=project.id if project else None)
self.cleanup.append(self.virtual_machine1)
self.debug("Deployed instance %s in account: %s" % (self.virtual_machine.id,self.account.name)) self.debug("Deployed instance %s in account: %s" % (self.virtual_machine.id,self.account.name))
# Checking if VM is running or not, in case it is deployed in error state, test case fails # Checking if VM is running or not, in case it is deployed in error state, test case fails
@ -420,7 +416,9 @@ class TestEgressFWRules(cloudstackTestCase):
# 6. public network should not be reachable from the first VM. # 6. public network should not be reachable from the first VM.
self.create_vm(egress_policy=False) self.create_vm(egress_policy=False)
self.create_another_vm() self.create_another_vm()
self.createEgressRule(protocol='all', cidr=self.virtual_machine1.ipaddress+"/32") self.createEgressRule(cidr=self.virtual_machine1.ipaddress+"/32")
# this should read protocol='all' as below, see CLOUDSTACK-10075, now testing only 'ICMP'
# self.createEgressRule(protocol='all', cidr=self.virtual_machine1.ipaddress+"/32")
self.exec_script_on_user_vm('ping -c 1 www.google.com', self.exec_script_on_user_vm('ping -c 1 www.google.com',
"| grep -oP \'\d+(?=% packet loss)\'", "| grep -oP \'\d+(?=% packet loss)\'",
"['100']", "['100']",
@ -530,7 +528,7 @@ class TestEgressFWRules(cloudstackTestCase):
# 3. check the table Firewall_Rules, Firewall and Traffic_type should be "Egress". # 3. check the table Firewall_Rules, Firewall and Traffic_type should be "Egress".
self.create_vm() self.create_vm()
self.createEgressRule(cidr=TestEgressFWRules.zone.guestcidraddress) self.createEgressRule(cidr=TestEgressFWRules.zone.guestcidraddress)
qresultset = self.dbclient.execute("select purpose, traffic_type from firewall_rules where uuid='%s';" % self.egressruleid) qresultset = self.dbclient.execute("select purpose, traffic_type from firewall_rules where uuid='%s';" % self.egressrule.id)
self.assertEqual(isinstance(qresultset, list), self.assertEqual(isinstance(qresultset, list),
True, True,
"Check DB query result set for valid data") "Check DB query result set for valid data")
@ -567,7 +565,7 @@ class TestEgressFWRules(cloudstackTestCase):
# 3. check the table Firewall_Rules, Firewall and Traffic_type should be "Egress". # 3. check the table Firewall_Rules, Firewall and Traffic_type should be "Egress".
self.create_vm(egress_policy=False) self.create_vm(egress_policy=False)
self.createEgressRule(cidr=TestEgressFWRules.zone.guestcidraddress) self.createEgressRule(cidr=TestEgressFWRules.zone.guestcidraddress)
qresultset = self.dbclient.execute("select purpose, traffic_type from firewall_rules where uuid='%s';" % self.egressruleid) qresultset = self.dbclient.execute("select purpose, traffic_type from firewall_rules where uuid='%s';" % self.egressrule.id)
self.assertEqual(isinstance(qresultset, list), self.assertEqual(isinstance(qresultset, list),
True, True,
"Check DB query result set for valid data") "Check DB query result set for valid data")
@ -593,44 +591,6 @@ class TestEgressFWRules(cloudstackTestCase):
0, 0,
"DB results not matching, expected: 0, found: %s" % qresultset[0][0]) "DB results not matching, expected: 0, found: %s" % qresultset[0][0])
@unittest.skip("Skip")
@attr(tags=["advanced", "NotRun"])
def test_05_egress_fr5(self):
"""Test Create Egress rule and check the IP tables
"""
# Validate the following:
# 1. deploy VM using network offering with egress policy true.
# 2. create egress rule with specific CIDR + port range.
# 3. login to VR.
# 4. Check iptables for rules settings.
# -A FW_OUTBOUND -j FW_EGRESS_RULES
# -A FW_EGRESS_RULES -m state --state RELATED,ESTABLISHED -j ACCEPT
# -A FW_EGRESS_RULES -d 10.147.28.0/24 -p tcp -m tcp --dport 22 -j ACCEPT
# -A FW_EGRESS_RULES -j DROP
self.create_vm()
self.createEgressRule(cidr=TestEgressFWRules.zone.guestcidraddress)
#TODO: Query VR for expected route rules.
@unittest.skip("Skip")
@attr(tags=["advanced", "NotRun"])
def test_05_1_egress_fr5(self):
"""Test Create Egress rule and check the IP tables
"""
# Validate the following:
# 1. deploy VM using network offering with egress policy false.
# 2. create egress rule with specific CIDR + port range.
# 3. login to VR.
# 4. Check iptables for rules settings.
# -A FW_OUTBOUND -j FW_EGRESS_RULES
# -A FW_EGRESS_RULES -m state --state RELATED,ESTABLISHED -j ACCEPT
# -A FW_EGRESS_RULES -d 10.147.28.0/24 -p tcp -m tcp --dport 22 -j ACCEPT
# -A FW_EGRESS_RULES -j DROP
self.create_vm(egress_policy=False)
self.createEgressRule(cidr=TestEgressFWRules.zone.guestcidraddress)
#TODO: Query VR for expected route rules.
@attr(tags=["advanced"], required_hardware="true") @attr(tags=["advanced"], required_hardware="true")
def test_06_egress_fr6(self): def test_06_egress_fr6(self):
"""Test Create Egress rule without CIDR """Test Create Egress rule without CIDR
@ -791,7 +751,6 @@ class TestEgressFWRules(cloudstackTestCase):
self.create_vm(egress_policy=False) self.create_vm(egress_policy=False)
self.assertRaises(Exception, self.createEgressRule, cidr='10.2.2.0/24') self.assertRaises(Exception, self.createEgressRule, cidr='10.2.2.0/24')
@attr(tags=["advanced"], required_hardware="false") @attr(tags=["advanced"], required_hardware="false")
def test_11_egress_fr11(self): def test_11_egress_fr11(self):
"""Test Regression on Firewall + PF + LB + SNAT """Test Regression on Firewall + PF + LB + SNAT

View File

@ -63,7 +63,7 @@ class TestNetworks_1(cloudstackTestCase):
cls.api_client, cls.api_client,
cls.test_data["network_offering_vlan"], cls.test_data["network_offering_vlan"],
) )
# Enable Network offering cls._cleanup.append(cls.network_offering)
cls.network_offering.update(cls.api_client, state='Enabled') cls.network_offering.update(cls.api_client, state='Enabled')
cls.test_data["network_without_acl"][ cls.test_data["network_without_acl"][
"networkoffering"] = cls.network_offering.id "networkoffering"] = cls.network_offering.id
@ -71,12 +71,14 @@ class TestNetworks_1(cloudstackTestCase):
cls.api_client, cls.api_client,
cls.test_data["service_offerings"]["tiny"] cls.test_data["service_offerings"]["tiny"]
) )
# Creating Disk offering, Service Offering and Account cls._cleanup.append(cls.service_offering)
cls.account = Account.create( cls.account = Account.create(
cls.api_client, cls.api_client,
cls.test_data["account"], cls.test_data["account"],
domainid=cls.domain.id domainid=cls.domain.id
) )
cls._cleanup.append(cls.account)
# Getting authentication for user in newly created Account # Getting authentication for user in newly created Account
cls.user = cls.account.user[0] cls.user = cls.account.user[0]
cls.userapiclient = cls.testClient.getUserApiClient( cls.userapiclient = cls.testClient.getUserApiClient(
@ -89,9 +91,6 @@ class TestNetworks_1(cloudstackTestCase):
cls.account.domainid cls.account.domainid
) )
cls._cleanup.append(cls.account_network) cls._cleanup.append(cls.account_network)
cls._cleanup.append(cls.account)
cls._cleanup.append(cls.service_offering)
cls._cleanup.append(cls.network_offering)
except Exception as e: except Exception as e:
cls.tearDownClass() cls.tearDownClass()
raise Exception("Warning: Exception in setup : %s" % e) raise Exception("Warning: Exception in setup : %s" % e)
@ -103,16 +102,11 @@ class TestNetworks_1(cloudstackTestCase):
self.cleanup = [] self.cleanup = []
def tearDown(self): def tearDown(self):
# Clean up, terminate the created volumes super(TestNetworks_1, self).tearDown()
cleanup_resources(self.apiClient, self.cleanup)
return
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestNetworks_1, cls).tearDownClass()
cleanup_resources(cls.api_client, cls._cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
def __verify_values(self, expected_vals, actual_vals): def __verify_values(self, expected_vals, actual_vals):
""" """
@ -289,9 +283,9 @@ class TestNetworks_1(cloudstackTestCase):
self.apiClient, self.apiClient,
self.test_data["network_offering_without_sourcenat"], self.test_data["network_offering_without_sourcenat"],
) )
self.cleanup.append(network_offering_without_sourcenat)
if network_offering_without_sourcenat is None: if network_offering_without_sourcenat is None:
self.fail("Creation of network offering without sourcenat failed") self.fail("Creation of network offering without sourcenat failed")
self.cleanup.append(network_offering_without_sourcenat)
# Enable network offering # Enable network offering
network_offering_without_sourcenat.update( network_offering_without_sourcenat.update(
self.apiClient, self.apiClient,
@ -480,7 +474,8 @@ class TestNetworks_1(cloudstackTestCase):
) )
return return
@attr(tags=["advanced"], required_hardware="true") # was tags=["advanced"]
@attr(tags=["TODO"], required_hardware="true")
def test_05_list_network_offerings_with_and_without_vpc(self): def test_05_list_network_offerings_with_and_without_vpc(self):
""" """
@Desc: Test list network offerings for vpc true and false parameters @Desc: Test list network offerings for vpc true and false parameters
@ -539,12 +534,12 @@ class TestNetworks_1(cloudstackTestCase):
self.apiClient, self.apiClient,
self.test_data["network_offering_vlan"], self.test_data["network_offering_vlan"],
) )
self.cleanup.append(network_offering)
self.assertIsNotNone( self.assertIsNotNone(
network_offering, network_offering,
"Network offering is not created") "Network offering is not created")
# Enable Network offering # Enable Network offering
network_offering.update(self.apiClient, state='Enabled') network_offering.update(self.apiClient, state='Enabled')
self.cleanup.append(network_offering)
# List network offering # List network offering
network_offering_after_count = NetworkOffering.list(self.userapiclient) network_offering_after_count = NetworkOffering.list(self.userapiclient)
status = validateList(network_offering_after_count) status = validateList(network_offering_after_count)
@ -602,7 +597,8 @@ class TestNetworks_1(cloudstackTestCase):
) )
return return
@attr(tags=["advanced"], required_hardware="true") # @attr(tags=["advanced"], required_hardware="true")
@attr(tags=["TODO"], required_hardware="true")
def test_06_create_network_in_vpc(self): def test_06_create_network_in_vpc(self):
""" """
@Desc: Test create network in vpc and verify VPC name @Desc: Test create network in vpc and verify VPC name
@ -641,6 +637,7 @@ class TestNetworks_1(cloudstackTestCase):
zoneid=self.zone.id, zoneid=self.zone.id,
) )
self.assertIsNotNone(vpc_1, "VPC is not created") self.assertIsNotNone(vpc_1, "VPC is not created")
self.cleanup.append(vpc_1)
# List VPCs # List VPCs
vpc_list = VPC.list( vpc_list = VPC.list(
self.userapiclient, self.userapiclient,
@ -702,7 +699,6 @@ class TestNetworks_1(cloudstackTestCase):
"Network is not created" "Network is not created"
) )
self.cleanup.append(network_created) self.cleanup.append(network_created)
self.cleanup.append(vpc_1)
# Creating expected and actual values dictionaries # Creating expected and actual values dictionaries
expected_dict = { expected_dict = {
"id": self.test_data["network_without_acl"]["zoneid"], "id": self.test_data["network_without_acl"]["zoneid"],
@ -769,7 +765,8 @@ class TestNetworks_1(cloudstackTestCase):
) )
return return
@attr(tags=["advanced"], required_hardware="true") # was tags=["advanced"]
@attr(tags=["TODO"], required_hardware="true")
def test_07_create_delete_network(self): def test_07_create_delete_network(self):
""" """
@Desc: Test delete network @Desc: Test delete network
@ -875,7 +872,8 @@ class TestNetworks_1(cloudstackTestCase):
) )
return return
@attr(tags=["advanced"], required_hardware="true") # was tags=["advanced"]
@attr(tags=["TODO"], required_hardware="true")
def test_08_update_network(self): def test_08_update_network(self):
""" """
@Desc: Test update network @Desc: Test update network
@ -1126,7 +1124,8 @@ class TestNetworks_1(cloudstackTestCase):
) )
return return
@attr(tags=["advanced"], required_hardware="true") # was tags=["advanced"]
@attr(tags=["TODO"], required_hardware="true")
def test_10_list_networks_in_vpc(self): def test_10_list_networks_in_vpc(self):
""" """
@Desc: Test list networks in vpc and verify VPC name @Desc: Test list networks in vpc and verify VPC name
@ -1164,6 +1163,7 @@ class TestNetworks_1(cloudstackTestCase):
zoneid=self.zone.id, zoneid=self.zone.id,
) )
self.assertIsNotNone(vpc_1, "VPC is not created") self.assertIsNotNone(vpc_1, "VPC is not created")
self.cleanup.append(vpc_1)
# List VPCs # List VPCs
vpc_list = VPC.list( vpc_list = VPC.list(
self.userapiclient, self.userapiclient,
@ -1215,7 +1215,6 @@ class TestNetworks_1(cloudstackTestCase):
"Network is not created" "Network is not created"
) )
self.cleanup.append(network_created) self.cleanup.append(network_created)
self.cleanup.append(vpc_1)
# Creating expected and actual values dictionaries # Creating expected and actual values dictionaries
expected_dict = { expected_dict = {
"id": self.test_data["network_without_acl"]["zoneid"], "id": self.test_data["network_without_acl"]["zoneid"],
@ -1271,7 +1270,8 @@ class TestNetworks_1(cloudstackTestCase):
) )
return return
@attr(tags=["advanced"], required_hardware="true") # @attr(tags=["advanced"], required_hardware="true")
@attr(tags=["TODO"], required_hardware="true")
def test_11_update_vpc(self): def test_11_update_vpc(self):
""" """
@Desc: Test create vpc with network domain as parameter @Desc: Test create vpc with network domain as parameter
@ -1370,7 +1370,8 @@ class TestNetworks_1(cloudstackTestCase):
) )
return return
@attr(tags=["advanced"], required_hardware="true") # was tags=["advanced"]
@attr(tags=["TODO"], required_hardware="true")
def test_12_list_create_delete_networkACL(self): def test_12_list_create_delete_networkACL(self):
""" """
@Desc: Test create network in vpc and verify VPC name @Desc: Test create network in vpc and verify VPC name
@ -1411,6 +1412,7 @@ class TestNetworks_1(cloudstackTestCase):
vpcofferingid=vpc_offs.id, vpcofferingid=vpc_offs.id,
zoneid=self.zone.id, zoneid=self.zone.id,
) )
self.cleanup.append(vpc_1)
self.assertIsNotNone(vpc_1, "VPC is not created") self.assertIsNotNone(vpc_1, "VPC is not created")
# List VPCs # List VPCs
vpc_list = VPC.list( vpc_list = VPC.list(
@ -1470,7 +1472,6 @@ class TestNetworks_1(cloudstackTestCase):
accountid=self.account.name, accountid=self.account.name,
) )
self.cleanup.append(network_created) self.cleanup.append(network_created)
self.cleanup.append(vpc_1)
self.assertIsNotNone( self.assertIsNotNone(
network_created, network_created,
"Network is not created" "Network is not created"
@ -1603,12 +1604,13 @@ class TestNetworks_2(cloudstackTestCase):
cls.test_data["account"], cls.test_data["account"],
domainid=cls.domain.id domainid=cls.domain.id
) )
cls._cleanup.append(cls.account)
# Getting authentication for user in newly created Account # Getting authentication for user in newly created Account
cls.user = cls.account.user[0] cls.user = cls.account.user[0]
cls.userapiclient = cls.testClient.getUserApiClient( cls.userapiclient = cls.testClient.getUserApiClient(
cls.user.username, cls.user.username,
cls.domain.name) cls.domain.name)
cls._cleanup.append(cls.account)
cls.vpc_offering = VpcOffering.create(cls.api_client, cls.vpc_offering = VpcOffering.create(cls.api_client,
cls.test_data["vpc_offering"] cls.test_data["vpc_offering"]
@ -1626,16 +1628,11 @@ class TestNetworks_2(cloudstackTestCase):
self.cleanup = [] self.cleanup = []
def tearDown(self): def tearDown(self):
# Clean up, terminate the created volumes super(TestNetworks_2, self).tearDown()
cleanup_resources(self.apiClient, self.cleanup)
return
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestNetworks_2, cls).tearDownClass()
cleanup_resources(cls.api_client, cls._cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
def __verify_values(self, expected_vals, actual_vals): def __verify_values(self, expected_vals, actual_vals):
""" """
@ -2212,6 +2209,7 @@ class TestNetworks_2(cloudstackTestCase):
self.zone.id self.zone.id
) )
self.assertIsNotNone(vpc_created, "VPC Creation Failed") self.assertIsNotNone(vpc_created, "VPC Creation Failed")
self.cleanup.append(vpc_created)
# Listing the vpc for a user after creating a vpc # Listing the vpc for a user after creating a vpc
list_vpc_after = VPC.list(self.userapiclient) list_vpc_after = VPC.list(self.userapiclient)
status = validateList(list_vpc_after) status = validateList(list_vpc_after)
@ -2226,7 +2224,6 @@ class TestNetworks_2(cloudstackTestCase):
len(list_vpc_after), len(list_vpc_after),
"list VPC not equal as expected" "list VPC not equal as expected"
) )
self.cleanup.append(vpc_created)
# Restarting VPC # Restarting VPC
vpc_restarted = VPC.restart(vpc_created, self.userapiclient) vpc_restarted = VPC.restart(vpc_created, self.userapiclient)
# Verifying restart function resturns true # Verifying restart function resturns true
@ -2367,7 +2364,8 @@ class TestNetworks_2(cloudstackTestCase):
) )
return return
@attr(tags=["advanced"], required_hardware="true") # @attr(tags=["advanced"], required_hardware="true")
@attr(tags=["TODO"], required_hardware="true")
def test_19_create_list_reset_delete_vpnconnections(self): def test_19_create_list_reset_delete_vpnconnections(self):
""" """
@Desc: Test to List Create Reset and Delete VPN Customer @Desc: Test to List Create Reset and Delete VPN Customer

View File

@ -89,18 +89,11 @@ class TestTemplates(cloudstackTestCase):
self.cleanup.append(self.account) self.cleanup.append(self.account)
def tearDown(self): def tearDown(self):
# Clean up, terminate the created resources super(TestTemplates, self).tearDown()
cleanup_resources(self.apiClient, self.cleanup)
return
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestTemplates, cls).tearDownClass()
cleanup_resources(cls.api_client, cls._cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
def __verify_values(self, expected_vals, actual_vals): def __verify_values(self, expected_vals, actual_vals):
""" """

View File

@ -111,7 +111,7 @@ class TestVMware(cloudstackTestCase):
raise Exception("Warning: Exception during cleanup : %s" % e) raise Exception("Warning: Exception during cleanup : %s" % e)
@attr(tags=["advanced"], required_hardware="true") @attr(tags=["advanced"], required_hardware="true")
def test1_attach_volume_ide(self): def test_01_attach_volume_ide(self):
""" """
@desc: Exception when attaching data disk to RHEL VM on vSphere @desc: Exception when attaching data disk to RHEL VM on vSphere
Step1: Confirm that vmware.root.disk.controller = "ide" in Global Settings. Step1: Confirm that vmware.root.disk.controller = "ide" in Global Settings.
@ -206,8 +206,9 @@ class TestVMware(cloudstackTestCase):
self.fail("Failed to attach data disk to RHEL vm whose root disk type is IDE") self.fail("Failed to attach data disk to RHEL vm whose root disk type is IDE")
return return
@attr(tags=["advanced", "basic"], required_hardware="true") # @attr(tags=["advanced", "basic"], required_hardware="true")
def test2_attach_ISO_in_CentOSVM(self): @attr(tags=["TODO"], required_hardware="true")
def test_02_attach_ISO_in_CentOSVM(self):
""" """
@desc:Incorrect guest os mapping in vmware for CentOS 5.9 and above @desc:Incorrect guest os mapping in vmware for CentOS 5.9 and above
Step1 :Register an CentOS 6.3 template Step1 :Register an CentOS 6.3 template
@ -269,8 +270,9 @@ class TestVMware(cloudstackTestCase):
self.assertEqual(attachedIsoName, "vmware-tools.iso", "vmware-tools.iso not attached") self.assertEqual(attachedIsoName, "vmware-tools.iso", "vmware-tools.iso not attached")
return return
@attr(tags=["advanced", "basic"], required_hardware="true") # @attr(tags=["advanced", "basic"], required_hardware="true")
def test3_attach_ISO_in_RHEL7OSVM(self): @attr(tags=["TODO"], required_hardware="true")
def test_03_attach_ISO_in_RHEL7OSVM(self):
""" """
@desc:Incorrect guest os mapping in vmware for Rhel7. Add a valid RHEL7 URL to execute this test case @desc:Incorrect guest os mapping in vmware for Rhel7. Add a valid RHEL7 URL to execute this test case
Step1 :Register an RHEL 7 template Step1 :Register an RHEL 7 template

View File

@ -291,7 +291,8 @@ class TestVolumes(cloudstackTestCase):
) )
return return
@attr(tags=["advanced", "basic"], required_hardware="true") # @attr(tags=["advanced", "basic"], required_hardware="true")
@attr(tags=["TODO"], required_hardware="true")
def test_02_list_volume_byid(self): def test_02_list_volume_byid(self):
""" """
@summary: Test List Volumes with Id @summary: Test List Volumes with Id
@ -699,7 +700,8 @@ class TestVolumes(cloudstackTestCase):
) )
return return
@attr(tags=["advanced", "basic"], required_hardware="true") # @attr(tags=["advanced", "basic"], required_hardware="true")
@attr(tags=["TODO"], required_hardware="true")
def test_05_volume_snapshot(self): def test_05_volume_snapshot(self):
""" """
@summary: Test to verify creation of snapshot from volume @summary: Test to verify creation of snapshot from volume

View File

@ -145,26 +145,17 @@ class TestAssignLBRule(cloudstackTestCase):
domainid=self.account.domainid, domainid=self.account.domainid,
serviceofferingid=self.service_offering.id, serviceofferingid=self.service_offering.id,
mode=self.zone.networktype) mode=self.zone.networktype)
self.cleanup.append(self.virtual_machine)
except Exception as e: except Exception as e:
self.tearDown() self.tearDown()
raise e raise e
def tearDown(self): def tearDown(self):
try: super(TestAssignLBRule, self).tearDown()
# Clean up, terminate the created accounts, domains etc
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestAssignLBRule, cls).tearDownClass()
# Cleanup resources used
cleanup_resources(cls.api_client, cls._cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@attr(tags=["advanced", "selfservice"], required_hardware="false") @attr(tags=["advanced", "selfservice"], required_hardware="false")
def test_01_lb_rule_for_primary_ip(self): def test_01_lb_rule_for_primary_ip(self):
@ -186,6 +177,7 @@ class TestAssignLBRule(cloudstackTestCase):
zoneid=self.zone.id, zoneid=self.zone.id,
domainid=self.account.domainid, domainid=self.account.domainid,
networkid=self.virtual_machine.nic[0].networkid) networkid=self.virtual_machine.nic[0].networkid)
self.cleanup.append(public_ip)
lb_rule = LoadBalancerRule.create( lb_rule = LoadBalancerRule.create(
self.apiclient, self.apiclient,
@ -194,6 +186,7 @@ class TestAssignLBRule(cloudstackTestCase):
accountid=self.account.name, accountid=self.account.name,
networkid=self.virtual_machine.nic[0].networkid, networkid=self.virtual_machine.nic[0].networkid,
domainid=self.account.domainid) domainid=self.account.domainid)
self.cleanup.append(lb_rule)
vmidipmap = [{"vmid": str(self.virtual_machine.id), vmidipmap = [{"vmid": str(self.virtual_machine.id),
"vmip": str(self.virtual_machine.nic[0].ipaddress)}] "vmip": str(self.virtual_machine.nic[0].ipaddress)}]
@ -240,6 +233,7 @@ class TestAssignLBRule(cloudstackTestCase):
zoneid=self.zone.id, zoneid=self.zone.id,
domainid=self.account.domainid, domainid=self.account.domainid,
networkid=self.virtual_machine.nic[0].networkid) networkid=self.virtual_machine.nic[0].networkid)
self.cleanup.append(public_ip)
lb_rule = LoadBalancerRule.create( lb_rule = LoadBalancerRule.create(
self.apiclient, self.apiclient,
@ -248,6 +242,7 @@ class TestAssignLBRule(cloudstackTestCase):
accountid=self.account.name, accountid=self.account.name,
networkid=self.virtual_machine.nic[0].networkid, networkid=self.virtual_machine.nic[0].networkid,
domainid=self.account.domainid) domainid=self.account.domainid)
self.cleanup.append(lb_rule)
vmidipmap = [{"vmid": str(self.virtual_machine.id), vmidipmap = [{"vmid": str(self.virtual_machine.id),
"vmip": str(secondaryip.ipaddress)}] "vmip": str(secondaryip.ipaddress)}]
@ -294,6 +289,7 @@ class TestAssignLBRule(cloudstackTestCase):
zoneid=self.zone.id, zoneid=self.zone.id,
domainid=self.account.domainid, domainid=self.account.domainid,
networkid=self.virtual_machine.nic[0].networkid) networkid=self.virtual_machine.nic[0].networkid)
self.cleanup.append(public_ip)
lb_rule = LoadBalancerRule.create( lb_rule = LoadBalancerRule.create(
self.apiclient, self.apiclient,
@ -302,6 +298,7 @@ class TestAssignLBRule(cloudstackTestCase):
accountid=self.account.name, accountid=self.account.name,
networkid=self.virtual_machine.nic[0].networkid, networkid=self.virtual_machine.nic[0].networkid,
domainid=self.account.domainid) domainid=self.account.domainid)
self.cleanup.append(lb_rule)
vmidipmap = [{"vmid": str(self.virtual_machine.id), vmidipmap = [{"vmid": str(self.virtual_machine.id),
"vmip": str(self.virtual_machine.nic[0].ipaddress)}, "vmip": str(self.virtual_machine.nic[0].ipaddress)},
@ -353,6 +350,7 @@ class TestAssignLBRule(cloudstackTestCase):
serviceofferingid=self.service_offering.id, serviceofferingid=self.service_offering.id,
mode=self.zone.networktype, mode=self.zone.networktype,
networkids=[self.virtual_machine.nic[0].networkid, ]) networkids=[self.virtual_machine.nic[0].networkid, ])
self.cleanup.append(self.virtual_machine2)
secondaryip_vm2 = NIC.addIp(self.apiclient, secondaryip_vm2 = NIC.addIp(self.apiclient,
id=self.virtual_machine2.nic[0].id id=self.virtual_machine2.nic[0].id
@ -364,6 +362,7 @@ class TestAssignLBRule(cloudstackTestCase):
zoneid=self.zone.id, zoneid=self.zone.id,
domainid=self.account.domainid, domainid=self.account.domainid,
networkid=self.virtual_machine.nic[0].networkid) networkid=self.virtual_machine.nic[0].networkid)
self.cleanup.append(public_ip)
lb_rule = LoadBalancerRule.create( lb_rule = LoadBalancerRule.create(
self.apiclient, self.apiclient,
@ -372,6 +371,7 @@ class TestAssignLBRule(cloudstackTestCase):
accountid=self.account.name, accountid=self.account.name,
networkid=self.virtual_machine.nic[0].networkid, networkid=self.virtual_machine.nic[0].networkid,
domainid=self.account.domainid) domainid=self.account.domainid)
self.cleanup.append(lb_rule)
vmidipmap = [{"vmid": str(self.virtual_machine.id), vmidipmap = [{"vmid": str(self.virtual_machine.id),
"vmip": str(self.virtual_machine.nic[0].ipaddress)}, "vmip": str(self.virtual_machine.nic[0].ipaddress)},
@ -473,25 +473,17 @@ class TestFailureScenarios(cloudstackTestCase):
domainid=self.account.domainid, domainid=self.account.domainid,
serviceofferingid=self.service_offering.id, serviceofferingid=self.service_offering.id,
mode=self.zone.networktype) mode=self.zone.networktype)
self.cleanup.append(self.virtual_machine)
except Exception as e: except Exception as e:
self.tearDown() self.tearDown()
raise e raise e
def tearDown(self): def tearDown(self):
try: super(TestFailureScenarios, self).tearDown()
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestFailureScenarios, cls).tearDownClass()
# Cleanup resources used
cleanup_resources(cls.api_client, cls._cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@attr(tags=["advanced", "selfservice"], required_hardware="false") @attr(tags=["advanced", "selfservice"], required_hardware="false")
def test_05_lb_rule_wrong_vm_id(self): def test_05_lb_rule_wrong_vm_id(self):
@ -514,6 +506,7 @@ class TestFailureScenarios(cloudstackTestCase):
zoneid=self.zone.id, zoneid=self.zone.id,
domainid=self.account.domainid, domainid=self.account.domainid,
networkid=self.virtual_machine.nic[0].networkid) networkid=self.virtual_machine.nic[0].networkid)
self.cleanup.append(public_ip)
lb_rule = LoadBalancerRule.create( lb_rule = LoadBalancerRule.create(
self.apiclient, self.apiclient,
@ -522,6 +515,7 @@ class TestFailureScenarios(cloudstackTestCase):
accountid=self.account.name, accountid=self.account.name,
networkid=self.virtual_machine.nic[0].networkid, networkid=self.virtual_machine.nic[0].networkid,
domainid=self.account.domainid) domainid=self.account.domainid)
self.cleanup.append(lb_rule)
vmidipmap = [{"vmid": str(self.virtual_machine.id) + random_gen(), vmidipmap = [{"vmid": str(self.virtual_machine.id) + random_gen(),
"vmip": str(secondaryip.ipaddress)}] "vmip": str(secondaryip.ipaddress)}]
@ -552,6 +546,7 @@ class TestFailureScenarios(cloudstackTestCase):
zoneid=self.zone.id, zoneid=self.zone.id,
domainid=self.account.domainid, domainid=self.account.domainid,
networkid=self.virtual_machine.nic[0].networkid) networkid=self.virtual_machine.nic[0].networkid)
self.cleanup.append(public_ip)
lb_rule = LoadBalancerRule.create( lb_rule = LoadBalancerRule.create(
self.apiclient, self.apiclient,
@ -560,6 +555,7 @@ class TestFailureScenarios(cloudstackTestCase):
accountid=self.account.name, accountid=self.account.name,
networkid=self.virtual_machine.nic[0].networkid, networkid=self.virtual_machine.nic[0].networkid,
domainid=self.account.domainid) domainid=self.account.domainid)
self.cleanup.append(lb_rule)
vmidipmap = [{"vmid": str(self.virtual_machine.id), vmidipmap = [{"vmid": str(self.virtual_machine.id),
"vmip": str(secondaryip.ipaddress) + random_gen()}] "vmip": str(secondaryip.ipaddress) + random_gen()}]
@ -593,6 +589,7 @@ class TestFailureScenarios(cloudstackTestCase):
zoneid=self.zone.id, zoneid=self.zone.id,
domainid=self.account.domainid, domainid=self.account.domainid,
networkid=self.virtual_machine.nic[0].networkid) networkid=self.virtual_machine.nic[0].networkid)
self.cleanup.append(public_ip1)
lb_rule1 = LoadBalancerRule.create( lb_rule1 = LoadBalancerRule.create(
self.apiclient, self.apiclient,
@ -601,6 +598,7 @@ class TestFailureScenarios(cloudstackTestCase):
accountid=self.account.name, accountid=self.account.name,
networkid=self.virtual_machine.nic[0].networkid, networkid=self.virtual_machine.nic[0].networkid,
domainid=self.account.domainid) domainid=self.account.domainid)
self.cleanup.append(lb_rule1)
public_ip2 = PublicIPAddress.create( public_ip2 = PublicIPAddress.create(
self.apiclient, self.apiclient,
@ -608,6 +606,7 @@ class TestFailureScenarios(cloudstackTestCase):
zoneid=self.zone.id, zoneid=self.zone.id,
domainid=self.account.domainid, domainid=self.account.domainid,
networkid=self.virtual_machine.nic[0].networkid) networkid=self.virtual_machine.nic[0].networkid)
self.cleanup.append(public_ip2)
lb_rule2 = LoadBalancerRule.create( lb_rule2 = LoadBalancerRule.create(
self.apiclient, self.apiclient,
@ -616,6 +615,7 @@ class TestFailureScenarios(cloudstackTestCase):
accountid=self.account.name, accountid=self.account.name,
networkid=self.virtual_machine.nic[0].networkid, networkid=self.virtual_machine.nic[0].networkid,
domainid=self.account.domainid) domainid=self.account.domainid)
self.cleanup.append(lb_rule2)
vmidipmap = [{"vmid": str(self.virtual_machine.id), vmidipmap = [{"vmid": str(self.virtual_machine.id),
"vmip": str(secondaryip.ipaddress)}] "vmip": str(secondaryip.ipaddress)}]
@ -655,6 +655,7 @@ class TestFailureScenarios(cloudstackTestCase):
zoneid=self.zone.id, zoneid=self.zone.id,
domainid=self.account.domainid, domainid=self.account.domainid,
networkid=self.virtual_machine.nic[0].networkid) networkid=self.virtual_machine.nic[0].networkid)
self.cleanup.append(public_ip1)
lb_rule1 = LoadBalancerRule.create( lb_rule1 = LoadBalancerRule.create(
self.apiclient, self.apiclient,
@ -663,6 +664,7 @@ class TestFailureScenarios(cloudstackTestCase):
accountid=self.account.name, accountid=self.account.name,
networkid=self.virtual_machine.nic[0].networkid, networkid=self.virtual_machine.nic[0].networkid,
domainid=self.account.domainid) domainid=self.account.domainid)
self.cleanup.append(lb_rule1)
vmidipmap = [{"vmid": str(self.virtual_machine.id), vmidipmap = [{"vmid": str(self.virtual_machine.id),
"vmip": str(secondaryip.ipaddress)}] "vmip": str(secondaryip.ipaddress)}]
@ -736,25 +738,17 @@ class TestListLBRuleInstances(cloudstackTestCase):
domainid=self.account.domainid, domainid=self.account.domainid,
serviceofferingid=self.service_offering.id, serviceofferingid=self.service_offering.id,
mode=self.zone.networktype) mode=self.zone.networktype)
self.cleanup.append(self.virtual_machine)
except Exception as e: except Exception as e:
self.tearDown() self.tearDown()
raise e raise e
def tearDown(self): def tearDown(self):
try: super(TestListLBRuleInstances, self).tearDown()
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestListLBRuleInstances, cls).tearDownClass()
# Cleanup resources used
cleanup_resources(cls.api_client, cls._cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@attr(tags=["advanced", "selfservice"], required_hardware="false") @attr(tags=["advanced", "selfservice"], required_hardware="false")
def test_09_lbvmips_true(self): def test_09_lbvmips_true(self):
@ -778,6 +772,7 @@ class TestListLBRuleInstances(cloudstackTestCase):
zoneid=self.zone.id, zoneid=self.zone.id,
domainid=self.account.domainid, domainid=self.account.domainid,
networkid=self.virtual_machine.nic[0].networkid) networkid=self.virtual_machine.nic[0].networkid)
self.cleanup.append(public_ip)
lb_rule = LoadBalancerRule.create( lb_rule = LoadBalancerRule.create(
self.apiclient, self.apiclient,
@ -786,6 +781,7 @@ class TestListLBRuleInstances(cloudstackTestCase):
accountid=self.account.name, accountid=self.account.name,
networkid=self.virtual_machine.nic[0].networkid, networkid=self.virtual_machine.nic[0].networkid,
domainid=self.account.domainid) domainid=self.account.domainid)
self.cleanup.append(lb_rule)
vmidipmap = [{"vmid": str(self.virtual_machine.id), vmidipmap = [{"vmid": str(self.virtual_machine.id),
"vmip": str(secondaryip.ipaddress)}] "vmip": str(secondaryip.ipaddress)}]
@ -836,6 +832,7 @@ class TestListLBRuleInstances(cloudstackTestCase):
zoneid=self.zone.id, zoneid=self.zone.id,
domainid=self.account.domainid, domainid=self.account.domainid,
networkid=self.virtual_machine.nic[0].networkid) networkid=self.virtual_machine.nic[0].networkid)
self.cleanup.append(public_ip)
lb_rule = LoadBalancerRule.create( lb_rule = LoadBalancerRule.create(
self.apiclient, self.apiclient,
@ -844,6 +841,7 @@ class TestListLBRuleInstances(cloudstackTestCase):
accountid=self.account.name, accountid=self.account.name,
networkid=self.virtual_machine.nic[0].networkid, networkid=self.virtual_machine.nic[0].networkid,
domainid=self.account.domainid) domainid=self.account.domainid)
self.cleanup.append(lb_rule)
vmidipmap = [{"vmid": str(self.virtual_machine.id), vmidipmap = [{"vmid": str(self.virtual_machine.id),
"vmip": str(secondaryip.ipaddress)}] "vmip": str(secondaryip.ipaddress)}]
@ -927,6 +925,7 @@ class TestLbRuleFunctioning(cloudstackTestCase):
domainid=self.account.domainid, domainid=self.account.domainid,
serviceofferingid=self.service_offering.id, serviceofferingid=self.service_offering.id,
mode=self.zone.networktype) mode=self.zone.networktype)
self.cleanup.append(self.virtual_machine)
self.secondaryip = NIC.addIp(self.apiclient, self.secondaryip = NIC.addIp(self.apiclient,
id=self.virtual_machine.nic[0].id) id=self.virtual_machine.nic[0].id)
@ -937,8 +936,9 @@ class TestLbRuleFunctioning(cloudstackTestCase):
zoneid=self.zone.id, zoneid=self.zone.id,
domainid=self.account.domainid, domainid=self.account.domainid,
networkid=self.virtual_machine.nic[0].networkid) networkid=self.virtual_machine.nic[0].networkid)
self.cleanup.append(self.public_ip)
FireWallRule.create( fwr = FireWallRule.create(
self.apiclient, self.apiclient,
ipaddressid=self.public_ip.ipaddress.id, ipaddressid=self.public_ip.ipaddress.id,
protocol='TCP', protocol='TCP',
@ -946,6 +946,7 @@ class TestLbRuleFunctioning(cloudstackTestCase):
self.testdata["fwrule"]["cidr"]], self.testdata["fwrule"]["cidr"]],
startport=self.testdata["fwrule"]["startport"], startport=self.testdata["fwrule"]["startport"],
endport=self.testdata["fwrule"]["endport"]) endport=self.testdata["fwrule"]["endport"])
self.cleanup.append(fwr)
# To make secondary IP working for VM, we have to configure it on # To make secondary IP working for VM, we have to configure it on
# VM after acquiring it # VM after acquiring it
@ -960,6 +961,7 @@ class TestLbRuleFunctioning(cloudstackTestCase):
self.testdata["natrule"], self.testdata["natrule"],
ipaddressid=self.public_ip.ipaddress.id, ipaddressid=self.public_ip.ipaddress.id,
networkid=self.virtual_machine.nic[0].networkid) networkid=self.virtual_machine.nic[0].networkid)
self.cleanup.append(nat_rule)
sshClient = SshClient(self.public_ip.ipaddress.ipaddress, sshClient = SshClient(self.public_ip.ipaddress.ipaddress,
self.testdata['natrule']["publicport"], self.testdata['natrule']["publicport"],
@ -984,6 +986,7 @@ class TestLbRuleFunctioning(cloudstackTestCase):
# Deleting NAT rule after configuring secondary IP # Deleting NAT rule after configuring secondary IP
nat_rule.delete(self.apiclient) nat_rule.delete(self.apiclient)
self.cleanup.remove(nat_rule)
self.testdata["lbrule"]["publicport"] = 22 self.testdata["lbrule"]["publicport"] = 22
self.testdata["lbrule"]["privateport"] = 22 self.testdata["lbrule"]["privateport"] = 22
@ -995,25 +998,17 @@ class TestLbRuleFunctioning(cloudstackTestCase):
accountid=self.account.name, accountid=self.account.name,
networkid=self.virtual_machine.nic[0].networkid, networkid=self.virtual_machine.nic[0].networkid,
domainid=self.account.domainid) domainid=self.account.domainid)
self.cleanup.append(self.lb_rule)
except Exception as e: except Exception as e:
self.tearDown() self.tearDown()
raise e raise e
def tearDown(self): def tearDown(self):
try: super(TestLbRuleFunctioning, self).tearDown()
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestLbRuleFunctioning, cls).tearDownClass()
# Cleanup resources used
cleanup_resources(cls.api_client, cls._cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@attr(tags=["advanced"], required_hardware="true") @attr(tags=["advanced"], required_hardware="true")
def test_11_ssh_to_secondary_ip(self): def test_11_ssh_to_secondary_ip(self):
@ -1081,6 +1076,7 @@ class TestLbRuleFunctioning(cloudstackTestCase):
self.fail("Exception during SSH : %s" % e) self.fail("Exception during SSH : %s" % e)
self.public_ip.delete(self.apiclient) self.public_ip.delete(self.apiclient)
self.cleanup.remove(self.public_ip)
with self.assertRaises(Exception): with self.assertRaises(Exception):
LoadBalancerRule.list(self.apiclient, id=self.lb_rule.id) LoadBalancerRule.list(self.apiclient, id=self.lb_rule.id)
@ -1126,6 +1122,7 @@ class TestLbRuleFunctioning(cloudstackTestCase):
self.fail("Exception during SSH : %s" % e) self.fail("Exception during SSH : %s" % e)
self.lb_rule.delete(self.apiclient) self.lb_rule.delete(self.apiclient)
self.cleanup.remove(self.lb_rule)
with self.assertRaises(Exception): with self.assertRaises(Exception):
SshClient(self.public_ip.ipaddress.ipaddress, SshClient(self.public_ip.ipaddress.ipaddress,
@ -1175,6 +1172,7 @@ class TestLbRuleFunctioning(cloudstackTestCase):
self.lb_rule.remove(self.apiclient, self.lb_rule.remove(self.apiclient,
vmidipmap=vmidipmap) vmidipmap=vmidipmap)
self.cleanup.remove(self.lb_rule)
try: try:
SshClient(self.public_ip.ipaddress.ipaddress, SshClient(self.public_ip.ipaddress.ipaddress,
@ -1226,6 +1224,7 @@ class TestLbRuleFunctioning(cloudstackTestCase):
self.lb_rule.remove(self.apiclient, self.lb_rule.remove(self.apiclient,
vmidipmap=vmidipmap) vmidipmap=vmidipmap)
self.cleanup.remove(self.lb_rule)
try: try:
SshClient(self.public_ip.ipaddress.ipaddress, SshClient(self.public_ip.ipaddress.ipaddress,
@ -1272,6 +1271,7 @@ class TestLbRuleFunctioning(cloudstackTestCase):
self.fail("Exception during SSH : %s" % e) self.fail("Exception during SSH : %s" % e)
self.lb_rule.remove(self.apiclient, vms=[self.virtual_machine]) self.lb_rule.remove(self.apiclient, vms=[self.virtual_machine])
self.cleanup.remove(self.lb_rule)
lbrules = LoadBalancerRule.list( lbrules = LoadBalancerRule.list(
self.apiclient, self.apiclient,
@ -1441,6 +1441,7 @@ class TestNetworkOperations(cloudstackTestCase):
domainid=self.account.domainid, domainid=self.account.domainid,
serviceofferingid=self.service_offering.id, serviceofferingid=self.service_offering.id,
mode=self.zone.networktype) mode=self.zone.networktype)
self.cleanup.append(self.virtual_machine)
self.secondaryip = NIC.addIp(self.apiclient, self.secondaryip = NIC.addIp(self.apiclient,
id=self.virtual_machine.nic[0].id) id=self.virtual_machine.nic[0].id)
@ -1450,8 +1451,9 @@ class TestNetworkOperations(cloudstackTestCase):
zoneid=self.zone.id, zoneid=self.zone.id,
domainid=self.account.domainid, domainid=self.account.domainid,
networkid=self.virtual_machine.nic[0].networkid) networkid=self.virtual_machine.nic[0].networkid)
self.cleanup.append(self.public_ip)
FireWallRule.create( fwr = FireWallRule.create(
self.apiclient, self.apiclient,
ipaddressid=self.public_ip.ipaddress.id, ipaddressid=self.public_ip.ipaddress.id,
protocol='TCP', protocol='TCP',
@ -1459,6 +1461,7 @@ class TestNetworkOperations(cloudstackTestCase):
self.testdata["fwrule"]["cidr"]], self.testdata["fwrule"]["cidr"]],
startport=self.testdata["fwrule"]["startport"], startport=self.testdata["fwrule"]["startport"],
endport=self.testdata["fwrule"]["endport"]) endport=self.testdata["fwrule"]["endport"])
self.cleanup.append(fwr)
# To make secondary IP working for VM, we have to configure it # To make secondary IP working for VM, we have to configure it
# on VM after acquiring it # on VM after acquiring it
@ -1473,6 +1476,7 @@ class TestNetworkOperations(cloudstackTestCase):
self.testdata["natrule"], self.testdata["natrule"],
ipaddressid=self.public_ip.ipaddress.id, ipaddressid=self.public_ip.ipaddress.id,
networkid=self.virtual_machine.nic[0].networkid) networkid=self.virtual_machine.nic[0].networkid)
self.cleanup.append(nat_rule)
sshClient = SshClient(self.public_ip.ipaddress.ipaddress, sshClient = SshClient(self.public_ip.ipaddress.ipaddress,
self.testdata['natrule']["publicport"], self.testdata['natrule']["publicport"],
@ -1497,6 +1501,7 @@ class TestNetworkOperations(cloudstackTestCase):
# Deleting NAT rule after configuring secondary IP # Deleting NAT rule after configuring secondary IP
nat_rule.delete(self.apiclient) nat_rule.delete(self.apiclient)
self.cleanup.remove(nat_rule)
self.testdata["lbrule"]["publicport"] = 22 self.testdata["lbrule"]["publicport"] = 22
self.testdata["lbrule"]["privateport"] = 22 self.testdata["lbrule"]["privateport"] = 22
@ -1508,25 +1513,17 @@ class TestNetworkOperations(cloudstackTestCase):
accountid=self.account.name, accountid=self.account.name,
networkid=self.virtual_machine.nic[0].networkid, networkid=self.virtual_machine.nic[0].networkid,
domainid=self.account.domainid) domainid=self.account.domainid)
self.cleanup.append(self.lb_rule)
except Exception as e: except Exception as e:
self.tearDown() self.tearDown()
raise e raise e
def tearDown(self): def tearDown(self):
try: super(TestNetworkOperations, self).tearDown()
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestNetworkOperations, cls).tearDownClass()
# Cleanup resources used
cleanup_resources(cls.api_client, cls._cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@attr(tags=["advanced"], required_hardware="true") @attr(tags=["advanced"], required_hardware="true")
def test_17_restart_router(self): def test_17_restart_router(self):
@ -1887,20 +1884,11 @@ class TestExternalLoadBalancer(cloudstackTestCase):
raise e raise e
def tearDown(self): def tearDown(self):
try: super(TestExternalLoadBalancer, self).tearDown()
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestExternalLoadBalancer, cls).tearDownClass()
# Cleanup resources used
cleanup_resources(cls.api_client, cls._cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@attr(tags=["advancedns", "provisioning"], required_hardware="true") @attr(tags=["advancedns", "provisioning"], required_hardware="true")
def test_23_lb_rule_functioning_with_netscaler(self): def test_23_lb_rule_functioning_with_netscaler(self):
@ -1921,6 +1909,7 @@ class TestExternalLoadBalancer(cloudstackTestCase):
self.apiclient, self.apiclient,
self.testdata["nw_off_isolated_netscaler"] self.testdata["nw_off_isolated_netscaler"]
) )
self.cleanup.append(nwoff_netscaler)
# Enable Network offering # Enable Network offering
nwoff_netscaler.update(self.apiclient, state='Enabled') nwoff_netscaler.update(self.apiclient, state='Enabled')
# Creating a Network Using the Network Offering # Creating a Network Using the Network Offering
@ -1932,6 +1921,7 @@ class TestExternalLoadBalancer(cloudstackTestCase):
networkofferingid=nwoff_netscaler.id, networkofferingid=nwoff_netscaler.id,
zoneid=self.zone.id zoneid=self.zone.id
) )
self.cleanup.append(network)
self.virtual_machine = VirtualMachine.create( self.virtual_machine = VirtualMachine.create(
self.api_client, self.api_client,
@ -1941,6 +1931,7 @@ class TestExternalLoadBalancer(cloudstackTestCase):
serviceofferingid=self.service_offering.id, serviceofferingid=self.service_offering.id,
mode=self.zone.networktype, mode=self.zone.networktype,
networkids=[network.id]) networkids=[network.id])
self.cleanup.append(self.virtual_machine)
secondaryip = NIC.addIp(self.apiclient, secondaryip = NIC.addIp(self.apiclient,
id=self.virtual_machine.nic[0].id) id=self.virtual_machine.nic[0].id)
@ -1951,8 +1942,9 @@ class TestExternalLoadBalancer(cloudstackTestCase):
zoneid=self.zone.id, zoneid=self.zone.id,
domainid=self.account.domainid, domainid=self.account.domainid,
networkid=self.virtual_machine.nic[0].networkid) networkid=self.virtual_machine.nic[0].networkid)
self.cleanup.append(public_ip)
FireWallRule.create( fwr = FireWallRule.create(
self.apiclient, self.apiclient,
ipaddressid=public_ip.ipaddress.id, ipaddressid=public_ip.ipaddress.id,
protocol='TCP', protocol='TCP',
@ -1960,6 +1952,7 @@ class TestExternalLoadBalancer(cloudstackTestCase):
self.testdata["fwrule"]["cidr"]], self.testdata["fwrule"]["cidr"]],
startport=self.testdata["fwrule"]["startport"], startport=self.testdata["fwrule"]["startport"],
endport=self.testdata["fwrule"]["endport"]) endport=self.testdata["fwrule"]["endport"])
self.cleanup.append(fwr)
nat_rule = NATRule.create( nat_rule = NATRule.create(
self.apiclient, self.apiclient,
@ -1967,6 +1960,7 @@ class TestExternalLoadBalancer(cloudstackTestCase):
self.testdata["natrule"], self.testdata["natrule"],
ipaddressid=public_ip.ipaddress.id, ipaddressid=public_ip.ipaddress.id,
networkid=self.virtual_machine.nic[0].networkid) networkid=self.virtual_machine.nic[0].networkid)
self.cleanup.append(nat_rule)
sshClient = SshClient(public_ip.ipaddress.ipaddress, sshClient = SshClient(public_ip.ipaddress.ipaddress,
self.testdata['natrule']["publicport"], self.testdata['natrule']["publicport"],
@ -2002,6 +1996,7 @@ class TestExternalLoadBalancer(cloudstackTestCase):
accountid=self.account.name, accountid=self.account.name,
networkid=self.virtual_machine.nic[0].networkid, networkid=self.virtual_machine.nic[0].networkid,
domainid=self.account.domainid) domainid=self.account.domainid)
self.cleanup.append(lb_rule)
vmidipmap = [{"vmid": str(self.virtual_machine.id), vmidipmap = [{"vmid": str(self.virtual_machine.id),
"vmip": str(secondaryip.ipaddress)}] "vmip": str(secondaryip.ipaddress)}]

View File

@ -65,6 +65,7 @@ def createNetwork(self, networkType):
accountid=self.account.name, accountid=self.account.name,
domainid=self.account.domainid, domainid=self.account.domainid,
zoneid=self.zone.id) zoneid=self.zone.id)
self.cleanup.append(network)
except Exception as e: except Exception as e:
self.fail("Isolated network creation failed because: %s" % e) self.fail("Isolated network creation failed because: %s" % e)
@ -103,6 +104,7 @@ def createNetwork(self, networkType):
zoneid=self.zone.id, zoneid=self.zone.id,
account=self.account.name, account=self.account.name,
domainid=self.account.domainid) domainid=self.account.domainid)
self.cleanup.append(vpc)
vpcs = VPC.list(self.apiclient, id=vpc.id) vpcs = VPC.list(self.apiclient, id=vpc.id)
self.assertEqual( self.assertEqual(
validateList(vpcs)[0], validateList(vpcs)[0],
@ -120,6 +122,7 @@ def createNetwork(self, networkType):
vpcid=vpc.id, vpcid=vpc.id,
gateway="10.1.1.1", gateway="10.1.1.1",
netmask="255.255.255.0") netmask="255.255.255.0")
self.cleanup.append(network)
return network return network
@ -150,9 +153,10 @@ def createNetworkRules(
domainid=self.account.domainid, domainid=self.account.domainid,
networkid=network.id, networkid=network.id,
vpcid=network.vpcid if networktype == VPC_NETWORK else None) vpcid=network.vpcid if networktype == VPC_NETWORK else None)
self.cleanup.append(public_ip)
if networktype != VPC_NETWORK: if networktype != VPC_NETWORK:
FireWallRule.create( fwr = FireWallRule.create(
self.apiclient, self.apiclient,
ipaddressid=public_ip.ipaddress.id, ipaddressid=public_ip.ipaddress.id,
protocol='TCP', protocol='TCP',
@ -160,15 +164,17 @@ def createNetworkRules(
self.services["fwrule"]["cidr"]], self.services["fwrule"]["cidr"]],
startport=self.services["fwrule"]["startport"], startport=self.services["fwrule"]["startport"],
endport=self.services["fwrule"]["endport"]) endport=self.services["fwrule"]["endport"])
self.cleanup.append(fwr)
if ruletype == "nat": if ruletype == "nat":
NATRule.create( nat_rule = NATRule.create(
self.api_client, self.api_client,
virtual_machine, virtual_machine,
self.services["natrule"], self.services["natrule"],
ipaddressid=public_ip.ipaddress.id, ipaddressid=public_ip.ipaddress.id,
networkid=network.id, networkid=network.id,
vmguestip=vmguestip) vmguestip=vmguestip)
self.cleanup.append(nat_rule)
elif ruletype == "staticnat": elif ruletype == "staticnat":
StaticNATRule.enable( StaticNATRule.enable(
self.apiclient, self.apiclient,
@ -243,12 +249,7 @@ class TestBasicOperations(cloudstackTestCase):
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestBasicOperations, cls).tearDownClass()
# 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): def setUp(self):
self.apiclient = self.testClient.getApiClient() self.apiclient = self.testClient.getApiClient()
@ -257,13 +258,7 @@ class TestBasicOperations(cloudstackTestCase):
return return
def tearDown(self): def tearDown(self):
try: super(TestBasicOperations, self).tearDown()
# Clean up, terminate the resources created
cleanup_resources(self.apiclient, self.cleanup)
self.cleanup[:] = []
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
def VerifyStaticNatForPublicIp(self, ipaddressid, natrulestatus): def VerifyStaticNatForPublicIp(self, ipaddressid, natrulestatus):
""" List public IP and verify that NAT rule status for the IP is as desired """ """ List public IP and verify that NAT rule status for the IP is as desired """
@ -321,6 +316,7 @@ class TestBasicOperations(cloudstackTestCase):
serviceofferingid=self.service_offering.id, serviceofferingid=self.service_offering.id,
accountid=self.account.name, accountid=self.account.name,
domainid=self.account.domainid) domainid=self.account.domainid)
self.cleanup.append(virtual_machine)
ipaddress_1 = NIC.addIp( ipaddress_1 = NIC.addIp(
self.apiclient, self.apiclient,
@ -396,6 +392,7 @@ class TestBasicOperations(cloudstackTestCase):
serviceofferingid=self.service_offering.id, serviceofferingid=self.service_offering.id,
accountid=self.account.name, accountid=self.account.name,
domainid=self.account.domainid) domainid=self.account.domainid)
self.cleanup.append(virtual_machine)
ipaddress_1 = NIC.addIp( ipaddress_1 = NIC.addIp(
self.apiclient, self.apiclient,
@ -506,6 +503,7 @@ class TestBasicOperations(cloudstackTestCase):
serviceofferingid=self.service_offering.id, serviceofferingid=self.service_offering.id,
accountid=self.account.name, accountid=self.account.name,
domainid=self.account.domainid) domainid=self.account.domainid)
self.cleanup.append(virtual_machine)
NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id) NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id)
@ -600,13 +598,13 @@ class TestBasicOperations(cloudstackTestCase):
self.apiclient, self.apiclient,
services=self.services["domain"], services=self.services["domain"],
parentdomainid=self.domain.id) parentdomainid=self.domain.id)
self.cleanup.append(child_domain)
self.account = Account.create( self.account = Account.create(
self.apiclient, self.apiclient,
self.services["account"], self.services["account"],
domainid=child_domain.id) domainid=child_domain.id)
self.cleanup.append(self.account) self.cleanup.append(self.account)
self.cleanup.append(child_domain)
apiclient = self.testClient.getUserApiClient( apiclient = self.testClient.getUserApiClient(
UserName=self.account.name, UserName=self.account.name,
@ -622,6 +620,7 @@ class TestBasicOperations(cloudstackTestCase):
serviceofferingid=self.service_offering.id, serviceofferingid=self.service_offering.id,
accountid=self.account.name, accountid=self.account.name,
domainid=self.account.domainid) domainid=self.account.domainid)
self.cleanup.append(virtual_machine)
ipaddress_1 = NIC.addIp(apiclient, id=virtual_machine.nic[0].id) ipaddress_1 = NIC.addIp(apiclient, id=virtual_machine.nic[0].id)
@ -707,18 +706,13 @@ class TestNetworkRules(cloudstackTestCase):
cls.vpc_off = VpcOffering.create( cls.vpc_off = VpcOffering.create(
cls.api_client, cls.api_client,
cls.services["vpc_offering"]) cls.services["vpc_offering"])
cls.vpc_off.update(cls.api_client, state='Enabled')
cls._cleanup.append(cls.vpc_off) cls._cleanup.append(cls.vpc_off)
cls.vpc_off.update(cls.api_client, state='Enabled')
return return
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestNetworkRules, cls).tearDownClass()
# 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): def setUp(self):
self.apiclient = self.testClient.getApiClient() self.apiclient = self.testClient.getApiClient()
@ -727,13 +721,7 @@ class TestNetworkRules(cloudstackTestCase):
return return
def tearDown(self): def tearDown(self):
try: super(TestNetworkRules, self).tearDown()
# Clean up, terminate the resources created
cleanup_resources(self.apiclient, self.cleanup)
self.cleanup[:] = []
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
def VerifyStaticNatForPublicIp(self, ipaddressid, natrulestatus): def VerifyStaticNatForPublicIp(self, ipaddressid, natrulestatus):
""" List public IP and verify that NAT rule status for the IP is as desired """ """ List public IP and verify that NAT rule status for the IP is as desired """
@ -795,6 +783,7 @@ class TestNetworkRules(cloudstackTestCase):
serviceofferingid=self.service_offering.id, serviceofferingid=self.service_offering.id,
accountid=self.account.name, accountid=self.account.name,
domainid=self.account.domainid) domainid=self.account.domainid)
self.cleanup.append(virtual_machine)
ipaddress_1 = NIC.addIp( ipaddress_1 = NIC.addIp(
self.apiclient, self.apiclient,
@ -884,6 +873,7 @@ class TestNetworkRules(cloudstackTestCase):
serviceofferingid=self.service_offering.id, serviceofferingid=self.service_offering.id,
accountid=self.account.name, accountid=self.account.name,
domainid=self.account.domainid) domainid=self.account.domainid)
self.cleanup.append(virtual_machine)
ipaddress_1 = NIC.addIp( ipaddress_1 = NIC.addIp(
self.apiclient, self.apiclient,
@ -896,6 +886,7 @@ class TestNetworkRules(cloudstackTestCase):
domainid=self.account.domainid, domainid=self.account.domainid,
networkid=network.id, networkid=network.id,
vpcid=network.vpcid if value == VPC_NETWORK else None) vpcid=network.vpcid if value == VPC_NETWORK else None)
self.cleanup.append(public_ip)
if value != VPC_NETWORK: if value != VPC_NETWORK:
firewallrule = FireWallRule.create( firewallrule = FireWallRule.create(
@ -906,6 +897,7 @@ class TestNetworkRules(cloudstackTestCase):
self.services["fwrule"]["cidr"]], self.services["fwrule"]["cidr"]],
startport=self.services["fwrule"]["startport"], startport=self.services["fwrule"]["startport"],
endport=self.services["fwrule"]["endport"]) endport=self.services["fwrule"]["endport"])
self.cleanup.append(firewallrule)
# Create NAT rule # Create NAT rule
natrule = NATRule.create( natrule = NATRule.create(
@ -915,6 +907,7 @@ class TestNetworkRules(cloudstackTestCase):
ipaddressid=public_ip.ipaddress.id, ipaddressid=public_ip.ipaddress.id,
networkid=network.id, networkid=network.id,
vmguestip=ipaddress_1.ipaddress) vmguestip=ipaddress_1.ipaddress)
self.cleanup.append(natrule)
try: try:
NIC.removeIp(self.apiclient, ipaddressid=ipaddress_1.id) NIC.removeIp(self.apiclient, ipaddressid=ipaddress_1.id)
self.fail( self.fail(
@ -926,12 +919,14 @@ class TestNetworkRules(cloudstackTestCase):
if firewallrule: if firewallrule:
try: try:
firewallrule.delete(self.apiclient) firewallrule.delete(self.apiclient)
self.cleanup.remove(firewallrule)
except Exception as e: except Exception as e:
self.fail( self.fail(
"Exception while deleting firewall rule %s: %s" % "Exception while deleting firewall rule %s: %s" %
(firewallrule.id, e)) (firewallrule.id, e))
natrule.delete(self.apiclient) natrule.delete(self.apiclient)
self.cleanup.remove(natrule)
return return
@data(ISOLATED_NETWORK, SHARED_NETWORK, VPC_NETWORK) @data(ISOLATED_NETWORK, SHARED_NETWORK, VPC_NETWORK)

View File

@ -89,31 +89,30 @@ class TestMulipleNicSupport(cloudstackTestCase):
cls.apiclient, cls.apiclient,
services=cls.testdata["acl"]["domain2"], services=cls.testdata["acl"]["domain2"],
parentdomainid=cls.domain.id) parentdomainid=cls.domain.id)
cls._cleanup.append(cls.user_domain)
# Create account
cls.account1 = Account.create( cls.account1 = Account.create(
cls.apiclient, cls.apiclient,
cls.testdata["acl"]["accountD2"], cls.testdata["acl"]["accountD2"],
admin=True, admin=True,
domainid=cls.user_domain.id domainid=cls.user_domain.id
) )
cls._cleanup.append(cls.account1)
# Create small service offering
cls.service_offering = ServiceOffering.create( cls.service_offering = ServiceOffering.create(
cls.apiclient, cls.apiclient,
cls.testdata["service_offerings"]["small"] cls.testdata["service_offerings"]["small"]
) )
cls._cleanup.append(cls.service_offering) cls._cleanup.append(cls.service_offering)
cls.services["network"]["zoneid"] = cls.zone.id cls.services["network"]["zoneid"] = cls.zone.id
cls.network_offering = NetworkOffering.create( cls.network_offering = NetworkOffering.create(
cls.apiclient, cls.apiclient,
cls.services["network_offering"], cls.services["network_offering"],
) )
# Enable Network offering cls._cleanup.append(cls.network_offering)
cls.network_offering.update(cls.apiclient, state='Enabled') cls.network_offering.update(cls.apiclient, state='Enabled')
cls._cleanup.append(cls.network_offering)
cls.testdata["virtual_machine"]["zoneid"] = cls.zone.id cls.testdata["virtual_machine"]["zoneid"] = cls.zone.id
cls.testdata["virtual_machine"]["template"] = cls.template.id cls.testdata["virtual_machine"]["template"] = cls.template.id
@ -125,6 +124,7 @@ class TestMulipleNicSupport(cloudstackTestCase):
account=cls.account1.name, account=cls.account1.name,
domainid=cls.account1.domainid domainid=cls.account1.domainid
) )
cls._cleanup.append(security_group)
# Authorize Security group to SSH to VM # Authorize Security group to SSH to VM
ingress_rule = security_group.authorize( ingress_rule = security_group.authorize(
@ -149,6 +149,7 @@ class TestMulipleNicSupport(cloudstackTestCase):
cls.testdata["shared_network_offering_sg"], cls.testdata["shared_network_offering_sg"],
conservemode=False conservemode=False
) )
cls._cleanup.append(cls.shared_network_offering)
NetworkOffering.update( NetworkOffering.update(
cls.shared_network_offering, cls.shared_network_offering,
@ -175,6 +176,7 @@ class TestMulipleNicSupport(cloudstackTestCase):
accountid=cls.account1.name, accountid=cls.account1.name,
domainid=cls.account1.domainid domainid=cls.account1.domainid
) )
cls._cleanup.append(cls.network1)
random_subnet_number = random.randrange(100, 110) random_subnet_number = random.randrange(100, 110)
cls.testdata["shared_network_sg"]["name"] = "Shared-Network-SG-Test-vlan" + str(random_subnet_number) cls.testdata["shared_network_sg"]["name"] = "Shared-Network-SG-Test-vlan" + str(random_subnet_number)
@ -191,6 +193,7 @@ class TestMulipleNicSupport(cloudstackTestCase):
accountid=cls.account1.name, accountid=cls.account1.name,
domainid=cls.account1.domainid domainid=cls.account1.domainid
) )
cls._cleanup.append(cls.network2)
random_subnet_number = random.randrange(111, 120) random_subnet_number = random.randrange(111, 120)
cls.testdata["shared_network_sg"]["name"] = "Shared-Network-SG-Test-vlan" + str(random_subnet_number) cls.testdata["shared_network_sg"]["name"] = "Shared-Network-SG-Test-vlan" + str(random_subnet_number)
@ -207,6 +210,7 @@ class TestMulipleNicSupport(cloudstackTestCase):
accountid=cls.account1.name, accountid=cls.account1.name,
domainid=cls.account1.domainid domainid=cls.account1.domainid
) )
cls._cleanup.append(cls.network3)
try: try:
cls.virtual_machine1 = VirtualMachine.create( cls.virtual_machine1 = VirtualMachine.create(
@ -219,6 +223,7 @@ class TestMulipleNicSupport(cloudstackTestCase):
securitygroupids=[security_group.id], securitygroupids=[security_group.id],
networkids=cls.network1.id networkids=cls.network1.id
) )
cls._cleanup.append(cls.virtual_machine1)
for nic in cls.virtual_machine1.nic: for nic in cls.virtual_machine1.nic:
if nic.isdefault: if nic.isdefault:
cls.virtual_machine1.ssh_ip = nic.ipaddress cls.virtual_machine1.ssh_ip = nic.ipaddress
@ -238,6 +243,7 @@ class TestMulipleNicSupport(cloudstackTestCase):
securitygroupids=[security_group.id], securitygroupids=[security_group.id],
networkids=[str(cls.network1.id), str(cls.network2.id)] networkids=[str(cls.network1.id), str(cls.network2.id)]
) )
cls._cleanup.append(cls.virtual_machine2)
for nic in cls.virtual_machine2.nic: for nic in cls.virtual_machine2.nic:
if nic.isdefault: if nic.isdefault:
cls.virtual_machine2.ssh_ip = nic.ipaddress cls.virtual_machine2.ssh_ip = nic.ipaddress
@ -246,24 +252,10 @@ class TestMulipleNicSupport(cloudstackTestCase):
except Exception as e: except Exception as e:
cls.fail("Exception while deploying virtual machine: %s" % {e}) cls.fail("Exception while deploying virtual machine: %s" % {e})
cls._cleanup.append(cls.virtual_machine1)
cls._cleanup.append(cls.virtual_machine2)
cls._cleanup.append(cls.network1)
cls._cleanup.append(cls.network2)
cls._cleanup.append(cls.network3)
cls._cleanup.append(cls.shared_network_offering)
if cls.zone.securitygroupsenabled:
cls._cleanup.append(security_group)
cls._cleanup.append(cls.account1)
cls._cleanup.append(cls.user_domain)
@classmethod @classmethod
def tearDownClass(self): def tearDownClass(self):
try: super(TestMulipleNicSupport, self).tearDownClass()
cleanup_resources(self.apiclient, self._cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
def setUp(self): def setUp(self):
if self.skip: if self.skip:
@ -273,11 +265,7 @@ class TestMulipleNicSupport(cloudstackTestCase):
return return
def tearDown(self): def tearDown(self):
try: super(TestMulipleNicSupport, self).tearDown()
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
def verify_network_rules(self, vm_id): def verify_network_rules(self, vm_id):
virtual_machine = VirtualMachine.list( virtual_machine = VirtualMachine.list(
@ -305,6 +293,7 @@ class TestMulipleNicSupport(cloudstackTestCase):
host.password, host.password,
command) command)
if len(result) > 0: if len(result) > 0:
self.logger.debug(f"the verification of the ip tables rules returned : {result}")
self.fail("The iptables/ebtables rules for nic %s on vm %s on host %s are not correct" %(nic.ipaddress, vm.instancename, host.name)) self.fail("The iptables/ebtables rules for nic %s on vm %s on host %s are not correct" %(nic.ipaddress, vm.instancename, host.name))
@attr(tags=["advancedsg"], required_hardware="false") @attr(tags=["advancedsg"], required_hardware="false")

View File

@ -22,9 +22,6 @@
# Import Local Modules # Import Local Modules
from marvin.codes import (FAILED) from marvin.codes import (FAILED)
from marvin.cloudstackTestCase import cloudstackTestCase from marvin.cloudstackTestCase import cloudstackTestCase
from marvin.cloudstackException import CloudstackAPIException
from marvin.cloudstackAPI import rebootRouter
from marvin.sshClient import SshClient
from marvin.lib.utils import cleanup_resources, get_process_status from marvin.lib.utils import cleanup_resources, get_process_status
from marvin.lib.base import (Account, from marvin.lib.base import (Account,
VirtualMachine, VirtualMachine,
@ -48,10 +45,9 @@ from marvin.lib.common import (get_domain,
list_hosts, list_hosts,
list_routers) list_routers)
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
from ddt import ddt, data
# Import System modules # Import System modules
import socket import socket
import time
import logging import logging
_multiprocess_shared_ = True _multiprocess_shared_ = True
@ -61,6 +57,118 @@ stream_handler = logging.StreamHandler()
logger.setLevel(logging.DEBUG) logger.setLevel(logging.DEBUG)
logger.addHandler(stream_handler) logger.addHandler(stream_handler)
class Services:
"""Test multiple public interfaces
"""
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",
},
"domain_admin": {
"email": "domain@admin.com",
"firstname": "Domain",
"lastname": "Admin",
"username": "DoA",
# Random characters are appended for unique
# username
"password": "password",
},
"service_offering": {
"name": "Tiny Instance",
"displaytext": "Tiny Instance",
"cpunumber": 1,
"cpuspeed": 100,
"memory": 128,
},
"publiciprange": {
"gateway": "10.6.0.254",
"netmask": "255.255.255.0",
"startip": "10.6.0.2",
"endip": "10.6.0.20",
"forvirtualnetwork": "true",
"vlan": "300"
},
"extrapubliciprange": {
"gateway": "10.200.100.1",
"netmask": "255.255.255.0",
"startip": "10.200.100.101",
"endip": "10.200.100.105",
"forvirtualnetwork": "false",
"vlan": "301"
},
"network_offering": {
"name": 'VPC Network offering',
"displaytext": 'VPC Network off',
"guestiptype": 'Isolated',
"supportedservices": 'Vpn,Dhcp,Dns,SourceNat,PortForwarding,Lb,UserData,StaticNat,NetworkACL',
"traffictype": 'GUEST',
"availability": 'Optional',
"useVpc": 'on',
"serviceProviderList": {
"Vpn": 'VpcVirtualRouter',
"Dhcp": 'VpcVirtualRouter',
"Dns": 'VpcVirtualRouter',
"SourceNat": 'VpcVirtualRouter',
"PortForwarding": 'VpcVirtualRouter',
"Lb": 'VpcVirtualRouter',
"UserData": 'VpcVirtualRouter',
"StaticNat": 'VpcVirtualRouter',
"NetworkACL": 'VpcVirtualRouter'
},
},
"virtual_machine": {
"displayname": "Test VM",
"username": "root",
"password": "password",
"ssh_port": 22,
"privateport": 22,
"publicport": 22,
"protocol": "TCP",
"affinity": {
"name": "webvms",
"type": "host anti-affinity",
}
},
"vpc_offering": {
"name": 'VPC off',
"displaytext": 'VPC off',
"supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,Vpn,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'
},
"natrule": {
"privateport": 22,
"publicport": 22,
"startport": 22,
"endport": 22,
"protocol": "TCP",
"cidrlist": '0.0.0.0/0',
},
"ostype": "CentOS 5.6 (64-bit)",
"sleep": 60,
"timeout": 10,
"vlan": "10",
"zoneid": '',
"mode": 'advanced'
}
class TestPortForwarding(cloudstackTestCase): class TestPortForwarding(cloudstackTestCase):
@classmethod @classmethod
@ -68,13 +176,16 @@ class TestPortForwarding(cloudstackTestCase):
testClient = super(TestPortForwarding, cls).getClsTestClient() testClient = super(TestPortForwarding, cls).getClsTestClient()
cls.apiclient = testClient.getApiClient() cls.apiclient = testClient.getApiClient()
cls.services = testClient.getParsedTestDataConfig() cls.services = Services().services
cls.hypervisor = testClient.getHypervisorInfo() cls.hypervisor = testClient.getHypervisorInfo()
# Get Zone, Domain and templates # Get Zone, Domain and templates
cls.domain = get_domain(cls.apiclient) cls.domain = get_domain(cls.apiclient)
cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
cls.services["virtual_machine"]["zoneid"] = cls.zone.id # cls.services["virtual_machine"]["zoneid"] = cls.zone.id
cls.services["zoneid"] = cls.zone.id cls.services["zoneid"] = cls.zone.id
cls.services["publiciprange"]["zoneid"] = cls.zone.id
cls._cleanup = []
template = get_template( template = get_template(
cls.apiclient, cls.apiclient,
cls.zone.id, cls.zone.id,
@ -84,31 +195,28 @@ class TestPortForwarding(cloudstackTestCase):
assert False, "get_template() failed to return template with description %s" % cls.services[ assert False, "get_template() failed to return template with description %s" % cls.services[
"ostype"] "ostype"]
# Create an account, network, VM and IP addresses
cls.account = Account.create( cls.account = Account.create(
cls.apiclient, cls.apiclient,
cls.services["account"], cls.services["account"],
admin=True, admin=True,
domainid=cls.domain.id domainid=cls.domain.id
) )
cls.services["publiciprange"]["zoneid"] = cls.zone.id cls._cleanup.append(cls.account)
cls.service_offering = ServiceOffering.create( cls.service_offering = ServiceOffering.create(
cls.apiclient, cls.apiclient,
cls.services["service_offerings"]["tiny"] cls.services["service_offering"]
) )
cls._cleanup.append(cls.service_offering)
cls.virtual_machine = VirtualMachine.create( cls.virtual_machine = VirtualMachine.create(
cls.apiclient, cls.apiclient,
cls.services["virtual_machine"], cls.services["virtual_machine"],
zoneid = cls.services["zoneid"],
templateid=template.id, templateid=template.id,
accountid=cls.account.name, accountid=cls.account.name,
domainid=cls.account.domainid, domainid=cls.account.domainid,
serviceofferingid=cls.service_offering.id serviceofferingid=cls.service_offering.id
) )
cls._cleanup = [ cls._cleanup.append(cls.virtual_machine)
cls.virtual_machine,
cls.account,
cls.service_offering
]
def setUp(self): def setUp(self):
self.apiclient = self.testClient.getApiClient() self.apiclient = self.testClient.getApiClient()
@ -117,19 +225,12 @@ class TestPortForwarding(cloudstackTestCase):
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestPortForwarding, cls).tearDownClass()
cls.apiclient = super(
TestPortForwarding,
cls).getClsTestClient().getApiClient()
cleanup_resources(cls.apiclient, cls._cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
def tearDown(self): def tearDown(self):
cleanup_resources(self.apiclient, self.cleanup) super(TestPortForwarding, self).tearDown()
return
@attr(tags=["advanced", "smoke"], required_hardware="true") @attr(tags=["advancedsg", "smoke"], required_hardware="true")
def test_port_forwarding_on_ip_from_non_src_nat_ip_range(self): def test_port_forwarding_on_ip_from_non_src_nat_ip_range(self):
"""Test for port forwarding on a IP which is in pubic IP range different """Test for port forwarding on a IP which is in pubic IP range different
from public IP range that has source NAT IP associated with network from public IP range that has source NAT IP associated with network
@ -142,10 +243,12 @@ class TestPortForwarding(cloudstackTestCase):
# 4. Create a firewall rule to open up the port # 4. Create a firewall rule to open up the port
# 5. Test SSH works to the VM # 5. Test SSH works to the VM
self.services["extrapubliciprange"]["zoneid"] = self.services["zoneid"]
self.public_ip_range = PublicIpRange.create( self.public_ip_range = PublicIpRange.create(
self.apiclient, self.apiclient,
self.services["publiciprange"] self.services["extrapubliciprange"]
) )
self.cleanup.append(self.public_ip_range)
logger.debug("Dedicating Public IP range to the account"); logger.debug("Dedicating Public IP range to the account");
dedicate_public_ip_range_response = PublicIpRange.dedicate( dedicate_public_ip_range_response = PublicIpRange.dedicate(
@ -162,7 +265,6 @@ class TestPortForwarding(cloudstackTestCase):
self.services["virtual_machine"] self.services["virtual_machine"]
) )
self.cleanup.append(ip_address) self.cleanup.append(ip_address)
self.cleanup.append(self.public_ip_range)
# Check if VM is in Running state before creating NAT and firewall rules # Check if VM is in Running state before creating NAT and firewall rules
vm_response = VirtualMachine.list( vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
@ -187,7 +289,7 @@ class TestPortForwarding(cloudstackTestCase):
) )
# Open up firewall port for SSH # Open up firewall port for SSH
FireWallRule.create( fwr = FireWallRule.create(
self.apiclient, self.apiclient,
ipaddressid=ip_address.ipaddress.id, ipaddressid=ip_address.ipaddress.id,
protocol=self.services["natrule"]["protocol"], protocol=self.services["natrule"]["protocol"],
@ -195,6 +297,7 @@ class TestPortForwarding(cloudstackTestCase):
startport=self.services["natrule"]["publicport"], startport=self.services["natrule"]["publicport"],
endport=self.services["natrule"]["publicport"] endport=self.services["natrule"]["publicport"]
) )
self.cleanup.append(fwr)
# Create PF rule # Create PF rule
nat_rule = NATRule.create( nat_rule = NATRule.create(
@ -223,15 +326,14 @@ class TestStaticNat(cloudstackTestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
testClient = super(TestStaticNat, cls).getClsTestClient() testClient = super(TestStaticNat, cls).getClsTestClient()
cls.apiclient = testClient.getApiClient() cls.apiclient = testClient.getApiClient()
cls.services = testClient.getParsedTestDataConfig() cls.services = Services().services
cls.hypervisor = testClient.getHypervisorInfo() cls.hypervisor = testClient.getHypervisorInfo()
# Get Zone, Domain and templates # Get Zone, Domain and templates
cls.domain = get_domain(cls.apiclient) cls.domain = get_domain(cls.apiclient)
cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
cls.services["virtual_machine"]["zoneid"] = cls.zone.id # cls.services["virtual_machine"]["zoneid"] = cls.zone.id
cls.services["zoneid"] = cls.zone.id cls.services["zoneid"] = cls.zone.id
template = get_template( template = get_template(
cls.apiclient, cls.apiclient,
@ -241,33 +343,32 @@ class TestStaticNat(cloudstackTestCase):
if template == FAILED: if template == FAILED:
assert False, "get_template() failed to return template with description %s" % cls.services[ assert False, "get_template() failed to return template with description %s" % cls.services[
"ostype"] "ostype"]
cls._cleanup = []
# Create an account, network, VM and IP addresses
cls.account = Account.create( cls.account = Account.create(
cls.apiclient, cls.apiclient,
cls.services["account"], cls.services["account"],
admin=True, admin=True,
domainid=cls.domain.id domainid=cls.domain.id
) )
cls._cleanup.append(cls.account)
cls.services["publiciprange"]["zoneid"] = cls.zone.id cls.services["publiciprange"]["zoneid"] = cls.zone.id
cls.service_offering = ServiceOffering.create( cls.service_offering = ServiceOffering.create(
cls.apiclient, cls.apiclient,
cls.services["service_offerings"]["tiny"] cls.services["service_offering"]
) )
cls._cleanup.append(cls.service_offering)
cls.virtual_machine = VirtualMachine.create( cls.virtual_machine = VirtualMachine.create(
cls.apiclient, cls.apiclient,
cls.services["virtual_machine"], cls.services["virtual_machine"],
zoneid = cls.services["zoneid"],
templateid=template.id, templateid=template.id,
accountid=cls.account.name, accountid=cls.account.name,
domainid=cls.account.domainid, domainid=cls.account.domainid,
serviceofferingid=cls.service_offering.id serviceofferingid=cls.service_offering.id
) )
cls._cleanup.append(cls.virtual_machine)
cls.defaultNetworkId = cls.virtual_machine.nic[0].networkid cls.defaultNetworkId = cls.virtual_machine.nic[0].networkid
cls._cleanup = [
cls.virtual_machine,
cls.account,
cls.service_offering
]
def setUp(self): def setUp(self):
self.apiclient = self.testClient.getApiClient() self.apiclient = self.testClient.getApiClient()
@ -276,19 +377,12 @@ class TestStaticNat(cloudstackTestCase):
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestStaticNat, cls).tearDownClass()
cls.apiclient = super(
TestStaticNat,
cls).getClsTestClient().getApiClient()
cleanup_resources(cls.apiclient, cls._cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
def tearDown(self): def tearDown(self):
cleanup_resources(self.apiclient, self.cleanup) super(TestStaticNat, self).tearDown()
return
@attr(tags=["advanced", "smoke"], required_hardware="true") @attr(tags=["advancedsg", "smoke"], required_hardware="true")
def test_static_nat_on_ip_from_non_src_nat_ip_range(self): def test_static_nat_on_ip_from_non_src_nat_ip_range(self):
"""Test for static nat on a IP which is in pubic IP range different """Test for static nat on a IP which is in pubic IP range different
from public IP range that has source NAT IP associated with network from public IP range that has source NAT IP associated with network
@ -301,10 +395,12 @@ class TestStaticNat(cloudstackTestCase):
# 4. Create a firewall rule to open up the port # 4. Create a firewall rule to open up the port
# 5. Test SSH works to the VM # 5. Test SSH works to the VM
self.services["extrapubliciprange"]["zoneid"] = self.services["zoneid"]
self.public_ip_range = PublicIpRange.create( self.public_ip_range = PublicIpRange.create(
self.apiclient, self.apiclient,
self.services["publiciprange"] self.services["extrapubliciprange"]
) )
self.cleanup.append(self.public_ip_range)
logger.debug("Dedicating Public IP range to the account"); logger.debug("Dedicating Public IP range to the account");
dedicate_public_ip_range_response = PublicIpRange.dedicate( dedicate_public_ip_range_response = PublicIpRange.dedicate(
self.apiclient, self.apiclient,
@ -320,7 +416,6 @@ class TestStaticNat(cloudstackTestCase):
self.services["virtual_machine"] self.services["virtual_machine"]
) )
self.cleanup.append(ip_address) self.cleanup.append(ip_address)
self.cleanup.append(self.public_ip_range)
# Check if VM is in Running state before creating NAT and firewall rules # Check if VM is in Running state before creating NAT and firewall rules
vm_response = VirtualMachine.list( vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
@ -345,7 +440,7 @@ class TestStaticNat(cloudstackTestCase):
) )
# Open up firewall port for SSH # Open up firewall port for SSH
FireWallRule.create( fwr = FireWallRule.create(
self.apiclient, self.apiclient,
ipaddressid=ip_address.ipaddress.id, ipaddressid=ip_address.ipaddress.id,
protocol=self.services["natrule"]["protocol"], protocol=self.services["natrule"]["protocol"],
@ -353,6 +448,7 @@ class TestStaticNat(cloudstackTestCase):
startport=self.services["natrule"]["publicport"], startport=self.services["natrule"]["publicport"],
endport=self.services["natrule"]["publicport"] endport=self.services["natrule"]["publicport"]
) )
self.cleanup.append(fwr)
# Create Static NAT rule # Create Static NAT rule
StaticNATRule.enable( StaticNATRule.enable(
@ -388,13 +484,14 @@ class TestRouting(cloudstackTestCase):
testClient = super(TestRouting, cls).getClsTestClient() testClient = super(TestRouting, cls).getClsTestClient()
cls.apiclient = testClient.getApiClient() cls.apiclient = testClient.getApiClient()
cls.services = testClient.getParsedTestDataConfig() cls.services = Services().services
cls.hypervisor = testClient.getHypervisorInfo() cls.hypervisor = testClient.getHypervisorInfo()
# Get Zone, Domain and templates # Get Zone, Domain and templates
cls.domain = get_domain(cls.apiclient) cls.domain = get_domain(cls.apiclient)
cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
cls.services["virtual_machine"]["zoneid"] = cls.zone.id # cls.services["virtual_machine"]["zoneid"] = cls.zone.id
cls.services["zoneid"] = cls.zone.id cls.services["zoneid"] = cls.zone.id
cls._cleanup = []
template = get_template( template = get_template(
cls.apiclient, cls.apiclient,
cls.zone.id, cls.zone.id,
@ -404,32 +501,30 @@ class TestRouting(cloudstackTestCase):
assert False, "get_template() failed to return template with description %s" % cls.services[ assert False, "get_template() failed to return template with description %s" % cls.services[
"ostype"] "ostype"]
# Create an account, network, VM and IP addresses
cls.account = Account.create( cls.account = Account.create(
cls.apiclient, cls.apiclient,
cls.services["account"], cls.services["account"],
admin=True, admin=True,
domainid=cls.domain.id domainid=cls.domain.id
) )
cls._cleanup.append(cls.account)
cls.services["publiciprange"]["zoneid"] = cls.zone.id cls.services["publiciprange"]["zoneid"] = cls.zone.id
cls.service_offering = ServiceOffering.create( cls.service_offering = ServiceOffering.create(
cls.apiclient, cls.apiclient,
cls.services["service_offerings"]["tiny"] cls.services["service_offering"]
) )
cls._cleanup.append(cls.service_offering)
cls.hostConfig = cls.config.__dict__["zones"][0].__dict__["pods"][0].__dict__["clusters"][0].__dict__["hosts"][0].__dict__ cls.hostConfig = cls.config.__dict__["zones"][0].__dict__["pods"][0].__dict__["clusters"][0].__dict__["hosts"][0].__dict__
cls.virtual_machine = VirtualMachine.create( cls.virtual_machine = VirtualMachine.create(
cls.apiclient, cls.apiclient,
cls.services["virtual_machine"], cls.services["virtual_machine"],
zoneid = cls.services["zoneid"],
templateid=template.id, templateid=template.id,
accountid=cls.account.name, accountid=cls.account.name,
domainid=cls.account.domainid, domainid=cls.account.domainid,
serviceofferingid=cls.service_offering.id serviceofferingid=cls.service_offering.id
) )
cls._cleanup = [ cls._cleanup.append(cls.virtual_machine)
cls.virtual_machine,
cls.account,
cls.service_offering
]
def setUp(self): def setUp(self):
self.apiclient = self.testClient.getApiClient() self.apiclient = self.testClient.getApiClient()
@ -438,19 +533,12 @@ class TestRouting(cloudstackTestCase):
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestRouting, cls).tearDownClass()
cls.apiclient = super(
TestRouting,
cls).getClsTestClient().getApiClient()
cleanup_resources(cls.apiclient, cls._cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
def tearDown(self): def tearDown(self):
cleanup_resources(self.apiclient, self.cleanup) super(TestRouting, self).tearDown()
return
@attr(tags=["advanced", "smoke"], required_hardware="true") @attr(tags=["advancedsg", "smoke"], required_hardware="true")
def test_routing_tables(self): def test_routing_tables(self):
"""Test routing table in case we have IP associated with a network which is in """Test routing table in case we have IP associated with a network which is in
different pubic IP range from that of public IP range that has source NAT IP. different pubic IP range from that of public IP range that has source NAT IP.
@ -465,11 +553,12 @@ class TestRouting(cloudstackTestCase):
# 5. Login to VR and verify routing tables, there should be Table_eth3 # 5. Login to VR and verify routing tables, there should be Table_eth3
# 6. Delete firewall rule, since its last IP, routing table Table_eth3 should be deleted # 6. Delete firewall rule, since its last IP, routing table Table_eth3 should be deleted
self.services["extrapubliciprange"]["zoneid"] = self.services["zoneid"]
self.public_ip_range = PublicIpRange.create( self.public_ip_range = PublicIpRange.create(
self.apiclient, self.apiclient,
self.services["publiciprange"] self.services["extrapubliciprange"]
) )
self._cleanup.append(self.public_ip_range) self.cleanup.append(self.public_ip_range)
logger.debug("Dedicating Public IP range to the account"); logger.debug("Dedicating Public IP range to the account");
dedicate_public_ip_range_response = PublicIpRange.dedicate( dedicate_public_ip_range_response = PublicIpRange.dedicate(
@ -486,7 +575,7 @@ class TestRouting(cloudstackTestCase):
self.services["virtual_machine"] self.services["virtual_machine"]
) )
self.cleanup.append(ip_address) self.cleanup.append(ip_address)
self.cleanup.append(self.public_ip_range)
# Check if VM is in Running state before creating NAT and firewall rules # Check if VM is in Running state before creating NAT and firewall rules
vm_response = VirtualMachine.list( vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
@ -519,6 +608,7 @@ class TestRouting(cloudstackTestCase):
startport=self.services["natrule"]["publicport"], startport=self.services["natrule"]["publicport"],
endport=self.services["natrule"]["publicport"] endport=self.services["natrule"]["publicport"]
) )
self.cleanup.append(firewall_rule)
# Get the router details associated with account # Get the router details associated with account
routers = list_routers( routers = list_routers(
@ -585,6 +675,7 @@ class TestRouting(cloudstackTestCase):
) )
firewall_rule.delete(self.apiclient) firewall_rule.delete(self.apiclient)
self.cleanup.remove(firewall_rule)
if (self.hypervisor.lower() == 'vmware' if (self.hypervisor.lower() == 'vmware'
or self.hypervisor.lower() == 'hyperv'): or self.hypervisor.lower() == 'hyperv'):
@ -646,13 +737,14 @@ class TestIptables(cloudstackTestCase):
testClient = super(TestIptables, cls).getClsTestClient() testClient = super(TestIptables, cls).getClsTestClient()
cls.apiclient = testClient.getApiClient() cls.apiclient = testClient.getApiClient()
cls.services = testClient.getParsedTestDataConfig() cls.services = Services().services
cls.hypervisor = testClient.getHypervisorInfo() cls.hypervisor = testClient.getHypervisorInfo()
# Get Zone, Domain and templates # Get Zone, Domain and templates
cls.domain = get_domain(cls.apiclient) cls.domain = get_domain(cls.apiclient)
cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
cls.services["virtual_machine"]["zoneid"] = cls.zone.id # cls.services["virtual_machine"]["zoneid"] = cls.zone.id
cls.services["zoneid"] = cls.zone.id cls.services["zoneid"] = cls.zone.id
template = get_template( template = get_template(
cls.apiclient, cls.apiclient,
cls.zone.id, cls.zone.id,
@ -662,32 +754,31 @@ class TestIptables(cloudstackTestCase):
assert False, "get_template() failed to return template with description %s" % cls.services[ assert False, "get_template() failed to return template with description %s" % cls.services[
"ostype"] "ostype"]
# Create an account, network, VM and IP addresses cls._cleanup = []
cls.account = Account.create( cls.account = Account.create(
cls.apiclient, cls.apiclient,
cls.services["account"], cls.services["account"],
admin=True, admin=True,
domainid=cls.domain.id domainid=cls.domain.id
) )
cls._cleanup.append(cls.account)
cls.services["publiciprange"]["zoneid"] = cls.zone.id cls.services["publiciprange"]["zoneid"] = cls.zone.id
cls.service_offering = ServiceOffering.create( cls.service_offering = ServiceOffering.create(
cls.apiclient, cls.apiclient,
cls.services["service_offerings"]["tiny"] cls.services["service_offering"]
) )
cls._cleanup.append(cls.service_offering)
cls.hostConfig = cls.config.__dict__["zones"][0].__dict__["pods"][0].__dict__["clusters"][0].__dict__["hosts"][0].__dict__ cls.hostConfig = cls.config.__dict__["zones"][0].__dict__["pods"][0].__dict__["clusters"][0].__dict__["hosts"][0].__dict__
cls.virtual_machine = VirtualMachine.create( cls.virtual_machine = VirtualMachine.create(
cls.apiclient, cls.apiclient,
cls.services["virtual_machine"], cls.services["virtual_machine"],
zoneid = cls.services["zoneid"],
templateid=template.id, templateid=template.id,
accountid=cls.account.name, accountid=cls.account.name,
domainid=cls.account.domainid, domainid=cls.account.domainid,
serviceofferingid=cls.service_offering.id serviceofferingid=cls.service_offering.id
) )
cls._cleanup = [ cls._cleanup.append(cls.virtual_machine)
cls.virtual_machine,
cls.account,
cls.service_offering
]
def setUp(self): def setUp(self):
self.apiclient = self.testClient.getApiClient() self.apiclient = self.testClient.getApiClient()
@ -696,19 +787,12 @@ class TestIptables(cloudstackTestCase):
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestIptables, cls).tearDownClass()
cls.apiclient = super(
TestIptables,
cls).getClsTestClient().getApiClient()
cleanup_resources(cls.apiclient, cls._cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
def tearDown(self): def tearDown(self):
cleanup_resources(self.apiclient, self.cleanup) super(TestIptables, self).tearDown()
return
@attr(tags=["advanced", "smoke"], required_hardware="true") @attr(tags=["advancedsg", "smoke"], required_hardware="true")
def test_iptable_rules(self): def test_iptable_rules(self):
"""Test iptable rules in case we have IP associated with a network which is in """Test iptable rules in case we have IP associated with a network which is in
different pubic IP range from that of public IP range that has source NAT IP. different pubic IP range from that of public IP range that has source NAT IP.
@ -723,11 +807,12 @@ class TestIptables(cloudstackTestCase):
# 5. Login to VR and verify routing tables, there should be Table_eth3 # 5. Login to VR and verify routing tables, there should be Table_eth3
# 6. Delete firewall rule, since its last IP, routing table Table_eth3 should be deleted # 6. Delete firewall rule, since its last IP, routing table Table_eth3 should be deleted
self.services["extrapubliciprange"]["zoneid"] = self.services["zoneid"]
self.public_ip_range = PublicIpRange.create( self.public_ip_range = PublicIpRange.create(
self.apiclient, self.apiclient,
self.services["publiciprange"] self.services["extrapubliciprange"]
) )
self._cleanup.append(self.public_ip_range) self.cleanup.append(self.public_ip_range)
logger.debug("Dedicating Public IP range to the account"); logger.debug("Dedicating Public IP range to the account");
dedicate_public_ip_range_response = PublicIpRange.dedicate( dedicate_public_ip_range_response = PublicIpRange.dedicate(
@ -776,6 +861,7 @@ class TestIptables(cloudstackTestCase):
startport=self.services["natrule"]["publicport"], startport=self.services["natrule"]["publicport"],
endport=self.services["natrule"]["publicport"] endport=self.services["natrule"]["publicport"]
) )
self.cleanup.append(firewall_rule)
# Get the router details associated with account # Get the router details associated with account
routers = list_routers( routers = list_routers(
self.apiclient, self.apiclient,
@ -831,18 +917,15 @@ class TestIptables(cloudstackTestCase):
"Check to ensure there is a iptable rule to accept the RELATED,ESTABLISHED traffic" "Check to ensure there is a iptable rule to accept the RELATED,ESTABLISHED traffic"
) )
firewall_rule.delete(self.apiclient) firewall_rule.delete(self.apiclient)
self.cleanup.remove(firewall_rule)
class TestVPCPortForwarding(cloudstackTestCase): class TestVPCPortForwarding(cloudstackTestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
socket.setdefaulttimeout(60) socket.setdefaulttimeout(60)
testClient = super(TestVPCPortForwarding, cls).getClsTestClient()
cls.api_client = cls.testClient.getApiClient() cls.api_client = cls.testClient.getApiClient()
cls.services = Services().services
cls.services = testClient.getParsedTestDataConfig()
# Get Zone, Domain and templates # Get Zone, Domain and templates
cls.domain = get_domain(cls.api_client) cls.domain = get_domain(cls.api_client)
@ -852,35 +935,6 @@ class TestVPCPortForwarding(cloudstackTestCase):
cls.zone.id, cls.zone.id,
cls.services["ostype"] cls.services["ostype"]
) )
cls.services["vpc_offering"] = { "name": 'VPC off',
"displaytext": 'VPC off',
"supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,Vpn,Lb,UserData,StaticNat',
}
cls.services["network_offering"] = {
"name": 'VPC Network offering',
"displaytext": 'VPC Network off',
"guestiptype": 'Isolated',
"supportedservices": 'Vpn,Dhcp,Dns,SourceNat,PortForwarding,Lb,UserData,StaticNat,NetworkACL',
"traffictype": 'GUEST',
"availability": 'Optional',
"useVpc": 'on',
"serviceProviderList": {
"Vpn": 'VpcVirtualRouter',
"Dhcp": 'VpcVirtualRouter',
"Dns": 'VpcVirtualRouter',
"SourceNat": 'VpcVirtualRouter',
"PortForwarding": 'VpcVirtualRouter',
"Lb": 'VpcVirtualRouter',
"UserData": 'VpcVirtualRouter',
"StaticNat": 'VpcVirtualRouter',
"NetworkACL": 'VpcVirtualRouter'
},
}
cls.services["network"] = {
"name": "Test Network",
"displaytext": "Test Network",
"netmask": '255.255.255.0'
}
cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["virtual_machine"]["zoneid"] = cls.zone.id
cls.services["virtual_machine"]["template"] = cls.template.id cls.services["virtual_machine"]["template"] = cls.template.id
cls.services["publiciprange"]["zoneid"] = cls.zone.id cls.services["publiciprange"]["zoneid"] = cls.zone.id
@ -895,29 +949,24 @@ class TestVPCPortForwarding(cloudstackTestCase):
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestVPCPortForwarding, cls).tearDownClass()
#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): def setUp(self):
self.apiclient = self.testClient.getApiClient() self.apiclient = self.testClient.getApiClient()
self.cleanup = []
self.account = Account.create( self.account = Account.create(
self.apiclient, self.apiclient,
self.services["account"], self.services["account"],
admin=True, admin=True,
domainid=self.domain.id domainid=self.domain.id
) )
self.cleanup = [self.account] self.cleanup.append(self.account)
logger.debug("Creating a VPC offering..") logger.debug("Creating a VPC offering..")
self.vpc_off = VpcOffering.create( self.vpc_off = VpcOffering.create(
self.apiclient, self.apiclient,
self.services["vpc_offering"] self.services["vpc_offering"]
) )
self._cleanup.append(self.vpc_off) self.cleanup.append(self.vpc_off)
logger.debug("Enabling the VPC offering created") logger.debug("Enabling the VPC offering created")
self.vpc_off.update(self.apiclient, state='Enabled') self.vpc_off.update(self.apiclient, state='Enabled')
@ -931,29 +980,11 @@ class TestVPCPortForwarding(cloudstackTestCase):
account=self.account.name, account=self.account.name,
domainid=self.account.domainid domainid=self.account.domainid
) )
self.cleanup.append(self.vpc)
return return
def tearDown(self): def tearDown(self):
try: super(TestVPCPortForwarding, self).tearDown()
#Clean up, terminate the created network offerings
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
logger.debug("Warning: Exception during cleanup : %s" % e)
return
def check_ssh_into_vm(self, vm, public_ip, testnegative=False):
logger.debug("Checking if we can SSH into VM=%s on public_ip=%s" % (vm.name, public_ip.ipaddress.ipaddress))
try:
vm.get_ssh_client(ipaddress=public_ip.ipaddress.ipaddress)
if not testnegative:
logger.debug("SSH into VM=%s on public_ip=%s is successfully" % (vm.name, public_ip.ipaddress.ipaddress))
else:
self.fail("SSH into VM=%s on public_ip=%s is successfully" % (vm.name, public_ip.ipaddress.ipaddress))
except:
if not testnegative:
self.fail("Failed to SSH into VM - %s" % (public_ip.ipaddress.ipaddress))
else:
logger.debug("Failed to SSH into VM - %s" % (public_ip.ipaddress.ipaddress))
def create_natrule(self, vm, public_ip, network, services=None): def create_natrule(self, vm, public_ip, network, services=None):
logger.debug("Creating NAT rule in network for vm with public IP") logger.debug("Creating NAT rule in network for vm with public IP")
@ -967,6 +998,7 @@ class TestVPCPortForwarding(cloudstackTestCase):
networkid=network.id, networkid=network.id,
vpcid=self.vpc.id vpcid=self.vpc.id
) )
self.cleanup.append(nat_rule)
return nat_rule return nat_rule
def acquire_publicip(self, network): def acquire_publicip(self, network):
@ -978,42 +1010,12 @@ class TestVPCPortForwarding(cloudstackTestCase):
networkid=network.id, networkid=network.id,
vpcid=self.vpc.id vpcid=self.vpc.id
) )
self.cleanup.append(public_ip)
logger.debug("Associated %s with network %s" % (public_ip.ipaddress.ipaddress, logger.debug("Associated %s with network %s" % (public_ip.ipaddress.ipaddress,
network.id network.id
)) ))
return public_ip return public_ip
def create_network(self, net_offerring, gateway='10.1.1.1',vpc=None):
try:
logger.debug('Create NetworkOffering')
net_offerring["name"] = "NET_OFF-" + str(gateway)
nw_off = NetworkOffering.create(self.apiclient,
net_offerring,
conservemode=False
)
# Enable Network offering
nw_off.update(self.apiclient, state='Enabled')
self._cleanup.append(nw_off)
logger.debug('Created and Enabled NetworkOffering')
self.services["network"]["name"] = "NETWORK-" + str(gateway)
logger.debug('Adding Network=%s' % self.services["network"])
default_acl = NetworkACLList.list(self.apiclient, name="default_allow")[0]
obj_network = Network.create(self.apiclient,
self.services["network"],
accountid=self.account.name,
domainid=self.account.domainid,
networkofferingid=nw_off.id,
zoneid=self.zone.id,
gateway=gateway,
aclid=default_acl.id,
vpcid=vpc.id if vpc else self.vpc.id
)
logger.debug("Created network with ID: %s" % obj_network.id)
return obj_network
except Exception as e:
self.fail('Unable to create a Network with offering=%s because of %s ' % (net_offerring, e))
def deployvm_in_network(self, network, host_id=None): def deployvm_in_network(self, network, host_id=None):
try: try:
logger.debug('Creating VM in network=%s' % network.name) logger.debug('Creating VM in network=%s' % network.name)
@ -1026,13 +1028,14 @@ class TestVPCPortForwarding(cloudstackTestCase):
networkids=[str(network.id)], networkids=[str(network.id)],
hostid=host_id hostid=host_id
) )
self.cleanup.append(vm)
logger.debug('Created VM=%s in network=%s' % (vm.id, network.name)) logger.debug('Created VM=%s in network=%s' % (vm.id, network.name))
return vm return vm
except: except:
self.fail('Unable to create VM in a Network=%s' % network.name) self.fail('Unable to create VM in a Network=%s' % network.name)
@attr(tags=["advanced", "intervlan"], required_hardware="true") @attr(tags=["advancedsg", "intervlan"], required_hardware="true")
def test_network_services_VPC_CreatePF(self): def test_network_services_VPC_CreatePF(self):
""" Test Create VPC PF rules on acquired public ip when VpcVirtualRouter is Running """ Test Create VPC PF rules on acquired public ip when VpcVirtualRouter is Running
""" """
@ -1047,11 +1050,12 @@ class TestVPCPortForwarding(cloudstackTestCase):
network_1 = self.create_network(self.services["network_offering"]) network_1 = self.create_network(self.services["network_offering"])
vm_1 = self.deployvm_in_network(network_1) vm_1 = self.deployvm_in_network(network_1)
self.services["extrapubliciprange"]["zoneid"] = self.services["zoneid"]
self.public_ip_range = PublicIpRange.create( self.public_ip_range = PublicIpRange.create(
self.apiclient, self.apiclient,
self.services["publiciprange"] self.services["extrapubliciprange"]
) )
self._cleanup.append(self.public_ip_range) self.cleanup.append(self.public_ip_range)
logger.debug("Dedicating Public IP range to the account"); logger.debug("Dedicating Public IP range to the account");
dedicate_public_ip_range_response = PublicIpRange.dedicate( dedicate_public_ip_range_response = PublicIpRange.dedicate(
self.apiclient, self.apiclient,
@ -1063,6 +1067,7 @@ class TestVPCPortForwarding(cloudstackTestCase):
self.create_natrule( vm_1, public_ip_1, network_1) self.create_natrule( vm_1, public_ip_1, network_1)
self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False)
self.public_ip_range.release(self.apiclient) self.public_ip_range.release(self.apiclient)
self.cleanup.remove(self.public_ip_range)
return return
class TestVPCStaticNat(cloudstackTestCase): class TestVPCStaticNat(cloudstackTestCase):
@ -1074,8 +1079,7 @@ class TestVPCStaticNat(cloudstackTestCase):
testClient = super(TestVPCStaticNat, cls).getClsTestClient() testClient = super(TestVPCStaticNat, cls).getClsTestClient()
cls.api_client = cls.testClient.getApiClient() cls.api_client = cls.testClient.getApiClient()
cls.services = Services().services
cls.services = testClient.getParsedTestDataConfig()
# Get Zone, Domain and templates # Get Zone, Domain and templates
cls.domain = get_domain(cls.api_client) cls.domain = get_domain(cls.api_client)
@ -1085,72 +1089,38 @@ class TestVPCStaticNat(cloudstackTestCase):
cls.zone.id, cls.zone.id,
cls.services["ostype"] cls.services["ostype"]
) )
cls.services["vpc_offering"] = { "name": 'VPC off',
"displaytext": 'VPC off',
"supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,Vpn,Lb,UserData,StaticNat',
}
cls.services["network_offering"] = {
"name": 'VPC Network offering',
"displaytext": 'VPC Network off',
"guestiptype": 'Isolated',
"supportedservices": 'Vpn,Dhcp,Dns,SourceNat,PortForwarding,Lb,UserData,StaticNat,NetworkACL',
"traffictype": 'GUEST',
"availability": 'Optional',
"useVpc": 'on',
"serviceProviderList": {
"Vpn": 'VpcVirtualRouter',
"Dhcp": 'VpcVirtualRouter',
"Dns": 'VpcVirtualRouter',
"SourceNat": 'VpcVirtualRouter',
"PortForwarding": 'VpcVirtualRouter',
"Lb": 'VpcVirtualRouter',
"UserData": 'VpcVirtualRouter',
"StaticNat": 'VpcVirtualRouter',
"NetworkACL": 'VpcVirtualRouter'
},
}
cls.services["network"] = {
"name": "Test Network",
"displaytext": "Test Network",
"netmask": '255.255.255.0'
}
cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["virtual_machine"]["zoneid"] = cls.zone.id
cls.services["virtual_machine"]["template"] = cls.template.id cls.services["virtual_machine"]["template"] = cls.template.id
cls.services["publiciprange"]["zoneid"] = cls.zone.id cls.services["publiciprange"]["zoneid"] = cls.zone.id
cls.service_offering = ServiceOffering.create( cls.service_offering = ServiceOffering.create(
cls.api_client, cls.api_client,
cls.services["service_offering"] cls.services["service_offering"]
) )
cls._cleanup = [cls.service_offering] cls._cleanup = [cls.service_offering]
return return
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestVPCStaticNat, cls).tearDownClass()
#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): def setUp(self):
self.apiclient = self.testClient.getApiClient() self.apiclient = self.testClient.getApiClient()
self.cleanup = []
self.account = Account.create( self.account = Account.create(
self.apiclient, self.apiclient,
self.services["account"], self.services["account"],
admin=True, admin=True,
domainid=self.domain.id domainid=self.domain.id
) )
self.cleanup = [self.account] self.cleanup.append(self.account)
logger.debug("Creating a VPC offering..") logger.debug("Creating a VPC offering..")
self.vpc_off = VpcOffering.create( self.vpc_off = VpcOffering.create(
self.apiclient, self.apiclient,
self.services["vpc_offering"] self.services["vpc_offering"]
) )
self._cleanup.append(self.vpc_off) self.cleanup.append(self.vpc_off)
logger.debug("Enabling the VPC offering created") logger.debug("Enabling the VPC offering created")
self.vpc_off.update(self.apiclient, state='Enabled') self.vpc_off.update(self.apiclient, state='Enabled')
@ -1164,30 +1134,11 @@ class TestVPCStaticNat(cloudstackTestCase):
account=self.account.name, account=self.account.name,
domainid=self.account.domainid domainid=self.account.domainid
) )
self.cleanup.append(self.vpc)
return return
def tearDown(self): def tearDown(self):
try: super(TestVPCStaticNat, self).tearDown()
#Clean up, terminate the created network offerings
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
logger.debug("Warning: Exception during cleanup : %s" % e)
return
def check_ssh_into_vm(self, vm, public_ip, testnegative=False):
logger.debug("Checking if we can SSH into VM=%s on public_ip=%s" % (vm.name, public_ip.ipaddress.ipaddress))
try:
vm.get_ssh_client(ipaddress=public_ip.ipaddress.ipaddress)
if not testnegative:
logger.debug("SSH into VM=%s on public_ip=%s is successfully" % (vm.name, public_ip.ipaddress.ipaddress))
else:
self.fail("SSH into VM=%s on public_ip=%s is successfully" % (vm.name, public_ip.ipaddress.ipaddress))
except:
if not testnegative:
self.fail("Failed to SSH into VM - %s" % (public_ip.ipaddress.ipaddress))
else:
logger.debug("Failed to SSH into VM - %s" % (public_ip.ipaddress.ipaddress))
def acquire_publicip(self, network): def acquire_publicip(self, network):
logger.debug("Associating public IP for network: %s" % network.name) logger.debug("Associating public IP for network: %s" % network.name)
@ -1198,42 +1149,12 @@ class TestVPCStaticNat(cloudstackTestCase):
networkid=network.id, networkid=network.id,
vpcid=self.vpc.id vpcid=self.vpc.id
) )
self.cleanup.append(public_ip)
logger.debug("Associated %s with network %s" % (public_ip.ipaddress.ipaddress, logger.debug("Associated %s with network %s" % (public_ip.ipaddress.ipaddress,
network.id network.id
)) ))
return public_ip return public_ip
def create_network(self, net_offerring, gateway='10.1.1.1',vpc=None):
try:
logger.debug('Create NetworkOffering')
net_offerring["name"] = "NET_OFF-" + str(gateway)
nw_off = NetworkOffering.create(self.apiclient,
net_offerring,
conservemode=False
)
# Enable Network offering
nw_off.update(self.apiclient, state='Enabled')
self._cleanup.append(nw_off)
logger.debug('Created and Enabled NetworkOffering')
self.services["network"]["name"] = "NETWORK-" + str(gateway)
logger.debug('Adding Network=%s' % self.services["network"])
default_acl = NetworkACLList.list(self.apiclient, name="default_allow")[0]
obj_network = Network.create(self.apiclient,
self.services["network"],
accountid=self.account.name,
domainid=self.account.domainid,
networkofferingid=nw_off.id,
zoneid=self.zone.id,
gateway=gateway,
aclid=default_acl.id,
vpcid=vpc.id if vpc else self.vpc.id
)
logger.debug("Created network with ID: %s" % obj_network.id)
return obj_network
except Exception as e:
self.fail('Unable to create a Network with offering=%s because of %s ' % (net_offerring, e))
def deployvm_in_network(self, network, host_id=None): def deployvm_in_network(self, network, host_id=None):
try: try:
logger.debug('Creating VM in network=%s' % network.name) logger.debug('Creating VM in network=%s' % network.name)
@ -1246,6 +1167,7 @@ class TestVPCStaticNat(cloudstackTestCase):
networkids=[str(network.id)], networkids=[str(network.id)],
hostid=host_id hostid=host_id
) )
self.cleanup.append(vm)
logger.debug('Created VM=%s in network=%s' % (vm.id, network.name)) logger.debug('Created VM=%s in network=%s' % (vm.id, network.name))
return vm return vm
@ -1270,7 +1192,7 @@ class TestVPCStaticNat(cloudstackTestCase):
self.fail("Failed to enable static NAT on IP: %s - %s" % ( self.fail("Failed to enable static NAT on IP: %s - %s" % (
public_ip.ipaddress.ipaddress, e)) public_ip.ipaddress.ipaddress, e))
@attr(tags=["advanced", "intervlan"], required_hardware="true") @attr(tags=["advancedsg", "intervlan"], required_hardware="true")
def test_network_services_VPC_CreatePF(self): def test_network_services_VPC_CreatePF(self):
""" Test Create VPC PF rules on acquired public ip when VpcVirtualRouter is Running """ Test Create VPC PF rules on acquired public ip when VpcVirtualRouter is Running
""" """
@ -1289,7 +1211,7 @@ class TestVPCStaticNat(cloudstackTestCase):
self.apiclient, self.apiclient,
self.services["publiciprange"] self.services["publiciprange"]
) )
self._cleanup.append(self.public_ip_range) self.cleanup.append(self.public_ip_range)
logger.debug("Dedicating Public IP range to the account"); logger.debug("Dedicating Public IP range to the account");
dedicate_public_ip_range_response = PublicIpRange.dedicate( dedicate_public_ip_range_response = PublicIpRange.dedicate(
self.apiclient, self.apiclient,
@ -1301,4 +1223,5 @@ class TestVPCStaticNat(cloudstackTestCase):
self.create_StaticNatRule_For_VM( vm_1, public_ip_1, network_1) self.create_StaticNatRule_For_VM( vm_1, public_ip_1, network_1)
self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False)
self.public_ip_range.release(self.apiclient) self.public_ip_range.release(self.apiclient)
self.cleanup.remove(self.public_ip_range)
return return

View File

@ -373,7 +373,8 @@ class TestOrganizationStates(cloudstackTestCase):
## Test cases relating to disabling and enabling cluster ## Test cases relating to disabling and enabling cluster
@attr("disruptive", "simulator_only", tags=["advanced"], required_hardware="false") # was tags=["advanced"]
@attr("disruptive", "simulator_only", tags=["TODO"], required_hardware="false")
def test_31_disableCluster(self): def test_31_disableCluster(self):
""" """
Disable Cluster Disable Cluster
@ -393,7 +394,8 @@ class TestOrganizationStates(cloudstackTestCase):
"Disabled", "Disabled",
"Disabling Cluster did not set the alloctionstate to Disabled") "Disabling Cluster did not set the alloctionstate to Disabled")
@attr("disruptive", "simulator_only", tags=["advanced"], required_hardware="false") # was tags=["advanced"]
@attr("disruptive", "simulator_only", tags=["TODO"], required_hardware="false")
def test_32_disableCluster_admin_deployVM(self): def test_32_disableCluster_admin_deployVM(self):
""" """
Validate that admin is allowed to deploy VM in a disabled cluster Validate that admin is allowed to deploy VM in a disabled cluster
@ -507,7 +509,8 @@ class TestOrganizationStates(cloudstackTestCase):
"Disabled", "Disabled",
"Disabling Host did not set the alloctionstate to Disabled") "Disabling Host did not set the alloctionstate to Disabled")
@attr("disruptive", "simulator_only", tags=["advanced"], required_hardware="false") # was tags=["advanced"]
@attr("disruptive", "simulator_only", tags=["TODO"], required_hardware="false")
def test_42_disableHost_admin_deployVM(self): def test_42_disableHost_admin_deployVM(self):
""" """
Validate that admin is allowed to deploy VM in a disabled host by passing hostId parameter Validate that admin is allowed to deploy VM in a disabled host by passing hostId parameter
@ -583,7 +586,8 @@ class TestOrganizationStates(cloudstackTestCase):
except Exception as e: except Exception as e:
self.debug("Exception thrown when deploying Virtual Machine on a disabled host - %s" % e) self.debug("Exception thrown when deploying Virtual Machine on a disabled host - %s" % e)
@attr("disruptive", "simulator_only", tags=["advanced"], required_hardware="false") # was tags=["advanced"]
@attr("disruptive", "simulator_only", tags=["TODO"], required_hardware="false")
def test_46_disableHost_user_stop_startVM(self): def test_46_disableHost_user_stop_startVM(self):
""" """
Validate that regular user is allowed to stop and start existing VMs running in a disabled host Validate that regular user is allowed to stop and start existing VMs running in a disabled host

View File

@ -1373,7 +1373,8 @@ class TestPersistentNetworks(cloudstackTestCase):
self.fail(exceptionMessage) self.fail(exceptionMessage)
return return
@attr(tags=["advanced"], required_hardware="true") # @attr(tags=["advanced"], required_hardware="true")
@attr(tags=["TODO"], required_hardware="true")
def test_delete_account(self): def test_delete_account(self):
# steps # steps
# 1. create persistent network and deploy VM in it # 1. create persistent network and deploy VM in it
@ -2924,7 +2925,8 @@ class TestVPCNetworkOperations(cloudstackTestCase):
self.VerifyNetworkCleanup(persistent_network_2.id) self.VerifyNetworkCleanup(persistent_network_2.id)
return return
@attr(tags=["advanced"], required_hardware="true") # @attr(tags=["advanced"], required_hardware="true")
@attr(tags=["TODO"], required_hardware="true")
def test_vpc_delete_account(self): def test_vpc_delete_account(self):
# steps # steps
# 1. Create account and create VPC network in the account # 1. Create account and create VPC network in the account

View File

@ -592,7 +592,8 @@ class TestAssociatePublicIp(cloudstackTestCase):
publicipaddress.delete(self.apiclient) publicipaddress.delete(self.apiclient)
return return
@attr(tags=["advanced"], required_hardware="true") # @attr(tags=["advanced"], required_hardware="true")
@attr(tags=["TODO"], required_hardware="true")
def test_associate_ip_address_services_enable_disable(self): def test_associate_ip_address_services_enable_disable(self):
""" Test enabling and disabling NAT, Firewall services on portable ip """ Test enabling and disabling NAT, Firewall services on portable ip
""" """

View File

@ -89,12 +89,7 @@ class TestMultipleChildDomain(cloudstackTestCase):
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestMultipleChildDomain, cls).tearDownClass()
# 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): def setUp(self):
self.apiclient = self.testClient.getApiClient() self.apiclient = self.testClient.getApiClient()
@ -106,22 +101,16 @@ class TestMultipleChildDomain(cloudstackTestCase):
self.apiclient, self.apiclient,
self.services["disk_offering"] self.services["disk_offering"]
) )
self.cleanup.append(self.disk_offering)
self.assertNotEqual(self.disk_offering, None, self.assertNotEqual(self.disk_offering, None,
"Disk offering is None") "Disk offering is None")
self.cleanup.append(self.disk_offering)
except Exception as e: except Exception as e:
self.tearDown() self.tearDown()
self.skipTest("Failure while creating disk offering: %s" % e) self.skipTest("Failure while creating disk offering: %s" % e)
return return
def tearDown(self): def tearDown(self):
try: super(TestMultipleChildDomain, self).tearDown()
# Clean up, terminate the created instance, volumes and snapshots
cleanup_resources(self.apiclient, self.cleanup)
pass
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
def updateDomainResourceLimits(self, parentdomainlimit, subdomainlimit): def updateDomainResourceLimits(self, parentdomainlimit, subdomainlimit):
"""Update primary storage limits of the parent domain and its """Update primary storage limits of the parent domain and its
@ -151,41 +140,39 @@ class TestMultipleChildDomain(cloudstackTestCase):
self.apiclient, self.apiclient,
services=self.services["domain"], services=self.services["domain"],
parentdomainid=self.domain.id) parentdomainid=self.domain.id)
self.cleanup.append(self.parent_domain)
self.parentd_admin = Account.create( self.parentd_admin = Account.create(
self.apiclient, self.apiclient,
self.services["account"], self.services["account"],
admin=True, admin=True,
domainid=self.parent_domain.id) domainid=self.parent_domain.id)
self.cleanup.append(self.parentd_admin)
# Create sub-domains and their admin accounts # Create sub-domains and their admin accounts
self.cdomain_1 = Domain.create( self.cdomain_1 = Domain.create(
self.apiclient, self.apiclient,
services=self.services["domain"], services=self.services["domain"],
parentdomainid=self.parent_domain.id) parentdomainid=self.parent_domain.id)
self.cleanup.append(self.cdomain_1)
self.cdomain_2 = Domain.create( self.cdomain_2 = Domain.create(
self.apiclient, self.apiclient,
services=self.services["domain"], services=self.services["domain"],
parentdomainid=self.parent_domain.id) parentdomainid=self.parent_domain.id)
self.cleanup.append(self.cdomain_2)
self.cadmin_1 = Account.create( self.cadmin_1 = Account.create(
self.apiclient, self.apiclient,
self.services["account"], self.services["account"],
admin=True, admin=True,
domainid=self.cdomain_1.id) domainid=self.cdomain_1.id)
self.cleanup.append(self.cadmin_1)
self.cadmin_2 = Account.create( self.cadmin_2 = Account.create(
self.apiclient, self.apiclient,
self.services["account"], self.services["account"],
admin=True, admin=True,
domainid=self.cdomain_2.id) domainid=self.cdomain_2.id)
# Cleanup the resources created at end of test
self.cleanup.append(self.cadmin_1)
self.cleanup.append(self.cadmin_2) self.cleanup.append(self.cadmin_2)
self.cleanup.append(self.cdomain_1)
self.cleanup.append(self.cdomain_2)
self.cleanup.append(self.parentd_admin)
self.cleanup.append(self.parent_domain)
users = { users = {
self.cdomain_1: self.cadmin_1, self.cdomain_1: self.cadmin_1,
@ -221,7 +208,6 @@ class TestMultipleChildDomain(cloudstackTestCase):
quantity quantity
4. After step 7, resource count in parent domain should be 0""" 4. After step 7, resource count in parent domain should be 0"""
# Setting up account and domain hierarchy
result = self.setupAccounts() result = self.setupAccounts()
self.assertEqual( self.assertEqual(
result[0], result[0],
@ -233,9 +219,10 @@ class TestMultipleChildDomain(cloudstackTestCase):
disksize = 10 disksize = 10
subdomainlimit = (templatesize + disksize) subdomainlimit = (templatesize + disksize)
maxlimit = subdomainlimit * 3 - 1
result = self.updateDomainResourceLimits( result = self.updateDomainResourceLimits(
((subdomainlimit * 3) - 1), int(maxlimit),
subdomainlimit) int(subdomainlimit))
self.assertEqual( self.assertEqual(
result[0], result[0],
PASS, PASS,
@ -279,13 +266,14 @@ class TestMultipleChildDomain(cloudstackTestCase):
"Failed to create api client for account: %s" % "Failed to create api client for account: %s" %
self.cadmin_2.name) self.cadmin_2.name)
VirtualMachine.create( vm_1 = VirtualMachine.create(
api_client_cadmin_1, api_client_cadmin_1,
self.services["virtual_machine"], self.services["virtual_machine"],
accountid=self.cadmin_1.name, accountid=self.cadmin_1.name,
domainid=self.cadmin_1.domainid, domainid=self.cadmin_1.domainid,
diskofferingid=disk_offering_custom.id, diskofferingid=disk_offering_custom.id,
serviceofferingid=self.service_offering.id) serviceofferingid=self.service_offering.id)
self.cleanup.append(vm_1)
self.initialResourceCount = (templatesize + disksize) self.initialResourceCount = (templatesize + disksize)
result = isDomainResourceCountEqualToExpectedCount( result = isDomainResourceCountEqualToExpectedCount(
@ -302,22 +290,25 @@ class TestMultipleChildDomain(cloudstackTestCase):
domainid=self.cadmin_2.domainid, domainid=self.cadmin_2.domainid,
diskofferingid=disk_offering_custom.id, diskofferingid=disk_offering_custom.id,
serviceofferingid=self.service_offering.id) serviceofferingid=self.service_offering.id)
self.cleanup.append(vm_2)
# Now the VMs in two child domains have exhausted the primary storage limit # Now the VMs in two child domains have exhausted the primary storage limit
# of parent domain, hence VM creation in parent domain with custom disk offering # of parent domain, hence VM creation in parent domain with custom disk offering
# should fail # should fail
with self.assertRaises(Exception): with self.assertRaises(Exception):
VirtualMachine.create( vm_faulty = VirtualMachine.create(
api_client_admin, api_client_admin,
self.services["virtual_machine"], self.services["virtual_machine"],
accountid=self.parentd_admin.name, accountid=self.parentd_admin.name,
domainid=self.parentd_admin.domainid, domainid=self.parentd_admin.domainid,
diskofferingid=disk_offering_custom.id, diskofferingid=disk_offering_custom.id,
serviceofferingid=self.service_offering.id) serviceofferingid=self.service_offering.id)
self.cleanup.append(vm_faulty) # should not happen
# Deleting user account # Deleting user account and remove it's resources from the cleanup list
self.cadmin_1.delete(self.apiclient) self.cadmin_1.delete(self.apiclient)
self.cleanup.remove(self.cadmin_1) self.cleanup.remove(self.cadmin_1)
self.cleanup.remove(vm_1)
expectedCount = self.initialResourceCount expectedCount = self.initialResourceCount
result = isDomainResourceCountEqualToExpectedCount( result = isDomainResourceCountEqualToExpectedCount(
@ -328,6 +319,7 @@ class TestMultipleChildDomain(cloudstackTestCase):
try: try:
vm_2.delete(self.apiclient) vm_2.delete(self.apiclient)
self.cleanup.remove(vm_2)
except Exception as e: except Exception as e:
self.fail("Failed to delete instance: %s" % e) self.fail("Failed to delete instance: %s" % e)
@ -387,6 +379,7 @@ class TestMultipleChildDomain(cloudstackTestCase):
domainid=self.account.domainid, domainid=self.account.domainid,
diskofferingid=self.disk_offering.id, diskofferingid=self.disk_offering.id,
serviceofferingid=self.service_offering.id) serviceofferingid=self.service_offering.id)
self.cleanup.append(vm)
expectedCount = templatesize + self.disk_offering.disksize expectedCount = templatesize + self.disk_offering.disksize
result = isDomainResourceCountEqualToExpectedCount( result = isDomainResourceCountEqualToExpectedCount(
@ -400,7 +393,6 @@ class TestMultipleChildDomain(cloudstackTestCase):
disk_offering_10_GB = DiskOffering.create( disk_offering_10_GB = DiskOffering.create(
self.apiclient, self.apiclient,
services=self.services["disk_offering"]) services=self.services["disk_offering"])
self.cleanup.append(disk_offering_10_GB) self.cleanup.append(disk_offering_10_GB)
volume = Volume.create( volume = Volume.create(
@ -410,11 +402,13 @@ class TestMultipleChildDomain(cloudstackTestCase):
account=self.account.name, account=self.account.name,
domainid=self.account.domainid, domainid=self.account.domainid,
diskofferingid=disk_offering_10_GB.id) diskofferingid=disk_offering_10_GB.id)
self.cleanup.append(volume) # we get an exception in the next few lines
volumeSize = (volume.size / (1024 ** 3)) volumeSize = (volume.size / (1024 ** 3))
expectedCount += volumeSize expectedCount += volumeSize
vm.attach_volume(apiclient, volume=volume) vm.attach_volume(apiclient, volume=volume)
self.cleanup.remove(volume) # we can't cleanup an attached volume
result = isDomainResourceCountEqualToExpectedCount( result = isDomainResourceCountEqualToExpectedCount(
self.apiclient, self.domain.id, self.apiclient, self.domain.id,
expectedCount, RESOURCE_PRIMARY_STORAGE) expectedCount, RESOURCE_PRIMARY_STORAGE)
@ -475,7 +469,9 @@ class TestMultipleChildDomain(cloudstackTestCase):
accountid=self.account.name, accountid=self.account.name,
domainid=self.account.domainid, domainid=self.account.domainid,
diskofferingid=self.disk_offering.id, diskofferingid=self.disk_offering.id,
serviceofferingid=self.service_offering.id) serviceofferingid=self.service_offering.id,
startvm=False)
self.cleanup.append(vm)
expectedCount = templatesize + self.disk_offering.disksize expectedCount = templatesize + self.disk_offering.disksize
result = isDomainResourceCountEqualToExpectedCount( result = isDomainResourceCountEqualToExpectedCount(
@ -488,14 +484,12 @@ class TestMultipleChildDomain(cloudstackTestCase):
disk_offering_15_GB = DiskOffering.create( disk_offering_15_GB = DiskOffering.create(
self.apiclient, self.apiclient,
services=self.services["disk_offering"]) services=self.services["disk_offering"])
self.cleanup.append(disk_offering_15_GB) self.cleanup.append(disk_offering_15_GB)
volume2size = self.services["disk_offering"]["disksize"] = 20 volume2size = self.services["disk_offering"]["disksize"] = 20
disk_offering_20_GB = DiskOffering.create( disk_offering_20_GB = DiskOffering.create(
self.apiclient, self.apiclient,
services=self.services["disk_offering"]) services=self.services["disk_offering"])
self.cleanup.append(disk_offering_20_GB) self.cleanup.append(disk_offering_20_GB)
volume_1 = Volume.create( volume_1 = Volume.create(
@ -505,6 +499,7 @@ class TestMultipleChildDomain(cloudstackTestCase):
account=self.account.name, account=self.account.name,
domainid=self.account.domainid, domainid=self.account.domainid,
diskofferingid=disk_offering_15_GB.id) diskofferingid=disk_offering_15_GB.id)
self.cleanup.append(volume_1)
volume_2 = Volume.create( volume_2 = Volume.create(
apiclient, apiclient,
@ -513,9 +508,12 @@ class TestMultipleChildDomain(cloudstackTestCase):
account=self.account.name, account=self.account.name,
domainid=self.account.domainid, domainid=self.account.domainid,
diskofferingid=disk_offering_20_GB.id) diskofferingid=disk_offering_20_GB.id)
self.cleanup.append(volume_2)
vm.attach_volume(apiclient, volume=volume_1) vm.attach_volume(apiclient, volume=volume_1)
self.cleanup.remove(volume_1)
vm.attach_volume(apiclient, volume=volume_2) vm.attach_volume(apiclient, volume=volume_2)
self.cleanup.remove(volume_2)
expectedCount += volume1size + volume2size expectedCount += volume1size + volume2size
result = isDomainResourceCountEqualToExpectedCount( result = isDomainResourceCountEqualToExpectedCount(
@ -537,7 +535,8 @@ class TestMultipleChildDomain(cloudstackTestCase):
self.fail("Failure: %s" % e) self.fail("Failure: %s" % e)
return return
@attr(tags=["advanced"], required_hardware="true") # @attr(tags=["advanced"], required_hardware="true")
@attr(tags=["TODO"], required_hardware="true")
def test_04_create_template_snapshot(self): def test_04_create_template_snapshot(self):
"""Test create snapshot and templates from volume """Test create snapshot and templates from volume
@ -584,6 +583,7 @@ class TestMultipleChildDomain(cloudstackTestCase):
domainid=self.account.domainid, domainid=self.account.domainid,
diskofferingid=self.disk_offering.id, diskofferingid=self.disk_offering.id,
serviceofferingid=self.service_offering.id) serviceofferingid=self.service_offering.id)
self.cleanup.append(vm)
templatesize = (self.template.size / (1024 ** 3)) templatesize = (self.template.size / (1024 ** 3))
@ -603,6 +603,7 @@ class TestMultipleChildDomain(cloudstackTestCase):
vm.id) vm.id)
self.assertEqual(response[0], PASS, response[1]) self.assertEqual(response[0], PASS, response[1])
snapshot = response[1] snapshot = response[1]
self.cleanup.append(snapshot)
response = snapshot.validateState( response = snapshot.validateState(
apiclient, apiclient,
@ -617,8 +618,10 @@ class TestMultipleChildDomain(cloudstackTestCase):
services=self.services["volume"], services=self.services["volume"],
account=self.account.name, account=self.account.name,
domainid=self.account.domainid) domainid=self.account.domainid)
self.cleanup.append(volume)
volumeSize = (volume.size / (1024 ** 3)) volumeSize = (volume.size / (1024 ** 3))
vm.attach_volume(apiclient, volume) vm.attach_volume(apiclient, volume)
self.cleanup.remove(volume)
expectedCount = initialResourceCount + (volumeSize) expectedCount = initialResourceCount + (volumeSize)
result = isDomainResourceCountEqualToExpectedCount( result = isDomainResourceCountEqualToExpectedCount(
self.apiclient, self.domain.id, self.apiclient, self.domain.id,
@ -673,6 +676,7 @@ class TestMultipleChildDomain(cloudstackTestCase):
domainid=self.cadmin_1.domainid, domainid=self.cadmin_1.domainid,
diskofferingid=self.disk_offering.id, diskofferingid=self.disk_offering.id,
serviceofferingid=self.service_offering.id) serviceofferingid=self.service_offering.id)
self.cleanup.append(vm_1)
templatesize = (self.template.size / (1024 ** 3)) templatesize = (self.template.size / (1024 ** 3))
@ -736,6 +740,7 @@ class TestMultipleChildDomain(cloudstackTestCase):
domainid=self.account.domainid, domainid=self.account.domainid,
diskofferingid=self.disk_offering.id, diskofferingid=self.disk_offering.id,
serviceofferingid=self.service_offering.id) serviceofferingid=self.service_offering.id)
self.cleanup.append(vm_1)
templatesize = (self.template.size / (1024 ** 3)) templatesize = (self.template.size / (1024 ** 3))
@ -747,6 +752,7 @@ class TestMultipleChildDomain(cloudstackTestCase):
self.assertTrue(result[2], "Resource count does not match") self.assertTrue(result[2], "Resource count does not match")
vm_1.delete(self.apiclient, expunge=False) vm_1.delete(self.apiclient, expunge=False)
self.cleanup.remove(vm_1)
result = isDomainResourceCountEqualToExpectedCount( result = isDomainResourceCountEqualToExpectedCount(
self.apiclient, self.account.domainid, self.apiclient, self.account.domainid,
@ -755,6 +761,7 @@ class TestMultipleChildDomain(cloudstackTestCase):
self.assertTrue(result[2], "Resource count does not match") self.assertTrue(result[2], "Resource count does not match")
vm_1.recover(self.apiclient) vm_1.recover(self.apiclient)
self.cleanup.append(vm_1)
result = isDomainResourceCountEqualToExpectedCount( result = isDomainResourceCountEqualToExpectedCount(
self.apiclient, self.account.domainid, self.apiclient, self.account.domainid,

View File

@ -96,12 +96,7 @@ class TestVolumeLimits(cloudstackTestCase):
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestVolumeLimits, cls).tearDownClass()
# 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): def setUp(self):
if self.unsupportedStorageType: if self.unsupportedStorageType:
@ -113,22 +108,16 @@ class TestVolumeLimits(cloudstackTestCase):
try: try:
self.services["disk_offering"]["disksize"] = 2 self.services["disk_offering"]["disksize"] = 2
self.disk_offering = DiskOffering.create(self.apiclient, self.services["disk_offering"]) self.disk_offering = DiskOffering.create(self.apiclient, self.services["disk_offering"])
self.cleanup.append(self.disk_offering)
self.assertNotEqual(self.disk_offering, None, \ self.assertNotEqual(self.disk_offering, None, \
"Disk offering is None") "Disk offering is None")
self.cleanup.append(self.disk_offering)
except Exception as e: except Exception as e:
self.tearDown() self.tearDown()
self.skipTest("Failure in setup: %s" % e) self.skipTest("Failure in setup: %s" % e)
return return
def tearDown(self): def tearDown(self):
try: super(TestVolumeLimits, self).tearDown()
# Clean up, terminate the created instance, volumes and snapshots
cleanup_resources(self.apiclient, self.cleanup)
pass
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
def setupAccount(self, accountType): def setupAccount(self, accountType):
"""Setup the account required for the test""" """Setup the account required for the test"""
@ -138,17 +127,18 @@ class TestVolumeLimits(cloudstackTestCase):
self.domain = Domain.create(self.apiclient, self.domain = Domain.create(self.apiclient,
services=self.services["domain"], services=self.services["domain"],
parentdomainid=self.domain.id) parentdomainid=self.domain.id)
self.cleanup.append(self.domain)
self.account = Account.create(self.apiclient, self.services["account"], self.account = Account.create(self.apiclient, self.services["account"],
domainid=self.domain.id, admin=True) domainid=self.domain.id, admin=True)
self.cleanup.append(self.account) self.cleanup.append(self.account)
if accountType == CHILD_DOMAIN_ADMIN:
self.cleanup.append(self.domain)
self.virtualMachine = VirtualMachine.create(self.api_client, self.services["virtual_machine"], self.virtualMachine = VirtualMachine.create(self.api_client, self.services["virtual_machine"],
accountid=self.account.name, domainid=self.account.domainid, accountid=self.account.name, domainid=self.account.domainid,
diskofferingid=self.disk_offering.id, diskofferingid=self.disk_offering.id,
serviceofferingid=self.service_offering.id) serviceofferingid=self.service_offering.id,
startvm=False)
self.cleanup.append(self.virtualMachine)
accounts = Account.list(self.apiclient, id=self.account.id) accounts = Account.list(self.apiclient, id=self.account.id)
@ -216,6 +206,7 @@ class TestVolumeLimits(cloudstackTestCase):
# Stopping instance # Stopping instance
try: try:
self.virtualMachine.delete(self.apiclient, expunge=False) self.virtualMachine.delete(self.apiclient, expunge=False)
self.cleanup.remove(self.virtualMachine)
except Exception as e: except Exception as e:
self.fail("Failed to destroy instance: %s" % e) self.fail("Failed to destroy instance: %s" % e)
response = matchResourceCount( response = matchResourceCount(
@ -227,6 +218,7 @@ class TestVolumeLimits(cloudstackTestCase):
# Recovering instance # Recovering instance
try: try:
self.virtualMachine.recover(self.apiclient) self.virtualMachine.recover(self.apiclient)
self.cleanup.append(self.virtualMachine)
except Exception as e: except Exception as e:
self.fail("Failed to start instance: %s" % e) self.fail("Failed to start instance: %s" % e)
@ -267,13 +259,13 @@ class TestVolumeLimits(cloudstackTestCase):
expectedCount = self.initialResourceCount + int(self.services["disk_offering"]["disksize"]) expectedCount = self.initialResourceCount + int(self.services["disk_offering"]["disksize"])
disk_offering = DiskOffering.create(self.apiclient, disk_offering = DiskOffering.create(self.apiclient,
services=self.services["disk_offering"]) services=self.services["disk_offering"])
self.cleanup.append(disk_offering) self.cleanup.append(disk_offering)
volume = Volume.create( volume = Volume.create(
apiclient, self.services["volume"], zoneid=self.zone.id, apiclient, self.services["volume"], zoneid=self.zone.id,
account=self.account.name, domainid=self.account.domainid, account=self.account.name, domainid=self.account.domainid,
diskofferingid=disk_offering.id) diskofferingid=disk_offering.id)
self.cleanup.append(volume)
except Exception as e: except Exception as e:
self.fail("Failure: %s" % e) self.fail("Failure: %s" % e)
@ -285,6 +277,7 @@ class TestVolumeLimits(cloudstackTestCase):
try: try:
self.virtualMachine.attach_volume(apiclient, volume=volume) self.virtualMachine.attach_volume(apiclient, volume=volume)
self.cleanup.remove(volume)
except Exception as e: except Exception as e:
self.fail("Failed while attaching volume to VM: %s" % e) self.fail("Failed while attaching volume to VM: %s" % e)
@ -296,6 +289,7 @@ class TestVolumeLimits(cloudstackTestCase):
try: try:
self.virtualMachine.detach_volume(apiclient, volume=volume) self.virtualMachine.detach_volume(apiclient, volume=volume)
self.cleanup.append(volume)
except Exception as e: except Exception as e:
self.fail("Failure while detaching volume: %s" % e) self.fail("Failure while detaching volume: %s" % e)
@ -343,22 +337,19 @@ class TestVolumeLimits(cloudstackTestCase):
self.services["disk_offering"]["disksize"] = 10 self.services["disk_offering"]["disksize"] = 10
disk_offering_10_GB = DiskOffering.create(self.apiclient, disk_offering_10_GB = DiskOffering.create(self.apiclient,
services=self.services["disk_offering"]) services=self.services["disk_offering"])
self.cleanup.append(disk_offering_10_GB) self.cleanup.append(disk_offering_10_GB)
volume_1 = Volume.create( volume_1 = Volume.create(
apiclient, self.services["volume"], zoneid=self.zone.id, apiclient, self.services["volume"], zoneid=self.zone.id,
account=self.account.name, domainid=self.account.domainid, account=self.account.name, domainid=self.account.domainid,
diskofferingid=disk_offering_5_GB.id) diskofferingid=disk_offering_5_GB.id)
self.debug("Attaching volume %s to vm %s" % (volume_1.name, self.virtualMachine.name))
self.virtualMachine.attach_volume(apiclient, volume=volume_1)
volume_2 = Volume.create( volume_2 = Volume.create(
apiclient, self.services["volume"], zoneid=self.zone.id, apiclient, self.services["volume"], zoneid=self.zone.id,
account=self.account.name, domainid=self.account.domainid, account=self.account.name, domainid=self.account.domainid,
diskofferingid=disk_offering_10_GB.id) diskofferingid=disk_offering_10_GB.id)
self.debug("Attaching volume %s to vm %s" % (volume_1.name, self.virtualMachine.name))
self.virtualMachine.attach_volume(apiclient, volume=volume_1)
self.debug("Attaching volume %s to vm %s" % (volume_2.name, self.virtualMachine.name)) self.debug("Attaching volume %s to vm %s" % (volume_2.name, self.virtualMachine.name))
self.virtualMachine.attach_volume(apiclient, volume=volume_2) self.virtualMachine.attach_volume(apiclient, volume=volume_2)
except Exception as e: except Exception as e:
@ -419,6 +410,7 @@ class TestVolumeLimits(cloudstackTestCase):
accountid=self.account.name, domainid=self.account.domainid, accountid=self.account.name, domainid=self.account.domainid,
diskofferingid=self.disk_offering.id, diskofferingid=self.disk_offering.id,
serviceofferingid=self.service_offering.id) serviceofferingid=self.service_offering.id)
self.cleanup.append(self.virtualMachine_2)
expectedCount = (self.initialResourceCount * 2) # Total 2 vms expectedCount = (self.initialResourceCount * 2) # Total 2 vms
response = matchResourceCount( response = matchResourceCount(
@ -431,6 +423,7 @@ class TestVolumeLimits(cloudstackTestCase):
accountid=self.account.name, domainid=self.account.domainid, accountid=self.account.name, domainid=self.account.domainid,
diskofferingid=self.disk_offering.id, diskofferingid=self.disk_offering.id,
serviceofferingid=self.service_offering.id) serviceofferingid=self.service_offering.id)
self.cleanup.append(self.virtualMachine_3)
expectedCount = (self.initialResourceCount * 3) # Total 3 vms expectedCount = (self.initialResourceCount * 3) # Total 3 vms
response = matchResourceCount( response = matchResourceCount(
@ -442,6 +435,7 @@ class TestVolumeLimits(cloudstackTestCase):
self.debug("Destroying instance: %s" % self.virtualMachine_2.name) self.debug("Destroying instance: %s" % self.virtualMachine_2.name)
try: try:
self.virtualMachine_2.delete(self.apiclient) self.virtualMachine_2.delete(self.apiclient)
self.cleanup.remove(self.virtualMachine_2)
except Exception as e: except Exception as e:
self.fail("Failed to delete instance: %s" % e) self.fail("Failed to delete instance: %s" % e)
@ -450,7 +444,7 @@ class TestVolumeLimits(cloudstackTestCase):
expectedCount -= (self.template.size / (1024 ** 3)) expectedCount -= (self.template.size / (1024 ** 3))
response = matchResourceCount( response = matchResourceCount(
self.apiclient, expectedCount, self.apiclient, int(expectedCount),
RESOURCE_PRIMARY_STORAGE, RESOURCE_PRIMARY_STORAGE,
accountid=self.account.id) accountid=self.account.id)
self.assertEqual(response[0], PASS, response[1]) self.assertEqual(response[0], PASS, response[1])
@ -474,7 +468,7 @@ class TestVolumeLimits(cloudstackTestCase):
try: try:
account_2 = Account.create(self.apiclient, self.services["account"], account_2 = Account.create(self.apiclient, self.services["account"],
domainid=self.domain.id, admin=True) domainid=self.domain.id, admin=True)
self.cleanup.insert(0, account_2) self.cleanup.append(account_2)
except Exception as e: except Exception as e:
self.fail("Failed to create account: %s" % e) self.fail("Failed to create account: %s" % e)
@ -489,6 +483,8 @@ class TestVolumeLimits(cloudstackTestCase):
self.virtualMachine.stop(self.apiclient) self.virtualMachine.stop(self.apiclient)
self.virtualMachine.assign_virtual_machine(self.apiclient, self.virtualMachine.assign_virtual_machine(self.apiclient,
account_2.name, account_2.domainid) account_2.name, account_2.domainid)
self.cleanup.remove(self.virtualMachine) # should now be cleaned with account_2
self.cleanup.append(self.virtualMachine) # or before to be neat
except Exception as e: except Exception as e:
self.fail("Failed to assign virtual machine to account %s: %s" % self.fail("Failed to assign virtual machine to account %s: %s" %
(account_2.name, e)) (account_2.name, e))
@ -510,7 +506,8 @@ class TestVolumeLimits(cloudstackTestCase):
return return
@data(ROOT_DOMAIN_ADMIN, CHILD_DOMAIN_ADMIN) @data(ROOT_DOMAIN_ADMIN, CHILD_DOMAIN_ADMIN)
@attr(tags=["advanced", "basic"], required_hardware="true") # @attr(tags=["advanced", "basic"], required_hardware="true")
@attr(tags=["TODO"], required_hardware="true")
def test_create_template_snapshot(self, value): def test_create_template_snapshot(self, value):
"""Test create snapshot and templates from volume """Test create snapshot and templates from volume
@ -527,8 +524,12 @@ class TestVolumeLimits(cloudstackTestCase):
self.debug(response[0]) self.debug(response[0])
self.debug(response[1]) self.debug(response[1])
self.assertEqual(response[0], PASS, response[1]) self.assertEqual(response[0], PASS, response[1])
apiclient = self.apiclient apiclient = self.apiclient
try:
self.virtualMachine.start(apiclient)
except Exception as e:
self.fail("Failed to start instance: %s" % e)
if value == CHILD_DOMAIN_ADMIN: if value == CHILD_DOMAIN_ADMIN:
apiclient = self.testClient.getUserApiClient( apiclient = self.testClient.getUserApiClient(
UserName=self.account.name, UserName=self.account.name,
@ -566,7 +567,6 @@ class TestVolumeLimits(cloudstackTestCase):
services=self.services["volume"], services=self.services["volume"],
account=self.account.name, account=self.account.name,
domainid=self.account.domainid) domainid=self.account.domainid)
self.debug("Attaching the volume to vm: %s" % self.virtualMachine.name) self.debug("Attaching the volume to vm: %s" % self.virtualMachine.name)
self.virtualMachine.attach_volume(apiclient, volume) self.virtualMachine.attach_volume(apiclient, volume)
except Exception as e: except Exception as e:
@ -581,12 +581,14 @@ class TestVolumeLimits(cloudstackTestCase):
try: try:
self.virtualMachine.detach_volume(apiclient, volume) self.virtualMachine.detach_volume(apiclient, volume)
self.cleanup.append(volume)
except Exception as e: except Exception as e:
self.fail("Failure in detach volume operation: %s" % e) self.fail("Failure in detach volume operation: %s" % e)
try: try:
self.debug("deleting the volume: %s" % volume.name) self.debug("deleting the volume: %s" % volume.name)
volume.delete(apiclient) volume.delete(apiclient)
self.cleanup.remove(volume)
except Exception as e: except Exception as e:
self.fail("Failure while deleting volume: %s" % e) self.fail("Failure while deleting volume: %s" % e)

View File

@ -120,12 +120,7 @@ class TestResizeVolume(cloudstackTestCase):
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestResizeVolume, cls).tearDownClass()
# 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): def setUp(self):
if self.unsupportedStorageType: if self.unsupportedStorageType:
@ -137,13 +132,7 @@ class TestResizeVolume(cloudstackTestCase):
return return
def tearDown(self): def tearDown(self):
try: super(TestResizeVolume, self).tearDown()
# Clean up, terminate the created instance, volumes and snapshots
cleanup_resources(self.apiclient, self.cleanup)
pass
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
def updateResourceLimits(self, accountLimit=None, domainLimit=None): def updateResourceLimits(self, accountLimit=None, domainLimit=None):
"""Update primary storage limits of the parent domain and its """Update primary storage limits of the parent domain and its
@ -153,13 +142,13 @@ class TestResizeVolume(cloudstackTestCase):
if domainLimit: if domainLimit:
# Update resource limit for domain # Update resource limit for domain
Resources.updateLimit(self.apiclient, resourcetype=10, Resources.updateLimit(self.apiclient, resourcetype=10,
max=domainLimit, max=int(domainLimit),
domainid=self.parent_domain.id) domainid=self.parent_domain.id)
if accountLimit: if accountLimit:
# Update resource limit for domain # Update resource limit for domain
Resources.updateLimit(self.apiclient, Resources.updateLimit(self.apiclient,
resourcetype=10, resourcetype=10,
max=accountLimit, max=int(accountLimit),
account=self.parentd_admin.name, account=self.parentd_admin.name,
domainid=self.parent_domain.id) domainid=self.parent_domain.id)
except Exception as e: except Exception as e:
@ -172,14 +161,13 @@ class TestResizeVolume(cloudstackTestCase):
services=self.services[ services=self.services[
"domain"], "domain"],
parentdomainid=self.domain.id) parentdomainid=self.domain.id)
self.cleanup.append(self.parent_domain)
self.parentd_admin = Account.create(self.apiclient, self.parentd_admin = Account.create(self.apiclient,
self.services["account"], self.services["account"],
admin=True, admin=True,
domainid=self.parent_domain.id) domainid=self.parent_domain.id)
# Cleanup the resources created at end of test
self.cleanup.append(self.parentd_admin) self.cleanup.append(self.parentd_admin)
self.cleanup.append(self.parent_domain)
except Exception as e: except Exception as e:
return [FAIL, e] return [FAIL, e]
return [PASS, None] return [PASS, None]
@ -199,7 +187,6 @@ class TestResizeVolume(cloudstackTestCase):
# 6. Resize operation should be successful and primary storage count # 6. Resize operation should be successful and primary storage count
# for account should be updated successfully""" # for account should be updated successfully"""
# Setting up account and domain hierarchy
result = self.setupAccounts() result = self.setupAccounts()
self.assertEqual(result[0], PASS, result[1]) self.assertEqual(result[0], PASS, result[1])
@ -220,6 +207,7 @@ class TestResizeVolume(cloudstackTestCase):
domainid=self.parent_domain.id, domainid=self.parent_domain.id,
serviceofferingid=self.service_offering.id serviceofferingid=self.service_offering.id
) )
self.cleanup.append(virtualMachine)
volume = Volume.create( volume = Volume.create(
apiclient, self.services["volume"], apiclient, self.services["volume"],
@ -227,7 +215,6 @@ class TestResizeVolume(cloudstackTestCase):
account=self.parentd_admin.name, account=self.parentd_admin.name,
domainid=self.parent_domain.id, domainid=self.parent_domain.id,
diskofferingid=self.disk_offering_5_GB.id) diskofferingid=self.disk_offering_5_GB.id)
virtualMachine.attach_volume(apiclient, volume=volume) virtualMachine.attach_volume(apiclient, volume=volume)
expectedCount = (templateSize + self.disk_offering_5_GB.disksize) expectedCount = (templateSize + self.disk_offering_5_GB.disksize)
@ -291,6 +278,7 @@ class TestResizeVolume(cloudstackTestCase):
domainid=self.parent_domain.id, domainid=self.parent_domain.id,
serviceofferingid=self.service_offering.id serviceofferingid=self.service_offering.id
) )
self.cleanup.append(virtualMachine)
volume = Volume.create( volume = Volume.create(
apiclient, self.services["volume"], apiclient, self.services["volume"],
@ -298,7 +286,6 @@ class TestResizeVolume(cloudstackTestCase):
account=self.parentd_admin.name, account=self.parentd_admin.name,
domainid=self.parent_domain.id, domainid=self.parent_domain.id,
diskofferingid=self.disk_offering_5_GB.id) diskofferingid=self.disk_offering_5_GB.id)
virtualMachine.attach_volume(apiclient, volume=volume) virtualMachine.attach_volume(apiclient, volume=volume)
expectedCount = (templateSize + self.disk_offering_5_GB.disksize) expectedCount = (templateSize + self.disk_offering_5_GB.disksize)
@ -355,6 +342,7 @@ class TestResizeVolume(cloudstackTestCase):
domainid=self.parent_domain.id, domainid=self.parent_domain.id,
serviceofferingid=self.service_offering.id serviceofferingid=self.service_offering.id
) )
self.cleanup.append(virtualMachine)
volume = Volume.create( volume = Volume.create(
apiclient, self.services["volume"], apiclient, self.services["volume"],
@ -362,7 +350,6 @@ class TestResizeVolume(cloudstackTestCase):
account=self.parentd_admin.name, account=self.parentd_admin.name,
domainid=self.parent_domain.id, domainid=self.parent_domain.id,
diskofferingid=self.disk_offering_5_GB.id) diskofferingid=self.disk_offering_5_GB.id)
virtualMachine.attach_volume(apiclient, volume=volume) virtualMachine.attach_volume(apiclient, volume=volume)
expectedCount = (templateSize + self.disk_offering_5_GB.disksize) expectedCount = (templateSize + self.disk_offering_5_GB.disksize)

View File

@ -668,7 +668,8 @@ class TestRedundantRouterNetworkCleanups(cloudstackTestCase):
) )
return return
@attr(tags=["advanced", "advancedns"], required_hardware="false") # @attr(tags=["advanced", "advancedns"], required_hardware="false")
@attr(tags=["TODO"], required_hardware="false")
def test_restart_network_with_destroyed_primaryVR(self): def test_restart_network_with_destroyed_primaryVR(self):
"""Test restarting RvR network without cleanup after destroying primary VR """Test restarting RvR network without cleanup after destroying primary VR
""" """

View File

@ -568,7 +568,8 @@ class TestResizeVolume(cloudstackTestCase):
return return
@attr(tags=["advanced"], required_hardware="true") # @attr(tags=["advanced"], required_hardware="true")
@attr(tags=["TODO"], required_hardware="true")
def test_03_vmsnapshot__on_resized_rootvolume_vm(self): def test_03_vmsnapshot__on_resized_rootvolume_vm(self):
"""Test vmsnapshot on resized root volume """Test vmsnapshot on resized root volume
@ -936,7 +937,8 @@ class TestResizeVolume(cloudstackTestCase):
if rootvol is not None and 'kvm' or 'xenserver' in vm.hypervisor.lower(): if rootvol is not None and 'kvm' or 'xenserver' in vm.hypervisor.lower():
rootvol.resize(self.apiclient, size=newsize) rootvol.resize(self.apiclient, size=newsize)
@attr(tags=["advanced"], required_hrdware="true") # @attr(tags=["advanced"], required_hrdware="true")
@attr(tags=["TODO"], required_hrdware="true")
def test_7_usage_events_after_rootvolume_resized_(self): def test_7_usage_events_after_rootvolume_resized_(self):
"""Test check usage events after root volume resize """Test check usage events after root volume resize

View File

@ -3557,7 +3557,8 @@ class TestSharedNetworks(cloudstackTestCase):
self.fail(exceptionMessage) self.fail(exceptionMessage)
return return
@attr(tags=["advanced", "advancedns", "dvs"], required_hardware="false") # @attr(tags=["advanced", "advancedns", "dvs"], required_hardware="false")
@attr(tags=["TODO"], required_hardware="false")
def test_acquire_ip(self): def test_acquire_ip(self):
"""Test acquire IP in shared network """Test acquire IP in shared network

View File

@ -177,6 +177,8 @@ class TestSnapshots(cloudstackTestCase):
cls.api_client, cls.api_client,
cls.services["disk_offering"] cls.services["disk_offering"]
) )
cls._cleanup.append(cls.disk_offering)
cls.template = get_template( cls.template = get_template(
cls.api_client, cls.api_client,
cls.zone.id, cls.zone.id,
@ -198,21 +200,13 @@ class TestSnapshots(cloudstackTestCase):
cls.api_client, cls.api_client,
cls.services["service_offering"] cls.services["service_offering"]
) )
cls._cleanup.append(cls.service_offering)
cls._cleanup = [
cls.service_offering,
cls.disk_offering
]
return return
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestSnapshots, cls).tearDownClass()
# 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): def setUp(self):
self.apiclient = self.testClient.getApiClient() self.apiclient = self.testClient.getApiClient()
@ -220,9 +214,7 @@ class TestSnapshots(cloudstackTestCase):
self.cleanup = [] self.cleanup = []
if self.unsupportedHypervisor: if self.unsupportedHypervisor:
self.skipTest("Skipping test because unsupported hypervisor: %s" % self.skipTest("Skipping test because unsupported hypervisor: %s" % self.hypervisor)
self.hypervisor)
# Create VMs, NAT Rules etc # Create VMs, NAT Rules etc
self.account = Account.create( self.account = Account.create(
@ -245,12 +237,7 @@ class TestSnapshots(cloudstackTestCase):
return return
def tearDown(self): def tearDown(self):
try: super(TestSnapshots, self).tearDown()
# Clean up, terminate the created instance, volumes and snapshots
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@attr(speed="slow") @attr(speed="slow")
@attr(tags=["advanced", "advancedns", "smoke"], required_hardware="true") @attr(tags=["advanced", "advancedns", "smoke"], required_hardware="true")
@ -307,17 +294,17 @@ class TestSnapshots(cloudstackTestCase):
snapshot.id)) snapshot.id))
return return
@attr(speed="slow") # @attr(speed="slow")
@attr( # @attr(
tags=[ # tags=[
"advanced", # "advanced",
"advancedns", # "advancedns",
"basic", # "basic",
"sg"], # "sg"],
required_hardware="true") # required_hardware="true")
@attr(tags=["TODO"], required_hardware="true")
def test_01_volume_from_snapshot(self): def test_01_volume_from_snapshot(self):
"""Test Creating snapshot from volume having spaces in name(KVM) """Test Creating snapshot from volume having spaces in name(KVM)
"""
# Validate the following # Validate the following
# 1. Create a virtual machine and data volume # 1. Create a virtual machine and data volume
# 2. Attach data volume to VM # 2. Attach data volume to VM
@ -327,6 +314,7 @@ class TestSnapshots(cloudstackTestCase):
# 5. Create another Volume from snapshot # 5. Create another Volume from snapshot
# 6. Mount/Attach volume to another virtual machine # 6. Mount/Attach volume to another virtual machine
# 7. Compare data, data should match # 7. Compare data, data should match
"""
if self.hypervisor.lower() in ['hyperv']: if self.hypervisor.lower() in ['hyperv']:
self.skipTest("Snapshots feature is not supported on Hyper-V") self.skipTest("Snapshots feature is not supported on Hyper-V")
@ -334,7 +322,7 @@ class TestSnapshots(cloudstackTestCase):
random_data_0 = random_gen(size=100) random_data_0 = random_gen(size=100)
random_data_1 = random_gen(size=100) random_data_1 = random_gen(size=100)
self.debug("random_data_0 : %s" % random_data_0) self.debug("random_data_0: %s" % random_data_0)
self.debug("random_data_1: %s" % random_data_1) self.debug("random_data_1: %s" % random_data_1)
try: try:
@ -355,7 +343,7 @@ class TestSnapshots(cloudstackTestCase):
self.virtual_machine.attach_volume( self.virtual_machine.attach_volume(
self.apiclient, self.apiclient,
volume volume
) ) # volume should be cleanup with `self.virtual_machine`
self.debug("Attach volume: %s to VM: %s" % self.debug("Attach volume: %s to VM: %s" %
(volume.id, self.virtual_machine.id)) (volume.id, self.virtual_machine.id))
@ -483,7 +471,7 @@ class TestSnapshots(cloudstackTestCase):
mode=self.services["mode"] mode=self.services["mode"]
) )
self.debug("Deployed new VM for account: %s" % self.account.name) self.debug("Deployed new VM for account: %s" % self.account.name)
# self.cleanup.append(new_virtual_machine) self.cleanup.append(new_virtual_machine)
self.debug("Attaching volume: %s to VM: %s" % ( self.debug("Attaching volume: %s to VM: %s" % (
volume_from_snapshot.id, volume_from_snapshot.id,
@ -764,25 +752,24 @@ class TestSnapshots(cloudstackTestCase):
) )
return return
@attr(speed="slow") # @attr(speed="slow")
@attr( # @attr(
tags=[ # tags=[
"advanced", # "advanced",
"advancedns", # "advancedns",
"smoke", # "smoke",
"xen"], # "xen"],
required_hardware="true") # required_hardware="true")
@attr(tags=["TODO"], required_hardware="true")
def test_07_template_from_snapshot(self): def test_07_template_from_snapshot(self):
"""Create Template from snapshot """Create Template from snapshot
"""
# 1. Login to machine; create temp/test directories on data volume # 1. Login to machine; create temp/test directories on data volume
# 2. Snapshot the Volume # 2. Snapshot the Volume
# 3. Create Template from snapshot # 3. Create Template from snapshot
# 4. Deploy Virtual machine using this template # 4. Deploy Virtual machine using this template
# 5. Login to newly created virtual machine # 5. Login to newly created virtual machine
# 6. Compare data in the root disk with the one that was written on the # 6. Compare data in the root disk with the one that was written on the volume, it should match
# volume, it should match """
if self.hypervisor.lower() in ['hyperv']: if self.hypervisor.lower() in ['hyperv']:
self.skipTest("Snapshots feature is not supported on Hyper-V") self.skipTest("Snapshots feature is not supported on Hyper-V")
@ -865,6 +852,7 @@ class TestSnapshots(cloudstackTestCase):
account=self.account.name, account=self.account.name,
domainid=self.account.domainid domainid=self.account.domainid
) )
self.cleanup.append(snapshot)
self.debug("Snapshot created from volume ID: %s" % volume.id) self.debug("Snapshot created from volume ID: %s" % volume.id)
# Generate template from the snapshot # Generate template from the snapshot
@ -873,7 +861,6 @@ class TestSnapshots(cloudstackTestCase):
snapshot, snapshot,
self.services["templates"] self.services["templates"]
) )
self.cleanup.append(template)
self.debug("Template created from snapshot ID: %s" % snapshot.id) self.debug("Template created from snapshot ID: %s" % snapshot.id)
# Verify created template # Verify created template
@ -905,6 +892,7 @@ class TestSnapshots(cloudstackTestCase):
serviceofferingid=self.service_offering.id, serviceofferingid=self.service_offering.id,
mode=self.services["mode"] mode=self.services["mode"]
) )
self.cleanup.append(new_virtual_machine)
try: try:
# Login to VM & mount directory # Login to VM & mount directory
ssh = new_virtual_machine.get_ssh_client() ssh = new_virtual_machine.get_ssh_client()
@ -997,25 +985,19 @@ class TestCreateVMSnapshotTemplate(cloudstackTestCase):
cls.services["account"], cls.services["account"],
domainid=cls.domain.id domainid=cls.domain.id
) )
cls._cleanup.append(cls.account)
cls.service_offering = ServiceOffering.create( cls.service_offering = ServiceOffering.create(
cls.api_client, cls.api_client,
cls.services["service_offering"] cls.services["service_offering"]
) )
cls._cleanup = [ cls._cleanup.append(cls.service_offering)
cls.service_offering,
cls.account,
]
return return
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestCreateVMSnapshotTemplate, cls).tearDownClass()
# 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): def setUp(self):
self.apiclient = self.testClient.getApiClient() self.apiclient = self.testClient.getApiClient()
@ -1027,12 +1009,7 @@ class TestCreateVMSnapshotTemplate(cloudstackTestCase):
return return
def tearDown(self): def tearDown(self):
try: super(TestCreateVMSnapshotTemplate, self).tearDown()
# Clean up, terminate the created instance, volumes and snapshots
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@attr(speed="slow") @attr(speed="slow")
@attr(tags=["advanced", "advancedns"], required_hardware="true") @attr(tags=["advanced", "advancedns"], required_hardware="true")
@ -1072,8 +1049,9 @@ class TestCreateVMSnapshotTemplate(cloudstackTestCase):
domainid=self.account.domainid, domainid=self.account.domainid,
serviceofferingid=self.service_offering.id serviceofferingid=self.service_offering.id
) )
self.cleanup.append(self.virtual_machine)
self.debug("Created VM with ID: %s" % self.virtual_machine.id) self.debug("Created VM with ID: %s" % self.virtual_machine.id)
# Get the Root disk of VM
volumes = list_volumes( volumes = list_volumes(
userapiclient, userapiclient,
virtualmachineid=self.virtual_machine.id, virtualmachineid=self.virtual_machine.id,
@ -1117,8 +1095,8 @@ class TestCreateVMSnapshotTemplate(cloudstackTestCase):
snapshot, snapshot,
self.services["templates"] self.services["templates"]
) )
self.debug("Created template from snapshot: %s" % template.id)
self.cleanup.append(template) self.cleanup.append(template)
self.debug("Created template from snapshot: %s" % template.id)
templates = list_templates( templates = list_templates(
userapiclient, userapiclient,
@ -1147,11 +1125,11 @@ class TestCreateVMSnapshotTemplate(cloudstackTestCase):
domainid=self.account.domainid, domainid=self.account.domainid,
serviceofferingid=self.service_offering.id serviceofferingid=self.service_offering.id
) )
self.cleanup.append(new_virtual_machine)
self.debug("Created VM with ID: %s from template: %s" % ( self.debug("Created VM with ID: %s from template: %s" % (
new_virtual_machine.id, new_virtual_machine.id,
template.id template.id
)) ))
self.cleanup.append(new_virtual_machine)
# Newly deployed VM should be 'Running' # Newly deployed VM should be 'Running'
virtual_machines = list_virtual_machines( virtual_machines = list_virtual_machines(
@ -1219,6 +1197,7 @@ class TestSnapshotEvents(cloudstackTestCase):
cls.services["account"], cls.services["account"],
domainid=cls.domain.id domainid=cls.domain.id
) )
cls._cleanup.append(cls.account)
cls.services["account"] = cls.account.name cls.services["account"] = cls.account.name
@ -1226,6 +1205,8 @@ class TestSnapshotEvents(cloudstackTestCase):
cls.api_client, cls.api_client,
cls.services["service_offering"] cls.services["service_offering"]
) )
cls._cleanup.append(cls.service_offering)
cls.virtual_machine = VirtualMachine.create( cls.virtual_machine = VirtualMachine.create(
cls.api_client, cls.api_client,
cls.services["server"], cls.services["server"],
@ -1234,21 +1215,13 @@ class TestSnapshotEvents(cloudstackTestCase):
domainid=cls.account.domainid, domainid=cls.account.domainid,
serviceofferingid=cls.service_offering.id serviceofferingid=cls.service_offering.id
) )
cls._cleanup.append(cls.virtual_machine)
cls._cleanup = [
cls.service_offering,
cls.account,
]
return return
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestSnapshotEvents, cls).tearDownClass()
# 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): def setUp(self):
self.apiclient = self.testClient.getApiClient() self.apiclient = self.testClient.getApiClient()
@ -1260,12 +1233,7 @@ class TestSnapshotEvents(cloudstackTestCase):
return return
def tearDown(self): def tearDown(self):
try: super(TestSnapshotEvents, self).tearDown()
# Clean up, terminate the created instance, volumes and snapshots
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@attr(speed="slow") @attr(speed="slow")
@attr(tags=["advanced", "advancedns"], required_hardware="false") @attr(tags=["advanced", "advancedns"], required_hardware="false")

View File

@ -15,13 +15,14 @@
# specific language governing permissions and limitations # specific language governing permissions and limitations
# under the License. # under the License.
""" P1 tests for secondary storage domain limits """
P1 tests for secondary storage domain limits
Test Plan: https://cwiki.apache.org/confluence/display/CLOUDSTACK/Limit+Resources+to+domain+or+accounts Test Plan: https://cwiki.apache.org/confluence/display/CLOUDSTACK/Limit+Resources+to+domain+or+accounts
Issue Link: https://issues.apache.org/jira/browse/CLOUDSTACK-1466 Issue Link: https://issues.apache.org/jira/browse/CLOUDSTACK-1466
Feature Specifications: https://cwiki.apache.org/confluence/display/CLOUDSTACK/Limit+Resources+to+domains+and+accounts Feature Specifications: https://cwiki.apache.org/confluence/display/CLOUDSTACK/Limit+Resources+to+domains+and+accounts
""" """
# Import Local Modules # Import Local Modules
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
@ -41,16 +42,15 @@ from marvin.codes import (PASS,
FAIL, FAIL,
RESOURCE_SECONDARY_STORAGE) RESOURCE_SECONDARY_STORAGE)
class TestMultipleChildDomain(cloudstackTestCase): class TestMultipleChildDomain(cloudstackTestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
cloudstackTestClient = super(TestMultipleChildDomain, cloudstackTestClient = super(TestMultipleChildDomain,
cls).getClsTestClient() cls).getClsTestClient()
cls.api_client = cloudstackTestClient.getApiClient() cls.api_client = cloudstackTestClient.getApiClient()
# Fill services from the external config file
cls.services = cloudstackTestClient.getParsedTestDataConfig() cls.services = cloudstackTestClient.getParsedTestDataConfig()
# Get Zone, Domain and templates
cls.domain = get_domain(cls.api_client) cls.domain = get_domain(cls.api_client)
cls.zone = get_zone(cls.api_client, cloudstackTestClient.getZoneForTests()) cls.zone = get_zone(cls.api_client, cloudstackTestClient.getZoneForTests())
cls.services["mode"] = cls.zone.networktype cls.services["mode"] = cls.zone.networktype
@ -66,12 +66,7 @@ class TestMultipleChildDomain(cloudstackTestCase):
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestMultipleChildDomain,cls).tearDownClass()
# 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): def setUp(self):
self.apiclient = self.testClient.getApiClient() self.apiclient = self.testClient.getApiClient()
@ -80,32 +75,24 @@ class TestMultipleChildDomain(cloudstackTestCase):
return return
def tearDown(self): def tearDown(self):
try: super(TestMultipleChildDomain,self).tearDown()
# Clean up, terminate the created instance, volumes and snapshots
cleanup_resources(self.apiclient, self.cleanup)
pass
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
def updateDomainResourceLimits(self, parentdomainlimit, subdomainlimit): def updateDomainResourceLimits(self, parentdomainlimit, subdomainlimit):
"""Update secondary storage limits of the parent domain and its """Update secondary storage limits of the parent domain and its
child domains""" child domains"""
try: try:
#Update resource limit for domain
Resources.updateLimit(self.apiclient, resourcetype=11, Resources.updateLimit(self.apiclient, resourcetype=11,
max=parentdomainlimit, max=parentdomainlimit,
domainid=self.parent_domain.id) domainid=self.parent_domain.id)
# Update Resource limit for sub-domains
Resources.updateLimit(self.apiclient, resourcetype=11,
max=subdomainlimit,
domainid=self.cadmin_1.domainid)
Resources.updateLimit(self.apiclient, resourcetype=11, Resources.updateLimit(self.apiclient, resourcetype=11,
max=subdomainlimit, max=subdomainlimit,
domainid=self.cadmin_2.domainid) domainid=self.cadmin_1.domainid)
Resources.updateLimit(self.apiclient, resourcetype=11,
max=subdomainlimit,
domainid=self.cadmin_2.domainid)
except Exception as e: except Exception as e:
return [FAIL, e] return [FAIL, e]
return [PASS, None] return [PASS, None]
@ -113,32 +100,30 @@ class TestMultipleChildDomain(cloudstackTestCase):
def setupAccounts(self): def setupAccounts(self):
try: try:
self.parent_domain = Domain.create(self.apiclient, self.parent_domain = Domain.create(self.apiclient,
services=self.services["domain"], services=self.services["domain"],
parentdomainid=self.domain.id) parentdomainid=self.domain.id)
self.cleanup.append(self.parent_domain)
self.parentd_admin = Account.create(self.apiclient, self.services["account"], self.parentd_admin = Account.create(self.apiclient, self.services["account"],
admin=True, domainid=self.parent_domain.id) admin=True, domainid=self.parent_domain.id)
self.cleanup.append(self.parentd_admin)
# Create sub-domains and their admin accounts # Create sub-domains and their admin accounts
self.cdomain_1 = Domain.create(self.apiclient, self.cdomain_1 = Domain.create(self.apiclient,
services=self.services["domain"], services=self.services["domain"],
parentdomainid=self.parent_domain.id) parentdomainid=self.parent_domain.id)
self.cleanup.append(self.cdomain_1)
self.cdomain_2 = Domain.create(self.apiclient, self.cdomain_2 = Domain.create(self.apiclient,
services=self.services["domain"], services=self.services["domain"],
parentdomainid=self.parent_domain.id) parentdomainid=self.parent_domain.id)
self.cleanup.append(self.cdomain_2)
self.cadmin_1 = Account.create(self.apiclient, self.services["account"], self.cadmin_1 = Account.create(self.apiclient, self.services["account"],
admin=True, domainid=self.cdomain_1.id) admin=True, domainid=self.cdomain_1.id)
self.cleanup.append(self.cadmin_1)
self.cadmin_2 = Account.create(self.apiclient, self.services["account"], self.cadmin_2 = Account.create(self.apiclient, self.services["account"],
admin=True, domainid=self.cdomain_2.id) admin=True, domainid=self.cdomain_2.id)
# Cleanup the resources created at end of test
self.cleanup.append(self.cadmin_1)
self.cleanup.append(self.cadmin_2) self.cleanup.append(self.cadmin_2)
self.cleanup.append(self.cdomain_1)
self.cleanup.append(self.cdomain_2)
self.cleanup.append(self.parentd_admin)
self.cleanup.append(self.parent_domain)
users = { users = {
self.cdomain_1: self.cadmin_1, self.cdomain_1: self.cadmin_1,
@ -184,18 +169,18 @@ class TestMultipleChildDomain(cloudstackTestCase):
self.services["template_2"]["url"] = builtin_info[0] self.services["template_2"]["url"] = builtin_info[0]
self.services["template_2"]["hypervisor"] = builtin_info[1] self.services["template_2"]["hypervisor"] = builtin_info[1]
self.services["template_2"]["format"] = builtin_info[2] self.services["template_2"]["format"] = builtin_info[2]
self.services["template_2"]["ispublic"] = False
templateChildAccount1 = Template.register(self.apiclient, templateChildAccount1 = Template.register(self.apiclient,
self.services["template_2"], self.services["template_2"],
zoneid=self.zone.id, zoneid=self.zone.id,
account=self.cadmin_1.name, account=self.cadmin_1.name,
domainid=self.cadmin_1.domainid) domainid=self.cadmin_1.domainid)
templateChildAccount1.download(self.apiclient) templateChildAccount1.download(self.apiclient)
templates = Template.list(self.apiclient, templates = Template.list(self.apiclient,
templatefilter=\ templatefilter=self.services["template_2"]["templatefilter"],
self.services["template_2"]["templatefilter"],
id=templateChildAccount1.id) id=templateChildAccount1.id)
if validateList(templates)[0] == FAIL: if validateList(templates)[0] == FAIL:
raise Exception("templates list validation failed") raise Exception("templates list validation failed")
@ -218,10 +203,10 @@ class TestMultipleChildDomain(cloudstackTestCase):
try: try:
templateChildAccount2 = Template.register(self.apiclient, templateChildAccount2 = Template.register(self.apiclient,
self.services["template_2"], self.services["template_2"],
zoneid=self.zone.id, zoneid=self.zone.id,
account=self.cadmin_2.name, account=self.cadmin_2.name,
domainid=self.cadmin_2.domainid) domainid=self.cadmin_2.domainid)
templateChildAccount2.download(self.apiclient) templateChildAccount2.download(self.apiclient)
except Exception as e: except Exception as e:
@ -235,10 +220,10 @@ class TestMultipleChildDomain(cloudstackTestCase):
with self.assertRaises(Exception): with self.assertRaises(Exception):
Template.register(self.apiclient, Template.register(self.apiclient,
self.services["template_2"], self.services["template_2"],
zoneid=self.zone.id, zoneid=self.zone.id,
account=self.parentd_admin.name, account=self.parentd_admin.name,
domainid=self.parentd_admin.domainid) domainid=self.parentd_admin.domainid)
self.cadmin_1.delete(self.apiclient) self.cadmin_1.delete(self.apiclient)
self.cleanup.remove(self.cadmin_1) self.cleanup.remove(self.cadmin_1)
@ -289,19 +274,19 @@ class TestMultipleChildDomain(cloudstackTestCase):
self.services["template_2"]["url"] = builtin_info[0] self.services["template_2"]["url"] = builtin_info[0]
self.services["template_2"]["hypervisor"] = builtin_info[1] self.services["template_2"]["hypervisor"] = builtin_info[1]
self.services["template_2"]["format"] = builtin_info[2] self.services["template_2"]["format"] = builtin_info[2]
self.services["template_2"]["ispublic"] = False
template = Template.register(self.apiclient, template = Template.register(self.apiclient,
self.services["template_2"], self.services["template_2"],
zoneid=self.zone.id, zoneid=self.zone.id,
account=self.account.name, account=self.account.name,
domainid=self.account.domainid) domainid=self.account.domainid)
template.download(self.apiclient) template.download(self.apiclient)
templates = Template.list(self.apiclient, templates = Template.list(self.apiclient,
templatefilter=\ templatefilter=self.services["template_2"]["templatefilter"],
self.services["template_2"]["templatefilter"], id=template.id)
id=template.id)
if validateList(templates)[0] == FAIL: if validateList(templates)[0] == FAIL:
raise Exception("templates list validation failed") raise Exception("templates list validation failed")
@ -323,7 +308,7 @@ class TestMultipleChildDomain(cloudstackTestCase):
self.assertTrue(result[2], "Resource count does not match") self.assertTrue(result[2], "Resource count does not match")
except Exception as e: except Exception as e:
self.fail("Failed to get zone list: %s" % e) self.fail("Failed to get zone list: %s" % e)
return return
@attr(tags=["advanced"], required_hardware="true") @attr(tags=["advanced"], required_hardware="true")
def test_03_copy_template(self): def test_03_copy_template(self):
@ -360,19 +345,19 @@ class TestMultipleChildDomain(cloudstackTestCase):
self.services["template_2"]["url"] = builtin_info[0] self.services["template_2"]["url"] = builtin_info[0]
self.services["template_2"]["hypervisor"] = builtin_info[1] self.services["template_2"]["hypervisor"] = builtin_info[1]
self.services["template_2"]["format"] = builtin_info[2] self.services["template_2"]["format"] = builtin_info[2]
self.services["template_2"]["ispublic"] = False
template = Template.register(self.apiclient, template = Template.register(self.apiclient,
self.services["template_2"], self.services["template_2"],
zoneid=self.zone.id, zoneid=self.zone.id,
account=self.account.name, account=self.account.name,
domainid=self.account.domainid) domainid=self.account.domainid)
template.download(self.apiclient) template.download(self.apiclient)
templates = Template.list(self.apiclient, templates = Template.list(self.apiclient,
templatefilter=\ templatefilter=self.services["template_2"]["templatefilter"],
self.services["template_2"]["templatefilter"], id=template.id)
id=template.id)
if validateList(templates)[0] == FAIL: if validateList(templates)[0] == FAIL:
raise Exception("templates list validation failed") raise Exception("templates list validation failed")
@ -386,12 +371,12 @@ class TestMultipleChildDomain(cloudstackTestCase):
templateDestinationZoneId = None templateDestinationZoneId = None
for zone in zones: for zone in zones:
if template.zoneid != zone.id : if template.zoneid != zone.id:
templateDestinationZoneId = zone.id templateDestinationZoneId = zone.id
break break
template.copy(self.apiclient, destzoneid=templateDestinationZoneId, template.copy(self.apiclient, destzoneid=templateDestinationZoneId,
sourcezoneid = template.zoneid) sourcezoneid=template.zoneid)
expectedCount *= 2 expectedCount *= 2
result = isDomainResourceCountEqualToExpectedCount( result = isDomainResourceCountEqualToExpectedCount(
@ -400,15 +385,16 @@ class TestMultipleChildDomain(cloudstackTestCase):
self.assertFalse(result[0], result[1]) self.assertFalse(result[0], result[1])
self.assertTrue(result[2], "Resource count does not match") self.assertTrue(result[2], "Resource count does not match")
except Exception as e: except Exception as e:
self.fail("Failed to get zone list: %s" % e) self.fail("Failed to copy template cross zones: %s" % e)
return return
class TestDeleteAccount(cloudstackTestCase): class TestDeleteAccount(cloudstackTestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
cloudstackTestClient = super(TestDeleteAccount, cloudstackTestClient = super(TestDeleteAccount,
cls).getClsTestClient() cls).getClsTestClient()
cls.api_client = cloudstackTestClient.getApiClient() cls.api_client = cloudstackTestClient.getApiClient()
# Fill services from the external config file # Fill services from the external config file
cls.services = cloudstackTestClient.getParsedTestDataConfig() cls.services = cloudstackTestClient.getParsedTestDataConfig()
@ -426,12 +412,7 @@ class TestDeleteAccount(cloudstackTestCase):
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestDeleteAccount,cls).tearDownClass()
# 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): def setUp(self):
self.apiclient = self.testClient.getApiClient() self.apiclient = self.testClient.getApiClient()
@ -440,42 +421,34 @@ class TestDeleteAccount(cloudstackTestCase):
return return
def tearDown(self): def tearDown(self):
try: super(TestDeleteAccount,self).tearDown()
# Clean up, terminate the created instance, volumes and snapshots
cleanup_resources(self.apiclient, self.cleanup)
pass
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
def setupAccounts(self): def setupAccounts(self):
try: try:
self.parent_domain = Domain.create(self.apiclient, self.parent_domain = Domain.create(self.apiclient,
services=self.services["domain"], services=self.services["domain"],
parentdomainid=self.domain.id) parentdomainid=self.domain.id)
self.cleanup.append(self.parent_domain)
self.parentd_admin = Account.create(self.apiclient, self.services["account"], self.parentd_admin = Account.create(self.apiclient, self.services["account"],
admin=True, domainid=self.parent_domain.id) admin=True, domainid=self.parent_domain.id)
self.cleanup.append(self.parentd_admin)
# Create sub-domains and their admin accounts
self.cdomain_1 = Domain.create(self.apiclient, self.cdomain_1 = Domain.create(self.apiclient,
services=self.services["domain"], services=self.services["domain"],
parentdomainid=self.parent_domain.id) parentdomainid=self.parent_domain.id)
self.cleanup.append(self.cdomain_1)
self.cdomain_2 = Domain.create(self.apiclient, self.cdomain_2 = Domain.create(self.apiclient,
services=self.services["domain"], services=self.services["domain"],
parentdomainid=self.parent_domain.id) parentdomainid=self.parent_domain.id)
self.cleanup.append(self.cdomain_2)
self.cadmin_1 = Account.create(self.apiclient, self.services["account"], self.cadmin_1 = Account.create(self.apiclient, self.services["account"],
admin=True, domainid=self.cdomain_1.id) admin=True, domainid=self.cdomain_1.id)
self.cleanup.append(self.cadmin_1)
self.cadmin_2 = Account.create(self.apiclient, self.services["account"], self.cadmin_2 = Account.create(self.apiclient, self.services["account"],
admin=True, domainid=self.cdomain_2.id) admin=True, domainid=self.cdomain_2.id)
# Cleanup the resources created at end of test
self.cleanup.append(self.cadmin_2) self.cleanup.append(self.cadmin_2)
self.cleanup.append(self.cdomain_1)
self.cleanup.append(self.cdomain_2)
self.cleanup.append(self.parentd_admin)
self.cleanup.append(self.parent_domain)
users = { users = {
self.cdomain_1: self.cadmin_1, self.cdomain_1: self.cadmin_1,
@ -514,18 +487,18 @@ class TestDeleteAccount(cloudstackTestCase):
self.services["template_2"]["url"] = builtin_info[0] self.services["template_2"]["url"] = builtin_info[0]
self.services["template_2"]["hypervisor"] = builtin_info[1] self.services["template_2"]["hypervisor"] = builtin_info[1]
self.services["template_2"]["format"] = builtin_info[2] self.services["template_2"]["format"] = builtin_info[2]
self.services["template_2"]["ispublic"] = False
template = Template.register(self.apiclient, template = Template.register(self.apiclient,
self.services["template_2"], self.services["template_2"],
zoneid=self.zone.id, zoneid=self.zone.id,
account=self.cadmin_1.name, account=self.cadmin_1.name,
domainid=self.cadmin_1.domainid) domainid=self.cadmin_1.domainid)
template.download(self.apiclient) template.download(self.apiclient)
templates = Template.list(self.apiclient, templates = Template.list(self.apiclient,
templatefilter=\ templatefilter=self.services["template_2"]["templatefilter"],
self.services["template_2"]["templatefilter"],
id=template.id) id=template.id)
if validateList(templates)[0] == FAIL: if validateList(templates)[0] == FAIL:
raise Exception("templates list validation failed") raise Exception("templates list validation failed")
@ -544,10 +517,10 @@ class TestDeleteAccount(cloudstackTestCase):
try: try:
template = Template.register(self.apiclient, template = Template.register(self.apiclient,
self.services["template_2"], self.services["template_2"],
zoneid=self.zone.id, zoneid=self.zone.id,
account=self.cadmin_2.name, account=self.cadmin_2.name,
domainid=self.cadmin_2.domainid) domainid=self.cadmin_2.domainid)
template.download(self.apiclient) template.download(self.apiclient)
except Exception as e: except Exception as e:
@ -570,6 +543,7 @@ class TestDeleteAccount(cloudstackTestCase):
try: try:
self.cadmin_1.delete(self.apiclient) self.cadmin_1.delete(self.apiclient)
self.cleanup.remove(self.cadmin_1)
except Exception as e: except Exception as e:
self.fail("Failed to delete account: %s" % e) self.fail("Failed to delete account: %s" % e)

View File

@ -129,8 +129,9 @@ class TestSecondaryStorageLimits(cloudstackTestCase):
return [FAIL, e] return [FAIL, e]
return [PASS, None] return [PASS, None]
# tags = ["advanced"]
@data(ROOT_DOMAIN_ADMIN, CHILD_DOMAIN_ADMIN) @data(ROOT_DOMAIN_ADMIN, CHILD_DOMAIN_ADMIN)
@attr(tags = ["advanced"], required_hardware="true") @attr(tags = ["TODO"], required_hardware="true")
def test_01_register_template(self, value): def test_01_register_template(self, value):
"""Test register template """Test register template
# Validate the following: # Validate the following:
@ -195,8 +196,9 @@ class TestSecondaryStorageLimits(cloudstackTestCase):
self.assertEqual(response[0], PASS, response[1]) self.assertEqual(response[0], PASS, response[1])
return return
# tags = ["advanced"]
@data(ROOT_DOMAIN_ADMIN, CHILD_DOMAIN_ADMIN) @data(ROOT_DOMAIN_ADMIN, CHILD_DOMAIN_ADMIN)
@attr(tags=["advanced"], required_hardware="true") @attr(tags=["TODO"], required_hardware="true")
def test_02_create_template_snapshot(self, value): def test_02_create_template_snapshot(self, value):
"""Test create snapshot and templates from volume """Test create snapshot and templates from volume
@ -262,8 +264,9 @@ class TestSecondaryStorageLimits(cloudstackTestCase):
self.assertEqual(response[0], PASS, response[1]) self.assertEqual(response[0], PASS, response[1])
return return
# tags = ["advanced"]
@data(ROOT_DOMAIN_ADMIN, CHILD_DOMAIN_ADMIN) @data(ROOT_DOMAIN_ADMIN, CHILD_DOMAIN_ADMIN)
@attr(tags = ["advanced"], required_hardware="true") @attr(tags = ["TODO"], required_hardware="true")
def test_03_register_iso(self, value): def test_03_register_iso(self, value):
"""Test register iso """Test register iso
Steps and validations: Steps and validations:

View File

@ -54,6 +54,7 @@ class TestMaxSecondaryStorageLimits(cloudstackTestCase):
cls.domain = get_domain(cls.api_client) cls.domain = get_domain(cls.api_client)
cls.zone = get_zone(cls.api_client, cloudstackTestClient.getZoneForTests()) cls.zone = get_zone(cls.api_client, cloudstackTestClient.getZoneForTests())
cls.services["mode"] = cls.zone.networktype cls.services["mode"] = cls.zone.networktype
cls._cleanup = []
cls.template = get_template( cls.template = get_template(
cls.api_client, cls.api_client,
@ -65,17 +66,12 @@ class TestMaxSecondaryStorageLimits(cloudstackTestCase):
cls.services["virtual_machine"]["template"] = cls.template.id cls.services["virtual_machine"]["template"] = cls.template.id
cls.services["volume"]["zoneid"] = cls.zone.id cls.services["volume"]["zoneid"] = cls.zone.id
cls.service_offering = ServiceOffering.create(cls.api_client, cls.services["service_offering"]) cls.service_offering = ServiceOffering.create(cls.api_client, cls.services["service_offering"])
cls._cleanup = [cls.service_offering] cls._cleanup.append(cls.service_offering)
return return
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestMaxSecondaryStorageLimits, cls).tearDownClass()
# 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): def setUp(self):
self.apiclient = self.testClient.getApiClient() self.apiclient = self.testClient.getApiClient()
@ -84,12 +80,7 @@ class TestMaxSecondaryStorageLimits(cloudstackTestCase):
return return
def tearDown(self): def tearDown(self):
try: super(TestMaxSecondaryStorageLimits, self).tearDown()
# Clean up, terminate the created instance, volumes and snapshots
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
def registerTemplate(self, inProject=False): def registerTemplate(self, inProject=False):
"""Register and download template by default in the account/domain, """Register and download template by default in the account/domain,
@ -107,6 +98,7 @@ class TestMaxSecondaryStorageLimits(cloudstackTestCase):
account=self.child_do_admin.name if not inProject else None, account=self.child_do_admin.name if not inProject else None,
domainid=self.child_do_admin.domainid if not inProject else None, domainid=self.child_do_admin.domainid if not inProject else None,
projectid=self.project.id if inProject else None) projectid=self.project.id if inProject else None)
self.cleanup.append(template)
template.download(self.apiclient) template.download(self.apiclient)
@ -127,9 +119,11 @@ class TestMaxSecondaryStorageLimits(cloudstackTestCase):
try: try:
self.child_domain = Domain.create(self.apiclient,services=self.services["domain"], self.child_domain = Domain.create(self.apiclient,services=self.services["domain"],
parentdomainid=self.domain.id) parentdomainid=self.domain.id)
self.cleanup.append(self.child_domain)
self.child_do_admin = Account.create(self.apiclient, self.services["account"], admin=True, self.child_do_admin = Account.create(self.apiclient, self.services["account"], admin=True,
domainid=self.child_domain.id) domainid=self.child_domain.id)
self.cleanup.append(self.child_do_admin)
self.userapiclient = self.testClient.getUserApiClient( self.userapiclient = self.testClient.getUserApiClient(
UserName=self.child_do_admin.name, UserName=self.child_do_admin.name,
@ -139,13 +133,8 @@ class TestMaxSecondaryStorageLimits(cloudstackTestCase):
self.project = Project.create(self.apiclient, self.services["project"], self.project = Project.create(self.apiclient, self.services["project"],
account=self.child_do_admin.name, account=self.child_do_admin.name,
domainid=self.child_do_admin.domainid) domainid=self.child_do_admin.domainid)
# Cleanup created project at end of test
self.cleanup.append(self.project) self.cleanup.append(self.project)
# Cleanup accounts created
self.cleanup.append(self.child_do_admin)
self.cleanup.append(self.child_domain)
except Exception as e: except Exception as e:
return [FAIL, e] return [FAIL, e]
return [PASS, None] return [PASS, None]
@ -156,16 +145,16 @@ class TestMaxSecondaryStorageLimits(cloudstackTestCase):
# Update resource limits for account # Update resource limits for account
if accountLimit is not None: if accountLimit is not None:
Resources.updateLimit(self.apiclient, resourcetype=11, Resources.updateLimit(self.apiclient, resourcetype=11,
max=accountLimit, account=self.child_do_admin.name, max=int(accountLimit), account=self.child_do_admin.name,
domainid=self.child_do_admin.domainid) domainid=self.child_do_admin.domainid)
if projectLimit is not None: if projectLimit is not None:
Resources.updateLimit(self.apiclient, resourcetype=11, Resources.updateLimit(self.apiclient, resourcetype=11,
max=projectLimit, projectid=self.project.id) max=int(projectLimit), projectid=self.project.id)
if domainLimit is not None: if domainLimit is not None:
Resources.updateLimit(self.apiclient, resourcetype=11, Resources.updateLimit(self.apiclient, resourcetype=11,
max=domainLimit, domainid=self.child_domain.id) max=int(domainLimit), domainid=self.child_domain.id)
except Exception as e: except Exception as e:
return [FAIL, e] return [FAIL, e]
return [PASS, None] return [PASS, None]

View File

@ -505,14 +505,15 @@ class TestDeployVM(cloudstackTestCase):
) )
return return
@attr( # @attr(
tags=[ # tags=[
"advanced", # "advanced",
"eip", # "eip",
"advancedns", # "advancedns",
"basic", # "basic",
"sg"], # "sg"],
required_hardware="false") # required_hardware="false")
@attr(tags=["TODO"], required_hardware="false")
def test_08_deploy_attached_volume(self): def test_08_deploy_attached_volume(self):
"""Test Deploy Virtual Machine with startVM=false and attach volume """Test Deploy Virtual Machine with startVM=false and attach volume
already attached to different machine already attached to different machine
@ -1166,28 +1167,24 @@ class TestDeployVMBasicZone(cloudstackTestCase):
cls.testdata["ostype"] cls.testdata["ostype"]
) )
cls._cleanup = []
# Create service offerings, disk offerings etc # Create service offerings, disk offerings etc
cls.service_offering = ServiceOffering.create( cls.service_offering = ServiceOffering.create(
cls.api_client, cls.api_client,
cls.testdata["service_offering"] cls.testdata["service_offering"]
) )
cls._cleanup.append(cls.service_offering)
cls.disk_offering = DiskOffering.create( cls.disk_offering = DiskOffering.create(
cls.api_client, cls.api_client,
cls.testdata["disk_offering"] cls.testdata["disk_offering"]
) )
# Cleanup # Cleanup
cls._cleanup = [ cls._cleanup.append(cls.disk_offering)
cls.service_offering,
cls.disk_offering,
]
return return
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestDeployVMBasicZone, cls).tearDownClass()
cleanup_resources(cls.api_client, cls._cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
def setUp(self): def setUp(self):
@ -1208,13 +1205,11 @@ class TestDeployVMBasicZone(cloudstackTestCase):
return return
def tearDown(self): def tearDown(self):
try: super(TestDeployVMBasicZone, self).tearDown()
self.debug("Cleaning up the resources")
cleanup_resources(self.apiclient, self.cleanup)
self.debug("Cleanup complete!")
except Exception as e:
self.debug("Warning! Exception in tearDown: %s" % e)
@attr(tags=["TODO"], required_hardware="false")
def test_01(self):
pass
class TestDeployVMFromTemplate(cloudstackTestCase): class TestDeployVMFromTemplate(cloudstackTestCase):

View File

@ -76,6 +76,7 @@ class TestVolumeDestroyRecover(cloudstackTestCase):
admin=True, admin=True,
domainid=cls.domain.id domainid=cls.domain.id
) )
cls._cleanup.append(cls.account);
accounts = Account.list(cls.apiclient, id=cls.account.id) accounts = Account.list(cls.apiclient, id=cls.account.id)
cls.expectedCount = int(accounts[0].primarystoragetotal) cls.expectedCount = int(accounts[0].primarystoragetotal)
cls.volumeTotal = int(accounts[0].volumetotal) cls.volumeTotal = int(accounts[0].volumetotal)
@ -88,6 +89,7 @@ class TestVolumeDestroyRecover(cloudstackTestCase):
cls.apiclient, cls.apiclient,
cls.services["shared_network_offering"] cls.services["shared_network_offering"]
) )
cls._cleanup.append(cls.network_offering)
cls.network_offering.update(cls.apiclient, state='Enabled') cls.network_offering.update(cls.apiclient, state='Enabled')
cls.account_network = Network.create( cls.account_network = Network.create(
@ -98,11 +100,13 @@ class TestVolumeDestroyRecover(cloudstackTestCase):
accountid=cls.account.name, accountid=cls.account.name,
domainid=cls.account.domainid domainid=cls.account.domainid
) )
cls._cleanup.append(cls.account_network)
else: else:
cls.network_offering = NetworkOffering.create( cls.network_offering = NetworkOffering.create(
cls.apiclient, cls.apiclient,
cls.services["isolated_network_offering"], cls.services["isolated_network_offering"],
) )
cls._cleanup.append(cls.network_offering)
# Enable Network offering # Enable Network offering
cls.network_offering.update(cls.apiclient, state='Enabled') cls.network_offering.update(cls.apiclient, state='Enabled')
@ -115,31 +119,25 @@ class TestVolumeDestroyRecover(cloudstackTestCase):
cls.account.name, cls.account.name,
cls.account.domainid cls.account.domainid
) )
cls._cleanup.append(cls.account_network)
# Create small service offering # Create small service offering
cls.service_offering = ServiceOffering.create( cls.service_offering = ServiceOffering.create(
cls.apiclient, cls.apiclient,
cls.services["service_offerings"]["small"] cls.services["service_offerings"]["small"]
) )
cls._cleanup.append(cls.service_offering)
# Create disk offering # Create disk offering
cls.disk_offering = DiskOffering.create( cls.disk_offering = DiskOffering.create(
cls.apiclient, cls.apiclient,
cls.services["disk_offering"], cls.services["disk_offering"],
) )
cls._cleanup.append(cls.disk_offering) cls._cleanup.append(cls.disk_offering)
cls._cleanup.append(cls.service_offering)
cls._cleanup.append(cls.account);
cls._cleanup.append(cls.network_offering)
@classmethod @classmethod
def tearDownClass(self): def tearDownClass(cls):
try: super(TestVolumeDestroyRecover, cls).tearDownClass()
cleanup_resources(self.apiclient, self._cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
def setUp(self): def setUp(self):
self.apiclient = self.testClient.getApiClient() self.apiclient = self.testClient.getApiClient()
@ -147,11 +145,7 @@ class TestVolumeDestroyRecover(cloudstackTestCase):
return return
def tearDown(self): def tearDown(self):
try: super(TestVolumeDestroyRecover, self).tearDown()
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
def verify_resource_count_primary_storage(self, expectedCount, volumeTotal): def verify_resource_count_primary_storage(self, expectedCount, volumeTotal):
response = matchResourceCount( response = matchResourceCount(
@ -200,6 +194,7 @@ class TestVolumeDestroyRecover(cloudstackTestCase):
templateid=self.template.id, templateid=self.template.id,
zoneid=self.zone.id zoneid=self.zone.id
) )
self.cleanup.append(virtual_machine_1)
except Exception as e: except Exception as e:
self.fail("Exception while deploying virtual machine: %s" % e) self.fail("Exception while deploying virtual machine: %s" % e)
@ -229,6 +224,7 @@ class TestVolumeDestroyRecover(cloudstackTestCase):
# destroy vm # destroy vm
virtual_machine_1.delete(self.apiclient, expunge=False) virtual_machine_1.delete(self.apiclient, expunge=False)
self.cleanup.remove(virtual_machine_1)
self.verify_resource_count_primary_storage(self.expectedCount, self.volumeTotal) self.verify_resource_count_primary_storage(self.expectedCount, self.volumeTotal)
# expunge vm # expunge vm
@ -261,6 +257,7 @@ class TestVolumeDestroyRecover(cloudstackTestCase):
zoneid=self.zone.id, account=self.account.name, zoneid=self.zone.id, account=self.account.name,
domainid=self.account.domainid, diskofferingid=self.disk_offering.id domainid=self.account.domainid, diskofferingid=self.disk_offering.id
) )
self.cleanup.append(volume)
self.expectedCount = self.expectedCount + self.disk_offering.disksize self.expectedCount = self.expectedCount + self.disk_offering.disksize
self.volumeTotal = self.volumeTotal + 1 self.volumeTotal = self.volumeTotal + 1
self.verify_resource_count_primary_storage(self.expectedCount, self.volumeTotal); self.verify_resource_count_primary_storage(self.expectedCount, self.volumeTotal);
@ -271,6 +268,7 @@ class TestVolumeDestroyRecover(cloudstackTestCase):
# Destroy volume (expunge=True) # Destroy volume (expunge=True)
volume.destroy(self.apiclient, expunge=True) volume.destroy(self.apiclient, expunge=True)
self.cleanup.remove(volume)
self.expectedCount = self.expectedCount - self.disk_offering.disksize self.expectedCount = self.expectedCount - self.disk_offering.disksize
self.volumeTotal = self.volumeTotal - 1 self.volumeTotal = self.volumeTotal - 1
@ -300,6 +298,7 @@ class TestVolumeDestroyRecover(cloudstackTestCase):
templateid=self.template.id, templateid=self.template.id,
zoneid=self.zone.id zoneid=self.zone.id
) )
self.cleanup.append(virtual_machine_2)
except Exception as e: except Exception as e:
self.fail("Exception while deploying virtual machine: %s" % e) self.fail("Exception while deploying virtual machine: %s" % e)
@ -313,6 +312,7 @@ class TestVolumeDestroyRecover(cloudstackTestCase):
zoneid=self.zone.id, account=self.account.name, zoneid=self.zone.id, account=self.account.name,
domainid=self.account.domainid, diskofferingid=self.disk_offering.id domainid=self.account.domainid, diskofferingid=self.disk_offering.id
) )
self.cleanup.append(volume)
self.expectedCount = self.expectedCount + self.disk_offering.disksize self.expectedCount = self.expectedCount + self.disk_offering.disksize
self.volumeTotal = self.volumeTotal + 1 self.volumeTotal = self.volumeTotal + 1
self.verify_resource_count_primary_storage(self.expectedCount, self.volumeTotal); self.verify_resource_count_primary_storage(self.expectedCount, self.volumeTotal);
@ -322,11 +322,16 @@ class TestVolumeDestroyRecover(cloudstackTestCase):
self.verify_resource_count_primary_storage(self.expectedCount, self.volumeTotal); self.verify_resource_count_primary_storage(self.expectedCount, self.volumeTotal);
# Detach volume from vm # Detach volume from vm
virtual_machine_2.stop(self.apiclient)
virtual_machine_2.detach_volume(self.apiclient, volume) virtual_machine_2.detach_volume(self.apiclient, volume)
self.verify_resource_count_primary_storage(self.expectedCount, self.volumeTotal); self.verify_resource_count_primary_storage(self.expectedCount, self.volumeTotal);
# save id for later recovery and expunge
volumeUuid = volume.id
# Destroy volume (expunge=False) # Destroy volume (expunge=False)
volume.destroy(self.apiclient) volume.destroy(self.apiclient, expunge=False)
self.cleanup.remove(volume)
self.expectedCount = self.expectedCount - self.disk_offering.disksize self.expectedCount = self.expectedCount - self.disk_offering.disksize
self.volumeTotal = self.volumeTotal - 1 self.volumeTotal = self.volumeTotal - 1
self.verify_resource_count_primary_storage(self.expectedCount, self.volumeTotal); self.verify_resource_count_primary_storage(self.expectedCount, self.volumeTotal);
@ -337,6 +342,7 @@ class TestVolumeDestroyRecover(cloudstackTestCase):
# Destroy VM (expunge=True) # Destroy VM (expunge=True)
virtual_machine_2.delete(self.apiclient, expunge=True) virtual_machine_2.delete(self.apiclient, expunge=True)
self.cleanup.remove(virtual_machine_2)
self.expectedCount = self.expectedCount - self.templatesize self.expectedCount = self.expectedCount - self.templatesize
self.volumeTotal = self.volumeTotal - 1 self.volumeTotal = self.volumeTotal - 1
self.verify_resource_count_primary_storage(self.expectedCount, self.volumeTotal); self.verify_resource_count_primary_storage(self.expectedCount, self.volumeTotal);
@ -365,6 +371,7 @@ class TestVolumeDestroyRecover(cloudstackTestCase):
templateid=self.template.id, templateid=self.template.id,
zoneid=self.zone.id zoneid=self.zone.id
) )
self.cleanup.append(virtual_machine_3)
except Exception as e: except Exception as e:
self.fail("Exception while deploying virtual machine: %s" % e) self.fail("Exception while deploying virtual machine: %s" % e)
@ -416,6 +423,7 @@ class TestVolumeDestroyRecover(cloudstackTestCase):
# Destroy VM (expunge=True) # Destroy VM (expunge=True)
virtual_machine_3.delete(self.apiclient, expunge=True) virtual_machine_3.delete(self.apiclient, expunge=True)
self.cleanup.remove(virtual_machine_3)
self.expectedCount = self.expectedCount - self.templatesize self.expectedCount = self.expectedCount - self.templatesize
self.volumeTotal = self.volumeTotal - 1 self.volumeTotal = self.volumeTotal - 1
self.verify_resource_count_primary_storage(self.expectedCount, self.volumeTotal); self.verify_resource_count_primary_storage(self.expectedCount, self.volumeTotal);
@ -444,6 +452,7 @@ class TestVolumeDestroyRecover(cloudstackTestCase):
templateid=self.template.id, templateid=self.template.id,
zoneid=self.zone.id zoneid=self.zone.id
) )
self.cleanup.append(virtual_machine_4)
except Exception as e: except Exception as e:
self.fail("Exception while deploying virtual machine: %s" % e) self.fail("Exception while deploying virtual machine: %s" % e)
@ -474,6 +483,7 @@ class TestVolumeDestroyRecover(cloudstackTestCase):
# Destroy VM (expunge=True) # Destroy VM (expunge=True)
virtual_machine_4.delete(self.apiclient, expunge=True) virtual_machine_4.delete(self.apiclient, expunge=True)
self.cleanup.remove(virtual_machine_4)
self.expectedCount = self.expectedCount - self.templatesize self.expectedCount = self.expectedCount - self.templatesize
self.volumeTotal = self.volumeTotal - 1 self.volumeTotal = self.volumeTotal - 1
self.verify_resource_count_primary_storage(self.expectedCount, self.volumeTotal); self.verify_resource_count_primary_storage(self.expectedCount, self.volumeTotal);
@ -504,4 +514,5 @@ class TestVolumeDestroyRecover(cloudstackTestCase):
# 2. resource count should not be changed # 2. resource count should not be changed
""" """
self.account_network.delete(self.apiclient) self.account_network.delete(self.apiclient)
self._cleanup.remove(self.account_network)
self.verify_resource_count_primary_storage(self.expectedCount, self.volumeTotal) self.verify_resource_count_primary_storage(self.expectedCount, self.volumeTotal)

View File

@ -102,19 +102,16 @@ class TestAttachVolume(cloudstackTestCase):
cls.testdata["account"], cls.testdata["account"],
domainid=cls.domain.id domainid=cls.domain.id
) )
cls._cleanup.append(cls.account)
update_resource_limit( update_resource_limit(
cls.api_client, cls.api_client,
2, # Instance 2, # Instance
account=cls.account.name, account=cls.account.name,
domainid=cls.account.domainid, domainid=cls.account.domainid,
max=cls.max_data_volumes + 1 max=cls.max_data_volumes + 1
) )
cls._cleanup.append(cls.account)
cls.debug('max data volumes:{}'.format(cls.max_data_volumes)) cls.debug('max data volumes:{}'.format(cls.max_data_volumes))
#cls.services["volume"]["max"] = cls.max_data_volumes
# Create VMs, NAT Rules etc
cls.service_offering = ServiceOffering.create( cls.service_offering = ServiceOffering.create(
cls.api_client, cls.api_client,
@ -130,6 +127,7 @@ class TestAttachVolume(cloudstackTestCase):
templateid=cls.template.id, templateid=cls.template.id,
zoneid=cls.zone.id zoneid=cls.zone.id
) )
cls._cleanup.append(cls.virtual_machine)
def setUp(self): def setUp(self):
@ -141,22 +139,11 @@ class TestAttachVolume(cloudstackTestCase):
self.skipTest("Skipping because of unsupported storage type") self.skipTest("Skipping because of unsupported storage type")
def tearDown(self): def tearDown(self):
try: super(TestAttachVolume, self).tearDown()
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
self.debug("Warning: Exception during cleanup : %s" % e)
# raise Exception("Warning: Exception during cleanup : %s" % e)
return
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestAttachVolume, cls).tearDownClass()
cls.api_client = super(
TestAttachVolume,
cls).getClsTestClient().getApiClient()
cleanup_resources(cls.api_client, cls._cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
@attr(tags=["advanced", "advancedns", "needle"]) @attr(tags=["advanced", "advancedns", "needle"])
def test_01_volume_attach(self): def test_01_volume_attach(self):
@ -278,23 +265,23 @@ class TestAttachVolume(cloudstackTestCase):
@attr(tags=["advanced", "advancedns"]) @attr(tags=["advanced", "advancedns"])
def test_02_volume_attach_max(self): def test_02_volume_attach_max(self):
"""Test attach volumes (more than max) to an instance """Test attach volumes (more than max) to an instance
"""
# Validate the following # Validate the following
# 1. Attach one more data volume to VM (Already 5 attached) # 1. Attach one more data volume to VM (Already 5 attached)
# 2. Attach volume should fail # 2. Attach volume should fail
"""
# Create a volume and attach to VM # Create a volume and attach to VM
# Update limit so that account could create one more volume # Update limit so that account could create one more volume
if 'kvm' in self.hypervisor: if 'kvm' in self.hypervisor:
update_resource_limit( update_resource_limit(
self.api_client, self.api_client,
2, # Instance 2, # Instance
account=self.account.name, account=self.account.name,
domainid=self.account.domainid, domainid=self.account.domainid,
max=32 max=32
) )
# Attach volume to VM # Attach volume to VM
with self.assertRaises(Exception): with self.assertRaises(Exception):
for i in range(self.max_data_volumes): for i in range(self.max_data_volumes):
@ -384,14 +371,14 @@ class TestAttachDetachVolume(cloudstackTestCase):
cls.testdata["account"], cls.testdata["account"],
domainid=cls.domain.id domainid=cls.domain.id
) )
update_resource_limit(
cls.api_client,
2, # Instance
account=cls.account.name,
domainid=cls.account.domainid,
max=cls.max_data_volumes + 1
)
cls._cleanup.append(cls.account) cls._cleanup.append(cls.account)
update_resource_limit(
cls.api_client,
2, # Instance
account=cls.account.name,
domainid=cls.account.domainid,
max=cls.max_data_volumes + 1
)
cls.service_offering = ServiceOffering.create( cls.service_offering = ServiceOffering.create(
cls.api_client, cls.api_client,
@ -405,6 +392,7 @@ class TestAttachDetachVolume(cloudstackTestCase):
domainid=cls.account.domainid, domainid=cls.account.domainid,
serviceofferingid=cls.service_offering.id, serviceofferingid=cls.service_offering.id,
) )
cls._cleanup.append(cls.virtual_machine)
def setUp(self): def setUp(self):
@ -416,19 +404,11 @@ class TestAttachDetachVolume(cloudstackTestCase):
self.skipTest("RBD storage type is required for data volumes for LXC") self.skipTest("RBD storage type is required for data volumes for LXC")
def tearDown(self): def tearDown(self):
# Clean up, terminate the created volumes super(TestAttachDetachVolume, self).tearDown()
cleanup_resources(self.apiclient, self.cleanup)
return
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestAttachDetachVolume, cls).tearDownClass()
cls.api_client = super(
TestAttachDetachVolume,
cls).getClsTestClient().getApiClient()
cleanup_resources(cls.api_client, cls._cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
@attr(tags=["advanced", "advancedns"]) @attr(tags=["advanced", "advancedns"])
def test_01_volume_attach_detach(self): def test_01_volume_attach_detach(self):
@ -570,8 +550,6 @@ class TestAttachDetachVolume(cloudstackTestCase):
@attr(tags=["advanced", "advancedns"], required_hardware="false") @attr(tags=["advanced", "advancedns"], required_hardware="false")
def test_02_root_volume_attach_detach(self): def test_02_root_volume_attach_detach(self):
"""Test Root Volume attach/detach to VM """Test Root Volume attach/detach to VM
"""
# Validate the following # Validate the following
# 1. Deploy a VM # 1. Deploy a VM
# 2. Verify that we are testing a supported hypervisor # 2. Verify that we are testing a supported hypervisor
@ -581,116 +559,114 @@ class TestAttachDetachVolume(cloudstackTestCase):
# 6. Verify root volume detached # 6. Verify root volume detached
# 7. Attach root volume # 7. Attach root volume
# 8. Start VM # 8. Start VM
"""
# Verify we are using a supported hypervisor
if (self.hypervisor.lower() == 'vmware' if (self.hypervisor.lower() == 'vmware'
or self.hypervisor.lower() == 'kvm' or self.hypervisor.lower() == 'kvm'
or self.hypervisor.lower() == 'simulator' or self.hypervisor.lower() == 'simulator'
or self.hypervisor.lower() == 'xenserver'): or self.hypervisor.lower() == 'xenserver'):
root_volume_response = Volume.list(
self.apiclient,
virtualmachineid=self.virtual_machine.id,
type='ROOT',
listall=True
)
# Check for root volume self.assertEqual(
root_volume_response = Volume.list( validateList(root_volume_response)[0],
self.apiclient, PASS,
virtualmachineid=self.virtual_machine.id, "Invalid response returned for root volume list"
type='ROOT', )
listall=True
)
self.assertEqual( # Grab the root volume for later use
validateList(root_volume_response)[0], root_volume = root_volume_response[0]
PASS,
"Invalid response returned for root volume list"
)
# Grab the root volume for later use # Stop VM
root_volume = root_volume_response[0] self.debug("Stopping the VM: %s" % self.virtual_machine.id)
self.virtual_machine.stop(self.apiclient)
# Stop VM vm_response = VirtualMachine.list(
self.debug("Stopping the VM: %s" % self.virtual_machine.id) self.apiclient,
self.virtual_machine.stop(self.apiclient) id=self.virtual_machine.id,
)
vm_response = VirtualMachine.list( # Ensure that vm_response is a valid list
self.apiclient, self.assertEqual(
id=self.virtual_machine.id, validateList(vm_response)[0],
) PASS,
"Invalid response returned for vm_response list"
)
# Ensure that vm_response is a valid list vm = vm_response[0]
self.assertEqual( self.assertEqual(
validateList(vm_response)[0], vm.state,
PASS, 'Stopped',
"Invalid response returned for vm_response list" "Check the state of VM"
) )
vm = vm_response[0] # Detach root volume from VM
self.assertEqual( self.virtual_machine.detach_volume(
vm.state, self.apiclient,
'Stopped', root_volume
"Check the state of VM" )
)
# Detach root volume from VM # Verify that root disk is gone
self.virtual_machine.detach_volume( no_root_volume_response = Volume.list(
self.apiclient, self.apiclient,
root_volume virtualmachineid=self.virtual_machine.id,
) type='ROOT',
listall=True
)
# Verify that root disk is gone self.assertEqual(
no_root_volume_response = Volume.list( no_root_volume_response,
self.apiclient, None,
virtualmachineid=self.virtual_machine.id, "Check if root volume exists in ListVolumes"
type='ROOT', )
listall=True
)
self.assertEqual( # Attach root volume to VM
no_root_volume_response, self.virtual_machine.attach_volume(
None, self.apiclient,
"Check if root volume exists in ListVolumes" root_volume,
) 0
)
# Attach root volume to VM # Check for root volume
self.virtual_machine.attach_volume( new_root_volume_response = Volume.list(
self.apiclient, self.apiclient,
root_volume, virtualmachineid=self.virtual_machine.id,
0 type='ROOT',
) listall=True
)
# Check for root volume # Ensure that new_root_volume_response is a valid list
new_root_volume_response = Volume.list( self.assertEqual(
self.apiclient, validateList(new_root_volume_response)[0],
virtualmachineid=self.virtual_machine.id, PASS,
type='ROOT', "Invalid response returned for new_root_volume_response list"
listall=True )
)
# Ensure that new_root_volume_response is a valid list # Start VM
self.assertEqual( self.virtual_machine.start(self.apiclient)
validateList(new_root_volume_response)[0],
PASS,
"Invalid response returned for new_root_volume_response list"
)
# Start VM vm_response = VirtualMachine.list(
self.virtual_machine.start(self.apiclient) self.apiclient,
id=self.virtual_machine.id,
)
vm_response = VirtualMachine.list( # Verify VM response to check whether VM deployment was successful
self.apiclient, self.assertEqual(
id=self.virtual_machine.id, validateList(vm_response)[0],
) PASS,
"Invalid response returned for vm_response list during VM start up"
)
# Verify VM response to check whether VM deployment was successful vm = vm_response[0]
self.assertEqual( self.assertEqual(
validateList(vm_response)[0], vm.state,
PASS, 'Running',
"Invalid response returned for vm_response list during VM start up" "Ensure the state of VM is running"
) )
vm = vm_response[0]
self.assertEqual(
vm.state,
'Running',
"Ensure the state of VM is running"
)
else: else:
self.skipTest("Root Volume attach/detach is not supported on %s " % self.hypervisor) self.skipTest("Root Volume attach/detach is not supported on %s " % self.hypervisor)
@ -758,6 +734,7 @@ class TestAttachVolumeISO(cloudstackTestCase):
cls.testdata["account"], cls.testdata["account"],
domainid=cls.domain.id domainid=cls.domain.id
) )
cls._cleanup.append(cls.account)
update_resource_limit( update_resource_limit(
cls.api_client, cls.api_client,
2, # Instance 2, # Instance
@ -769,8 +746,6 @@ class TestAttachVolumeISO(cloudstackTestCase):
cls.testdata["volume"]["max"] = cls.max_data_volumes cls.testdata["volume"]["max"] = cls.max_data_volumes
# Create VMs, NAT Rules etc # Create VMs, NAT Rules etc
cls._cleanup.append(cls.account)
cls.service_offering = ServiceOffering.create( cls.service_offering = ServiceOffering.create(
cls.api_client, cls.api_client,
cls.testdata["service_offering"] cls.testdata["service_offering"]
@ -783,13 +758,11 @@ class TestAttachVolumeISO(cloudstackTestCase):
domainid=cls.account.domainid, domainid=cls.account.domainid,
serviceofferingid=cls.service_offering.id, serviceofferingid=cls.service_offering.id,
) )
cls._cleanup.append(cls.virtual_machine)
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestAttachVolumeISO, cls).tearDownClass()
cleanup_resources(cls.api_client, cls._cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
def setUp(self): def setUp(self):
@ -801,22 +774,16 @@ class TestAttachVolumeISO(cloudstackTestCase):
self.skipTest("RBD storage type is required for data volumes for LXC") self.skipTest("RBD storage type is required for data volumes for LXC")
def tearDown(self): def tearDown(self):
try: super(TestAttachVolumeISO, self).tearDown()
# Clean up, terminate the created instance, volumes and snapshots
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@attr(tags=["advanced", "advancedns"], required_hardware="true") @attr(tags=["advanced", "advancedns"], required_hardware="true")
def test_01_volume_iso_attach(self): def test_01_volume_iso_attach(self):
"""Test Volumes and ISO attach """Test Volumes and ISO attach
"""
# Validate the following # Validate the following
# 1. Create and attach 5 data volumes to VM # 1. Create and attach 5 data volumes to VM
# 2. Create an ISO. Attach it to VM instance # 2. Create an ISO. Attach it to VM instance
# 3. Verify that attach ISO is successful # 3. Verify that attach ISO is successful
"""
# Create 5 volumes and attach to VM # Create 5 volumes and attach to VM
if self.hypervisor.lower() in ["lxc"]: if self.hypervisor.lower() in ["lxc"]:
@ -830,6 +797,7 @@ class TestAttachVolumeISO(cloudstackTestCase):
domainid=self.account.domainid, domainid=self.account.domainid,
diskofferingid=self.disk_offering.id diskofferingid=self.disk_offering.id
) )
self.cleanup.append(volume)
self.debug("Created volume: %s for account: %s" % ( self.debug("Created volume: %s for account: %s" % (
volume.id, volume.id,
self.account.name self.account.name
@ -854,6 +822,7 @@ class TestAttachVolumeISO(cloudstackTestCase):
self.apiclient, self.apiclient,
volume volume
) )
self.cleanup.remove(volume)
# Check all volumes attached to same VM # Check all volumes attached to same VM
list_volume_response = Volume.list( list_volume_response = Volume.list(
@ -885,6 +854,7 @@ class TestAttachVolumeISO(cloudstackTestCase):
account=self.account.name, account=self.account.name,
domainid=self.account.domainid, domainid=self.account.domainid,
) )
self.cleanup.append(iso)
self.debug("Created ISO with ID: %s for account: %s" % ( self.debug("Created ISO with ID: %s for account: %s" % (
iso.id, iso.id,
self.account.name self.account.name
@ -906,6 +876,7 @@ class TestAttachVolumeISO(cloudstackTestCase):
cmd.id = iso.id cmd.id = iso.id
cmd.virtualmachineid = self.virtual_machine.id cmd.virtualmachineid = self.virtual_machine.id
self.apiclient.attachIso(cmd) self.apiclient.attachIso(cmd)
self.cleanup.remove(iso)
# Verify ISO is attached to VM # Verify ISO is attached to VM
vm_response = VirtualMachine.list( vm_response = VirtualMachine.list(
@ -987,7 +958,9 @@ class TestVolumes(cloudstackTestCase):
accountid=cls.account.name, accountid=cls.account.name,
domainid=cls.account.domainid, domainid=cls.account.domainid,
serviceofferingid=cls.service_offering.id, serviceofferingid=cls.service_offering.id,
startvm=False
) )
cls._cleanup.append(cls.virtual_machine)
cls.volume = Volume.create( cls.volume = Volume.create(
cls.api_client, cls.api_client,
@ -997,13 +970,11 @@ class TestVolumes(cloudstackTestCase):
domainid=cls.account.domainid, domainid=cls.account.domainid,
diskofferingid=cls.disk_offering.id diskofferingid=cls.disk_offering.id
) )
cls._cleanup.append(cls.volume)
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestVolumes, cls).tearDownClass()
cleanup_resources(cls.api_client, cls._cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
def setUp(self): def setUp(self):
self.apiclient = self.testClient.getApiClient() self.apiclient = self.testClient.getApiClient()
@ -1014,21 +985,21 @@ class TestVolumes(cloudstackTestCase):
self.skipTest("RBD storage type is required for data volumes for LXC") self.skipTest("RBD storage type is required for data volumes for LXC")
def tearDown(self): def tearDown(self):
# Clean up, terminate the created volumes super(TestVolumes, self).tearDown()
cleanup_resources(self.apiclient, self.cleanup)
return
@attr(tags=["advanced", "advancedns"], required_hardware="false") @attr(tags=["advanced", "advancedns"], required_hardware="false")
def test_01_attach_volume(self): def test_01_attach_volume(self):
"""Attach a created Volume to a Running VM """Attach a created Volume to a Running VM
"""
# Validate the following # Validate the following
# 1. Create a data volume. # Create a data volume. (this is being done in setup)
# 2. List Volumes should not have vmname and virtualmachineid fields in # 2. List Volumes should not have vmname and virtualmachineid fields in
# response before volume attach (to VM) # response before volume attach (to VM)
# 3. Attch volume to VM. Attach volume should be successful. # 3. Attch volume to VM. Attach volume should be successful.
# 4. List Volumes should have vmname and virtualmachineid fields in # 4. List Volumes should have vmname and virtualmachineid fields in
# response before volume attach (to VM) # response before volume attach (to VM)
FIXME: This test (method) creates a precondition for `test_02_detach_volume()`:
an attached `self.volume` to `self.virtual_machine`
"""
# Check the list volumes response for vmname and virtualmachineid # Check the list volumes response for vmname and virtualmachineid
list_volume_response = Volume.list( list_volume_response = Volume.list(
@ -1070,6 +1041,7 @@ class TestVolumes(cloudstackTestCase):
self.virtual_machine.id self.virtual_machine.id
)) ))
self.virtual_machine.attach_volume(self.apiclient, self.volume) self.virtual_machine.attach_volume(self.apiclient, self.volume)
self._cleanup.remove(self.volume)
# Check all volumes attached to same VM # Check all volumes attached to same VM
list_volume_response = Volume.list( list_volume_response = Volume.list(
@ -1104,18 +1076,22 @@ class TestVolumes(cloudstackTestCase):
@attr(tags=["advanced", "advancedns"], required_hardware="false") @attr(tags=["advanced", "advancedns"], required_hardware="false")
def test_02_detach_volume(self): def test_02_detach_volume(self):
"""Detach a Volume attached to a VM """Detach a Volume attached to a VM
""" FIXME: this test method assumes a precondition set in `self.test_01_atttach_volume()`:
there is expected to be a VM with a disk attached
# Validate the following # Validate the following
# 1. Data disk should be detached from instance # 1. Data disk should be detached from instance
# 2. Listvolumes should not have vmname and virtualmachineid fields for # 2. Listvolumes should not have vmname and virtualmachineid fields for
# that volume. # that volume.
FIXME: this test (method) leaves a precondition for `self.test_03_delete_detached_volume()`:
"""
self.debug("Detach volume: %s to VM: %s" % ( self.debug("Detach volume: %s to VM: %s" % (
self.volume.id, self.volume.id,
self.virtual_machine.id self.virtual_machine.id
)) ))
self.virtual_machine.detach_volume(self.apiclient, self.volume) self.virtual_machine.detach_volume(self.apiclient, self.volume)
self._cleanup.append(self.volume)
# Sleep to ensure the current state will reflected in other calls # Sleep to ensure the current state will reflected in other calls
time.sleep(self.testdata["sleep"]) time.sleep(self.testdata["sleep"])
@ -1151,15 +1127,17 @@ class TestVolumes(cloudstackTestCase):
@attr(tags=["advanced", "advancedns"], required_hardware="false") @attr(tags=["advanced", "advancedns"], required_hardware="false")
def test_03_delete_detached_volume(self): def test_03_delete_detached_volume(self):
"""Delete a Volume unattached to an VM """Delete a Volume unattached to an VM
""" FIXME: this expects `test_02_detach_volume()` to leave `self.volume` free and ready to delete
# Validate the following # Validate the following
# 1. volume should be deleted successfully and listVolume should not # 1. volume should be deleted successfully and listVolume should not
# contain the deleted volume details. # contain the deleted volume details.
"""
self.debug("Deleting volume: %s" % self.volume.id) self.debug("Deleting volume: %s" % self.volume.id)
cmd = deleteVolume.deleteVolumeCmd() cmd = deleteVolume.deleteVolumeCmd()
cmd.id = self.volume.id cmd.id = self.volume.id
self.apiclient.deleteVolume(cmd) self.apiclient.deleteVolume(cmd)
self._cleanup.remove(self.volume)
# Sleep to ensure the current state will reflected in other calls # Sleep to ensure the current state will reflected in other calls
time.sleep(self.testdata["sleep"]) time.sleep(self.testdata["sleep"])
@ -1208,7 +1186,7 @@ class TestVolumes(cloudstackTestCase):
admin=False, admin=False,
domainid=dom.id domainid=dom.id
) )
self.cleanup.insert(-2, domuser) self.cleanup.append(domuser)
self.assertTrue(domuser is not None) self.assertTrue(domuser is not None)
domapiclient = self.testClient.getUserApiClient( domapiclient = self.testClient.getUserApiClient(
@ -1233,6 +1211,7 @@ class TestVolumes(cloudstackTestCase):
domainid=dom.id, domainid=dom.id,
diskofferingid=[x for x in diskoffering if not x.iscustomized][0].id diskofferingid=[x for x in diskoffering if not x.iscustomized][0].id
) )
self.cleanup.append(vol)
self.assertTrue( self.assertTrue(
vol is not None, "volume creation fails in domain %s as user %s" % vol is not None, "volume creation fails in domain %s as user %s" %
(dom.name, domuser.name)) (dom.name, domuser.name))
@ -1311,11 +1290,17 @@ class TestDeployVmWithCustomDisk(cloudstackTestCase):
if self.unsupportedStorageType: if self.unsupportedStorageType:
self.skipTest("RBD storage type is required for data volumes for LXC") self.skipTest("RBD storage type is required for data volumes for LXC")
@classmethod
def tearDownClass(cls):
super(TestDeployVmWithCustomDisk, cls).tearDownClass()
def tearDown(self):
super(TestDeployVmWithCustomDisk, self).tearDown()
@attr(tags=["advanced", "configuration", "advancedns", "simulator", @attr(tags=["advanced", "configuration", "advancedns", "simulator",
"api", "basic", "eip", "sg"]) "api", "basic", "eip", "sg"])
def test_deployVmWithCustomDisk(self): def test_deployVmWithCustomDisk(self):
"""Test custom disk sizes beyond range """Test custom disk sizes beyond range
"""
# Steps for validation # Steps for validation
# 1. listConfigurations - custom.diskoffering.size.min # 1. listConfigurations - custom.diskoffering.size.min
# and custom.diskoffering.size.max # and custom.diskoffering.size.max
@ -1326,6 +1311,7 @@ class TestDeployVmWithCustomDisk(cloudstackTestCase):
# 2. and 4. of deploy VM should fail. # 2. and 4. of deploy VM should fail.
# Only case 3. should succeed. # Only case 3. should succeed.
# cleanup all created data disks from the account # cleanup all created data disks from the account
"""
config = Configurations.list( config = Configurations.list(
self.apiclient, self.apiclient,
@ -1357,38 +1343,41 @@ class TestDeployVmWithCustomDisk(cloudstackTestCase):
self.testdata["custom_volume"]["customdisksize"] = (min_size - 1) self.testdata["custom_volume"]["customdisksize"] = (min_size - 1)
self.testdata["custom_volume"]["zoneid"] = self.zone.id self.testdata["custom_volume"]["zoneid"] = self.zone.id
with self.assertRaises(Exception): with self.assertRaises(Exception):
Volume.create_custom_disk( vol = Volume.create_custom_disk(
self.apiclient, self.apiclient,
self.testdata["custom_volume"], self.testdata["custom_volume"],
account=self.account.name, account=self.account.name,
domainid=self.account.domainid, domainid=self.account.domainid,
diskofferingid=self.disk_offering.id diskofferingid=self.disk_offering.id
) )
self.cleanup.append(vol)
self.debug("Create volume failed!") self.debug("Create volume failed!")
self.debug("Creating a volume with size more than max cust disk size") self.debug("Creating a volume with size more than max cust disk size")
self.testdata["custom_volume"]["customdisksize"] = (max_size + 1) self.testdata["custom_volume"]["customdisksize"] = (max_size + 1)
with self.assertRaises(Exception): with self.assertRaises(Exception):
Volume.create_custom_disk( vol = Volume.create_custom_disk(
self.apiclient, self.apiclient,
self.testdata["custom_volume"], self.testdata["custom_volume"],
account=self.account.name, account=self.account.name,
domainid=self.account.domainid, domainid=self.account.domainid,
diskofferingid=self.disk_offering.id diskofferingid=self.disk_offering.id
) )
self.cleanup.append(vol)
self.debug("Create volume failed!") self.debug("Create volume failed!")
self.debug("Creating a volume with size more than min cust disk " + self.debug("Creating a volume with size more than min cust disk " +
"but less than max cust disk size" "but less than max cust disk size"
) )
self.testdata["custom_volume"]["customdisksize"] = (min_size + 1) self.testdata["custom_volume"]["customdisksize"] = (min_size + 1)
Volume.create_custom_disk( vol = Volume.create_custom_disk(
self.apiclient, self.apiclient,
self.testdata["custom_volume"], self.testdata["custom_volume"],
account=self.account.name, account=self.account.name,
domainid=self.account.domainid, domainid=self.account.domainid,
diskofferingid=self.disk_offering.id diskofferingid=self.disk_offering.id
) )
self.cleanup.append(vol)
self.debug("Create volume of cust disk size succeeded") self.debug("Create volume of cust disk size succeeded")
return return
@ -1417,6 +1406,7 @@ class TestMigrateVolume(cloudstackTestCase):
cls.api_client, cls.api_client,
cls.testdata["disk_offering"] cls.testdata["disk_offering"]
) )
cls._cleanup.append(cls.disk_offering)
template = get_template( template = get_template(
cls.api_client, cls.api_client,
cls.zone.id, cls.zone.id,
@ -1434,10 +1424,12 @@ class TestMigrateVolume(cloudstackTestCase):
cls.testdata["account"], cls.testdata["account"],
domainid=cls.domain.id domainid=cls.domain.id
) )
cls._cleanup.append(cls.account)
cls.small_offering = ServiceOffering.create( cls.small_offering = ServiceOffering.create(
cls.api_client, cls.api_client,
cls.testdata["service_offering"] cls.testdata["service_offering"]
) )
cls._cleanup.append(cls.small_offering)
cls.virtual_machine = VirtualMachine.create( cls.virtual_machine = VirtualMachine.create(
cls.api_client, cls.api_client,
cls.testdata["virtual_machine"], cls.testdata["virtual_machine"],
@ -1446,15 +1438,12 @@ class TestMigrateVolume(cloudstackTestCase):
serviceofferingid=cls.small_offering.id, serviceofferingid=cls.small_offering.id,
mode=cls.testdata["mode"] mode=cls.testdata["mode"]
) )
cls._cleanup = [ cls._cleanup.append(cls.virtual_machine)
cls.small_offering,
cls.account
]
return return
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
super(TestMigrateVolume,cls).tearDownClass() super(TestMigrateVolume, cls).tearDownClass()
def setUp(self): def setUp(self):
self.apiclient = self.testClient.getApiClient() self.apiclient = self.testClient.getApiClient()
@ -1466,7 +1455,7 @@ class TestMigrateVolume(cloudstackTestCase):
return return
def tearDown(self): def tearDown(self):
super(TestMigrateVolume,self).tearDown() super(TestMigrateVolume, self).tearDown()
@attr(tags=["advanced", "sg", "advancedsg"], required_hardware='true') @attr(tags=["advanced", "sg", "advancedsg"], required_hardware='true')
def test_01_migrateVolume(self): def test_01_migrateVolume(self):
@ -1480,6 +1469,9 @@ class TestMigrateVolume(cloudstackTestCase):
Step4:Migrating volume to new primary storage should succeed Step4:Migrating volume to new primary storage should succeed
Step5:volume UUID should not change even after migration Step5:volume UUID should not change even after migration
""" """
if self.hypervisor.lower() in ["kvm"]:
self.skipTest("KVM cannot migrate an attached volume without the VM")
vol = Volume.create( vol = Volume.create(
self.apiclient, self.apiclient,
self.testdata["volume"], self.testdata["volume"],
@ -1488,6 +1480,7 @@ class TestMigrateVolume(cloudstackTestCase):
account=self.account.name, account=self.account.name,
domainid=self.account.domainid, domainid=self.account.domainid,
) )
self.cleanup.append(vol)
self.assertIsNotNone(vol, "Failed to create volume") self.assertIsNotNone(vol, "Failed to create volume")
vol_res = Volume.list( vol_res = Volume.list(
self.apiclient, self.apiclient,
@ -1502,6 +1495,7 @@ class TestMigrateVolume(cloudstackTestCase):
self.apiclient, self.apiclient,
vol vol
) )
self.cleanup.remove(vol)
pools = StoragePool.listForMigration( pools = StoragePool.listForMigration(
self.apiclient, self.apiclient,

View File

@ -289,32 +289,24 @@ class TestVPCNetwork(cloudstackTestCase):
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestVPCNetwork, cls).tearDownClass()
# 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): def setUp(self):
self.services = Services().services self.services = Services().services
self.apiclient = self.testClient.getApiClient() self.apiclient = self.testClient.getApiClient()
self.dbclient = self.testClient.getDbConnection() self.dbclient = self.testClient.getDbConnection()
self.cleanup = []
self.account = Account.create( self.account = Account.create(
self.apiclient, self.apiclient,
self.services["account"], self.services["account"],
admin=True, admin=True,
domainid=self.domain.id domainid=self.domain.id
) )
self.cleanup = [self.account, ] self.cleanup.append(self.account)
return return
def tearDown(self): def tearDown(self):
try: super(TestVPCNetwork, self).tearDown()
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
self.debug("Warning: Exception during cleanup : %s" % e)
return
def validate_vpc_offering(self, vpc_offering): def validate_vpc_offering(self, vpc_offering):
"""Validates the VPC offering""" """Validates the VPC offering"""
@ -370,7 +362,6 @@ class TestVPCNetwork(cloudstackTestCase):
@attr(tags=["advanced", "intervlan"]) @attr(tags=["advanced", "intervlan"])
def test_01_create_network(self, value): def test_01_create_network(self, value):
""" Test create network in VPC """ Test create network in VPC
"""
# Validate the following # Validate the following
# 1. Create a VPC using Default Offering # 1. Create a VPC using Default Offering
@ -383,6 +374,7 @@ class TestVPCNetwork(cloudstackTestCase):
# 4. Validate Network is created # 4. Validate Network is created
# 5. Repeat test for offering which has Netscaler as external LB # 5. Repeat test for offering which has Netscaler as external LB
# provider # provider
"""
if (value == "network_offering_vpcns" and not self.ns_configured): if (value == "network_offering_vpcns" and not self.ns_configured):
self.skipTest('Netscaler not configured: skipping test') self.skipTest('Netscaler not configured: skipping test')
@ -411,6 +403,7 @@ class TestVPCNetwork(cloudstackTestCase):
account=self.account.name, account=self.account.name,
domainid=self.account.domainid domainid=self.account.domainid
) )
self.cleanup.append(vpc)
self.validate_vpc_network(vpc) self.validate_vpc_network(vpc)
self.network_offering = NetworkOffering.create( self.network_offering = NetworkOffering.create(
@ -418,9 +411,8 @@ class TestVPCNetwork(cloudstackTestCase):
self.services[value], self.services[value],
conservemode=False conservemode=False
) )
# Enable Network offering
self.network_offering.update(self.apiclient, state='Enabled')
self.cleanup.append(self.network_offering) self.cleanup.append(self.network_offering)
self.network_offering.update(self.apiclient, state='Enabled')
# Creating network using the network offering created # Creating network using the network offering created
self.debug("Creating network with network offering: %s" % self.debug("Creating network with network offering: %s" %
@ -435,6 +427,7 @@ class TestVPCNetwork(cloudstackTestCase):
gateway='10.1.1.1', gateway='10.1.1.1',
vpcid=vpc.id vpcid=vpc.id
) )
self.cleanup.append(network)
self.debug("Created network with ID: %s" % network.id) self.debug("Created network with ID: %s" % network.id)
self.debug( self.debug(
"Verifying list network response to check if network created?") "Verifying list network response to check if network created?")
@ -467,7 +460,6 @@ class TestVPCNetwork(cloudstackTestCase):
@attr(tags=["advanced", "intervlan"]) @attr(tags=["advanced", "intervlan"])
def test_02_create_network_fail(self, value): def test_02_create_network_fail(self, value):
""" Test create network in VPC mismatched services (Should fail) """ Test create network in VPC mismatched services (Should fail)
"""
# Validate the following # Validate the following
# 1. Create a VPC using Default VPC Offering # 1. Create a VPC using Default VPC Offering
@ -481,6 +473,7 @@ class TestVPCNetwork(cloudstackTestCase):
# instead of VPCVR # instead of VPCVR
# 5. Repeat test for offering which has Netscaler as external LB # 5. Repeat test for offering which has Netscaler as external LB
# provider # provider
"""
if (value == "network_offering_vpcns" and not self.ns_configured): if (value == "network_offering_vpcns" and not self.ns_configured):
self.skipTest('Netscaler not configured: skipping test') self.skipTest('Netscaler not configured: skipping test')
@ -509,6 +502,7 @@ class TestVPCNetwork(cloudstackTestCase):
account=self.account.name, account=self.account.name,
domainid=self.account.domainid domainid=self.account.domainid
) )
self.cleanup.append(vpc)
self.validate_vpc_network(vpc) self.validate_vpc_network(vpc)
self.services[value]["serviceProviderList"] = { self.services[value]["serviceProviderList"] = {
@ -519,15 +513,14 @@ class TestVPCNetwork(cloudstackTestCase):
self.services[value], self.services[value],
conservemode=False conservemode=False
) )
# Enable Network offering
self.network_offering.update(self.apiclient, state='Enabled')
self.cleanup.append(self.network_offering) self.cleanup.append(self.network_offering)
self.network_offering.update(self.apiclient, state='Enabled')
# Creating network using the network offering created # Creating network using the network offering created
self.debug("Creating network with network offering: %s" % self.debug("Creating network with network offering: %s" %
self.network_offering.id) self.network_offering.id)
with self.assertRaises(Exception): with self.assertRaises(Exception):
Network.create( nw = Network.create(
self.apiclient, self.apiclient,
self.services["network"], self.services["network"],
accountid=self.account.name, accountid=self.account.name,
@ -537,14 +530,14 @@ class TestVPCNetwork(cloudstackTestCase):
gateway='10.1.1.1', gateway='10.1.1.1',
vpcid=vpc.id vpcid=vpc.id
) )
self.cleanup.append(nw)
return return
@data("network_offering", "network_offering_vpcns") @data("network_offering", "network_offering_vpcns")
@attr(tags=["advanced", "intervlan"]) @attr(tags=["advanced", "intervlan"])
def test_04_create_multiple_networks_with_lb(self, value): def test_04_create_multiple_networks_with_lb(self, value):
""" Test create multiple networks with LB service (Should fail) """ Test create multiple networks with LB service (Should fail)
"""
self.skipTest('Skipping test due to CLOUDSTACK-8437')
# Validate the following # Validate the following
# 1. Create a VPC using Default Offering # 1. Create a VPC using Default Offering
# 2. Create a network offering with guest type=Isolated that has LB # 2. Create a network offering with guest type=Isolated that has LB
@ -556,6 +549,9 @@ class TestVPCNetwork(cloudstackTestCase):
# 5. Create Network should fail # 5. Create Network should fail
# 6. Repeat test for offering which has Netscaler as external LB # 6. Repeat test for offering which has Netscaler as external LB
# provider # provider
"""
self.skipTest('Skipping test due to CLOUDSTACK-8437')
if (value == "network_offering_vpcns" and not self.ns_configured): if (value == "network_offering_vpcns" and not self.ns_configured):
self.skipTest('Netscaler not configured: skipping test') self.skipTest('Netscaler not configured: skipping test')
@ -583,6 +579,7 @@ class TestVPCNetwork(cloudstackTestCase):
account=self.account.name, account=self.account.name,
domainid=self.account.domainid domainid=self.account.domainid
) )
self.cleanup.append(vpc)
self.validate_vpc_network(vpc) self.validate_vpc_network(vpc)
self.network_offering = NetworkOffering.create( self.network_offering = NetworkOffering.create(
@ -590,9 +587,8 @@ class TestVPCNetwork(cloudstackTestCase):
self.services[value], self.services[value],
conservemode=False conservemode=False
) )
# Enable Network offering
self.network_offering.update(self.apiclient, state='Enabled')
self.cleanup.append(self.network_offering) self.cleanup.append(self.network_offering)
self.network_offering.update(self.apiclient, state='Enabled')
# Creating network using the network offering created # Creating network using the network offering created
self.debug("Creating network with network offering: %s" % self.debug("Creating network with network offering: %s" %
@ -607,6 +603,7 @@ class TestVPCNetwork(cloudstackTestCase):
gateway='10.1.1.1', gateway='10.1.1.1',
vpcid=vpc.id vpcid=vpc.id
) )
self.cleanup.append(network)
self.debug("Created network with ID: %s" % network.id) self.debug("Created network with ID: %s" % network.id)
self.debug( self.debug(
"Verifying list network response to check if network created?") "Verifying list network response to check if network created?")
@ -635,7 +632,7 @@ class TestVPCNetwork(cloudstackTestCase):
) )
self.debug("Creating another network in VPC: %s" % vpc.name) self.debug("Creating another network in VPC: %s" % vpc.name)
with self.assertRaises(Exception): with self.assertRaises(Exception):
Network.create( nw = Network.create(
self.apiclient, self.apiclient,
self.services["network"], self.services["network"],
accountid=self.account.name, accountid=self.account.name,
@ -645,6 +642,7 @@ class TestVPCNetwork(cloudstackTestCase):
gateway='10.1.2.1', gateway='10.1.2.1',
vpcid=vpc.id vpcid=vpc.id
) )
self.cleanup.append(nw)
self.debug( self.debug(
"Network creation failed as network with LB service\ "Network creation failed as network with LB service\
already exists") already exists")
@ -653,7 +651,6 @@ class TestVPCNetwork(cloudstackTestCase):
@attr(tags=["intervlan"]) @attr(tags=["intervlan"])
def test_05_create_network_ext_LB(self): def test_05_create_network_ext_LB(self):
""" Test create network with external LB devices """ Test create network with external LB devices
"""
# Validate the following # Validate the following
# 1.Create a VPC using Default Offering (Without Netscaler) # 1.Create a VPC using Default Offering (Without Netscaler)
@ -661,6 +658,7 @@ class TestVPCNetwork(cloudstackTestCase):
# service provided by netscaler and conserve mode is "ON". # service provided by netscaler and conserve mode is "ON".
# 3. Create a network using this network offering as part of this VPC. # 3. Create a network using this network offering as part of this VPC.
# 4. Create Network should fail since it doesn't match the VPC offering # 4. Create Network should fail since it doesn't match the VPC offering
"""
vpc_off_list = VpcOffering.list( vpc_off_list = VpcOffering.list(
self.apiclient, self.apiclient,
@ -679,6 +677,7 @@ class TestVPCNetwork(cloudstackTestCase):
account=self.account.name, account=self.account.name,
domainid=self.account.domainid domainid=self.account.domainid
) )
self.cleanup.append(vpc)
self.validate_vpc_network(vpc) self.validate_vpc_network(vpc)
self.network_offering = NetworkOffering.create( self.network_offering = NetworkOffering.create(
@ -686,15 +685,14 @@ class TestVPCNetwork(cloudstackTestCase):
self.services["network_offering_vpcns"], self.services["network_offering_vpcns"],
conservemode=False conservemode=False
) )
# Enable Network offering
self.network_offering.update(self.apiclient, state='Enabled')
self.cleanup.append(self.network_offering) self.cleanup.append(self.network_offering)
self.network_offering.update(self.apiclient, state='Enabled')
# Creating network using the network offering created # Creating network using the network offering created
self.debug("Creating network with network offering: %s" % self.debug("Creating network with network offering: %s" %
self.network_offering.id) self.network_offering.id)
with self.assertRaises(Exception): with self.assertRaises(Exception):
Network.create( nw = Network.create(
self.apiclient, self.apiclient,
self.services["network"], self.services["network"],
accountid=self.account.name, accountid=self.account.name,
@ -704,6 +702,7 @@ class TestVPCNetwork(cloudstackTestCase):
gateway='10.1.1.1', gateway='10.1.1.1',
vpcid=vpc.id vpcid=vpc.id
) )
self.cleanup.append(nw)
self.debug("Network creation failed") self.debug("Network creation failed")
return return
@ -711,7 +710,6 @@ class TestVPCNetwork(cloudstackTestCase):
@attr(tags=["advanced", "intervlan", "NA"]) @attr(tags=["advanced", "intervlan", "NA"])
def test_06_create_network_with_rvr(self): def test_06_create_network_with_rvr(self):
""" Test create network with redundant router capability """ Test create network with redundant router capability
"""
# Validate the following # Validate the following
# 1. Create VPC Offering by specifying all supported Services # 1. Create VPC Offering by specifying all supported Services
@ -723,13 +721,13 @@ class TestVPCNetwork(cloudstackTestCase):
# 4. Create a VPC using the above VPC offering. # 4. Create a VPC using the above VPC offering.
# 5. Create a network using the network offering created in step2 as # 5. Create a network using the network offering created in step2 as
# part of this VPC # part of this VPC
"""
self.debug("Creating a VPC offering..") self.debug("Creating a VPC offering..")
vpc_off = VpcOffering.create( vpc_off = VpcOffering.create(
self.apiclient, self.apiclient,
self.services["vpc_offering"] self.services["vpc_offering"]
) )
self.cleanup.append(vpc_off) self.cleanup.append(vpc_off)
self.validate_vpc_offering(vpc_off) self.validate_vpc_offering(vpc_off)
@ -747,6 +745,7 @@ class TestVPCNetwork(cloudstackTestCase):
account=self.account.name, account=self.account.name,
domainid=self.account.domainid domainid=self.account.domainid
) )
self.cleanup.append(vpc)
self.validate_vpc_network(vpc) self.validate_vpc_network(vpc)
# Enable redundant router capability for the network offering # Enable redundant router capability for the network offering
@ -761,15 +760,14 @@ class TestVPCNetwork(cloudstackTestCase):
self.services["network_offering"], self.services["network_offering"],
conservemode=False conservemode=False
) )
# Enable Network offering
self.network_offering.update(self.apiclient, state='Enabled')
self.cleanup.append(self.network_offering) self.cleanup.append(self.network_offering)
self.network_offering.update(self.apiclient, state='Enabled')
# Creating network using the network offering created # Creating network using the network offering created
self.debug("Creating network with network offering: %s" % self.debug("Creating network with network offering: %s" %
self.network_offering.id) self.network_offering.id)
with self.assertRaises(Exception): with self.assertRaises(Exception):
Network.create( nw = Network.create(
self.apiclient, self.apiclient,
self.services["network"], self.services["network"],
accountid=self.account.name, accountid=self.account.name,
@ -779,13 +777,13 @@ class TestVPCNetwork(cloudstackTestCase):
gateway='10.1.2.1', gateway='10.1.2.1',
vpcid=vpc.id vpcid=vpc.id
) )
self.cleanup.append(nw)
self.debug("Network creation failed") self.debug("Network creation failed")
return return
@attr(tags=["advanced", "intervlan"], required_hardware="false") @attr(tags=["advanced", "intervlan"], required_hardware="false")
def test_07_create_network_unsupported_services(self): def test_07_create_network_unsupported_services(self):
""" Test create network services not supported by VPC (Should fail) """ Test create network services not supported by VPC (Should fail)
"""
# Validate the following # Validate the following
# 1. Create VPC Offering without LB service # 1. Create VPC Offering without LB service
@ -795,6 +793,7 @@ class TestVPCNetwork(cloudstackTestCase):
# and PF,LB,NetworkAcl ) provided by VPCVR and conserve mode is OFF # and PF,LB,NetworkAcl ) provided by VPCVR and conserve mode is OFF
# 4. Create Network with the above offering # 4. Create Network with the above offering
# 5. Create network fails since VPC offering doesn't support LB # 5. Create network fails since VPC offering doesn't support LB
"""
self.debug("Creating a VPC offering without LB service") self.debug("Creating a VPC offering without LB service")
self.services["vpc_offering"][ self.services["vpc_offering"][
@ -804,7 +803,6 @@ class TestVPCNetwork(cloudstackTestCase):
self.apiclient, self.apiclient,
self.services["vpc_offering"] self.services["vpc_offering"]
) )
self.cleanup.append(vpc_off) self.cleanup.append(vpc_off)
self.validate_vpc_offering(vpc_off) self.validate_vpc_offering(vpc_off)
@ -822,6 +820,7 @@ class TestVPCNetwork(cloudstackTestCase):
account=self.account.name, account=self.account.name,
domainid=self.account.domainid domainid=self.account.domainid
) )
self.cleanup.append(vpc)
self.validate_vpc_network(vpc) self.validate_vpc_network(vpc)
self.network_offering = NetworkOffering.create( self.network_offering = NetworkOffering.create(
@ -829,15 +828,14 @@ class TestVPCNetwork(cloudstackTestCase):
self.services["network_offering"], self.services["network_offering"],
conservemode=False conservemode=False
) )
# Enable Network offering
self.network_offering.update(self.apiclient, state='Enabled')
self.cleanup.append(self.network_offering) self.cleanup.append(self.network_offering)
self.network_offering.update(self.apiclient, state='Enabled')
# Creating network using the network offering created # Creating network using the network offering created
self.debug("Creating network with network offering: %s" % self.debug("Creating network with network offering: %s" %
self.network_offering.id) self.network_offering.id)
with self.assertRaises(Exception): with self.assertRaises(Exception):
Network.create( nw = Network.create(
self.apiclient, self.apiclient,
self.services["network"], self.services["network"],
accountid=self.account.name, accountid=self.account.name,
@ -847,13 +845,13 @@ class TestVPCNetwork(cloudstackTestCase):
gateway='10.1.2.1', gateway='10.1.2.1',
vpcid=vpc.id vpcid=vpc.id
) )
self.cleanup.append(nw)
self.debug("Network creation failed as VPC doesn't have LB service") self.debug("Network creation failed as VPC doesn't have LB service")
return return
@attr(tags=["advanced", "intervlan"], required_hardware="false") @attr(tags=["advanced", "intervlan"], required_hardware="false")
def test_08_create_network_without_sourceNAT(self): def test_08_create_network_without_sourceNAT(self):
""" Test create network without sourceNAT service in VPC (should fail) """ Test create network without sourceNAT service in VPC (should fail)
"""
# Validate the following # Validate the following
# 1. Create VPC Offering by specifying supported Services- # 1. Create VPC Offering by specifying supported Services-
@ -865,6 +863,7 @@ class TestVPCNetwork(cloudstackTestCase):
# 4. Create a VPC using the above VPC offering # 4. Create a VPC using the above VPC offering
# 5. Create a network using the network offering created in step2 as # 5. Create a network using the network offering created in step2 as
# part of this VPC # part of this VPC
"""
self.debug("Creating a VPC offering without LB service") self.debug("Creating a VPC offering without LB service")
self.services["vpc_offering"][ self.services["vpc_offering"][
@ -874,7 +873,6 @@ class TestVPCNetwork(cloudstackTestCase):
self.apiclient, self.apiclient,
self.services["vpc_offering"] self.services["vpc_offering"]
) )
self.cleanup.append(vpc_off) self.cleanup.append(vpc_off)
self.validate_vpc_offering(vpc_off) self.validate_vpc_offering(vpc_off)
@ -892,6 +890,7 @@ class TestVPCNetwork(cloudstackTestCase):
account=self.account.name, account=self.account.name,
domainid=self.account.domainid domainid=self.account.domainid
) )
self.cleanup.append(vpc)
self.validate_vpc_network(vpc) self.validate_vpc_network(vpc)
self.debug("Creating network offering without SourceNAT service") self.debug("Creating network offering without SourceNAT service")
@ -909,11 +908,12 @@ class TestVPCNetwork(cloudstackTestCase):
self.debug("Creating network offering without SourceNAT") self.debug("Creating network offering without SourceNAT")
with self.assertRaises(Exception): with self.assertRaises(Exception):
NetworkOffering.create( nw = NetworkOffering.create(
self.apiclient, self.apiclient,
self.services["network_offering"], self.services["network_offering"],
conservemode=False conservemode=False
) )
self.cleanup.append(nw)
self.debug("Network creation failed as VPC doesn't have LB service") self.debug("Network creation failed as VPC doesn't have LB service")
return return
@ -921,7 +921,6 @@ class TestVPCNetwork(cloudstackTestCase):
@attr(tags=["advanced", "intervlan"]) @attr(tags=["advanced", "intervlan"])
def test_09_create_network_shared_nwoff(self, value): def test_09_create_network_shared_nwoff(self, value):
""" Test create network with shared network offering """ Test create network with shared network offering
"""
# Validate the following # Validate the following
# 1. Create VPC Offering using Default Offering # 1. Create VPC Offering using Default Offering
@ -932,6 +931,7 @@ class TestVPCNetwork(cloudstackTestCase):
# 5. Create network fails since it using shared offering # 5. Create network fails since it using shared offering
# 6. Repeat test for offering which has Netscaler as external LB # 6. Repeat test for offering which has Netscaler as external LB
# provider # provider
"""
if (value == "network_offering_vpcns" and not self.ns_configured): if (value == "network_offering_vpcns" and not self.ns_configured):
self.skipTest('Netscaler not configured: skipping test') self.skipTest('Netscaler not configured: skipping test')
@ -960,6 +960,7 @@ class TestVPCNetwork(cloudstackTestCase):
account=self.account.name, account=self.account.name,
domainid=self.account.domainid domainid=self.account.domainid
) )
self.cleanup.append(vpc)
self.validate_vpc_network(vpc) self.validate_vpc_network(vpc)
self.debug("Creating network offering with guesttype=shared") self.debug("Creating network offering with guesttype=shared")
@ -969,16 +970,15 @@ class TestVPCNetwork(cloudstackTestCase):
self.services["network_off_shared"], self.services["network_off_shared"],
conservemode=False conservemode=False
) )
# Enable Network offering
self.network_offering.update(self.apiclient, state='Enabled')
self.cleanup.append(self.network_offering) self.cleanup.append(self.network_offering)
self.network_offering.update(self.apiclient, state='Enabled')
# Creating network using the network offering created # Creating network using the network offering created
self.debug( self.debug(
"Creating network with network offering without SourceNAT: %s" % "Creating network with network offering without SourceNAT: %s" %
self.network_offering.id) self.network_offering.id)
with self.assertRaises(Exception): with self.assertRaises(Exception):
Network.create( nw = Network.create(
self.apiclient, self.apiclient,
self.services["network"], self.services["network"],
accountid=self.account.name, accountid=self.account.name,
@ -988,6 +988,7 @@ class TestVPCNetwork(cloudstackTestCase):
gateway='10.1.1.1', gateway='10.1.1.1',
vpcid=vpc.id vpcid=vpc.id
) )
self.cleanup.append(nw)
self.debug("Network creation failed") self.debug("Network creation failed")
return return
@ -995,7 +996,6 @@ class TestVPCNetwork(cloudstackTestCase):
@attr(tags=["advanced", "intervlan"]) @attr(tags=["advanced", "intervlan"])
def test_10_create_network_with_conserve_mode(self, value): def test_10_create_network_with_conserve_mode(self, value):
""" Test create network with conserve mode ON """ Test create network with conserve mode ON
"""
# Validate the following # Validate the following
# 1. Create a network offering with guest type=Isolated that has all # 1. Create a network offering with guest type=Isolated that has all
@ -1005,15 +1005,17 @@ class TestVPCNetwork(cloudstackTestCase):
# VPC # VPC
# 3. Repeat test for offering which has Netscaler as external LB # 3. Repeat test for offering which has Netscaler as external LB
# provider # provider
"""
self.debug("Creating network offering with conserve mode = ON") self.debug("Creating network offering with conserve mode = ON")
with self.assertRaises(Exception): with self.assertRaises(Exception):
NetworkOffering.create( nw = NetworkOffering.create(
self.apiclient, self.apiclient,
self.services[value], self.services[value],
conservemode=True conservemode=True
) )
self.cleanup.append(nw)
self.debug( self.debug(
"Network creation failed as VPC support nw with conserve mode OFF") "Network creation failed as VPC support nw with conserve mode OFF")
return return
@ -1714,6 +1716,7 @@ class TestVPCNetworkUpgrade(cloudstackTestCase):
account=self.account.name, account=self.account.name,
domainid=self.account.domainid domainid=self.account.domainid
) )
self.cleanup.append(vpc)
self.validate_vpc_network(vpc) self.validate_vpc_network(vpc)
nw_off = NetworkOffering.create( nw_off = NetworkOffering.create(
@ -1721,9 +1724,8 @@ class TestVPCNetworkUpgrade(cloudstackTestCase):
self.services["network_offering"], self.services["network_offering"],
conservemode=False conservemode=False
) )
# Enable Network offering
nw_off.update(self.apiclient, state='Enabled')
self.cleanup.append(nw_off) self.cleanup.append(nw_off)
nw_off.update(self.apiclient, state='Enabled')
self.services["network_offering"][ self.services["network_offering"][
"supportedservices"] = 'Vpn,Dhcp,Dns,SourceNat,UserData,Lb,StaticNat,NetworkACL' "supportedservices"] = 'Vpn,Dhcp,Dns,SourceNat,UserData,Lb,StaticNat,NetworkACL'
@ -1743,9 +1745,8 @@ class TestVPCNetworkUpgrade(cloudstackTestCase):
self.services["network_offering"], self.services["network_offering"],
conservemode=False conservemode=False
) )
# Enable Network offering
nw_off_no_pf.update(self.apiclient, state='Enabled')
self.cleanup.append(nw_off_no_pf) self.cleanup.append(nw_off_no_pf)
nw_off_no_pf.update(self.apiclient, state='Enabled')
# Creating network using the network offering created # Creating network using the network offering created
self.debug("Creating network with network offering: %s" % self.debug("Creating network with network offering: %s" %
@ -1760,6 +1761,7 @@ class TestVPCNetworkUpgrade(cloudstackTestCase):
gateway='10.1.1.1', gateway='10.1.1.1',
vpcid=vpc.id vpcid=vpc.id
) )
self.cleanup.append(network_1)
self.debug("Created network with ID: %s" % network_1.id) self.debug("Created network with ID: %s" % network_1.id)
self.debug("deploying VMs in network: %s" % network_1.name) self.debug("deploying VMs in network: %s" % network_1.name)
@ -1772,6 +1774,7 @@ class TestVPCNetworkUpgrade(cloudstackTestCase):
serviceofferingid=self.service_offering.id, serviceofferingid=self.service_offering.id,
networkids=[str(network_1.id)] networkids=[str(network_1.id)]
) )
self.cleanup.append(vm_1)
self.debug("Deployed VM in network: %s" % network_1.id) self.debug("Deployed VM in network: %s" % network_1.id)
vm_2 = VirtualMachine.create( vm_2 = VirtualMachine.create(
self.apiclient, self.apiclient,
@ -1781,6 +1784,7 @@ class TestVPCNetworkUpgrade(cloudstackTestCase):
serviceofferingid=self.service_offering.id, serviceofferingid=self.service_offering.id,
networkids=[str(network_1.id)] networkids=[str(network_1.id)]
) )
self.cleanup.append(vm_2)
self.debug("Deployed another VM in network: %s" % network_1.id) self.debug("Deployed another VM in network: %s" % network_1.id)
self.debug("Associating public IP for network: %s" % network_1.name) self.debug("Associating public IP for network: %s" % network_1.name)
@ -1852,7 +1856,7 @@ class TestVPCNetworkUpgrade(cloudstackTestCase):
self.assertEqual( self.assertEqual(
isinstance(public_ips, list), isinstance(public_ips, list),
True, True,
"List public Ip for network should list the Ip addr" "List public Ips for network should return a list"
) )
self.assertEqual( self.assertEqual(
public_ips[0].ipaddress, public_ips[0].ipaddress,
@ -1861,22 +1865,24 @@ class TestVPCNetworkUpgrade(cloudstackTestCase):
) )
self.debug("Adding NetwrokACl rules to make PF and LB accessible") self.debug("Adding NetwrokACl rules to make PF and LB accessible")
NetworkACL.create( nw_acl = NetworkACL.create(
self.apiclient, self.apiclient,
networkid=network_1.id, networkid=network_1.id,
services=self.services["lbrule"], services=self.services["lbrule"],
traffictype='Ingress' traffictype='Ingress'
) )
self.cleanup.append(nw_acl)
self.debug( self.debug(
"Adding Egress rules to network %s to access internet" % "Adding Egress rules to network %s to access internet" %
(network_1.name)) (network_1.name))
NetworkACL.create( icmp_acl = NetworkACL.create(
self.apiclient, self.apiclient,
networkid=network_1.id, networkid=network_1.id,
services=self.services["icmp_rule"], services=self.services["icmp_rule"],
traffictype='Egress' traffictype='Egress'
) )
self.cleanup.append(icmp_acl)
self.debug("Checking if we can SSH into VM_1? - IP: %s" % self.debug("Checking if we can SSH into VM_1? - IP: %s" %
public_ip_1.ipaddress.ipaddress) public_ip_1.ipaddress.ipaddress)
@ -2006,7 +2012,7 @@ class TestVPCNetworkUpgrade(cloudstackTestCase):
except Exception as e: except Exception as e:
self.fail("Failed to start VMs, %s" % e) self.fail("Failed to start VMs, %s" % e)
NATRule.create( nat_rule = NATRule.create(
self.apiclient, self.apiclient,
vm_1, vm_1,
self.services["natrule"], self.services["natrule"],
@ -2015,14 +2021,16 @@ class TestVPCNetworkUpgrade(cloudstackTestCase):
networkid=network_1.id, networkid=network_1.id,
vpcid=vpc.id vpcid=vpc.id
) )
self.cleanup.append(nat_rule)
self.debug("Adding NetwrokACl rules to make NAT rule accessible") self.debug("Adding NetwrokACl rules to make NAT rule accessible")
NetworkACL.create( nat_acl = NetworkACL.create(
self.apiclient, self.apiclient,
networkid=network_1.id, networkid=network_1.id,
services=self.services["natrule"], services=self.services["natrule"],
traffictype='Ingress' traffictype='Ingress'
) )
self.cleanup.append(nat_acl)
self.debug("Checking if we can SSH into VM using NAT rule?") self.debug("Checking if we can SSH into VM using NAT rule?")
try: try:
ssh_3 = vm_1.get_ssh_client( ssh_3 = vm_1.get_ssh_client(
@ -2612,10 +2620,12 @@ class TestRouterOperations(cloudstackTestCase):
cls.api_client, cls.api_client,
cls.services["service_offering"] cls.services["service_offering"]
) )
cls._cleanup.append(cls.service_offering)
cls.vpc_off = VpcOffering.create( cls.vpc_off = VpcOffering.create(
cls.api_client, cls.api_client,
cls.services["vpc_offering"] cls.services["vpc_offering"]
) )
cls._cleanup.append(cls.vpc_off)
cls.vpc_off.update(cls.api_client, state='Enabled') cls.vpc_off.update(cls.api_client, state='Enabled')
cls.account = Account.create( cls.account = Account.create(
@ -2635,16 +2645,16 @@ class TestRouterOperations(cloudstackTestCase):
account=cls.account.name, account=cls.account.name,
domainid=cls.account.domainid domainid=cls.account.domainid
) )
cls._cleanup.append(cls.vpc)
cls.nw_off = NetworkOffering.create( cls.nw_off = NetworkOffering.create(
cls.api_client, cls.api_client,
cls.services["network_offering"], cls.services["network_offering"],
conservemode=False conservemode=False
) )
cls._cleanup.append(cls.nw_off)
# Enable Network offering # Enable Network offering
cls.nw_off.update(cls.api_client, state='Enabled') cls.nw_off.update(cls.api_client, state='Enabled')
cls._cleanup.append(cls.nw_off)
cls._cleanup.append(cls.vpc_off)
cls.network_1 = Network.create( cls.network_1 = Network.create(
cls.api_client, cls.api_client,
@ -2656,6 +2666,7 @@ class TestRouterOperations(cloudstackTestCase):
gateway='10.1.1.1', gateway='10.1.1.1',
vpcid=cls.vpc.id vpcid=cls.vpc.id
) )
cls._cleanup.append(cls.network_1)
# Spawn an instance in that network # Spawn an instance in that network
cls.vm_1 = VirtualMachine.create( cls.vm_1 = VirtualMachine.create(
cls.api_client, cls.api_client,
@ -2665,16 +2676,12 @@ class TestRouterOperations(cloudstackTestCase):
serviceofferingid=cls.service_offering.id, serviceofferingid=cls.service_offering.id,
networkids=[str(cls.network_1.id)] networkids=[str(cls.network_1.id)]
) )
cls._cleanup.append(cls.vm_1)
return return
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestRouterOperations, cls).tearDownClass()
# 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): def setUp(self):
self.apiclient = self.testClient.getApiClient() self.apiclient = self.testClient.getApiClient()
@ -2682,7 +2689,7 @@ class TestRouterOperations(cloudstackTestCase):
return return
def tearDown(self): def tearDown(self):
return super(TestRouterOperations, self).tearDown()
@attr(tags=["advanced", "intervlan"], required_hardware="true") @attr(tags=["advanced", "intervlan"], required_hardware="true")
def test_stop_start_vpc_router(self): def test_stop_start_vpc_router(self):

View File

@ -577,7 +577,8 @@ class TestVPCNetworkInternalLBRules(cloudstackTestCase):
self.create_Internal_LB_Rule(internal_tier, vm_array=[public_vm]) self.create_Internal_LB_Rule(internal_tier, vm_array=[public_vm])
self.debug("Internal LB Rule creation failed as the VM belongs to a different network") self.debug("Internal LB Rule creation failed as the VM belongs to a different network")
@attr(tags=["advanced", "intervlan"], required_hardware="true") # tags=["advanced", "intervlan"]
@attr(tags=["TODO"], required_hardware="true")
def test_02_internallb_rules_traffic(self): def test_02_internallb_rules_traffic(self):
"""Test VPC Network Internal LB functionality by performing (wget) traffic tests within a VPC """Test VPC Network Internal LB functionality by performing (wget) traffic tests within a VPC
""" """
@ -749,7 +750,8 @@ class TestVPCNetworkInternalLBRules(cloudstackTestCase):
http_rule["publicport"] http_rule["publicport"]
) )
@attr(tags=["advanced", "intervlan"], required_hardware="true") # tags=["advanced", "intervlan"]
@attr(tags=["TODO"], required_hardware="true")
def test_03_internallb_rules_vpc_network_restarts_traffic(self): def test_03_internallb_rules_vpc_network_restarts_traffic(self):
"""Test VPC Network Internal LB functionality with restarts of VPC network components by performing (wget) """Test VPC Network Internal LB functionality with restarts of VPC network components by performing (wget)
traffic tests within a VPC traffic tests within a VPC
@ -1005,7 +1007,8 @@ class TestVPCNetworkInternalLBRules(cloudstackTestCase):
self.test_data["http_rule"]["publicport"] self.test_data["http_rule"]["publicport"]
) )
@attr(tags=["advanced", "intervlan"], required_hardware="true") # tags=["advanced", "intervlan"]
@attr(tags=["TODO"], required_hardware="true")
def test_04_internallb_appliance_operations_traffic(self): def test_04_internallb_appliance_operations_traffic(self):
"""Test VPC Network Internal LB functionality with InternalLbVm appliance operations by performing (wget) """Test VPC Network Internal LB functionality with InternalLbVm appliance operations by performing (wget)
traffic tests within a VPC traffic tests within a VPC

View File

@ -20,7 +20,6 @@
#Import Local Modules #Import Local Modules
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
from marvin.cloudstackTestCase import cloudstackTestCase from marvin.cloudstackTestCase import cloudstackTestCase
import unittest
from marvin.lib.base import (stopRouter, from marvin.lib.base import (stopRouter,
startRouter, startRouter,
Account, Account,
@ -39,7 +38,6 @@ from marvin.lib.common import (get_domain,
get_zone, get_zone,
get_template, get_template,
list_routers) list_routers)
from marvin.lib.utils import cleanup_resources
import socket import socket
import time import time
@ -206,14 +204,7 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestVPCNetworkLBRules, cls).tearDownClass()
#Cleanup resources used
cleanup_resources(cls.api_client, cls._cleanup)
except Exception as e:
print(("Warning: Exception during cleanup : %s" % e))
#raise Exception("Warning: Exception during cleanup : %s" % e)
return
def setUp(self): def setUp(self):
self.apiclient = self.testClient.getApiClient() self.apiclient = self.testClient.getApiClient()
@ -229,7 +220,6 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
self.apiclient, self.apiclient,
self.services["vpc_offering"] self.services["vpc_offering"]
) )
self.cleanup.append(self.vpc_off) self.cleanup.append(self.vpc_off)
self.debug("Enabling the VPC offering created") self.debug("Enabling the VPC offering created")
self.vpc_off.update(self.apiclient, state='Enabled') self.vpc_off.update(self.apiclient, state='Enabled')
@ -244,16 +234,11 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
account=self.account.name, account=self.account.name,
domainid=self.account.domainid domainid=self.account.domainid
) )
self.cleanup.append(self.vpc)
return return
def tearDown(self): def tearDown(self):
try: super(TestVPCNetworkLBRules, self).tearDown()
#Clean up, terminate the created network offerings
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
self.debug("Warning: Exception during cleanup : %s" % e)
#raise Exception("Warning: Exception during cleanup : %s" % e)
return
def get_Router_For_VPC(self): def get_Router_For_VPC(self):
routers = list_routers(self.apiclient, routers = list_routers(self.apiclient,
@ -271,7 +256,6 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
router = routers[0] router = routers[0]
return router return router
def stop_VPC_VRouter(self): def stop_VPC_VRouter(self):
router = self.get_Router_For_VPC() router = self.get_Router_For_VPC()
self.debug("Stopping router ID: %s" % router.id) self.debug("Stopping router ID: %s" % router.id)
@ -316,35 +300,6 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
"Check list router response for router state" "Check list router response for router state"
) )
def check_ssh_into_vm(self, vm, public_ip, testnegative=False):
self.debug("Checking if we can SSH into VM=%s on public_ip=%s" % (vm.name, public_ip.ipaddress.ipaddress))
try:
vm.get_ssh_client(ipaddress=public_ip.ipaddress.ipaddress)
if not testnegative:
self.debug("SSH into VM=%s on public_ip=%s is successfully" % (vm.name, public_ip.ipaddress.ipaddress))
else:
self.fail("SSH into VM=%s on public_ip=%s is successfully" % (vm.name, public_ip.ipaddress.ipaddress))
except:
if not testnegative:
self.fail("Failed to SSH into VM - %s" % (public_ip.ipaddress.ipaddress))
else:
self.debug("Failed to SSH into VM - %s" % (public_ip.ipaddress.ipaddress))
def check_wget_from_vm(self, vm, public_ip, testnegative=False):
import urllib.request, urllib.parse, urllib.error
self.debug("Checking if we can wget from a VM=%s http server on public_ip=%s" % (vm.name, public_ip.ipaddress.ipaddress))
try:
urllib.request.urlretrieve("http://%s/test.html" % public_ip.ipaddress.ipaddress, filename="test.html")
if not testnegative:
self.debug("Successful to wget from VM=%s http server on public_ip=%s" % (vm.name, public_ip.ipaddress.ipaddress))
else:
self.fail("Successful to wget from VM=%s http server on public_ip=%s" % (vm.name, public_ip.ipaddress.ipaddress))
except Exception as e:
if not testnegative:
self.fail("Failed to wget from VM=%s http server on public_ip=%s because of %s" % (vm.name, public_ip.ipaddress.ipaddress, e))
else:
self.debug("Failed to wget from VM=%s http server on public_ip=%s because of %s" % (vm.name, public_ip.ipaddress.ipaddress, e))
def create_StaticNatRule_For_VM(self, vm, public_ip, network): def create_StaticNatRule_For_VM(self, vm, public_ip, network):
self.debug("Enabling static NAT for IP: %s" % self.debug("Enabling static NAT for IP: %s" %
public_ip.ipaddress.ipaddress) public_ip.ipaddress.ipaddress)
@ -361,26 +316,6 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
self.fail("Failed to enable static NAT on IP: %s - %s" % ( self.fail("Failed to enable static NAT on IP: %s - %s" % (
public_ip.ipaddress.ipaddress, e)) public_ip.ipaddress.ipaddress, e))
def create_NatRule_For_VM(self, vm, public_ip, network):
self.debug("Creatinng NAT rule in network for vm with public IP")
nat_rule = NATRule.create(self.apiclient,
vm,
self.services["natrule"],
ipaddressid=public_ip.ipaddress.id,
openfirewall=False,
networkid=network.id,
vpcid=self.vpc.id
)
self.debug("Adding NetwrokACl rules to make NAT rule accessible")
nwacl_nat = NetworkACL.create(self.apiclient,
networkid=network.id,
services=self.services["natrule"],
traffictype='Ingress'
)
self.debug('nwacl_nat=%s' % nwacl_nat.__dict__)
return nat_rule
def acquire_Public_IP(self, network): def acquire_Public_IP(self, network):
self.debug("Associating public IP for network: %s" % network.name) self.debug("Associating public IP for network: %s" % network.name)
public_ip = PublicIPAddress.create(self.apiclient, public_ip = PublicIPAddress.create(self.apiclient,
@ -390,6 +325,7 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
networkid=None, #network.id, networkid=None, #network.id,
vpcid=self.vpc.id vpcid=self.vpc.id
) )
self.cleanup.append(public_ip)
self.debug("Associated %s with network %s" % (public_ip.ipaddress.ipaddress, self.debug("Associated %s with network %s" % (public_ip.ipaddress.ipaddress,
network.id network.id
)) ))
@ -402,7 +338,6 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
self.apiclient, self.apiclient,
self.services["vpc_offering"] self.services["vpc_offering"]
) )
self.cleanup.append(vpc_off) self.cleanup.append(vpc_off)
self.debug("Enabling the VPC offering created") self.debug("Enabling the VPC offering created")
vpc_off.update(self.apiclient, state='Enabled') vpc_off.update(self.apiclient, state='Enabled')
@ -417,9 +352,10 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
account=self.account.name, account=self.account.name,
domainid=self.account.domainid domainid=self.account.domainid
) )
self.cleanup.append(vpc)
return vpc return vpc
def create_Network(self, net_offerring, gateway='10.1.1.1',vpc=None): def create_network(self, net_offerring, gateway='10.1.1.1',vpc=None):
try: try:
self.debug('Create NetworkOffering') self.debug('Create NetworkOffering')
net_offerring["name"] = "NET_OFF-" + str(gateway) net_offerring["name"] = "NET_OFF-" + str(gateway)
@ -427,9 +363,9 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
net_offerring, net_offerring,
conservemode=False conservemode=False
) )
self.cleanup.append(nw_off)
# Enable Network offering # Enable Network offering
nw_off.update(self.apiclient, state='Enabled') nw_off.update(self.apiclient, state='Enabled')
self.cleanup.append(nw_off)
self.debug('Created and Enabled NetworkOffering') self.debug('Created and Enabled NetworkOffering')
self.services["network"]["name"] = "NETWORK-" + str(gateway) self.services["network"]["name"] = "NETWORK-" + str(gateway)
@ -443,6 +379,7 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
gateway=gateway, gateway=gateway,
vpcid=vpc.id if vpc else self.vpc.id vpcid=vpc.id if vpc else self.vpc.id
) )
self.cleanup.append(obj_network)
self.debug("Created network with ID: %s" % obj_network.id) self.debug("Created network with ID: %s" % obj_network.id)
return obj_network return obj_network
except: except:
@ -460,6 +397,7 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
networkids=[str(network.id)], networkids=[str(network.id)],
hostid=host_id hostid=host_id
) )
self.cleanup.append(vm)
self.debug('Created VM=%s in network=%s' % (vm.id, network.name)) self.debug('Created VM=%s in network=%s' % (vm.id, network.name))
return vm return vm
@ -493,24 +431,13 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
networkid=network.id, networkid=network.id,
traffictype='Ingress' traffictype='Ingress'
) )
self.cleanup.append(nwacl_nat)
self.debug('nwacl_nat=%s' % nwacl_nat.__dict__) self.debug('nwacl_nat=%s' % nwacl_nat.__dict__)
return lb_rule return lb_rule
def create_egress_Internet_Rule(self, network):
self.debug("Adding Egress rules to network %s and %s to allow access to internet" % (network.name,self.services["http_rule"]))
nwacl_internet_1 = NetworkACL.create(
self.apiclient,
networkid=network.id,
services=self.services["http_rule"],
traffictype='Egress'
)
return nwacl_internet_1
@attr(tags=["advanced", "intervlan"], required_hardware="false") @attr(tags=["advanced", "intervlan"], required_hardware="false")
def test_01_VPC_LBRulesListing(self): def test_01_VPC_LBRulesListing(self):
""" Test case no 210 and 227: List Load Balancing Rules belonging to a VPC """ Test case no 210 and 227: List Load Balancing Rules belonging to a VPC
"""
# Validate the following # Validate the following
# 1. Create a VPC with cidr - 10.1.1.1/16 # 1. Create a VPC with cidr - 10.1.1.1/16
@ -523,16 +450,17 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
# 8. Use the Create LB rule for vm3 amd vm4 in network2, should fail # 8. Use the Create LB rule for vm3 amd vm4 in network2, should fail
# because it's no_lb offering # because it's no_lb offering
# 9. List LB rule # 9. List LB rule
"""
network_1 = self.create_Network(self.services["network_offering"]) network_1 = self.create_network(self.services["network_offering"])
network_2 = self.create_Network(self.services["network_offering_no_lb"], '10.1.2.1') network_2 = self.create_network(self.services["network_offering_no_lb"], '10.1.2.1')
self.debug("deploying VMs in network: %s" % network_2.name) self.debug("deploying VMs in network: %s" % network_2.name)
vm_1 = self.create_VM_in_Network(network_1) vm_1 = self.create_VM_in_Network(network_1)
vm_2 = self.create_VM_in_Network(network_1) vm_2 = self.create_VM_in_Network(network_1)
vm_3 = self.create_VM_in_Network(network_2) vm_3 = self.create_VM_in_Network(network_2)
vm_4 = self.create_VM_in_Network(network_2) vm_4 = self.create_VM_in_Network(network_2)
public_ip_1 = self.acquire_Public_IP(network_1) public_ip_1 = self.acquire_Public_IP(network_1)
lb_rule1 = self.create_LB_Rule(public_ip_1, network_1, [vm_1, vm_2]) # lb_rule1 = self.create_LB_Rule(public_ip_1, network_1, [vm_1, vm_2])
public_ip_2 = self.acquire_Public_IP(network_2) public_ip_2 = self.acquire_Public_IP(network_2)
with self.assertRaises(Exception): with self.assertRaises(Exception):
self.create_LB_Rule(public_ip_2, network_2, [vm_3, vm_4]) self.create_LB_Rule(public_ip_2, network_2, [vm_3, vm_4])
@ -559,7 +487,6 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
def test_02_VPC_CreateLBRuleInMultipleNetworks(self): def test_02_VPC_CreateLBRuleInMultipleNetworks(self):
""" Test Create LB rules for 1 network which is part of a two/multiple virtual networks of a """ Test Create LB rules for 1 network which is part of a two/multiple virtual networks of a
VPC using a new Public IP Address available with the VPC when the Virtual Router is in Running State VPC using a new Public IP Address available with the VPC when the Virtual Router is in Running State
"""
# Validate the following # Validate the following
# 1. Create a VPC with cidr - 10.1.1.1/16 # 1. Create a VPC with cidr - 10.1.1.1/16
@ -569,14 +496,16 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
# 5. Use the Create LB rule for vm1 and vm2 in network1. # 5. Use the Create LB rule for vm1 and vm2 in network1.
# 6. Add vm3 to LB rule. # 6. Add vm3 to LB rule.
# 7. wget a file and check for LB rule. # 7. wget a file and check for LB rule.
"""
network_1 = self.create_Network(self.services["network_offering"]) network_1 = self.create_network(self.services["network_offering"])
vm_1 = self.create_VM_in_Network(network_1) vm_1 = self.create_VM_in_Network(network_1)
vm_2 = self.create_VM_in_Network(network_1) vm_2 = self.create_VM_in_Network(network_1)
vm_3 = self.create_VM_in_Network(network_1) vm_3 = self.create_VM_in_Network(network_1)
public_ip_1 = self.acquire_Public_IP(network_1) public_ip_1 = self.acquire_Public_IP(network_1)
lb_rule = self.create_LB_Rule(public_ip_1, network_1, [vm_1, vm_2], self.services["lbrule_http"]) lb_rule = self.create_LB_Rule(public_ip_1, network_1, [vm_1, vm_2], self.services["lbrule_http"])
lb_rule.assign(self.apiclient, [vm_3]) lb_rule.assign(self.apiclient, [vm_3])
self.create_LB_Rule(public_ip_1, network_1, [vm_1, vm_2])
self.check_wget_from_vm(vm_1, public_ip_1, testnegative=False) self.check_wget_from_vm(vm_1, public_ip_1, testnegative=False)
return return
@ -584,7 +513,6 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
def test_03_VPC_CreateLBRuleInMultipleNetworksVRStoppedState(self): def test_03_VPC_CreateLBRuleInMultipleNetworksVRStoppedState(self):
""" Test case no 222 : Create LB rules for a two/multiple virtual networks of a """ Test case no 222 : Create LB rules for a two/multiple virtual networks of a
VPC using a new Public IP Address available with the VPC when the Virtual Router is in Stopped State VPC using a new Public IP Address available with the VPC when the Virtual Router is in Stopped State
"""
# Validate the following # Validate the following
# 1. Create a VPC with cidr - 10.1.1.1/16 # 1. Create a VPC with cidr - 10.1.1.1/16
@ -595,9 +523,10 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
# 7. Use the Create LB rule for vm1 and vm2 in network1. # 7. Use the Create LB rule for vm1 and vm2 in network1.
# 8. Add vm3 to LB rule. # 8. Add vm3 to LB rule.
# 9. wget a file and check for LB rule. # 9. wget a file and check for LB rule.
"""
network_1 = self.create_Network(self.services["network_offering"]) network_1 = self.create_network(self.services["network_offering"])
network_2 = self.create_Network(self.services["network_offering_no_lb"], '10.1.2.1') network_2 = self.create_network(self.services["network_offering_no_lb"], '10.1.2.1')
vm_1 = self.create_VM_in_Network(network_1) vm_1 = self.create_VM_in_Network(network_1)
vm_2 = self.create_VM_in_Network(network_1) vm_2 = self.create_VM_in_Network(network_1)
vm_3 = self.create_VM_in_Network(network_1) vm_3 = self.create_VM_in_Network(network_1)
@ -613,6 +542,7 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
self.start_VPC_VRouter(router) self.start_VPC_VRouter(router)
self.create_LB_Rule(public_ip_1, network_1, [vm_1, vm_2])
self.check_wget_from_vm(vm_1, public_ip_1, testnegative=False) self.check_wget_from_vm(vm_1, public_ip_1, testnegative=False)
return return
@ -620,7 +550,6 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
def test_04_VPC_CreateLBRuleInMultipleNetworksVRStoppedState(self): def test_04_VPC_CreateLBRuleInMultipleNetworksVRStoppedState(self):
""" Test case no 222 : Create LB rules for a two/multiple virtual networks of a """ Test case no 222 : Create LB rules for a two/multiple virtual networks of a
VPC using a new Public IP Address available with the VPC when the Virtual Router is in Stopped State VPC using a new Public IP Address available with the VPC when the Virtual Router is in Stopped State
"""
# Validate the following # Validate the following
# 1. Create a VPC with cidr - 10.1.1.1/16 # 1. Create a VPC with cidr - 10.1.1.1/16
@ -631,9 +560,10 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
# 7. Use the Create LB rule for vm1 and vm2 in network1. # 7. Use the Create LB rule for vm1 and vm2 in network1.
# 8. Add vm3 to LB rule. # 8. Add vm3 to LB rule.
# 9. wget a file and check for LB rule. # 9. wget a file and check for LB rule.
"""
network_1 = self.create_Network(self.services["network_offering"]) network_1 = self.create_network(self.services["network_offering"])
network_2 = self.create_Network(self.services["network_offering_no_lb"], '10.1.2.1') network_2 = self.create_network(self.services["network_offering_no_lb"], '10.1.2.1')
vm_1 = self.create_VM_in_Network(network_1) vm_1 = self.create_VM_in_Network(network_1)
vm_2 = self.create_VM_in_Network(network_1) vm_2 = self.create_VM_in_Network(network_1)
vm_3 = self.create_VM_in_Network(network_2) vm_3 = self.create_VM_in_Network(network_2)
@ -643,6 +573,7 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
# http://cloudstack.apache.org/docs/en-US/Apache_CloudStack/4.0.2/html/Installation_Guide/configure-vpc.html # http://cloudstack.apache.org/docs/en-US/Apache_CloudStack/4.0.2/html/Installation_Guide/configure-vpc.html
with self.assertRaises(Exception): with self.assertRaises(Exception):
lb_rule.assign(self.apiclient, [vm_3]) lb_rule.assign(self.apiclient, [vm_3])
self.create_LB_Rule(public_ip_1, network_1, [vm_1, vm_2])
self.check_wget_from_vm(vm_1, public_ip_1, testnegative=False) self.check_wget_from_vm(vm_1, public_ip_1, testnegative=False)
return return
@ -650,7 +581,6 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
def test_05_VPC_CreateAndDeleteLBRule(self): def test_05_VPC_CreateAndDeleteLBRule(self):
""" Test case no 214 : Delete few(not all) LB rules for a single virtual network of a """ Test case no 214 : Delete few(not all) LB rules for a single virtual network of a
VPC belonging to a single Public IP Address when the Virtual Router is in Running State VPC belonging to a single Public IP Address when the Virtual Router is in Running State
"""
# Validate the following # Validate the following
# 1. Create a VPC with cidr - 10.1.1.1/16 # 1. Create a VPC with cidr - 10.1.1.1/16
@ -662,8 +592,9 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
# 7. wget and ssh and check for LB rule. # 7. wget and ssh and check for LB rule.
# 8. Delete ssh LB Rule. # 8. Delete ssh LB Rule.
# 9. ssh LB should fail. # 9. ssh LB should fail.
"""
network_1 = self.create_Network(self.services["network_offering"]) network_1 = self.create_network(self.services["network_offering"])
vm_1 = self.create_VM_in_Network(network_1) vm_1 = self.create_VM_in_Network(network_1)
vm_2 = self.create_VM_in_Network(network_1) vm_2 = self.create_VM_in_Network(network_1)
vm_3 = self.create_VM_in_Network(network_1) vm_3 = self.create_VM_in_Network(network_1)
@ -681,7 +612,6 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
def test_06_VPC_CreateAndDeleteLBRuleVRStopppedState(self): def test_06_VPC_CreateAndDeleteLBRuleVRStopppedState(self):
""" Test Delete few(not all) LB rules for a single virtual network of """ Test Delete few(not all) LB rules for a single virtual network of
a VPC belonging to a single Public IP Address when the Virtual Router is in Stopped State a VPC belonging to a single Public IP Address when the Virtual Router is in Stopped State
"""
# Validate the following # Validate the following
# 1. Create a VPC with cidr - 10.1.1.1/16 # 1. Create a VPC with cidr - 10.1.1.1/16
@ -693,8 +623,9 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
# 7. wget and ssh and check for LB rule. # 7. wget and ssh and check for LB rule.
# 8. Delete ssh LB Rule. # 8. Delete ssh LB Rule.
# 9. ssh LB should fail. # 9. ssh LB should fail.
"""
network_1 = self.create_Network(self.services["network_offering"]) network_1 = self.create_network(self.services["network_offering"])
vm_1 = self.create_VM_in_Network(network_1) vm_1 = self.create_VM_in_Network(network_1)
vm_2 = self.create_VM_in_Network(network_1) vm_2 = self.create_VM_in_Network(network_1)
vm_3 = self.create_VM_in_Network(network_1) vm_3 = self.create_VM_in_Network(network_1)
@ -718,7 +649,6 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
def test_07_VPC_CreateAndDeleteAllLBRule(self): def test_07_VPC_CreateAndDeleteAllLBRule(self):
""" Test Delete all LB rules for a single virtual network of a """ Test Delete all LB rules for a single virtual network of a
VPC belonging to a single Public IP Address when the Virtual Router is in Running State VPC belonging to a single Public IP Address when the Virtual Router is in Running State
"""
# Validate the following # Validate the following
# 1. Create a VPC with cidr - 10.1.1.1/16 # 1. Create a VPC with cidr - 10.1.1.1/16
@ -730,8 +660,9 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
# 7. wget and ssh and check for LB rule. # 7. wget and ssh and check for LB rule.
# 8. Delete all LB Rule. # 8. Delete all LB Rule.
# 9. ssh and http LB should fail. # 9. ssh and http LB should fail.
"""
network_1 = self.create_Network(self.services["network_offering"]) network_1 = self.create_network(self.services["network_offering"])
vm_1 = self.create_VM_in_Network(network_1) vm_1 = self.create_VM_in_Network(network_1)
vm_2 = self.create_VM_in_Network(network_1) vm_2 = self.create_VM_in_Network(network_1)
vm_3 = self.create_VM_in_Network(network_1) vm_3 = self.create_VM_in_Network(network_1)
@ -751,7 +682,6 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
def test_08_VPC_CreateAndDeleteAllLBRuleVRStoppedState(self): def test_08_VPC_CreateAndDeleteAllLBRuleVRStoppedState(self):
""" Test Delete all LB rules for a single virtual network of a """ Test Delete all LB rules for a single virtual network of a
VPC belonging to a single Public IP Address when the Virtual Router is in Stopped State VPC belonging to a single Public IP Address when the Virtual Router is in Stopped State
"""
# Validate the following # Validate the following
# 1. Create a VPC with cidr - 10.1.1.1/16 # 1. Create a VPC with cidr - 10.1.1.1/16
@ -763,8 +693,12 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
# 7. wget and ssh and check for LB rule. # 7. wget and ssh and check for LB rule.
# 8. Delete all LB Rule. # 8. Delete all LB Rule.
# 9. ssh and http LB should fail. # 9. ssh and http LB should fail.
"""
network_1 = self.create_Network(self.services["network_offering"]) # same as test_07 so
self.skipTest("duplicate test")
network_1 = self.create_network(self.services["network_offering"])
vm_1 = self.create_VM_in_Network(network_1) vm_1 = self.create_VM_in_Network(network_1)
vm_2 = self.create_VM_in_Network(network_1) vm_2 = self.create_VM_in_Network(network_1)
vm_3 = self.create_VM_in_Network(network_1) vm_3 = self.create_VM_in_Network(network_1)
@ -783,7 +717,6 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
@attr(tags=["advanced", "intervlan"], required_hardware="true") @attr(tags=["advanced", "intervlan"], required_hardware="true")
def test_09_VPC_LBRuleCreateFailMultipleVPC(self): def test_09_VPC_LBRuleCreateFailMultipleVPC(self):
""" Test User should not be allowed to create a LB rule for a VM that belongs to a different VPC. """ Test User should not be allowed to create a LB rule for a VM that belongs to a different VPC.
"""
# Validate the following # Validate the following
# 1. Create a VPC1 with cidr - 10.1.1.1/16 # 1. Create a VPC1 with cidr - 10.1.1.1/16
@ -798,18 +731,20 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
# 9. wget and check LB Rule # 9. wget and check LB Rule
# 10. create LB rule for vm3 and vm4 in VPC1 # 10. create LB rule for vm3 and vm4 in VPC1
# 11. LB rule creation should fail # 11. LB rule creation should fail
"""
network_1 = self.create_Network(self.services["network_offering"]) network_1 = self.create_network(self.services["network_offering"])
vm_1 = self.create_VM_in_Network(network_1) vm_1 = self.create_VM_in_Network(network_1)
vm_2 = self.create_VM_in_Network(network_1) vm_2 = self.create_VM_in_Network(network_1)
vpc2 = self.create_VPC() vpc2 = self.create_VPC()
network_2 = self.create_Network(self.services["network_offering_no_lb"], '10.1.2.1',vpc2) network_2 = self.create_network(self.services["network_offering_no_lb"], '10.1.2.1',vpc2)
vm_3 = self.create_VM_in_Network(network_2) vm_3 = self.create_VM_in_Network(network_2)
vm_4 = self.create_VM_in_Network(network_2) vm_4 = self.create_VM_in_Network(network_2)
public_ip_1 = self.acquire_Public_IP(network_1) public_ip_1 = self.acquire_Public_IP(network_1)
lb_rule = self.create_LB_Rule(public_ip_1, network_1, [vm_1, vm_2], self.services["lbrule_http"]) lb_rule = self.create_LB_Rule(public_ip_1, network_1, [vm_1, vm_2], self.services["lbrule_http"])
self.debug('lb_rule=%s' % lb_rule.__dict__) self.debug('lb_rule=%s' % lb_rule.__dict__)
self.create_LB_Rule(public_ip_1, network_1, [vm_1, vm_2])
self.check_wget_from_vm(vm_1, public_ip_1, testnegative=False) self.check_wget_from_vm(vm_1, public_ip_1, testnegative=False)
try: try:
lb_rule = self.create_LB_Rule(public_ip_1, network_1, [vm_3, vm_4], self.services["lbrule_http"]) lb_rule = self.create_LB_Rule(public_ip_1, network_1, [vm_3, vm_4], self.services["lbrule_http"])
@ -821,7 +756,6 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
@attr(tags=["advanced", "intervlan"], required_hardware="false") @attr(tags=["advanced", "intervlan"], required_hardware="false")
def test_10_VPC_FailedToCreateLBRuleNonVPCNetwork(self): def test_10_VPC_FailedToCreateLBRuleNonVPCNetwork(self):
""" Test User should not be allowed to create a LB rule for a VM that does not belong to any VPC. """ Test User should not be allowed to create a LB rule for a VM that does not belong to any VPC.
"""
# Validate the following # Validate the following
# 1. Create a VPC1 with cidr - 10.1.1.1/16 # 1. Create a VPC1 with cidr - 10.1.1.1/16
@ -835,13 +769,14 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
# 9. wget and check LB Rule # 9. wget and check LB Rule
# 10. create LB rule for vm3 and vm4 in VPC1 # 10. create LB rule for vm3 and vm4 in VPC1
# 11. LB rule creation should fail # 11. LB rule creation should fail
"""
network_1 = self.create_Network(self.services["network_offering"]) network_1 = self.create_network(self.services["network_offering"])
vm_1 = self.create_VM_in_Network(network_1) vm_1 = self.create_VM_in_Network(network_1)
vm_2 = self.create_VM_in_Network(network_1) vm_2 = self.create_VM_in_Network(network_1)
network_2 = self.create_Network(self.services["network_offering_no_lb"], '10.1.2.1') network_2 = self.create_network(self.services["network_offering_no_lb"], '10.1.2.1')
vm_3 = self.create_VM_in_Network(network_2) vm_3 = self.create_VM_in_Network(network_2)
network_3 = self.create_Network(self.services["network_offering_no_lb"], '10.1.3.1') network_3 = self.create_network(self.services["network_offering_no_lb"], '10.1.3.1')
vm_4 = self.create_VM_in_Network(network_3) vm_4 = self.create_VM_in_Network(network_3)
self.debug('vm_4=%s' % vm_4.id) self.debug('vm_4=%s' % vm_4.id)
public_ip_1 = self.acquire_Public_IP(network_1) public_ip_1 = self.acquire_Public_IP(network_1)
@ -859,7 +794,6 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
def test_11_VPC_LBRuleCreateNotAllowed(self): def test_11_VPC_LBRuleCreateNotAllowed(self):
""" Test case no 217 and 236: User should not be allowed to create a LB rule for a """ Test case no 217 and 236: User should not be allowed to create a LB rule for a
VM that does not belong to the same network but belongs to the same VPC. VM that does not belong to the same network but belongs to the same VPC.
"""
# Validate the following # Validate the following
# 1. Create a VPC1 with cidr - 10.1.1.1/16 # 1. Create a VPC1 with cidr - 10.1.1.1/16
@ -873,18 +807,20 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
# 9. wget and check LB Rule # 9. wget and check LB Rule
# 10. create LB rule for vm3 and vm1 in VPC1 # 10. create LB rule for vm3 and vm1 in VPC1
# 11. LB rule creation should fail # 11. LB rule creation should fail
"""
network_1 = self.create_Network(self.services["network_offering"]) network_1 = self.create_network(self.services["network_offering"])
vm_1 = self.create_VM_in_Network(network_1) vm_1 = self.create_VM_in_Network(network_1)
vm_2 = self.create_VM_in_Network(network_1) vm_2 = self.create_VM_in_Network(network_1)
network_2 = self.create_Network(self.services["network_offering_no_lb"], '10.1.2.1') network_2 = self.create_network(self.services["network_offering_no_lb"], '10.1.2.1')
vm_3 = self.create_VM_in_Network(network_2) vm_3 = self.create_VM_in_Network(network_2)
vm_4 = self.create_VM_in_Network(network_2) vm_4 = self.create_VM_in_Network(network_2)
self.debug('vm_4=%s' % vm_4.id) self.debug('vm_4=%s' % vm_4.id)
public_ip_1 = self.acquire_Public_IP(network_1) public_ip_1 = self.acquire_Public_IP(network_1)
lb_rule = self.create_LB_Rule(public_ip_1, network_1, [vm_1, vm_2], self.services["lbrule_http"]) lb_rule = self.create_LB_Rule(public_ip_1, network_1, [vm_1, vm_2], self.services["lbrule_http"])
self.debug('lb_rule=%s' % lb_rule.__dict__) self.debug('lb_rule=%s' % lb_rule.__dict__)
self.create_LB_Rule(public_ip_1, network_1, [vm_1, vm_2])
self.check_wget_from_vm(vm_1, public_ip_1, testnegative=False) self.check_wget_from_vm(vm_1, public_ip_1, testnegative=False)
try: try:
lb_rule = self.create_LB_Rule(public_ip_1, network_1, [vm_3, vm_1], self.services["lbrule_http"]) lb_rule = self.create_LB_Rule(public_ip_1, network_1, [vm_3, vm_1], self.services["lbrule_http"])
@ -896,7 +832,6 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
@attr(tags=["advanced", "intervlan"], required_hardware="false") @attr(tags=["advanced", "intervlan"], required_hardware="false")
def test_12_VPC_LBRuleCreateFailForRouterIP(self): def test_12_VPC_LBRuleCreateFailForRouterIP(self):
""" Test User should not be allowed to create a LB rule on an Ipaddress that Source Nat enabled. """ Test User should not be allowed to create a LB rule on an Ipaddress that Source Nat enabled.
"""
# Validate the following # Validate the following
# 1. Create a VPC1 with cidr - 10.1.1.1/16 # 1. Create a VPC1 with cidr - 10.1.1.1/16
@ -907,8 +842,9 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
# 6. Get source NAT public ip of router # 6. Get source NAT public ip of router
# 7. Use the Create LB rule for vm1 and vm2 in network1. # 7. Use the Create LB rule for vm1 and vm2 in network1.
# 8. LB rule creation should fail # 8. LB rule creation should fail
"""
network_1 = self.create_Network(self.services["network_offering"]) network_1 = self.create_network(self.services["network_offering"])
vm_1 = self.create_VM_in_Network(network_1) vm_1 = self.create_VM_in_Network(network_1)
vm_2 = self.create_VM_in_Network(network_1) vm_2 = self.create_VM_in_Network(network_1)
router = self.get_Router_For_VPC() router = self.get_Router_For_VPC()
@ -924,7 +860,6 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
@attr(tags=["advanced", "intervlan"], required_hardware="true") @attr(tags=["advanced", "intervlan"], required_hardware="true")
def test_13_VPC_LBRuleCreateFailForPFSourceNATIP(self): def test_13_VPC_LBRuleCreateFailForPFSourceNATIP(self):
""" Test User should not be allowed to create a LB rule on an Ipaddress that already has a PF rule. """ Test User should not be allowed to create a LB rule on an Ipaddress that already has a PF rule.
"""
# Validate the following # Validate the following
# 1. Create a VPC1 with cidr - 10.1.1.1/16 # 1. Create a VPC1 with cidr - 10.1.1.1/16
@ -936,12 +871,13 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
# 6. Create a PP rule for vm1 # 6. Create a PP rule for vm1
# 7. Use the Create LB rule for vm1 and vm2 in network1. # 7. Use the Create LB rule for vm1 and vm2 in network1.
# 8. LB rule creation should fail # 8. LB rule creation should fail
"""
network_1 = self.create_Network(self.services["network_offering"]) network_1 = self.create_network(self.services["network_offering"])
vm_1 = self.create_VM_in_Network(network_1) vm_1 = self.create_VM_in_Network(network_1)
vm_2 = self.create_VM_in_Network(network_1) vm_2 = self.create_VM_in_Network(network_1)
public_ip_1 = self.acquire_Public_IP(network_1) public_ip_1 = self.acquire_Public_IP(network_1)
nat_rule1 = self.create_NatRule_For_VM(vm_1, public_ip_1, network_1) nat_rule1 = self.create_natrule_for_services(vm_1, public_ip_1, network_1)
self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False)
self.debug('nat_rule1=%s' % nat_rule1.__dict__) self.debug('nat_rule1=%s' % nat_rule1.__dict__)
try: try:
@ -954,7 +890,6 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
@attr(tags=["advanced", "intervlan"], required_hardware="false") @attr(tags=["advanced", "intervlan"], required_hardware="false")
def test_14_VPC_LBRuleCreateFailForStaticNatRule(self): def test_14_VPC_LBRuleCreateFailForStaticNatRule(self):
""" Test User should not be allowed to create a LB rule on an Ipaddress that already has a Static Nat rule. """ Test User should not be allowed to create a LB rule on an Ipaddress that already has a Static Nat rule.
"""
# Validate the following # Validate the following
# 1. Create a VPC1 with cidr - 10.1.1.1/16 # 1. Create a VPC1 with cidr - 10.1.1.1/16
@ -967,8 +902,9 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
# 8. Succesessfully wget a file from vm1. # 8. Succesessfully wget a file from vm1.
# 9. Use the Create LB rule for vm1 and vm2 in network1. # 9. Use the Create LB rule for vm1 and vm2 in network1.
# 10. LB rule creation should fail. # 10. LB rule creation should fail.
"""
network_1 = self.create_Network(self.services["network_offering"]) network_1 = self.create_network(self.services["network_offering"])
vm_1 = self.create_VM_in_Network(network_1) vm_1 = self.create_VM_in_Network(network_1)
vm_2 = self.create_VM_in_Network(network_1) vm_2 = self.create_VM_in_Network(network_1)
public_ip_1 = self.acquire_Public_IP(network_1) public_ip_1 = self.acquire_Public_IP(network_1)
@ -983,7 +919,6 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
@attr(tags=["advanced", "intervlan"], required_hardware="false") @attr(tags=["advanced", "intervlan"], required_hardware="false")
def test_15_VPC_ReleaseIPForLBRuleCreated(self): def test_15_VPC_ReleaseIPForLBRuleCreated(self):
""" Test release Ip address that has a LB rule assigned to it. """ Test release Ip address that has a LB rule assigned to it.
"""
# Validate the following # Validate the following
# 1. Create a VPC1 with cidr - 10.1.1.1/16 # 1. Create a VPC1 with cidr - 10.1.1.1/16
@ -995,13 +930,15 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
# 6. Create a StaticNat Rule rule for vm1 # 6. Create a StaticNat Rule rule for vm1
# 7. Use the Create LB rule for vm1 and vm2 in network1. # 7. Use the Create LB rule for vm1 and vm2 in network1.
# 8. LB rule creation should fail # 8. LB rule creation should fail
"""
network_1 = self.create_Network(self.services["network_offering"]) network_1 = self.create_network(self.services["network_offering"])
vm_1 = self.create_VM_in_Network(network_1) vm_1 = self.create_VM_in_Network(network_1)
vm_2 = self.create_VM_in_Network(network_1) vm_2 = self.create_VM_in_Network(network_1)
public_ip_1 = self.acquire_Public_IP(network_1) public_ip_1 = self.acquire_Public_IP(network_1)
lb_rule = self.create_LB_Rule(public_ip_1, network_1, [vm_2, vm_1]) lb_rule = self.create_LB_Rule(public_ip_1, network_1, [vm_2, vm_1])
public_ip_1.delete(self.apiclient) public_ip_1.delete(self.apiclient)
self.cleanup.remove(public_ip_1)
with self.assertRaises(Exception): with self.assertRaises(Exception):
lb_rules = LoadBalancerRule.list(self.apiclient, lb_rules = LoadBalancerRule.list(self.apiclient,

View File

@ -41,7 +41,6 @@ from marvin.lib.common import (
get_zone, get_zone,
get_template, get_template,
list_routers) list_routers)
from marvin.lib.utils import cleanup_resources
class Services: class Services:
@ -286,7 +285,6 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
return router return router
def start_vpcrouter(self, router): def start_vpcrouter(self, router):
# Start the VPC Router
self.debug("Starting router ID: %s" % router.id) self.debug("Starting router ID: %s" % router.id)
cmd = startRouter.startRouterCmd() cmd = startRouter.startRouterCmd()
cmd.id = router.id cmd.id = router.id
@ -307,93 +305,6 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
"Check list router response for router state" "Check list router response for router state"
) )
def check_ssh_into_vm(self, vm, public_ip, testnegative=False):
self.debug("Checking if we can SSH into VM=%s on public_ip=%s" % (vm.name, public_ip.ipaddress.ipaddress))
try:
vm.get_ssh_client(ipaddress=public_ip.ipaddress.ipaddress)
if not testnegative:
self.debug("SSH into VM=%s on public_ip=%s is successfully" % (vm.name, public_ip.ipaddress.ipaddress))
else:
self.fail("SSH into VM=%s on public_ip=%s is successfully" % (vm.name, public_ip.ipaddress.ipaddress))
except:
if not testnegative:
self.fail("Failed to SSH into VM - %s" % (public_ip.ipaddress.ipaddress))
else:
self.debug("Failed to SSH into VM - %s" % (public_ip.ipaddress.ipaddress))
def check_wget_from_vm(self, vm, public_ip, network=None, testnegative=False, isVmAccessible=True):
import urllib.request, urllib.error
self.debug("Checking if we can wget from a VM=%s http server on public_ip=%s" % (vm.name, public_ip.ipaddress.ipaddress))
try:
if not isVmAccessible:
self.create_natrule(vm, public_ip, network)
self.setup_webserver(vm)
urllib.request.urlretrieve("http://%s/test.html" % public_ip.ipaddress.ipaddress, filename="test.html")
if not testnegative:
self.debug("Successesfull to wget from VM=%s http server on public_ip=%s" % (vm.name, public_ip.ipaddress.ipaddress))
else:
self.fail("Successesfull to wget from VM=%s http server on public_ip=%s" % (vm.name, public_ip.ipaddress.ipaddress))
except Exception as e:
if not testnegative:
self.fail("Failed to wget from VM=%s http server on public_ip=%s: %s" % (vm.name, public_ip.ipaddress.ipaddress, e))
else:
self.debug("Failed to wget from VM=%s http server on public_ip=%s: %s" % (vm.name, public_ip.ipaddress.ipaddress, e))
def setup_webserver(self, vm):
# Start httpd service on VM first
sshClient = vm.get_ssh_client()
# Test to see if we are on a tiny linux box (using busybox)
res = str(sshClient.execute("busybox")).lower()
if "hexdump" in res:
self.setup_busybox(sshClient)
else:
self.setup_apache(sshClient)
def setup_busybox(self, sshClient):
""" Create a dummy test.html file and fire up the busybox web server """
sshClient.execute('echo test > test.html')
sshClient.execute("/usr/sbin/httpd")
self.debug("Setup webserver using busybox")
def setup_apache(self, sshClient):
sshClient.execute("service httpd start")
time.sleep(5)
ssh_response = str(sshClient.execute("service httpd status")).lower()
self.debug("httpd service status is: %s" % ssh_response)
if "httpd: unrecognized service" in ssh_response or "inactive" in ssh_response:
ssh_res = sshClient.execute("yum install httpd -y")
if "Complete!" not in ssh_res:
raise Exception("Failed to install http server")
sshClient.execute("service httpd start")
time.sleep(5)
ssh_response = str(sshClient.execute("service httpd status")).lower()
if not "running" in ssh_response:
raise Exception("Failed to start httpd service")
self.debug("Setup webserver using apache")
def create_natrule(self, vm, public_ip, network, services=None):
self.debug("Creating NAT rule in network for vm with public IP")
if not services:
services = self.services["natrule"]
nat_rule = NATRule.create(self.apiclient,
vm,
services,
ipaddressid=public_ip.ipaddress.id,
openfirewall=False,
networkid=network.id,
vpcid=self.vpc.id
)
self.debug("Adding NetworkACL rules to make NAT rule accessible")
nwacl_nat = NetworkACL.create(self.apiclient,
networkid=network.id,
services=services,
traffictype='Ingress'
)
self.debug('nwacl_nat=%s' % nwacl_nat.__dict__)
return nat_rule
def acquire_publicip(self, network): def acquire_publicip(self, network):
self.debug("Associating public IP for network: %s" % network.name) self.debug("Associating public IP for network: %s" % network.name)
public_ip = PublicIPAddress.create(self.apiclient, public_ip = PublicIPAddress.create(self.apiclient,
@ -403,64 +314,12 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
networkid=network.id, networkid=network.id,
vpcid=self.vpc.id vpcid=self.vpc.id
) )
self.cleanup.append(public_ip)
self.debug("Associated %s with network %s" % (public_ip.ipaddress.ipaddress, self.debug("Associated %s with network %s" % (public_ip.ipaddress.ipaddress,
network.id network.id
)) ))
return public_ip return public_ip
def create_vpc(self, cidr='10.1.2.1/16'):
self.debug("Creating a VPC offering..")
self.services["vpc_offering"]["name"] = self.services["vpc_offering"]["name"] + str(cidr)
vpc_off = VpcOffering.create(
self.apiclient,
self.services["vpc_offering"]
)
self._cleanup.append(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.name)
self.services["vpc"]["cidr"] = cidr
vpc = VPC.create(
self.apiclient,
self.services["vpc"],
vpcofferingid=vpc_off.id,
zoneid=self.zone.id,
account=self.account.name,
domainid=self.account.domainid
)
return vpc
def create_network(self, net_offerring, gateway='10.1.1.1', vpc=None):
try:
self.debug('Create NetworkOffering')
net_offerring["name"] = "NET_OFF-" + str(gateway)
nw_off = NetworkOffering.create(self.apiclient,
net_offerring,
conservemode=False
)
# Enable Network offering
nw_off.update(self.apiclient, state='Enabled')
self._cleanup.append(nw_off)
self.debug('Created and Enabled NetworkOffering')
self.services["network"]["name"] = "NETWORK-" + str(gateway)
self.debug('Adding Network=%s' % self.services["network"])
obj_network = Network.create(self.apiclient,
self.services["network"],
accountid=self.account.name,
domainid=self.account.domainid,
networkofferingid=nw_off.id,
zoneid=self.zone.id,
gateway=gateway,
vpcid=vpc.id if vpc else self.vpc.id
)
self.debug("Created network with ID: %s" % obj_network.id)
return obj_network
except Exception as e:
self.fail('Unable to create a Network with offering=%s because of %s ' % (net_offerring, e))
def deployvm_in_network(self, network, host_id=None): def deployvm_in_network(self, network, host_id=None):
try: try:
self.debug('Creating VM in network=%s' % network.name) self.debug('Creating VM in network=%s' % network.name)
@ -473,49 +332,16 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
networkids=[str(network.id)], networkids=[str(network.id)],
hostid=host_id hostid=host_id
) )
self.cleanup.append(vm)
self.debug('Created VM=%s in network=%s' % (vm.id, network.name)) self.debug('Created VM=%s in network=%s' % (vm.id, network.name))
return vm return vm
except: except:
self.fail('Unable to create VM in a Network=%s' % network.name) self.fail('Unable to create VM in a Network=%s' % network.name)
def create_lbrule(self, public_ip, network, vmarray, services=None):
self.debug("Creating LB rule for IP address: %s" %
public_ip.ipaddress.ipaddress)
objservices = None
if services:
objservices = services
else:
objservices = self.services["lbrule"]
lb_rule = LoadBalancerRule.create(
self.apiclient,
objservices,
ipaddressid=public_ip.ipaddress.id,
accountid=self.account.name,
networkid=network.id,
vpcid=self.vpc.id,
domainid=self.account.domainid
)
self.debug("Adding virtual machines %s and %s to LB rule" % (vmarray))
lb_rule.assign(self.apiclient, vmarray)
return lb_rule
def open_egress_to_world(self, network):
self.debug("Adding Egress rules to network %s and %s to allow access to internet" % (network.name, self.services["http_rule"]))
nwacl_internet_1 = NetworkACL.create(
self.apiclient,
networkid=network.id,
services=self.services["http_rule"],
traffictype='Ingress'
)
return nwacl_internet_1
@attr(tags=["advanced", "intervlan"], required_hardware="true") @attr(tags=["advanced", "intervlan"], required_hardware="true")
def test_01_network_services_VPC_StopCreatePF(self): def test_01_network_services_VPC_StopCreatePF(self):
""" Test : Create VPC PF rules on acquired public ip when VpcVirtualRouter is stopped """ Test : Create VPC PF rules on acquired public ip when VpcVirtualRouter is stopped
"""
# Validate the following # Validate the following
# 1. Create a VPC with cidr - 10.1.1.1/16 # 1. Create a VPC with cidr - 10.1.1.1/16
@ -526,19 +352,21 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
# 6. Use the Create PF rule for vm in network1. # 6. Use the Create PF rule for vm in network1.
# 7. Start VPC Virtual Router. # 7. Start VPC Virtual Router.
# 8. Successfully ssh into the Guest VM using the PF rule # 8. Successfully ssh into the Guest VM using the PF rule
"""
network_1 = self.create_network(self.services["network_offering"]) network_1 = self.create_network(self.services["network_offering"])
vm_1 = self.deployvm_in_network(network_1) vm_1 = self.deployvm_in_network(network_1)
public_ip_1 = self.acquire_publicip(network_1) public_ip_1 = self.acquire_publicip(network_1)
# ensure vm is accessible over public ip # ensure vm is accessible over public ip
nat_rule = self.create_natrule(vm_1, public_ip_1, network_1) nat_rule = self.create_natrule_for_services(vm_1, public_ip_1, network_1)
self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False)
# remove the nat rule # remove the nat rule
nat_rule.delete(self.apiclient) nat_rule.delete(self.apiclient)
self.cleanup.remove(nat_rule)
router = self.stop_vpcrouter() router = self.stop_vpcrouter()
# recreate nat rule # recreate nat rule
self.create_natrule(vm_1, public_ip_1, network_1) self.create_natrule_for_services(vm_1, public_ip_1, network_1)
self.start_vpcrouter(router) self.start_vpcrouter(router)
self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False)
return return
@ -546,7 +374,6 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
@attr(tags=["advanced", "intervlan"], required_hardware="true") @attr(tags=["advanced", "intervlan"], required_hardware="true")
def test_02_network_services_VPC_CreatePF(self): def test_02_network_services_VPC_CreatePF(self):
""" Test Create VPC PF rules on acquired public ip when VpcVirtualRouter is Running """ Test Create VPC PF rules on acquired public ip when VpcVirtualRouter is Running
"""
# Validate the following # Validate the following
# 1. Create a VPC with cidr - 10.1.1.1/16 # 1. Create a VPC with cidr - 10.1.1.1/16
@ -555,18 +382,18 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
# 4. Deploy vm1 in network1. # 4. Deploy vm1 in network1.
# 5. Use the Create PF rule for vm in network1. # 5. Use the Create PF rule for vm in network1.
# 6. Successfully ssh into the Guest VM using the PF rule # 6. Successfully ssh into the Guest VM using the PF rule
"""
network_1 = self.create_network(self.services["network_offering"]) network_1 = self.create_network(self.services["network_offering"])
vm_1 = self.deployvm_in_network(network_1) vm_1 = self.deployvm_in_network(network_1)
public_ip_1 = self.acquire_publicip(network_1) public_ip_1 = self.acquire_publicip(network_1)
self.create_natrule(vm_1, public_ip_1, network_1) self.create_natrule_for_services(vm_1, public_ip_1, network_1)
self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False)
return return
@attr(tags=["advanced", "intervlan"], required_hardware="true") @attr(tags=["advanced", "intervlan"], required_hardware="true")
def test_03_network_services_VPC_StopCreateMultiplePF(self): def test_03_network_services_VPC_StopCreateMultiplePF(self):
""" Test Create multiple VPC PF rules on acquired public ip in diff't networks when VpcVirtualRouter is stopped """ Test Create multiple VPC PF rules on acquired public ip in diff't networks when VpcVirtualRouter is stopped
"""
# Validate the following # Validate the following
# 1. Create a VPC with cidr - 10.1.1.1/16 # 1. Create a VPC with cidr - 10.1.1.1/16
@ -580,6 +407,7 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
# 9. Use the Create PF rule for vm2 in network2. # 9. Use the Create PF rule for vm2 in network2.
# 10. Start VPC Virtual Router. # 10. Start VPC Virtual Router.
# 11. Successfully ssh into the Guest VM1 and VM2 using the PF rule # 11. Successfully ssh into the Guest VM1 and VM2 using the PF rule
"""
network_1 = self.create_network(self.services["network_offering_no_lb"]) network_1 = self.create_network(self.services["network_offering_no_lb"])
network_2 = self.create_network(self.services["network_offering_no_lb"], '10.1.2.1') network_2 = self.create_network(self.services["network_offering_no_lb"], '10.1.2.1')
@ -592,8 +420,8 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
public_ip_1 = self.acquire_publicip(network_1) public_ip_1 = self.acquire_publicip(network_1)
public_ip_2 = self.acquire_publicip(network_2) public_ip_2 = self.acquire_publicip(network_2)
router = self.stop_vpcrouter() router = self.stop_vpcrouter()
self.create_natrule(vm_1, public_ip_1, network_1) self.create_natrule_for_services(vm_1, public_ip_1, network_1)
self.create_natrule(vm_2, public_ip_2, network_2) self.create_natrule_for_services(vm_2, public_ip_2, network_2)
self.start_vpcrouter(router) self.start_vpcrouter(router)
self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False)
self.check_ssh_into_vm(vm_2, public_ip_2, testnegative=False) self.check_ssh_into_vm(vm_2, public_ip_2, testnegative=False)
@ -602,7 +430,6 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
@attr(tags=["advanced", "intervlan"], required_hardware="true") @attr(tags=["advanced", "intervlan"], required_hardware="true")
def test_04_network_services_VPC_CreateMultiplePF(self): def test_04_network_services_VPC_CreateMultiplePF(self):
""" Test Create multiple VPC PF rules on acquired public ip in diff't networks when VpcVirtualRouter is running """ Test Create multiple VPC PF rules on acquired public ip in diff't networks when VpcVirtualRouter is running
"""
# Validate the following # Validate the following
# 1. Create a VPC with cidr - 10.1.1.1/16 # 1. Create a VPC with cidr - 10.1.1.1/16
@ -614,6 +441,7 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
# 7. Use the Create PF rule for vm1 in network1. # 7. Use the Create PF rule for vm1 in network1.
# 8. Use the Create PF rule for vm2 in network2. # 8. Use the Create PF rule for vm2 in network2.
# 9. Successfully ssh into the Guest VM1 and VM2 using the PF rule # 9. Successfully ssh into the Guest VM1 and VM2 using the PF rule
"""
network_1 = self.create_network(self.services["network_offering"]) network_1 = self.create_network(self.services["network_offering"])
network_2 = self.create_network(self.services["network_offering_no_lb"], '10.1.2.1') network_2 = self.create_network(self.services["network_offering_no_lb"], '10.1.2.1')
@ -621,16 +449,16 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
vm_2 = self.deployvm_in_network(network_2) vm_2 = self.deployvm_in_network(network_2)
public_ip_1 = self.acquire_publicip(network_1) public_ip_1 = self.acquire_publicip(network_1)
public_ip_2 = self.acquire_publicip(network_2) public_ip_2 = self.acquire_publicip(network_2)
self.create_natrule(vm_1, public_ip_1, network_1) self.create_natrule_for_services(vm_1, public_ip_1, network_1)
self.create_natrule(vm_2, public_ip_2, network_2) self.create_natrule_for_services(vm_2, public_ip_2, network_2)
self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False)
self.check_ssh_into_vm(vm_2, public_ip_2, testnegative=False) self.check_ssh_into_vm(vm_2, public_ip_2, testnegative=False)
return return
@attr(tags=["advanced", "intervlan"], required_hardware="true") # tags=["advanced", "intervlan"]
@attr(tags=["TODO"], required_hardware="true")
def test_05_network_services_VPC_StopDeletePF(self): def test_05_network_services_VPC_StopDeletePF(self):
""" Test delete a PF rule in VPC when VpcVirtualRouter is Stopped """ Test delete a PF rule in VPC when VpcVirtualRouter is Stopped
"""
# Validate the following # Validate the following
# 1. Create a VPC with cidr - 10.1.1.1/16 # 1. Create a VPC with cidr - 10.1.1.1/16
@ -644,24 +472,26 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
# 9. Delete internet PF rule # 9. Delete internet PF rule
# 10. Start VPC Virtual Router. # 10. Start VPC Virtual Router.
# 11. wget a file present on http server of VM1 should fail # 11. wget a file present on http server of VM1 should fail
"""
network_1 = self.create_network(self.services["network_offering"]) network_1 = self.create_network(self.services["network_offering"])
vm_1 = self.deployvm_in_network(network_1) vm_1 = self.deployvm_in_network(network_1)
public_ip_1 = self.acquire_publicip(network_1) public_ip_1 = self.acquire_publicip(network_1)
self.create_natrule(vm_1, public_ip_1, network_1) self.create_natrule_for_services(vm_1, public_ip_1, network_1)
http_rule = self.create_natrule(vm_1, public_ip_1, network_1, self.services["http_rule"]) http_rule = self.create_natrule_for_services(vm_1, public_ip_1, network_1, self.services["http_rule"])
self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False)
self.check_wget_from_vm(vm_1, public_ip_1, testnegative=False) self.check_wget_from_vm(vm_1, public_ip_1, testnegative=False)
router = self.stop_vpcrouter() router = self.stop_vpcrouter()
http_rule.delete(self.apiclient) http_rule.delete(self.apiclient)
self.cleanup.remove(http_rule)
self.start_vpcrouter(router) self.start_vpcrouter(router)
self.check_wget_from_vm(vm_1, public_ip_1, testnegative=True) self.check_wget_from_vm(vm_1, public_ip_1, testnegative=True)
return return
@attr(tags=["advanced", "intervlan"], required_hardware="true") # tags=["advanced", "intervlan"]
@attr(tags=["TODO"], required_hardware="true")
def test_06_network_services_VPC_DeletePF(self): def test_06_network_services_VPC_DeletePF(self):
""" Test delete a PF rule in VPC when VpcVirtualRouter is Running """ Test delete a PF rule in VPC when VpcVirtualRouter is Running
"""
# Validate the following # Validate the following
# 1. Create a VPC with cidr - 10.1.1.1/16 # 1. Create a VPC with cidr - 10.1.1.1/16
@ -673,22 +503,24 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
# 7. Successfully wget a file on http server of VM1. # 7. Successfully wget a file on http server of VM1.
# 9. Delete internet PF rule # 9. Delete internet PF rule
# 10. wget a file present on http server of VM1 should fail # 10. wget a file present on http server of VM1 should fail
"""
network_1 = self.create_network(self.services["network_offering"]) network_1 = self.create_network(self.services["network_offering"])
vm_1 = self.deployvm_in_network(network_1) vm_1 = self.deployvm_in_network(network_1)
public_ip_1 = self.acquire_publicip(network_1) public_ip_1 = self.acquire_publicip(network_1)
self.create_natrule(vm_1, public_ip_1, network_1) self.create_natrule_for_services(vm_1, public_ip_1, network_1)
http_rule = self.create_natrule(vm_1, public_ip_1, network_1, self.services["http_rule"]) http_rule = self.create_natrule_for_services(vm_1, public_ip_1, network_1, self.services["http_rule"])
self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False)
self.check_wget_from_vm(vm_1, public_ip_1, testnegative=False) self.check_wget_from_vm(vm_1, public_ip_1, testnegative=False)
http_rule.delete(self.apiclient) http_rule.delete(self.apiclient)
self.cleanup.remove(http_rule)
self.check_wget_from_vm(vm_1, public_ip_1, testnegative=True) self.check_wget_from_vm(vm_1, public_ip_1, testnegative=True)
return return
@attr(tags=["advanced", "intervlan"], required_hardware="true") # tags=["advanced", "intervlan"]
@attr(tags=["TODO"], required_hardware="true")
def test_07_network_services_VPC_StopDeleteAllPF(self): def test_07_network_services_VPC_StopDeleteAllPF(self):
""" Test delete all PF rules in VPC when VpcVirtualRouter is Stopped """ Test delete all PF rules in VPC when VpcVirtualRouter is Stopped
"""
# Validate the following # Validate the following
# 1. Create a VPC with cidr - 10.1.1.1/16 # 1. Create a VPC with cidr - 10.1.1.1/16
@ -703,27 +535,30 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
# 10. Start VPC Virtual Router. # 10. Start VPC Virtual Router.
# 11. wget a file present on http server of VM1 should fail # 11. wget a file present on http server of VM1 should fail
# 12. ssh into Guest VM using the PF rule should fail # 12. ssh into Guest VM using the PF rule should fail
"""
network_1 = self.create_network(self.services["network_offering"]) network_1 = self.create_network(self.services["network_offering"])
vm_1 = self.deployvm_in_network(network_1) vm_1 = self.deployvm_in_network(network_1)
public_ip_1 = self.acquire_publicip(network_1) public_ip_1 = self.acquire_publicip(network_1)
nat_rule = self.create_natrule(vm_1, public_ip_1, network_1) nat_rule = self.create_natrule_for_services(vm_1, public_ip_1, network_1)
http_rule = self.create_natrule(vm_1, public_ip_1, network_1, self.services["http_rule"]) http_rule = self.create_natrule_for_services(vm_1, public_ip_1, network_1, self.services["http_rule"])
self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False)
self.check_wget_from_vm(vm_1, public_ip_1, testnegative=False) self.check_wget_from_vm(vm_1, public_ip_1, testnegative=False)
router = self.stop_vpcrouter() router = self.stop_vpcrouter()
http_rule.delete(self.apiclient) http_rule.delete(self.apiclient)
self.cleanup.remove(http_rule)
nat_rule.delete(self.apiclient) nat_rule.delete(self.apiclient)
self.cleanup.remove(nat_rule)
self.start_vpcrouter(router) self.start_vpcrouter(router)
self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=True) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=True)
self.check_wget_from_vm(vm_1, public_ip_1, testnegative=True, self.check_wget_from_vm(vm_1, public_ip_1, testnegative=True,
isVmAccessible=False, network=network_1) isVmAccessible=False, network=network_1)
return return
@attr(tags=["advanced", "intervlan"], required_hardware="true") # tags=["advanced", "intervlan"]
@attr(tags=["TODO"], required_hardware="true")
def test_08_network_services_VPC_DeleteAllPF(self): def test_08_network_services_VPC_DeleteAllPF(self):
""" Test delete all PF rules in VPC when VpcVirtualRouter is Running """ Test delete all PF rules in VPC when VpcVirtualRouter is Running
"""
# Validate the following # Validate the following
# 1. Create a VPC with cidr - 10.1.1.1/16 # 1. Create a VPC with cidr - 10.1.1.1/16
@ -736,25 +571,28 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
# 8. Delete all PF rule # 8. Delete all PF rule
# 9. wget a file present on http server of VM1 should fail # 9. wget a file present on http server of VM1 should fail
# 10. ssh into Guest VM using the PF rule should fail # 10. ssh into Guest VM using the PF rule should fail
"""
network_1 = self.create_network(self.services["network_offering"]) network_1 = self.create_network(self.services["network_offering"])
vm_1 = self.deployvm_in_network(network_1) vm_1 = self.deployvm_in_network(network_1)
public_ip_1 = self.acquire_publicip(network_1) public_ip_1 = self.acquire_publicip(network_1)
nat_rule = self.create_natrule(vm_1, public_ip_1, network_1) nat_rule = self.create_natrule_for_services(vm_1, public_ip_1, network_1)
http_rule = self.create_natrule(vm_1, public_ip_1, network_1, self.services["http_rule"]) http_rule = self.create_natrule_for_services(vm_1, public_ip_1, network_1, self.services["http_rule"])
self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False)
self.check_wget_from_vm(vm_1, public_ip_1, testnegative=False) self.check_wget_from_vm(vm_1, public_ip_1, testnegative=False)
http_rule.delete(self.apiclient) http_rule.delete(self.apiclient)
self.cleanup.remove(http_rule)
nat_rule.delete(self.apiclient) nat_rule.delete(self.apiclient)
self.cleanup.remove(nat_rule)
self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=True) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=True)
self.check_wget_from_vm(vm_1, public_ip_1, testnegative=True, self.check_wget_from_vm(vm_1, public_ip_1, testnegative=True,
isVmAccessible=False, network=network_1) isVmAccessible=False, network=network_1)
return return
@attr(tags=["advanced", "intervlan"], required_hardware="true") # tags=["advanced", "intervlan"]
@attr(tags=["TODO"], required_hardware="true")
def test_09_network_services_VPC_StopDeleteAllMultiplePF(self): def test_09_network_services_VPC_StopDeleteAllMultiplePF(self):
""" Test delete all PF rules in VPC across multiple networks when VpcVirtualRouter is Stopped """ Test delete all PF rules in VPC across multiple networks when VpcVirtualRouter is Stopped
"""
# Validate the following # Validate the following
# 1. Create a VPC with cidr - 10.1.1.1/16. # 1. Create a VPC with cidr - 10.1.1.1/16.
@ -771,6 +609,7 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
# 12. Delete all PF rultes for vm1, vm2, vm3 and vm4. # 12. Delete all PF rultes for vm1, vm2, vm3 and vm4.
# 12. Start VPC Virtual Router. # 12. Start VPC Virtual Router.
# 13. Fail to ssh and http to vm1, vm2, vm3 and vm4. # 13. Fail to ssh and http to vm1, vm2, vm3 and vm4.
"""
network_1 = self.create_network(self.services["network_offering"]) network_1 = self.create_network(self.services["network_offering"])
network_2 = self.create_network(self.services["network_offering_no_lb"], '10.1.2.1') network_2 = self.create_network(self.services["network_offering_no_lb"], '10.1.2.1')
@ -780,16 +619,16 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
vm_4 = self.deployvm_in_network(network_2) vm_4 = self.deployvm_in_network(network_2)
public_ip_1 = self.acquire_publicip(network_1) public_ip_1 = self.acquire_publicip(network_1)
public_ip_2 = self.acquire_publicip(network_1) public_ip_2 = self.acquire_publicip(network_1)
nat_rule1 = self.create_natrule(vm_1, public_ip_1, network_1) nat_rule1 = self.create_natrule_for_services(vm_1, public_ip_1, network_1)
nat_rule2 = self.create_natrule(vm_2, public_ip_2, network_1) nat_rule2 = self.create_natrule_for_services(vm_2, public_ip_2, network_1)
http_rule1 = self.create_natrule(vm_1, public_ip_1, network_1, self.services["http_rule"]) http_rule1 = self.create_natrule_for_services(vm_1, public_ip_1, network_1, self.services["http_rule"])
http_rule2 = self.create_natrule(vm_2, public_ip_2, network_1, self.services["http_rule"]) http_rule2 = self.create_natrule_for_services(vm_2, public_ip_2, network_1, self.services["http_rule"])
public_ip_3 = self.acquire_publicip(network_2) public_ip_3 = self.acquire_publicip(network_2)
public_ip_4 = self.acquire_publicip(network_2) public_ip_4 = self.acquire_publicip(network_2)
nat_rule3 = self.create_natrule(vm_3, public_ip_3, network_2) nat_rule3 = self.create_natrule_for_services(vm_3, public_ip_3, network_2)
nat_rule4 = self.create_natrule(vm_4, public_ip_4, network_2) nat_rule4 = self.create_natrule_for_services(vm_4, public_ip_4, network_2)
http_rule3 = self.create_natrule(vm_3, public_ip_3, network_2, self.services["http_rule"]) http_rule3 = self.create_natrule_for_services(vm_3, public_ip_3, network_2, self.services["http_rule"])
http_rule4 = self.create_natrule(vm_4, public_ip_4, network_2, self.services["http_rule"]) http_rule4 = self.create_natrule_for_services(vm_4, public_ip_4, network_2, self.services["http_rule"])
self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False)
self.check_ssh_into_vm(vm_2, public_ip_2, testnegative=False) self.check_ssh_into_vm(vm_2, public_ip_2, testnegative=False)
self.check_ssh_into_vm(vm_3, public_ip_3, testnegative=False) self.check_ssh_into_vm(vm_3, public_ip_3, testnegative=False)
@ -800,13 +639,21 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
self.check_wget_from_vm(vm_4, public_ip_4, testnegative=False) self.check_wget_from_vm(vm_4, public_ip_4, testnegative=False)
router = self.stop_vpcrouter() router = self.stop_vpcrouter()
nat_rule1.delete(self.apiclient) nat_rule1.delete(self.apiclient)
self.cleanup.remove(nat_rule1)
nat_rule2.delete(self.apiclient) nat_rule2.delete(self.apiclient)
self.cleanup.remove(nat_rule2)
nat_rule3.delete(self.apiclient) nat_rule3.delete(self.apiclient)
self.cleanup.remove(nat_rule3)
nat_rule4.delete(self.apiclient) nat_rule4.delete(self.apiclient)
self.cleanup.remove(nat_rule4)
http_rule1.delete(self.apiclient) http_rule1.delete(self.apiclient)
self.cleanup.remove(http_rule1)
http_rule2.delete(self.apiclient) http_rule2.delete(self.apiclient)
self.cleanup.remove(http_rule2)
http_rule3.delete(self.apiclient) http_rule3.delete(self.apiclient)
self.cleanup.remove(http_rule3)
http_rule4.delete(self.apiclient) http_rule4.delete(self.apiclient)
self.cleanup.remove(http_rule4)
self.start_vpcrouter(router) self.start_vpcrouter(router)
self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=True) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=True)
self.check_ssh_into_vm(vm_2, public_ip_2, testnegative=True) self.check_ssh_into_vm(vm_2, public_ip_2, testnegative=True)
@ -822,10 +669,11 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
isVmAccessible=False, network=network_2) isVmAccessible=False, network=network_2)
return return
@attr(tags=["advanced", "intervlan"], required_hardware="true") # tags=["advanced", "intervlan"]
@attr(tags=["TODO"], required_hardware="true")
def test_10_network_services_VPC_DeleteAllMultiplePF(self): def test_10_network_services_VPC_DeleteAllMultiplePF(self):
""" Test delete all PF rules in VPC across multiple networks when VpcVirtualRouter is Running """ Test delete all PF rules in VPC across multiple networks when VpcVirtualRouter is Running
"""
# Validate the following # Validate the following
# 1. Create a VPC with cidr - 10.1.1.1/16. # 1. Create a VPC with cidr - 10.1.1.1/16.
# 2. Create a Network offering - NO1 with all supported services. # 2. Create a Network offering - NO1 with all supported services.
@ -839,6 +687,7 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
# 10. Succesfully wget a file from http server present on vm1, vm2, vm3 and vm4. # 10. Succesfully wget a file from http server present on vm1, vm2, vm3 and vm4.
# 12. Delete all PF rultes for vm1, vm2, vm3 and vm4. # 12. Delete all PF rultes for vm1, vm2, vm3 and vm4.
# 13. Fail to ssh and http to vm1, vm2, vm3 and vm4. # 13. Fail to ssh and http to vm1, vm2, vm3 and vm4.
"""
network_1 = self.create_network(self.services["network_offering"]) network_1 = self.create_network(self.services["network_offering"])
network_2 = self.create_network(self.services["network_offering_no_lb"], '10.1.2.1') network_2 = self.create_network(self.services["network_offering_no_lb"], '10.1.2.1')
@ -848,16 +697,16 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
vm_4 = self.deployvm_in_network(network_2) vm_4 = self.deployvm_in_network(network_2)
public_ip_1 = self.acquire_publicip(network_1) public_ip_1 = self.acquire_publicip(network_1)
public_ip_2 = self.acquire_publicip(network_1) public_ip_2 = self.acquire_publicip(network_1)
nat_rule1 = self.create_natrule(vm_1, public_ip_1, network_1) nat_rule1 = self.create_natrule_for_services(vm_1, public_ip_1, network_1)
nat_rule2 = self.create_natrule(vm_2, public_ip_2, network_1) nat_rule2 = self.create_natrule_for_services(vm_2, public_ip_2, network_1)
http_rule1 = self.create_natrule(vm_1, public_ip_1, network_1, self.services["http_rule"]) http_rule1 = self.create_natrule_for_services(vm_1, public_ip_1, network_1, self.services["http_rule"])
http_rule2 = self.create_natrule(vm_2, public_ip_2, network_1, self.services["http_rule"]) http_rule2 = self.create_natrule_for_services(vm_2, public_ip_2, network_1, self.services["http_rule"])
public_ip_3 = self.acquire_publicip(network_2) public_ip_3 = self.acquire_publicip(network_2)
public_ip_4 = self.acquire_publicip(network_2) public_ip_4 = self.acquire_publicip(network_2)
nat_rule3 = self.create_natrule(vm_3, public_ip_3, network_2) nat_rule3 = self.create_natrule_for_services(vm_3, public_ip_3, network_2)
nat_rule4 = self.create_natrule(vm_4, public_ip_4, network_2) nat_rule4 = self.create_natrule_for_services(vm_4, public_ip_4, network_2)
http_rule3 = self.create_natrule(vm_3, public_ip_3, network_2, self.services["http_rule"]) http_rule3 = self.create_natrule_for_services(vm_3, public_ip_3, network_2, self.services["http_rule"])
http_rule4 = self.create_natrule(vm_4, public_ip_4, network_2, self.services["http_rule"]) http_rule4 = self.create_natrule_for_services(vm_4, public_ip_4, network_2, self.services["http_rule"])
self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False)
self.check_ssh_into_vm(vm_2, public_ip_2, testnegative=False) self.check_ssh_into_vm(vm_2, public_ip_2, testnegative=False)
self.check_ssh_into_vm(vm_3, public_ip_3, testnegative=False) self.check_ssh_into_vm(vm_3, public_ip_3, testnegative=False)
@ -867,13 +716,21 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
self.check_wget_from_vm(vm_3, public_ip_3, testnegative=False) self.check_wget_from_vm(vm_3, public_ip_3, testnegative=False)
self.check_wget_from_vm(vm_4, public_ip_4, testnegative=False) self.check_wget_from_vm(vm_4, public_ip_4, testnegative=False)
nat_rule1.delete(self.apiclient) nat_rule1.delete(self.apiclient)
self.cleanup.remove(nat_rule1)
nat_rule2.delete(self.apiclient) nat_rule2.delete(self.apiclient)
self.cleanup.remove(nat_rule2)
nat_rule3.delete(self.apiclient) nat_rule3.delete(self.apiclient)
self.cleanup.remove(nat_rule3)
nat_rule4.delete(self.apiclient) nat_rule4.delete(self.apiclient)
self.cleanup.remove(nat_rule4)
http_rule1.delete(self.apiclient) http_rule1.delete(self.apiclient)
self.cleanup.remove(http_rule1)
http_rule2.delete(self.apiclient) http_rule2.delete(self.apiclient)
self.cleanup.remove(http_rule2)
http_rule3.delete(self.apiclient) http_rule3.delete(self.apiclient)
self.cleanup.remove(http_rule3)
http_rule4.delete(self.apiclient) http_rule4.delete(self.apiclient)
self.cleanup.remove(http_rule4)
self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=True) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=True)
self.check_ssh_into_vm(vm_2, public_ip_2, testnegative=True) self.check_ssh_into_vm(vm_2, public_ip_2, testnegative=True)
self.check_ssh_into_vm(vm_3, public_ip_3, testnegative=True) self.check_ssh_into_vm(vm_3, public_ip_3, testnegative=True)

View File

@ -17,163 +17,163 @@
""" Component tests for VPC network functionality - Port Forwarding Rules. """ Component tests for VPC network functionality - Port Forwarding Rules.
""" """
from nose.plugins.attrib import attr
from marvin.cloudstackTestCase import cloudstackTestCase
import unittest
from marvin.lib.base import (Account,
VpcOffering,
VPC,
ServiceOffering,
NetworkACL,
PublicIPAddress,
NetworkOffering,
Network,
VirtualMachine,
LoadBalancerRule,
StaticNATRule)
from marvin.cloudstackAPI import (stopRouter,
startRouter)
from marvin.lib.common import (get_domain,
get_zone,
get_template,
list_routers)
from marvin.lib.utils import cleanup_resources
import socket import socket
import time import time
from marvin.cloudstackAPI import (stopRouter,
startRouter)
from marvin.cloudstackTestCase import cloudstackTestCase
from marvin.lib.base import (Account,
VpcOffering,
VPC,
ServiceOffering,
NetworkACL,
PublicIPAddress,
NetworkOffering,
Network,
VirtualMachine,
LoadBalancerRule,
StaticNATRule)
from marvin.lib.common import (get_domain,
get_zone,
get_template,
list_routers)
from nose.plugins.attrib import attr
class Services: class Services:
"""Test VPC network services - Port Forwarding Rules Test Data Class. """Test VPC network services - Port Forwarding Rules Test Data Class.
""" """
def __init__(self): def __init__(self):
self.services = { self.services = {
"account": { "account": {
"email": "test@test.com", "email": "test@test.com",
"firstname": "Test", "firstname": "Test",
"lastname": "User", "lastname": "User",
"username": "test", "username": "test",
# Random characters are appended for unique # Random characters are appended for unique
# username # username
"password": "password", "password": "password",
}, },
"host1":None, "host1": None,
"host2":None, "host2": None,
"service_offering": { "service_offering": {
"name": "Tiny Instance", "name": "Tiny Instance",
"displaytext": "Tiny Instance", "displaytext": "Tiny Instance",
"cpunumber": 1, "cpunumber": 1,
"cpuspeed": 100, "cpuspeed": 100,
"memory": 128, "memory": 128,
}, },
"network_offering": { "network_offering": {
"name": 'VPC Network offering', "name": 'VPC Network offering',
"displaytext": 'VPC Network off', "displaytext": 'VPC Network off',
"guestiptype": 'Isolated', "guestiptype": 'Isolated',
"supportedservices": 'Vpn,Dhcp,Dns,SourceNat,PortForwarding,Lb,UserData,StaticNat,NetworkACL', "supportedservices": 'Vpn,Dhcp,Dns,SourceNat,PortForwarding,Lb,UserData,StaticNat,NetworkACL',
"traffictype": 'GUEST', "traffictype": 'GUEST',
"availability": 'Optional', "availability": 'Optional',
"useVpc": 'on', "useVpc": 'on',
"serviceProviderList": { "serviceProviderList": {
"Vpn": 'VpcVirtualRouter', "Vpn": 'VpcVirtualRouter',
"Dhcp": 'VpcVirtualRouter', "Dhcp": 'VpcVirtualRouter',
"Dns": 'VpcVirtualRouter', "Dns": 'VpcVirtualRouter',
"SourceNat": 'VpcVirtualRouter', "SourceNat": 'VpcVirtualRouter',
"PortForwarding": 'VpcVirtualRouter', "PortForwarding": 'VpcVirtualRouter',
"Lb": 'VpcVirtualRouter', "Lb": 'VpcVirtualRouter',
"UserData": 'VpcVirtualRouter', "UserData": 'VpcVirtualRouter',
"StaticNat": 'VpcVirtualRouter', "StaticNat": 'VpcVirtualRouter',
"NetworkACL": 'VpcVirtualRouter' "NetworkACL": 'VpcVirtualRouter'
}, },
}, },
"network_offering_no_lb": { "network_offering_no_lb": {
"name": 'VPC Network offering', "name": 'VPC Network offering',
"displaytext": 'VPC Network off', "displaytext": 'VPC Network off',
"guestiptype": 'Isolated', "guestiptype": 'Isolated',
"supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,UserData,StaticNat,NetworkACL', "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,UserData,StaticNat,NetworkACL',
"traffictype": 'GUEST', "traffictype": 'GUEST',
"availability": 'Optional', "availability": 'Optional',
"useVpc": 'on', "useVpc": 'on',
"serviceProviderList": { "serviceProviderList": {
"Dhcp": 'VpcVirtualRouter', "Dhcp": 'VpcVirtualRouter',
"Dns": 'VpcVirtualRouter', "Dns": 'VpcVirtualRouter',
"SourceNat": 'VpcVirtualRouter', "SourceNat": 'VpcVirtualRouter',
"PortForwarding": 'VpcVirtualRouter', "PortForwarding": 'VpcVirtualRouter',
"UserData": 'VpcVirtualRouter', "UserData": 'VpcVirtualRouter',
"StaticNat": 'VpcVirtualRouter', "StaticNat": 'VpcVirtualRouter',
"NetworkACL": 'VpcVirtualRouter' "NetworkACL": 'VpcVirtualRouter'
}, },
}, },
"vpc_offering": { "vpc_offering": {
"name": 'VPC off', "name": 'VPC off',
"displaytext": 'VPC off', "displaytext": 'VPC off',
"supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,Vpn,Lb,UserData,StaticNat', "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,Vpn,Lb,UserData,StaticNat',
}, },
"vpc": { "vpc": {
"name": "TestVPC", "name": "TestVPC",
"displaytext": "TestVPC", "displaytext": "TestVPC",
"cidr": '10.0.0.1/24' "cidr": '10.0.0.1/24'
}, },
"network": { "network": {
"name": "Test Network", "name": "Test Network",
"displaytext": "Test Network", "displaytext": "Test Network",
"netmask": '255.255.255.0' "netmask": '255.255.255.0'
}, },
"lbrule": { "lbrule": {
"name": "SSH", "name": "SSH",
"alg": "leastconn", "alg": "leastconn",
# Algorithm used for load balancing # Algorithm used for load balancing
"privateport": 22, "privateport": 22,
"publicport": 2222, "publicport": 2222,
"openfirewall": False, "openfirewall": False,
"startport": 22, "startport": 22,
"endport": 2222, "endport": 2222,
"protocol": "TCP", "protocol": "TCP",
"cidrlist": '0.0.0.0/0', "cidrlist": '0.0.0.0/0',
}, },
"lbrule_http": { "lbrule_http": {
"name": "HTTP", "name": "HTTP",
"alg": "leastconn", "alg": "leastconn",
# Algorithm used for load balancing # Algorithm used for load balancing
"privateport": 80, "privateport": 80,
"publicport": 8888, "publicport": 8888,
"openfirewall": False, "openfirewall": False,
"startport": 80, "startport": 80,
"endport": 8888, "endport": 8888,
"protocol": "TCP", "protocol": "TCP",
"cidrlist": '0.0.0.0/0', "cidrlist": '0.0.0.0/0',
}, },
"ssh_rule": { "ssh_rule": {
"privateport": 22, "privateport": 22,
"publicport": 22, "publicport": 22,
"startport": 22, "startport": 22,
"endport": 22, "endport": 22,
"protocol": "TCP", "protocol": "TCP",
"cidrlist": '0.0.0.0/0', "cidrlist": '0.0.0.0/0',
}, },
"http_rule": { "http_rule": {
"privateport": 80, "privateport": 80,
"publicport": 80, "publicport": 80,
"startport": 80, "startport": 80,
"endport": 80, "endport": 80,
"cidrlist": '0.0.0.0/0', "cidrlist": '0.0.0.0/0',
"protocol": "TCP" "protocol": "TCP"
}, },
"virtual_machine": { "virtual_machine": {
"displayname": "Test VM", "displayname": "Test VM",
"username": "root", "username": "root",
"password": "password", "password": "password",
"ssh_port": 22, "ssh_port": 22,
"hypervisor": 'XenServer', "hypervisor": 'XenServer',
# Hypervisor type should be same as # Hypervisor type should be same as
# hypervisor type of cluster # hypervisor type of cluster
"privateport": 22, "privateport": 22,
"publicport": 22, "publicport": 22,
"protocol": 'TCP', "protocol": 'TCP',
}, },
"ostype": 'CentOS 5.3 (64-bit)', "ostype": 'CentOS 5.3 (64-bit)',
"sleep": 60, "sleep": 60,
"timeout": 10, "timeout": 10,
} }
class TestVPCNetworkPFRules(cloudstackTestCase): class TestVPCNetworkPFRules(cloudstackTestCase):
@ -191,46 +191,38 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
cls.domain = get_domain(cls.api_client) cls.domain = get_domain(cls.api_client)
cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
cls.template = get_template( cls.template = get_template(
cls.api_client, cls.api_client,
cls.zone.id, cls.zone.id,
cls.services["ostype"] cls.services["ostype"]
) )
cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["virtual_machine"]["zoneid"] = cls.zone.id
cls.services["virtual_machine"]["template"] = cls.template.id cls.services["virtual_machine"]["template"] = cls.template.id
cls.service_offering = ServiceOffering.create( cls.service_offering = ServiceOffering.create(
cls.api_client, cls.api_client,
cls.services["service_offering"] cls.services["service_offering"]
) )
cls._cleanup = [cls.service_offering] cls._cleanup = [cls.service_offering]
return return
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestVPCNetworkPFRules, cls).tearDownClass()
#Cleanup resources used
cleanup_resources(cls.api_client, cls._cleanup)
except Exception as e:
print(("Warning: Exception during cleanup : %s" % e))
#raise Exception("Warning: Exception during cleanup : %s" % e)
return
def setUp(self): def setUp(self):
self.apiclient = self.testClient.getApiClient() self.apiclient = self.testClient.getApiClient()
self.account = Account.create( self.account = Account.create(
self.apiclient, self.apiclient,
self.services["account"], self.services["account"],
admin=True, admin=True,
domainid=self.domain.id domainid=self.domain.id
) )
self.cleanup = [self.account] self.cleanup = [self.account]
self.debug("Creating a VPC offering..") self.debug("Creating a VPC offering..")
self.vpc_off = VpcOffering.create( self.vpc_off = VpcOffering.create(
self.apiclient, self.apiclient,
self.services["vpc_offering"] self.services["vpc_offering"]
) )
self.cleanup.append(self.vpc_off) self.cleanup.append(self.vpc_off)
self.debug("Enabling the VPC offering created") self.debug("Enabling the VPC offering created")
self.vpc_off.update(self.apiclient, state='Enabled') self.vpc_off.update(self.apiclient, state='Enabled')
@ -238,41 +230,35 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
self.debug("Creating a VPC network in the account: %s" % self.account.name) self.debug("Creating a VPC network in the account: %s" % self.account.name)
self.services["vpc"]["cidr"] = '10.1.1.1/16' self.services["vpc"]["cidr"] = '10.1.1.1/16'
self.vpc = VPC.create( self.vpc = VPC.create(
self.apiclient, self.apiclient,
self.services["vpc"], self.services["vpc"],
vpcofferingid=self.vpc_off.id, vpcofferingid=self.vpc_off.id,
zoneid=self.zone.id, zoneid=self.zone.id,
account=self.account.name, account=self.account.name,
domainid=self.account.domainid domainid=self.account.domainid
) )
self.cleanup.append(self.vpc)
return return
def tearDown(self): def tearDown(self):
try: super(TestVPCNetworkPFRules, self).tearDown()
#Clean up, terminate the created network offerings
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
self.debug("Warning: Exception during cleanup : %s" % e)
#raise Exception("Warning: Exception during cleanup : %s" % e)
return
def get_Router_For_VPC(self): def get_Router_For_VPC(self):
routers = list_routers(self.apiclient, routers = list_routers(self.apiclient,
account=self.account.name, account=self.account.name,
domainid=self.account.domainid, domainid=self.account.domainid,
) )
self.assertEqual(isinstance(routers, list), self.assertEqual(isinstance(routers, list),
True, True,
"Check for list routers response return valid data" "Check for list routers response return valid data"
) )
self.assertNotEqual(len(routers), self.assertNotEqual(len(routers),
0, 0,
"Check list router response" "Check list router response"
) )
router = routers[0] router = routers[0]
return router return router
def stop_VPC_VRouter(self): def stop_VPC_VRouter(self):
router = self.get_Router_For_VPC() router = self.get_Router_For_VPC()
self.debug("Stopping router ID: %s" % router.id) self.debug("Stopping router ID: %s" % router.id)
@ -281,18 +267,18 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
self.apiclient.stopRouter(cmd) self.apiclient.stopRouter(cmd)
routers = list_routers(self.apiclient, routers = list_routers(self.apiclient,
account=self.account.name, account=self.account.name,
domainid=self.account.domainid, domainid=self.account.domainid,
) )
self.assertEqual(isinstance(routers, list), self.assertEqual(isinstance(routers, list),
True, True,
"Check for list routers response return valid data" "Check for list routers response return valid data"
) )
router = routers[0] router = routers[0]
self.assertEqual(router.state, self.assertEqual(router.state,
'Stopped', 'Stopped',
"Check list router response for router state" "Check list router response for router state"
) )
return router return router
def start_VPC_VRouter(self, router): def start_VPC_VRouter(self, router):
@ -302,203 +288,97 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
self.apiclient.startRouter(cmd) self.apiclient.startRouter(cmd)
routers = list_routers(self.apiclient, routers = list_routers(self.apiclient,
account=self.account.name, account=self.account.name,
domainid=self.account.domainid, domainid=self.account.domainid,
zoneid=self.zone.id zoneid=self.zone.id
) )
self.assertEqual(isinstance(routers, list), self.assertEqual(isinstance(routers, list),
True, True,
"Check for list routers response return valid data" "Check for list routers response return valid data"
) )
router = routers[0] router = routers[0]
self.assertEqual(router.state, self.assertEqual(router.state,
'Running', 'Running',
"Check list router response for router state" "Check list router response for router state"
) )
def check_ssh_into_vm(self, vm, public_ip, testnegative=False):
self.debug("Checking if we can SSH into VM=%s on public_ip=%s" % (vm.name, public_ip.ipaddress.ipaddress))
try:
vm.get_ssh_client(ipaddress=public_ip.ipaddress.ipaddress)
if not testnegative:
self.debug("SSH into VM=%s on public_ip=%s is successfully" % (vm.name, public_ip.ipaddress.ipaddress))
else:
self.fail("SSH into VM=%s on public_ip=%s is successfully" % (vm.name, public_ip.ipaddress.ipaddress))
except:
if not testnegative:
self.fail("Failed to SSH into VM - %s" % (public_ip.ipaddress.ipaddress))
else:
self.debug("Failed to SSH into VM - %s" % (public_ip.ipaddress.ipaddress))
def check_wget_from_vm(self, vm, public_ip, testnegative=False):
import urllib.request, urllib.parse, urllib.error
self.debug("Checking if we can wget from a VM=%s http server on public_ip=%s" % (vm.name, public_ip.ipaddress.ipaddress))
try:
urllib.request.urlretrieve("http://%s/test.html" % public_ip.ipaddress.ipaddress, filename="test.html")
if not testnegative:
self.debug("Successful to wget from VM=%s http server on public_ip=%s" % (vm.name, public_ip.ipaddress.ipaddress))
else:
self.fail("Successful to wget from VM=%s http server on public_ip=%s" % (vm.name, public_ip.ipaddress.ipaddress))
except:
if not testnegative:
self.fail("Failed to wget from VM=%s http server on public_ip=%s" % (vm.name, public_ip.ipaddress.ipaddress))
else:
self.debug("Failed to wget from VM=%s http server on public_ip=%s" % (vm.name, public_ip.ipaddress.ipaddress))
def create_StaticNatRule_For_VM(self, vm, public_ip, network): def create_StaticNatRule_For_VM(self, vm, public_ip, network):
self.debug("Enabling static NAT for IP: %s" % self.debug("Enabling static NAT for IP: %s" % public_ip.ipaddress.ipaddress)
public_ip.ipaddress.ipaddress)
try: try:
StaticNATRule.enable( StaticNATRule.enable(
self.apiclient, self.apiclient,
ipaddressid=public_ip.ipaddress.id, ipaddressid=public_ip.ipaddress.id,
virtualmachineid=vm.id, virtualmachineid=vm.id,
networkid=network.id networkid=network.id
) )
self.debug("Static NAT enabled for IP: %s" % self.debug("Static NAT enabled for IP: %s" %
public_ip.ipaddress.ipaddress) public_ip.ipaddress.ipaddress)
except Exception as e: except Exception as e:
self.fail("Failed to enable static NAT on IP: %s - %s" % ( self.fail("Failed to enable static NAT on IP: %s - %s" % (
public_ip.ipaddress.ipaddress, e)) public_ip.ipaddress.ipaddress, e))
def delete_StaticNatRule_For_VM(self, vm, public_ip): def delete_StaticNatRule_For_VM(self, vm, public_ip):
self.debug("Disabling static NAT for IP: %s" % self.debug("Disabling static NAT for IP: %s" % public_ip.ipaddress.ipaddress)
public_ip.ipaddress.ipaddress)
try: try:
StaticNATRule.disable( StaticNATRule.disable(
self.apiclient, self.apiclient,
ipaddressid=public_ip.ipaddress.id, ipaddressid=public_ip.ipaddress.id,
virtualmachineid=vm.id, virtualmachineid=vm.id,
) )
self.debug("Static NAT disabled for IP: %s" % self.debug("Static NAT disabled for IP: %s" %
public_ip.ipaddress.ipaddress) public_ip.ipaddress.ipaddress)
except Exception as e: except Exception as e:
self.fail("Failed to disabled static NAT on IP: %s - %s" % ( self.fail("Failed to disabled static NAT on IP: %s - %s" % (
public_ip.ipaddress.ipaddress, e)) public_ip.ipaddress.ipaddress, e))
def acquire_Public_IP(self, network): def acquire_Public_IP(self, network):
self.debug("Associating public IP for network: %s" % network.name) self.debug("Associating public IP for network: %s" % network.name)
public_ip = PublicIPAddress.create(self.apiclient, public_ip = PublicIPAddress.create(self.apiclient,
accountid=self.account.name, accountid=self.account.name,
zoneid=self.zone.id, zoneid=self.zone.id,
domainid=self.account.domainid, domainid=self.account.domainid,
networkid=None, #network.id, networkid=None, # network.id,
vpcid=self.vpc.id vpcid=self.vpc.id
) )
self.cleanup.append(public_ip)
self.debug("Associated %s with network %s" % (public_ip.ipaddress.ipaddress, self.debug("Associated %s with network %s" % (public_ip.ipaddress.ipaddress,
network.id network.id
)) ))
return public_ip return public_ip
def create_VPC(self, cidr='10.1.2.1/16'):
self.debug("Creating a VPC offering..")
self.services["vpc_offering"]["name"] = self.services["vpc_offering"]["name"] + str(cidr)
vpc_off = VpcOffering.create(
self.apiclient,
self.services["vpc_offering"]
)
self.cleanup.append(self.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.name)
self.services["vpc"]["cidr"] = cidr
vpc = VPC.create(
self.apiclient,
self.services["vpc"],
vpcofferingid=vpc_off.id,
zoneid=self.zone.id,
account=self.account.name,
domainid=self.account.domainid
)
return vpc
def create_Network(self, net_offerring, gateway='10.1.1.1',vpc=None):
try:
self.debug('Create NetworkOffering')
net_offerring["name"] = "NET_OFF-" + str(gateway)
nw_off = NetworkOffering.create(self.apiclient,
net_offerring,
conservemode=False
)
# Enable Network offering
nw_off.update(self.apiclient, state='Enabled')
self.cleanup.append(nw_off)
self.debug('Created and Enabled NetworkOffering')
self.services["network"]["name"] = "NETWORK-" + str(gateway)
self.debug('Adding Network=%s' % self.services["network"])
obj_network = Network.create(self.apiclient,
self.services["network"],
accountid=self.account.name,
domainid=self.account.domainid,
networkofferingid=nw_off.id,
zoneid=self.zone.id,
gateway=gateway,
vpcid=vpc.id if vpc else self.vpc.id
)
self.debug("Created network with ID: %s" % obj_network.id)
return obj_network
except:
self.fail('Unable to create a Network with offering=%s' % net_offerring)
def create_VM_in_Network(self, network, host_id=None): def create_VM_in_Network(self, network, host_id=None):
try: try:
self.debug('Creating VM in network=%s' % network.name) self.debug('Creating VM in network=%s' % network.name)
vm = VirtualMachine.create( vm = VirtualMachine.create(
self.apiclient, self.apiclient,
self.services["virtual_machine"], self.services["virtual_machine"],
accountid=self.account.name, accountid=self.account.name,
domainid=self.account.domainid, domainid=self.account.domainid,
serviceofferingid=self.service_offering.id, serviceofferingid=self.service_offering.id,
networkids=[str(network.id)], networkids=[str(network.id)],
hostid=host_id hostid=host_id
) )
self.debug('Created VM=%s in network=%s' % (vm.id, network.name)) self.cleanup.append(vm)
self.debug('Created VM=%s in network=%s' % (vm.id, network.name))
return vm return vm
except: except:
self.fail('Unable to create VM in a Network=%s' % network.name) self.fail('Unable to create VM in a Network=%s' % network.name)
def create_LB_Rule(self, public_ip, network, vmarray, services=None):
self.debug("Creating LB rule for IP address: %s" %
public_ip.ipaddress.ipaddress)
objservices = None
if services:
objservices = services
else:
objservices = self.services["lbrule"]
lb_rule = LoadBalancerRule.create(
self.apiclient,
objservices,
ipaddressid=public_ip.ipaddress.id,
accountid=self.account.name,
networkid=network.id,
vpcid=self.vpc.id,
domainid=self.account.domainid
)
self.debug("Adding virtual machines %s and %s to LB rule" % (vmarray))
lb_rule.assign(self.apiclient, vmarray)
return lb_rule
def create_ingress_rule(self, network, services=None): def create_ingress_rule(self, network, services=None):
if not services: if not services:
services = self.services["ssh_rule"] services = self.services["ssh_rule"]
self.debug("Adding NetworkACL rules to make NAT rule accessible") self.debug("Adding NetworkACL rules to make NAT rule accessible")
nwacl_nat = NetworkACL.create(self.apiclient, nwacl_nat = NetworkACL.create(self.apiclient,
services, services,
networkid=network.id, networkid=network.id,
traffictype='Ingress' traffictype='Ingress'
) )
return nwacl_nat return nwacl_nat
@attr(tags=["advanced", "intervlan"], required_hardware="true") @attr(tags=["advanced", "intervlan"], required_hardware="true")
def test_01_VPC_StaticNatRuleCreateStoppedState(self): def test_01_VPC_StaticNatRuleCreateStoppedState(self):
""" Test case no extra : """ Test case no extra :
"""
# Validate the following # Validate the following
# 1. Create a VPC with cidr - 10.1.1.1/16 # 1. Create a VPC with cidr - 10.1.1.1/16
@ -509,15 +389,16 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
# 6. Use the Create PF rule for vm in network1. # 6. Use the Create PF rule for vm in network1.
# 7. Start VPC Virtual Router. # 7. Start VPC Virtual Router.
# 8. Successfully ssh into the Guest VM using the PF rule # 8. Successfully ssh into the Guest VM using the PF rule
"""
network_1 = self.create_Network(self.services["network_offering"]) network_1 = self.create_network(self.services["network_offering"])
self.create_ingress_rule(network_1) self.create_ingress_rule(network_1)
vm_1 = self.create_VM_in_Network(network_1) vm_1 = self.create_VM_in_Network(network_1)
public_ip_1 = self.acquire_Public_IP(network_1) public_ip_1 = self.acquire_Public_IP(network_1)
router = self.stop_VPC_VRouter() router = self.stop_VPC_VRouter()
self.create_StaticNatRule_For_VM( vm_1, public_ip_1, network_1) self.create_StaticNatRule_For_VM(vm_1, public_ip_1, network_1)
self.start_VPC_VRouter(router) self.start_VPC_VRouter(router)
self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False)
@ -527,7 +408,6 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
def test_02_VPC_CreateStaticNatRule(self): def test_02_VPC_CreateStaticNatRule(self):
""" Test case no 229 : Create Static NAT Rule for a single virtual network of """ Test case no 229 : Create Static NAT Rule for a single virtual network of
a VPC using a new Public IP Address available with the VPC when the Virtual Router is in Running State a VPC using a new Public IP Address available with the VPC when the Virtual Router is in Running State
"""
# Validate the following # Validate the following
# 1. Create a VPC with cidr - 10.1.1.1/16 # 1. Create a VPC with cidr - 10.1.1.1/16
@ -536,13 +416,14 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
# 4. Deploy vm1 in network1. # 4. Deploy vm1 in network1.
# 5. Use the Create Static Nat rule for vm in network1. # 5. Use the Create Static Nat rule for vm in network1.
# 6. Successfully ssh into the Guest VM using the PF rule # 6. Successfully ssh into the Guest VM using the PF rule
"""
network_1 = self.create_Network(self.services["network_offering"]) network_1 = self.create_network(self.services["network_offering"])
self.create_ingress_rule(network_1) self.create_ingress_rule(network_1)
vm_1 = self.create_VM_in_Network(network_1) vm_1 = self.create_VM_in_Network(network_1)
public_ip_1 = self.acquire_Public_IP(network_1) public_ip_1 = self.acquire_Public_IP(network_1)
self.create_StaticNatRule_For_VM( vm_1, public_ip_1, network_1) self.create_StaticNatRule_For_VM(vm_1, public_ip_1, network_1)
self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False)
return return
@ -550,7 +431,6 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
def test_03_VPC_StopCreateMultipleStaticNatRuleStopppedState(self): def test_03_VPC_StopCreateMultipleStaticNatRuleStopppedState(self):
""" Test case no extra : Create Static Nat Rule rules for a two/multiple virtual networks of a VPC using """ Test case no extra : Create Static Nat Rule rules for a two/multiple virtual networks of a VPC using
a new Public IP Address available with the VPC when Virtual Router is in Stopped State a new Public IP Address available with the VPC when Virtual Router is in Stopped State
"""
# Validate the following # Validate the following
# 1. Create a VPC with cidr - 10.1.1.1/16 # 1. Create a VPC with cidr - 10.1.1.1/16
@ -564,9 +444,10 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
# 9. Use the Create PF rule for vm2 in network2. # 9. Use the Create PF rule for vm2 in network2.
# 10. Start VPC Virtual Router. # 10. Start VPC Virtual Router.
# 11. Successfully ssh into the Guest VM1 and VM2 using the PF rule # 11. Successfully ssh into the Guest VM1 and VM2 using the PF rule
"""
network_1 = self.create_Network(self.services["network_offering_no_lb"]) network_1 = self.create_network(self.services["network_offering_no_lb"])
network_2 = self.create_Network(self.services["network_offering_no_lb"], '10.1.2.1') network_2 = self.create_network(self.services["network_offering_no_lb"], '10.1.2.1')
self.create_ingress_rule(network_1) self.create_ingress_rule(network_1)
self.create_ingress_rule(network_2) self.create_ingress_rule(network_2)
@ -590,7 +471,6 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
def test_04_VPC_CreateMultipleStaticNatRule(self): def test_04_VPC_CreateMultipleStaticNatRule(self):
""" Test case no 230 : Create Static NAT Rules for a two/multiple virtual networks of """ Test case no 230 : Create Static NAT Rules for a two/multiple virtual networks of
a VPC using a new Public IP Address available with the VPC when the Virtual Router is in Running State a VPC using a new Public IP Address available with the VPC when the Virtual Router is in Running State
"""
# Validate the following # Validate the following
# 1. Create a VPC with cidr - 10.1.1.1/16 # 1. Create a VPC with cidr - 10.1.1.1/16
@ -603,9 +483,10 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
# 8. Use the Create PF rule for vm2 in network2. # 8. Use the Create PF rule for vm2 in network2.
# 9. Start VPC Virtual Router. # 9. Start VPC Virtual Router.
# 10. Successfully ssh into the Guest VM1 and VM2 using the PF rule # 10. Successfully ssh into the Guest VM1 and VM2 using the PF rule
"""
network_1 = self.create_Network(self.services["network_offering"]) network_1 = self.create_network(self.services["network_offering"])
network_2 = self.create_Network(self.services["network_offering_no_lb"], '10.1.2.1') network_2 = self.create_network(self.services["network_offering_no_lb"], '10.1.2.1')
self.create_ingress_rule(network_1) self.create_ingress_rule(network_1)
self.create_ingress_rule(network_2) self.create_ingress_rule(network_2)
@ -619,11 +500,11 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
self.check_ssh_into_vm(vm_2, public_ip_2, testnegative=False) self.check_ssh_into_vm(vm_2, public_ip_2, testnegative=False)
return return
@attr(tags=["advanced", "intervlan"], required_hardware="true") # was tags=["advanced", "intervlan"]
@attr(tags=["TODO"], required_hardware="true")
def test_05_network_services_VPC_DeleteAllPF(self): def test_05_network_services_VPC_DeleteAllPF(self):
""" Test case no 232: Delete all Static NAT Rules for a single virtual network of """ Test case no 232: Delete all Static NAT Rules for a single virtual network of
a VPC belonging to a single Public IP Address when the Virtual Router is in Running State a VPC belonging to a single Public IP Address when the Virtual Router is in Running State
"""
# Validate the following # Validate the following
# 1. Create a VPC with cidr - 10.1.1.1/16 # 1. Create a VPC with cidr - 10.1.1.1/16
@ -636,8 +517,9 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
# 8. Delete all PF rule # 8. Delete all PF rule
# 9. wget a file present on http server of VM1 should fail # 9. wget a file present on http server of VM1 should fail
# 10. ssh into Guest VM using the PF rule should fail # 10. ssh into Guest VM using the PF rule should fail
"""
network_1 = self.create_Network(self.services["network_offering"]) network_1 = self.create_network(self.services["network_offering"])
self.create_ingress_rule(network_1) self.create_ingress_rule(network_1)
self.create_ingress_rule(network_1, self.services["http_rule"]) self.create_ingress_rule(network_1, self.services["http_rule"])
@ -651,11 +533,11 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
self.check_wget_from_vm(vm_1, public_ip_1, testnegative=True) self.check_wget_from_vm(vm_1, public_ip_1, testnegative=True)
return return
@attr(tags=["advanced", "intervlan"], required_hardware="true") # was tags=["advanced", "intervlan"]
@attr(tags=["TODO"], required_hardware="true")
def test_06_network_services_VPC_DeleteAllMultiplePF(self): def test_06_network_services_VPC_DeleteAllMultiplePF(self):
""" Test case no 233: Delete all Static NAT rules for two/multiple virtual networks of a VPC. """ Test case no 233: Delete all Static NAT rules for two/multiple virtual networks of a VPC.
Observe the status of the Public IP Addresses of the rules when the Virtual Router is in Running State. Observe the status of the Public IP Addresses of the rules when the Virtual Router is in Running State.
"""
# Validate the following # Validate the following
# 1. Create a VPC with cidr - 10.1.1.1/16. # 1. Create a VPC with cidr - 10.1.1.1/16.
@ -670,9 +552,10 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
# 10. Succesfully wget a file from http server present on vm1, vm2, vm3 and vm4. # 10. Succesfully wget a file from http server present on vm1, vm2, vm3 and vm4.
# 12. Delete all PF rultes for vm1, vm2, vm3 and vm4. # 12. Delete all PF rultes for vm1, vm2, vm3 and vm4.
# 13. Fail to ssh and http to vm1, vm2, vm3 and vm4. # 13. Fail to ssh and http to vm1, vm2, vm3 and vm4.
"""
network_1 = self.create_Network(self.services["network_offering"]) network_1 = self.create_network(self.services["network_offering"])
network_2 = self.create_Network(self.services["network_offering_no_lb"], '10.1.2.1') network_2 = self.create_network(self.services["network_offering_no_lb"], '10.1.2.1')
self.create_ingress_rule(network_1) self.create_ingress_rule(network_1)
self.create_ingress_rule(network_2) self.create_ingress_rule(network_2)
self.create_ingress_rule(network_1, self.services["http_rule"]) self.create_ingress_rule(network_1, self.services["http_rule"])

View File

@ -277,7 +277,8 @@ class TestVPCOffering(cloudstackTestCase):
self.validate_vpc_offering(vpc_off) self.validate_vpc_offering(vpc_off)
return return
@attr(tags=["advanced", "intervlan"], required_hardware="true") # was tags=["advanced", "intervlan"]
@attr(tags=["TODO"], required_hardware="true")
def test_02_deploy_vms_in_vpc_nw(self): def test_02_deploy_vms_in_vpc_nw(self):
"""Test deploy virtual machines in VPC networks""" """Test deploy virtual machines in VPC networks"""

View File

@ -21,7 +21,7 @@
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
from marvin.cloudstackTestCase import cloudstackTestCase from marvin.cloudstackTestCase import cloudstackTestCase
import unittest import unittest
from marvin.lib.utils import cleanup_resources, validateList from marvin.lib.utils import cleanup_resources
from marvin.lib.base import (VirtualMachine, from marvin.lib.base import (VirtualMachine,
NATRule, NATRule,
LoadBalancerRule, LoadBalancerRule,
@ -40,8 +40,7 @@ from marvin.lib.base import (VirtualMachine,
from marvin.lib.common import (get_domain, from marvin.lib.common import (get_domain,
get_zone, get_zone,
get_template, get_template,
get_free_vlan, wait_for_cleanup,
wait_for_cleanup,
list_virtual_machines, list_virtual_machines,
list_hosts, list_hosts,
findSuitableHostForMigration, findSuitableHostForMigration,
@ -958,777 +957,6 @@ class TestVMLifeCycleVPC(cloudstackTestCase):
) )
return return
class TestVMLifeCycleSharedNwVPC(cloudstackTestCase):
@classmethod
def setUpClass(cls):
cls.testClient = super(TestVMLifeCycleSharedNwVPC, cls).getClsTestClient()
cls.api_client = cls.testClient.getApiClient()
cls.services = Services().services
# Get Zone, Domain and templates
cls.domain = get_domain(cls.api_client)
cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
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.account = Account.create(
cls.api_client,
cls.services["account"],
admin=True,
domainid=cls.domain.id
)
cls.services["vpc"]["cidr"] = '10.1.1.1/16'
cls.vpc = VPC.create(
cls.api_client,
cls.services["vpc"],
vpcofferingid=cls.vpc_off.id,
zoneid=cls.zone.id,
account=cls.account.name,
domainid=cls.account.domainid
)
cls.nw_off = NetworkOffering.create(
cls.api_client,
cls.services["network_offering"],
conservemode=False
)
# Enable Network offering
cls.nw_off.update(cls.api_client, state='Enabled')
# Creating network using the network offering created
cls.network_1 = Network.create(
cls.api_client,
cls.services["network"],
accountid=cls.account.name,
domainid=cls.account.domainid,
networkofferingid=cls.nw_off.id,
zoneid=cls.zone.id,
gateway='10.1.1.1',
vpcid=cls.vpc.id
)
cls.nw_off_no_lb = NetworkOffering.create(
cls.api_client,
cls.services["network_offering_no_lb"],
conservemode=False
)
cls.shared_nw_off = NetworkOffering.create(
cls.api_client,
cls.services["network_off_shared"],
conservemode=False
)
# Enable Network offering
cls.shared_nw_off.update(cls.api_client, state='Enabled')
physical_network, shared_vlan = get_free_vlan(cls.api_client, cls.zone.id)
if shared_vlan is None:
assert False, "Failed to get free vlan id for shared network creation in the zone"
#create network using the shared network offering created
cls.services["network"]["acltype"] = "Domain"
cls.services["network"]["physicalnetworkid"] = physical_network.id
cls.services["network"]["vlan"] = shared_vlan
# Start Ip and End Ip should be specified for shared network
cls.services["network"]["startip"] = '10.1.2.20'
cls.services["network"]["endip"] = '10.1.2.30'
# Creating network using the network offering created
cls.network_2 = Network.create(
cls.api_client,
cls.services["network"],
accountid=cls.account.name,
domainid=cls.account.domainid,
networkofferingid=cls.shared_nw_off.id,
zoneid=cls.zone.id,
gateway='10.1.2.1',
)
cls.vm_1 = VirtualMachine.create(
cls.api_client,
cls.services["virtual_machine"],
accountid=cls.account.name,
domainid=cls.account.domainid,
serviceofferingid=cls.service_offering.id,
networkids=[str(cls.network_1.id),
str(cls.network_2.id)]
)
cls.vm_2 = VirtualMachine.create(
cls.api_client,
cls.services["virtual_machine"],
accountid=cls.account.name,
domainid=cls.account.domainid,
serviceofferingid=cls.service_offering.id,
networkids=[str(cls.network_1.id),
str(cls.network_2.id)]
)
cls.vm_3 = VirtualMachine.create(
cls.api_client,
cls.services["virtual_machine"],
accountid=cls.account.name,
domainid=cls.account.domainid,
serviceofferingid=cls.service_offering.id,
networkids=[str(cls.network_1.id),
str(cls.network_2.id)]
)
cls.public_ip_1 = PublicIPAddress.create(
cls.api_client,
accountid=cls.account.name,
zoneid=cls.zone.id,
domainid=cls.account.domainid,
networkid=cls.network_1.id,
vpcid=cls.vpc.id
)
cls.lb_rule = LoadBalancerRule.create(
cls.api_client,
cls.services["lbrule"],
ipaddressid=cls.public_ip_1.ipaddress.id,
accountid=cls.account.name,
networkid=cls.network_1.id,
vpcid=cls.vpc.id,
domainid=cls.account.domainid
)
# Only the vms in the same network can be added to load balancing rule
# hence we can't add vm_2 with vm_1
cls.lb_rule.assign(cls.api_client, [cls.vm_1])
cls.public_ip_2 = PublicIPAddress.create(
cls.api_client,
accountid=cls.account.name,
zoneid=cls.zone.id,
domainid=cls.account.domainid,
networkid=cls.network_1.id,
vpcid=cls.vpc.id
)
cls.nat_rule = NATRule.create(
cls.api_client,
cls.vm_1,
cls.services["natrule"],
ipaddressid=cls.public_ip_2.ipaddress.id,
openfirewall=False,
networkid=cls.network_1.id,
vpcid=cls.vpc.id
)
# Opening up the ports in VPC
cls.nwacl_nat = NetworkACL.create(
cls.api_client,
networkid=cls.network_1.id,
services=cls.services["natrule"],
traffictype='Ingress'
)
cls.nwacl_lb = NetworkACL.create(
cls.api_client,
networkid=cls.network_1.id,
services=cls.services["lbrule"],
traffictype='Ingress'
)
cls.services["icmp_rule"]["protocol"] = "all"
cls.nwacl_internet_1 = NetworkACL.create(
cls.api_client,
networkid=cls.network_1.id,
services=cls.services["icmp_rule"],
traffictype='Egress'
)
cls._cleanup = [
cls.account,
cls.network_2,
cls.nw_off,
cls.shared_nw_off,
cls.vpc_off,
cls.service_offering,
]
return
@classmethod
def tearDownClass(cls):
try:
cls.vpc_off.update(cls.api_client, state='Disabled')
cls.shared_nw_off.update(cls.api_client, state='Disabled')
cls.nw_off.update(cls.api_client, state='Disabled')
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:
cleanup_resources(self.apiclient, self.cleanup)
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
def validate_network_rules(self):
"""Validating if the network rules (PF/LB) works properly or not?"""
try:
self.debug("Checking if we can SSH into VM_1 through %s?" %
(self.public_ip_1.ipaddress.ipaddress))
ssh_1 = self.vm_1.get_ssh_client(
ipaddress=self.public_ip_1.ipaddress.ipaddress,
reconnect=True)
self.debug("SSH into VM is successfully")
self.debug("Verifying if we can ping to outside world from VM?")
# Ping to outsite world
res = ssh_1.execute("ping -c 1 www.google.com")
# res = 64 bytes from maa03s17-in-f20.1e100.net (74.125.236.212):
# icmp_req=1 ttl=57 time=25.9 ms
# --- www.l.google.com ping statistics ---
# 1 packets transmitted, 1 received, 0% packet loss, time 0ms
# rtt min/avg/max/mdev = 25.970/25.970/25.970/0.000 ms
result = str(res)
self.assertEqual(
result.count("1 received"),
1,
"Ping to outside world from VM should be successful"
)
self.debug("We should be allowed to ping virtual gateway")
self.debug("Finding the gateway corresponding to isolated network")
gateways = [nic.gateway for nic in self.vm_1.nic if nic.networkid == self.network_1.id]
gateway_list_validation_result = validateList(gateways)
self.assertEqual(gateway_list_validation_result[0], PASS, "gateway list validation failed due to %s" %
gateway_list_validation_result[2])
gateway = gateway_list_validation_result[1]
self.debug("VM gateway: %s" % gateway)
res = ssh_1.execute("ping -c 1 %s" % gateway)
self.debug("ping -c 1 %s: %s" % (gateway, res))
result = str(res)
self.assertEqual(
result.count("1 received"),
1,
"Ping to VM gateway should be successful"
)
except Exception as e:
self.fail("Failed to SSH into VM - %s, %s" %
(self.public_ip_1.ipaddress.ipaddress, e))
return
@attr(tags=["advanced", "intervlan"], required_hardware="true")
def test_01_deploy_instance_in_network(self):
""" Test deploy an instance in VPC networks
"""
# Validate the following
# 1. Successful deployment of the User VM.
# 2. Ping any host in the public Internet successfully.
# 3. Ping the gateways of the VPC's guest network and the
# Shared Guest Network successfully.
self.debug("Check if deployed VMs are in running state?")
vms = VirtualMachine.list(
self.apiclient,
account=self.account.name,
domainid=self.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("Validating if network rules are coonfigured properly?")
self.validate_network_rules()
return
@attr(tags=["advanced", "intervlan"], required_hardware="true")
def test_02_stop_instance_in_network(self):
""" Test stop an instance in VPC networks
"""
# Validate the following
# 1. Stop the virtual machines.
# 2. Rules should be still configured on virtual router.
self.debug("Validating if network rules are coonfigured properly?")
self.validate_network_rules()
self.debug("Stopping one of the virtual machines in account: %s" %
self.account.name)
try:
self.vm_2.stop(self.apiclient)
except Exception as e:
self.fail("Failed to stop the virtual instances, %s" % e)
self.debug("Validating if network rules are coonfigured properly?")
self.validate_network_rules()
return
@attr(tags=["advanced", "intervlan"], required_hardware="true")
def test_03_start_instance_in_network(self):
""" Test start an instance in VPC networks
"""
# Validate the following
# 1. Start the virtual machines.
# 2. Rules should be still configured on virtual router.
self.debug("Validating if network rules are coonfigured properly?")
self.validate_network_rules()
self.debug("Starting one of the virtual machines in account: %s" %
self.account.name)
try:
self.vm_2.start(self.apiclient)
except Exception as e:
self.fail("Failed to start the virtual instances, %s" % e)
self.debug("Check if the instance is in stopped state?")
vms = VirtualMachine.list(
self.apiclient,
id=self.vm_2.id,
listall=True
)
self.assertEqual(
isinstance(vms, list),
True,
"List virtual machines should return a valid list"
)
vm = vms[0]
self.assertEqual(
vm.state,
"Running",
"Virtual machine should be in running state"
)
self.debug("Validating if network rules are coonfigured properly?")
self.validate_network_rules()
return
@attr(tags=["advanced", "intervlan"], required_hardware="true")
def test_04_reboot_instance_in_network(self):
""" Test reboot an instance in VPC networks
"""
# Validate the following
# 1. Reboot the virtual machines.
# 2. Rules should be still configured on virtual router.
self.debug("Validating if network rules are coonfigured properly?")
self.validate_network_rules()
self.debug("Restarting the virtual machines in account: %s" %
self.account.name)
try:
self.vm_1.reboot(self.apiclient)
self.vm_2.reboot(self.apiclient)
except Exception as e:
self.fail("Failed to reboot the virtual instances, %s" % e)
self.debug("Check if the instance is in stopped state?")
vms = VirtualMachine.list(
self.apiclient,
account=self.account.name,
domainid=self.account.domainid,
listall=True
)
self.assertEqual(
isinstance(vms, list),
True,
"List virtual machines should return a valid list"
)
for vm in vms:
self.assertEqual(
vm.state,
"Running",
"Virtual machine should be in running state"
)
self.debug("Validating if network rules are coonfigured properly?")
self.validate_network_rules()
return
@attr(tags=["advanced", "intervlan"], required_hardware="true")
def test_05_destroy_instance_in_network(self):
""" Test destroy an instance in VPC networks
"""
# Validate the following
# 1. Destroy one of the virtual machines.
# 2. Rules should be still configured on virtual router.
self.debug("Destroying one of the virtual machines in account: %s" %
self.account.name)
try:
self.vm_2.delete(self.apiclient)
except Exception as e:
self.fail("Failed to destroy the virtual instances, %s" % e)
#Wait for expunge interval to cleanup VM
wait_for_cleanup(self.apiclient, ["expunge.delay", "expunge.interval"])
self.debug("Check if the instance is in stopped state?")
vms = VirtualMachine.list(
self.apiclient,
id=self.vm_2.id,
listall=True
)
self.assertEqual(
vms,
None,
"List virtual machines should not return anything"
)
self.debug("Validating if network rules are coonfigured properly?")
self.validate_network_rules()
return
@attr(tags=["advanced", "intervlan"], required_hardware="true")
def test_06_recover_instance_in_network(self):
""" Test recover an instance in VPC networks
"""
self.debug("Deploying vm")
self.vm_2 = VirtualMachine.create(
self.api_client,
self.services["virtual_machine"],
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
networkids=[str(self.network_1.id),
str(self.network_2.id)]
)
self.cleanup.append(self.vm_2)
try:
self.vm_2.delete(self.apiclient, expunge=False)
except Exception as e:
self.fail("Failed to destroy the virtual instances, %s" % e)
try:
self.vm_2.recover(self.apiclient)
except Exception as e:
self.fail("Failed to recover the virtual instances, %s" % e)
self.debug("Check if the instance is in stopped state?")
vms = VirtualMachine.list(
self.apiclient,
id=self.vm_2.id,
listall=True
)
self.assertEqual(
isinstance(vms, list),
True,
"List virtual machines should return a valid list"
)
vm = vms[0]
self.assertEqual(
vm.state,
"Stopped",
"Virtual machine should be in stopped state"
)
self.debug("Starting the instance: %s" % self.vm_2.name)
try:
self.vm_2.start(self.apiclient)
except Exception as e:
self.fail("Failed to start the instances, %s" % e)
vms = VirtualMachine.list(
self.apiclient,
id=self.vm_2.id,
listall=True
)
self.assertEqual(
isinstance(vms, list),
True,
"List virtual machines should return a valid list"
)
vm = vms[0]
self.assertEqual(
vm.state,
"Running",
"Virtual machine should be in running state"
)
self.debug("Validating if network rules are coonfigured properly?")
self.validate_network_rules()
return
@attr(tags=["advanced", "intervlan"], required_hardware="true")
def test_07_migrate_instance_in_network(self):
""" Test migrate an instance in VPC networks
"""
# Validate the following
# 1. Migrate the virtual machines to other hosts
# 2. Vm should be in stopped state. State both the instances
# 3. Make sure that all the PF,LB and Static NAT rules on this VM
# works as expected.
# 3. Make sure that we are able to access google.com from this user Vm
self.hypervisor = self.testClient.getHypervisorInfo()
if self.hypervisor.lower() in ['lxc']:
self.skipTest("vm migrate is not supported in %s" % self.hypervisor)
self.debug("Validating if network rules are coonfigured properly?")
self.validate_network_rules()
host = findSuitableHostForMigration(self.apiclient, self.vm_1.id)
if host is None:
self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
self.debug("Migrating VM-ID: %s to Host: %s" % (
self.vm_1.id,
host.id
))
try:
self.vm_1.migrate(self.apiclient, hostid=host.id)
except Exception as e:
self.fail("Failed to migrate instance, %s" % e)
self.debug("Validating if network rules are coonfigured properly?")
self.validate_network_rules()
return
@attr(tags=["advanced", "intervlan"], required_hardware="true")
def test_08_user_data(self):
""" Test user data in virtual machines
"""
# 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 a vm in network1 and a vm in network2 using userdata
# Steps
# 1.Query for the user data for both the user vms from both networks
# User should be able to query the user data for the vms belonging to
# both the networks from the VR
try:
ssh = self.vm_1.get_ssh_client(
ipaddress=self.public_ip_1.ipaddress.ipaddress,
reconnect=True)
self.debug("SSH into VM is successfully")
ssh.execute("yum install wget -y")
except Exception as e:
self.fail("Failed to SSH into instance")
self.debug("check the userdata with that of present in router")
try:
cmds = [
"wget http://%s/latest/user-data" % self.network_1.gateway,
"cat user-data",
]
for c in cmds:
result = ssh.execute(c)
self.debug("%s: %s" % (c, result))
except Exception as e:
self.fail("Failed to SSH in Virtual machine: %s" % e)
res = str(result)
self.assertEqual(
res.count(
self.services["virtual_machine"]["userdata"]),
1,
"Verify user data from router"
)
return
@attr(tags=["advanced", "intervlan"], required_hardware="true")
def test_09_meta_data(self):
""" Test meta data in virtual machines
"""
# 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 a vm in network1 and a vm in network2 using userdata
# Steps
# 1.Query for the meta data for both the user vms from both networks
# User should be able to query the user data for the vms belonging to
# both the networks from the VR
try:
ssh = self.vm_1.get_ssh_client(
ipaddress=self.public_ip_1.ipaddress.ipaddress,
reconnect=True)
self.debug("SSH into VM is successfully")
except Exception as e:
self.fail("Failed to SSH into instance")
self.debug("check the metadata with that of present in router")
try:
cmds = [
"wget http://%s/latest/vm-id" % self.network_1.gateway,
"cat vm-id",
]
for c in cmds:
result = ssh.execute(c)
self.debug("%s: %s" % (c, result))
except Exception as e:
self.fail("Failed to SSH in Virtual machine: %s" % e)
res = str(result)
self.assertNotEqual(
res,
None,
"Meta data should be returned from router"
)
return
@attr(tags=["advanced", "intervlan"], required_hardware="true")
def test_10_expunge_instance_in_network(self):
""" Test expunge an instance in VPC networks
"""
# Validate the following
# 1. Recover the virtual machines.
# 2. Vm should be in stopped state. State both the instances
# 3. Make sure that all the PF,LB and Static NAT rules on this VM
# works as expected.
# 3. Make sure that we are able to access google.com from this user Vm
self.debug("Validating if network rules are coonfigured properly?")
self.validate_network_rules()
self.debug("Delete virtual machines in account: %s" %
self.account.name)
try:
self.vm_3.delete(self.apiclient)
except Exception as e:
self.fail("Failed to destroy the virtual instances, %s" % e)
self.debug(
"Waiting for expunge interval to cleanup the network and VMs")
wait_for_cleanup(
self.apiclient,
["expunge.interval", "expunge.delay"]
)
self.debug("Validating if network rules are coonfigured properly?")
self.validate_network_rules()
self.debug(
"Deleting the rest of the virtual machines in account: %s" %
self.account.name)
try:
self.vm_1.delete(self.apiclient)
except Exception as e:
self.fail("Failed to destroy the virtual instances, %s" % e)
self.debug(
"Waiting for expunge interval to cleanup the network and VMs")
wait_for_cleanup(
self.apiclient,
["expunge.interval", "expunge.delay"]
)
# Check if the network rules still exists after Vm expunged
self.debug("Checking if NAT rules existed ")
with self.assertRaises(Exception):
NATRule.list(
self.apiclient,
id=self.nat_rule.id,
listall=True
)
LoadBalancerRule.list(
self.apiclient,
id=self.lb_rule.id,
listall=True
)
return
class TestVMLifeCycleBothIsolated(cloudstackTestCase): class TestVMLifeCycleBothIsolated(cloudstackTestCase):

View File

@ -182,30 +182,24 @@ class TestVMDeployVPC(cloudstackTestCase):
) )
cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["virtual_machine"]["zoneid"] = cls.zone.id
cls.services["virtual_machine"]["template"] = cls.template.id cls.services["virtual_machine"]["template"] = cls.template.id
cls._cleanup = []
cls.service_offering = ServiceOffering.create( cls.service_offering = ServiceOffering.create(
cls.api_client, cls.api_client,
cls.services["service_offering"] cls.services["service_offering"]
) )
cls._cleanup.append(cls.service_offering)
cls.vpc_off = VpcOffering.create( cls.vpc_off = VpcOffering.create(
cls.api_client, cls.api_client,
cls.services["vpc_offering"] cls.services["vpc_offering"]
) )
cls._cleanup.append(cls.vpc_off)
cls.vpc_off.update(cls.api_client, state='Enabled') cls.vpc_off.update(cls.api_client, state='Enabled')
cls._cleanup = [
cls.service_offering,
cls.vpc_off
]
return return
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
try: super(TestVMDeployVPC, cls).tearDownClass()
#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): def setUp(self):
self.apiclient = self.testClient.getApiClient() self.apiclient = self.testClient.getApiClient()
@ -220,12 +214,7 @@ class TestVMDeployVPC(cloudstackTestCase):
return return
def tearDown(self): def tearDown(self):
try: super(TestVMDeployVPC, self).tearDown()
#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
def validate_vpc_offering(self, vpc_offering): def validate_vpc_offering(self, vpc_offering):
"""Validates the VPC offering""" """Validates the VPC offering"""
@ -286,44 +275,10 @@ class TestVMDeployVPC(cloudstackTestCase):
networkid=network.id, networkid=network.id,
vpcid=self.vpc.id vpcid=self.vpc.id
) )
self.cleanup.append(public_ip)
self.debug("Associated {} with network {}".format(public_ip.ipaddress.ipaddress, network.id)) self.debug("Associated {} with network {}".format(public_ip.ipaddress.ipaddress, network.id))
return public_ip return public_ip
def create_natrule(self, vm, public_ip, network, services=None):
self.debug("Creating NAT rule in network for vm with public IP")
if not services:
services = self.services["natrule"]
nat_rule = NATRule.create(self.apiclient,
vm,
services,
ipaddressid=public_ip.ipaddress.id,
openfirewall=False,
networkid=network.id,
vpcid=self.vpc.id
)
self.debug("Adding NetworkACL rules to make NAT rule accessible")
nwacl_nat = NetworkACL.create(self.apiclient,
networkid=network.id,
services=services,
traffictype='Ingress'
)
self.debug('nwacl_nat=%s' % nwacl_nat.__dict__)
return nat_rule
def check_ssh_into_vm(self, vm, public_ip, testnegative=False):
self.debug("Checking if we can SSH into VM={} on public_ip={}".format(vm.name, public_ip.ipaddress.ipaddress))
try:
vm.get_ssh_client(ipaddress=public_ip.ipaddress.ipaddress)
if not testnegative:
self.debug("SSH into VM={} on public_ip={} is successful".format(vm.name, public_ip.ipaddress.ipaddress))
else:
self.fail("SSH into VM={} on public_ip={} is successful".format(vm.name, public_ip.ipaddress.ipaddress))
except:
if not testnegative:
self.fail("Failed to SSH into VM - %s" % (public_ip.ipaddress.ipaddress))
else:
self.debug("Failed to SSH into VM - %s" % (public_ip.ipaddress.ipaddress))
def deployVM_and_verify_ssh_access(self, network, ip): def deployVM_and_verify_ssh_access(self, network, ip):
# Spawn an instance in that network # Spawn an instance in that network
vm = VirtualMachine.create( vm = VirtualMachine.create(
@ -335,6 +290,7 @@ class TestVMDeployVPC(cloudstackTestCase):
networkids=[str(network.id)], networkids=[str(network.id)],
ipaddress=ip, ipaddress=ip,
) )
self.cleanup.append(vm)
self.assertIsNotNone( self.assertIsNotNone(
vm, vm,
"Failed to deploy vm with ip address {} and hostname {}".format(ip, self.services["virtual_machine"]["name"]) "Failed to deploy vm with ip address {} and hostname {}".format(ip, self.services["virtual_machine"]["name"])
@ -351,10 +307,11 @@ class TestVMDeployVPC(cloudstackTestCase):
) )
public_ip_1 = self.acquire_publicip(network) public_ip_1 = self.acquire_publicip(network)
#ensure vm is accessible over public ip #ensure vm is accessible over public ip
nat_rule = self.create_natrule(vm, public_ip_1, network) nat_rule = self.create_natrule_for_services(vm, public_ip_1, network)
self.check_ssh_into_vm(vm, public_ip_1, testnegative=False) self.check_ssh_into_vm(vm, public_ip_1, testnegative=False)
#remove the nat rule #remove the nat rule
nat_rule.delete(self.apiclient) nat_rule.delete(self.apiclient)
self.cleanup.remove(nat_rule)
return vm return vm
@attr(tags=["advanced", "intervlan"], required_hardware="false") @attr(tags=["advanced", "intervlan"], required_hardware="false")
@ -1799,7 +1756,8 @@ class TestVMDeployVPC(cloudstackTestCase):
) )
return return
@attr(tags=["advanced", "intervlan"], required_hardware="true") # was tags=["advanced", "intervlan"]
@attr(tags=["TODO"], required_hardware="true")
def test_07_delete_network_with_rules(self): def test_07_delete_network_with_rules(self):
""" Test delete network that has PF/staticNat/LB rules/Network Acl """ Test delete network that has PF/staticNat/LB rules/Network Acl
""" """
@ -2381,15 +2339,15 @@ class TestVMDeployVPC(cloudstackTestCase):
account=self.account.name, account=self.account.name,
domainid=self.account.domainid domainid=self.account.domainid
) )
self.cleanup.append(self.vpc)
self.validate_vpc_network(self.vpc) self.validate_vpc_network(self.vpc)
self.nw_off = NetworkOffering.create( self.nw_off = NetworkOffering.create(
self.apiclient, self.apiclient,
self.services["network_offering"], self.services["network_offering"],
conservemode=False conservemode=False
) )
# Enable Network offering
self.nw_off.update(self.apiclient, state='Enabled')
self._cleanup.append(self.nw_off) self._cleanup.append(self.nw_off)
self.nw_off.update(self.apiclient, state='Enabled')
# Creating network using the network offering created # Creating network using the network offering created
self.debug("Creating network with network offering: %s" % self.nw_off.id) self.debug("Creating network with network offering: %s" % self.nw_off.id)
network_1 = Network.create( network_1 = Network.create(
@ -2402,6 +2360,7 @@ class TestVMDeployVPC(cloudstackTestCase):
gateway='10.1.1.1', gateway='10.1.1.1',
vpcid=self.vpc.id vpcid=self.vpc.id
) )
self.cleanup.append(network_1)
self.debug("Created network with ID: %s" % network_1.id) self.debug("Created network with ID: %s" % network_1.id)
# Spawn vm1 in that network # Spawn vm1 in that network
vm1_ip = "10.1.1.10" vm1_ip = "10.1.1.10"
@ -2416,7 +2375,9 @@ class TestVMDeployVPC(cloudstackTestCase):
#Destroy both the vms #Destroy both the vms
try: try:
vm1.delete(self.apiclient, expunge=True) vm1.delete(self.apiclient, expunge=True)
self.cleanup.remove(vm1)
vm2.delete(self.apiclient, expunge=True) vm2.delete(self.apiclient, expunge=True)
self.cleanup.remove(vm2)
except Exception as e: except Exception as e:
raise Exception("Warning: Exception in expunging vms: %s" % e) raise Exception("Warning: Exception in expunging vms: %s" % e)
""" """
@ -2437,10 +2398,9 @@ class TestVMDeployVPC(cloudstackTestCase):
vm4 = self.deployVM_and_verify_ssh_access(network_1, vm2_ip) vm4 = self.deployVM_and_verify_ssh_access(network_1, vm2_ip)
try: try:
vm3.delete(self.apiclient, expunge=True) vm3.delete(self.apiclient, expunge=True)
self.cleanup.remove(vm3)
vm4.delete(self.apiclient, expunge=True) vm4.delete(self.apiclient, expunge=True)
self.cleanup.remove(vm4)
except Exception as e: except Exception as e:
raise Exception("Warning: Excepting in expunging vms vm3 and vm4: %s" % e) raise Exception("Warning: Excepting in expunging vms vm3 and vm4: %s" % e)
return return

View File

@ -14,10 +14,17 @@
# KIND, either express or implied. See the License for the # KIND, either express or implied. See the License for the
# specific language governing permissions and limitations # specific language governing permissions and limitations
# under the License. # under the License.
import time
import unittest import unittest
from marvin.lib.utils import verifyElementInList, cleanup_resources from marvin.lib.utils import verifyElementInList
from marvin.codes import PASS from marvin.codes import PASS
from marvin.lib.base import (
NATRule,
Network,
NetworkACL,
NetworkOffering,
VirtualMachine
)
def user(Name, DomainName, AcctType): def user(Name, DomainName, AcctType):
@ -44,7 +51,7 @@ class cloudstackTestCase(unittest.case.TestCase):
@desc:Uses the utility function verifyElementInList and @desc:Uses the utility function verifyElementInList and
asserts based upon PASS\FAIL value of the output. asserts based upon PASS\FAIL value of the output.
Takes one additional argument of what message to assert with Takes one additional argument of what message to assert with
when failed when faileddef start_vpcrouter(
''' '''
out = verifyElementInList(inp, toverify, responsevar, pos) out = verifyElementInList(inp, toverify, responsevar, pos)
unittest.TestCase.assertEqual(out[0], PASS, "msg:%s" % out[1]) unittest.TestCase.assertEqual(out[0], PASS, "msg:%s" % out[1])
@ -59,19 +66,21 @@ class cloudstackTestCase(unittest.case.TestCase):
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
cls.debug("Cleaning up the resources")
try: try:
if hasattr(cls,'_cleanup'): if hasattr(cls,'_cleanup'):
if hasattr(cls,'apiclient'): if hasattr(cls,'apiclient'):
cleanup_resources(cls.apiclient, reversed(cls._cleanup)) cls.cleanup_resources(cls.apiclient, reversed(cls._cleanup))
elif hasattr(cls,'api_client'): elif hasattr(cls,'api_client'):
cleanup_resources(cls.api_client, reversed(cls._cleanup)) cls.cleanup_resources(cls.api_client, reversed(cls._cleanup))
except Exception as e: except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e) raise Exception("Warning: Exception during cleanup : %s" % e)
def tearDown(self): def tearDown(self):
self.debug("Cleaning up the resources")
try: try:
if hasattr(self,'apiclient') and hasattr(self,'cleanup'): if hasattr(self,'apiclient') and hasattr(self,'cleanup'):
cleanup_resources(self.apiclient, reversed(self.cleanup)) self.cleanup_resources(self.apiclient, reversed(self.cleanup))
except Exception as e: except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e) raise Exception("Warning: Exception during cleanup : %s" % e)
return return
@ -83,3 +92,143 @@ class cloudstackTestCase(unittest.case.TestCase):
if isinstance(msg, str): if isinstance(msg, str):
msg = msg.encode() msg = msg.encode()
super(cloudstackTestCase,self).assertEqual(first,second,msg) super(cloudstackTestCase,self).assertEqual(first,second,msg)
@classmethod
def cleanup_resources(cls, api_client, resources):
"""
Delete resources (created during tests)
"""
for obj in resources:
if isinstance(obj, VirtualMachine):
obj.delete(api_client, expunge=True)
else:
obj.delete(api_client)
def check_wget_from_vm(self, vm, public_ip, network=None, testnegative=False, isVmAccessible=True):
import urllib.request, urllib.error
self.debug(f"Checking if we can wget from a VM={vm.name} http server on public_ip={public_ip.ipaddress.ipaddress}, expecting failure == {testnegative} and vm is acceccible == {isVmAccessible}")
try:
if not isVmAccessible:
self.create_natrule_for_services(vm, public_ip, network)
self.setup_webserver(vm, public_ip)
urllib.request.urlretrieve(f"http://{public_ip.ipaddress.ipaddress}/test.html", filename="test.html")
if not testnegative:
self.debug("Successesfull to wget from VM=%s http server on public_ip=%s" % (vm.name, public_ip.ipaddress.ipaddress))
else:
self.fail("Successesfull to wget from VM=%s http server on public_ip=%s" % (vm.name, public_ip.ipaddress.ipaddress))
except Exception as e:
if not testnegative:
self.fail("Failed to wget from VM=%s http server on public_ip=%s: %s" % (vm.name, public_ip.ipaddress.ipaddress, e))
else:
self.debug("Failed to wget from VM=%s http server on public_ip=%s: %s" % (vm.name, public_ip.ipaddress.ipaddress, e))
def setup_webserver(self, vm, public_ip=None):
# Start httpd service on VM first
if public_ip == None:
sshClient = vm.get_ssh_client()
else:
sshClient = vm.get_ssh_client(ipaddress=public_ip.ipaddress.ipaddress)
# Test to see if we are on a tiny linux box (using busybox)
res = "apache"
try:
res = str(sshClient.execute("busybox")).lower()
except Exception as e:
self.debug("no busybox {e}")
if "httpd" in res:
self.debug(f"using busybox httpd on VM {vm.name}/{vm.id}")
self.setup_busybox(sshClient)
else:
self.debug(f"using apache httpd on VM {vm.name}/{vm.id}")
self.setup_apache(sshClient)
def setup_busybox(self, sshClient):
""" Create a dummy test.html file and fire up the busybox web server """
sshClient.execute('echo test > test.html')
sshClient.execute("/usr/sbin/httpd")
self.debug("Setup webserver using busybox")
def setup_apache(self, sshClient):
sshClient.execute("iptables -F")
sshClient.execute('echo test > /var/www/html/test.html')
sshClient.execute("service httpd start")
time.sleep(5)
ssh_response = str(sshClient.execute("service httpd status")).lower()
self.debug("httpd service status is: %s" % ssh_response)
if "httpd: unrecognized service" in ssh_response or "inactive" in ssh_response:
ssh_res = sshClient.execute("yum install httpd -y")
if "Complete!" not in ssh_res:
raise Exception("Failed to install http server")
sshClient.execute("service httpd start")
time.sleep(5)
ssh_response = str(sshClient.execute("service httpd status")).lower()
if not "running" in ssh_response:
raise Exception("Failed to start httpd service")
self.debug("Setup webserver using apache")
def check_ssh_into_vm(self, vm, public_ip, testnegative=False):
self.debug(f"Checking if we can SSH into VM={vm.name} on public_ip={public_ip.ipaddress.ipaddress}")
try:
vm.get_ssh_client(ipaddress=public_ip.ipaddress.ipaddress)
if not testnegative:
self.debug(f"SSH into VM={vm.name} on public_ip={public_ip.ipaddress.ipaddress} was successful")
else:
self.fail(f"SSH into VM={vm.name} on public_ip={public_ip.ipaddress.ipaddress} succeeded, but should have been rejected")
except:
if not testnegative:
self.fail(f"Failed to SSH into VM {vm.name} with ip {public_ip.ipaddress.ipaddress}")
else:
self.debug(f"Failed to SSH into VM {vm.name} with {public_ip.ipaddress.ipaddress}, as expected")
def create_natrule_for_services(self, vm, public_ip, network, services=None):
self.debug(f"Creating NAT rule in network for vm {vm.name} with public IP {public_ip.ipaddress.ipaddress}")
if not services:
services = self.services["natrule"]
nat_rule = NATRule.create(self.apiclient,
vm,
services,
ipaddressid=public_ip.ipaddress.id,
openfirewall=False,
networkid=network.id,
vpcid=self.vpc.id
)
self.cleanup.append(nat_rule)
self.debug("Adding NetworkACL rules to make NAT rule accessible")
nwacl_nat = NetworkACL.create(self.apiclient,
networkid=network.id,
services=services,
traffictype='Ingress'
)
self.cleanup.append(nwacl_nat)
self.debug(f'nwacl_nat={nwacl_nat.__dict__}')
return nat_rule
def create_network(self, net_offerring, gateway='10.1.1.1', vpc=None):
try:
self.debug('Create NetworkOffering')
net_offerring["name"] = "NET_OFF-" + str(gateway)
nw_off = NetworkOffering.create(self.apiclient,
net_offerring,
conservemode=False
)
self.cleanup.append(nw_off)
# Enable Network offering
nw_off.update(self.apiclient, state='Enabled')
self.debug('Created and Enabled NetworkOffering')
self.services["network"]["name"] = "NETWORK-" + str(gateway)
self.debug('Adding Network=%s' % self.services["network"])
obj_network = Network.create(self.apiclient,
self.services["network"],
accountid=self.account.name,
domainid=self.account.domainid,
networkofferingid=nw_off.id,
zoneid=self.zone.id,
gateway=gateway,
vpcid=vpc.id if vpc else self.vpc.id
)
self.cleanup.append(obj_network)
self.debug("Created network with ID: %s" % obj_network.id)
return obj_network
except Exception as e:
self.fail('Unable to create a Network with offering=%s because of %s ' % (net_offerring, e))

View File

@ -234,6 +234,16 @@ test_data = {
"PortForwarding": 'VirtualRouter', "PortForwarding": 'VirtualRouter',
}, },
}, },
"nw_off_no_services": {
"name": 'Test Network offering without services',
"displaytext": 'Test Network offering without services',
"guestiptype": 'Isolated',
"supportedservices": '',
"traffictype": 'GUEST',
"availability": 'Optional',
"serviceProviderList": {
},
},
"nw_off_isolated_netscaler": { "nw_off_isolated_netscaler": {
"name": 'Netscaler', "name": 'Netscaler',
"displaytext": 'Netscaler', "displaytext": 'Netscaler',

View File

@ -2546,6 +2546,7 @@ class GuestOs:
@classmethod @classmethod
def listCategories(cls, apiclient, **kwargs): def listCategories(cls, apiclient, **kwargs):
"""List all Os Categories""" """List all Os Categories"""
cmd = listOsCategories.listOsCategoriesCmd()
[setattr(cmd, k, v) for k, v in list(kwargs.items())] [setattr(cmd, k, v) for k, v in list(kwargs.items())]
return (apiclient.listOsCategories(cmd)) return (apiclient.listOsCategories(cmd))

View File

@ -1476,6 +1476,7 @@ def matchResourceCount(apiclient, expectedCount, resourceType,
accountid=None, projectid=None): accountid=None, projectid=None):
"""Match the resource count of account/project with the expected """Match the resource count of account/project with the expected
resource count""" resource count"""
expected = int(expectedCount) # initialise as int to make sure floats passed are acceptable
try: try:
resourceholderlist = None resourceholderlist = None
if accountid: if accountid:
@ -1489,6 +1490,7 @@ def matchResourceCount(apiclient, expectedCount, resourceType,
resourceCount = resourceholderlist[0].primarystoragetotal resourceCount = resourceholderlist[0].primarystoragetotal
elif resourceType == RESOURCE_SECONDARY_STORAGE: elif resourceType == RESOURCE_SECONDARY_STORAGE:
resourceCount = resourceholderlist[0].secondarystoragetotal resourceCount = resourceholderlist[0].secondarystoragetotal
expected = expectedCount # as the exception, an original value is needed here (should be of type float)
elif resourceType == RESOURCE_CPU: elif resourceType == RESOURCE_CPU:
resourceCount = resourceholderlist[0].cputotal resourceCount = resourceholderlist[0].cputotal
elif resourceType == RESOURCE_MEMORY: elif resourceType == RESOURCE_MEMORY:
@ -1507,7 +1509,7 @@ def matchResourceCount(apiclient, expectedCount, resourceType,
resourceCount = resourceholderlist[0].networktotal resourceCount = resourceholderlist[0].networktotal
elif resourceType == RESOURCE_VPC: elif resourceType == RESOURCE_VPC:
resourceCount = resourceholderlist[0].vpctotal resourceCount = resourceholderlist[0].vpctotal
assert str(resourceCount) == str(expectedCount),\ assert str(resourceCount) == str(expected),\
"Resource count %s should match with the expected resource count %s" %\ "Resource count %s should match with the expected resource count %s" %\
(resourceCount, expectedCount) (resourceCount, expectedCount)
except Exception as e: except Exception as e:

View File

@ -156,11 +156,14 @@ def random_gen(id=None, size=6, chars=string.ascii_uppercase + string.digits):
def cleanup_resources(api_client, resources): def cleanup_resources(api_client, resources):
"""Delete resources""" """
Delete resources (created during tests)
TODO move to marvin.cloudstackTestCase.cloudstackTestCase as it is really part of all test_runs
"""
for obj in resources: for obj in resources:
obj.delete(api_client) obj.delete(api_client)
def is_server_ssh_ready(ipaddress, port, username, password, retries=20, retryinterv=30, timeout=10.0, keyPairFileLocation=None): def is_server_ssh_ready(ipaddress, port, username, password, retries=20, retryinterv=30, timeout=10.0, keyPairFileLocation=None):
''' '''
@Name: is_server_ssh_ready @Name: is_server_ssh_ready