diff --git a/test/integration/component/test_project_limits.py b/test/integration/component/test_project_limits.py index d4fb92d8da9..adae0474399 100644 --- a/test/integration/component/test_project_limits.py +++ b/test/integration/component/test_project_limits.py @@ -18,7 +18,7 @@ """ #Import Local Modules from nose.plugins.attrib import attr -from marvin.cloudstackTestCase import cloudstackTestCase +from marvin.cloudstackTestCase import cloudstackTestCase,unittest #from marvin.cloudstackAPI import * from marvin.lib.utils import (cleanup_resources, validateList) @@ -522,7 +522,7 @@ class TestResourceLimitsProject(cloudstackTestCase): def setUpClass(cls): cls.testClient = super(TestResourceLimitsProject, cls).getClsTestClient() cls.api_client = cls.testClient.getApiClient() - + cls.hypervisor = cls.testClient.getHypervisorInfo() cls.services = Services().services cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype @@ -758,6 +758,8 @@ class TestResourceLimitsProject(cloudstackTestCase): # 5. Try to create another snapshot in this project. It should give # user an appropriate error and an alert should be generated. + if self.hypervisor.lower() in ['hyperv']: + raise self.skipTest("Snapshots feature is not supported on Hyper-V") self.debug( "Updating snapshot resource limits for project: %s" % self.project.id) diff --git a/test/integration/component/test_ps_domain_limits.py b/test/integration/component/test_ps_domain_limits.py index 268174f61a9..f9aa023b000 100644 --- a/test/integration/component/test_ps_domain_limits.py +++ b/test/integration/component/test_ps_domain_limits.py @@ -46,25 +46,29 @@ from marvin.codes import (PASS, FAILED, RESOURCE_PRIMARY_STORAGE) + class TestMultipleChildDomain(cloudstackTestCase): @classmethod def setUpClass(cls): cloudstackTestClient = super(TestMultipleChildDomain, - cls).getClsTestClient() + cls).getClsTestClient() cls.api_client = cloudstackTestClient.getApiClient() + cls.hypervisor = cloudstackTestClient.getHypervisorInfo() # Fill services from the external config file cls.services = cloudstackTestClient.getParsedTestDataConfig() # Get Zone, Domain and templates 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.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) + 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 @@ -72,8 +76,9 @@ class TestMultipleChildDomain(cloudstackTestCase): cls._cleanup = [] try: - 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.append(cls.service_offering) except Exception as e: cls.tearDownClass() @@ -96,11 +101,11 @@ class TestMultipleChildDomain(cloudstackTestCase): self.services["disk_offering"]["disksize"] = 5 try: self.disk_offering = DiskOffering.create( - self.apiclient, - self.services["disk_offering"] - ) - self.assertNotEqual(self.disk_offering, None, \ - "Disk offering is None") + self.apiclient, + self.services["disk_offering"] + ) + self.assertNotEqual(self.disk_offering, None, + "Disk offering is None") self.cleanup.append(self.disk_offering) except Exception as e: self.tearDown() @@ -121,44 +126,56 @@ class TestMultipleChildDomain(cloudstackTestCase): child domains""" try: - #Update resource limit for domain + # Update resource limit for domain Resources.updateLimit(self.apiclient, resourcetype=10, - max=parentdomainlimit, - domainid=self.parent_domain.id) + max=parentdomainlimit, + domainid=self.parent_domain.id) # Update Resource limit for sub-domains Resources.updateLimit(self.apiclient, resourcetype=10, - max=subdomainlimit, - domainid=self.cadmin_1.domainid) + max=subdomainlimit, + domainid=self.cadmin_1.domainid) Resources.updateLimit(self.apiclient, resourcetype=10, - max=subdomainlimit, - domainid=self.cadmin_2.domainid) + max=subdomainlimit, + domainid=self.cadmin_2.domainid) except Exception as e: return [FAIL, e] return [PASS, None] def setupAccounts(self): try: - self.parent_domain = Domain.create(self.apiclient, - services=self.services["domain"], - parentdomainid=self.domain.id) - self.parentd_admin = Account.create(self.apiclient, self.services["account"], - admin=True, domainid=self.parent_domain.id) + self.parent_domain = Domain.create( + self.apiclient, + services=self.services["domain"], + parentdomainid=self.domain.id) + self.parentd_admin = Account.create( + self.apiclient, + self.services["account"], + admin=True, + domainid=self.parent_domain.id) # Create sub-domains and their admin accounts - self.cdomain_1 = Domain.create(self.apiclient, - services=self.services["domain"], - parentdomainid=self.parent_domain.id) - self.cdomain_2 = Domain.create(self.apiclient, - services=self.services["domain"], - parentdomainid=self.parent_domain.id) + self.cdomain_1 = Domain.create( + self.apiclient, + services=self.services["domain"], + parentdomainid=self.parent_domain.id) + self.cdomain_2 = Domain.create( + self.apiclient, + services=self.services["domain"], + parentdomainid=self.parent_domain.id) - self.cadmin_1 = Account.create(self.apiclient, self.services["account"], - admin=True, domainid=self.cdomain_1.id) + self.cadmin_1 = Account.create( + self.apiclient, + self.services["account"], + admin=True, + domainid=self.cdomain_1.id) - self.cadmin_2 = Account.create(self.apiclient, self.services["account"], - admin=True, domainid=self.cdomain_2.id) + self.cadmin_2 = Account.create( + self.apiclient, + self.services["account"], + admin=True, + domainid=self.cdomain_2.id) # Cleanup the resources created at end of test self.cleanup.append(self.cadmin_1) @@ -169,14 +186,14 @@ class TestMultipleChildDomain(cloudstackTestCase): self.cleanup.append(self.parent_domain) users = { - self.cdomain_1: self.cadmin_1, - self.cdomain_2: self.cadmin_2 - } + self.cdomain_1: self.cadmin_1, + self.cdomain_2: self.cadmin_2 + } except Exception as e: return [FAIL, e, None] return [PASS, None, users] - @attr(tags=["advanced","selfservice"]) + @attr(tags=["advanced", "selfservice"]) def test_01_multiple_domains_primary_storage_limits(self): """Test primary storage limit of domain and its sub-domains @@ -204,73 +221,97 @@ class TestMultipleChildDomain(cloudstackTestCase): # Setting up account and domain hierarchy result = self.setupAccounts() - self.assertEqual(result[0], PASS,\ - "Failure while setting up accounts and domains: %s" % result[1]) + self.assertEqual( + result[0], + PASS, + "Failure while setting up accounts and domains: %s" % + result[1]) - templatesize = (self.template.size / (1024**3)) + templatesize = (self.template.size / (1024 ** 3)) disksize = 10 subdomainlimit = (templatesize + disksize) - result = self.updateDomainResourceLimits(((subdomainlimit*3)- 1), subdomainlimit) - self.assertEqual(result[0], PASS,\ - "Failure while updating resource limits: %s" % result[1]) + result = self.updateDomainResourceLimits( + ((subdomainlimit * 3) - 1), + subdomainlimit) + self.assertEqual( + result[0], + PASS, + "Failure while updating resource limits: %s" % + result[1]) try: self.services["disk_offering"]["disksize"] = disksize - disk_offering_custom = DiskOffering.create(self.apiclient, - services=self.services["disk_offering"]) + disk_offering_custom = DiskOffering.create( + self.apiclient, + services=self.services["disk_offering"]) self.cleanup.append(disk_offering_custom) except Exception as e: self.fail("Failed to create disk offering") # Get API clients of parent and child domain admin accounts api_client_admin = self.testClient.getUserApiClient( - UserName=self.parentd_admin.name, - DomainName=self.parentd_admin.domain) - self.assertNotEqual(api_client_admin, FAILED,\ - "Failed to create api client for account: %s" % self.parentd_admin.name) + UserName=self.parentd_admin.name, + DomainName=self.parentd_admin.domain) + self.assertNotEqual( + api_client_admin, + FAILED, + "Failed to create api client for account: %s" % + self.parentd_admin.name) api_client_cadmin_1 = self.testClient.getUserApiClient( - UserName=self.cadmin_1.name, - DomainName=self.cadmin_1.domain) - self.assertNotEqual(api_client_cadmin_1, FAILED,\ - "Failed to create api client for account: %s" % self.cadmin_1.name) + UserName=self.cadmin_1.name, + DomainName=self.cadmin_1.domain) + self.assertNotEqual( + api_client_cadmin_1, + FAILED, + "Failed to create api client for account: %s" % + self.cadmin_1.name) api_client_cadmin_2 = self.testClient.getUserApiClient( - UserName=self.cadmin_2.name, - DomainName=self.cadmin_2.domain) - self.assertNotEqual(api_client_cadmin_2, FAILED,\ - "Failed to create api client for account: %s" % self.cadmin_2.name) + UserName=self.cadmin_2.name, + DomainName=self.cadmin_2.domain) + self.assertNotEqual( + api_client_cadmin_2, + FAILED, + "Failed to create api client for account: %s" % + self.cadmin_2.name) VirtualMachine.create( - api_client_cadmin_1, self.services["virtual_machine"], - accountid=self.cadmin_1.name, domainid=self.cadmin_1.domainid, - diskofferingid=disk_offering_custom.id, serviceofferingid=self.service_offering.id - ) + api_client_cadmin_1, + self.services["virtual_machine"], + accountid=self.cadmin_1.name, + domainid=self.cadmin_1.domainid, + diskofferingid=disk_offering_custom.id, + serviceofferingid=self.service_offering.id) self.initialResourceCount = (templatesize + disksize) result = isDomainResourceCountEqualToExpectedCount( - self.apiclient, self.parent_domain.id, - self.initialResourceCount, RESOURCE_PRIMARY_STORAGE) + self.apiclient, self.parent_domain.id, + self.initialResourceCount, RESOURCE_PRIMARY_STORAGE) self.assertFalse(result[0], result[1]) self.assertTrue(result[2], "Resource count does not match") # Create VM in second child domain vm_2 = VirtualMachine.create( - api_client_cadmin_2, self.services["virtual_machine"], - accountid=self.cadmin_2.name, domainid=self.cadmin_2.domainid, - diskofferingid=disk_offering_custom.id, serviceofferingid=self.service_offering.id - ) + api_client_cadmin_2, + self.services["virtual_machine"], + accountid=self.cadmin_2.name, + domainid=self.cadmin_2.domainid, + diskofferingid=disk_offering_custom.id, + serviceofferingid=self.service_offering.id) # 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 # should fail with self.assertRaises(Exception): VirtualMachine.create( - api_client_admin, self.services["virtual_machine"], - accountid=self.parentd_admin.name, domainid=self.parentd_admin.domainid, - diskofferingid=disk_offering_custom.id, serviceofferingid=self.service_offering.id - ) + api_client_admin, + self.services["virtual_machine"], + accountid=self.parentd_admin.name, + domainid=self.parentd_admin.domainid, + diskofferingid=disk_offering_custom.id, + serviceofferingid=self.service_offering.id) # Deleting user account self.cadmin_1.delete(self.apiclient) @@ -278,8 +319,8 @@ class TestMultipleChildDomain(cloudstackTestCase): expectedCount = self.initialResourceCount result = isDomainResourceCountEqualToExpectedCount( - self.apiclient, self.parent_domain.id, - expectedCount, RESOURCE_PRIMARY_STORAGE) + self.apiclient, self.parent_domain.id, + expectedCount, RESOURCE_PRIMARY_STORAGE) self.assertFalse(result[0], result[1]) self.assertTrue(result[2], "Resource count does not match") @@ -293,8 +334,8 @@ class TestMultipleChildDomain(cloudstackTestCase): expectedCount = 0 result = isDomainResourceCountEqualToExpectedCount( - self.apiclient, self.parent_domain.id, - expectedCount, RESOURCE_PRIMARY_STORAGE) + self.apiclient, self.parent_domain.id, + expectedCount, RESOURCE_PRIMARY_STORAGE) self.assertFalse(result[0], result[1]) self.assertTrue(result[2], "Resource count does not match") return @@ -315,68 +356,79 @@ class TestMultipleChildDomain(cloudstackTestCase): # Setting up account and domain hierarchy result = self.setupAccounts() - self.assertEqual(result[0], PASS,\ - "Failure while setting up accounts and domains: %s" % result[1]) + self.assertEqual( + result[0], + PASS, + "Failure while setting up accounts and domains: %s" % + result[1]) users = result[2] - templatesize = (self.template.size / (1024**3)) + templatesize = (self.template.size / (1024 ** 3)) for domain, admin in users.items(): self.account = admin self.domain = domain apiclient = self.testClient.getUserApiClient( - UserName=self.account.name, - DomainName=self.account.domain) - self.assertNotEqual(apiclient, FAILED,\ - "Failed to create api client for account: %s" % self.account.name) + UserName=self.account.name, + DomainName=self.account.domain) + self.assertNotEqual( + apiclient, + FAILED, + "Failed to create api client for account: %s" % + self.account.name) try: vm = VirtualMachine.create( - apiclient, self.services["virtual_machine"], - accountid=self.account.name, domainid=self.account.domainid, - diskofferingid=self.disk_offering.id, serviceofferingid=self.service_offering.id - ) + apiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + diskofferingid=self.disk_offering.id, + serviceofferingid=self.service_offering.id) expectedCount = templatesize + self.disk_offering.disksize result = isDomainResourceCountEqualToExpectedCount( - self.apiclient, self.domain.id, - expectedCount, RESOURCE_PRIMARY_STORAGE) + self.apiclient, self.domain.id, + expectedCount, RESOURCE_PRIMARY_STORAGE) self.assertFalse(result[0], result[1]) self.assertTrue(result[2], "Resource count does not match") # Creating service offering with 10 GB volume self.services["disk_offering"]["disksize"] = 10 - disk_offering_10_GB = DiskOffering.create(self.apiclient, - services=self.services["disk_offering"]) + disk_offering_10_GB = DiskOffering.create( + self.apiclient, + services=self.services["disk_offering"]) self.cleanup.append(disk_offering_10_GB) volume = Volume.create( - apiclient, self.services["volume"], - zoneid=self.zone.id, account=self.account.name, - domainid=self.account.domainid, diskofferingid=disk_offering_10_GB.id - ) + apiclient, + self.services["volume"], + zoneid=self.zone.id, + account=self.account.name, + domainid=self.account.domainid, + diskofferingid=disk_offering_10_GB.id) - volumeSize = (volume.size / (1024**3)) + volumeSize = (volume.size / (1024 ** 3)) expectedCount += volumeSize - vm.attach_volume(apiclient, volume=volume) + vm.attach_volume(apiclient, volume=volume) result = isDomainResourceCountEqualToExpectedCount( - self.apiclient, self.domain.id, - expectedCount, RESOURCE_PRIMARY_STORAGE) + self.apiclient, self.domain.id, + expectedCount, RESOURCE_PRIMARY_STORAGE) self.assertFalse(result[0], result[1]) self.assertTrue(result[2], "Resource count does not match") expectedCount -= volumeSize vm.detach_volume(apiclient, volume=volume) result = isDomainResourceCountEqualToExpectedCount( - self.apiclient, self.domain.id, - expectedCount, RESOURCE_PRIMARY_STORAGE) + self.apiclient, self.domain.id, + expectedCount, RESOURCE_PRIMARY_STORAGE) self.assertFalse(result[0], result[1]) self.assertTrue(result[2], "Resource count does not match") except Exception as e: self.fail("Failure: %s" % e) - return + return @attr(tags=["advanced"], required_hardware="false") def test_03_multiple_domains_multiple_volumes(self): @@ -397,67 +449,80 @@ class TestMultipleChildDomain(cloudstackTestCase): # Setting up account and domain hierarchy result = self.setupAccounts() if result[0] == FAIL: - self.fail("Failure while setting up accounts and domains: %s" % result[1]) + self.fail( + "Failure while setting up accounts and domains: %s" % + result[1]) else: users = result[2] - templatesize = (self.template.size / (1024**3)) + templatesize = (self.template.size / (1024 ** 3)) for domain, admin in users.items(): self.account = admin self.domain = domain apiclient = self.testClient.getUserApiClient( - UserName=self.account.name, - DomainName=self.account.domain) - self.assertNotEqual(apiclient, FAILED,\ - "Failed to create api client for account: %s" % self.account.name) + UserName=self.account.name, + DomainName=self.account.domain) + self.assertNotEqual( + apiclient, + FAILED, + "Failed to create api client for account: %s" % + self.account.name) try: vm = VirtualMachine.create( - apiclient, self.services["virtual_machine"], - accountid=self.account.name, domainid=self.account.domainid, - diskofferingid=self.disk_offering.id, serviceofferingid=self.service_offering.id - ) + apiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + diskofferingid=self.disk_offering.id, + serviceofferingid=self.service_offering.id) expectedCount = templatesize + self.disk_offering.disksize result = isDomainResourceCountEqualToExpectedCount( - self.apiclient, self.domain.id, - expectedCount, RESOURCE_PRIMARY_STORAGE) + self.apiclient, self.domain.id, + expectedCount, RESOURCE_PRIMARY_STORAGE) self.assertFalse(result[0], result[1]) self.assertTrue(result[2], "Resource count does not match") volume1size = self.services["disk_offering"]["disksize"] = 15 - disk_offering_15_GB = DiskOffering.create(self.apiclient, - services=self.services["disk_offering"]) + disk_offering_15_GB = DiskOffering.create( + self.apiclient, + services=self.services["disk_offering"]) self.cleanup.append(disk_offering_15_GB) volume2size = self.services["disk_offering"]["disksize"] = 20 - disk_offering_20_GB = DiskOffering.create(self.apiclient, - services=self.services["disk_offering"]) + disk_offering_20_GB = DiskOffering.create( + self.apiclient, + services=self.services["disk_offering"]) self.cleanup.append(disk_offering_20_GB) volume_1 = Volume.create( - apiclient, self.services["volume"], - zoneid=self.zone.id, account=self.account.name, - domainid=self.account.domainid, diskofferingid=disk_offering_15_GB.id - ) + apiclient, + self.services["volume"], + zoneid=self.zone.id, + account=self.account.name, + domainid=self.account.domainid, + diskofferingid=disk_offering_15_GB.id) volume_2 = Volume.create( - apiclient, self.services["volume"], - zoneid=self.zone.id, account=self.account.name, - domainid=self.account.domainid, diskofferingid=disk_offering_20_GB.id - ) + apiclient, + self.services["volume"], + zoneid=self.zone.id, + account=self.account.name, + domainid=self.account.domainid, + diskofferingid=disk_offering_20_GB.id) vm.attach_volume(apiclient, volume=volume_1) vm.attach_volume(apiclient, volume=volume_2) expectedCount += volume1size + volume2size result = isDomainResourceCountEqualToExpectedCount( - self.apiclient, self.domain.id, - expectedCount, RESOURCE_PRIMARY_STORAGE) + self.apiclient, self.domain.id, + expectedCount, RESOURCE_PRIMARY_STORAGE) self.assertFalse(result[0], result[1]) self.assertTrue(result[2], "Resource count does not match") @@ -466,16 +531,16 @@ class TestMultipleChildDomain(cloudstackTestCase): expectedCount -= volume1size result = isDomainResourceCountEqualToExpectedCount( - self.apiclient, self.domain.id, - expectedCount, RESOURCE_PRIMARY_STORAGE) + self.apiclient, self.domain.id, + expectedCount, RESOURCE_PRIMARY_STORAGE) self.assertFalse(result[0], result[1]) self.assertTrue(result[2], "Resource count does not match") expectedCount -= volume2size vm.detach_volume(apiclient, volume=volume_2) result = isDomainResourceCountEqualToExpectedCount( - self.apiclient, self.domain.id, - expectedCount, RESOURCE_PRIMARY_STORAGE) + self.apiclient, self.domain.id, + expectedCount, RESOURCE_PRIMARY_STORAGE) self.assertFalse(result[0], result[1]) self.assertTrue(result[2], "Resource count does not match") except Exception as e: @@ -498,9 +563,14 @@ class TestMultipleChildDomain(cloudstackTestCase): # 5. Delete volume which was created from snapshot and verify primary storage resource count""" + if self.hypervisor.lower() in ['hyperv']: + self.skipTest("Snapshots feature is not supported on Hyper-V") + result = self.setupAccounts() if result[0] == FAIL: - self.fail("Failure while setting up accounts and domains: %s" % result[1]) + self.fail( + "Failure while setting up accounts and domains: %s" % + result[1]) users = result[2] for domain, admin in users.items(): @@ -509,62 +579,75 @@ class TestMultipleChildDomain(cloudstackTestCase): try: apiclient = self.testClient.getUserApiClient( - UserName=self.account.name, - DomainName=self.account.domain) - self.assertNotEqual(apiclient, FAILED,\ - "Failed to create api client for account: %s" % self.account.name) + UserName=self.account.name, + DomainName=self.account.domain) + self.assertNotEqual( + apiclient, + FAILED, + "Failed to create api client for account: %s" % + self.account.name) vm = VirtualMachine.create( - apiclient, self.services["virtual_machine"], - accountid=self.account.name, domainid=self.account.domainid, - diskofferingid=self.disk_offering.id, serviceofferingid=self.service_offering.id - ) + apiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + diskofferingid=self.disk_offering.id, + serviceofferingid=self.service_offering.id) - templatesize = (self.template.size / (1024**3)) + templatesize = (self.template.size / (1024 ** 3)) - initialResourceCount = expectedCount = templatesize + self.disk_offering.disksize + initialResourceCount = expectedCount = templatesize + \ + self.disk_offering.disksize result = isDomainResourceCountEqualToExpectedCount( - self.apiclient, self.domain.id, - initialResourceCount, RESOURCE_PRIMARY_STORAGE) + self.apiclient, self.domain.id, + initialResourceCount, RESOURCE_PRIMARY_STORAGE) self.assertFalse(result[0], result[1]) self.assertTrue(result[2], "Resource count does not match") vm.stop(self.apiclient) - response = createSnapshotFromVirtualMachineVolume(apiclient, self.account, vm.id) + response = createSnapshotFromVirtualMachineVolume( + apiclient, + self.account, + vm.id) self.assertEqual(response[0], PASS, response[1]) snapshot = response[1] - response = snapshot.validateState(apiclient, Snapshot.BACKED_UP) + response = snapshot.validateState( + apiclient, + Snapshot.BACKED_UP) self.assertEqual(response[0], PASS, response[1]) - self.services["volume"]["size"] = self.services["disk_offering"]["disksize"] - volume = Volume.create_from_snapshot(apiclient, - snapshot_id=snapshot.id, - services=self.services["volume"], - account=self.account.name, - domainid=self.account.domainid) - volumeSize = (volume.size / (1024**3)) + self.services["volume"]["size"] = self.services[ + "disk_offering"]["disksize"] + volume = Volume.create_from_snapshot( + apiclient, + snapshot_id=snapshot.id, + services=self.services["volume"], + account=self.account.name, + domainid=self.account.domainid) + volumeSize = (volume.size / (1024 ** 3)) vm.attach_volume(apiclient, volume) expectedCount = initialResourceCount + (volumeSize) result = isDomainResourceCountEqualToExpectedCount( - self.apiclient, self.domain.id, - expectedCount, RESOURCE_PRIMARY_STORAGE) + self.apiclient, self.domain.id, + expectedCount, RESOURCE_PRIMARY_STORAGE) self.assertFalse(result[0], result[1]) self.assertTrue(result[2], "Resource count does not match") expectedCount -= volumeSize vm.detach_volume(apiclient, volume) result = isDomainResourceCountEqualToExpectedCount( - self.apiclient, self.domain.id, - expectedCount, RESOURCE_PRIMARY_STORAGE) + self.apiclient, self.domain.id, + expectedCount, RESOURCE_PRIMARY_STORAGE) self.assertFalse(result[0], result[1]) self.assertTrue(result[2], "Resource count does not match") volume.delete(apiclient) result = isDomainResourceCountEqualToExpectedCount( - self.apiclient, self.domain.id, - expectedCount, RESOURCE_PRIMARY_STORAGE) + self.apiclient, self.domain.id, + expectedCount, RESOURCE_PRIMARY_STORAGE) self.assertFalse(result[0], result[1]) self.assertTrue(result[2], "Resource count does not match") except Exception as e: @@ -573,7 +656,7 @@ class TestMultipleChildDomain(cloudstackTestCase): @attr(tags=["advanced"], required_hardware="false") def test_05_assign_virtual_machine_different_domain(self): - """Test assign virtual machine to account belonging to different domain + """Test assign virtual machine to account belonging to different domain # Steps 1. Create a parent domain and two sub-domains in it (also admin accounts @@ -590,41 +673,48 @@ class TestMultipleChildDomain(cloudstackTestCase): self.assertEqual(result[0], PASS, result[1]) apiclient = self.testClient.getUserApiClient( - UserName=self.cadmin_1.name, - DomainName=self.cadmin_1.domain) - self.assertNotEqual(apiclient, FAILED,\ - "Failed to create api client for account: %s" % self.cadmin_1.name) + UserName=self.cadmin_1.name, + DomainName=self.cadmin_1.domain) + self.assertNotEqual( + apiclient, + FAILED, + "Failed to create api client for account: %s" % + self.cadmin_1.name) try: vm_1 = VirtualMachine.create( - apiclient, self.services["virtual_machine"], - accountid=self.cadmin_1.name, domainid=self.cadmin_1.domainid, - diskofferingid=self.disk_offering.id, serviceofferingid=self.service_offering.id - ) + apiclient, + self.services["virtual_machine"], + accountid=self.cadmin_1.name, + domainid=self.cadmin_1.domainid, + diskofferingid=self.disk_offering.id, + serviceofferingid=self.service_offering.id) - templatesize = (self.template.size / (1024**3)) + templatesize = (self.template.size / (1024 ** 3)) expectedCount = templatesize + self.disk_offering.disksize result = isDomainResourceCountEqualToExpectedCount( - self.apiclient, self.cadmin_1.domainid, - expectedCount, RESOURCE_PRIMARY_STORAGE) + self.apiclient, self.cadmin_1.domainid, + expectedCount, RESOURCE_PRIMARY_STORAGE) self.assertFalse(result[0], result[1]) self.assertTrue(result[2], "Resource count does not match") vm_1.stop(apiclient) - vm_1.assign_virtual_machine(self.apiclient, account=self.cadmin_2.name, - domainid=self.cadmin_2.domainid) + vm_1.assign_virtual_machine( + self.apiclient, + account=self.cadmin_2.name, + domainid=self.cadmin_2.domainid) result = isDomainResourceCountEqualToExpectedCount( - self.apiclient, self.cadmin_2.domainid, - expectedCount, RESOURCE_PRIMARY_STORAGE) + self.apiclient, self.cadmin_2.domainid, + expectedCount, RESOURCE_PRIMARY_STORAGE) self.assertFalse(result[0], result[1]) self.assertTrue(result[2], "Resource count does not match") expectedCount = 0 result = isDomainResourceCountEqualToExpectedCount( - self.apiclient, self.cadmin_1.domainid, - expectedCount, RESOURCE_PRIMARY_STORAGE) + self.apiclient, self.cadmin_1.domainid, + expectedCount, RESOURCE_PRIMARY_STORAGE) self.assertFalse(result[0], result[1]) self.assertTrue(result[2], "Resource count does not match") except Exception as e: @@ -633,7 +723,7 @@ class TestMultipleChildDomain(cloudstackTestCase): @attr(tags=["advanced"], required_hardware="false") def test_06_destroy_recover_vm(self): - """Test primary storage counts while destroying and recovering VM + """Test primary storage counts while destroying and recovering VM # Steps 1. Create a parent domain and two sub-domains in it (also admin accounts of each domain) @@ -656,33 +746,35 @@ class TestMultipleChildDomain(cloudstackTestCase): self.domain = domain try: vm_1 = VirtualMachine.create( - self.apiclient, self.services["virtual_machine"], - accountid=self.account.name, domainid=self.account.domainid, - diskofferingid=self.disk_offering.id, serviceofferingid=self.service_offering.id - ) + self.apiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + diskofferingid=self.disk_offering.id, + serviceofferingid=self.service_offering.id) - templatesize = (self.template.size / (1024**3)) + templatesize = (self.template.size / (1024 ** 3)) expectedCount = templatesize + self.disk_offering.disksize result = isDomainResourceCountEqualToExpectedCount( - self.apiclient, self.account.domainid, - expectedCount, RESOURCE_PRIMARY_STORAGE) + self.apiclient, self.account.domainid, + expectedCount, RESOURCE_PRIMARY_STORAGE) self.assertFalse(result[0], result[1]) self.assertTrue(result[2], "Resource count does not match") vm_1.delete(self.apiclient, expunge=False) result = isDomainResourceCountEqualToExpectedCount( - self.apiclient, self.account.domainid, - expectedCount, RESOURCE_PRIMARY_STORAGE) + self.apiclient, self.account.domainid, + expectedCount, RESOURCE_PRIMARY_STORAGE) self.assertFalse(result[0], result[1]) self.assertTrue(result[2], "Resource count does not match") vm_1.recover(self.apiclient) result = isDomainResourceCountEqualToExpectedCount( - self.apiclient, self.account.domainid, - expectedCount, RESOURCE_PRIMARY_STORAGE) + self.apiclient, self.account.domainid, + expectedCount, RESOURCE_PRIMARY_STORAGE) self.assertFalse(result[0], result[1]) self.assertTrue(result[2], "Resource count does not match") except Exception as e: diff --git a/test/integration/component/test_ps_limits.py b/test/integration/component/test_ps_limits.py index e557249792d..c9a754b86bb 100644 --- a/test/integration/component/test_ps_limits.py +++ b/test/integration/component/test_ps_limits.py @@ -56,6 +56,7 @@ class TestVolumeLimits(cloudstackTestCase): cloudstackTestClient = super(TestVolumeLimits, cls).getClsTestClient() cls.api_client = cloudstackTestClient.getApiClient() + cls.hypervisor = cloudstackTestClient.getHypervisorInfo() # Fill services from the external config file cls.services = cloudstackTestClient.getParsedTestDataConfig() # Get Zone, Domain and templates @@ -505,7 +506,8 @@ class TestVolumeLimits(cloudstackTestCase): # 3. Create volume againt from this snapshto and attach to VM # 4. Verify that primary storage count increases by the volume size # 5. Detach and delete volume, verify primary storage count decreaes by volume size""" - + if self.hypervisor.lower() in ['hyperv']: + self.skipTest("Snapshots feature is not supported on Hyper-V") response = self.setupAccount(value) self.debug(response[0]) self.debug(response[1]) diff --git a/test/integration/component/test_resource_limits.py b/test/integration/component/test_resource_limits.py index f7fecb00e6b..5f29d70b62c 100644 --- a/test/integration/component/test_resource_limits.py +++ b/test/integration/component/test_resource_limits.py @@ -18,7 +18,7 @@ """ #Import Local Modules from nose.plugins.attrib import attr -from marvin.cloudstackTestCase import cloudstackTestCase +from marvin.cloudstackTestCase import cloudstackTestCase,unittest from marvin.lib.base import (VirtualMachine, Snapshot, Template, @@ -129,7 +129,7 @@ class TestResourceLimitsAccount(cloudstackTestCase): def setUpClass(cls): cls.testClient = super(TestResourceLimitsAccount, cls).getClsTestClient() cls.api_client = cls.testClient.getApiClient() - + cls.hypervisor = cls.testClient.getHypervisorInfo() cls.services = Services().services # Get Zone, Domain and templates cls.domain = get_domain(cls.api_client) @@ -448,6 +448,8 @@ class TestResourceLimitsAccount(cloudstackTestCase): # 5. Create 2 snapshot in account 2. Verify account 2 should be able to # create snapshots without any warning + if self.hypervisor.lower() in ['hyperv']: + self.skipTest("Snapshots feature is not supported on Hyper-V") self.debug( "Updating public IP resource limit for account: %s" % self.account_1.name) @@ -914,7 +916,7 @@ class TestResourceLimitsDomain(cloudstackTestCase): def setUpClass(cls): cls.testClient = super(TestResourceLimitsDomain, cls).getClsTestClient() cls.api_client = cls.testClient.getApiClient() - + cls.hypervisor = cls.testClient.getHypervisorInfo() cls.services = Services().services cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype @@ -1132,7 +1134,8 @@ class TestResourceLimitsDomain(cloudstackTestCase): # created # 5. Try to create another snapshot in this domain. It should give the # user an appropriate error and an alert should be generated. - + if self.hypervisor.lower() in ['hyperv']: + self.skipTest("Snapshots feature is not supported on Hyper-V") self.debug( "Updating snapshot resource limits for domain: %s" % self.account.domainid) diff --git a/test/integration/component/test_snapshots.py b/test/integration/component/test_snapshots.py index 4bb2dcf333e..5b8cdc720de 100644 --- a/test/integration/component/test_snapshots.py +++ b/test/integration/component/test_snapshots.py @@ -16,142 +16,143 @@ # under the License. """ P1 tests for Snapshots """ -#Import Local Modules -from nose.plugins.attrib import attr -from marvin.cloudstackTestCase import cloudstackTestCase +# Import Local Modules +from nose.plugins.attrib import attr +from marvin.cloudstackTestCase import cloudstackTestCase -from marvin.lib.base import (Snapshot, - Template, - VirtualMachine, - Account, - ServiceOffering, - DiskOffering, - Volume) +from marvin.lib.base import (Snapshot, + Template, + VirtualMachine, + Account, + ServiceOffering, + DiskOffering, + Volume) -from marvin.lib.common import (get_domain, - get_zone, - get_template, - list_events, - list_volumes, - list_snapshots, - list_templates, - list_virtual_machines, - ) +from marvin.lib.common import (get_domain, + get_zone, + get_template, + list_events, + list_volumes, + list_snapshots, + list_templates, + list_virtual_machines, + ) -from marvin.lib.utils import (cleanup_resources, - format_volume_to_ext3, - random_gen, - is_snapshot_on_nfs, - get_hypervisor_type) +from marvin.lib.utils import (cleanup_resources, + format_volume_to_ext3, + random_gen, + is_snapshot_on_nfs, + get_hypervisor_type) -from marvin.cloudstackAPI import detachVolume +from marvin.cloudstackAPI import detachVolume import time - class Services: + """Test Snapshots Services """ def __init__(self): self.services = { - "account": { - "email": "test@test.com", - "firstname": "Test", - "lastname": "User", - "username": "test", - # Random characters are appended for unique - # username - "password": "password", - }, - "service_offering": { - "name": "Tiny Instance", - "displaytext": "Tiny Instance", - "cpunumber": 1, - "cpuspeed": 200, # in MHz + "account": { + "email": "test@test.com", + "firstname": "Test", + "lastname": "User", + "username": "test", + # Random characters are appended for unique + # username + "password": "password", + }, + "service_offering": { + "name": "Tiny Instance", + "displaytext": "Tiny Instance", + "cpunumber": 1, + "cpuspeed": 200, # in MHz "memory": 256, # In MBs - }, - "disk_offering": { - "displaytext": "Small Disk", - "name": "Small Disk", - "disksize": 1 - }, - "server_with_disk": - { - "displayname": "Test VM -With Disk", - "username": "root", - "password": "password", - "ssh_port": 22, - "hypervisor": 'XenServer', - "privateport": 22, - "publicport": 22, - "protocol": 'TCP', - }, + }, + "disk_offering": { + "displaytext": "Small Disk", + "name": "Small Disk", + "disksize": 1 + }, + "server_with_disk": + { + "displayname": "Test VM -With Disk", + "username": "root", + "password": "password", + "ssh_port": 22, + "hypervisor": 'XenServer', + "privateport": 22, + "publicport": 22, + "protocol": 'TCP', + }, - "server_without_disk": - { - "displayname": "Test VM-No Disk", - "username": "root", - "password": "password", - "ssh_port": 22, - "hypervisor": 'XenServer', - "privateport": 22, - # For NAT rule creation - "publicport": 22, - "protocol": 'TCP', - }, - "server": { - "displayname": "TestVM", - "username": "root", - "password": "password", - "ssh_port": 22, - "hypervisor": 'XenServer', - "privateport": 22, - "publicport": 22, - "protocol": 'TCP', - }, - "recurring_snapshot": { - "intervaltype": 'HOURLY', - # Frequency of snapshots - "maxsnaps": 1, # Should be min 2 - "schedule": 1, - "timezone": 'US/Arizona', - # Timezone Formats - http://cloud.mindtouch.us/CloudStack_Documentation/Developer's_Guide%3A_CloudStack - }, - "templates": { - "displaytext": 'Template', - "name": 'Template', - "ostype": "CentOS 5.3 (64-bit)", - "templatefilter": 'self', - }, - "volume": { - "diskname": "APP Data Volume", - "size": 1, # in GBs - "xenserver": {"rootdiskdevice":"/dev/xvda", - "datadiskdevice_1": '/dev/xvdb', - "datadiskdevice_2": '/dev/xvdc', # Data Disk - }, - "kvm": {"rootdiskdevice": "/dev/vda", - "datadiskdevice_1": "/dev/vdb", - "datadiskdevice_2": "/dev/vdc" - }, - "vmware": {"rootdiskdevice": "/dev/hda", - "datadiskdevice_1": "/dev/hdb", - "datadiskdevice_2": "/dev/hdc" - } + "server_without_disk": + { + "displayname": "Test VM-No Disk", + "username": "root", + "password": "password", + "ssh_port": 22, + "hypervisor": 'XenServer', + "privateport": 22, + # For NAT rule creation + "publicport": 22, + "protocol": 'TCP', + }, + "server": { + "displayname": "TestVM", + "username": "root", + "password": "password", + "ssh_port": 22, + "hypervisor": 'XenServer', + "privateport": 22, + "publicport": 22, + "protocol": 'TCP', + }, + "recurring_snapshot": { + "intervaltype": 'HOURLY', + # Frequency of snapshots + "maxsnaps": 1, # Should be min 2 + "schedule": 1, + "timezone": 'US/Arizona', + # Timezone Formats - + # http://cloud.mindtouch.us/CloudStack_Documentation/Developer's_Guide%3A_CloudStack + }, + "templates": { + "displaytext": 'Template', + "name": 'Template', + "ostype": "CentOS 5.3 (64-bit)", + "templatefilter": 'self', + }, + "volume": { + "diskname": "APP Data Volume", + "size": 1, # in GBs + "xenserver": {"rootdiskdevice": "/dev/xvda", + "datadiskdevice_1": '/dev/xvdb', + "datadiskdevice_2": '/dev/xvdc', # Data Disk + }, + "kvm": {"rootdiskdevice": "/dev/vda", + "datadiskdevice_1": "/dev/vdb", + "datadiskdevice_2": "/dev/vdc" }, - "paths": { - "mount_dir": "/mnt/tmp", - "sub_dir": "test", - "sub_lvl_dir1": "test1", - "sub_lvl_dir2": "test2", - "random_data": "random.data", - }, - "ostype": "CentOS 5.3 (64-bit)", - # Cent OS 5.3 (64 bit) - "sleep": 60, - "timeout": 10, - } + "vmware": {"rootdiskdevice": "/dev/hda", + "datadiskdevice_1": "/dev/hdb", + "datadiskdevice_2": "/dev/hdc" + } + }, + "paths": { + "mount_dir": "/mnt/tmp", + "sub_dir": "test", + "sub_lvl_dir1": "test1", + "sub_lvl_dir2": "test2", + "random_data": "random.data", + }, + "ostype": "CentOS 5.3 (64-bit)", + # Cent OS 5.3 (64 bit) + "sleep": 60, + "timeout": 10, + } class TestSnapshots(cloudstackTestCase): @@ -167,17 +168,18 @@ class TestSnapshots(cloudstackTestCase): cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.disk_offering = DiskOffering.create( - cls.api_client, - cls.services["disk_offering"] - ) + cls.api_client, + cls.services["disk_offering"] + ) cls.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) + cls.api_client, + cls.zone.id, + cls.services["ostype"] + ) cls.services["domainid"] = cls.domain.id - cls.services["volume"]["zoneid"] = cls.services["server_with_disk"]["zoneid"] = cls.zone.id + cls.services["volume"]["zoneid"] = cls.services[ + "server_with_disk"]["zoneid"] = cls.zone.id cls.services["server_with_disk"]["diskoffering"] = cls.disk_offering.id cls.services["server_without_disk"]["zoneid"] = cls.zone.id @@ -187,23 +189,23 @@ class TestSnapshots(cloudstackTestCase): cls.services["diskoffering"] = cls.disk_offering.id cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] - ) + cls.api_client, + cls.services["service_offering"] + ) # Get Hypervisor Type cls.hypervisor = (get_hypervisor_type(cls.api_client)).lower() cls._cleanup = [ - cls.service_offering, - cls.disk_offering - ] + cls.service_offering, + cls.disk_offering + ] return @classmethod def tearDownClass(cls): try: - #Cleanup resources used + # Cleanup resources used cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -216,92 +218,105 @@ class TestSnapshots(cloudstackTestCase): # Create VMs, NAT Rules etc self.account = Account.create( - self.apiclient, - self.services["account"], - domainid=self.domain.id - ) + self.apiclient, + self.services["account"], + domainid=self.domain.id + ) self.virtual_machine = self.virtual_machine_with_disk = \ - VirtualMachine.create( - self.api_client, - self.services["server_with_disk"], - templateid=self.template.id, - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - mode=self.services["mode"] - ) + VirtualMachine.create( + self.api_client, + self.services["server_with_disk"], + templateid=self.template.id, + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + mode=self.services["mode"] + ) self.cleanup = [self.account, ] return def tearDown(self): try: - #Clean up, terminate the created instance, volumes and snapshots + # 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") def test_02_snapshot_data_disk(self): """Test Snapshot Data Disk """ volume = list_volumes( - self.apiclient, - virtualmachineid=self.virtual_machine_with_disk.id, - type='DATADISK', - listall=True - ) + self.apiclient, + virtualmachineid=self.virtual_machine_with_disk.id, + type='DATADISK', + listall=True + ) self.assertEqual( - isinstance(volume, list), - True, - "Check list response returns a valid list" - ) + isinstance(volume, list), + True, + "Check list response returns a valid list" + ) self.debug("Creating a Snapshot from data volume: %s" % volume[0].id) snapshot = Snapshot.create( - self.apiclient, - volume[0].id, - account=self.account.name, - domainid=self.account.domainid - ) + self.apiclient, + volume[0].id, + account=self.account.name, + domainid=self.account.domainid + ) snapshots = list_snapshots( - self.apiclient, - id=snapshot.id - ) + self.apiclient, + id=snapshot.id + ) self.assertEqual( - isinstance(snapshots, list), - True, - "Check list response returns a valid list" - ) + isinstance(snapshots, list), + True, + "Check list response returns a valid list" + ) self.assertNotEqual( - snapshots, - None, - "Check if result exists in list item call" - ) + snapshots, + None, + "Check if result exists in list item call" + ) self.assertEqual( - snapshots[0].id, - snapshot.id, - "Check resource id in list resources call" - ) - self.assertTrue(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config, self.zone.id, snapshot.id)) + snapshots[0].id, + snapshot.id, + "Check resource id in list resources call" + ) + self.assertTrue( + is_snapshot_on_nfs( + self.apiclient, + self.dbclient, + self.config, + self.zone.id, + snapshot.id)) return - @attr(speed = "slow") - @attr(tags=["advanced", "advancedns", "basic", "sg"], required_hardware="true") + @attr(speed="slow") + @attr( + tags=[ + "advanced", + "advancedns", + "basic", + "sg"], + required_hardware="true") def test_01_volume_from_snapshot(self): """Test Creating snapshot from volume having spaces in name(KVM) """ # Validate the following - #1. Create a virtual machine and data volume - #2. Attach data volume to VM - #3. Login to machine; create temp/test directories on data volume and write some random data - #4. Snapshot the Volume - #5. Create another Volume from snapshot - #6. Mount/Attach volume to another virtual machine - #7. Compare data, data should match + # 1. Create a virtual machine and data volume + # 2. Attach data volume to VM + # 3. Login to machine; create temp/test directories on data volume + # and write some random data + # 4. Snapshot the Volume + # 5. Create another Volume from snapshot + # 6. Mount/Attach volume to another virtual machine + # 7. Compare data, data should match random_data_0 = random_gen(size=100) random_data_1 = random_gen(size=100) @@ -316,63 +331,60 @@ class TestSnapshots(cloudstackTestCase): self.virtual_machine.ipaddress) volume = Volume.create( - self.apiclient, - self.services["volume"], - zoneid=self.zone.id, - account=self.account.name, - domainid=self.account.domainid, - diskofferingid=self.disk_offering.id - ) + self.apiclient, + self.services["volume"], + zoneid=self.zone.id, + account=self.account.name, + domainid=self.account.domainid, + diskofferingid=self.disk_offering.id + ) self.debug("Created volume with ID: %s" % volume.id) self.virtual_machine.attach_volume( - self.apiclient, - volume - ) + self.apiclient, + volume + ) self.debug("Attach volume: %s to VM: %s" % - (volume.id, self.virtual_machine.id)) - + (volume.id, self.virtual_machine.id)) self.debug("Formatting volume: %s to ext3" % volume.id) - #Format partition using ext3 - # Note that this is the second data disk partition of virtual machine as it was already containing - # data disk before attaching the new volume, Hence datadiskdevice_2 + # Format partition using ext3 + # Note that this is the second data disk partition of virtual machine + # as it was already containing data disk before attaching the new + # volume, Hence datadiskdevice_2 format_volume_to_ext3( - ssh_client, - self.services["volume"][self.hypervisor]["datadiskdevice_2"] - ) - cmds = [ "fdisk -l", - "mkdir -p %s" % self.services["paths"]["mount_dir"], - "mount -t ext3 %s1 %s" % ( - self.services["volume"][self.hypervisor]["datadiskdevice_2"], - self.services["paths"]["mount_dir"] - ), - "mkdir -p %s/%s/{%s,%s} " % ( - self.services["paths"]["mount_dir"], - self.services["paths"]["sub_dir"], - self.services["paths"]["sub_lvl_dir1"], - self.services["paths"]["sub_lvl_dir2"] - ), - "echo %s > %s/%s/%s/%s" % ( - random_data_0, - self.services["paths"]["mount_dir"], - self.services["paths"]["sub_dir"], - self.services["paths"]["sub_lvl_dir1"], - self.services["paths"]["random_data"] - ), - "echo %s > %s/%s/%s/%s" % ( - random_data_1, - self.services["paths"]["mount_dir"], - self.services["paths"]["sub_dir"], - self.services["paths"]["sub_lvl_dir2"], - self.services["paths"]["random_data"] - ), - "cat %s/%s/%s/%s" % ( - self.services["paths"]["mount_dir"], - self.services["paths"]["sub_dir"], - self.services["paths"]["sub_lvl_dir1"], - self.services["paths"]["random_data"] - ) - ] + ssh_client, + self.services["volume"][self.hypervisor]["datadiskdevice_2"] + ) + cmds = [ + "fdisk -l", + "mkdir -p %s" % + self.services["paths"]["mount_dir"], + "mount -t ext3 %s1 %s" % + (self.services["volume"][ + self.hypervisor]["datadiskdevice_2"], + self.services["paths"]["mount_dir"]), + "mkdir -p %s/%s/{%s,%s} " % + (self.services["paths"]["mount_dir"], + self.services["paths"]["sub_dir"], + self.services["paths"]["sub_lvl_dir1"], + self.services["paths"]["sub_lvl_dir2"]), + "echo %s > %s/%s/%s/%s" % + (random_data_0, + self.services["paths"]["mount_dir"], + self.services["paths"]["sub_dir"], + self.services["paths"]["sub_lvl_dir1"], + self.services["paths"]["random_data"]), + "echo %s > %s/%s/%s/%s" % + (random_data_1, + self.services["paths"]["mount_dir"], + self.services["paths"]["sub_dir"], + self.services["paths"]["sub_lvl_dir2"], + self.services["paths"]["random_data"]), + "cat %s/%s/%s/%s" % + (self.services["paths"]["mount_dir"], + self.services["paths"]["sub_dir"], + self.services["paths"]["sub_lvl_dir1"], + self.services["paths"]["random_data"])] for c in cmds: self.debug("Command: %s" % c) result = ssh_client.execute(c) @@ -380,95 +392,95 @@ class TestSnapshots(cloudstackTestCase): # Unmount the Sec Storage cmds = [ - "umount %s" % (self.services["paths"]["mount_dir"]), - ] + "umount %s" % (self.services["paths"]["mount_dir"]), + ] for c in cmds: self.debug("Command: %s" % c) ssh_client.execute(c) list_volume_response = Volume.list( - self.apiclient, - virtualmachineid=self.virtual_machine.id, - type='DATADISK', - id=volume.id - ) + self.apiclient, + virtualmachineid=self.virtual_machine.id, + type='DATADISK', + id=volume.id + ) self.assertEqual( - isinstance(list_volume_response, list), - True, - "Check list volume response for valid data" - ) + isinstance(list_volume_response, list), + True, + "Check list volume response for valid data" + ) volume_response = list_volume_response[0] - #Create snapshot from attached volume + # Create snapshot from attached volume snapshot = Snapshot.create( - self.apiclient, - volume_response.id, - account=self.account.name, - domainid=self.account.domainid - ) + self.apiclient, + volume_response.id, + account=self.account.name, + domainid=self.account.domainid + ) self.debug("Created snapshot: %s" % snapshot.id) - #Create volume from snapshot + # Create volume from snapshot volume_from_snapshot = Volume.create_from_snapshot( - self.apiclient, - snapshot.id, - self.services["volume"], - account=self.account.name, - domainid=self.account.domainid - ) + self.apiclient, + snapshot.id, + self.services["volume"], + account=self.account.name, + domainid=self.account.domainid + ) # Detach the volume from virtual machine self.virtual_machine.detach_volume( - self.apiclient, - volume - ) + self.apiclient, + volume + ) self.debug("Detached volume: %s from VM: %s" % - (volume.id, self.virtual_machine.id)) + (volume.id, self.virtual_machine.id)) self.debug("Created Volume: %s from Snapshot: %s" % ( - volume_from_snapshot.id, - snapshot.id)) + volume_from_snapshot.id, + snapshot.id)) volumes = Volume.list( - self.apiclient, - id=volume_from_snapshot.id - ) + self.apiclient, + id=volume_from_snapshot.id + ) self.assertEqual( - isinstance(volumes, list), - True, - "Check list response returns a valid list" - ) + isinstance(volumes, list), + True, + "Check list response returns a valid list" + ) self.assertNotEqual( - len(volumes), - None, - "Check Volume list Length" - ) + len(volumes), + None, + "Check Volume list Length" + ) self.assertEqual( - volumes[0].id, - volume_from_snapshot.id, - "Check Volume in the List Volumes" - ) - #Attaching volume to new VM + volumes[0].id, + volume_from_snapshot.id, + "Check Volume in the List Volumes" + ) + # Attaching volume to new VM new_virtual_machine = VirtualMachine.create( - self.apiclient, - self.services["server_without_disk"], - templateid=self.template.id, - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - mode=self.services["mode"] - ) + self.apiclient, + self.services["server_without_disk"], + templateid=self.template.id, + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + mode=self.services["mode"] + ) 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" % ( - volume_from_snapshot.id, - new_virtual_machine.id - )) + volume_from_snapshot.id, + new_virtual_machine.id + )) new_virtual_machine.attach_volume( - self.apiclient, - volume_from_snapshot - ) + self.apiclient, + volume_from_snapshot + ) # Rebooting is required so that newly attached disks are detected self.debug("Rebooting : %s" % new_virtual_machine.id) @@ -476,17 +488,20 @@ class TestSnapshots(cloudstackTestCase): new_virtual_machine.reboot(self.apiclient) try: - #Login to VM to verify test directories and files + # Login to VM to verify test directories and files ssh = new_virtual_machine.get_ssh_client() - # Mount datadiskdevice_1 because this is the first data disk of the new virtual machine - cmds = ["fdisk -l", - "mkdir -p %s" % self.services["paths"]["mount_dir"], - "mount -t ext3 %s1 %s" % ( - self.services["volume"][self.hypervisor]["datadiskdevice_1"], - self.services["paths"]["mount_dir"] - ), - ] + # Mount datadiskdevice_1 because this is the first data disk of the + # new virtual machine + cmds = [ + "fdisk -l", + "mkdir -p %s" % + self.services["paths"]["mount_dir"], + "mount -t ext3 %s1 %s" % + (self.services["volume"][ + self.hypervisor]["datadiskdevice_1"], + self.services["paths"]["mount_dir"]), + ] for c in cmds: self.debug("Command: %s" % c) @@ -494,107 +509,119 @@ class TestSnapshots(cloudstackTestCase): self.debug(result) returned_data_0 = ssh.execute( - "cat %s/%s/%s/%s" % ( - self.services["paths"]["mount_dir"], - self.services["paths"]["sub_dir"], - self.services["paths"]["sub_lvl_dir1"], - self.services["paths"]["random_data"] - )) + "cat %s/%s/%s/%s" % ( + self.services["paths"]["mount_dir"], + self.services["paths"]["sub_dir"], + self.services["paths"]["sub_lvl_dir1"], + self.services["paths"]["random_data"] + )) returned_data_1 = ssh.execute( - "cat %s/%s/%s/%s" % ( - self.services["paths"]["mount_dir"], - self.services["paths"]["sub_dir"], - self.services["paths"]["sub_lvl_dir2"], - self.services["paths"]["random_data"] - )) + "cat %s/%s/%s/%s" % ( + self.services["paths"]["mount_dir"], + self.services["paths"]["sub_dir"], + self.services["paths"]["sub_lvl_dir2"], + self.services["paths"]["random_data"] + )) except Exception as e: self.fail("SSH access failed for VM: %s, Exception: %s" % - (new_virtual_machine.ipaddress, e)) + (new_virtual_machine.ipaddress, e)) self.debug("returned_data_0: %s" % returned_data_0[0]) self.debug("returned_data_1: %s" % returned_data_1[0]) - #Verify returned data + # Verify returned data self.assertEqual( - random_data_0, - returned_data_0[0], - "Verify newly attached volume contents with existing one" - ) + random_data_0, + returned_data_0[0], + "Verify newly attached volume contents with existing one" + ) self.assertEqual( - random_data_1, - returned_data_1[0], - "Verify newly attached volume contents with existing one" - ) + random_data_1, + returned_data_1[0], + "Verify newly attached volume contents with existing one" + ) # Unmount the Sec Storage cmds = [ - "umount %s" % (self.services["paths"]["mount_dir"]), - ] + "umount %s" % (self.services["paths"]["mount_dir"]), + ] for c in cmds: self.debug("Command: %s" % c) ssh_client.execute(c) return - @attr(speed = "slow") + @attr(speed="slow") @attr(tags=["advanced", "advancedns", "smoke"], required_hardware="true") def test_04_delete_snapshot(self): """Test Delete Snapshot """ - #1. Snapshot the Volume - #2. Delete the snapshot - #3. Verify snapshot is removed by calling List Snapshots API - #4. Verify snapshot was removed from image store + # 1. Snapshot the Volume + # 2. Delete the snapshot + # 3. Verify snapshot is removed by calling List Snapshots API + # 4. Verify snapshot was removed from image store self.debug("Creating volume under account: %s" % self.account.name) volume = Volume.create( - self.apiclient, - self.services["volume"], - zoneid=self.zone.id, - account=self.account.name, - domainid=self.account.domainid, - diskofferingid=self.disk_offering.id - ) + self.apiclient, + self.services["volume"], + zoneid=self.zone.id, + account=self.account.name, + domainid=self.account.domainid, + diskofferingid=self.disk_offering.id + ) self.debug("Created volume: %s" % volume.id) self.debug("Attaching volume to vm: %s" % self.virtual_machine.id) self.virtual_machine.attach_volume( - self.apiclient, - volume - ) + self.apiclient, + volume + ) self.debug("Volume attached to vm") volumes = list_volumes( - self.apiclient, - virtualmachineid=self.virtual_machine.id, - type='DATADISK', - id=volume.id - ) + self.apiclient, + virtualmachineid=self.virtual_machine.id, + type='DATADISK', + id=volume.id + ) self.assertEqual( - isinstance(volumes, list), - True, - "Check list response returns a valid list" - ) + isinstance(volumes, list), + True, + "Check list response returns a valid list" + ) snapshot = Snapshot.create( - self.apiclient, - volumes[0].id, - account=self.account.name, - domainid=self.account.domainid - ) + self.apiclient, + volumes[0].id, + account=self.account.name, + domainid=self.account.domainid + ) snapshot.delete(self.apiclient) snapshots = list_snapshots( - self.apiclient, - id=snapshot.id - ) + self.apiclient, + id=snapshot.id + ) self.assertEqual( - snapshots, - None, - "Check if result exists in list item call" - ) - self.assertFalse(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config, self.zone.id, snapshot.id)) + snapshots, + None, + "Check if result exists in list item call" + ) + self.assertFalse( + is_snapshot_on_nfs( + self.apiclient, + self.dbclient, + self.config, + self.zone.id, + snapshot.id)) return - @attr(speed = "slow") - @attr(tags=["advanced", "advancedns", "basic", "sg"], required_hardware="true") + @attr(speed="slow") + @attr( + tags=[ + "advanced", + "advancedns", + "basic", + "sg"], + required_hardware="true") def test_03_snapshot_detachedDisk(self): """Test snapshot from detached disk """ @@ -609,167 +636,174 @@ class TestSnapshots(cloudstackTestCase): # 6. verify backup_snap_id was non null in the `snapshots` table volumes = list_volumes( - self.apiclient, - virtualmachineid=self.virtual_machine.id, - type='DATADISK', - listall=True - ) + self.apiclient, + virtualmachineid=self.virtual_machine.id, + type='DATADISK', + listall=True + ) self.assertEqual( - isinstance(volumes, list), - True, - "Check list response returns a valid list" - ) + isinstance(volumes, list), + True, + "Check list response returns a valid list" + ) volume = volumes[0] random_data_0 = random_gen(size=100) random_data_1 = random_gen(size=100) try: ssh_client = self.virtual_machine.get_ssh_client() - #Format partition using ext3 + # Format partition using ext3 format_volume_to_ext3( - ssh_client, - self.services["volume"][self.hypervisor]["datadiskdevice_1"] - ) + ssh_client, + self.services["volume"][self.hypervisor]["datadiskdevice_1"] + ) cmds = [ - "mkdir -p %s" % self.services["paths"]["mount_dir"], - "mount %s1 %s" % ( - self.services["volume"][self.hypervisor]["datadiskdevice_1"], - self.services["paths"]["mount_dir"] - ), - "pushd %s" % self.services["paths"]["mount_dir"], - "mkdir -p %s/{%s,%s} " % ( - self.services["paths"]["sub_dir"], - self.services["paths"]["sub_lvl_dir1"], - self.services["paths"]["sub_lvl_dir2"] - ), - "echo %s > %s/%s/%s" % ( - random_data_0, - self.services["paths"]["sub_dir"], - self.services["paths"]["sub_lvl_dir1"], - self.services["paths"]["random_data"] - ), - "echo %s > %s/%s/%s" % ( - random_data_1, - self.services["paths"]["sub_dir"], - self.services["paths"]["sub_lvl_dir2"], - self.services["paths"]["random_data"] - ), - "sync", - "umount %s" % (self.services["paths"]["mount_dir"]), - ] + "mkdir -p %s" % + self.services["paths"]["mount_dir"], + "mount %s1 %s" % + (self.services["volume"][ + self.hypervisor]["datadiskdevice_1"], + self.services["paths"]["mount_dir"]), + "pushd %s" % + self.services["paths"]["mount_dir"], + "mkdir -p %s/{%s,%s} " % + (self.services["paths"]["sub_dir"], + self.services["paths"]["sub_lvl_dir1"], + self.services["paths"]["sub_lvl_dir2"]), + "echo %s > %s/%s/%s" % + (random_data_0, + self.services["paths"]["sub_dir"], + self.services["paths"]["sub_lvl_dir1"], + self.services["paths"]["random_data"]), + "echo %s > %s/%s/%s" % + (random_data_1, + self.services["paths"]["sub_dir"], + self.services["paths"]["sub_lvl_dir2"], + self.services["paths"]["random_data"]), + "sync", + "umount %s" % + (self.services["paths"]["mount_dir"]), + ] for c in cmds: self.debug(ssh_client.execute(c)) - #detach volume from VM + # detach volume from VM cmd = detachVolume.detachVolumeCmd() cmd.id = volume.id self.apiclient.detachVolume(cmd) - #Create snapshot from detached volume + # Create snapshot from detached volume snapshot = Snapshot.create(self.apiclient, volume.id) volumes = list_volumes( - self.apiclient, - virtualmachineid=self.virtual_machine.id, - type='DATADISK', - listall=True - ) + self.apiclient, + virtualmachineid=self.virtual_machine.id, + type='DATADISK', + listall=True + ) self.assertEqual( - volumes, - None, - "Check Volume is detached" - ) + volumes, + None, + "Check Volume is detached" + ) # Verify the snapshot was created or not snapshots = list_snapshots( - self.apiclient, - id=snapshot.id - ) + self.apiclient, + id=snapshot.id + ) self.assertNotEqual( - snapshots, - None, - "Check if result exists in list snapshots call" - ) + snapshots, + None, + "Check if result exists in list snapshots call" + ) self.assertEqual( - snapshots[0].id, - snapshot.id, - "Check snapshot id in list resources call" - ) + snapshots[0].id, + snapshot.id, + "Check snapshot id in list resources call" + ) except Exception as e: self.fail("SSH failed for VM with IP: %s - %s" % - (self.virtual_machine.ssh_ip, e)) + (self.virtual_machine.ssh_ip, e)) qresultset = self.dbclient.execute( - "select id from snapshots where uuid = '%s';" \ - % snapshot.id - ) + "select id from snapshots where uuid = '%s';" + % snapshot.id + ) self.assertNotEqual( - len(qresultset), - 0, - "Check DB Query result set" - ) + len(qresultset), + 0, + "Check DB Query result set" + ) qresult = qresultset[0] self.assertNotEqual( - str(qresult[0]), - 'NULL', - "Check if backup_snap_id is not null" - ) + str(qresult[0]), + 'NULL', + "Check if backup_snap_id is not null" + ) return - @attr(speed = "slow") - @attr(tags=["advanced", "advancedns", "smoke", "xen"], required_hardware="true") + @attr(speed="slow") + @attr( + tags=[ + "advanced", + "advancedns", + "smoke", + "xen"], + required_hardware="true") def test_07_template_from_snapshot(self): """Create Template from snapshot """ - #1. Login to machine; create temp/test directories on data volume - #2. Snapshot the Volume - #3. Create Template from snapshot - #4. Deploy Virtual machine using this template - #5. Login to newly created virtual machine - #6. Compare data in the root disk with the one that was written on the volume, it should match + # 1. Login to machine; create temp/test directories on data volume + # 2. Snapshot the Volume + # 3. Create Template from snapshot + # 4. Deploy Virtual machine using this template + # 5. Login to newly created virtual machine + # 6. Compare data in the root disk with the one that was written on the + # volume, it should match userapiclient = self.testClient.getUserApiClient( - UserName=self.account.name, - DomainName=self.account.domain) + UserName=self.account.name, + DomainName=self.account.domain) random_data_0 = random_gen(size=100) random_data_1 = random_gen(size=100) try: - #Login to virtual machine + # Login to virtual machine ssh_client = self.virtual_machine.get_ssh_client() cmds = [ - "mkdir -p %s" % self.services["paths"]["mount_dir"], - "mount %s1 %s" % ( - self.services["volume"][self.hypervisor]["rootdiskdevice"], - self.services["paths"]["mount_dir"] - ), - "mkdir -p %s/%s/{%s,%s} " % ( - self.services["paths"]["mount_dir"], - self.services["paths"]["sub_dir"], - self.services["paths"]["sub_lvl_dir1"], - self.services["paths"]["sub_lvl_dir2"] - ), - "echo %s > %s/%s/%s/%s" % ( - random_data_0, - self.services["paths"]["mount_dir"], - self.services["paths"]["sub_dir"], - self.services["paths"]["sub_lvl_dir1"], - self.services["paths"]["random_data"] - ), - "echo %s > %s/%s/%s/%s" % ( - random_data_1, - self.services["paths"]["mount_dir"], - self.services["paths"]["sub_dir"], - self.services["paths"]["sub_lvl_dir2"], - self.services["paths"]["random_data"] - ), - "sync", - ] + "mkdir -p %s" % self.services["paths"]["mount_dir"], + "mount %s1 %s" % ( + self.services["volume"][self.hypervisor]["rootdiskdevice"], + self.services["paths"]["mount_dir"] + ), + "mkdir -p %s/%s/{%s,%s} " % ( + self.services["paths"]["mount_dir"], + self.services["paths"]["sub_dir"], + self.services["paths"]["sub_lvl_dir1"], + self.services["paths"]["sub_lvl_dir2"] + ), + "echo %s > %s/%s/%s/%s" % ( + random_data_0, + self.services["paths"]["mount_dir"], + self.services["paths"]["sub_dir"], + self.services["paths"]["sub_lvl_dir1"], + self.services["paths"]["random_data"] + ), + "echo %s > %s/%s/%s/%s" % ( + random_data_1, + self.services["paths"]["mount_dir"], + self.services["paths"]["sub_dir"], + self.services["paths"]["sub_lvl_dir2"], + self.services["paths"]["random_data"] + ), + "sync", + ] for c in cmds: self.debug(c) @@ -778,125 +812,124 @@ class TestSnapshots(cloudstackTestCase): except Exception as e: self.fail("SSH failed for VM with IP address: %s" % - self.virtual_machine.ipaddress) + self.virtual_machine.ipaddress) # Unmount the Volume cmds = [ - "umount %s" % (self.services["paths"]["mount_dir"]), - ] + "umount %s" % (self.services["paths"]["mount_dir"]), + ] for c in cmds: self.debug(c) ssh_client.execute(c) volumes = list_volumes( - userapiclient, - virtualmachineid=self.virtual_machine.id, - type='ROOT', - listall=True - ) + userapiclient, + virtualmachineid=self.virtual_machine.id, + type='ROOT', + listall=True + ) self.assertEqual( - isinstance(volumes, list), - True, - "Check list response returns a valid list" - ) + isinstance(volumes, list), + True, + "Check list response returns a valid list" + ) volume = volumes[0] - #Create a snapshot of volume + # Create a snapshot of volume snapshot = Snapshot.create( - userapiclient, - volume.id, - account=self.account.name, - domainid=self.account.domainid - ) + userapiclient, + volume.id, + account=self.account.name, + domainid=self.account.domainid + ) self.debug("Snapshot created from volume ID: %s" % volume.id) # Generate template from the snapshot template = Template.create_from_snapshot( - userapiclient, - snapshot, - self.services["templates"] - ) + userapiclient, + snapshot, + self.services["templates"] + ) self.cleanup.append(template) self.debug("Template created from snapshot ID: %s" % snapshot.id) # Verify created template templates = list_templates( - userapiclient, - templatefilter=\ - self.services["templates"]["templatefilter"], - id=template.id - ) + userapiclient, + templatefilter=self.services["templates"]["templatefilter"], + id=template.id + ) self.assertNotEqual( - templates, - None, - "Check if result exists in list item call" - ) + templates, + None, + "Check if result exists in list item call" + ) self.assertEqual( - templates[0].id, - template.id, - "Check new template id in list resources call" - ) + templates[0].id, + template.id, + "Check new template id in list resources call" + ) self.debug("Deploying new VM from template: %s" % template.id) # Deploy new virtual machine using template new_virtual_machine = VirtualMachine.create( - userapiclient, - self.services["server_without_disk"], - templateid=template.id, - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - mode=self.services["mode"] - ) + userapiclient, + self.services["server_without_disk"], + templateid=template.id, + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + mode=self.services["mode"] + ) try: - #Login to VM & mount directory + # Login to VM & mount directory ssh = new_virtual_machine.get_ssh_client() cmds = [ - "mkdir -p %s" % self.services["paths"]["mount_dir"], - "mount %s1 %s" % ( - self.services["volume"][self.hypervisor]["rootdiskdevice"], - self.services["paths"]["mount_dir"] - ) - ] + "mkdir -p %s" % self.services["paths"]["mount_dir"], + "mount %s1 %s" % ( + self.services["volume"][self.hypervisor]["rootdiskdevice"], + self.services["paths"]["mount_dir"] + ) + ] for c in cmds: ssh.execute(c) returned_data_0 = ssh.execute("cat %s/%s/%s/%s" % ( - self.services["paths"]["mount_dir"], - self.services["paths"]["sub_dir"], - self.services["paths"]["sub_lvl_dir1"], - self.services["paths"]["random_data"] - )) + self.services["paths"]["mount_dir"], + self.services["paths"]["sub_dir"], + self.services["paths"]["sub_lvl_dir1"], + self.services["paths"]["random_data"] + )) self.debug(returned_data_0) returned_data_1 = ssh.execute("cat %s/%s/%s/%s" % ( - self.services["paths"]["mount_dir"], - self.services["paths"]["sub_dir"], - self.services["paths"]["sub_lvl_dir2"], - self.services["paths"]["random_data"] - )) + self.services["paths"]["mount_dir"], + self.services["paths"]["sub_dir"], + self.services["paths"]["sub_lvl_dir2"], + self.services["paths"]["random_data"] + )) self.debug(returned_data_1) except Exception as e: self.fail("SSH failed for VM with IP address: %s" % - new_virtual_machine.ipaddress) - #Verify returned data + new_virtual_machine.ipaddress) + # Verify returned data self.assertEqual( - random_data_0, - returned_data_0[0], - "Verify newly attached volume contents with existing one" - ) + random_data_0, + returned_data_0[0], + "Verify newly attached volume contents with existing one" + ) self.assertEqual( - random_data_1, - returned_data_1[0], - "Verify newly attached volume contents with existing one" - ) + random_data_1, + returned_data_1[0], + "Verify newly attached volume contents with existing one" + ) # Unmount the volume cmds = [ - "umount %s" % (self.services["paths"]["mount_dir"]), - ] + "umount %s" % (self.services["paths"]["mount_dir"]), + ] try: for c in cmds: self.debug(c) @@ -904,7 +937,7 @@ class TestSnapshots(cloudstackTestCase): except Exception as e: self.fail("SSH failed for VM with IP address: %s, Exception: %s" % - (new_virtual_machine.ipaddress, e)) + (new_virtual_machine.ipaddress, e)) return @@ -912,9 +945,11 @@ class TestCreateVMSnapshotTemplate(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.testClient = super(TestCreateVMSnapshotTemplate, cls).getClsTestClient() + cls.testClient = super( + TestCreateVMSnapshotTemplate, + cls).getClsTestClient() cls.api_client = cls.testClient.getApiClient() - + cls.hypervisor = cls.testClient.getHypervisorInfo() cls.services = Services().services # Get Zone, Domain and templates cls.domain = get_domain(cls.api_client) @@ -922,35 +957,34 @@ class TestCreateVMSnapshotTemplate(cloudstackTestCase): cls.services['mode'] = cls.zone.networktype cls.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) + cls.api_client, + cls.zone.id, + cls.services["ostype"] + ) cls.services["domainid"] = cls.domain.id cls.services["server"]["zoneid"] = cls.zone.id - # Create VMs, NAT Rules etc cls.account = Account.create( - cls.api_client, - cls.services["account"], - domainid=cls.domain.id - ) + cls.api_client, + cls.services["account"], + domainid=cls.domain.id + ) cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] - ) + cls.api_client, + cls.services["service_offering"] + ) cls._cleanup = [ - cls.service_offering, - cls.account, - ] + cls.service_offering, + cls.account, + ] return @classmethod def tearDownClass(cls): try: - #Cleanup resources used + # Cleanup resources used cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -965,13 +999,13 @@ class TestCreateVMSnapshotTemplate(cloudstackTestCase): def tearDown(self): try: - #Clean up, terminate the created instance, volumes and snapshots + # 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") def test_01_createVM_snapshotTemplate(self): """Test create VM, Snapshot and Template @@ -984,35 +1018,39 @@ class TestCreateVMSnapshotTemplate(cloudstackTestCase): # 4. Create a instance from above created template. # 5. listSnapshots should list the snapshot that was created. # 6. verify that secondary storage NFS share contains the reqd - # volume under /secondary/snapshots/$accountid/$volumeid/$snapshot_uuid + # volume under /secondary/snapshots/$accountid/ + # $volumeid/$snapshot_uuid # 7. verify backup_snap_id was non null in the `snapshots` table # 8. listTemplates() should return the newly created Template, # and check for template state as READY" # 9. listVirtualMachines() command should return the deployed VM. # State of this VM should be Running. - #Create Virtual Machine + # Create Virtual Machine + + if self.hypervisor.lower() in ['hyperv']: + self.skipTest("Snapshots feature is not supported on Hyper-V") userapiclient = self.testClient.getUserApiClient( - UserName=self.account.name, - DomainName=self.account.domain) + UserName=self.account.name, + DomainName=self.account.domain) self.virtual_machine = VirtualMachine.create( - userapiclient, - self.services["server"], - templateid=self.template.id, - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id - ) + userapiclient, + self.services["server"], + templateid=self.template.id, + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id + ) self.debug("Created VM with ID: %s" % self.virtual_machine.id) # Get the Root disk of VM volumes = list_volumes( - userapiclient, - virtualmachineid=self.virtual_machine.id, - type='ROOT', - listall=True - ) + userapiclient, + virtualmachineid=self.virtual_machine.id, + type='ROOT', + listall=True + ) volume = volumes[0] # Create a snapshot from the ROOTDISK @@ -1021,105 +1059,111 @@ class TestCreateVMSnapshotTemplate(cloudstackTestCase): self.cleanup.append(snapshot) snapshots = list_snapshots( - userapiclient, - id=snapshot.id - ) + userapiclient, + id=snapshot.id + ) self.assertEqual( - isinstance(snapshots, list), - True, - "Check list response returns a valid list" - ) + isinstance(snapshots, list), + True, + "Check list response returns a valid list" + ) self.assertNotEqual( - snapshots, - None, - "Check if result exists in list snapshots call" - ) + snapshots, + None, + "Check if result exists in list snapshots call" + ) self.assertEqual( - snapshots[0].id, - snapshot.id, - "Check snapshot id in list resources call" - ) - self.debug("select backup_snap_id, account_id, volume_id from snapshots where uuid = '%s';" \ - % snapshot.id) + snapshots[0].id, + snapshot.id, + "Check snapshot id in list resources call" + ) + self.debug( + "select backup_snap_id, account_id, volume_id from snapshots where uuid = '%s';" % + snapshot.id) snapshot_uuid = snapshot.id # Generate template from the snapshot template = Template.create_from_snapshot( - userapiclient, - snapshot, - self.services["templates"] - ) + userapiclient, + snapshot, + self.services["templates"] + ) self.debug("Created template from snapshot: %s" % template.id) self.cleanup.append(template) templates = list_templates( - userapiclient, - templatefilter=\ - self.services["templates"]["templatefilter"], - id=template.id - ) + userapiclient, + templatefilter=self.services["templates"]["templatefilter"], + id=template.id + ) self.assertNotEqual( - templates, - None, - "Check if result exists in list item call" - ) + templates, + None, + "Check if result exists in list item call" + ) self.assertEqual( - templates[0].isready, - True, - "Check new template state in list templates call" - ) + templates[0].isready, + True, + "Check new template state in list templates call" + ) # Deploy new virtual machine using template new_virtual_machine = VirtualMachine.create( - userapiclient, - self.services["server"], - templateid=template.id, - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id - ) + userapiclient, + self.services["server"], + templateid=template.id, + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id + ) self.debug("Created VM with ID: %s from template: %s" % ( - new_virtual_machine.id, - template.id - )) + new_virtual_machine.id, + template.id + )) self.cleanup.append(new_virtual_machine) # Newly deployed VM should be 'Running' virtual_machines = list_virtual_machines( - userapiclient, - id=new_virtual_machine.id, - account=self.account.name, - domainid=self.account.domainid - ) + userapiclient, + id=new_virtual_machine.id, + account=self.account.name, + domainid=self.account.domainid + ) self.assertEqual( - isinstance(virtual_machines, list), - True, - "Check list response returns a valid list" - ) + isinstance(virtual_machines, list), + True, + "Check list response returns a valid list" + ) self.assertNotEqual( - len(virtual_machines), - 0, - "Check list virtual machines response" - ) + len(virtual_machines), + 0, + "Check list virtual machines response" + ) for virtual_machine in virtual_machines: self.assertEqual( - virtual_machine.state, - 'Running', - "Check list VM response for Running state" - ) - self.assertTrue(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config, self.zone.id, snapshot_uuid)) + virtual_machine.state, + 'Running', + "Check list VM response for Running state" + ) + self.assertTrue( + is_snapshot_on_nfs( + self.apiclient, + self.dbclient, + self.config, + self.zone.id, + snapshot_uuid)) return + class TestSnapshotEvents(cloudstackTestCase): @classmethod def setUpClass(cls): cls.testClient = super(TestSnapshotEvents, cls).getClsTestClient() cls.api_client = cls.testClient.getApiClient() - - + cls.hypervisor = cls.testClient.getHypervisorInfo() cls.services = Services().services # Get Zone, Domain and templates cls.domain = get_domain(cls.api_client) @@ -1127,46 +1171,46 @@ class TestSnapshotEvents(cloudstackTestCase): cls.services['mode'] = cls.zone.networktype template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) + cls.api_client, + cls.zone.id, + cls.services["ostype"] + ) cls.services["server"]["zoneid"] = cls.zone.id cls.services["template"] = template.id # Create VMs, NAT Rules etc cls.account = Account.create( - cls.api_client, - cls.services["account"], - domainid=cls.domain.id - ) + cls.api_client, + cls.services["account"], + domainid=cls.domain.id + ) cls.services["account"] = cls.account.name cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] - ) + cls.api_client, + cls.services["service_offering"] + ) cls.virtual_machine = VirtualMachine.create( - cls.api_client, - cls.services["server"], - templateid=template.id, - accountid=cls.account.name, - domainid=cls.account.domainid, - serviceofferingid=cls.service_offering.id - ) + cls.api_client, + cls.services["server"], + templateid=template.id, + accountid=cls.account.name, + domainid=cls.account.domainid, + serviceofferingid=cls.service_offering.id + ) cls._cleanup = [ - cls.service_offering, - cls.account, - ] + cls.service_offering, + cls.account, + ] return @classmethod def tearDownClass(cls): try: - #Cleanup resources used + # Cleanup resources used cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -1181,34 +1225,38 @@ class TestSnapshotEvents(cloudstackTestCase): def tearDown(self): try: - #Clean up, terminate the created instance, volumes and snapshots + # 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") def test_05_snapshot_events(self): """Test snapshot events """ # Validate the following - # 1. Perform snapshot on the root disk of this VM and check the events/alerts. + # 1. Perform snapshot on the root disk of this VM and + # check the events/alerts. # 2. delete the snapshots and check the events/alerts # 3. listEvents() shows created/deleted snapshot events + if self.hypervisor.lower() in ['hyperv']: + self.skipTest("Snapshots feature is not supported on Hyper-V") + # Get the Root disk of VM volumes = list_volumes( - self.apiclient, - virtualmachineid=self.virtual_machine.id, - type='ROOT', - listall=True - ) + self.apiclient, + virtualmachineid=self.virtual_machine.id, + type='ROOT', + listall=True + ) self.assertEqual( - isinstance(volumes, list), - True, - "Check list response returns a valid list" - ) + isinstance(volumes, list), + True, + "Check list response returns a valid list" + ) volume = volumes[0] # Create a snapshot from the ROOTDISK @@ -1216,47 +1264,47 @@ class TestSnapshotEvents(cloudstackTestCase): self.debug("Snapshot created with ID: %s" % snapshot.id) snapshots = list_snapshots( - self.apiclient, - id=snapshot.id - ) + self.apiclient, + id=snapshot.id + ) self.assertEqual( - isinstance(snapshots, list), - True, - "Check list response returns a valid list" - ) + isinstance(snapshots, list), + True, + "Check list response returns a valid list" + ) self.assertNotEqual( - snapshots, - None, - "Check if result exists in list snapshots call" - ) + snapshots, + None, + "Check if result exists in list snapshots call" + ) self.assertEqual( - snapshots[0].id, - snapshot.id, - "Check snapshot id in list resources call" - ) + snapshots[0].id, + snapshot.id, + "Check snapshot id in list resources call" + ) snapshot.delete(self.apiclient) # Sleep to ensure that snapshot is deleted properly time.sleep(self.services["sleep"]) events = list_events( - self.apiclient, - account=self.account.name, - domainid=self.account.domainid, - type='SNAPSHOT.DELETE' - ) + self.apiclient, + account=self.account.name, + domainid=self.account.domainid, + type='SNAPSHOT.DELETE' + ) self.assertEqual( - isinstance(events, list), - True, - "Check list response returns a valid list" - ) + isinstance(events, list), + True, + "Check list response returns a valid list" + ) self.assertNotEqual( - events, - None, - "Check if event exists in list events call" - ) + events, + None, + "Check if event exists in list events call" + ) self.assertIn( - events[0].state, - ['Completed', 'Scheduled'], - "Check events state in list events call" - ) + events[0].state, + ['Completed', 'Scheduled'], + "Check events state in list events call" + ) return diff --git a/test/integration/component/test_ss_limits.py b/test/integration/component/test_ss_limits.py index d5ee0633080..32201d8d21e 100644 --- a/test/integration/component/test_ss_limits.py +++ b/test/integration/component/test_ss_limits.py @@ -58,6 +58,7 @@ class TestSecondaryStorageLimits(cloudstackTestCase): cloudstackTestClient = super(TestSecondaryStorageLimits, cls).getClsTestClient() cls.api_client = cloudstackTestClient.getApiClient() + cls.hypervisor = cloudstackTestClient.getHypervisorInfo() # Fill services from the external config file cls.services = cloudstackTestClient.getParsedTestDataConfig() # Get Zone, Domain and templates @@ -205,6 +206,9 @@ class TestSecondaryStorageLimits(cloudstackTestCase): 5. Verify that the secondary storage count of the account equals the size of the template""" + if self.hypervisor.lower() in ['hyperv']: + self.skipTest("Snapshots feature is not supported on Hyper-V") + response = self.setupAccount(value) self.assertEqual(response[0], PASS, response[1]) diff --git a/test/integration/component/test_tags.py b/test/integration/component/test_tags.py index 2b05fbb1432..e3235782757 100644 --- a/test/integration/component/test_tags.py +++ b/test/integration/component/test_tags.py @@ -16,7 +16,7 @@ # under the License. """ P1 tests for tags """ -#Import Local Modules +# Import Local Modules from nose.plugins.attrib import attr from marvin.cloudstackTestCase import cloudstackTestCase from marvin.lib.utils import cleanup_resources @@ -43,147 +43,149 @@ from marvin.lib.common import (get_zone, from marvin.codes import FAILED import time + class Services: + """Test tags Services """ def __init__(self): self.services = { - "domain": { - "name": "Domain", - }, - "project": { - "name": "Project", - "displaytext": "Test project", - }, - "account": { - "email": "administrator@clogeny.com", - "firstname": "Test", - "lastname": "User", - "username": "test", - # Random characters are appended for unique - # username - "password": "password", - }, - "user": { - "email": "user@clogeny.com", - "firstname": "User", - "lastname": "User", - "username": "User", - # Random characters are appended for unique - # username - "password": "password", - }, - "other_user": { - "email": "otheruser@clogeny.com", - "firstname": "Other", - "lastname": "User", - "username": "User", - # Random characters are appended for unique - # username - "password": "password", - }, - "service_offering": { - "name": "Tiny Instance", - "displaytext": "Tiny Instance", - "cpunumber": 1, - "cpuspeed": 100, - # in MHz - "memory": 128, - # In MBs - }, - "disk_offering": { - "displaytext": "Tiny Disk Offering", - "name": "Tiny Disk Offering", - "disksize": 1 - }, - "volume": { - "diskname": "Test Volume", - }, - "virtual_machine": { - "displayname": "TestVM", - "username": "root", - "password": "password", - "ssh_port": 22, - "hypervisor": 'XenServer', - "privateport": 22, - "publicport": 22, - "protocol": 'TCP', - }, - "template": { - "displaytext": "Cent OS Template", - "name": "Cent OS Template", - "ostype": 'CentOS 5.3 (64-bit)', - "templatefilter": 'self', - }, - "iso": - { - "displaytext": "Dummy ISO", - "name": "Dummy ISO", - "url": "http://people.apache.org/~tsp/dummy.iso", - # Source URL where ISO is located - "isextractable": True, - "isfeatured": True, - "ispublic": False, - "ostype": 'CentOS 5.3 (64-bit)', - "mode": 'HTTP_DOWNLOAD', - # Used in Extract template, value must be HTTP_DOWNLOAD - }, - "network_offering": { - "name": 'Network offering-VR services', - "displaytext": 'Network offering-VR services', - "guestiptype": 'Isolated', - "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,Vpn,Firewall,Lb,UserData,StaticNat', - "traffictype": 'GUEST', - "availability": 'Optional', - "serviceProviderList": { - "Dhcp": 'VirtualRouter', - "Dns": 'VirtualRouter', - "SourceNat": 'VirtualRouter', - "PortForwarding": 'VirtualRouter', - "Vpn": 'VirtualRouter', - "Firewall": 'VirtualRouter', - "Lb": 'VirtualRouter', - "UserData": 'VirtualRouter', - "StaticNat": 'VirtualRouter', - }, - }, - "network": { - "name": "Test Network", - "displaytext": "Test Network", - }, - "lbrule": { - "name": "SSH", - "alg": "leastconn", - # Algorithm used for load balancing - "privateport": 22, - "publicport": 22, - "openfirewall": False, - }, - "natrule": { - "privateport": 22, - "publicport": 22, - "protocol": "TCP" - }, - "fw_rule": { - "startport": 1, - "endport": 6000, - "cidr": '55.55.0.0/11', - # Any network (For creating FW rule) - }, - "security_group": { - "name": 'SSH', - "protocol": 'TCP', - "startport": 22, - "endport": 22, - "cidrlist": '0.0.0.0/0', - }, - # Cent OS 5.3 (64 bit) - "sleep": 60, - "ostype": 'CentOS 5.3 (64-bit)', - "timeout": 10, - "mode": 'advanced', - } + "domain": { + "name": "Domain", + }, + "project": { + "name": "Project", + "displaytext": "Test project", + }, + "account": { + "email": "administrator@clogeny.com", + "firstname": "Test", + "lastname": "User", + "username": "test", + # Random characters are appended for unique + # username + "password": "password", + }, + "user": { + "email": "user@clogeny.com", + "firstname": "User", + "lastname": "User", + "username": "User", + # Random characters are appended for unique + # username + "password": "password", + }, + "other_user": { + "email": "otheruser@clogeny.com", + "firstname": "Other", + "lastname": "User", + "username": "User", + # Random characters are appended for unique + # username + "password": "password", + }, + "service_offering": { + "name": "Tiny Instance", + "displaytext": "Tiny Instance", + "cpunumber": 1, + "cpuspeed": 100, + # in MHz + "memory": 128, + # In MBs + }, + "disk_offering": { + "displaytext": "Tiny Disk Offering", + "name": "Tiny Disk Offering", + "disksize": 1 + }, + "volume": { + "diskname": "Test Volume", + }, + "virtual_machine": { + "displayname": "TestVM", + "username": "root", + "password": "password", + "ssh_port": 22, + "hypervisor": 'XenServer', + "privateport": 22, + "publicport": 22, + "protocol": 'TCP', + }, + "template": { + "displaytext": "Cent OS Template", + "name": "Cent OS Template", + "ostype": 'CentOS 5.3 (64-bit)', + "templatefilter": 'self', + }, + "iso": + { + "displaytext": "Dummy ISO", + "name": "Dummy ISO", + "url": "http://people.apache.org/~tsp/dummy.iso", + # Source URL where ISO is located + "isextractable": True, + "isfeatured": True, + "ispublic": False, + "ostype": 'CentOS 5.3 (64-bit)', + "mode": 'HTTP_DOWNLOAD', + # Used in Extract template, value must be HTTP_DOWNLOAD + }, + "network_offering": { + "name": 'Network offering-VR services', + "displaytext": 'Network offering-VR services', + "guestiptype": 'Isolated', + "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,Vpn,Firewall,Lb,UserData,StaticNat', + "traffictype": 'GUEST', + "availability": 'Optional', + "serviceProviderList": { + "Dhcp": 'VirtualRouter', + "Dns": 'VirtualRouter', + "SourceNat": 'VirtualRouter', + "PortForwarding": 'VirtualRouter', + "Vpn": 'VirtualRouter', + "Firewall": 'VirtualRouter', + "Lb": 'VirtualRouter', + "UserData": 'VirtualRouter', + "StaticNat": 'VirtualRouter', + }, + }, + "network": { + "name": "Test Network", + "displaytext": "Test Network", + }, + "lbrule": { + "name": "SSH", + "alg": "leastconn", + # Algorithm used for load balancing + "privateport": 22, + "publicport": 22, + "openfirewall": False, + }, + "natrule": { + "privateport": 22, + "publicport": 22, + "protocol": "TCP" + }, + "fw_rule": { + "startport": 1, + "endport": 6000, + "cidr": '55.55.0.0/11', + # Any network (For creating FW rule) + }, + "security_group": { + "name": 'SSH', + "protocol": 'TCP', + "startport": 22, + "endport": 22, + "cidrlist": '0.0.0.0/0', + }, + # Cent OS 5.3 (64 bit) + "sleep": 60, + "ostype": 'CentOS 5.3 (64-bit)', + "timeout": 10, + "mode": 'advanced', + } class TestResourceTags(cloudstackTestCase): @@ -192,7 +194,7 @@ class TestResourceTags(cloudstackTestCase): def setUpClass(cls): cls.testClient = super(TestResourceTags, cls).getClsTestClient() cls.api_client = cls.testClient.getApiClient() - + cls.hypervisor = cls.testClient.getHypervisorInfo() cls.services = Services().services # Get Zone, Domain and templates @@ -200,65 +202,66 @@ class TestResourceTags(cloudstackTestCase): cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.domain = get_domain(cls.api_client) cls.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) + cls.api_client, + cls.zone.id, + cls.services["ostype"] + ) if cls.template == FAILED: - assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] + assert False, "get_template() failed to return template\ + with description %s" % cls.services["ostype"] cls.account = Account.create( - cls.api_client, - cls.services["account"], - admin=True, - ) - + cls.api_client, + cls.services["account"], + admin=True, + ) + cls.user_api_client = cls.testClient.getUserApiClient( - UserName=cls.account.name, - DomainName=cls.account.domain - ) - + UserName=cls.account.name, + DomainName=cls.account.domain + ) + # Create service offerings, disk offerings etc cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] - ) + cls.api_client, + cls.services["service_offering"] + ) cls.disk_offering = DiskOffering.create( - cls.api_client, - cls.services["disk_offering"] - ) - + cls.api_client, + cls.services["disk_offering"] + ) + cls.services["iso"]["zoneid"] = cls.zone.id cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["virtual_machine"]["template"] = cls.template.id 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, - mode=cls.zone.networktype - ) + cls.api_client, + cls.services["virtual_machine"], + accountid=cls.account.name, + domainid=cls.account.domainid, + serviceofferingid=cls.service_offering.id, + mode=cls.zone.networktype + ) 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, - mode=cls.zone.networktype - ) + cls.api_client, + cls.services["virtual_machine"], + accountid=cls.account.name, + domainid=cls.account.domainid, + serviceofferingid=cls.service_offering.id, + mode=cls.zone.networktype + ) cls._cleanup = [ - cls.account, - cls.service_offering, - cls.disk_offering - ] + cls.account, + cls.service_offering, + cls.disk_offering + ] return @classmethod def tearDownClass(cls): try: - #Cleanup resources used + # Cleanup resources used print("Cleanup resources used") cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: @@ -274,18 +277,18 @@ class TestResourceTags(cloudstackTestCase): def tearDown(self): try: - #Clean up, terminate the created accounts, domains etc + # 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) - + for tag in self.rm_tags: tag['tag_obj'].delete(self.apiclient, tag['resid'], - tag['restype'], - {tag['key']: tag['value']}) + tag['restype'], + {tag['key']: tag['value']}) return - + @attr(tags=["advanced"], required_hardware="false") def test_01_lbrule_tag(self): """ Test Create tag on LB rule and remove the LB rule @@ -296,131 +299,131 @@ class TestResourceTags(cloudstackTestCase): # 3. Delete the LB rule self.debug("Fetching the network details for account: %s" % - self.account.name) + self.account.name) networks = Network.list( - self.apiclient, - account=self.account.name, - domainid=self.account.domainid, - listall=True - ) + self.apiclient, + account=self.account.name, + domainid=self.account.domainid, + listall=True + ) self.assertEqual( - isinstance(networks, list), - True, - "List networks should not return an empty response" - ) + isinstance(networks, list), + True, + "List networks should not return an empty response" + ) network = networks[0] self.debug("Network for the account: %s is %s" % - (self.account.name, network.name)) + (self.account.name, network.name)) self.debug("Associating public IP for network: %s" % network.id) public_ip = PublicIPAddress.create( - self.apiclient, - accountid=self.account.name, - zoneid=self.zone.id, - domainid=self.account.domainid, - networkid=network.id - ) + self.apiclient, + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + networkid=network.id + ) self.cleanup.append(public_ip) self.debug("Trying to create LB rule on IP: %s" % - public_ip.ipaddress.ipaddress) + public_ip.ipaddress.ipaddress) # Create Load Balancer rule on the public ip lb_rule = LoadBalancerRule.create( - self.apiclient, - self.services["lbrule"], - ipaddressid=public_ip.ipaddress.id, - accountid=self.account.name - ) + self.apiclient, + self.services["lbrule"], + ipaddressid=public_ip.ipaddress.id, + accountid=self.account.name + ) # Check if the LB rule created successfully lb_rules = LoadBalancerRule.list( - self.apiclient, - id=lb_rule.id - ) + self.apiclient, + id=lb_rule.id + ) self.assertEqual( - isinstance(lb_rules, list), - True, - "List LB rules should return valid list" - ) + isinstance(lb_rules, list), + True, + "List LB rules should return valid list" + ) self.debug("Assigning the virtual machines (%s, %s) to lb rule: %s" % - (self.vm_1.name, - self.vm_2.name, - lb_rule.name)) + (self.vm_1.name, + self.vm_2.name, + lb_rule.name)) lb_rule.assign(self.apiclient, [self.vm_1, self.vm_2]) self.debug("Creating a tag for load balancer rule") tag = Tag.create( - self.apiclient, - resourceIds=lb_rule.id, - resourceType='LoadBalancer', - tags={'LB': 40} - ) + self.apiclient, + resourceIds=lb_rule.id, + resourceType='LoadBalancer', + tags={'LB': 40} + ) self.debug("Tag created: %s" % tag.__dict__) tags = Tag.list( - self.apiclient, - listall=True, - resourceType='LoadBalancer', - key='LB', - account=self.account.name, - domainid=self.account.domainid, - value=40 - ) + self.apiclient, + listall=True, + resourceType='LoadBalancer', + key='LB', + account=self.account.name, + domainid=self.account.domainid, + value=40 + ) self.debug("Tag created: %s" % str(tags)) self.assertEqual( - isinstance(tags, list), - True, - "List tags should not return empty response" - ) + isinstance(tags, list), + True, + "List tags should not return empty response" + ) self.assertEqual( - int(tags[0].value), - 40, - "The tag value should match with the original value" - ) - + int(tags[0].value), + 40, + "The tag value should match with the original value" + ) + lb_rules = LoadBalancerRule.list( - self.apiclient, - listall=True, - key='FW', - value=40 - ) + self.apiclient, + listall=True, + key='FW', + value=40 + ) self.assertEqual( - isinstance(lb_rules, list), - True, - "List LB rules should return valid list" - ) + isinstance(lb_rules, list), + True, + "List LB rules should return valid list" + ) self.debug("Deleting the created tag..") try: tag.delete( - self.apiclient, - resourceIds=lb_rule.id, - resourceType='LoadBalancer', - tags={'LB': 40} - ) + self.apiclient, + resourceIds=lb_rule.id, + resourceType='LoadBalancer', + tags={'LB': 40} + ) except Exception as e: self.fail("Failed to delete the tag - %s" % e) self.debug("Verifying if tag is actually deleted!") tags = Tag.list( - self.apiclient, - listall=True, - resourceType='LoadBalancer', - key='LB', - account=self.account.name, - domainid=self.account.domainid - ) + self.apiclient, + listall=True, + resourceType='LoadBalancer', + key='LB', + account=self.account.name, + domainid=self.account.domainid + ) self.assertEqual( - tags, - None, - "List tags should return empty response" - ) + tags, + None, + "List tags should return empty response" + ) self.debug("Deleting the Load balancer rule") try: @@ -439,126 +442,126 @@ class TestResourceTags(cloudstackTestCase): # 3. Delete the PF rule self.debug("Fetching the network details for account: %s" % - self.account.name) + self.account.name) networks = Network.list( - self.apiclient, - account=self.account.name, - domainid=self.account.domainid, - listall=True - ) + self.apiclient, + account=self.account.name, + domainid=self.account.domainid, + listall=True + ) self.assertEqual( - isinstance(networks, list), - True, - "List networks should not return an empty response" - ) + isinstance(networks, list), + True, + "List networks should not return an empty response" + ) network = networks[0] self.debug("Network for the account: %s is %s" % - (self.account.name, network.name)) + (self.account.name, network.name)) self.debug("Associating public IP for network: %s" % network.id) public_ip = PublicIPAddress.create( - self.apiclient, - accountid=self.account.name, - zoneid=self.zone.id, - domainid=self.account.domainid, - networkid=network.id - ) + self.apiclient, + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + networkid=network.id + ) self.cleanup.append(public_ip) self.debug("Trying to create LB rule on IP: %s" % - public_ip.ipaddress.ipaddress) + public_ip.ipaddress.ipaddress) self.debug("Creating PF rule for vm: %s on Ip: %s" % - (self.vm_1.name, public_ip.ipaddress.ipaddress)) + (self.vm_1.name, public_ip.ipaddress.ipaddress)) nat_rule = NATRule.create( - self.apiclient, - self.vm_1, - self.services["natrule"], - ipaddressid=public_ip.ipaddress.id - ) + self.apiclient, + self.vm_1, + self.services["natrule"], + ipaddressid=public_ip.ipaddress.id + ) # Check if NAT rule created successfully nat_rules = NATRule.list( - self.apiclient, - id=nat_rule.id - ) + self.apiclient, + id=nat_rule.id + ) self.assertEqual( - isinstance(nat_rules, list), - True, - "List NAT rules should return valid list" - ) + isinstance(nat_rules, list), + True, + "List NAT rules should return valid list" + ) self.debug("Creating a tag for port forwarding rule") tag = Tag.create( - self.apiclient, - resourceIds=nat_rule.id, - resourceType='portForwardingRule', - tags={'PF': 40} - ) + self.apiclient, + resourceIds=nat_rule.id, + resourceType='portForwardingRule', + tags={'PF': 40} + ) self.debug("Tag created: %s" % tag.__dict__) tags = Tag.list( - self.apiclient, - listall=True, - resourceType='portForwardingRule', - account=self.account.name, - domainid=self.account.domainid, - key='PF', - value=40 - ) + self.apiclient, + listall=True, + resourceType='portForwardingRule', + account=self.account.name, + domainid=self.account.domainid, + key='PF', + value=40 + ) self.assertEqual( - isinstance(tags, list), - True, - "List tags should not return empty response" - ) + isinstance(tags, list), + True, + "List tags should not return empty response" + ) self.assertEqual( - int(tags[0].value), - 40, - "The tag value should match with the original value" - ) - + int(tags[0].value), + 40, + "The tag value should match with the original value" + ) + nat_rules = NATRule.list( - self.apiclient, - listall=True, - key='FW', - value=40 - ) + self.apiclient, + listall=True, + key='FW', + value=40 + ) self.assertEqual( - isinstance(nat_rules, list), - True, - "List NAT rules should return valid list" - ) - + isinstance(nat_rules, list), + True, + "List NAT rules should return valid list" + ) + self.debug("Deleting the created tag..") try: tag.delete( - self.apiclient, - resourceIds=nat_rule.id, - resourceType='portForwardingRule', - tags={'PF': 40} - ) + self.apiclient, + resourceIds=nat_rule.id, + resourceType='portForwardingRule', + tags={'PF': 40} + ) except Exception as e: self.fail("Failed to delete the tag - %s" % e) self.debug("Verifying if tag is actually deleted!") tags = Tag.list( - self.apiclient, - listall=True, - resourceType='portForwardingRule', - account=self.account.name, - domainid=self.account.domainid, - key='PF', - value=40 - ) + self.apiclient, + listall=True, + resourceType='portForwardingRule', + account=self.account.name, + domainid=self.account.domainid, + key='PF', + value=40 + ) self.assertEqual( - tags, - None, - "List tags should return empty response" - ) + tags, + None, + "List tags should return empty response" + ) self.debug("Deleting the port forwarding rule") try: nat_rule.delete(self.apiclient) @@ -576,131 +579,131 @@ class TestResourceTags(cloudstackTestCase): # 3. Delete the firewall rule self.debug("Fetching the network details for account: %s" % - self.account.name) + self.account.name) networks = Network.list( - self.apiclient, - account=self.account.name, - domainid=self.account.domainid, - listall=True - ) + self.apiclient, + account=self.account.name, + domainid=self.account.domainid, + listall=True + ) self.assertEqual( - isinstance(networks, list), - True, - "List networks should not return an empty response" - ) + isinstance(networks, list), + True, + "List networks should not return an empty response" + ) network = networks[0] self.debug("Network for the account: %s is %s" % - (self.account.name, network.name)) + (self.account.name, network.name)) self.debug("Associating public IP for network: %s" % network.id) public_ip = PublicIPAddress.create( - self.apiclient, - accountid=self.account.name, - zoneid=self.zone.id, - domainid=self.account.domainid, - networkid=network.id - ) + self.apiclient, + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + networkid=network.id + ) self.cleanup.append(public_ip) self.debug("Creating firewall rule on public IP: %s" % - public_ip.ipaddress.ipaddress) + public_ip.ipaddress.ipaddress) # Create Firewall rule on public IP fw_rule = FireWallRule.create( - self.apiclient, - ipaddressid=public_ip.ipaddress.id, - protocol='TCP', - cidrlist=[self.services["fw_rule"]["cidr"]], - startport=self.services["fw_rule"]["startport"], - endport=self.services["fw_rule"]["endport"] - ) + self.apiclient, + ipaddressid=public_ip.ipaddress.id, + protocol='TCP', + cidrlist=[self.services["fw_rule"]["cidr"]], + startport=self.services["fw_rule"]["startport"], + endport=self.services["fw_rule"]["endport"] + ) self.debug("Created firewall rule: %s" % fw_rule.id) fw_rules = FireWallRule.list( - self.apiclient, - id=fw_rule.id - ) + self.apiclient, + id=fw_rule.id + ) self.assertEqual( - isinstance(fw_rules, list), - True, - "List fw rules should return a valid firewall rules" - ) + isinstance(fw_rules, list), + True, + "List fw rules should return a valid firewall rules" + ) self.assertNotEqual( - len(fw_rules), - 0, - "Length of fw rules response should not be zero" - ) + len(fw_rules), + 0, + "Length of fw rules response should not be zero" + ) self.debug("Creating a tag for firewall rule") tag = Tag.create( - self.apiclient, - resourceIds=fw_rule.id, - resourceType='FirewallRule', - tags={'FW': '40'} - ) + self.apiclient, + resourceIds=fw_rule.id, + resourceType='FirewallRule', + tags={'FW': '40'} + ) self.debug("Tag created: %s" % tag.__dict__) tags = Tag.list( - self.apiclient, - listall=True, - resourceType='FirewallRule', - account=self.account.name, - domainid=self.account.domainid, - key='FW', - value='40' - ) + self.apiclient, + listall=True, + resourceType='FirewallRule', + account=self.account.name, + domainid=self.account.domainid, + key='FW', + value='40' + ) self.assertEqual( - isinstance(tags, list), - True, - "List tags should not return empty response" - ) - + isinstance(tags, list), + True, + "List tags should not return empty response" + ) + self.assertEqual( - tags[0].value, - '40', - "The tag value should match with the original value" - ) + tags[0].value, + '40', + "The tag value should match with the original value" + ) fw_rules = FireWallRule.list( - self.apiclient, - listall=True, - key='FW', - value='40' - ) + self.apiclient, + listall=True, + key='FW', + value='40' + ) self.assertEqual( - isinstance(fw_rules, list), - True, - "List fw rules should return a valid firewall rules" - ) + isinstance(fw_rules, list), + True, + "List fw rules should return a valid firewall rules" + ) self.debug("Deleting the created tag..") try: tag.delete( - self.apiclient, - resourceIds=fw_rule.id, - resourceType='FirewallRule', - tags={'FW': '40'} - ) + self.apiclient, + resourceIds=fw_rule.id, + resourceType='FirewallRule', + tags={'FW': '40'} + ) except Exception as e: self.fail("Failed to delete the tag - %s" % e) self.debug("Verifying if tag is actually deleted!") tags = Tag.list( - self.apiclient, - listall=True, - resourceType='FirewallRule', - account=self.account.name, - domainid=self.account.domainid, - key='FW', - value='40' - ) + self.apiclient, + listall=True, + resourceType='FirewallRule', + account=self.account.name, + domainid=self.account.domainid, + key='FW', + value='40' + ) self.assertEqual( - tags, - None, - "List tags should return empty response" - ) + tags, + None, + "List tags should return empty response" + ) self.debug("Deleting the firewall rule") try: @@ -720,139 +723,139 @@ class TestResourceTags(cloudstackTestCase): self.skipTest("VPN resource tags are unsupported in 4.0") self.debug("Fetching the network details for account: %s" % - self.account.name) + self.account.name) networks = Network.list( - self.apiclient, - account=self.account.name, - domainid=self.account.domainid, - listall=True - ) + self.apiclient, + account=self.account.name, + domainid=self.account.domainid, + listall=True + ) self.assertEqual( - isinstance(networks, list), - True, - "List networks should not return an empty response" - ) + isinstance(networks, list), + True, + "List networks should not return an empty response" + ) network = networks[0] self.debug("Network for the account: %s is %s" % - (self.account.name, network.name)) + (self.account.name, network.name)) self.debug("Associating public IP for network: %s" % network.id) public_ip = PublicIPAddress.create( - self.apiclient, - accountid=self.account.name, - zoneid=self.zone.id, - domainid=self.account.domainid, - networkid=network.id - ) + self.apiclient, + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + networkid=network.id + ) self.cleanup.append(public_ip) nat_rule = NATRule.create( - self.apiclient, - self.vm_1, - self.services["natrule"], - ipaddressid=public_ip.ipaddress.id - ) + self.apiclient, + self.vm_1, + self.services["natrule"], + ipaddressid=public_ip.ipaddress.id + ) # Check if NAT rule created successfully nat_rules = NATRule.list( - self.apiclient, - id=nat_rule.id - ) + self.apiclient, + id=nat_rule.id + ) self.assertEqual( - isinstance(nat_rules, list), - True, - "List NAT rules should return valid list" - ) + isinstance(nat_rules, list), + True, + "List NAT rules should return valid list" + ) # User should be able to enable VPN on source NAT self.debug("Creating VPN with public NAT IP: %s" % - public_ip.ipaddress.ipaddress) + public_ip.ipaddress.ipaddress) # Assign VPN to source NAT try: vpn = Vpn.create( - self.apiclient, - public_ip.ipaddress.id, - account=self.account.name, - domainid=self.account.domainid - ) + self.apiclient, + public_ip.ipaddress.id, + account=self.account.name, + domainid=self.account.domainid + ) except Exception as e: print e vpns = Vpn.list( - self.apiclient, - publicipid=public_ip.ipaddress.id, - listall=True, - ) + self.apiclient, + publicipid=public_ip.ipaddress.id, + listall=True, + ) self.assertEqual( - isinstance(vpns, list), - True, - "List VPNs should return a valid VPN list" - ) + isinstance(vpns, list), + True, + "List VPNs should return a valid VPN list" + ) self.assertNotEqual( - len(vpns), - 0, - "Length of list VPN response should not be zero" - ) + len(vpns), + 0, + "Length of list VPN response should not be zero" + ) self.debug("Creating a tag for VPN rule") tag = Tag.create( - self.apiclient, - resourceIds=nat_rule.id, - resourceType='VPN', - tags={'protocol': 'L2TP'} - ) + self.apiclient, + resourceIds=nat_rule.id, + resourceType='VPN', + tags={'protocol': 'L2TP'} + ) self.debug("Tag created: %s" % tag.__dict__) tags = Tag.list( - self.apiclient, - listall=True, - resourceType='VPN', - account=self.account.name, - domainid=self.account.domainid, - key='protocol', - value='L2TP' - ) + self.apiclient, + listall=True, + resourceType='VPN', + account=self.account.name, + domainid=self.account.domainid, + key='protocol', + value='L2TP' + ) self.assertEqual( - isinstance(tags, list), - True, - "List tags should not return empty response" - ) + isinstance(tags, list), + True, + "List tags should not return empty response" + ) self.assertEqual( - tags[0].value, - 'L2TP', - "The tag value should match with the original value" - ) + tags[0].value, + 'L2TP', + "The tag value should match with the original value" + ) self.debug("Deleting the created tag..") try: tag.delete( - self.apiclient, - resourceIds=vpn.id, - resourceType='VPN', - tags={'protocol': 'L2TP'} - ) + self.apiclient, + resourceIds=vpn.id, + resourceType='VPN', + tags={'protocol': 'L2TP'} + ) except Exception as e: self.fail("Failed to delete the tag - %s" % e) self.debug("Verifying if tag is actually deleted!") tags = Tag.list( - self.apiclient, - listall=True, - resourceType='VPN', - account=self.account.name, - domainid=self.account.domainid, - key='protocol', - value='L2TP' - ) + self.apiclient, + listall=True, + resourceType='VPN', + account=self.account.name, + domainid=self.account.domainid, + key='protocol', + value='L2TP' + ) self.assertEqual( - tags, - None, - "List tags should return empty response" - ) + tags, + None, + "List tags should return empty response" + ) self.debug("Disabling the VPN") try: @@ -871,71 +874,71 @@ class TestResourceTags(cloudstackTestCase): self.debug("Creating a tag for user VM") tag = Tag.create( - self.apiclient, - resourceIds=self.vm_1.id, - resourceType='userVM', - tags={'region': 'India'} - ) + self.apiclient, + resourceIds=self.vm_1.id, + resourceType='userVM', + tags={'region': 'India'} + ) self.debug("Tag created: %s" % tag.__dict__) tags = Tag.list( - self.apiclient, - listall=True, - resourceType='userVM', - account=self.account.name, - domainid=self.account.domainid, - key='region', - value='India' - ) + self.apiclient, + listall=True, + resourceType='userVM', + account=self.account.name, + domainid=self.account.domainid, + key='region', + value='India' + ) self.assertEqual( - isinstance(tags, list), - True, - "List tags should not return empty response" - ) + isinstance(tags, list), + True, + "List tags should not return empty response" + ) self.assertEqual( - tags[0].value, - 'India', - "The tag value should match with the original value" - ) - + tags[0].value, + 'India', + "The tag value should match with the original value" + ) + vms = VirtualMachine.list( - self.apiclient, - listall=True, - key='region', - value='India' - ) - + self.apiclient, + listall=True, + key='region', + value='India' + ) + self.assertEqual( - isinstance(vms, list), - True, - "Tag based VMs listing failed") - + isinstance(vms, list), + True, + "Tag based VMs listing failed") + self.debug("Deleting the created tag..") try: tag.delete( - self.apiclient, - resourceIds=self.vm_1.id, - resourceType='userVM', - tags={'region': 'India'} - ) + self.apiclient, + resourceIds=self.vm_1.id, + resourceType='userVM', + tags={'region': 'India'} + ) except Exception as e: self.fail("Failed to delete the tag - %s" % e) self.debug("Verifying if tag is actually deleted!") tags = Tag.list( - self.apiclient, - listall=True, - resourceType='userVM', - account=self.account.name, - domainid=self.account.domainid, - key='region', - value='India' - ) + self.apiclient, + listall=True, + resourceType='userVM', + account=self.account.name, + domainid=self.account.domainid, + key='region', + value='India' + ) self.assertEqual( - tags, - None, - "List tags should return empty response" - ) + tags, + None, + "List tags should return empty response" + ) return @attr(tags=["advanced", "basic"], required_hardware="false") @@ -948,7 +951,7 @@ class TestResourceTags(cloudstackTestCase): try: self.debug("Stopping the virtual machine: %s" % self.vm_1.name) - #Stop virtual machine + # Stop virtual machine self.vm_1.stop(self.user_api_client) except Exception as e: self.fail("Failed to stop VM: %s" % e) @@ -956,11 +959,11 @@ class TestResourceTags(cloudstackTestCase): timeout = self.services["timeout"] while True: list_volume = Volume.list( - self.user_api_client, - virtualmachineid=self.vm_1.id, - type='ROOT', - listall=True - ) + self.user_api_client, + virtualmachineid=self.vm_1.id, + type='ROOT', + listall=True + ) if isinstance(list_volume, list): break elif timeout == 0: @@ -972,78 +975,77 @@ class TestResourceTags(cloudstackTestCase): self.volume = list_volume[0] self.debug("Creating template from ROOT disk of virtual machine: %s" % - self.vm_1.name) - #Create template from volume + self.vm_1.name) + # Create template from volume template = Template.create( - self.user_api_client, - self.services["template"], - self.volume.id - ) + self.user_api_client, + self.services["template"], + self.volume.id + ) self.cleanup.append(template) self.debug("Created the template(%s). Now restarting the userVm: %s" % - (template.name, self.vm_1.name)) + (template.name, self.vm_1.name)) self.vm_1.start(self.user_api_client) self.debug("Creating a tag for the template") tag = Tag.create( - self.user_api_client, - resourceIds=template.id, - resourceType='Template', - tags={'OS': 'CentOS'} - ) + self.user_api_client, + resourceIds=template.id, + resourceType='Template', + tags={'OS': 'CentOS'} + ) self.debug("Tag created: %s" % tag.__dict__) tags = Tag.list( - self.user_api_client, - listall=True, - resourceType='Template', - key='OS', - value='CentOS' - ) + self.user_api_client, + listall=True, + resourceType='Template', + key='OS', + value='CentOS' + ) self.assertEqual( - isinstance(tags, list), - True, - "List tags should not return empty response" - ) + isinstance(tags, list), + True, + "List tags should not return empty response" + ) self.assertEqual( - tags[0].value, - 'CentOS', - 'The tag should have original value' - ) + tags[0].value, + 'CentOS', + 'The tag should have original value' + ) Template.list( - self.user_api_client, - templatefilter=\ - self.services["template"]["templatefilter"], - listall=True, - key='OS', - value='CentOS' - ) + self.user_api_client, + templatefilter=self.services["template"]["templatefilter"], + listall=True, + key='OS', + value='CentOS' + ) self.debug("Deleting the created tag..") try: tag.delete( - self.user_api_client, - resourceIds=template.id, - resourceType='Template', - tags={'OS': 'CentOS'} - ) + self.user_api_client, + resourceIds=template.id, + resourceType='Template', + tags={'OS': 'CentOS'} + ) except Exception as e: self.fail("Failed to delete the tag - %s" % e) self.debug("Verifying if tag is actually deleted!") tags = Tag.list( - self.user_api_client, - listall=True, - resourceType='Template', - key='OS', - value='CentOS' - ) + self.user_api_client, + listall=True, + resourceType='Template', + key='OS', + value='CentOS' + ) self.assertEqual( - tags, - None, - "List tags should return empty response" - ) + tags, + None, + "List tags should return empty response" + ) return @attr(tags=["advanced", "basic"], required_hardware="false") @@ -1055,90 +1057,90 @@ class TestResourceTags(cloudstackTestCase): # 2. Delete above created tag using deleteTags API iso = Iso.create( - self.apiclient, - self.services["iso"], - account=self.account.name, - domainid=self.account.domainid - ) + self.apiclient, + self.services["iso"], + account=self.account.name, + domainid=self.account.domainid + ) self.debug("ISO created with ID: %s" % iso.id) list_iso_response = Iso.list(self.apiclient, id=iso.id) self.assertEqual( - isinstance(list_iso_response, list), - True, - "Check list response returns a valid list" - ) + isinstance(list_iso_response, list), + True, + "Check list response returns a valid list" + ) self.debug("Creating a tag for the ISO") tag = Tag.create( - self.apiclient, - resourceIds=iso.id, - resourceType='ISO', - tags={'OS': 'CentOS'} - ) + self.apiclient, + resourceIds=iso.id, + resourceType='ISO', + tags={'OS': 'CentOS'} + ) self.debug("Tag created: %s" % tag.__dict__) tags = Tag.list( - self.apiclient, - listall=True, - resourceType='ISO', - account=self.account.name, - domainid=self.account.domainid, - key='OS', - value='CentOS' - ) + self.apiclient, + listall=True, + resourceType='ISO', + account=self.account.name, + domainid=self.account.domainid, + key='OS', + value='CentOS' + ) self.assertEqual( - isinstance(tags, list), - True, - "List tags should not return empty response" - ) + isinstance(tags, list), + True, + "List tags should not return empty response" + ) self.assertEqual( - tags[0].value, - 'CentOS', - 'The tag should have original value' - ) + tags[0].value, + 'CentOS', + 'The tag should have original value' + ) isos = Iso.list( - self.apiclient, - key='OS', - value='CentOS', - account=self.account.name, - domainid=self.account.domainid, - isofilter='all' - ) + self.apiclient, + key='OS', + value='CentOS', + account=self.account.name, + domainid=self.account.domainid, + isofilter='all' + ) self.assertEqual( - isinstance(isos, list), - True, - "List isos should not return an empty response" - ) + isinstance(isos, list), + True, + "List isos should not return an empty response" + ) self.debug("Deleting the created tag..") try: tag.delete( - self.apiclient, - resourceIds=iso.id, - resourceType='ISO', - tags={'OS': 'CentOS'} - ) + self.apiclient, + resourceIds=iso.id, + resourceType='ISO', + tags={'OS': 'CentOS'} + ) except Exception as e: self.fail("Failed to delete the tag - %s" % e) self.debug("Verifying if tag is actually deleted!") tags = Tag.list( - self.apiclient, - listall=True, - resourceType='ISO', - account=self.account.name, - domainid=self.account.domainid, - key='OS', - value='CentOS' - ) + self.apiclient, + listall=True, + resourceType='ISO', + account=self.account.name, + domainid=self.account.domainid, + key='OS', + value='CentOS' + ) self.assertEqual( - tags, - None, - "List tags should return empty response" - ) + tags, + None, + "List tags should return empty response" + ) return @attr(tags=["advanced", "basic"], required_hardware="false") @@ -1150,84 +1152,84 @@ class TestResourceTags(cloudstackTestCase): # 2. Delete above created tag using deleteTags API self.debug("Creating volume for account: %s " % - self.account.name) + self.account.name) volume = Volume.create( - self.apiclient, - self.services["volume"], - zoneid=self.zone.id, - account=self.account.name, - domainid=self.account.domainid, - diskofferingid=self.disk_offering.id - ) + self.apiclient, + self.services["volume"], + zoneid=self.zone.id, + account=self.account.name, + domainid=self.account.domainid, + diskofferingid=self.disk_offering.id + ) self.cleanup.append(volume) self.debug("Volume created in account: %s" % volume.name) self.debug("Creating a tag for the volume") tag = Tag.create( - self.apiclient, - resourceIds=volume.id, - resourceType='volume', - tags={'region': 'India'} - ) + self.apiclient, + resourceIds=volume.id, + resourceType='volume', + tags={'region': 'India'} + ) self.debug("Tag created: %s" % tag.__dict__) tags = Tag.list( - self.apiclient, - listall=True, - resourceType='volume', - account=self.account.name, - domainid=self.account.domainid, - key='region', - value='India' - ) + self.apiclient, + listall=True, + resourceType='volume', + account=self.account.name, + domainid=self.account.domainid, + key='region', + value='India' + ) self.assertEqual( - isinstance(tags, list), - True, - "List tags should not return empty response" - ) + isinstance(tags, list), + True, + "List tags should not return empty response" + ) self.assertEqual( - tags[0].value, - 'India', - 'The tag should have original value' - ) - + tags[0].value, + 'India', + 'The tag should have original value' + ) + vols = Volume.list(self.apiclient, - listall=True, - key='region', - value='India' - ) + listall=True, + key='region', + value='India' + ) self.assertEqual( - isinstance(vols, list), - True, - "List volumes should not return empty response" - ) - + isinstance(vols, list), + True, + "List volumes should not return empty response" + ) + self.debug("Deleting the created tag..") try: tag.delete( - self.apiclient, - resourceIds=volume.id, - resourceType='volume', - tags={'region': 'India'} - ) + self.apiclient, + resourceIds=volume.id, + resourceType='volume', + tags={'region': 'India'} + ) except Exception as e: self.fail("Failed to delete the tag - %s" % e) self.debug("Verifying if tag is actually deleted!") tags = Tag.list( - self.apiclient, - listall=True, - resourceType='volume', - account=self.account.name, - domainid=self.account.domainid, - key='region' - ) + self.apiclient, + listall=True, + resourceType='volume', + account=self.account.name, + domainid=self.account.domainid, + key='region' + ) self.assertEqual( - tags, - None, - "List tags should return empty response" - ) + tags, + None, + "List tags should return empty response" + ) return @attr(tags=["advanced", "basic"], required_hardware="false") @@ -1238,8 +1240,11 @@ class TestResourceTags(cloudstackTestCase): # 1. Create a tag on snapshot using createTags API # 2. Delete above created tag using deleteTags API + if self.hypervisor.lower() in ['hyperv']: + self.skipTest("Snapshots feature is not supported on Hyper-V") + self.debug("Creating snapshot on ROOT volume for VM: %s " % - self.vm_1.name) + self.vm_1.name) # Get the Root disk of VM volumes = Volume.list(self.apiclient, virtualmachineid=self.vm_1.id, @@ -1255,80 +1260,80 @@ class TestResourceTags(cloudstackTestCase): snapshots = Snapshot.list(self.apiclient, id=snapshot.id) self.assertEqual( - isinstance(snapshots, list), - True, - "Tag based snapshot listing failed") + isinstance(snapshots, list), + True, + "Tag based snapshot listing failed") self.debug("Creating a tag for the snapshot") tag = Tag.create( - self.apiclient, - resourceIds=snapshot.id, - resourceType='snapshot', - tags={'type': 'manual'} - ) + self.apiclient, + resourceIds=snapshot.id, + resourceType='snapshot', + tags={'type': 'manual'} + ) self.debug("Tag created: %s" % tag.__dict__) tags = Tag.list( - self.apiclient, - listall=True, - resourceType='snapshot', - account=self.account.name, - domainid=self.account.domainid, - key='type', - value='manual' - ) + self.apiclient, + listall=True, + resourceType='snapshot', + account=self.account.name, + domainid=self.account.domainid, + key='type', + value='manual' + ) self.assertEqual( - isinstance(tags, list), - True, - "List tags should not return empty response" - ) + isinstance(tags, list), + True, + "List tags should not return empty response" + ) self.assertEqual( - tags[0].value, - 'manual', - 'The tag should have original value' - ) + tags[0].value, + 'manual', + 'The tag should have original value' + ) snapshots = Snapshot.list(self.apiclient, listall=True, key='type', value='manual') self.assertEqual( - isinstance(snapshots, list), - True, - "Check list response returns a valid list" - ) + isinstance(snapshots, list), + True, + "Check list response returns a valid list" + ) self.assertNotEqual( - snapshots, - None, - "Check if result exists in list snapshots call" - ) + snapshots, + None, + "Check if result exists in list snapshots call" + ) self.debug("Listing snapshots by tag was successful") self.debug("Deleting the created tag..") try: tag.delete( - self.apiclient, - resourceIds=snapshot.id, - resourceType='snapshot', - tags={'type': 'manual'} - ) + self.apiclient, + resourceIds=snapshot.id, + resourceType='snapshot', + tags={'type': 'manual'} + ) except Exception as e: self.fail("Failed to delete the tag - %s" % e) self.debug("Verifying if tag is actually deleted!") tags = Tag.list( - self.apiclient, - listall=True, - resourceType='snapshot', - account=self.account.name, - domainid=self.account.domainid, - key='type', - value='manual' - ) + self.apiclient, + listall=True, + resourceType='snapshot', + account=self.account.name, + domainid=self.account.domainid, + key='type', + value='manual' + ) self.assertEqual( - tags, - None, - "List tags should return empty response" - ) + tags, + None, + "List tags should return empty response" + ) return @@ -1341,91 +1346,91 @@ class TestResourceTags(cloudstackTestCase): # 2. Delete above created tag using deleteTags API self.debug("Fetching the network details for account: %s" % - self.account.name) + self.account.name) networks = Network.list( - self.apiclient, - account=self.account.name, - domainid=self.account.domainid, - listall=True - ) + self.apiclient, + account=self.account.name, + domainid=self.account.domainid, + listall=True + ) self.assertEqual( - isinstance(networks, list), - True, - "List networks should not return an empty response" - ) + isinstance(networks, list), + True, + "List networks should not return an empty response" + ) network = networks[0] self.debug("Network for the account: %s is %s" % - (self.account.name, network.name)) + (self.account.name, network.name)) self.debug("Creating a tag for load balancer rule") tag = Tag.create( - self.apiclient, - resourceIds=network.id, - resourceType='Network', - tags={'region': 'India'} - ) + self.apiclient, + resourceIds=network.id, + resourceType='Network', + tags={'region': 'India'} + ) self.debug("Tag created: %s" % tag.__dict__) tags = Tag.list( - self.apiclient, - listall=True, - resourceType='Network', - account=self.account.name, - domainid=self.account.domainid, - key='region', - value='India' - ) + self.apiclient, + listall=True, + resourceType='Network', + account=self.account.name, + domainid=self.account.domainid, + key='region', + value='India' + ) self.assertEqual( - isinstance(tags, list), - True, - "List tags should not return empty response" - ) + isinstance(tags, list), + True, + "List tags should not return empty response" + ) self.assertEqual( - tags[0].value, - 'India', - 'The tag should have original value' - ) - + tags[0].value, + 'India', + 'The tag should have original value' + ) + networks = Network.list( - self.apiclient, - account=self.account.name, - domainid=self.account.domainid, - listall=True, - key='region', - value='India' - ) + self.apiclient, + account=self.account.name, + domainid=self.account.domainid, + listall=True, + key='region', + value='India' + ) self.assertEqual( - isinstance(networks, list), - True, - "List networks should not return an empty response" - ) + isinstance(networks, list), + True, + "List networks should not return an empty response" + ) self.debug("Deleting the created tag..") try: tag.delete( - self.apiclient, - resourceIds=network.id, - resourceType='Network', - tags={'region': 'India'} - ) + self.apiclient, + resourceIds=network.id, + resourceType='Network', + tags={'region': 'India'} + ) except Exception as e: self.fail("Failed to delete the tag - %s" % e) self.debug("Verifying if tag is actually deleted!") tags = Tag.list( - self.apiclient, - listall=True, - resourceType='Network', - account=self.account.name, - domainid=self.account.domainid, - key='region', - value='India' - ) + self.apiclient, + listall=True, + resourceType='Network', + account=self.account.name, + domainid=self.account.domainid, + key='region', + value='India' + ) self.assertEqual( - tags, - None, - "List tags should return empty response" - ) + tags, + None, + "List tags should return empty response" + ) return @attr(tags=["basic", "sg"]) @@ -1437,29 +1442,29 @@ class TestResourceTags(cloudstackTestCase): # 2. Delete above created tag using deleteTags API vms = VirtualMachine.list( - self.apiclient, - id=self.vm_1.id, - listall=True - ) + self.apiclient, + id=self.vm_1.id, + listall=True + ) self.assertEqual( - isinstance(vms, list), - True, - "List vms should not return empty response" - ) + isinstance(vms, list), + True, + "List vms should not return empty response" + ) source_host = vms[0].hostid - + hosts = Host.list( - self.apiclient, - zoneid=self.zone.id, - resourcestate='Enabled', - type='Routing' - ) + self.apiclient, + zoneid=self.zone.id, + resourcestate='Enabled', + type='Routing' + ) self.assertEqual( - isinstance(hosts, list), - True, - "List hosts should return valid host response" - ) + isinstance(hosts, list), + True, + "List hosts should return valid host response" + ) self.debug("Available hosts: ") for host in hosts: @@ -1474,64 +1479,64 @@ class TestResourceTags(cloudstackTestCase): self.debug("Creating a tag for user VM") tag = Tag.create( - self.apiclient, - resourceIds=self.vm_1.id, - resourceType='userVM', - tags={'region': 'India'} - ) + self.apiclient, + resourceIds=self.vm_1.id, + resourceType='userVM', + tags={'region': 'India'} + ) self.debug("Tag created: %s" % tag.__dict__) tags = Tag.list( - self.apiclient, - listall=True, - resourceType='userVM', - account=self.account.name, - domainid=self.account.domainid, - key='region', - value='India' - ) + self.apiclient, + listall=True, + resourceType='userVM', + account=self.account.name, + domainid=self.account.domainid, + key='region', + value='India' + ) self.assertEqual( - isinstance(tags, list), - True, - "List tags should not return empty response" - ) + isinstance(tags, list), + True, + "List tags should not return empty response" + ) self.assertEqual( - tags[0].value, - 'India', - 'The tag should have original value' - ) + tags[0].value, + 'India', + 'The tag should have original value' + ) self.debug("Migrating the instance from: %s to %s" % - (source_host, dest_host.id)) + (source_host, dest_host.id)) self.vm_1.migrate(self.apiclient, hostid=dest_host.id) self.debug("Deleting the created tag..") try: tag.delete( - self.apiclient, - resourceIds=self.vm_1.id, - resourceType='userVM', - tags={'region': 'India'} - ) + self.apiclient, + resourceIds=self.vm_1.id, + resourceType='userVM', + tags={'region': 'India'} + ) except Exception as e: self.fail("Failed to delete the tag - %s" % e) self.debug("Verifying if tag is actually deleted!") tags = Tag.list( - self.apiclient, - listall=True, - resourceType='userVM', - account=self.account.name, - domainid=self.account.domainid, - key='region', - value='India' - ) + self.apiclient, + listall=True, + resourceType='userVM', + account=self.account.name, + domainid=self.account.domainid, + key='region', + value='India' + ) self.assertEqual( - tags, - None, - "List tags should return empty response" - ) + tags, + None, + "List tags should return empty response" + ) return @attr(tags=["advanced", "basic"], required_hardware="false") @@ -1545,33 +1550,33 @@ class TestResourceTags(cloudstackTestCase): self.debug("Creating a tag for user VM") tag_1 = Tag.create( - self.apiclient, - resourceIds=self.vm_1.id, - resourceType='userVM', - tags={'region': 'India'} - ) + self.apiclient, + resourceIds=self.vm_1.id, + resourceType='userVM', + tags={'region': 'India'} + ) self.debug("Tag created: %s" % tag_1.__dict__) tags = Tag.list( - self.apiclient, - listall=True, - resourceType='userVM', - account=self.account.name, - domainid=self.account.domainid, - key='region', - value='India' - ) + self.apiclient, + listall=True, + resourceType='userVM', + account=self.account.name, + domainid=self.account.domainid, + key='region', + value='India' + ) self.assertEqual( - isinstance(tags, list), - True, - "List tags should not return empty response" - ) + isinstance(tags, list), + True, + "List tags should not return empty response" + ) self.assertEqual( - tags[0].value, - 'India', - 'The tag should have original value' - ) + tags[0].value, + 'India', + 'The tag should have original value' + ) try: Tag.create(self.apiclient, resourceIds=self.vm_1.id, @@ -1584,29 +1589,29 @@ class TestResourceTags(cloudstackTestCase): try: tag_1.delete( - self.apiclient, - resourceIds=self.vm_1.id, - resourceType='userVM', - tags={'region': 'India'} - ) + self.apiclient, + resourceIds=self.vm_1.id, + resourceType='userVM', + tags={'region': 'India'} + ) except Exception as e: self.fail("Failed to delete the tag - %s" % e) self.debug("Verifying if tag is actually deleted!") tags = Tag.list( - self.apiclient, - listall=True, - resourceType='userVM', - account=self.account.name, - domainid=self.account.domainid, - key='region', - value='India' - ) + self.apiclient, + listall=True, + resourceType='userVM', + account=self.account.name, + domainid=self.account.domainid, + key='region', + value='India' + ) self.assertEqual( - tags, - None, - "List tags should return empty response" - ) + tags, + None, + "List tags should return empty response" + ) return @@ -1620,63 +1625,63 @@ class TestResourceTags(cloudstackTestCase): self.debug("Creating a tag for user VM") tag = Tag.create( - self.apiclient, - resourceIds=self.vm_1.id, - resourceType='userVM', - tags={ - 'region': 'India', - 'offering': 'high', - 'type': 'webserver', - 'priority': 'critical', - 'networking': 'advanced', - 'os': 'centos', - 'backup': 'no$required', - 'rootvolume': 'NFS', - 'iso': 'na', - 'ha': 'yes', - 'test': 'test' - } - ) + self.apiclient, + resourceIds=self.vm_1.id, + resourceType='userVM', + tags={ + 'region': 'India', + 'offering': 'high', + 'type': 'webserver', + 'priority': 'critical', + 'networking': 'advanced', + 'os': 'centos', + 'backup': 'no$required', + 'rootvolume': 'NFS', + 'iso': 'na', + 'ha': 'yes', + 'test': 'test' + } + ) self.debug("Tags created: %s" % tag.__dict__) tags = Tag.list( - self.apiclient, - listall=True, - resourceType='userVM', - account=self.account.name, - domainid=self.account.domainid, - key='region', - value='India' - ) + self.apiclient, + listall=True, + resourceType='userVM', + account=self.account.name, + domainid=self.account.domainid, + key='region', + value='India' + ) self.assertEqual( - isinstance(tags, list), - True, - "List tags should not return empty response" - ) + isinstance(tags, list), + True, + "List tags should not return empty response" + ) self.assertEqual( - tags[0].value, - 'India', - 'The tag should have original value' - ) + tags[0].value, + 'India', + 'The tag should have original value' + ) # Cleanup tag.delete( - self.apiclient, - resourceIds=self.vm_1.id, - resourceType='userVM', - tags={ - 'region': 'India', - 'offering': 'high', - 'type': 'webserver', - 'priority': 'critical', - 'networking': 'advanced', - 'os': 'centos', - 'backup': 'no$required', - 'rootvolume': 'NFS', - 'iso': 'na', - 'ha': 'yes', - 'test': 'test' - } - ) + self.apiclient, + resourceIds=self.vm_1.id, + resourceType='userVM', + tags={ + 'region': 'India', + 'offering': 'high', + 'type': 'webserver', + 'priority': 'critical', + 'networking': 'advanced', + 'os': 'centos', + 'backup': 'no$required', + 'rootvolume': 'NFS', + 'iso': 'na', + 'ha': 'yes', + 'test': 'test' + } + ) return @attr(tags=["advanced"], required_hardware="false") @@ -1684,91 +1689,90 @@ class TestResourceTags(cloudstackTestCase): """ Test creation, listing and deletion tags on projects """ # Validate the following - # 1. Create a new project + # 1. Create a new project # 2. Create a tag on projects using createTags API # 3. Delete the tag. # Create project as a domain admin project = Project.create( - self.apiclient, - self.services["project"], - account=self.account.name, - domainid=self.account.domainid - ) + self.apiclient, + self.services["project"], + account=self.account.name, + domainid=self.account.domainid + ) # Cleanup created project at end of test self.cleanup.append(project) self.debug("Created project with domain admin with ID: %s" % - project.id) + project.id) self.debug("Creating a tag for the project") tag = Tag.create( - self.apiclient, - resourceIds=project.id, - resourceType='project', - tags={'region': 'India'} - ) + self.apiclient, + resourceIds=project.id, + resourceType='project', + tags={'region': 'India'} + ) self.debug("Tag created: %s" % tag.__dict__) tags = Tag.list( - self.apiclient, - listall=True, - resourceType='project', - resourceIds=project.id, - key='region', - ) + self.apiclient, + listall=True, + resourceType='project', + resourceIds=project.id, + key='region', + ) self.debug("tags = %s" % tags) - + self.assertEqual( - isinstance(tags, list), - True, - "List tags should not return empty response" - ) + isinstance(tags, list), + True, + "List tags should not return empty response" + ) self.assertEqual( - tags[0].value, - 'India', - 'The tag should have original value' - ) - + tags[0].value, + 'India', + 'The tag should have original value' + ) + projects = Project.list( - self.apiclient, - listall=True, - key='region', - value='India' - ) + self.apiclient, + listall=True, + key='region', + value='India' + ) self.assertEqual( - isinstance(projects, list), - True, - "List Project should return valid list" - ) - + isinstance(projects, list), + True, + "List Project should return valid list" + ) self.debug("Deleting the created tag..") try: tag.delete( - self.apiclient, - resourceIds=project.id, - resourceType='project', - tags={'region': 'India'} - ) + self.apiclient, + resourceIds=project.id, + resourceType='project', + tags={'region': 'India'} + ) except Exception as e: self.fail("Failed to delete the tag - %s" % e) self.debug("Verifying if tag is actually deleted!") tags = Tag.list( - self.apiclient, - listall=True, - resourceType='project', - account=self.account.name, - domainid=self.account.domainid, - key='region', - value='India' - ) + self.apiclient, + listall=True, + resourceType='project', + account=self.account.name, + domainid=self.account.domainid, + key='region', + value='India' + ) self.assertEqual( - tags, - None, - "List tags should return empty response" - ) + tags, + None, + "List tags should return empty response" + ) return @attr(tags=["advanced", "basic"], required_hardware="false") @@ -1784,79 +1788,79 @@ class TestResourceTags(cloudstackTestCase): self.debug("Creating user accounts..") user_account = Account.create( - self.apiclient, - self.services["user"], - domainid=self.domain.id - ) + self.apiclient, + self.services["user"], + domainid=self.domain.id + ) self.cleanup.append(user_account) other_user_account = Account.create( - self.apiclient, - self.services["other_user"], - domainid=self.domain.id - ) + self.apiclient, + self.services["other_user"], + domainid=self.domain.id + ) self.cleanup.append(other_user_account) iso = Iso.create( - self.apiclient, - self.services["iso"], - account=user_account.name, - domainid=user_account.domainid - ) + self.apiclient, + self.services["iso"], + account=user_account.name, + domainid=user_account.domainid + ) self.debug("ISO created with ID: %s" % iso.id) list_iso_response = Iso.list(self.apiclient, id=iso.id) self.assertEqual( - isinstance(list_iso_response, list), - True, - "Check list response returns a valid list" - ) + isinstance(list_iso_response, list), + True, + "Check list response returns a valid list" + ) self.debug("Creating a tag for the ISO") tag = Tag.create( - self.apiclient, - resourceIds=iso.id, - resourceType='ISO', - tags={'region': 'India'} - ) + self.apiclient, + resourceIds=iso.id, + resourceType='ISO', + tags={'region': 'India'} + ) self.debug("Tag created: %s" % tag.__dict__) tags = Tag.list( - self.apiclient, - listall=True, - resourceType='ISO', - account=user_account.name, - domainid=user_account.domainid, - key='region', - ) + self.apiclient, + listall=True, + resourceType='ISO', + account=user_account.name, + domainid=user_account.domainid, + key='region', + ) self.assertEqual( - isinstance(tags, list), - True, - "List tags should not return empty response" - ) + isinstance(tags, list), + True, + "List tags should not return empty response" + ) self.assertEqual( - tags[0].value, - 'India', - "The tag value should match with the original value" - ) - + tags[0].value, + 'India', + "The tag value should match with the original value" + ) + self.debug("Verify listTag API using other account") tags = Tag.list( - self.apiclient, - listall=True, - resourceType='ISO', - account=other_user_account.name, - domainid=other_user_account.domainid, - key='region', - ) - + self.apiclient, + listall=True, + resourceType='ISO', + account=other_user_account.name, + domainid=other_user_account.domainid, + key='region', + ) + self.assertEqual( - tags, - None, - "List tags should return empty response" - ) - + tags, + None, + "List tags should return empty response" + ) + return @attr(tags=["advanced", "basic"], required_hardware="false") @@ -1872,68 +1876,68 @@ class TestResourceTags(cloudstackTestCase): self.debug("Creating user accounts..") user_account = Account.create( - self.apiclient, - self.services["user"], - domainid=self.domain.id - ) + self.apiclient, + self.services["user"], + domainid=self.domain.id + ) self.cleanup.append(user_account) iso = Iso.create( - self.apiclient, - self.services["iso"], - account=user_account.name, - domainid=user_account.domainid - ) + self.apiclient, + self.services["iso"], + account=user_account.name, + domainid=user_account.domainid + ) list_iso_response = Iso.list(self.apiclient, id=iso.id) self.assertEqual( - isinstance(list_iso_response, list), - True, - "Check list response returns a valid list" - ) + isinstance(list_iso_response, list), + True, + "Check list response returns a valid list" + ) Tag.create(self.apiclient, resourceIds=iso.id, resourceType='ISO', tags={'region': 'India'}) tags = Tag.list( - self.apiclient, - listall=True, - resourceType='ISO', - account=user_account.name, - domainid=user_account.domainid, - key='region', - ) + self.apiclient, + listall=True, + resourceType='ISO', + account=user_account.name, + domainid=user_account.domainid, + key='region', + ) self.assertEqual( - isinstance(tags, list), - True, - "List tags should not return empty response" - ) + isinstance(tags, list), + True, + "List tags should not return empty response" + ) self.assertEqual( - tags[0].value, - 'India', - "The tag value should match with the original value" - ) - + tags[0].value, + 'India', + "The tag value should match with the original value" + ) + self.debug("Verify listTag API using admin account") tags = Tag.list( - self.apiclient, - listall=True, - resourceType='ISO', - key='region', - ) + self.apiclient, + listall=True, + resourceType='ISO', + key='region', + ) self.assertEqual( - isinstance(tags, list), - True, - "List tags should not return empty response" - ) + isinstance(tags, list), + True, + "List tags should not return empty response" + ) self.assertEqual( - tags[0].value, - 'India', - 'The tag should have original value' - ) - + tags[0].value, + 'India', + 'The tag should have original value' + ) + return @attr(tags=["advanced", "basic", "simulator"], required_hardware="false") @@ -1946,32 +1950,36 @@ class TestResourceTags(cloudstackTestCase): self.debug("Creating a tag for user VM") tag = Tag.create( - self.apiclient, - resourceIds=self.vm_1.id, - resourceType='userVM', - tags={'region': 'India'} - ) + self.apiclient, + resourceIds=self.vm_1.id, + resourceType='userVM', + tags={'region': 'India'} + ) self.debug("Tag created: %s" % tag.__dict__) - # Add tag for removal during teardown. vm_1 is shared resource if it is tagged + # Add tag for removal during teardown. vm_1 is shared + # resource if it is tagged # and the test fails with exception then the tag is not deleted. And # subsequent tests fail to tag the vm_1 with same key-pair - # breaking the tests. - self.rm_tags.append({'tag_obj': tag,'restype': 'userVM', 'resid': self.vm_1.id, - 'key': 'region', 'value': 'India'}) + # breaking the tests. + self.rm_tags.append({'tag_obj': tag, + 'restype': 'userVM', + 'resid': self.vm_1.id, + 'key': 'region', + 'value': 'India'}) self.debug("Passing invalid key parameter to the listAPI for vms") vms = VirtualMachine.list(self.apiclient, - **{'tags[0].key': 'region111', - 'tags[0].value': 'India', - 'listall' : 'True'} - ) + **{'tags[0].key': 'region111', + 'tags[0].value': 'India', + 'listall': 'True'} + ) self.assertEqual( - vms, - None, - "List vms should return empty response" - ) + vms, + None, + "List vms should return empty response" + ) return @@ -1986,97 +1994,97 @@ class TestResourceTags(cloudstackTestCase): self.debug("Creating a tag for user VM") tag = Tag.create( - self.apiclient, - resourceIds=self.vm_1.id, - resourceType='userVM', - tags={'region': 'India'} - ) + self.apiclient, + resourceIds=self.vm_1.id, + resourceType='userVM', + tags={'region': 'India'} + ) self.debug("Tag created: %s" % tag.__dict__) tags = Tag.list( - self.apiclient, - listall=True, - resourceType='userVM', - account=self.account.name, - domainid=self.account.domainid, - key='region', - value='India' - ) + self.apiclient, + listall=True, + resourceType='userVM', + account=self.account.name, + domainid=self.account.domainid, + key='region', + value='India' + ) self.assertEqual( - isinstance(tags, list), - True, - "List tags should not return empty response" - ) + isinstance(tags, list), + True, + "List tags should not return empty response" + ) self.assertEqual( - tags[0].value, - "India", - "Tag created with incorrect value" - ) + tags[0].value, + "India", + "Tag created with incorrect value" + ) self.debug("Deleting the created tag..") try: tag.delete( - self.apiclient, - resourceIds=self.vm_1.id, - resourceType='userVM', - tags={'region': 'India'} - ) + self.apiclient, + resourceIds=self.vm_1.id, + resourceType='userVM', + tags={'region': 'India'} + ) except Exception as e: self.fail("Failed to delete the tag - %s" % e) self.debug("Verifying if tag is actually deleted!") tags = Tag.list( - self.apiclient, - listall=True, - resourceType='userVM', - account=self.account.name, - domainid=self.account.domainid, - key='region', - value='India' - ) + self.apiclient, + listall=True, + resourceType='userVM', + account=self.account.name, + domainid=self.account.domainid, + key='region', + value='India' + ) self.assertEqual( - tags, - None, - "List tags should return empty response" - ) + tags, + None, + "List tags should return empty response" + ) self.debug("Recreating the tag with same name") tag = Tag.create( - self.apiclient, - resourceIds=self.vm_1.id, - resourceType='userVM', - tags={'region': 'India'} - ) + self.apiclient, + resourceIds=self.vm_1.id, + resourceType='userVM', + tags={'region': 'India'} + ) self.debug("Tag created: %s" % tag.__dict__) tags = Tag.list( - self.apiclient, - listall=True, - resourceType='userVM', - account=self.account.name, - domainid=self.account.domainid, - key='region', - value='India' - ) + self.apiclient, + listall=True, + resourceType='userVM', + account=self.account.name, + domainid=self.account.domainid, + key='region', + value='India' + ) self.assertEqual( - isinstance(tags, list), - True, - "List tags should not return empty response" - ) + isinstance(tags, list), + True, + "List tags should not return empty response" + ) self.assertEqual(tags[0].value, "India", "Tag created with incorrect value" ) - + self.debug("Deleting the created tag..") try: tag.delete( - self.apiclient, - resourceIds=self.vm_1.id, - resourceType='userVM', - tags={'region': 'India'} - ) + self.apiclient, + resourceIds=self.vm_1.id, + resourceType='userVM', + tags={'region': 'India'} + ) except Exception as e: self.fail("Failed to delete the tag - %s" % e) return @@ -2086,103 +2094,103 @@ class TestResourceTags(cloudstackTestCase): "Test creation of same tag on multiple resources" self.debug("Creating volume for account: %s " % - self.account.name) + self.account.name) volume = Volume.create( - self.apiclient, - self.services["volume"], - zoneid=self.zone.id, - account=self.account.name, - domainid=self.account.domainid, - diskofferingid=self.disk_offering.id - ) + self.apiclient, + self.services["volume"], + zoneid=self.zone.id, + account=self.account.name, + domainid=self.account.domainid, + diskofferingid=self.disk_offering.id + ) self.cleanup.append(volume) self.debug("Volume created in account: %s" % volume.name) self.debug("Creating a tag for the volume") tag = Tag.create( - self.apiclient, - resourceIds=volume.id, - resourceType='volume', - tags={'region': 'India'} - ) + self.apiclient, + resourceIds=volume.id, + resourceType='volume', + tags={'region': 'India'} + ) self.debug("Tag created: %s" % tag.__dict__) tags = Tag.list( - self.apiclient, - listall=True, - resourceType='volume', - account=self.account.name, - domainid=self.account.domainid, - key='region', - ) + self.apiclient, + listall=True, + resourceType='volume', + account=self.account.name, + domainid=self.account.domainid, + key='region', + ) self.assertEqual( - isinstance(tags, list), - True, - "List tags should not return empty response" - ) + isinstance(tags, list), + True, + "List tags should not return empty response" + ) self.assertEqual( - tags[0].value, - 'India', - 'The tag should have original value' - ) - + tags[0].value, + 'India', + 'The tag should have original value' + ) + self.debug("Creating a tag for user VM") tag = Tag.create( - self.apiclient, - resourceIds=self.vm_1.id, - resourceType='userVM', - tags={'region': 'India'} - ) + self.apiclient, + resourceIds=self.vm_1.id, + resourceType='userVM', + tags={'region': 'India'} + ) self.debug("Tag created: %s" % tag.__dict__) tags = Tag.list( - self.apiclient, - listall=True, - resourceType='userVM', - account=self.account.name, - domainid=self.account.domainid, - key='region', - value='India' - ) + self.apiclient, + listall=True, + resourceType='userVM', + account=self.account.name, + domainid=self.account.domainid, + key='region', + value='India' + ) self.assertEqual( - isinstance(tags, list), - True, - "List tags should not return empty response" - ) + isinstance(tags, list), + True, + "List tags should not return empty response" + ) self.assertEqual( - tags[0].value, - "India", - "Tag created with incorrect value" - ) - + tags[0].value, + "India", + "Tag created with incorrect value" + ) + self.debug("Deleting the created tag..") try: tag.delete( - self.apiclient, - resourceIds=self.vm_1.id, - resourceType='userVM', - tags={'region': 'India'} - ) + self.apiclient, + resourceIds=self.vm_1.id, + resourceType='userVM', + tags={'region': 'India'} + ) except Exception as e: self.fail("Failed to delete the tag - %s" % e) self.debug("Verifying if tag is actually deleted!") tags = Tag.list( - self.apiclient, - listall=True, - resourceType='userVM', - account=self.account.name, - domainid=self.account.domainid, - key='region', - value='India' - ) + self.apiclient, + listall=True, + resourceType='userVM', + account=self.account.name, + domainid=self.account.domainid, + key='region', + value='India' + ) self.assertEqual( - tags, - None, - "List tags should return empty response" - ) + tags, + None, + "List tags should return empty response" + ) return @@ -2192,46 +2200,46 @@ class TestResourceTags(cloudstackTestCase): try: self.debug("Stopping the virtual machine: %s" % self.vm_1.name) - #Stop virtual machine + # Stop virtual machine self.vm_1.stop(self.apiclient) self.debug("Creating a tag for user VM") tag = Tag.create( - self.apiclient, - resourceIds=self.vm_1.id, - resourceType='userVM', - tags={'region': 'India'} - ) + self.apiclient, + resourceIds=self.vm_1.id, + resourceType='userVM', + tags={'region': 'India'} + ) self.debug("Tag created: %s" % tag.__dict__) tags = Tag.list( - self.apiclient, - listall=True, - resourceType='userVM', - account=self.account.name, - domainid=self.account.domainid, - key='region', - value='India' - ) + self.apiclient, + listall=True, + resourceType='userVM', + account=self.account.name, + domainid=self.account.domainid, + key='region', + value='India' + ) self.assertEqual( - isinstance(tags, list), - True, - "List tags should not return empty response" - ) + isinstance(tags, list), + True, + "List tags should not return empty response" + ) self.assertEqual( - tags[0].value, - "India", - "Tag created with incorrect value" - ) + tags[0].value, + "India", + "Tag created with incorrect value" + ) self.debug("Deleting the created tag..") tag.delete( - self.apiclient, - resourceIds=self.vm_1.id, - resourceType='userVM', - tags={'region': 'India'} - ) + self.apiclient, + resourceIds=self.vm_1.id, + resourceType='userVM', + tags={'region': 'India'} + ) except Exception as e: self.fail("Exception occured - %s" % e) return @@ -2245,42 +2253,42 @@ class TestResourceTags(cloudstackTestCase): self.debug("Creating a tag for user VM") tag = Tag.create( - self.apiclient, - resourceIds=self.vm_1.id, - resourceType='userVM', - tags={'region': 'India'} - ) + self.apiclient, + resourceIds=self.vm_1.id, + resourceType='userVM', + tags={'region': 'India'} + ) self.debug("Tag created: %s" % tag.__dict__) tags = Tag.list( - self.apiclient, - listall=True, - resourceType='userVM', - account=self.account.name, - domainid=self.account.domainid, - key='region', - value='India' - ) + self.apiclient, + listall=True, + resourceType='userVM', + account=self.account.name, + domainid=self.account.domainid, + key='region', + value='India' + ) self.assertEqual( - isinstance(tags, list), - True, - "List tags should not return empty response" - ) + isinstance(tags, list), + True, + "List tags should not return empty response" + ) self.assertEqual( - tags[0].value, - "India", - "Tag created with incorrect value" - ) + tags[0].value, + "India", + "Tag created with incorrect value" + ) self.debug("Deleting the created tag..") try: tag.delete( - self.apiclient, - resourceIds=self.vm_1.id, - resourceType='userVM', - tags={'region': 'India'} - ) + self.apiclient, + resourceIds=self.vm_1.id, + resourceType='userVM', + tags={'region': 'India'} + ) except Exception as e: self.fail("Failed to delete the tag - %s" % e) diff --git a/test/integration/component/test_templates.py b/test/integration/component/test_templates.py index 753e71af646..06b8c5f58d6 100644 --- a/test/integration/component/test_templates.py +++ b/test/integration/component/test_templates.py @@ -284,7 +284,7 @@ class TestTemplates(cloudstackTestCase): cls.testClient = super(TestTemplates, cls).getClsTestClient() cls.api_client = cls.testClient.getApiClient() - + cls.hypervisor = cls.testClient.getHypervisorInfo() cls.services = Services().services # Get Zone, Domain and templates cls.domain = get_domain(cls.api_client) @@ -495,6 +495,9 @@ class TestTemplates(cloudstackTestCase): # 4. Deploy Virtual machine using this template # 5. VM should be in running state + if self.hypervisor.lower() in ['hyperv']: + self.skipTest("Snapshots feature is not supported on Hyper-V") + userapiclient = self.testClient.getUserApiClient( UserName=self.account.name, DomainName=self.account.domain) diff --git a/test/integration/component/test_usage.py b/test/integration/component/test_usage.py index 58cfbedae1d..262a3714524 100644 --- a/test/integration/component/test_usage.py +++ b/test/integration/component/test_usage.py @@ -16,7 +16,7 @@ # under the License. """ P1 tests for Snapshots """ -#Import Local Modules +# Import Local Modules from nose.plugins.attrib import attr from marvin.cloudstackTestCase import cloudstackTestCase, unittest from marvin.cloudstackAPI import deleteVolume @@ -39,84 +39,86 @@ from marvin.lib.common import (get_zone, get_domain, get_template) + class Services: + """Test Snapshots Services """ def __init__(self): self.services = { - "account": { - "email": "test@test.com", - "firstname": "Test", - "lastname": "User", - "username": "test", - # Random characters are appended for unique - # username - "password": "password", - }, - "service_offering": { - "name": "Tiny Instance", - "displaytext": "Tiny Instance", - "cpunumber": 1, - "cpuspeed": 100, # in MHz - "memory": 128, # In MBs - }, - "disk_offering": { - "displaytext": "Small", - "name": "Small", - "disksize": 1 - }, - "volume": { - "diskname": "TestDiskServ", - }, - "server": { - "displayname": "TestVM", - "username": "root", - "password": "password", - "ssh_port": 22, - "hypervisor": 'XenServer', - "privateport": 22, - "publicport": 22, - "protocol": 'TCP', - }, - "templates": { - "displaytext": 'Template', - "name": 'Template', - "ostype": 'CentOS 5.3 (64-bit)', - "templatefilter": 'self', - "url": "http://download.cloud.com/releases/2.0.0/UbuntuServer-10-04-64bit.qcow2.bz2" - }, - "iso": { - "displaytext": "Test ISO", - "name": "Test ISO", - "url": "http://people.apache.org/~tsp/dummy.iso", - # Source URL where ISO is located - "isextractable": True, - "isfeatured": True, - "ispublic": True, - "ostype": 'CentOS 5.3 (64-bit)', - }, - "lbrule": { - "name": "SSH", - "alg": "roundrobin", - # Algorithm used for load balancing - "privateport": 22, - "publicport": 2222, - }, - "natrule": { - "privateport": 22, - "publicport": 22, - "protocol": "TCP" - }, - "vpn_user": { - "username": "test", - "password": "test", - }, - "ostype": 'CentOS 5.3 (64-bit)', - # Cent OS 5.3 (64 bit) - "sleep": 60, - "timeout": 10, - } + "account": { + "email": "test@test.com", + "firstname": "Test", + "lastname": "User", + "username": "test", + # Random characters are appended for unique + # username + "password": "password", + }, + "service_offering": { + "name": "Tiny Instance", + "displaytext": "Tiny Instance", + "cpunumber": 1, + "cpuspeed": 100, # in MHz + "memory": 128, # In MBs + }, + "disk_offering": { + "displaytext": "Small", + "name": "Small", + "disksize": 1 + }, + "volume": { + "diskname": "TestDiskServ", + }, + "server": { + "displayname": "TestVM", + "username": "root", + "password": "password", + "ssh_port": 22, + "hypervisor": 'XenServer', + "privateport": 22, + "publicport": 22, + "protocol": 'TCP', + }, + "templates": { + "displaytext": 'Template', + "name": 'Template', + "ostype": 'CentOS 5.3 (64-bit)', + "templatefilter": 'self', + "url": "http://download.cloud.com/releases/2.0.0/UbuntuServer-10-04-64bit.qcow2.bz2" + }, + "iso": { + "displaytext": "Test ISO", + "name": "Test ISO", + "url": "http://people.apache.org/~tsp/dummy.iso", + # Source URL where ISO is located + "isextractable": True, + "isfeatured": True, + "ispublic": True, + "ostype": 'CentOS 5.3 (64-bit)', + }, + "lbrule": { + "name": "SSH", + "alg": "roundrobin", + # Algorithm used for load balancing + "privateport": 22, + "publicport": 2222, + }, + "natrule": { + "privateport": 22, + "publicport": 22, + "protocol": "TCP" + }, + "vpn_user": { + "username": "test", + "password": "test", + }, + "ostype": 'CentOS 5.3 (64-bit)', + # Cent OS 5.3 (64 bit) + "sleep": 60, + "timeout": 10, + } class TestVmUsage(cloudstackTestCase): @@ -133,45 +135,45 @@ class TestVmUsage(cloudstackTestCase): cls.services['mode'] = cls.zone.networktype template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) + cls.api_client, + cls.zone.id, + cls.services["ostype"] + ) cls.services["server"]["zoneid"] = cls.zone.id cls.services["template"] = template.id # Create Account, VMs etc cls.account = Account.create( - cls.api_client, - cls.services["account"], - domainid=cls.domain.id - ) + cls.api_client, + cls.services["account"], + domainid=cls.domain.id + ) cls.services["account"] = cls.account.name cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] - ) + cls.api_client, + cls.services["service_offering"] + ) cls.virtual_machine = VirtualMachine.create( - cls.api_client, - cls.services["server"], - templateid=template.id, - accountid=cls.account.name, - domainid=cls.account.domainid, - serviceofferingid=cls.service_offering.id - ) + cls.api_client, + cls.services["server"], + templateid=template.id, + accountid=cls.account.name, + domainid=cls.account.domainid, + serviceofferingid=cls.service_offering.id + ) cls._cleanup = [ - cls.service_offering, - cls.account, - ] + cls.service_offering, + cls.account, + ] return @classmethod def tearDownClass(cls): try: - #Cleanup resources used + # Cleanup resources used cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -185,13 +187,21 @@ class TestVmUsage(cloudstackTestCase): def tearDown(self): try: - #Clean up, terminate the created instance, volumes and snapshots + # 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", "basic", "sg", "eip", "advancedns", "simulator"], required_hardware="false") + @attr( + tags=[ + "advanced", + "basic", + "sg", + "eip", + "advancedns", + "simulator"], + required_hardware="false") def test_01_vm_usage(self): """Test Create/Destroy VM and verify usage calculation """ @@ -219,94 +229,94 @@ class TestVmUsage(cloudstackTestCase): self.fail("Failed to destroy VM: %s" % e) # Fetch account ID from account_uuid - self.debug("select id from account where uuid = '%s';" \ - % self.account.id) + self.debug("select id from account where uuid = '%s';" + % self.account.id) qresultset = self.dbclient.execute( - "select id from account where uuid = '%s';" \ - % self.account.id - ) + "select id from account where uuid = '%s';" + % self.account.id + ) self.assertEqual( - isinstance(qresultset, list), - True, - "Check DB query result set for valid data" - ) + isinstance(qresultset, list), + True, + "Check DB query result set for valid data" + ) self.assertNotEqual( - len(qresultset), - 0, - "Check DB Query result set" - ) + len(qresultset), + 0, + "Check DB Query result set" + ) qresult = qresultset[0] account_id = qresult[0] - self.debug("select type from usage_event where account_id = '%s';" \ - % account_id) + self.debug("select type from usage_event where account_id = '%s';" + % account_id) qresultset = self.dbclient.execute( - "select type from usage_event where account_id = '%s';" \ - % account_id - ) + "select type from usage_event where account_id = '%s';" + % account_id + ) self.assertEqual( - isinstance(qresultset, list), - True, - "Check DB query result set for valid data" - ) + isinstance(qresultset, list), + True, + "Check DB query result set for valid data" + ) self.assertNotEqual( - len(qresultset), - 0, - "Check DB Query result set" - ) + len(qresultset), + 0, + "Check DB Query result set" + ) qresult = str(qresultset) self.debug("Query result: %s" % qresult) # Check if VM.CREATE, VM.DESTROY events present in usage_event table self.assertEqual( - qresult.count('VM.START'), - 1, - "Check VM.START event in events table" - ) + qresult.count('VM.START'), + 1, + "Check VM.START event in events table" + ) self.assertEqual( - qresult.count('NETWORK.OFFERING.ASSIGN'), - 1, - "Check NETWORK.OFFERING.ASSIGN in events table" - ) + qresult.count('NETWORK.OFFERING.ASSIGN'), + 1, + "Check NETWORK.OFFERING.ASSIGN in events table" + ) self.assertEqual( - qresult.count('VM.CREATE'), - 1, - "Check VM.CREATE in list events" - ) + qresult.count('VM.CREATE'), + 1, + "Check VM.CREATE in list events" + ) self.assertEqual( - qresult.count('VOLUME.CREATE'), - 1, - "Check VOLUME.CREATE in events table" - ) + qresult.count('VOLUME.CREATE'), + 1, + "Check VOLUME.CREATE in events table" + ) self.assertEqual( - qresult.count('VM.STOP'), - 1, - "Check VM.STOP in events table" - ) + qresult.count('VM.STOP'), + 1, + "Check VM.STOP in events table" + ) self.assertEqual( - qresult.count('NETWORK.OFFERING.REMOVE'), - 1, - "Check NETWORK.OFFERING.REMOVE in list events" - ) + qresult.count('NETWORK.OFFERING.REMOVE'), + 1, + "Check NETWORK.OFFERING.REMOVE in list events" + ) self.assertEqual( - qresult.count('VM.DESTROY'), - 1, - "Check VM.DESTROY in events table" - ) + qresult.count('VM.DESTROY'), + 1, + "Check VM.DESTROY in events table" + ) self.assertEqual( - qresult.count('VOLUME.DELETE'), - 1, - "Check VOLUME.DELETE in events table" - ) + qresult.count('VOLUME.DELETE'), + 1, + "Check VOLUME.DELETE in events table" + ) return @@ -324,53 +334,53 @@ class TestPublicIPUsage(cloudstackTestCase): cls.services['mode'] = cls.zone.networktype template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) + cls.api_client, + cls.zone.id, + cls.services["ostype"] + ) cls.services["server"]["zoneid"] = cls.zone.id cls.services["template"] = template.id # Create VMs, Assign Public IP etc cls.account = Account.create( - cls.api_client, - cls.services["account"], - domainid=cls.domain.id - ) + cls.api_client, + cls.services["account"], + domainid=cls.domain.id + ) cls.services["account"] = cls.account.name cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] - ) + cls.api_client, + cls.services["service_offering"] + ) cls.virtual_machine = VirtualMachine.create( - cls.api_client, - cls.services["server"], - templateid=template.id, - accountid=cls.account.name, - domainid=cls.account.domainid, - serviceofferingid=cls.service_offering.id - ) + cls.api_client, + cls.services["server"], + templateid=template.id, + accountid=cls.account.name, + domainid=cls.account.domainid, + serviceofferingid=cls.service_offering.id + ) cls.public_ip = PublicIPAddress.create( - cls.api_client, - accountid=cls.virtual_machine.account, - zoneid=cls.virtual_machine.zoneid, - domainid=cls.virtual_machine.domainid, - services=cls.services["server"] - ) + cls.api_client, + accountid=cls.virtual_machine.account, + zoneid=cls.virtual_machine.zoneid, + domainid=cls.virtual_machine.domainid, + services=cls.services["server"] + ) cls._cleanup = [ - cls.service_offering, - cls.account, - ] + cls.service_offering, + cls.account, + ] return @classmethod def tearDownClass(cls): try: - #Cleanup resources used + # Cleanup resources used cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -384,13 +394,19 @@ class TestPublicIPUsage(cloudstackTestCase): def tearDown(self): try: - #Clean up, terminate the created instance + # Clean up, terminate the created instance cleanup_resources(self.apiclient, self.cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) return - @attr(tags=["advanced", "eip", "advancedns", "simulator"], required_hardware="false") + @attr( + tags=[ + "advanced", + "eip", + "advancedns", + "simulator"], + required_hardware="false") def test_01_public_ip_usage(self): """Test Assign new IP and verify usage calculation """ @@ -402,65 +418,65 @@ class TestPublicIPUsage(cloudstackTestCase): # 3. Delete the newly created account self.debug("Deleting public IP: %s" % - self.public_ip.ipaddress) + self.public_ip.ipaddress) # Release one of the IP self.public_ip.delete(self.apiclient) # Fetch account ID from account_uuid - self.debug("select id from account where uuid = '%s';" \ - % self.account.id) + self.debug("select id from account where uuid = '%s';" + % self.account.id) qresultset = self.dbclient.execute( - "select id from account where uuid = '%s';" \ - % self.account.id - ) + "select id from account where uuid = '%s';" + % self.account.id + ) self.assertEqual( - isinstance(qresultset, list), - True, - "Check DB query result set for valid data" - ) + isinstance(qresultset, list), + True, + "Check DB query result set for valid data" + ) self.assertNotEqual( - len(qresultset), - 0, - "Check DB Query result set" - ) + len(qresultset), + 0, + "Check DB Query result set" + ) qresult = qresultset[0] account_id = qresult[0] - self.debug("select type from usage_event where account_id = '%s';" \ - % account_id) + self.debug("select type from usage_event where account_id = '%s';" + % account_id) qresultset = self.dbclient.execute( - "select type from usage_event where account_id = '%s';" \ - % account_id - ) + "select type from usage_event where account_id = '%s';" + % account_id + ) self.assertEqual( - isinstance(qresultset, list), - True, - "Check DB query result set for valid data" - ) + isinstance(qresultset, list), + True, + "Check DB query result set for valid data" + ) self.assertNotEqual( - len(qresultset), - 0, - "Check DB Query result set" - ) + len(qresultset), + 0, + "Check DB Query result set" + ) qresult = str(qresultset) # Check if NET.IPASSIGN, NET.IPRELEASE events present in usage_event # table self.assertEqual( - qresult.count('NET.IPASSIGN') > 0, - True, - "Check NET.IPASSIGN event in events table" - ) + qresult.count('NET.IPASSIGN') > 0, + True, + "Check NET.IPASSIGN event in events table" + ) self.assertEqual( - qresult.count('NET.IPRELEASE') > 0, - True, - "Check NET.IPRELEASE in events table" - ) + qresult.count('NET.IPRELEASE') > 0, + True, + "Check NET.IPRELEASE in events table" + ) return @@ -477,50 +493,50 @@ class TestVolumeUsage(cloudstackTestCase): cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.disk_offering = DiskOffering.create( - cls.api_client, - cls.services["disk_offering"] - ) + cls.api_client, + cls.services["disk_offering"] + ) template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) + cls.api_client, + cls.zone.id, + cls.services["ostype"] + ) cls.services["server"]["zoneid"] = cls.zone.id cls.services["server"]["diskoffering"] = cls.disk_offering.id cls.services["template"] = template.id # Create Account, VMs etc cls.account = Account.create( - cls.api_client, - cls.services["account"], - domainid=cls.domain.id - ) + cls.api_client, + cls.services["account"], + domainid=cls.domain.id + ) cls.services["account"] = cls.account.name cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] - ) + cls.api_client, + cls.services["service_offering"] + ) cls.virtual_machine = VirtualMachine.create( - cls.api_client, - cls.services["server"], - templateid=template.id, - accountid=cls.account.name, - domainid=cls.account.domainid, - serviceofferingid=cls.service_offering.id - ) + cls.api_client, + cls.services["server"], + templateid=template.id, + accountid=cls.account.name, + domainid=cls.account.domainid, + serviceofferingid=cls.service_offering.id + ) cls._cleanup = [ - cls.service_offering, - cls.disk_offering, - cls.account, - ] + cls.service_offering, + cls.disk_offering, + cls.account, + ] return @classmethod def tearDownClass(cls): try: - #Cleanup resources used + # Cleanup resources used cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -534,13 +550,21 @@ class TestVolumeUsage(cloudstackTestCase): def tearDown(self): try: - #Clean up, terminate the created instance, volumes + # Clean up, terminate the created instance, volumes cleanup_resources(self.apiclient, self.cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) return - @attr(tags=["advanced", "basic", "sg", "eip", "advancedns", "simulator"], required_hardware="false") + @attr( + tags=[ + "advanced", + "basic", + "sg", + "eip", + "advancedns", + "simulator"], + required_hardware="false") def test_01_volume_usage(self): """Test Create/delete a volume and verify correct usage is recorded """ @@ -560,22 +584,22 @@ class TestVolumeUsage(cloudstackTestCase): self.fail("Failed to stop instance: %s" % e) volume_response = Volume.list( - self.apiclient, - virtualmachineid=self.virtual_machine.id, - type='DATADISK', - listall=True) + self.apiclient, + virtualmachineid=self.virtual_machine.id, + type='DATADISK', + listall=True) self.assertEqual( - isinstance(volume_response, list), - True, - "Check for valid list volumes response" - ) + isinstance(volume_response, list), + True, + "Check for valid list volumes response" + ) data_volume = volume_response[0] # Detach data Disk self.debug("Detaching volume ID: %s VM with ID: %s" % ( - data_volume.id, - self.virtual_machine.id - )) + data_volume.id, + self.virtual_machine.id + )) self.virtual_machine.detach_volume(self.apiclient, data_volume) # Delete Data disk @@ -585,60 +609,60 @@ class TestVolumeUsage(cloudstackTestCase): self.apiclient.deleteVolume(cmd) # Fetch account ID from account_uuid - self.debug("select id from account where uuid = '%s';" \ - % self.account.id) + self.debug("select id from account where uuid = '%s';" + % self.account.id) qresultset = self.dbclient.execute( - "select id from account where uuid = '%s';" \ - % self.account.id - ) + "select id from account where uuid = '%s';" + % self.account.id + ) self.assertEqual( - isinstance(qresultset, list), - True, - "Check DB query result set for valid data" - ) + isinstance(qresultset, list), + True, + "Check DB query result set for valid data" + ) self.assertNotEqual( - len(qresultset), - 0, - "Check DB Query result set" - ) + len(qresultset), + 0, + "Check DB Query result set" + ) qresult = qresultset[0] account_id = qresult[0] - self.debug("select type from usage_event where account_id = '%s';" \ - % account_id) + self.debug("select type from usage_event where account_id = '%s';" + % account_id) qresultset = self.dbclient.execute( - "select type from usage_event where account_id = '%s';" \ - % account_id - ) + "select type from usage_event where account_id = '%s';" + % account_id + ) self.assertNotEqual( - len(qresultset), - 0, - "Check DB Query result set" - ) + len(qresultset), + 0, + "Check DB Query result set" + ) self.assertEqual( - isinstance(qresultset, list), - True, - "Check DB query result set for valid data" - ) + isinstance(qresultset, list), + True, + "Check DB query result set for valid data" + ) qresult = str(qresultset) self.debug("Query result: %s" % qresult) # Check VOLUME.CREATE, VOLUME.DESTROY events in cloud.usage_event table self.assertEqual( - qresult.count('VOLUME.CREATE'), - 2, - "Check VOLUME.CREATE event in events table" - ) + qresult.count('VOLUME.CREATE'), + 2, + "Check VOLUME.CREATE event in events table" + ) self.assertEqual( - qresult.count('VOLUME.DELETE'), - 1, - "Check VOLUME.DELETE in events table" - ) + qresult.count('VOLUME.DELETE'), + 1, + "Check VOLUME.DELETE in events table" + ) return @@ -656,48 +680,48 @@ class TestTemplateUsage(cloudstackTestCase): cls.services['mode'] = cls.zone.networktype cls.services["server"]["zoneid"] = cls.zone.id template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) + cls.api_client, + cls.zone.id, + cls.services["ostype"] + ) cls.services["server"]["zoneid"] = cls.zone.id cls._cleanup = [] try: cls.account = Account.create( - cls.api_client, - cls.services["account"], - domainid=cls.domain.id - ) + cls.api_client, + cls.services["account"], + domainid=cls.domain.id + ) cls._cleanup.append(cls.account) cls.userapiclient = cls.testClient.getUserApiClient( - UserName=cls.account.name, - DomainName=cls.account.domain) + UserName=cls.account.name, + DomainName=cls.account.domain) cls.services["account"] = cls.account.name cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] - ) + cls.api_client, + cls.services["service_offering"] + ) cls._cleanup.append(cls.service_offering) - #create virtual machine + # create virtual machine cls.virtual_machine = VirtualMachine.create( - cls.api_client, - cls.services["server"], - templateid=template.id, - accountid=cls.account.name, - domainid=cls.account.domainid, - serviceofferingid=cls.service_offering.id, - mode=cls.services["mode"] - ) + cls.api_client, + cls.services["server"], + templateid=template.id, + accountid=cls.account.name, + domainid=cls.account.domainid, + serviceofferingid=cls.service_offering.id, + mode=cls.services["mode"] + ) - #Stop virtual machine + # Stop virtual machine cls.virtual_machine.stop(cls.api_client) list_volume = Volume.list( - cls.api_client, - virtualmachineid=cls.virtual_machine.id, - type='ROOT', - listall=True) + cls.api_client, + virtualmachineid=cls.virtual_machine.id, + type='ROOT', + listall=True) if isinstance(list_volume, list): cls.volume = list_volume[0] else: @@ -710,7 +734,7 @@ class TestTemplateUsage(cloudstackTestCase): @classmethod def tearDownClass(cls): try: - #Cleanup resources used + # Cleanup resources used cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -724,13 +748,20 @@ class TestTemplateUsage(cloudstackTestCase): def tearDown(self): try: - #Clean up, terminate the created instance, templates + # Clean up, terminate the created instance, templates cleanup_resources(self.apiclient, self.cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) return - @attr(tags=["advanced", "basic", "sg", "eip", "advancedns"], required_hardware="false") + @attr( + tags=[ + "advanced", + "basic", + "sg", + "eip", + "advancedns"], + required_hardware="false") def test_01_template_usage(self): """Test Upload/ delete a template and verify correct usage is generated for the template uploaded @@ -743,75 +774,75 @@ class TestTemplateUsage(cloudstackTestCase): # cloud.usage_event tables for this account # 4. Destroy the account - #Create template from Virtual machine and Volume ID + # Create template from Virtual machine and Volume ID self.template = Template.create( - self.userapiclient, - self.services["templates"], - self.volume.id, - TestTemplateUsage.account.name, - TestTemplateUsage.account.domainid - ) + self.userapiclient, + self.services["templates"], + self.volume.id, + TestTemplateUsage.account.name, + TestTemplateUsage.account.domainid + ) self.debug("Created template with ID: %s" % self.template.id) # Delete template self.template.delete(self.userapiclient) self.debug("Deleted template with ID: %s" % self.template.id) # Fetch account ID from account_uuid - self.debug("select id from account where uuid = '%s';" \ - % self.account.id) + self.debug("select id from account where uuid = '%s';" + % self.account.id) qresultset = self.dbclient.execute( - "select id from account where uuid = '%s';" \ - % self.account.id - ) + "select id from account where uuid = '%s';" + % self.account.id + ) self.assertEqual( - isinstance(qresultset, list), - True, - "Check DB query result set for valid data" - ) + isinstance(qresultset, list), + True, + "Check DB query result set for valid data" + ) self.assertNotEqual( - len(qresultset), - 0, - "Check DB Query result set" - ) + len(qresultset), + 0, + "Check DB Query result set" + ) qresult = qresultset[0] account_id = qresult[0] - self.debug("select type from usage_event where account_id = '%s';" \ - % account_id) + self.debug("select type from usage_event where account_id = '%s';" + % account_id) qresultset = self.dbclient.execute( - "select type from usage_event where account_id = '%s';" \ - % account_id - ) + "select type from usage_event where account_id = '%s';" + % account_id + ) self.assertEqual( - isinstance(qresultset, list), - True, - "Check DB query result set for valid data" - ) + isinstance(qresultset, list), + True, + "Check DB query result set for valid data" + ) self.assertNotEqual( - len(qresultset), - 0, - "Check DB Query result set" - ) + len(qresultset), + 0, + "Check DB Query result set" + ) qresult = str(qresultset) self.debug("Query result: %s" % qresult) # Check for TEMPLATE.CREATE, TEMPLATE.DELETE in cloud.usage_event table self.assertEqual( - qresult.count('TEMPLATE.CREATE'), - 1, - "Check TEMPLATE.CREATE event in events table" - ) + qresult.count('TEMPLATE.CREATE'), + 1, + "Check TEMPLATE.CREATE event in events table" + ) self.assertEqual( - qresult.count('TEMPLATE.DELETE'), - 1, - "Check TEMPLATE.DELETE in events table" - ) + qresult.count('TEMPLATE.DELETE'), + 1, + "Check TEMPLATE.DELETE in events table" + ) return @@ -831,34 +862,34 @@ class TestISOUsage(cloudstackTestCase): cls.services["iso"]["zoneid"] = cls.zone.id # Create Account, ISO image etc cls.account = Account.create( - cls.api_client, - cls.services["account"], - domainid=cls.domain.id - ) + cls.api_client, + cls.services["account"], + domainid=cls.domain.id + ) cls.services["account"] = cls.account.name cls.iso = Iso.create( - cls.api_client, - cls.services["iso"], - account=cls.account.name, - domainid=cls.account.domainid - ) + cls.api_client, + cls.services["iso"], + account=cls.account.name, + domainid=cls.account.domainid + ) try: # Wait till ISO gets downloaded cls.iso.download(cls.api_client) except Exception as e: raise Exception("%s: Failed to download ISO: %s" % ( - e, - cls.iso.id - )) + e, + cls.iso.id + )) cls._cleanup = [ - cls.account, - ] + cls.account, + ] return @classmethod def tearDownClass(cls): try: - #Cleanup resources used + # Cleanup resources used cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -872,13 +903,20 @@ class TestISOUsage(cloudstackTestCase): def tearDown(self): try: - #Clean up, terminate the created ISO images + # Clean up, terminate the created ISO images cleanup_resources(self.apiclient, self.cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) return - @attr(tags=["advanced", "basic", "sg", "eip", "advancedns"], required_hardware="false") + @attr( + tags=[ + "advanced", + "basic", + "sg", + "eip", + "advancedns"], + required_hardware="false") def test_01_ISO_usage(self): """Test Create/Delete a ISO and verify its usage is generated correctly """ @@ -895,62 +933,62 @@ class TestISOUsage(cloudstackTestCase): self.iso.delete(self.apiclient) # Fetch account ID from account_uuid - self.debug("select id from account where uuid = '%s';" \ - % self.account.id) + self.debug("select id from account where uuid = '%s';" + % self.account.id) qresultset = self.dbclient.execute( - "select id from account where uuid = '%s';" \ - % self.account.id - ) + "select id from account where uuid = '%s';" + % self.account.id + ) self.assertEqual( - isinstance(qresultset, list), - True, - "Check DB query result set for valid data" - ) + isinstance(qresultset, list), + True, + "Check DB query result set for valid data" + ) self.assertNotEqual( - len(qresultset), - 0, - "Check DB Query result set" - ) + len(qresultset), + 0, + "Check DB Query result set" + ) qresult = qresultset[0] account_id = qresult[0] - self.debug("select type from usage_event where account_id = '%s';" \ - % account_id) + self.debug("select type from usage_event where account_id = '%s';" + % account_id) qresultset = self.dbclient.execute( - "select type from usage_event where account_id = '%s';" \ - % account_id - ) + "select type from usage_event where account_id = '%s';" + % account_id + ) self.assertEqual( - isinstance(qresultset, list), - True, - "Check DB query result set for valid data" - ) + isinstance(qresultset, list), + True, + "Check DB query result set for valid data" + ) self.assertNotEqual( - len(qresultset), - 0, - "Check DB Query result set" - ) + len(qresultset), + 0, + "Check DB Query result set" + ) qresult = str(qresultset) self.debug("Query result: %s" % qresult) - imageStores = ImageStore.list(self.api_client,zoneid=self.zone.id) + imageStores = ImageStore.list(self.api_client, zoneid=self.zone.id) # Check for ISO.CREATE, ISO.DELETE events in cloud.usage_event table self.assertEqual( - qresult.count('ISO.CREATE'), - len(imageStores), - "Check ISO.CREATE event in events table" - ) + qresult.count('ISO.CREATE'), + len(imageStores), + "Check ISO.CREATE event in events table" + ) self.assertEqual( - qresult.count('ISO.DELETE'), - len(imageStores), - "Check ISO.DELETE in events table" - ) + qresult.count('ISO.DELETE'), + len(imageStores), + "Check ISO.DELETE in events table" + ) return @@ -967,52 +1005,52 @@ class TestLBRuleUsage(cloudstackTestCase): cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) + cls.api_client, + cls.zone.id, + cls.services["ostype"] + ) cls.services["server"]["zoneid"] = cls.zone.id cls.services["template"] = template.id # Create VMs, LB Rules etc cls.account = Account.create( - cls.api_client, - cls.services["account"], - domainid=cls.domain.id - ) + cls.api_client, + cls.services["account"], + domainid=cls.domain.id + ) cls.services["account"] = cls.account.name cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] - ) + cls.api_client, + cls.services["service_offering"] + ) cls.virtual_machine = VirtualMachine.create( - cls.api_client, - cls.services["server"], - templateid=template.id, - accountid=cls.account.name, - domainid=cls.account.domainid, - serviceofferingid=cls.service_offering.id - ) + cls.api_client, + cls.services["server"], + templateid=template.id, + accountid=cls.account.name, + domainid=cls.account.domainid, + serviceofferingid=cls.service_offering.id + ) cls.public_ip_1 = PublicIPAddress.create( - cls.api_client, - accountid=cls.virtual_machine.account, - zoneid=cls.virtual_machine.zoneid, - domainid=cls.virtual_machine.domainid, - services=cls.services["server"] - ) + cls.api_client, + accountid=cls.virtual_machine.account, + zoneid=cls.virtual_machine.zoneid, + domainid=cls.virtual_machine.domainid, + services=cls.services["server"] + ) cls._cleanup = [ - cls.service_offering, - cls.account, - ] + cls.service_offering, + cls.account, + ] return @classmethod def tearDownClass(cls): try: - #Cleanup resources used + # Cleanup resources used cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -1026,13 +1064,19 @@ class TestLBRuleUsage(cloudstackTestCase): def tearDown(self): try: - #Clean up, terminate the created instance, LB rules + # Clean up, terminate the created instance, LB rules cleanup_resources(self.apiclient, self.cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) return - @attr(tags=["advanced", "eip", "advancedns", "simulator"], required_hardware="false") + @attr( + tags=[ + "advanced", + "eip", + "advancedns", + "simulator"], + required_hardware="false") def test_01_lb_usage(self): """Test Create/Delete a LB rule and verify correct usage is recorded """ @@ -1046,75 +1090,75 @@ class TestLBRuleUsage(cloudstackTestCase): self.debug( "Creating load balancer rule for public IP: %s" % - self.public_ip_1.ipaddress.id) - #Create Load Balancer rule and assign VMs to rule + self.public_ip_1.ipaddress.id) + # Create Load Balancer rule and assign VMs to rule lb_rule = LoadBalancerRule.create( - self.apiclient, - self.services["lbrule"], - self.public_ip_1.ipaddress.id, - accountid=self.account.name - ) + self.apiclient, + self.services["lbrule"], + self.public_ip_1.ipaddress.id, + accountid=self.account.name + ) # Delete LB Rule self.debug("Deleting LB rule with ID: %s" % lb_rule.id) lb_rule.delete(self.apiclient) # Fetch account ID from account_uuid - self.debug("select id from account where uuid = '%s';" \ - % self.account.id) + self.debug("select id from account where uuid = '%s';" + % self.account.id) qresultset = self.dbclient.execute( - "select id from account where uuid = '%s';" \ - % self.account.id - ) + "select id from account where uuid = '%s';" + % self.account.id + ) self.assertEqual( - isinstance(qresultset, list), - True, - "Check DB query result set for valid data" - ) + isinstance(qresultset, list), + True, + "Check DB query result set for valid data" + ) self.assertNotEqual( - len(qresultset), - 0, - "Check DB Query result set" - ) + len(qresultset), + 0, + "Check DB Query result set" + ) qresult = qresultset[0] account_id = qresult[0] - self.debug("select type from usage_event where account_id = '%s';" \ - % account_id) + self.debug("select type from usage_event where account_id = '%s';" + % account_id) qresultset = self.dbclient.execute( - "select type from usage_event where account_id = '%s';" \ - % account_id - ) + "select type from usage_event where account_id = '%s';" + % account_id + ) self.assertEqual( - isinstance(qresultset, list), - True, - "Check DB query result set for valid data" - ) + isinstance(qresultset, list), + True, + "Check DB query result set for valid data" + ) self.assertNotEqual( - len(qresultset), - 0, - "Check DB Query result set" - ) + len(qresultset), + 0, + "Check DB Query result set" + ) qresult = str(qresultset) self.debug("Query result: %s" % qresult) # Check for LB.CREATE, LB.DELETE in cloud.usage_event table self.assertEqual( - qresult.count('LB.CREATE'), - 1, - "Check LB.CREATE event in events table" - ) + qresult.count('LB.CREATE'), + 1, + "Check LB.CREATE event in events table" + ) self.assertEqual( - qresult.count('LB.DELETE'), - 1, - "Check LB.DELETE in events table" - ) + qresult.count('LB.DELETE'), + 1, + "Check LB.DELETE in events table" + ) return @@ -1124,7 +1168,7 @@ class TestSnapshotUsage(cloudstackTestCase): def setUpClass(cls): cls.testClient = super(TestSnapshotUsage, cls).getClsTestClient() cls.api_client = cls.testClient.getApiClient() - + cls.hypervisor = cls.testClient.getHypervisorInfo() cls.services = Services().services # Get Zone, Domain and templates cls.domain = get_domain(cls.api_client) @@ -1132,45 +1176,45 @@ class TestSnapshotUsage(cloudstackTestCase): cls.services['mode'] = cls.zone.networktype template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) + cls.api_client, + cls.zone.id, + cls.services["ostype"] + ) cls.services["server"]["zoneid"] = cls.zone.id cls.services["template"] = template.id # Create Account, VMs etc cls.account = Account.create( - cls.api_client, - cls.services["account"], - domainid=cls.domain.id - ) + cls.api_client, + cls.services["account"], + domainid=cls.domain.id + ) cls.services["account"] = cls.account.name cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] - ) + cls.api_client, + cls.services["service_offering"] + ) cls.virtual_machine = VirtualMachine.create( - cls.api_client, - cls.services["server"], - templateid=template.id, - accountid=cls.account.name, - domainid=cls.account.domainid, - serviceofferingid=cls.service_offering.id - ) + cls.api_client, + cls.services["server"], + templateid=template.id, + accountid=cls.account.name, + domainid=cls.account.domainid, + serviceofferingid=cls.service_offering.id + ) cls._cleanup = [ - cls.service_offering, - cls.account, - ] + cls.service_offering, + cls.account, + ] return @classmethod def tearDownClass(cls): try: - #Cleanup resources used + # Cleanup resources used cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -1184,14 +1228,22 @@ class TestSnapshotUsage(cloudstackTestCase): def tearDown(self): try: - #Clean up, terminate the created instance and snapshots + # Clean up, terminate the created instance 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(tags=["advanced", "basic", "sg", "eip", "advancedns", "simulator"], required_hardware="false") + @attr(speed="slow") + @attr( + tags=[ + "advanced", + "basic", + "sg", + "eip", + "advancedns", + "simulator"], + required_hardware="false") def test_01_snapshot_usage(self): """Test Create/Delete a manual snap shot and verify correct usage is recorded @@ -1204,16 +1256,20 @@ class TestSnapshotUsage(cloudstackTestCase): # 3. Delete the account # Get the Root disk of VM + + if self.hypervisor.lower() in ['hyperv']: + self.skipTest("Snapshots feature is not supported on Hyper-V") + volumes = Volume.list( - self.apiclient, - virtualmachineid=self.virtual_machine.id, - type='ROOT', - listall=True) + self.apiclient, + virtualmachineid=self.virtual_machine.id, + type='ROOT', + listall=True) self.assertEqual( - isinstance(volumes, list), - True, - "Check if list volumes return a valid data" - ) + isinstance(volumes, list), + True, + "Check if list volumes return a valid data" + ) # Create a snapshot from the ROOTDISK self.debug("Creating snapshot from volume: %s" % volumes[0].id) @@ -1224,63 +1280,63 @@ class TestSnapshotUsage(cloudstackTestCase): snapshot.delete(self.apiclient) # Fetch account ID from account_uuid - self.debug("select id from account where uuid = '%s';" \ - % self.account.id) + self.debug("select id from account where uuid = '%s';" + % self.account.id) qresultset = self.dbclient.execute( - "select id from account where uuid = '%s';" \ - % self.account.id - ) + "select id from account where uuid = '%s';" + % self.account.id + ) self.assertEqual( - isinstance(qresultset, list), - True, - "Check DB query result set for valid data" - ) + isinstance(qresultset, list), + True, + "Check DB query result set for valid data" + ) self.assertNotEqual( - len(qresultset), - 0, - "Check DB Query result set" - ) + len(qresultset), + 0, + "Check DB Query result set" + ) qresult = qresultset[0] account_id = qresult[0] - self.debug("select type from usage_event where account_id = '%s';" \ - % account_id) + self.debug("select type from usage_event where account_id = '%s';" + % account_id) qresultset = self.dbclient.execute( - "select type from usage_event where account_id = '%s';" \ - % account_id - ) + "select type from usage_event where account_id = '%s';" + % account_id + ) self.assertEqual( - isinstance(qresultset, list), - True, - "Check if database query returns a valid data" - ) + isinstance(qresultset, list), + True, + "Check if database query returns a valid data" + ) self.assertNotEqual( - len(qresultset), - 0, - "Check DB Query result set" - ) + len(qresultset), + 0, + "Check DB Query result set" + ) qresult = str(qresultset) self.debug("Query Result: %s" % qresult) - # Check for SNAPSHOT.CREATE, SNAPSHOT.DELETE events in cloud.usage_event - # table + # Check for SNAPSHOT.CREATE, SNAPSHOT.DELETE events in + # cloud.usage_event table self.assertEqual( - qresult.count('SNAPSHOT.CREATE'), - 1, - "Check SNAPSHOT.CREATE event in events table" - ) + qresult.count('SNAPSHOT.CREATE'), + 1, + "Check SNAPSHOT.CREATE event in events table" + ) self.assertEqual( - qresult.count('SNAPSHOT.DELETE'), - 1, - "Check SNAPSHOT.DELETE in events table" - ) + qresult.count('SNAPSHOT.DELETE'), + 1, + "Check SNAPSHOT.DELETE in events table" + ) return @@ -1297,52 +1353,52 @@ class TestNatRuleUsage(cloudstackTestCase): cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) + cls.api_client, + cls.zone.id, + cls.services["ostype"] + ) cls.services["server"]["zoneid"] = cls.zone.id cls.services["template"] = template.id # Create VMs, NAT Rules etc cls.account = Account.create( - cls.api_client, - cls.services["account"], - domainid=cls.domain.id - ) + cls.api_client, + cls.services["account"], + domainid=cls.domain.id + ) cls.services["account"] = cls.account.name cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] - ) + cls.api_client, + cls.services["service_offering"] + ) cls.virtual_machine = VirtualMachine.create( - cls.api_client, - cls.services["server"], - templateid=template.id, - accountid=cls.account.name, - domainid=cls.account.domainid, - serviceofferingid=cls.service_offering.id - ) + cls.api_client, + cls.services["server"], + templateid=template.id, + accountid=cls.account.name, + domainid=cls.account.domainid, + serviceofferingid=cls.service_offering.id + ) cls.public_ip_1 = PublicIPAddress.create( - cls.api_client, - accountid=cls.virtual_machine.account, - zoneid=cls.virtual_machine.zoneid, - domainid=cls.virtual_machine.domainid, - services=cls.services["server"] - ) + cls.api_client, + accountid=cls.virtual_machine.account, + zoneid=cls.virtual_machine.zoneid, + domainid=cls.virtual_machine.domainid, + services=cls.services["server"] + ) cls._cleanup = [ - cls.service_offering, - cls.account, - ] + cls.service_offering, + cls.account, + ] return @classmethod def tearDownClass(cls): try: - #Cleanup resources used + # Cleanup resources used cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -1356,13 +1412,18 @@ class TestNatRuleUsage(cloudstackTestCase): def tearDown(self): try: - #Clean up, terminate the created instance, NAT rules + # Clean up, terminate the created instance, NAT rules cleanup_resources(self.apiclient, self.cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) return - @attr(tags=["advanced", "advancedns", "simulator"], required_hardware="false") + @attr( + tags=[ + "advanced", + "advancedns", + "simulator"], + required_hardware="false") def test_01_nat_usage(self): """Test Create/Delete a PF rule and verify correct usage is recorded """ @@ -1376,75 +1437,75 @@ class TestNatRuleUsage(cloudstackTestCase): # 4. Delete this account. self.debug("Creating NAT rule with public IP: %s" % - self.public_ip_1.ipaddress.id) - #Create NAT rule + self.public_ip_1.ipaddress.id) + # Create NAT rule nat_rule = NATRule.create( - self.apiclient, - self.virtual_machine, - self.services["natrule"], - self.public_ip_1.ipaddress.id - ) + self.apiclient, + self.virtual_machine, + self.services["natrule"], + self.public_ip_1.ipaddress.id + ) # Delete NAT Rule self.debug("Deleting NAT rule: %s" % nat_rule.id) nat_rule.delete(self.apiclient) # Fetch account ID from account_uuid - self.debug("select id from account where uuid = '%s';" \ - % self.account.id) + self.debug("select id from account where uuid = '%s';" + % self.account.id) qresultset = self.dbclient.execute( - "select id from account where uuid = '%s';" \ - % self.account.id - ) + "select id from account where uuid = '%s';" + % self.account.id + ) self.assertEqual( - isinstance(qresultset, list), - True, - "Check DB query result set for valid data" - ) + isinstance(qresultset, list), + True, + "Check DB query result set for valid data" + ) self.assertNotEqual( - len(qresultset), - 0, - "Check DB Query result set" - ) + len(qresultset), + 0, + "Check DB Query result set" + ) qresult = qresultset[0] account_id = qresult[0] - self.debug("select type from usage_event where account_id = '%s';" \ - % account_id) + self.debug("select type from usage_event where account_id = '%s';" + % account_id) qresultset = self.dbclient.execute( - "select type from usage_event where account_id = '%s';" \ - % account_id - ) + "select type from usage_event where account_id = '%s';" + % account_id + ) self.assertEqual( - isinstance(qresultset, list), - True, - "Check DB query result set for valid data" - ) + isinstance(qresultset, list), + True, + "Check DB query result set for valid data" + ) self.assertNotEqual( - len(qresultset), - 0, - "Check DB Query result set" - ) + len(qresultset), + 0, + "Check DB Query result set" + ) qresult = str(qresultset) self.debug("Query result: %s" % qresult) # Check for NET.RULEADD, NET.RULEDELETE in cloud.usage_event table self.assertEqual( - qresult.count('NET.RULEADD'), - 1, - "Check NET.RULEADD event in events table" - ) + qresult.count('NET.RULEADD'), + 1, + "Check NET.RULEADD event in events table" + ) self.assertEqual( - qresult.count('NET.RULEDELETE'), - 1, - "Check NET.RULEDELETE in events table" - ) + qresult.count('NET.RULEDELETE'), + 1, + "Check NET.RULEDELETE in events table" + ) return @@ -1461,10 +1522,10 @@ class TestVpnUsage(cloudstackTestCase): cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) + cls.api_client, + cls.zone.id, + cls.services["ostype"] + ) cls.services["server"]["zoneid"] = cls.zone.id cls.services["template"] = template.id @@ -1472,41 +1533,41 @@ class TestVpnUsage(cloudstackTestCase): # Create Service offerings, VMs etc cls.account = Account.create( - cls.api_client, - cls.services["account"], - admin=True, - domainid=cls.domain.id - ) + cls.api_client, + cls.services["account"], + admin=True, + domainid=cls.domain.id + ) cls._cleanup.append(cls.account) cls.services["account"] = cls.account.name cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] - ) + cls.api_client, + cls.services["service_offering"] + ) cls._cleanup.append(cls.service_offering) cls.virtual_machine = VirtualMachine.create( - cls.api_client, - cls.services["server"], - templateid=template.id, - accountid=cls.account.name, - domainid=cls.account.domainid, - serviceofferingid=cls.service_offering.id - ) + cls.api_client, + cls.services["server"], + templateid=template.id, + accountid=cls.account.name, + domainid=cls.account.domainid, + serviceofferingid=cls.service_offering.id + ) cls.public_ip = PublicIPAddress.create( - cls.api_client, - accountid=cls.virtual_machine.account, - zoneid=cls.virtual_machine.zoneid, - domainid=cls.virtual_machine.domainid, - services=cls.services["server"] - ) + cls.api_client, + accountid=cls.virtual_machine.account, + zoneid=cls.virtual_machine.zoneid, + domainid=cls.virtual_machine.domainid, + services=cls.services["server"] + ) return @classmethod def tearDownClass(cls): try: - #Cleanup resources used + # Cleanup resources used cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -1520,7 +1581,7 @@ class TestVpnUsage(cloudstackTestCase): def tearDown(self): try: - #Clean up, terminate the created instance, VPN users + # Clean up, terminate the created instance, VPN users cleanup_resources(self.apiclient, self.cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -1539,25 +1600,25 @@ class TestVpnUsage(cloudstackTestCase): # 4. Delete this account. self.debug("Created VPN with public IP: %s" % - self.public_ip.ipaddress.id) - #Assign VPN to Public IP + self.public_ip.ipaddress.id) + # Assign VPN to Public IP vpn = Vpn.create( - self.apiclient, - self.public_ip.ipaddress.id, - account=self.account.name, - domainid=self.account.domainid - ) + self.apiclient, + self.public_ip.ipaddress.id, + account=self.account.name, + domainid=self.account.domainid + ) self.debug("Created VPN user for account: %s" % - self.account.name) + self.account.name) vpnuser = VpnUser.create( - self.apiclient, - self.services["vpn_user"]["username"], - self.services["vpn_user"]["password"], - account=self.account.name, - domainid=self.account.domainid - ) + self.apiclient, + self.services["vpn_user"]["username"], + self.services["vpn_user"]["password"], + account=self.account.name, + domainid=self.account.domainid + ) # Remove VPN user self.debug("Deleting VPN user: %s" % vpnuser.id) @@ -1568,59 +1629,59 @@ class TestVpnUsage(cloudstackTestCase): vpn.delete(self.apiclient) # Fetch account ID from account_uuid - self.debug("select id from account where uuid = '%s';" \ - % self.account.id) + self.debug("select id from account where uuid = '%s';" + % self.account.id) qresultset = self.dbclient.execute( - "select id from account where uuid = '%s';" \ - % self.account.id - ) + "select id from account where uuid = '%s';" + % self.account.id + ) self.assertEqual( - isinstance(qresultset, list), - True, - "Check DB query result set for valid data" - ) + isinstance(qresultset, list), + True, + "Check DB query result set for valid data" + ) self.assertNotEqual( - len(qresultset), - 0, - "Check DB Query result set" - ) + len(qresultset), + 0, + "Check DB Query result set" + ) qresult = qresultset[0] account_id = qresult[0] - self.debug("select type from usage_event where account_id = '%s';" \ - % account_id) + self.debug("select type from usage_event where account_id = '%s';" + % account_id) qresultset = self.dbclient.execute( - "select type from usage_event where account_id = '%s';" \ - % account_id - ) + "select type from usage_event where account_id = '%s';" + % account_id + ) self.assertEqual( - isinstance(qresultset, list), - True, - "Check DB query result set for valid data" - ) + isinstance(qresultset, list), + True, + "Check DB query result set for valid data" + ) self.assertNotEqual( - len(qresultset), - 0, - "Check DB Query result set" - ) + len(qresultset), + 0, + "Check DB Query result set" + ) qresult = str(qresultset) self.debug("Query result: %s" % qresult) # Check for VPN user related events self.assertEqual( - qresult.count('VPN.USER.ADD'), - 1, - "Check VPN.USER.ADD event in events table" - ) + qresult.count('VPN.USER.ADD'), + 1, + "Check VPN.USER.ADD event in events table" + ) self.assertEqual( - qresult.count('VPN.USER.ADD'), - 1, - "Check VPN.USER.ADD in events table" - ) + qresult.count('VPN.USER.ADD'), + 1, + "Check VPN.USER.ADD in events table" + ) return