diff --git a/test/integration/component/test_escalations_instances.py b/test/integration/component/test_escalations_instances.py index 1aaa688fe0a..7e4cfe632cd 100644 --- a/test/integration/component/test_escalations_instances.py +++ b/test/integration/component/test_escalations_instances.py @@ -16,17 +16,28 @@ # under the License. # Import Local Modules -from marvin.cloudstackTestCase import * -from marvin.cloudstackException import * -from marvin.cloudstackAPI import * -from marvin.sshClient import SshClient -from marvin.lib.utils import * -from marvin.lib.base import * -from marvin.lib.common import * +from marvin.cloudstackTestCase import cloudstackTestCase, unittest +from marvin.lib.utils import cleanup_resources, validateList +from marvin.lib.base import (Account, + ServiceOffering, + NetworkOffering, + Network, + VirtualMachine, + SecurityGroup, + DiskOffering, + Resources, + Iso, + Configurations, + SSHKeyPair, + Volume, + VmSnapshot, + Zone) +from marvin.lib.common import (get_zone, + get_template, + get_domain) from marvin.codes import PASS from nose.plugins.attrib import attr -from time import sleep -# from ctypes.wintypes import BOOLEAN + class TestListInstances(cloudstackTestCase): @@ -40,19 +51,23 @@ class TestListInstances(cloudstackTestCase): cls.hypervisor = cls.testClient.getHypervisorInfo() # Get Domain, Zone, Template cls.domain = get_domain(cls.api_client) - cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) + cls.zone = get_zone( + cls.api_client, + cls.testClient.getZoneForTests()) cls.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) + cls.api_client, + cls.zone.id, + cls.services["ostype"] + ) if cls.zone.localstorageenabled: cls.storagetype = 'local' - cls.services["service_offerings"]["tiny"]["storagetype"] = 'local' + cls.services["service_offerings"][ + "tiny"]["storagetype"] = 'local' cls.services["disk_offering"]["storagetype"] = 'local' else: cls.storagetype = 'shared' - cls.services["service_offerings"]["tiny"]["storagetype"] = 'shared' + cls.services["service_offerings"][ + "tiny"]["storagetype"] = 'shared' cls.services["disk_offering"]["storagetype"] = 'shared' cls.services['mode'] = cls.zone.networktype @@ -62,32 +77,13 @@ class TestListInstances(cloudstackTestCase): cls.services["custom_volume"]["zoneid"] = cls.zone.id # Creating Disk offering, Service Offering and Account cls.disk_offering = DiskOffering.create( - cls.api_client, - cls.services["disk_offering"] - ) + cls.api_client, + cls.services["disk_offering"] + ) cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offerings"]["tiny"] - ) - cls.account = Account.create( - cls.api_client, - cls.services["account"], - domainid=cls.domain.id - ) - # Getting authentication for user in newly created Account - cls.user = cls.account.user[0] - cls.userapiclient = cls.testClient.getUserApiClient(cls.user.username, cls.domain.name) - # Updating resource Limits - for i in range(0, 12): - Resources.updateLimit( - cls.api_client, - account=cls.account.name, - domainid=cls.domain.id, - max=-1, - resourcetype=i - ) - - cls._cleanup.append(cls.account) + cls.api_client, + cls.services["service_offerings"]["tiny"] + ) cls._cleanup.append(cls.service_offering) cls._cleanup.append(cls.disk_offering) except Exception as e: @@ -98,7 +94,27 @@ class TestListInstances(cloudstackTestCase): def setUp(self): self.apiClient = self.testClient.getApiClient() - self.cleanup = [] + self.account = Account.create( + self.apiClient, + self.services["account"], + domainid=self.domain.id + ) + # Getting authentication for user in newly created Account + self.user = self.account.user[0] + self.userapiclient = self.testClient.getUserApiClient( + self.user.username, + self.domain.name) + # Updating resource Limits + for i in range(0, 12): + Resources.updateLimit( + self.api_client, + account=self.account.name, + domainid=self.domain.id, + max=-1, + resourcetype=i + ) + + self.cleanup = [self.account, ] def tearDown(self): # Clean up, terminate the created resources @@ -115,14 +131,15 @@ class TestListInstances(cloudstackTestCase): return def __verify_values(self, expected_vals, actual_vals): - """ + """ @Desc: Function to verify expected and actual values @Steps: Step1: Initializing return flag to True - Step1: Verifying length of expected and actual dictionaries is matching. + Step1: Verifying length of expected and actual dictionaries is matching If not matching returning false Step2: Listing all the keys from expected dictionary - Step3: Looping through each key from step2 and verifying expected and actual dictionaries have same value + Step3: Looping through each key from step2 and verifying expected and + actual dictionaries have same value If not making return flag to False Step4: returning the return flag after all the values are verified """ @@ -139,24 +156,26 @@ class TestListInstances(cloudstackTestCase): return_flag = return_flag and True else: return_flag = return_flag and False - self.debug("expected Value: %s, is not matching with actual value: %s" % ( - exp_val, - act_val - )) + self.debug( + "expected Value: %s, is not matching with\ + actual value: %s" % + (exp_val, act_val)) return return_flag @attr(tags=["advanced", "basic"], required_hardware="false") def test_01_list_instances_pagination(self): - """ + """ @Desc: Test List Instances pagination @Steps: Step1: Listing all the Instances for a user Step2: Verifying listed Instances for account created at class level - Step3: If number of volumes is less than (page size + 1), then creating them + Step3: If number of volumes is less than + (page size + 1), then creating them Step4: Listing all the volumes again after creation of volumes Step5: Verifying the length of the volumes is (page size + 1) Step6: Listing all the volumes in page1 - Step7: Verifying that the length of the volumes in page 1 is (page size) + Step7: Verifying that the length of the volumes in page 1 is + (page size) Step8: Listing all the volumes in page2 Step9: Verifying that the length of the volumes in page 2 is 1 Step10: Deleting the volume present in page 2 @@ -164,124 +183,128 @@ class TestListInstances(cloudstackTestCase): Step12: Verifying that there are no volumes present in page 2 """ # Listing all the instances for a user - list_instances_before = VirtualMachine.list(self.userapiclient, listall=self.services["listall"]) + list_instances_before = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"]) # Verifying listed instances for account created at class level self.assertIsNone( - list_instances_before, - "Virtual Machine already exists for newly created user" - ) - # If number of instances are less than (pagesize + 1), then creating them + list_instances_before, + "Virtual Machine already exists for newly created user" + ) + # If number of instances are less than (pagesize + 1), then creating + # them for i in range(0, (self.services["pagesize"] + 1)): vm_created = VirtualMachine.create( - self.userapiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - ) + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) self.assertIsNotNone( - vm_created, - "VM creation failed" - ) - if(i < (self.services["pagesize"])): - self.cleanup.append(vm_created) + vm_created, + "VM creation failed" + ) self.assertEqual( - self.services["virtual_machine"]["displayname"], - vm_created.displayname, - "Newly created VM name and the test data VM name are not matching" - ) + self.services["virtual_machine"]["displayname"], + vm_created.displayname, + "Newly created VM name and the test data VM name\ + are not matching") # Listing all the instances again after creating VM's - list_instances_after = VirtualMachine.list(self.userapiclient, listall=self.services["listall"]) + list_instances_after = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"]) status = validateList(list_instances_after) self.assertEquals( - PASS, - status[0], - "Listing of instances after creation failed" - ) + PASS, + status[0], + "Listing of instances after creation failed" + ) # Verifying the length of the instances is (page size + 1) self.assertEqual( - len(list_instances_after), - (self.services["pagesize"] + 1), - "Number of instances created is not matching as expected" - ) + len(list_instances_after), + (self.services["pagesize"] + 1), + "Number of instances created is not matching as expected" + ) # Listing all the volumes in page1 list_instances_page1 = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - page=1, - pagesize=self.services["pagesize"], - domainid=self.account.domainid - ) + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid + ) status = validateList(list_instances_page1) self.assertEquals( - PASS, - status[0], - "Listing of instances in page1 failed" - ) + PASS, + status[0], + "Listing of instances in page1 failed" + ) # Verifying that the length of the instances in page 1 is (page size) self.assertEqual( - self.services["pagesize"], - len(list_instances_page1), - "List VM response is not matching with the page size length for page 1" - ) + self.services["pagesize"], + len(list_instances_page1), + "List VM response is not matching with the page size\ + length for page 1") # Listing all the VM's in page2 list_instances_page2 = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - page=2, - pagesize=self.services["pagesize"], - domainid=self.account.domainid - ) + self.userapiclient, + listall=self.services["listall"], + page=2, + pagesize=self.services["pagesize"], + domainid=self.account.domainid + ) status = validateList(list_instances_page2) self.assertEquals( - PASS, - status[0], - "Listing of instances in page2 failed" - ) + PASS, + status[0], + "Listing of instances in page2 failed" + ) # Verifying that the length of the VM's in page 2 is 1 self.assertEqual( - 1, - len(list_instances_page2), - "List VM response is not matching with the page size length for page 2" - ) + 1, + len(list_instances_page2), + "List VM response is not matching with the\ + page size length for page 2" + ) instance_page2 = list_instances_page2[0] # Verifying that the VM on page 2 is not present in page1 for i in range(0, len(list_instances_page1)): instance_page1 = list_instances_page1[i] self.assertNotEquals( - instance_page2.id, - instance_page1.id, - "VM listed in page 2 is also listed in page 1" - ) + instance_page2.id, + instance_page1.id, + "VM listed in page 2 is also listed in page 1" + ) # Deleting a single VM - VirtualMachine.delete(vm_created, self.userapiclient, expunge=True) + VirtualMachine.delete(vm_created, self.apiClient, expunge=True) # Listing the VM's in page 2 list_instance_response = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - page=2, - pagesize=self.services["pagesize"], - domainid=self.account.domainid - ) + self.userapiclient, + listall=self.services["listall"], + page=2, + pagesize=self.services["pagesize"], + domainid=self.account.domainid + ) # verifying that VM does not exists on page 2 self.assertEqual( - list_instance_response, - None, - "VM was not deleted" - ) + list_instance_response, + None, + "VM was not deleted" + ) return @attr(tags=["advanced", "basic"], required_hardware="false") def test_02_list_Running_vm(self): - """ + """ @Desc: Test List Running VM's @Steps: Step1: Listing all the Running VMs for a user @@ -289,90 +312,90 @@ class TestListInstances(cloudstackTestCase): Step3: Deploying a VM Step4: Listing all the Running VMs for a user again Step5: Verifying that the size of the list is increased by 1 - Step6: Verifying that the details of the Running VM listed are same as the VM deployed in Step3 + Step6: Verifying that the details of the Running VM listed are + same as the VM deployed in Step3 """ # Listing all the Running VM's for a User list_running_vms_before = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - page=1, - pagesize=self.services["pagesize"], - domainid=self.account.domainid, - state="Running" - ) + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + state="Running" + ) self.assertIsNone( - list_running_vms_before, - "Virtual Machine already exists for newly created user" - ) + list_running_vms_before, + "Virtual Machine already exists for newly created user" + ) # Deploying a VM vm_created = VirtualMachine.create( - self.userapiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - ) + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) self.assertIsNotNone( - vm_created, - "VM creation failed" - ) - self.cleanup.append(vm_created) + vm_created, + "VM creation failed" + ) # Listing all the Running VM's for a User list_running_vms_after = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - page=1, - pagesize=self.services["pagesize"], - domainid=self.account.domainid, - state="Running" - ) + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + state="Running" + ) status = validateList(list_running_vms_after) self.assertEquals( - PASS, - status[0], - "Newly created VM is not in Running state" - ) + PASS, + status[0], + "Newly created VM is not in Running state" + ) # Verifying list size is 1 self.assertEquals( - 1, - len(list_running_vms_after), - "Running VM list count is not matching" - ) + 1, + len(list_running_vms_after), + "Running VM list count is not matching" + ) running_vm = list_running_vms_after[0] # Creating expected and actual values dictionaries expected_dict = { - "id":vm_created.id, - "name":vm_created.name, - "displayname":vm_created.displayname, - "state":"Running", - "zoneid":vm_created.zoneid, - "account":vm_created.account, - "template":vm_created.templateid - } + "id": vm_created.id, + "name": vm_created.name, + "displayname": vm_created.displayname, + "state": "Running", + "zoneid": vm_created.zoneid, + "account": vm_created.account, + "template": vm_created.templateid + } actual_dict = { - "id":running_vm.id, - "name":running_vm.name, - "displayname":running_vm.displayname, - "state":running_vm.state, - "zoneid":running_vm.zoneid, - "account":running_vm.account, - "template":running_vm.templateid - } + "id": running_vm.id, + "name": running_vm.name, + "displayname": running_vm.displayname, + "state": running_vm.state, + "zoneid": running_vm.zoneid, + "account": running_vm.account, + "template": running_vm.templateid + } running_vm_status = self.__verify_values( - expected_dict, - actual_dict - ) + expected_dict, + actual_dict + ) self.assertEqual( - True, - running_vm_status, - "Listed Running VM details are not as expected" - ) + True, + running_vm_status, + "Listed Running VM details are not as expected" + ) return @attr(tags=["advanced", "basic"], required_hardware="false") def test_03_list_Stopped_vm(self): - """ + """ @Desc: Test List Stopped VM's @Steps: Step1: Listing all the Stopped VMs for a user @@ -381,86 +404,86 @@ class TestListInstances(cloudstackTestCase): Step4: Stopping the VM deployed in step3 Step5: Listing all the Stopped VMs for a user again Step6: Verifying that the size of the list is increased by 1 - Step7: Verifying that the details of the Stopped VM listed are same as the VM stopped in Step4 + Step7: Verifying that the details of the Stopped VM listed are + same as the VM stopped in Step4 """ # Listing all the Stopped VM's for a User list_stopped_vms_before = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - page=1, - pagesize=self.services["pagesize"], - domainid=self.account.domainid, - state="Stopped" - ) + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + state="Stopped" + ) self.assertIsNone( - list_stopped_vms_before, - "Virtual Machine already exists for newly created user" - ) + list_stopped_vms_before, + "Virtual Machine already exists for newly created user" + ) # Deploying a VM vm_created = VirtualMachine.create( - self.userapiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - ) + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) self.assertIsNotNone( - vm_created, - "VM creation failed" - ) - self.cleanup.append(vm_created) + vm_created, + "VM creation failed" + ) # Stopping the VM VirtualMachine.stop(vm_created, self.userapiclient) # Listing all the Stopped VM's for a User list_stopped_vms_after = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - page=1, - pagesize=self.services["pagesize"], - domainid=self.account.domainid, - state="Stopped" - ) + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + state="Stopped" + ) status = validateList(list_stopped_vms_after) self.assertEquals( - PASS, - status[0], - "Stopped VM is not in Stopped state" - ) + PASS, + status[0], + "Stopped VM is not in Stopped state" + ) # Verifying list size is 1 self.assertEquals( - 1, - len(list_stopped_vms_after), - "Stopped VM list count is not matching" - ) + 1, + len(list_stopped_vms_after), + "Stopped VM list count is not matching" + ) stopped_vm = list_stopped_vms_after[0] # Creating expected and actual values dictionaries expected_dict = { - "id":vm_created.id, - "name":vm_created.name, - "displayname":vm_created.displayname, - "state":"Stopped", - "zoneid":vm_created.zoneid, - "account":vm_created.account, - "template":vm_created.templateid - } + "id": vm_created.id, + "name": vm_created.name, + "displayname": vm_created.displayname, + "state": "Stopped", + "zoneid": vm_created.zoneid, + "account": vm_created.account, + "template": vm_created.templateid + } actual_dict = { - "id":stopped_vm.id, - "name":stopped_vm.name, - "displayname":stopped_vm.displayname, - "state":stopped_vm.state, - "zoneid":stopped_vm.zoneid, - "account":stopped_vm.account, - "template":stopped_vm.templateid - } + "id": stopped_vm.id, + "name": stopped_vm.name, + "displayname": stopped_vm.displayname, + "state": stopped_vm.state, + "zoneid": stopped_vm.zoneid, + "account": stopped_vm.account, + "template": stopped_vm.templateid + } stopped_vm_status = self.__verify_values( - expected_dict, - actual_dict - ) + expected_dict, + actual_dict + ) self.assertEqual( - True, - stopped_vm_status, - "Listed Stopped VM details are not as expected" - ) + True, + stopped_vm_status, + "Listed Stopped VM details are not as expected" + ) return @attr(tags=["advanced", "basic"], required_hardware="false") @@ -476,99 +499,100 @@ class TestListInstances(cloudstackTestCase): Step6: Verifying that destroyed VM is not listed for User Step7: Listing all the destroyed VMs as admin Step8: Verifying that the size of the list is 1 - Step9: Verifying that the details of the Destroyed VM listed are same as the VM destroyed in Step4 + Step9: Verifying that the details of the Destroyed VM listed + are same as the VM destroyed in Step4 """ # Listing all the Destroyed VM's for a User list_destroyed_vms_before = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - page=1, - pagesize=self.services["pagesize"], - domainid=self.account.domainid, - state="Destroyed" - ) + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + state="Destroyed" + ) self.assertIsNone( - list_destroyed_vms_before, - "Virtual Machine in Destroyed state already exists for newly created user" - ) + list_destroyed_vms_before, + "Virtual Machine in Destroyed state already exists\ + for newly created user") # Deploying a VM vm_created = VirtualMachine.create( - self.userapiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - ) + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) self.assertIsNotNone( - vm_created, - "VM creation failed" - ) + vm_created, + "VM creation failed" + ) # Destroying the VM VirtualMachine.delete(vm_created, self.userapiclient, expunge=False) # Listing all the Destroyed VM's for a User list_destroyed_vms_after = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - page=1, - pagesize=self.services["pagesize"], - domainid=self.account.domainid, - state="Destroyed" - ) + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + state="Destroyed" + ) self.assertIsNone( - list_destroyed_vms_after, - "Destroyed VM is not in destroyed state" - ) + list_destroyed_vms_after, + "Destroyed VM is not in destroyed state" + ) # Listing destroyed VMs as admin user list_destroyed_vms_admin = VirtualMachine.list( - self.apiClient, - listall=self.services["listall"], - page=1, - pagesize=self.services["pagesize"], - domainid=self.account.domainid, - state="Destroyed", - id=vm_created.id - ) + self.apiClient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + state="Destroyed", + id=vm_created.id + ) status = validateList(list_destroyed_vms_admin) self.assertEquals( - PASS, - status[0], - "Destroyed VM is not in Destroyed state" - ) + PASS, + status[0], + "Destroyed VM is not in Destroyed state" + ) # Verifying that the length of the destroyed VMs list should be 1 self.assertEquals( - 1, - len(list_destroyed_vms_admin), - "Destroyed VM list count is not matching" - ) + 1, + len(list_destroyed_vms_admin), + "Destroyed VM list count is not matching" + ) destroyed_vm = list_destroyed_vms_admin[0] # Creating expected and actual values dictionaries expected_dict = { - "id":vm_created.id, - "name":vm_created.name, - "displayname":vm_created.displayname, - "state":"Destroyed", - "zoneid":vm_created.zoneid, - "account":vm_created.account, - "template":vm_created.templateid - } + "id": vm_created.id, + "name": vm_created.name, + "displayname": vm_created.displayname, + "state": "Destroyed", + "zoneid": vm_created.zoneid, + "account": vm_created.account, + "template": vm_created.templateid + } actual_dict = { - "id":destroyed_vm.id, - "name":destroyed_vm.name, - "displayname":destroyed_vm.displayname, - "state":destroyed_vm.state, - "zoneid":destroyed_vm.zoneid, - "account":destroyed_vm.account, - "template":destroyed_vm.templateid - } + "id": destroyed_vm.id, + "name": destroyed_vm.name, + "displayname": destroyed_vm.displayname, + "state": destroyed_vm.state, + "zoneid": destroyed_vm.zoneid, + "account": destroyed_vm.account, + "template": destroyed_vm.templateid + } destroyed_vm_status = self.__verify_values( - expected_dict, - actual_dict - ) + expected_dict, + actual_dict + ) self.assertEqual( - True, - destroyed_vm_status, - "Listed Destroyed VM details are not as expected" - ) + True, + destroyed_vm_status, + "Listed Destroyed VM details are not as expected" + ) return @attr(tags=["advanced", "basic"], required_hardware="false") @@ -582,95 +606,95 @@ class TestListInstances(cloudstackTestCase): Step4: Listing all the VMs for a user again Step5: Verifying that the size of the list is increased by 1 Step6: List a VM by specifying the Id if the VM deployed in Step3 - Step7: Verifying that the details of the Listed VM are same as the VM deployed in Step3 + Step7: Verifying that the details of the Listed VM are same as + the VM deployed in Step3 """ # Listing all the VM's for a User list_vms_before = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - page=1, - pagesize=self.services["pagesize"], - domainid=self.account.domainid, - account=self.account.name - ) + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + account=self.account.name + ) self.assertIsNone( - list_vms_before, - "Virtual Machine already exists for newly created user" - ) + list_vms_before, + "Virtual Machine already exists for newly created user" + ) # Deploying a VM vm_created = VirtualMachine.create( - self.userapiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - ) + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) self.assertIsNotNone( - vm_created, - "VM creation failed" - ) - self.cleanup.append(vm_created) + vm_created, + "VM creation failed" + ) # Listing all the VM's for a User list_vms_after = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - page=1, - pagesize=self.services["pagesize"], - domainid=self.account.domainid, - account=self.account.name - ) + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + account=self.account.name + ) status = validateList(list_vms_after) self.assertEquals( - PASS, - status[0], - "Listing of VM after creation failed" - ) + PASS, + status[0], + "Listing of VM after creation failed" + ) self.assertEquals( - 1, - len(list_vms_after), - "VM list count is not matching" - ) + 1, + len(list_vms_after), + "VM list count is not matching" + ) # Listing a VM by Id list_vm_byid = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - id=vm_created.id - ) + self.userapiclient, + listall=self.services["listall"], + id=vm_created.id + ) status = validateList(list_vm_byid) self.assertEquals( - PASS, - status[0], - "Listing of VM by Id failed" - ) + PASS, + status[0], + "Listing of VM by Id failed" + ) listed_vm = list_vm_byid[0] # Creating expected and actual values dictionaries expected_dict = { - "id":vm_created.id, - "name":vm_created.name, - "displayname":vm_created.displayname, - "state":vm_created.state, - "zoneid":vm_created.zoneid, - "account":vm_created.account, - "template":vm_created.templateid - } + "id": vm_created.id, + "name": vm_created.name, + "displayname": vm_created.displayname, + "state": vm_created.state, + "zoneid": vm_created.zoneid, + "account": vm_created.account, + "template": vm_created.templateid + } actual_dict = { - "id":listed_vm.id, - "name":listed_vm.name, - "displayname":listed_vm.displayname, - "state":listed_vm.state, - "zoneid":listed_vm.zoneid, - "account":listed_vm.account, - "template":listed_vm.templateid - } + "id": listed_vm.id, + "name": listed_vm.name, + "displayname": listed_vm.displayname, + "state": listed_vm.state, + "zoneid": listed_vm.zoneid, + "account": listed_vm.account, + "template": listed_vm.templateid + } list_vm_status = self.__verify_values( - expected_dict, - actual_dict - ) + expected_dict, + actual_dict + ) self.assertEqual( - True, - list_vm_status, - "Listed VM by Id details are not as expected" - ) + True, + list_vm_status, + "Listed VM by Id details are not as expected" + ) return @attr(tags=["advanced", "basic"], required_hardware="false") @@ -683,134 +707,136 @@ class TestListInstances(cloudstackTestCase): Step3: Deploying a 2 VM's Step4: Listing all the VMs for a user again Step5: Verifying that list size is increased by 2 - Step6: Listing the VM by specifying complete name of VM-1 created in step3 + Step6: Listing the VM by specifying complete name of + VM-1 created in step3 Step7: Verifying that the size of the list is 1 - Step8: Verifying that the details of the listed VM are same as the VM-1 created in step3 + Step8: Verifying that the details of the listed VM are same as the + VM-1 created in step3 Step9: Listing the VM by specifying the partial name of VM Step10: Verifying that the size of the list is 2 """ # Listing all the VM's for a User list_vms_before = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - page=1, - pagesize=self.services["pagesize"], - domainid=self.account.domainid, - ) + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + ) self.assertIsNone( - list_vms_before, - "Virtual Machine already exists for newly created user" - ) + list_vms_before, + "Virtual Machine already exists for newly created user" + ) vms = {} for i in range(0, 2): # Deploying a VM vm_created = VirtualMachine.create( - self.userapiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - ) + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) self.assertIsNotNone( - vm_created, - "VM creation failed" - ) - self.cleanup.append(vm_created) + vm_created, + "VM creation failed" + ) vms.update({i: vm_created}) # Listing all the VM's for a User list_vms_after = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - page=1, - pagesize=self.services["pagesize"], - domainid=self.account.domainid, - ) + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + ) status = validateList(list_vms_after) self.assertEquals( - PASS, - status[0], - "VM's creation failed" - ) + PASS, + status[0], + "VM's creation failed" + ) self.assertEquals( - 2, - len(list_vms_after), - "VM's list count is not matching" - ) + 2, + len(list_vms_after), + "VM's list count is not matching" + ) # Listing the VM by complete name list_vm_byfullname = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - page=1, - pagesize=self.services["pagesize"], - domainid=self.account.domainid, - name=vms[0].name - ) + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + name=vms[0].name + ) status = validateList(list_vm_byfullname) self.assertEquals( - PASS, - status[0], - "Failed to list VM by Name" - ) + PASS, + status[0], + "Failed to list VM by Name" + ) # Verifying that the size of the list is 1 self.assertEquals( - 1, - len(list_vm_byfullname), - "VM list by full name count is not matching" - ) - # Verifying that the details of the listed VM are same as the VM created above + 1, + len(list_vm_byfullname), + "VM list by full name count is not matching" + ) + # Verifying that the details of the listed VM are same + # as the VM created above # Creating expected and actual values dictionaries expected_dict = { - "id":vms[0].id, - "name":vms[0].name, - "displayname":vms[0].displayname, - "state":vms[0].state, - "zoneid":vms[0].zoneid, - "account":vms[0].account, - "template":vms[0].templateid - } + "id": vms[0].id, + "name": vms[0].name, + "displayname": vms[0].displayname, + "state": vms[0].state, + "zoneid": vms[0].zoneid, + "account": vms[0].account, + "template": vms[0].templateid + } actual_dict = { - "id":list_vm_byfullname[0].id, - "name":list_vm_byfullname[0].name, - "displayname":list_vm_byfullname[0].displayname, - "state":list_vm_byfullname[0].state, - "zoneid":list_vm_byfullname[0].zoneid, - "account":list_vm_byfullname[0].account, - "template":list_vm_byfullname[0].templateid - } + "id": list_vm_byfullname[0].id, + "name": list_vm_byfullname[0].name, + "displayname": list_vm_byfullname[0].displayname, + "state": list_vm_byfullname[0].state, + "zoneid": list_vm_byfullname[0].zoneid, + "account": list_vm_byfullname[0].account, + "template": list_vm_byfullname[0].templateid + } list_vm_status = self.__verify_values( - expected_dict, - actual_dict - ) + expected_dict, + actual_dict + ) self.assertEqual( - True, - list_vm_status, - "Listed VM details are not as expected" - ) + True, + list_vm_status, + "Listed VM details are not as expected" + ) # Listing the VM by partial name list_vm_bypartialname = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - domainid=self.account.domainid, - name=vms[0].name[:1] - ) + self.userapiclient, + listall=self.services["listall"], + domainid=self.account.domainid, + name=vms[0].name[:1] + ) status = validateList(list_vm_bypartialname) self.assertEquals( - PASS, - status[0], - "Failed to list VM by Name" - ) + PASS, + status[0], + "Failed to list VM by Name" + ) # Verifying that the size of the list is 2 self.assertEquals( - 2, - len(list_vm_bypartialname), - "VM list by full name count is not matching" - ) + 2, + len(list_vm_bypartialname), + "VM list by full name count is not matching" + ) return @attr(tags=["advanced", "basic"], required_hardware="false") def test_07_list_vm_by_name_state(self): - """ + """ @Desc: Test List VM's by Name and State @Steps: Step1: Listing all the VMs for a user @@ -818,143 +844,147 @@ class TestListInstances(cloudstackTestCase): Step3: Deploying a VM Step4: Listing all the VMs for a user again Step5: Verifying that list size is increased by 1 - Step6: Listing the VM by specifying name of VM created in step3 and state as Running (matching name and state) + Step6: Listing the VM by specifying name of VM created in step3 and + state as Running (matching name and state) Step7: Verifying that the size of the list is 1 - Step8: Verifying that the details of the listed VM are same as the VM created in step3 - Step9: Listing the VM by specifying name of VM created in step3 and state as Stopped (non matching state) + Step8: Verifying that the details of the listed VM are same as + the VM created in step3 + Step9: Listing the VM by specifying name of VM created in step3 + and state as Stopped (non matching state) Step10: Verifying that the size of the list is 0 - Step11: Listing the VM by specifying non matching name and state as Running (non matching name) + Step11: Listing the VM by specifying non matching name and + state as Running (non matching name) Step12: Verifying that the size of the list is 0 """ # Listing all the VM's for a User list_vms_before = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - page=1, - pagesize=self.services["pagesize"], - domainid=self.account.domainid, - ) + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + ) self.assertIsNone( - list_vms_before, - "Virtual Machine already exists for newly created user" - ) + list_vms_before, + "Virtual Machine already exists for newly created user" + ) # Deploying a VM vm_created = VirtualMachine.create( - self.userapiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - ) + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) self.assertIsNotNone( - vm_created, - "VM creation failed" - ) - self.cleanup.append(vm_created) + vm_created, + "VM creation failed" + ) # Listing all the VM's for a User list_vms_after = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - page=1, - pagesize=self.services["pagesize"], - domainid=self.account.domainid, - ) + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + ) status = validateList(list_vms_after) self.assertEquals( - PASS, - status[0], - "VM's creation failed" - ) + PASS, + status[0], + "VM's creation failed" + ) self.assertEquals( - 1, - len(list_vms_after), - "VM's list count is not matching" - ) + 1, + len(list_vms_after), + "VM's list count is not matching" + ) # Listing the VM by matching Name and State list_running_vm = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - page=1, - pagesize=self.services["pagesize"], - domainid=self.account.domainid, - name=vm_created.name, - state="Running" - ) + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + name=vm_created.name, + state="Running" + ) status = validateList(list_running_vm) self.assertEquals( - PASS, - status[0], - "List VM by name and state failed" - ) + PASS, + status[0], + "List VM by name and state failed" + ) # Verifying that the size of the list is 1 self.assertEquals( - 1, - len(list_running_vm), - "Count of VM list by name and state is not matching" - ) - # Verifying that the details of the listed VM are same as the VM created above + 1, + len(list_running_vm), + "Count of VM list by name and state is not matching" + ) + # Verifying that the details of the listed VM are same + # as the VM created above # Creating expected and actual values dictionaries expected_dict = { - "id":vm_created.id, - "name":vm_created.name, - "displayname":vm_created.displayname, - "state":"Running", - "zoneid":vm_created.zoneid, - "account":vm_created.account, - "template":vm_created.templateid - } + "id": vm_created.id, + "name": vm_created.name, + "displayname": vm_created.displayname, + "state": "Running", + "zoneid": vm_created.zoneid, + "account": vm_created.account, + "template": vm_created.templateid + } actual_dict = { - "id":list_running_vm[0].id, - "name":list_running_vm[0].name, - "displayname":list_running_vm[0].displayname, - "state":list_running_vm[0].state, - "zoneid":list_running_vm[0].zoneid, - "account":list_running_vm[0].account, - "template":list_running_vm[0].templateid - } + "id": list_running_vm[0].id, + "name": list_running_vm[0].name, + "displayname": list_running_vm[0].displayname, + "state": list_running_vm[0].state, + "zoneid": list_running_vm[0].zoneid, + "account": list_running_vm[0].account, + "template": list_running_vm[0].templateid + } list_vm_status = self.__verify_values( - expected_dict, - actual_dict - ) + expected_dict, + actual_dict + ) self.assertEqual( - True, - list_vm_status, - "Listed VM details are not as expected" - ) + True, + list_vm_status, + "Listed VM details are not as expected" + ) # Listing the VM by matching name and non matching state list_running_vm = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - page=1, - pagesize=self.services["pagesize"], - domainid=self.account.domainid, - name=vm_created.name, - state="Stopped" - ) + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + name=vm_created.name, + state="Stopped" + ) self.assertIsNone( - list_running_vm, - "Listed VM with non matching state" - ) + list_running_vm, + "Listed VM with non matching state" + ) # Listing the VM by non matching name and matching state list_running_vm = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - page=1, - pagesize=self.services["pagesize"], - domainid=self.account.domainid, - name="name", - state="Running" - ) + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + name="name", + state="Running" + ) self.assertIsNone( - list_running_vm, - "Listed VM with non matching name" - ) + list_running_vm, + "Listed VM with non matching name" + ) return @attr(tags=["advanced", "basic"], required_hardware="false") def test_08_list_vm_by_zone(self): - """ - @Desc: Test List VM by Zone. + """ + @Desc: Test List VM by Zone. This test case is applicable for a setup having multiple zones. @Steps: Step1: Listing all the zones @@ -966,7 +996,8 @@ class TestListInstances(cloudstackTestCase): Step6: Deploying a VM Step7: Listing all the VMs for a user again for matching zone Step8: Verifying that the size of the list is 1 - Step9: Verifying that the details of the Listed VM are same as the VM deployed in Step6 + Step9: Verifying that the details of the Listed VM are same + as the VM deployed in Step6 Step10: Listing all the VMs for a user again for non-matching zone Step11: Verifying that the size of the list is 0 """ @@ -974,10 +1005,10 @@ class TestListInstances(cloudstackTestCase): zones_list = Zone.list(self.apiClient) status = validateList(zones_list) self.assertEquals( - PASS, - status[0], - "zones not available in the given setup" - ) + PASS, + status[0], + "zones not available in the given setup" + ) current_zone = self.services["virtual_machine"]["zoneid"] current_template = self.services["virtual_machine"]["template"] # Checking if there are multiple zones in the setup. @@ -986,114 +1017,114 @@ class TestListInstances(cloudstackTestCase): else: # Getting the template available under the zone template = get_template( - self.apiClient, - zones_list[0].id, - self.services["ostype"] - ) + self.apiClient, + zones_list[0].id, + self.services["ostype"] + ) self.assertIsNotNone( - template, - "Template not found for zone" - ) + template, + "Template not found for zone" + ) self.services["virtual_machine"]["zoneid"] = zones_list[0].id self.services["virtual_machine"]["template"] = template.id # Listing all the VM's for a User list_vms_before = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - page=1, - pagesize=self.services["pagesize"], - domainid=self.account.domainid, - zoneid=zones_list[0].id - ) + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + zoneid=zones_list[0].id + ) self.assertIsNone( - list_vms_before, - "Virtual Machine already exists for newly created user" - ) + list_vms_before, + "Virtual Machine already exists for newly created user" + ) # Deploying a VM vm_created = VirtualMachine.create( - self.userapiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - ) + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) self.assertIsNotNone( - vm_created, - "VM creation failed" - ) - self.cleanup.append(vm_created) + vm_created, + "VM creation failed" + ) # Listing all the VMs for a user again for matching zone list_vms_after = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - page=1, - pagesize=self.services["pagesize"], - domainid=self.account.domainid, - zoneid=zones_list[0].id - ) + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + zoneid=zones_list[0].id + ) status = validateList(list_vms_after) self.assertEquals( - PASS, - status[0], - "VM creation failed" - ) + PASS, + status[0], + "VM creation failed" + ) # Verifying that the size of the list is 1 self.assertEquals( - 1, - len(list_vms_after), - "VM list count is not matching" - ) + 1, + len(list_vms_after), + "VM list count is not matching" + ) listed_vm = list_vms_after[0] - # Verifying that the details of the Listed VM are same as the VM deployed above + # Verifying that the details of the Listed VM are + # same as the VM deployed above # Creating expected and actual values dictionaries expected_dict = { - "id":vm_created.id, - "name":vm_created.name, - "displayname":vm_created.displayname, - "state":vm_created.state, - "zoneid":vm_created.zoneid, - "account":vm_created.account, - "template":vm_created.templateid - } + "id": vm_created.id, + "name": vm_created.name, + "displayname": vm_created.displayname, + "state": vm_created.state, + "zoneid": vm_created.zoneid, + "account": vm_created.account, + "template": vm_created.templateid + } actual_dict = { - "id":listed_vm.id, - "name":listed_vm.name, - "displayname":listed_vm.displayname, - "state":listed_vm.state, - "zoneid":listed_vm.zoneid, - "account":listed_vm.account, - "template":listed_vm.templateid - } + "id": listed_vm.id, + "name": listed_vm.name, + "displayname": listed_vm.displayname, + "state": listed_vm.state, + "zoneid": listed_vm.zoneid, + "account": listed_vm.account, + "template": listed_vm.templateid + } list_vm_status = self.__verify_values( - expected_dict, - actual_dict - ) + expected_dict, + actual_dict + ) self.assertEqual( - True, - list_vm_status, - "Listed VM by Id details are not as expected" - ) + True, + list_vm_status, + "Listed VM by Id details are not as expected" + ) # Listing all the VMs for a user again for non-matching zone list_vms = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - page=1, - pagesize=self.services["pagesize"], - domainid=self.account.domainid, - zoneid=zones_list[1].id - ) + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + zoneid=zones_list[1].id + ) self.assertIsNone( - list_vms, - "VM's listed for non matching zone" - ) + list_vms, + "VM's listed for non matching zone" + ) self.services["virtual_machine"]["zoneid"] = current_zone self.services["virtual_machine"]["template"] = current_template return @attr(tags=["advanced", "basic"], required_hardware="false") def test_09_list_vm_by_zone_name(self): - """ - @Desc: Test List VM by Zone. + """ + @Desc: Test List VM by Zone. This test case is applicable for a setup having multiple zones. @Steps: Step1: Listing all the zones @@ -1105,22 +1136,26 @@ class TestListInstances(cloudstackTestCase): Step6: Deploying a VM Step7: Listing all the VMs for a user again Step8: Verifying that list size is increased by 1 - Step9: Listing the VM by specifying name of VM created in step6 and matching zone (matching name and zone) + Step9: Listing the VM by specifying name of VM created in step6 + and matching zone (matching name and zone) Step10: Verifying that the size of the list is 1 - Step11: Verifying that the details of the listed VM are same as the VM created in step3 - Step12: Listing the VM by specifying name of VM created in step6 and non matching zone (non matching zone) + Step11: Verifying that the details of the listed VM are same + as the VM created in step3 + Step12: Listing the VM by specifying name of VM created in step6 + and non matching zone (non matching zone) Step13: Verifying that the size of the list is 0 - Step14: Listing the VM by specifying non matching name and matching zone (non matching name) + Step14: Listing the VM by specifying non matching name and + matching zone (non matching name) Step15: Verifying that the size of the list is 0 """ # Listing all the zones available zones_list = Zone.list(self.apiClient) status = validateList(zones_list) self.assertEquals( - PASS, - status[0], - "zones not available in the given setup" - ) + PASS, + status[0], + "zones not available in the given setup" + ) current_zone = self.services["virtual_machine"]["zoneid"] current_template = self.services["virtual_machine"]["template"] # Checking if there are multiple zones in the setup. @@ -1129,343 +1164,353 @@ class TestListInstances(cloudstackTestCase): else: # Getting the template available under the zone template = get_template( - self.apiClient, - zones_list[0].id, - self.services["ostype"] - ) + self.apiClient, + zones_list[0].id, + self.services["ostype"] + ) self.assertIsNotNone( - template, - "Template not found for zone" - ) + template, + "Template not found for zone" + ) self.services["virtual_machine"]["zoneid"] = zones_list[0].id self.services["virtual_machine"]["template"] = template.id # Listing all the VM's for a User list_vms_before = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - page=1, - pagesize=self.services["pagesize"], - domainid=self.account.domainid, - zoneid=zones_list[0].id, - account=self.account.name - ) + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + zoneid=zones_list[0].id, + account=self.account.name + ) self.assertIsNone( - list_vms_before, - "Virtual Machine already exists for newly created user" - ) + list_vms_before, + "Virtual Machine already exists for newly created user" + ) # Deploying a VM vm_created = VirtualMachine.create( - self.userapiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - ) + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) self.assertIsNotNone( - vm_created, - "VM creation failed" - ) - self.cleanup.append(vm_created) + vm_created, + "VM creation failed" + ) # Listing all the VMs for a user again for matching zone list_vms_after = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - page=1, - pagesize=self.services["pagesize"], - domainid=self.account.domainid, - zoneid=zones_list[0].id, - account=self.account.name - ) + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + zoneid=zones_list[0].id, + account=self.account.name + ) status = validateList(list_vms_after) self.assertEquals( - PASS, - status[0], - "VM creation failed" - ) + PASS, + status[0], + "VM creation failed" + ) # Verifying that the size of the list is 1 self.assertEquals( - 1, - len(list_vms_after), - "VM list count is not matching" - ) - # Listing the VM by specifying name of VM created in above and matching zone + 1, + len(list_vms_after), + "VM list count is not matching" + ) + # Listing the VM by specifying name of VM created in above and + # matching zone list_vms = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - page=1, - pagesize=self.services["pagesize"], - domainid=self.account.domainid, - zoneid=zones_list[0].id, - name=vm_created.name - ) + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + zoneid=zones_list[0].id, + name=vm_created.name + ) status = validateList(list_vms) self.assertEquals( - PASS, - status[0], - "Listing VM's by name and zone failed" - ) + PASS, + status[0], + "Listing VM's by name and zone failed" + ) # Verifying Verifying that the size of the list is 1 self.assertEquals( - 1, - len(list_vms), - "Count of listed VM's by name and zone is not as expected" - ) + 1, + len(list_vms), + "Count of listed VM's by name and zone is not as expected" + ) listed_vm = list_vms[0] - # Verifying that the details of the Listed VM are same as the VM deployed above + # Verifying that the details of the Listed VM are same + # as the VM deployed above # Creating expected and actual values dictionaries expected_dict = { - "id":vm_created.id, - "name":vm_created.name, - "displayname":vm_created.displayname, - "state":vm_created.state, - "zoneid":vm_created.zoneid, - "account":vm_created.account, - "template":vm_created.templateid - } + "id": vm_created.id, + "name": vm_created.name, + "displayname": vm_created.displayname, + "state": vm_created.state, + "zoneid": vm_created.zoneid, + "account": vm_created.account, + "template": vm_created.templateid + } actual_dict = { - "id":listed_vm.id, - "name":listed_vm.name, - "displayname":listed_vm.displayname, - "state":listed_vm.state, - "zoneid":listed_vm.zoneid, - "account":listed_vm.account, - "template":listed_vm.templateid - } + "id": listed_vm.id, + "name": listed_vm.name, + "displayname": listed_vm.displayname, + "state": listed_vm.state, + "zoneid": listed_vm.zoneid, + "account": listed_vm.account, + "template": listed_vm.templateid + } list_vm_status = self.__verify_values( - expected_dict, - actual_dict - ) + expected_dict, + actual_dict + ) self.assertEqual( - True, - list_vm_status, - "Listed VM by Id details are not as expected" - ) - # Listing the VM by specifying name of VM created in step3 and non matching zone + True, + list_vm_status, + "Listed VM by Id details are not as expected" + ) + # Listing the VM by specifying name of VM created in step3 and non + # matching zone list_vms = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - page=1, - pagesize=self.services["pagesize"], - domainid=self.account.domainid, - zoneid=zones_list[1].id, - name=vm_created.name - ) + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + zoneid=zones_list[1].id, + name=vm_created.name + ) self.assertIsNone( - list_vms, - "VM's listed for non matching zone" - ) - # Listing the VM by specifying non matching name of VM and matching zone + list_vms, + "VM's listed for non matching zone" + ) + # Listing the VM by specifying non matching name of VM and matching + # zone list_vms = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - page=1, - pagesize=self.services["pagesize"], - domainid=self.account.domainid, - zoneid=zones_list[0].id, - name="name" - ) + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + zoneid=zones_list[0].id, + name="name" + ) self.assertIsNone( - list_vms, - "VM's listed for non matching zone" - ) + list_vms, + "VM's listed for non matching zone" + ) self.services["virtual_machine"]["zoneid"] = current_zone self.services["virtual_machine"]["template"] = current_template return @attr(tags=["advanced", "basic"], required_hardware="false") def test_10_list_vm_by_zone_name_state(self): - """ - @Desc: Test List VM by Zone. + """ + @Desc: Test List VM by Zone. @Steps: Step1: Listing all the VMs for a user Step2: Verifying that the size of the list is 0 Step3: Deploying a VM Step4: Listing all the VMs for a user again Step5: Verifying that list size is increased by 1 - Step6: Listing the VM by specifying name of VM created in step3 and matching zone and state as Running + Step6: Listing the VM by specifying name of VM created in step3 + and matching zone and state as Running Step7: Verifying that the size of the list is 1 - Step8: Verifying that the details of the listed VM are same as the VM created in step3 - Step9: Listing the VM by specifying name of VM created in step3 and matching zone and state as Stopped + Step8: Verifying that the details of the listed VM are same + as the VM created in step3 + Step9: Listing the VM by specifying name of VM created in step3 and + matching zone and state as Stopped Step10: Verifying that the size of the list is 0 Step11: Listing the VM by name, Zone and account Step12: Verifying that the size of the list is 1 - Step13: Verifying that the details of the listed VM are same as the VM created in step3 + Step13: Verifying that the details of the listed VM are same + as the VM created in step3 """ # Listing all the VM's for a User list_vms_before = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - page=1, - pagesize=self.services["pagesize"], - domainid=self.account.domainid, - zoneid=self.zone.id, - account=self.account.name - ) + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + zoneid=self.zone.id, + account=self.account.name + ) self.assertIsNone( - list_vms_before, - "Virtual Machine already exists for newly created user" - ) + list_vms_before, + "Virtual Machine already exists for newly created user" + ) # Deploying a VM vm_created = VirtualMachine.create( - self.userapiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - ) + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) self.assertIsNotNone( - vm_created, - "VM creation failed" - ) - self.cleanup.append(vm_created) + vm_created, + "VM creation failed" + ) # Listing all the VMs for a user again for matching zone list_vms_after = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - page=1, - pagesize=self.services["pagesize"], - domainid=self.account.domainid, - zoneid=self.zone.id, - account=self.account.name - ) + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + zoneid=self.zone.id, + account=self.account.name + ) status = validateList(list_vms_after) self.assertEquals( - PASS, - status[0], - "VM creation failed" - ) + PASS, + status[0], + "VM creation failed" + ) # Verifying that the size of the list is 1 self.assertEquals( - 1, - len(list_vms_after), - "VM list count is not matching" - ) - # Listing the VM by specifying name of VM created in step3 and matching zone and state as Running + 1, + len(list_vms_after), + "VM list count is not matching" + ) + # Listing the VM by specifying name of VM created in step3 and matching + # zone and state as Running list_vms = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - page=1, - pagesize=self.services["pagesize"], - domainid=self.account.domainid, - zoneid=self.zone.id, - name=vm_created.name, - state="Running" - ) + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + zoneid=self.zone.id, + name=vm_created.name, + state="Running" + ) status = validateList(list_vms) self.assertEquals( - PASS, - status[0], - "Listing VM's by name and zone failed" - ) + PASS, + status[0], + "Listing VM's by name and zone failed" + ) # Verifying Verifying that the size of the list is 1 self.assertEquals( - 1, - len(list_vms), - "Count of listed VM's by name, zone and state is not as expected" - ) + 1, + len(list_vms), + "Count of listed VM's by name, zone and state is not as expected" + ) listed_vm = list_vms[0] - # Verifying that the details of the Listed VM are same as the VM deployed above + # Verifying that the details of the Listed VM are same + # as the VM deployed above # Creating expected and actual values dictionaries expected_dict = { - "id":vm_created.id, - "name":vm_created.name, - "displayname":vm_created.displayname, - "state":vm_created.state, - "zoneid":vm_created.zoneid, - "account":vm_created.account, - "template":vm_created.templateid - } + "id": vm_created.id, + "name": vm_created.name, + "displayname": vm_created.displayname, + "state": vm_created.state, + "zoneid": vm_created.zoneid, + "account": vm_created.account, + "template": vm_created.templateid + } actual_dict = { - "id":listed_vm.id, - "name":listed_vm.name, - "displayname":listed_vm.displayname, - "state":listed_vm.state, - "zoneid":listed_vm.zoneid, - "account":listed_vm.account, - "template":listed_vm.templateid - } + "id": listed_vm.id, + "name": listed_vm.name, + "displayname": listed_vm.displayname, + "state": listed_vm.state, + "zoneid": listed_vm.zoneid, + "account": listed_vm.account, + "template": listed_vm.templateid + } list_vm_status = self.__verify_values( - expected_dict, - actual_dict - ) + expected_dict, + actual_dict + ) self.assertEqual( - True, - list_vm_status, - "Listed VM by Id details are not as expected" - ) - # Listing the VM by specifying name of VM created in step3, zone and State as Stopped + True, + list_vm_status, + "Listed VM by Id details are not as expected" + ) + # Listing the VM by specifying name of VM created in step3, zone and + # State as Stopped list_vms = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - page=1, - pagesize=self.services["pagesize"], - domainid=self.account.domainid, - zoneid=self.zone.id, - name=vm_created.name, - state="Stopped" - ) + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + zoneid=self.zone.id, + name=vm_created.name, + state="Stopped" + ) self.assertIsNone( - list_vms, - "VM's listed for non matching zone" - ) + list_vms, + "VM's listed for non matching zone" + ) # Listing the VM by name, zone and account list_vms = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - page=1, - pagesize=self.services["pagesize"], - domainid=self.account.domainid, - zoneid=self.zone.id, - name=vm_created.name, - account=self.account.name - ) + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + zoneid=self.zone.id, + name=vm_created.name, + account=self.account.name + ) status = validateList(list_vms) self.assertEquals( - PASS, - status[0], - "Listing VM's by name, account and zone failed" - ) + PASS, + status[0], + "Listing VM's by name, account and zone failed" + ) # Verifying Verifying that the size of the list is 1 self.assertEquals( - 1, - len(list_vms), - "Count of listed VM's by name, zone and account is not as expected" - ) + 1, + len(list_vms), + "Count of listed VM's by name, zone and account is not as expected" + ) listed_vm = list_vms[0] - # Verifying that the details of the Listed VM are same as the VM deployed above + # Verifying that the details of the Listed VM are same + # as the VM deployed above # Creating expected and actual values dictionaries expected_dict = { - "id":vm_created.id, - "name":vm_created.name, - "displayname":vm_created.displayname, - "state":vm_created.state, - "zoneid":vm_created.zoneid, - "account":vm_created.account, - "template":vm_created.templateid - } + "id": vm_created.id, + "name": vm_created.name, + "displayname": vm_created.displayname, + "state": vm_created.state, + "zoneid": vm_created.zoneid, + "account": vm_created.account, + "template": vm_created.templateid + } actual_dict = { - "id":listed_vm.id, - "name":listed_vm.name, - "displayname":listed_vm.displayname, - "state":listed_vm.state, - "zoneid":listed_vm.zoneid, - "account":listed_vm.account, - "template":listed_vm.templateid - } + "id": listed_vm.id, + "name": listed_vm.name, + "displayname": listed_vm.displayname, + "state": listed_vm.state, + "zoneid": listed_vm.zoneid, + "account": listed_vm.account, + "template": listed_vm.templateid + } list_vm_status = self.__verify_values( - expected_dict, - actual_dict - ) + expected_dict, + actual_dict + ) self.assertEqual( - True, - list_vm_status, - "Listed VM by Id details are not as expected" - ) + True, + list_vm_status, + "Listed VM by Id details are not as expected" + ) return @attr(tags=["advanced", "basic"], required_hardware="true") def test_11_register_reset_vm_sshkey(self): - """ + """ @Desc: Test to verify registering and reset of SSH Key for VM @Steps: Step1: Deploying a VM @@ -1479,114 +1524,113 @@ class TestListInstances(cloudstackTestCase): """ # Listing all the VM's for a User list_vms_before = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - ) + self.userapiclient, + listall=self.services["listall"], + ) self.assertIsNone( - list_vms_before, - "Virtual Machine already exists for newly created user" - ) + list_vms_before, + "Virtual Machine already exists for newly created user" + ) # Deploying a VM vm_created = VirtualMachine.create( - self.userapiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - ) + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) self.assertIsNotNone( - vm_created, - "VM creation failed" - ) - self.cleanup.append(vm_created) + vm_created, + "VM creation failed" + ) # Listing all the VMs for a user again list_vms_after = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - ) + self.userapiclient, + listall=self.services["listall"], + ) status = validateList(list_vms_after) self.assertEquals( - PASS, - status[0], - "VM creation failed" - ) + PASS, + status[0], + "VM creation failed" + ) # Verifying that the size of the list is 1 self.assertEquals( - 1, - len(list_vms_after), - "VM list count is not matching" - ) + 1, + len(list_vms_after), + "VM list count is not matching" + ) # Stopping the VM deployed above vm_created.stop( - self.userapiclient, - forced=True - ) + self.userapiclient, + forced=True + ) # Listing all the SSH Key pairs list_keypairs_before = SSHKeyPair.list( - self.userapiclient - ) + self.userapiclient + ) list_keypairs_before_size = 0 if list_keypairs_before is not None: list_keypairs_before_size = len(list_keypairs_before) # Registering new Key pair new_keypair = SSHKeyPair.register( - self.userapiclient, - name="keypair1", - publickey="ssh-rsa: e6:9a:1e:b5:98:75:88:5d:56:bc:92:7b:43:48:05:b2" - ) + self.userapiclient, + name="keypair1", + publickey="ssh-rsa: e6:9a:1e:b5:98:75:88:5d:56:bc:92:7b:43:48:05:b2" + ) self.assertIsNotNone( - new_keypair, - "New Key pair generation failed" - ) + new_keypair, + "New Key pair generation failed" + ) self.assertEquals( - "keypair1", - new_keypair.name, - "Key Pair not created with given name" - ) + "keypair1", + new_keypair.name, + "Key Pair not created with given name" + ) # Listing all the SSH Key pairs again list_keypairs_after = SSHKeyPair.list( - self.userapiclient - ) + self.userapiclient + ) status = validateList(list_keypairs_after) self.assertEquals( - PASS, - status[0], - "Listing of Key pairs failed" - ) + PASS, + status[0], + "Listing of Key pairs failed" + ) # Verifying that list size is increased by 1 self.assertEquals( - list_keypairs_before_size + 1, - len(list_keypairs_after), - "List count is not matching" - ) + list_keypairs_before_size + 1, + len(list_keypairs_after), + "List count is not matching" + ) # Resetting the VM SSH key to the Key pair created above vm_created.resetSshKey( - self.userapiclient, - keypair=new_keypair.name - ) + self.userapiclient, + keypair=new_keypair.name + ) # Listing VM details again list_vm = VirtualMachine.list( - self.userapiclient, - id=vm_created.id - ) + self.userapiclient, + id=vm_created.id + ) status = validateList(list_vm) self.assertEquals( - PASS, - status[0], - "Listing of VM failed" - ) + PASS, + status[0], + "Listing of VM failed" + ) self.assertEquals( - 1, - len(list_vm), - "VMs list is not as expected" - ) + 1, + len(list_vm), + "VMs list is not as expected" + ) # Verifying that VM's SSH keypair is set to newly created keypair self.assertEquals( - new_keypair.name, - list_vm[0].keypair, - "VM is not set to newly created SSH Key pair" - ) + new_keypair.name, + list_vm[0].keypair, + "VM is not set to newly created SSH Key pair" + ) return @attr(tags=["advanced", "basic"], required_hardware="true") @@ -1596,112 +1640,116 @@ class TestListInstances(cloudstackTestCase): @Steps: Step1: Deploying a VM Step2: Listing all the existing service offerings - Step3: If there is a matching Service Offering for change service of stopped VM - use that service offering. If not create one service offering for change service. + Step3: If there is a matching Service Offering for + change service of stopped VM + use that service offering. If not create + one service offering for change service. Step4: Perform change service for the Running VM Step5: Verifying that change service is not possible for Running VM """ # Listing all the VM's for a User list_vms_before = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - ) + self.userapiclient, + listall=self.services["listall"], + ) self.assertIsNone( - list_vms_before, - "Virtual Machine already exists for newly created user" - ) + list_vms_before, + "Virtual Machine already exists for newly created user" + ) # Deploying a VM vm_created = VirtualMachine.create( - self.userapiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - ) + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) self.assertIsNotNone( - vm_created, - "VM creation failed" - ) - self.cleanup.append(vm_created) + vm_created, + "VM creation failed" + ) # Listing details of current Service Offering vm_so_list = ServiceOffering.list( - self.userapiclient, - id=vm_created.serviceofferingid - ) + self.userapiclient, + id=vm_created.serviceofferingid + ) status = validateList(vm_so_list) self.assertEquals( - PASS, - status[0], - "Listing of VM Service offering failed" - ) + PASS, + status[0], + "Listing of VM Service offering failed" + ) current_so = vm_so_list[0] # Listing all the VMs for a user again list_vms_after = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - ) + self.userapiclient, + listall=self.services["listall"], + ) status = validateList(list_vms_after) self.assertEquals( - PASS, - status[0], - "VM creation failed" - ) + PASS, + status[0], + "VM creation failed" + ) # Verifying that the size of the list is 1 self.assertEquals( - 1, - len(list_vms_after), - "VM list count is not matching" - ) + 1, + len(list_vms_after), + "VM list count is not matching" + ) # Listing all the service offerings service_offerings_list = ServiceOffering.list( - self.userapiclient, - virtualmachineid=vm_created.id - ) + self.userapiclient, + virtualmachineid=vm_created.id + ) # Verifying if any Service offering available for change service of VM so_exists = False if service_offerings_list is not None: for i in range(0, len(service_offerings_list)): - if ((current_so.id != service_offerings_list[i].id) and\ - (current_so.storagetype == service_offerings_list[i].storagetype)): + if ((current_so.id != service_offerings_list[i].id) and ( + current_so.storagetype == + service_offerings_list[i].storagetype)): so_exists = True new_so = service_offerings_list[i] break - # If service offering does not exists, then creating one service offering for scale up + # If service offering does not exists, then creating one service + # offering for scale up if not so_exists: - self.services["service_offerings"]["small"]["storagetype"] = current_so.storagetype + self.services["service_offerings"]["small"][ + "storagetype"] = current_so.storagetype new_so = ServiceOffering.create( - self.apiClient, - self.services["service_offerings"]["small"] - ) + self.apiClient, + self.services["service_offerings"]["small"] + ) self.cleanup.append(new_so) # Changing service for the Running VM with self.assertRaises(Exception): vm_created.change_service_offering( - self.userapiclient, - new_so.id - ) + self.userapiclient, + new_so.id + ) # Listing VM details again list_vms_after = VirtualMachine.list( - self.userapiclient, - id=vm_created.id - ) + self.userapiclient, + id=vm_created.id + ) status = validateList(list_vms_after) self.assertEquals( - PASS, - status[0], - "Listing of VM failed" - ) + PASS, + status[0], + "Listing of VM failed" + ) self.assertEquals( - 1, - len(list_vms_after), - "VMs list is not as expected" - ) + 1, + len(list_vms_after), + "VMs list is not as expected" + ) # Verifying that VM's service offerings is not changed self.assertEquals( - current_so.id, - list_vms_after[0].serviceofferingid, - "VM is not containing old Service Offering" - ) + current_so.id, + list_vms_after[0].serviceofferingid, + "VM is not containing old Service Offering" + ) return @attr(tags=["advanced"], required_hardware="true") @@ -1720,168 +1768,171 @@ class TestListInstances(cloudstackTestCase): Step8: Adding the networks created in step4 to VM deployed in step1 Step9: Verifying that VM deployed in step1 has 2 nics Step10: Verifying that isdefault is set to true for only 1 nic - Step11: Verifying that isdefault is set to true for the Network created when deployed a VM + Step11: Verifying that isdefault is set to true for the Network + created when deployed a VM Step12: Making the nic created in step4 as default nic Step13: Verifying that isdefault is set to true for only 1 nic - Step14: Verifying that the isdefault is set to true for the nic created in step4 + Step14: Verifying that the isdefault is set to true for the + nic created in step4 Step15: Removing the non-default nic from VM Step16: Verifying that VM deployed in step1 has only 1 nic """ if self.hypervisor.lower() in ['hyperv']: - raise unittest.SkipTest("This feature is not supported on existing hypervisor. Hence, skipping the test") + raise unittest.SkipTest( + "This feature is not supported on existing hypervisor.\ + Hence, skipping the test") # Listing all the VM's for a User list_vms_before = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - ) + self.userapiclient, + listall=self.services["listall"], + ) self.assertIsNone( - list_vms_before, - "Virtual Machine already exists for newly created user" - ) + list_vms_before, + "Virtual Machine already exists for newly created user" + ) # Deploying a VM vm_created = VirtualMachine.create( - self.userapiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - ) + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) self.assertIsNotNone( - vm_created, - "VM creation failed" - ) - self.cleanup.append(vm_created) + vm_created, + "VM creation failed" + ) # Listing all the VMs for a user again list_vms_after = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - ) + self.userapiclient, + listall=self.services["listall"], + ) status = validateList(list_vms_after) self.assertEquals( - PASS, - status[0], - "VM creation failed" - ) + PASS, + status[0], + "VM creation failed" + ) # Verifying that the size of the list is 1 self.assertEquals( - 1, - len(list_vms_after), - "VM list count is not matching" - ) + 1, + len(list_vms_after), + "VM list count is not matching" + ) # Listing all the networks before list_network_before = Network.list( - self.userapiclient, - isdefault="true", - zoneid=self.zone.id, - account=self.account.name, - domainid=self.domain.id, - type="Isolated" - ) + self.userapiclient, + isdefault="true", + zoneid=self.zone.id, + account=self.account.name, + domainid=self.domain.id, + type="Isolated" + ) status = validateList(list_network_before) self.assertEquals( - PASS, - status[0], - "Default Network not created when deploying a VM" - ) + PASS, + status[0], + "Default Network not created when deploying a VM" + ) # Verifying that only 1 network is created while deploying a VM self.assertEquals( - 1, - len(list_network_before), - "More than 1 default network exists" - ) + 1, + len(list_network_before), + "More than 1 default network exists" + ) network1 = list_network_before[0] # Listing Network Offerings network_offerings_list = NetworkOffering.list( - self.apiClient, - forvpc="false", - guestiptype="Isolated", - state="Enabled", - supportedservices="SourceNat", - zoneid=self.zone.id - ) + self.apiClient, + forvpc="false", + guestiptype="Isolated", + state="Enabled", + supportedservices="SourceNat", + zoneid=self.zone.id + ) self.assertIsNotNone( - network_offerings_list, - "Isolated Network Offerings with sourceNat enabled are not found" - ) + network_offerings_list, + "Isolated Network Offerings with sourceNat enabled are not found" + ) # Creating one more network network2 = Network.create( - self.userapiclient, - self.services["network"], - accountid=self.account.name, - domainid=self.domain.id, - networkofferingid=network_offerings_list[0].id, - zoneid=self.zone.id - ) + self.userapiclient, + self.services["network"], + accountid=self.account.name, + domainid=self.domain.id, + networkofferingid=network_offerings_list[0].id, + zoneid=self.zone.id + ) self.assertIsNotNone( - network2, - "Network creation failed" - ) + network2, + "Network creation failed" + ) # Listing all the networks again list_network_after = Network.list( - self.userapiclient, - zoneid=self.zone.id, - account=self.account.name, - domainid=self.domain.id, - type="Isolated" - ) + self.userapiclient, + zoneid=self.zone.id, + account=self.account.name, + domainid=self.domain.id, + type="Isolated" + ) status = validateList(list_network_after) self.assertEquals( - PASS, - status[0], - "List of Networks failed" - ) + PASS, + status[0], + "List of Networks failed" + ) # Verifying that list size is 2 self.assertEquals( - 2, - len(list_network_after), - "More than 1 default network exists" - ) + 2, + len(list_network_after), + "More than 1 default network exists" + ) # Verifying that VM created is having only 1 nic vm_nics_before = vm_created.nic self.assertIsNotNone( - vm_nics_before, - "Nic not found for the VM deployed" - ) + vm_nics_before, + "Nic not found for the VM deployed" + ) self.assertEquals( - 1, - len(vm_nics_before), - "VM Nic count is not matching" - ) + 1, + len(vm_nics_before), + "VM Nic count is not matching" + ) # Verifying that the nic is same as the default network listed above self.assertEquals( - network1.id, - vm_nics_before[0].networkid, - "Default NIC for VM is not as expected" - ) + network1.id, + vm_nics_before[0].networkid, + "Default NIC for VM is not as expected" + ) # Adding network2 created above to VM VirtualMachine.add_nic( - vm_created, - self.userapiclient, - network2.id - ) + vm_created, + self.userapiclient, + network2.id + ) # Listing the Vm details again list_vms_after = VirtualMachine.list( - self.userapiclient, - id=vm_created.id - ) + self.userapiclient, + id=vm_created.id + ) status = validateList(list_vms_after) self.assertEquals( - PASS, - status[0], - "Listing of VM failed" - ) + PASS, + status[0], + "Listing of VM failed" + ) vm = list_vms_after[0] # Verifying that VM nics size is 2 now vm_nics_after = vm.nic self.assertIsNotNone( - vm_nics_after, - "Nic not found for the deployed VM" - ) + vm_nics_after, + "Nic not found for the deployed VM" + ) self.assertEquals( - 2, - len(vm_nics_after), - "VM NIC's count is not matching" - ) + 2, + len(vm_nics_after), + "VM NIC's count is not matching" + ) # Verifying that isdefault is set to true for only 1 nic default_count = 0 for i in range(0, len(vm_nics_after)): @@ -1891,44 +1942,45 @@ class TestListInstances(cloudstackTestCase): else: non_default_nic = vm_nics_after[i] self.assertEquals( - 1, - default_count, - "Default NIC count is not matching" - ) - # Verifying that default NIC is same the network created when VM is deployed + 1, + default_count, + "Default NIC count is not matching" + ) + # Verifying that default NIC is same the network created when VM is + # deployed self.assertEquals( - network1.id, - default_nic.networkid, - "Default NIC is not matching for VM" - ) + network1.id, + default_nic.networkid, + "Default NIC is not matching for VM" + ) # Updating network 2 as default NIC vm_created.update_default_nic( - self.userapiclient, - non_default_nic.id - ) + self.userapiclient, + non_default_nic.id + ) # Listing the Vm details again list_vms_after = VirtualMachine.list( - self.userapiclient, - id=vm_created.id - ) + self.userapiclient, + id=vm_created.id + ) status = validateList(list_vms_after) self.assertEquals( - PASS, - status[0], - "Listing of VM failed" - ) + PASS, + status[0], + "Listing of VM failed" + ) vm = list_vms_after[0] # Verifying that VM nics size is 2 now vm_nics_after = vm.nic self.assertIsNotNone( - vm_nics_after, - "Nic not found for the deployed VM" - ) + vm_nics_after, + "Nic not found for the deployed VM" + ) self.assertEquals( - 2, - len(vm_nics_after), - "VM NIC's count is not matching" - ) + 2, + len(vm_nics_after), + "VM NIC's count is not matching" + ) # Verifying that isdefault is set to true for only 1 nic default_count = 0 for i in range(0, len(vm_nics_after)): @@ -1939,52 +1991,54 @@ class TestListInstances(cloudstackTestCase): non_default_nic = vm_nics_after[i] self.assertEquals( - 1, - default_count, - "Default NIC count is not matching" - ) - # Verifying that default NIC is same the newly updated network (network 2) + 1, + default_count, + "Default NIC count is not matching" + ) + # Verifying that default NIC is same the newly updated network (network + # 2) self.assertEquals( - network2.id, - default_nic.networkid, - "Default NIC is not matching for VM" - ) + network2.id, + default_nic.networkid, + "Default NIC is not matching for VM" + ) # Deleting non default NIC vm_created.remove_nic( - self.userapiclient, - non_default_nic.id - ) + self.userapiclient, + non_default_nic.id + ) # Listing the Vm details again list_vms_after = VirtualMachine.list( - self.userapiclient, - id=vm_created.id - ) + self.userapiclient, + id=vm_created.id + ) status = validateList(list_vms_after) self.assertEquals( - PASS, - status[0], - "Listing of VM failed" - ) + PASS, + status[0], + "Listing of VM failed" + ) vm = list_vms_after[0] # Verifying that VM nics size is 1 now vm_nics_after = vm.nic self.assertIsNotNone( - vm_nics_after, - "Nic not found for the deployed VM" - ) + vm_nics_after, + "Nic not found for the deployed VM" + ) self.assertEquals( - 1, - len(vm_nics_after), - "VM NIC's count is not matching" - ) + 1, + len(vm_nics_after), + "VM NIC's count is not matching" + ) # Verifying the nic network is same as the default nic network self.assertEquals( - network2.id, - vm_nics_after[0].networkid, - "VM NIC is not same as expected" - ) + network2.id, + vm_nics_after[0].networkid, + "VM NIC is not same as expected" + ) return + class TestInstances(cloudstackTestCase): @classmethod @@ -1997,19 +2051,23 @@ class TestInstances(cloudstackTestCase): cls.hypervisor = cls.testClient.getHypervisorInfo() # Get Domain, Zone, Template cls.domain = get_domain(cls.api_client) - cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) + cls.zone = get_zone( + cls.api_client, + cls.testClient.getZoneForTests()) cls.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) + cls.api_client, + cls.zone.id, + cls.services["ostype"] + ) if cls.zone.localstorageenabled: cls.storagetype = 'local' - cls.services["service_offerings"]["tiny"]["storagetype"] = 'local' + cls.services["service_offerings"][ + "tiny"]["storagetype"] = 'local' cls.services["disk_offering"]["storagetype"] = 'local' else: cls.storagetype = 'shared' - cls.services["service_offerings"]["tiny"]["storagetype"] = 'shared' + cls.services["service_offerings"][ + "tiny"]["storagetype"] = 'shared' cls.services["disk_offering"]["storagetype"] = 'shared' cls.services['mode'] = cls.zone.networktype @@ -2020,30 +2078,32 @@ class TestInstances(cloudstackTestCase): # Creating Disk offering, Service Offering and Account cls.disk_offering = DiskOffering.create( - cls.api_client, - cls.services["disk_offering"] - ) + cls.api_client, + cls.services["disk_offering"] + ) cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offerings"]["tiny"] - ) + cls.api_client, + cls.services["service_offerings"]["tiny"] + ) cls.account = Account.create( - cls.api_client, - cls.services["account"], - domainid=cls.domain.id - ) + cls.api_client, + cls.services["account"], + domainid=cls.domain.id + ) # Getting authentication for user in newly created Account cls.user = cls.account.user[0] - cls.userapiclient = cls.testClient.getUserApiClient(cls.user.username, cls.domain.name) + cls.userapiclient = cls.testClient.getUserApiClient( + cls.user.username, + cls.domain.name) # Updating resource Limits for i in range(0, 8): Resources.updateLimit( - cls.api_client, - account=cls.account.name, - domainid=cls.domain.id, - max=-1, - resourcetype=i - ) + cls.api_client, + account=cls.account.name, + domainid=cls.domain.id, + max=-1, + resourcetype=i + ) cls._cleanup.append(cls.account) cls._cleanup.append(cls.service_offering) cls._cleanup.append(cls.disk_offering) @@ -2079,10 +2139,12 @@ class TestInstances(cloudstackTestCase): @Desc: Function to verify expected and actual values @Steps: Step1: Initializing return flag to True - Step1: Verifying length of expected and actual dictionaries is matching. + Step1: Verifying length of expected and actual + dictionaries is matching. If not matching returning false Step2: Listing all the keys from expected dictionary - Step3: Looping through each key from step2 and verifying expected and actual dictionaries have same value + Step3: Looping through each key from step2 and verifying expected + and actual dictionaries have same value If not making return flag to False Step4: returning the return flag after all the values are verified """ @@ -2099,10 +2161,10 @@ class TestInstances(cloudstackTestCase): return_flag = return_flag and True else: return_flag = return_flag and False - self.debug("expected Value: %s, is not matching with actual value: %s" % ( - exp_val, - act_val - )) + self.debug( + "expected Value: %s, is not matching\ + with actual value: %s" % + (exp_val, act_val)) return return_flag @attr(tags=["advanced", "basic"], required_hardware="true") @@ -2123,115 +2185,118 @@ class TestInstances(cloudstackTestCase): Step11: Verifying that detached ISO details are not associated with VM """ if self.hypervisor.lower() in ['kvm', 'hyperv']: - raise unittest.SkipTest("This feature is not supported on existing hypervisor. Hence, skipping the test") + raise unittest.SkipTest( + "This feature is not supported on existing hypervisor. Hence,\ + skipping the test") # Listing all the VM's for a User list_vms_before = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - page=1, - pagesize=self.services["pagesize"], - domainid=self.account.domainid, - zoneid=self.zone.id, - account=self.account.name - ) + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + zoneid=self.zone.id, + account=self.account.name + ) self.assertIsNone( - list_vms_before, - "Virtual Machine already exists for newly created user" - ) + list_vms_before, + "Virtual Machine already exists for newly created user" + ) # Deploying a VM vm_created = VirtualMachine.create( - self.userapiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - ) + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) self.assertIsNotNone( - vm_created, - "VM creation failed" - ) + vm_created, + "VM creation failed" + ) self.cleanup.append(vm_created) # Listing all the VMs for a user again for matching zone list_vms_after = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - page=1, - pagesize=self.services["pagesize"], - domainid=self.account.domainid, - zoneid=self.zone.id, - account=self.account.name - ) + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + zoneid=self.zone.id, + account=self.account.name + ) status = validateList(list_vms_after) self.assertEquals( - PASS, - status[0], - "VM creation failed" - ) + PASS, + status[0], + "VM creation failed" + ) # Verifying that the size of the list is 1 self.assertEquals( - 1, - len(list_vms_after), - "VM list count is not matching" - ) + 1, + len(list_vms_after), + "VM list count is not matching" + ) # Listing the ISO's in ready state isos_list = Iso.list( - self.userapiclient, - isready="true", - isofilter="executable", - zoneid=self.zone.id - ) + self.userapiclient, + isready="true", + isofilter="executable", + zoneid=self.zone.id + ) # Verifying if size of the list is >= 1 if isos_list is not None: iso_toattach = isos_list[0] # Attaching ISO listed to VM deployed VirtualMachine.attach_iso( - vm_created, - self.userapiclient, - iso_toattach - ) + vm_created, + self.userapiclient, + iso_toattach + ) list_vm = VirtualMachine.list( - self.userapiclient, - id=vm_created.id - ) + self.userapiclient, + id=vm_created.id + ) status = validateList(list_vm) self.assertEquals( - PASS, - status[0], - "VM listing by Id failed" - ) + PASS, + status[0], + "VM listing by Id failed" + ) # Verifying that attached ISO details are present in VM self.assertEquals( - iso_toattach.name, - list_vm[0].isoname, - "Attached ISO name is not matching" - ) + iso_toattach.name, + list_vm[0].isoname, + "Attached ISO name is not matching" + ) self.assertEquals( - iso_toattach.displaytext, - list_vm[0].isodisplaytext, - "Attached ISO display is not matching" - ) + iso_toattach.displaytext, + list_vm[0].isodisplaytext, + "Attached ISO display is not matching" + ) # Detaching ISO from VM VirtualMachine.detach_iso( - vm_created, - self.userapiclient - ) + vm_created, + self.userapiclient + ) list_vm = VirtualMachine.list( - self.userapiclient, - id=vm_created.id - ) + self.userapiclient, + id=vm_created.id + ) status = validateList(list_vm) self.assertEquals( - PASS, - status[0], - "VM listing by Id failed" - ) + PASS, + status[0], + "VM listing by Id failed" + ) # Verifying that ISO details are NOT present in VM self.assertIsNone( - list_vm[0].isoname, - "ISO not detached from VM" - ) + list_vm[0].isoname, + "ISO not detached from VM" + ) else: - self.fail("Executable ISO in Ready is not found in the given setup") + self.fail( + "Executable ISO in Ready is not found in the given setup") return @@ -2255,143 +2320,145 @@ class TestInstances(cloudstackTestCase): Step13: Verifying that size of the list is 0 """ if self.hypervisor.lower() in ['kvm', 'hyperv']: - raise unittest.SkipTest("This feature is not supported on existing hypervisor. Hence, skipping the test") + raise unittest.SkipTest( + "This feature is not supported on existing hypervisor. Hence,\ + skipping the test") # Listing all the VM's for a User list_vms_before = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - ) + self.userapiclient, + listall=self.services["listall"], + ) self.assertIsNone( - list_vms_before, - "Virtual Machine already exists for newly created user" - ) + list_vms_before, + "Virtual Machine already exists for newly created user" + ) # Deploying a VM vm_created = VirtualMachine.create( - self.userapiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - ) + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) self.assertIsNotNone( - vm_created, - "VM creation failed" - ) + vm_created, + "VM creation failed" + ) self.cleanup.append(vm_created) # Listing all the VMs for a user again list_vms_after = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - ) + self.userapiclient, + listall=self.services["listall"], + ) status = validateList(list_vms_after) self.assertEquals( - PASS, - status[0], - "VM creation failed" - ) + PASS, + status[0], + "VM creation failed" + ) # Verifying that the size of the list is 1 self.assertEquals( - 1, - len(list_vms_after), - "VM list count is not matching" - ) + 1, + len(list_vms_after), + "VM list count is not matching" + ) # Listing all the VM snapshots for VM deployed above list_snapshots_before = VmSnapshot.list( - self.userapiclient, - listall=self.services["listall"], - virtualmachineid=vm_created.id - ) + self.userapiclient, + listall=self.services["listall"], + virtualmachineid=vm_created.id + ) # Verifying that the VM snapshot list is None self.assertIsNone( - list_snapshots_before, - "Snapshots already exists for newly created VM" - ) + list_snapshots_before, + "Snapshots already exists for newly created VM" + ) # Creating pagesize + 1 number of VM snapshots for i in range(0, (self.services["pagesize"] + 1)): snapshot_created = VmSnapshot.create( - self.userapiclient, - vm_created.id, - ) + self.userapiclient, + vm_created.id, + ) self.assertIsNotNone( - snapshot_created, - "Snapshot creation failed" - ) + snapshot_created, + "Snapshot creation failed" + ) # Listing all the VM snapshots for VM again list_snapshots_after = VmSnapshot.list( - self.userapiclient, - listall=self.services["listall"], - virtualmachineid=vm_created.id - ) + self.userapiclient, + listall=self.services["listall"], + virtualmachineid=vm_created.id + ) status = validateList(list_snapshots_after) self.assertEquals( - PASS, - status[0], - "VM Snapshots creation failed" - ) + PASS, + status[0], + "VM Snapshots creation failed" + ) self.assertEquals( - self.services["pagesize"] + 1, - len(list_snapshots_after), - "Count of VM Snapshots is not matching" - ) + self.services["pagesize"] + 1, + len(list_snapshots_after), + "Count of VM Snapshots is not matching" + ) # Listing all the VM snapshots in Page 1 with page size list_snapshots_page1 = VmSnapshot.list( - self.userapiclient, - listall=self.services["listall"], - virtualmachineid=vm_created.id, - page=1, - pagesize=self.services["pagesize"], - ) + self.userapiclient, + listall=self.services["listall"], + virtualmachineid=vm_created.id, + page=1, + pagesize=self.services["pagesize"], + ) status = validateList(list_snapshots_page1) self.assertEquals( - PASS, - status[0], - "Listing of VM Snapshots failed in page 1" - ) + PASS, + status[0], + "Listing of VM Snapshots failed in page 1" + ) # Verifying the list size is equal to pagesize self.assertEquals( - self.services["pagesize"], - len(list_snapshots_page1), - "List VM Snapshot count is not matching in page 1" - ) + self.services["pagesize"], + len(list_snapshots_page1), + "List VM Snapshot count is not matching in page 1" + ) # Listing all the VM Snapshots in page 2 list_snapshots_page2 = VmSnapshot.list( - self.userapiclient, - listall=self.services["listall"], - virtualmachineid=vm_created.id, - page=2, - pagesize=self.services["pagesize"], - ) + self.userapiclient, + listall=self.services["listall"], + virtualmachineid=vm_created.id, + page=2, + pagesize=self.services["pagesize"], + ) status = validateList(list_snapshots_page2) self.assertEquals( - PASS, - status[0], - "Listing of VM Snapshots failed in page 2" - ) + PASS, + status[0], + "Listing of VM Snapshots failed in page 2" + ) # Verifying the list size is equal to 1 self.assertEquals( - 1, - len(list_snapshots_page2), - "List VM Snapshot count is not matching in page 2" - ) + 1, + len(list_snapshots_page2), + "List VM Snapshot count is not matching in page 2" + ) # Deleting VM Snapshot in page 2 VmSnapshot.deleteVMSnapshot( - self.userapiclient, - snapshot_created.id - ) + self.userapiclient, + snapshot_created.id + ) # Listing all the VM Snapshots in page 2 again list_snapshots_page2 = VmSnapshot.list( - self.userapiclient, - listall=self.services["listall"], - virtualmachineid=vm_created.id, - page=2, - pagesize=self.services["pagesize"], - ) + self.userapiclient, + listall=self.services["listall"], + virtualmachineid=vm_created.id, + page=2, + pagesize=self.services["pagesize"], + ) # Verifying the list size is equal to 0 self.assertIsNone( - list_snapshots_page2, - "VM Snapshots exists in page 2" - ) + list_snapshots_page2, + "VM Snapshots exists in page 2" + ) return @attr(tags=["advanced", "basic"], required_hardware="true") @@ -2406,97 +2473,103 @@ class TestInstances(cloudstackTestCase): Step5: Listing all the Snapshots of the VM deployed in Step 1 Step6: Verifying that the list size is 2 Step7: Verifying that only 1 snapshot is have current flag set to True - Step8: Verifying that the VM snapshot with current flag set as true is the latest snapshot created - Step9: Reverting VM to snapshot having current flag as false (non current snapshot) - Step10: Verifying that only 1 VM snapshot is having current flag set as true. - Step11: Verifying that the VM Snapshot with current flag set to true is the reverted snapshot in Step 8 + Step8: Verifying that the VM snapshot with current flag set as true is + the latest snapshot created + Step9: Reverting VM to snapshot having current flag as false + (non current snapshot) + Step10: Verifying that only 1 VM snapshot is having current + flag set as true. + Step11: Verifying that the VM Snapshot with current flag set to true + is the reverted snapshot in Step 8 """ if self.hypervisor.lower() in ['kvm', 'hyperv']: - raise unittest.SkipTest("This feature is not supported on existing hypervisor. Hence, skipping the test") + raise unittest.SkipTest( + "This feature is not supported on existing hypervisor.\ + Hence, skipping the test") # Listing all the VM's for a User list_vms_before = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - ) + self.userapiclient, + listall=self.services["listall"], + ) self.assertIsNone( - list_vms_before, - "Virtual Machine already exists for newly created user" - ) + list_vms_before, + "Virtual Machine already exists for newly created user" + ) # Deploying a VM vm_created = VirtualMachine.create( - self.userapiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - ) + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) self.assertIsNotNone( - vm_created, - "VM creation failed" - ) + vm_created, + "VM creation failed" + ) self.cleanup.append(vm_created) # Listing all the VMs for a user again list_vms_after = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - ) + self.userapiclient, + listall=self.services["listall"], + ) status = validateList(list_vms_after) self.assertEquals( - PASS, - status[0], - "VM creation failed" - ) + PASS, + status[0], + "VM creation failed" + ) # Verifying that the size of the list is 1 self.assertEquals( - 1, - len(list_vms_after), - "VM list count is not matching" - ) + 1, + len(list_vms_after), + "VM list count is not matching" + ) # Listing all the VM snapshots for VM deployed above list_snapshots_before = VmSnapshot.list( - self.userapiclient, - listall=self.services["listall"], - virtualmachineid=vm_created.id - ) + self.userapiclient, + listall=self.services["listall"], + virtualmachineid=vm_created.id + ) # Verifying that the VM snapshot list is None self.assertIsNone( - list_snapshots_before, - "Snapshots already exists for newly created VM" - ) + list_snapshots_before, + "Snapshots already exists for newly created VM" + ) # Creating 2 of VM snapshots snapshot1 = VmSnapshot.create( - self.userapiclient, - vm_created.id, - ) + self.userapiclient, + vm_created.id, + ) self.assertIsNotNone( - snapshot1, - "Snapshot creation failed" - ) + snapshot1, + "Snapshot creation failed" + ) snapshot2 = VmSnapshot.create( - self.userapiclient, - vm_created.id, - ) + self.userapiclient, + vm_created.id, + ) self.assertIsNotNone( - snapshot2, - "Snapshot creation failed" - ) + snapshot2, + "Snapshot creation failed" + ) # Listing all the VM snapshots for VM again list_snapshots_after = VmSnapshot.list( - self.userapiclient, - listall=self.services["listall"], - virtualmachineid=vm_created.id - ) + self.userapiclient, + listall=self.services["listall"], + virtualmachineid=vm_created.id + ) status = validateList(list_snapshots_after) self.assertEquals( - PASS, - status[0], - "VM Snapshots creation failed" - ) + PASS, + status[0], + "VM Snapshots creation failed" + ) self.assertEquals( - 2, - len(list_snapshots_after), - "Count of VM Snapshots is not matching" - ) + 2, + len(list_snapshots_after), + "Count of VM Snapshots is not matching" + ) # Verifying that only 1 snapshot is having current flag set to true # and that snapshot is the latest snapshot created (snapshot2) current_count = 0 @@ -2506,37 +2579,37 @@ class TestInstances(cloudstackTestCase): current_snapshot = list_snapshots_after[i] self.assertEquals( - 1, - current_count, - "count of VM Snapshot with current flag as true is not matching" - ) + 1, + current_count, + "count of VM Snapshot with current flag as true is not matching" + ) self.assertEquals( - snapshot2.id, - current_snapshot.id, - "Latest snapshot taken is not marked as current" - ) + snapshot2.id, + current_snapshot.id, + "Latest snapshot taken is not marked as current" + ) # Reverting the VM to Snapshot 1 VmSnapshot.revertToSnapshot( - self.userapiclient, - snapshot1.id - ) + self.userapiclient, + snapshot1.id + ) # Listing the VM snapshots again list_snapshots_after = VmSnapshot.list( - self.userapiclient, - listall=self.services["listall"], - virtualmachineid=vm_created.id - ) + self.userapiclient, + listall=self.services["listall"], + virtualmachineid=vm_created.id + ) status = validateList(list_snapshots_after) self.assertEquals( - PASS, - status[0], - "VM Snapshots creation failed" - ) + PASS, + status[0], + "VM Snapshots creation failed" + ) self.assertEquals( - 2, - len(list_snapshots_after), - "Count of VM Snapshots is not matching" - ) + 2, + len(list_snapshots_after), + "Count of VM Snapshots is not matching" + ) # Verifying that only 1 snapshot is having current flag set to true # and that snapshot is snapshot1 current_count = 0 @@ -2545,15 +2618,15 @@ class TestInstances(cloudstackTestCase): current_count = current_count + 1 current_snapshot = list_snapshots_after[i] self.assertEquals( - 1, - current_count, - "count of VM Snapshot with current flag as true is not matching" - ) + 1, + current_count, + "count of VM Snapshot with current flag as true is not matching" + ) self.assertEquals( - snapshot1.id, - current_snapshot.id, - "Current flag was set properly after reverting the VM to snapshot" - ) + snapshot1.id, + current_snapshot.id, + "Current flag was set properly after reverting the VM to snapshot" + ) return @attr(tags=["advanced", "basic"], required_hardware="false") @@ -2565,7 +2638,8 @@ class TestInstances(cloudstackTestCase): Step2: Listing all the Volumes of the VM deployed in Step 1 Step3: Verifying that the list size is 1 Step4: Creating page size number of volumes - Step5: Attaching all the volumes created in step4 to VM deployed in Step1 + Step5: Attaching all the volumes created in step4 to + VM deployed in Step1 Step6: Listing all the Volumes for the VM in step1 Step7: Verifying that the list size is equal to page size + 1 Step8: Listing all the volumes of VM in page 1 @@ -2578,176 +2652,176 @@ class TestInstances(cloudstackTestCase): """ # Listing all the VM's for a User list_vms_before = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - ) + self.userapiclient, + listall=self.services["listall"], + ) self.assertIsNone( - list_vms_before, - "Virtual Machine already exists for newly created user" - ) + list_vms_before, + "Virtual Machine already exists for newly created user" + ) # Deploying a VM vm_created = VirtualMachine.create( - self.userapiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - ) + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) self.assertIsNotNone( - vm_created, - "VM creation failed" - ) + vm_created, + "VM creation failed" + ) self.cleanup.append(vm_created) # Listing all the VMs for a user again list_vms_after = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - ) + self.userapiclient, + listall=self.services["listall"], + ) status = validateList(list_vms_after) self.assertEquals( - PASS, - status[0], - "VM creation failed" - ) + PASS, + status[0], + "VM creation failed" + ) # Verifying that the size of the list is 1 self.assertEquals( - 1, - len(list_vms_after), - "VM list count is not matching" - ) + 1, + len(list_vms_after), + "VM list count is not matching" + ) # Listing all the Volumes for the VM deployed list_volumes_before = Volume.list( - self.userapiclient, - listall=self.services["listall"], - virtualmachineid=vm_created.id - ) + self.userapiclient, + listall=self.services["listall"], + virtualmachineid=vm_created.id + ) status = validateList(list_volumes_before) self.assertEquals( - PASS, - status[0], - "Root volume is not created for VM deployed" - ) + PASS, + status[0], + "Root volume is not created for VM deployed" + ) # Verifying the size of the list is 1 self.assertEquals( - 1, - len(list_volumes_before), - "Volumes count is not matching" - ) + 1, + len(list_volumes_before), + "Volumes count is not matching" + ) # Creating Page size number of volumes for i in range(0, self.services["pagesize"]): volume_created = Volume.create( - self.userapiclient, - self.services["volume"], - zoneid=self.zone.id, - diskofferingid=self.disk_offering.id - ) + self.userapiclient, + self.services["volume"], + zoneid=self.zone.id, + diskofferingid=self.disk_offering.id + ) self.assertIsNotNone( - volume_created, - "Volume is not created" - ) + volume_created, + "Volume is not created" + ) self.cleanup.append(volume_created) # Attaching all the volumes created to VM vm_created.attach_volume( - self.userapiclient, - volume_created - ) + self.userapiclient, + volume_created + ) # List all the volumes for the VM again list_volumes_after = Volume.list( - self.userapiclient, - listall=self.services["listall"], - virtualmachineid=vm_created.id - ) + self.userapiclient, + listall=self.services["listall"], + virtualmachineid=vm_created.id + ) status = validateList(list_volumes_after) self.assertEquals( - PASS, - status[0], - "Volumes are not listed" - ) + PASS, + status[0], + "Volumes are not listed" + ) # Verifying that size of the list is equal to page size + 1 self.assertEquals( - self.services["pagesize"] + 1, - len(list_volumes_after), - "VM's volume count is not matching" - ) + self.services["pagesize"] + 1, + len(list_volumes_after), + "VM's volume count is not matching" + ) # Listing all the volumes for a VM in page 1 list_volumes_page1 = Volume.list( - self.userapiclient, - listall=self.services["listall"], - virtualmachineid=vm_created.id, - page=1, - pagesize=self.services["pagesize"] - ) + self.userapiclient, + listall=self.services["listall"], + virtualmachineid=vm_created.id, + page=1, + pagesize=self.services["pagesize"] + ) status = validateList(list_volumes_page1) self.assertEquals( - PASS, - status[0], - "Volumes not listed in page1" - ) + PASS, + status[0], + "Volumes not listed in page1" + ) # Verifying that list size is equal to page size self.assertEquals( - self.services["pagesize"], - len(list_volumes_page1), - "VM's volume count is not matching in page 1" - ) + self.services["pagesize"], + len(list_volumes_page1), + "VM's volume count is not matching in page 1" + ) # Listing all the volumes for a VM in page 2 list_volumes_page2 = Volume.list( - self.userapiclient, - listall=self.services["listall"], - virtualmachineid=vm_created.id, - page=2, - pagesize=self.services["pagesize"] - ) + self.userapiclient, + listall=self.services["listall"], + virtualmachineid=vm_created.id, + page=2, + pagesize=self.services["pagesize"] + ) status = validateList(list_volumes_page2) self.assertEquals( - PASS, - status[0], - "Volumes not listed in page2" - ) + PASS, + status[0], + "Volumes not listed in page2" + ) # Verifying that list size is equal to 1 self.assertEquals( - 1, - len(list_volumes_page2), - "VM's volume count is not matching in page 1" - ) + 1, + len(list_volumes_page2), + "VM's volume count is not matching in page 1" + ) # Detaching 1 volume from VM vm_created.detach_volume( - self.userapiclient, - volume_created - ) + self.userapiclient, + volume_created + ) # Listing all the volumes for a VM in page 2 again list_volumes_page2 = Volume.list( - self.userapiclient, - listall=self.services["listall"], - virtualmachineid=vm_created.id, - page=2, - pagesize=self.services["pagesize"] - ) + self.userapiclient, + listall=self.services["listall"], + virtualmachineid=vm_created.id, + page=2, + pagesize=self.services["pagesize"] + ) # Verifying that there are no volumes present in page 2 self.assertIsNone( - list_volumes_page2, - "Volumes listed in page 2" - ) + list_volumes_page2, + "Volumes listed in page 2" + ) # Listing all the volumes for a VM again in page 1 list_volumes_page1 = Volume.list( - self.userapiclient, - listall=self.services["listall"], - virtualmachineid=vm_created.id, - page=1, - pagesize=self.services["pagesize"] - ) + self.userapiclient, + listall=self.services["listall"], + virtualmachineid=vm_created.id, + page=1, + pagesize=self.services["pagesize"] + ) status = validateList(list_volumes_page1) self.assertEquals( - PASS, - status[0], - "Volumes not listed in page1" - ) + PASS, + status[0], + "Volumes not listed in page1" + ) # Verifying that list size is equal to page size self.assertEquals( - self.services["pagesize"], - len(list_volumes_page1), - "VM's volume count is not matching in page 1" - ) + self.services["pagesize"], + len(list_volumes_page1), + "VM's volume count is not matching in page 1" + ) # stopping VM before detaching volumes vm_created.stop(self.userapiclient) @@ -2756,9 +2830,9 @@ class TestInstances(cloudstackTestCase): # Detaching all the volumes attached from VM for i in range(0, len(list_volumes_page1)): vm_created.detach_volume( - self.userapiclient, - list_volumes_page1[i] - ) + self.userapiclient, + list_volumes_page1[i] + ) return @attr(tags=["advanced", "basic"], required_hardware="true") @@ -2766,139 +2840,158 @@ class TestInstances(cloudstackTestCase): """ @Desc: Test to verify change service for Running VM @Steps: - Step1: Checking if dynamic scaling of virtual machines is enabled in zone and template. - If yes then continuing. - If not then printing message that scale up is not possible for Running VM + Step1: Checking if dynamic scaling of virtual machines is + enabled in zone and template. + If yes then continuing. + If not then printing message that scale up is + not possible for Running VM Step2: Deploying a VM Step3: Listing all the existing service offerings - Step4: If there is a matching Service Offering for scale-up of running VM - use that service offering. If not create one service offering for scale up. - Step5: Perform change service (scale up) the Running VM deployed in step1 + Step4: If there is a matching Service Offering for scale-up of + running VM + use that service offering. If not create one + service offering for scale up. + Step5: Perform change service (scale up) the Running VM + deployed in step1 Step6: Verifying that VM's service offerings is changed """ if self.hypervisor.lower() == 'kvm': - raise unittest.SkipTest("ScaleVM is not supported on KVM. Hence, skipping the test") + raise unittest.SkipTest( + "ScaleVM is not supported on KVM. Hence, skipping the test") # Checking if Dynamic scaling of VM is supported or not list_config = Configurations.list( - self.apiClient, - zoneid=self.zone.id, - name="enable.dynamic.scale.vm" - ) + self.apiClient, + zoneid=self.zone.id, + name="enable.dynamic.scale.vm" + ) status = validateList(list_config) self.assertEquals( - PASS, - status[0], - "Listing of configuration failed" - ) + PASS, + status[0], + "Listing of configuration failed" + ) # Checking if dynamic scaling is allowed in Zone and Template - if not ((list_config[0].value is True) and (self.template.isdynamicallyscalable)): - self.debug("Scale up of Running VM is not possible as Zone/Template does not support") + if not ( + (list_config[0].value is True) and ( + self.template.isdynamicallyscalable)): + self.debug( + "Scale up of Running VM is not possible as Zone/Template\ + does not support") else: # Listing all the VM's for a User list_vms_before = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - ) + self.userapiclient, + listall=self.services["listall"], + ) self.assertIsNone( - list_vms_before, - "Virtual Machine already exists for newly created user" - ) + list_vms_before, + "Virtual Machine already exists for newly created user" + ) # Deploying a VM vm_created = VirtualMachine.create( - self.userapiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - ) + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) self.assertIsNotNone( - vm_created, - "VM creation failed" - ) + vm_created, + "VM creation failed" + ) self.cleanup.append(vm_created) # Listing details of current Service Offering vm_so_list = ServiceOffering.list( - self.userapiclient, - id=vm_created.serviceofferingid - ) + self.userapiclient, + id=vm_created.serviceofferingid + ) status = validateList(vm_so_list) self.assertEquals( - PASS, - status[0], - "Listing of VM Service offering failed" - ) + PASS, + status[0], + "Listing of VM Service offering failed" + ) current_so = vm_so_list[0] # Listing all the VMs for a user again list_vms_after = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - ) + self.userapiclient, + listall=self.services["listall"], + ) status = validateList(list_vms_after) self.assertEquals( - PASS, - status[0], - "VM creation failed" - ) + PASS, + status[0], + "VM creation failed" + ) # Verifying that the size of the list is 1 self.assertEquals( - 1, - len(list_vms_after), - "VM list count is not matching" - ) + 1, + len(list_vms_after), + "VM list count is not matching" + ) # Listing all the existing service offerings service_offerings_list = ServiceOffering.list( - self.userapiclient, - virtualmachineid=vm_created.id - ) + self.userapiclient, + virtualmachineid=vm_created.id + ) # Verifying if any Service offering available for scale up of VM so_exists = False if service_offerings_list is not None: for i in range(0, len(service_offerings_list)): - if not ((current_so.cpunumber > service_offerings_list[i].cpunumber or\ - current_so.cpuspeed > service_offerings_list[i].cpuspeed or\ - current_so.memory > service_offerings_list[i].memory) or\ - (current_so.cpunumber == service_offerings_list[i].cpunumber and\ - current_so.cpuspeed == service_offerings_list[i].cpuspeed and\ - current_so.memory == service_offerings_list[i].memory)): - if(current_so.storagetype == service_offerings_list[i].storagetype): - so_exists = True - new_so = service_offerings_list[i] - break - # If service offering does not exists, then creating one service offering for scale up + if not ((current_so.cpunumber > + service_offerings_list[i].cpunumber or + current_so.cpuspeed > + service_offerings_list[i].cpuspeed or + current_so.memory > + service_offerings_list[i].memory) or + (current_so.cpunumber == + service_offerings_list[i].cpunumber and + current_so.cpuspeed == + service_offerings_list[i].cpuspeed and + current_so.memory == + service_offerings_list[i].memory)): + if(current_so.storagetype == + service_offerings_list[i].storagetype): + so_exists = True + new_so = service_offerings_list[i] + break + # If service offering does not exists, then creating one service + # offering for scale up if not so_exists: - self.services["service_offerings"]["small"]["storagetype"] = current_so.storagetype + self.services["service_offerings"]["small"][ + "storagetype"] = current_so.storagetype new_so = ServiceOffering.create( - self.apiClient, - self.services["service_offerings"]["small"] - ) + self.apiClient, + self.services["service_offerings"]["small"] + ) self.cleanup.append(new_so) # Scaling up the VM vm_created.scale_virtualmachine( - self.userapiclient, - new_so.id - ) + self.userapiclient, + new_so.id + ) # Listing VM details again list_vms_after = VirtualMachine.list( - self.userapiclient, - id=vm_created.id - ) + self.userapiclient, + id=vm_created.id + ) status = validateList(list_vms_after) self.assertEquals( - PASS, - status[0], - "Listing of VM failed" - ) + PASS, + status[0], + "Listing of VM failed" + ) self.assertEquals( - 1, - len(list_vms_after), - "VMs list is not as expected" - ) + 1, + len(list_vms_after), + "VMs list is not as expected" + ) # Verifying that VM's service offerings is changed self.assertEquals( - new_so.id, - list_vms_after[0].serviceofferingid, - "VM is not containing New Service Offering" - ) + new_so.id, + list_vms_after[0].serviceofferingid, + "VM is not containing New Service Offering" + ) return @attr(tags=["advanced", "basic"], required_hardware="true") @@ -2909,116 +3002,121 @@ class TestInstances(cloudstackTestCase): Step1: Deploying a VM Step2: Stopping the VM deployed in step1 Step3: Listing all the existing service offerings - Step4: If there is a matching Service Offering for change service of stopped VM - use that service offering. If not create one service offering for change service. + Step4: If there is a matching Service Offering for change service + of stopped VM + use that service offering. If not create one service + offering for change service. Step5: Perform change service for the Stopped VM Step6: Verifying that VM's service offerings is changed """ # Listing all the VM's for a User list_vms_before = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - ) + self.userapiclient, + listall=self.services["listall"], + ) self.assertIsNone( - list_vms_before, - "Virtual Machine already exists for newly created user" - ) + list_vms_before, + "Virtual Machine already exists for newly created user" + ) # Deploying a VM vm_created = VirtualMachine.create( - self.userapiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - ) + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) self.assertIsNotNone( - vm_created, - "VM creation failed" - ) + vm_created, + "VM creation failed" + ) self.cleanup.append(vm_created) # Listing details of current Service Offering vm_so_list = ServiceOffering.list( - self.userapiclient, - id=vm_created.serviceofferingid - ) + self.userapiclient, + id=vm_created.serviceofferingid + ) status = validateList(vm_so_list) self.assertEquals( - PASS, - status[0], - "Listing of VM Service offering failed" - ) + PASS, + status[0], + "Listing of VM Service offering failed" + ) current_so = vm_so_list[0] # Listing all the VMs for a user again list_vms_after = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - ) + self.userapiclient, + listall=self.services["listall"], + ) status = validateList(list_vms_after) self.assertEquals( - PASS, - status[0], - "VM creation failed" - ) + PASS, + status[0], + "VM creation failed" + ) # Verifying that the size of the list is 1 self.assertEquals( - 1, - len(list_vms_after), - "VM list count is not matching" - ) + 1, + len(list_vms_after), + "VM list count is not matching" + ) # Stopping the VM deployed above vm_created.stop( - self.userapiclient, - forced=True - ) + self.userapiclient, + forced=True + ) # Listing all the service offerings service_offerings_list = ServiceOffering.list( - self.userapiclient, - virtualmachineid=vm_created.id - ) + self.userapiclient, + virtualmachineid=vm_created.id + ) # Verifying if any Service offering available for change service of VM so_exists = False if service_offerings_list is not None: for i in range(0, len(service_offerings_list)): - if ((current_so.id != service_offerings_list[i].id) and\ - (current_so.storagetype == service_offerings_list[i].storagetype)): + if ((current_so.id != service_offerings_list[i].id) and ( + current_so.storagetype == + service_offerings_list[i].storagetype)): so_exists = True new_so = service_offerings_list[i] break - # If service offering does not exists, then creating one service offering for scale up + # If service offering does not exists, then creating one service + # offering for scale up if not so_exists: - self.services["service_offerings"]["small"]["storagetype"] = current_so.storagetype + self.services["service_offerings"]["small"][ + "storagetype"] = current_so.storagetype new_so = ServiceOffering.create( - self.apiClient, - self.services["service_offerings"]["small"] - ) + self.apiClient, + self.services["service_offerings"]["small"] + ) self.cleanup.append(new_so) # Changing service for the VM vm_created.scale_virtualmachine( - self.userapiclient, - new_so.id - ) + self.userapiclient, + new_so.id + ) # Listing VM details again list_vm = VirtualMachine.list( - self.userapiclient, - id=vm_created.id - ) + self.userapiclient, + id=vm_created.id + ) status = validateList(list_vm) self.assertEquals( - PASS, - status[0], - "Listing of VM failed" - ) + PASS, + status[0], + "Listing of VM failed" + ) self.assertEquals( - 1, - len(list_vm), - "VMs list is not as expected" - ) + 1, + len(list_vm), + "VMs list is not as expected" + ) # Verifying that VM's service offerings is changed self.assertEquals( - new_so.id, - list_vm[0].serviceofferingid, - "VM is not containing New Service Offering" - ) + new_so.id, + list_vm[0].serviceofferingid, + "VM is not containing New Service Offering" + ) return @attr(tags=["advanced", "basic"], required_hardware="true") @@ -3037,115 +3135,115 @@ class TestInstances(cloudstackTestCase): """ # Listing all the VM's for a User list_vms_before = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - ) + self.userapiclient, + listall=self.services["listall"], + ) self.assertIsNone( - list_vms_before, - "Virtual Machine already exists for newly created user" - ) + list_vms_before, + "Virtual Machine already exists for newly created user" + ) # Deploying a VM vm_created = VirtualMachine.create( - self.userapiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - ) + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) self.assertIsNotNone( - vm_created, - "VM creation failed" - ) + vm_created, + "VM creation failed" + ) self.cleanup.append(vm_created) # Listing all the VMs for a user again list_vms_after = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - ) + self.userapiclient, + listall=self.services["listall"], + ) status = validateList(list_vms_after) self.assertEquals( - PASS, - status[0], - "VM creation failed" - ) + PASS, + status[0], + "VM creation failed" + ) # Verifying that the size of the list is 1 self.assertEquals( - 1, - len(list_vms_after), - "VM list count is not matching" - ) + 1, + len(list_vms_after), + "VM list count is not matching" + ) # Stopping the VM deployed above vm_created.stop( - self.userapiclient, - forced=True - ) + self.userapiclient, + forced=True + ) # Listing all the SSH Key pairs list_keypairs_before = SSHKeyPair.list( - self.userapiclient - ) + self.userapiclient + ) list_keypairs_before_size = 0 if list_keypairs_before is not None: list_keypairs_before_size = len(list_keypairs_before) # Creating a new Key pair new_keypair = SSHKeyPair.create( - self.userapiclient, - name="keypair1", - account=self.account.name, - domainid=self.domain.id - ) + self.userapiclient, + name="keypair1", + account=self.account.name, + domainid=self.domain.id + ) self.assertIsNotNone( - new_keypair, - "New Key pair generation failed" - ) + new_keypair, + "New Key pair generation failed" + ) self.assertEquals( - "keypair1", - new_keypair.name, - "Key Pair not created with given name" - ) + "keypair1", + new_keypair.name, + "Key Pair not created with given name" + ) # Listing all the SSH Key pairs again list_keypairs_after = SSHKeyPair.list( - self.userapiclient - ) + self.userapiclient + ) status = validateList(list_keypairs_after) self.assertEquals( - PASS, - status[0], - "Listing of Key pairs failed" - ) + PASS, + status[0], + "Listing of Key pairs failed" + ) # Verifying that list size is increased by 1 self.assertEquals( - list_keypairs_before_size + 1, - len(list_keypairs_after), - "List count is not matching" - ) + list_keypairs_before_size + 1, + len(list_keypairs_after), + "List count is not matching" + ) # Resetting the VM SSH key to the Key pair created above vm_created.resetSshKey( - self.userapiclient, - keypair=new_keypair.name - ) + self.userapiclient, + keypair=new_keypair.name + ) # Listing VM details again list_vm = VirtualMachine.list( - self.userapiclient, - id=vm_created.id - ) + self.userapiclient, + id=vm_created.id + ) status = validateList(list_vm) self.assertEquals( - PASS, - status[0], - "Listing of VM failed" - ) + PASS, + status[0], + "Listing of VM failed" + ) self.assertEquals( - 1, - len(list_vm), - "VMs list is not as expected" - ) + 1, + len(list_vm), + "VMs list is not as expected" + ) # Verifying that VM's SSH keypair is set to newly created keypair self.assertEquals( - new_keypair.name, - list_vm[0].keypair, - "VM is not set to newly created SSH Key pair" - ) + new_keypair.name, + list_vm[0].keypair, + "VM is not set to newly created SSH Key pair" + ) return @attr(tags=["advanced", "basic"], required_hardware="false") @@ -3163,90 +3261,90 @@ class TestInstances(cloudstackTestCase): """ # Listing all the VM's for a User list_vms_before = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - ) + self.userapiclient, + listall=self.services["listall"], + ) self.assertIsNone( - list_vms_before, - "Virtual Machine already exists for newly created user" - ) + list_vms_before, + "Virtual Machine already exists for newly created user" + ) self.services["virtual_machine"]["keyboard"] = "us" # Deploying a VM vm_created = VirtualMachine.create( - self.userapiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - group="groupName" - ) + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + group="groupName" + ) self.assertIsNotNone( - vm_created, - "VM creation failed" - ) + vm_created, + "VM creation failed" + ) self.cleanup.append(vm_created) # Verifying the displayname and group details for deployed VM self.assertEquals( - self.services["virtual_machine"]["displayname"], - vm_created.displayname, - "Display name of VM is not as expected" - ) + self.services["virtual_machine"]["displayname"], + vm_created.displayname, + "Display name of VM is not as expected" + ) self.assertEquals( - "groupName", - vm_created.group, - "Group of VM is not as expected" - ) + "groupName", + vm_created.group, + "Group of VM is not as expected" + ) # Listing all the VMs for a user again list_vms_after = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - ) + self.userapiclient, + listall=self.services["listall"], + ) status = validateList(list_vms_after) self.assertEquals( - PASS, - status[0], - "VM creation failed" - ) + PASS, + status[0], + "VM creation failed" + ) # Verifying that the size of the list is 1 self.assertEquals( - 1, - len(list_vms_after), - "VM list count is not matching" - ) + 1, + len(list_vms_after), + "VM list count is not matching" + ) # Updating the VM details - displayname and group vm_created.update( - self.userapiclient, - displayname="DisplayName", - group="Group", - haenable=False - ) + self.userapiclient, + displayname="DisplayName", + group="Group", + haenable=False + ) # Listing VM details again list_vm = VirtualMachine.list( - self.userapiclient, - id=vm_created.id, - ) + self.userapiclient, + id=vm_created.id, + ) status = validateList(list_vm) self.assertEquals( - PASS, - status[0], - "Listing of VM by Id failed" - ) + PASS, + status[0], + "Listing of VM by Id failed" + ) self.assertEquals( - 1, - len(list_vm), - "Count of List VM by Id is not matching" - ) + 1, + len(list_vm), + "Count of List VM by Id is not matching" + ) # Verifying that displayname and group details are updated self.assertEquals( - "DisplayName", - list_vm[0].displayname, - "Displayname of VM is not updated" - ) + "DisplayName", + list_vm[0].displayname, + "Displayname of VM is not updated" + ) self.assertEquals( - "Group", - list_vm[0].group, - "Group of VM is not updated" - ) + "Group", + list_vm[0].group, + "Group of VM is not updated" + ) return @attr(tags=["advanced", "basic"], required_hardware="true") @@ -3259,81 +3357,82 @@ class TestInstances(cloudstackTestCase): Step3: Listing all the VM's again for the user Step4: Verifying that list size is increased by 1 Step5: Restoring the VM deployed in step2 - Step6: Verifying that restored VM details are same as the VM deployed in step2 + Step6: Verifying that restored VM details are same as + the VM deployed in step2 """ # Listing all the VM's for a User list_vms_before = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - ) + self.userapiclient, + listall=self.services["listall"], + ) self.assertIsNone( - list_vms_before, - "Virtual Machine already exists for newly created user" - ) + list_vms_before, + "Virtual Machine already exists for newly created user" + ) # Deploying a VM vm_created = VirtualMachine.create( - self.userapiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - ) + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) self.assertIsNotNone( - vm_created, - "VM creation failed" - ) + vm_created, + "VM creation failed" + ) self.cleanup.append(vm_created) # Listing all the VMs for a user again list_vms_after = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - ) + self.userapiclient, + listall=self.services["listall"], + ) status = validateList(list_vms_after) self.assertEquals( - PASS, - status[0], - "VM creation failed" - ) + PASS, + status[0], + "VM creation failed" + ) # Verifying that the size of the list is 1 self.assertEquals( - 1, - len(list_vms_after), - "VM list count is not matching" - ) + 1, + len(list_vms_after), + "VM list count is not matching" + ) # Restoring the VM restored_vm = vm_created.restore(self.userapiclient) self.assertIsNotNone( - restored_vm, - "VM restore failed" - ) + restored_vm, + "VM restore failed" + ) # Verifying the restored VM details expected_dict = { - "id":vm_created.id, - "name":vm_created.name, - "displayname":vm_created.displayname, - "state":vm_created.state, - "zoneid":vm_created.zoneid, - "account":vm_created.account, - "template":vm_created.templateid - } + "id": vm_created.id, + "name": vm_created.name, + "displayname": vm_created.displayname, + "state": vm_created.state, + "zoneid": vm_created.zoneid, + "account": vm_created.account, + "template": vm_created.templateid + } actual_dict = { - "id":restored_vm.id, - "name":restored_vm.name, - "displayname":restored_vm.displayname, - "state":restored_vm.state, - "zoneid":restored_vm.zoneid, - "account":restored_vm.account, - "template":restored_vm.templateid - } + "id": restored_vm.id, + "name": restored_vm.name, + "displayname": restored_vm.displayname, + "state": restored_vm.state, + "zoneid": restored_vm.zoneid, + "account": restored_vm.account, + "template": restored_vm.templateid + } restored_vm_status = self.__verify_values( - expected_dict, - actual_dict - ) + expected_dict, + actual_dict + ) self.assertEqual( - True, - restored_vm_status, - "Restored VM details are not as expected" - ) + True, + restored_vm_status, + "Restored VM details are not as expected" + ) return @attr(tags=["advanced"], required_hardware="false") @@ -3342,7 +3441,8 @@ class TestInstances(cloudstackTestCase): @Desc: Test to verify deploy VM with multiple networks @Steps: Step1: List all the networks for user - Step2: If size of list networks is greater than 2 then get all the networks id's + Step2: If size of list networks is greater than 2 then + get all the networks id's Else create 2 networks and get network id's Step3: List all the VM's for a user Step4: Deploy a VM with multiple network id's @@ -3352,122 +3452,123 @@ class TestInstances(cloudstackTestCase): """ # Listing all the networks available networks_list_before = Network.list( - self.userapiclient, - listall=self.services["listall"], - type="Isolated" - ) + self.userapiclient, + listall=self.services["listall"], + type="Isolated" + ) networks_list_size = 0 if networks_list_before is not None: networks_list_size = len(networks_list_before) # Listing Network Offerings network_offerings_list = NetworkOffering.list( - self.apiClient, - forvpc="false", - guestiptype="Isolated", - state="Enabled", - supportedservices="SourceNat", - zoneid=self.zone.id - ) + self.apiClient, + forvpc="false", + guestiptype="Isolated", + state="Enabled", + supportedservices="SourceNat", + zoneid=self.zone.id + ) status = validateList(network_offerings_list) self.assertEquals( - PASS, - status[0], - "Isolated Network Offerings with sourceNat enabled are not found" - ) + PASS, + status[0], + "Isolated Network Offerings with sourceNat enabled are not found" + ) while networks_list_size < 2: # Creating a network network = Network.create( - self.userapiclient, - self.services["network"], - accountid=self.account.name, - domainid=self.domain.id, - networkofferingid=network_offerings_list[0].id, - zoneid=self.zone.id - ) + self.userapiclient, + self.services["network"], + accountid=self.account.name, + domainid=self.domain.id, + networkofferingid=network_offerings_list[0].id, + zoneid=self.zone.id + ) self.assertIsNotNone( - network, - "Network creation failed" - ) + network, + "Network creation failed" + ) self.cleanup.append(network) networks_list_size = networks_list_size + 1 # Listing the networks again networks_list_after = Network.list( - self.userapiclient, - listall=self.services["listall"], - type="Isolated" - ) + self.userapiclient, + listall=self.services["listall"], + type="Isolated" + ) status = validateList(network_offerings_list) self.assertEquals( - PASS, - status[0], - "Listing networks failed" - ) + PASS, + status[0], + "Listing networks failed" + ) # populating network id's - networkids = networks_list_after[0].id + "," + networks_list_after[1].id + networkids = networks_list_after[ + 0].id + "," + networks_list_after[1].id # Listing all the VM's for a User list_vms_before = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - ) + self.userapiclient, + listall=self.services["listall"], + ) self.assertIsNone( - list_vms_before, - "Virtual Machine already exists for newly created user" - ) + list_vms_before, + "Virtual Machine already exists for newly created user" + ) # Deploying a VM vm_created = VirtualMachine.create( - self.userapiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - networkids=networkids, - serviceofferingid=self.service_offering.id, - ) + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + networkids=networkids, + serviceofferingid=self.service_offering.id, + ) self.assertIsNotNone( - vm_created, - "VM creation failed" - ) + vm_created, + "VM creation failed" + ) self.cleanup.insert(-2, vm_created) # Listing all the VMs for a user again list_vms_after = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - ) + self.userapiclient, + listall=self.services["listall"], + ) status = validateList(list_vms_after) self.assertEquals( - PASS, - status[0], - "VM creation failed" - ) + PASS, + status[0], + "VM creation failed" + ) # Verifying that the size of the list is 1 self.assertEquals( - 1, - len(list_vms_after), - "VM list count is not matching" - ) + 1, + len(list_vms_after), + "VM list count is not matching" + ) # Verifying that the NIC's in VM created are same as provided vm_nics = vm_created.nic # Verifying that the size of nics is 2 self.assertEquals( - 2, - len(vm_nics), - "NIC's count in VM created is not matching" - ) + 2, + len(vm_nics), + "NIC's count in VM created is not matching" + ) # Verifying that NIC network ID's are as expected for i in range(0, len(vm_nics)): if vm_nics[i].isdefault is True: self.assertEquals( - networks_list_after[0].id, - vm_nics[i].networkid, - "Default NIC is not as expected" - ) + networks_list_after[0].id, + vm_nics[i].networkid, + "Default NIC is not as expected" + ) else: self.assertEquals( - networks_list_after[1].id, - vm_nics[i].networkid, - "Non Default NIC is not as expected" - ) + networks_list_after[1].id, + vm_nics[i].networkid, + "Non Default NIC is not as expected" + ) return @attr(tags=["basic"], required_hardware="true") @@ -3476,8 +3577,9 @@ class TestInstances(cloudstackTestCase): @Desc: Test to verify deploy VM with multiple Security Groups @Steps: Step1: List all the security groups for user - Step2: If size of list security groups is greater than 2 then get all the security groups id's - Else creating 2 security groups and get security groups id's + Step2: If size of list security groups is greater than 2 then get + all the security groups id's + Else creating 2 security groups and get security groups id's Step3: List all the VM's for a user Step4: Deploy a VM with multiple security groups id's Step5: Listing all the VM's again for the user @@ -3486,10 +3588,10 @@ class TestInstances(cloudstackTestCase): """ # Listing all the security groups available security_groups_list = SecurityGroup.list( - self.userapiclient, - listall=self.services["listall"], - domainid=self.domain.id - ) + self.userapiclient, + listall=self.services["listall"], + domainid=self.domain.id + ) security_groups_list_size = 0 if security_groups_list is not None: security_groups_list_size = len(security_groups_list) @@ -3497,93 +3599,96 @@ class TestInstances(cloudstackTestCase): while security_groups_list_size < 2: # Creating a security group security_group = SecurityGroup.create( - self.userapiclient, - self.services["security_group"], - account=self.account.name, - domainid=self.domain.id - ) + self.userapiclient, + self.services["security_group"], + account=self.account.name, + domainid=self.domain.id + ) self.assertIsNotNone( - security_group, - "Security Group creation failed" - ) + security_group, + "Security Group creation failed" + ) self.cleanup.append(security_group) security_groups_list_size = security_groups_list_size + 1 # Listing the networks again security_groups_list = SecurityGroup.list( - self.userapiclient, - listall=self.services["listall"], - domainid=self.domain.id - ) + self.userapiclient, + listall=self.services["listall"], + domainid=self.domain.id + ) status = validateList(security_groups_list) self.assertEquals( - PASS, - status[0], - "Listing Security Groups failed" - ) + PASS, + status[0], + "Listing Security Groups failed" + ) # populating Security Groups id's - securitygroupids = {security_groups_list[0].id , security_groups_list[1].id} + securitygroupids = { + security_groups_list[0].id, + security_groups_list[1].id} # Listing all the VM's for a User list_vms_before = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - ) + self.userapiclient, + listall=self.services["listall"], + ) self.assertIsNone( - list_vms_before, - "Virtual Machine already exists for newly created user" - ) + list_vms_before, + "Virtual Machine already exists for newly created user" + ) # Deploying a VM vm_created = VirtualMachine.create( - self.userapiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - securitygroupids=securitygroupids, - ) + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + securitygroupids=securitygroupids, + ) self.assertIsNotNone( - vm_created, - "VM creation failed" - ) + vm_created, + "VM creation failed" + ) self.cleanup_vm.append(vm_created) # Listing all the VMs for a user again list_vms_after = VirtualMachine.list( - self.userapiclient, - listall=self.services["listall"], - ) + self.userapiclient, + listall=self.services["listall"], + ) status = validateList(list_vms_after) self.assertEquals( - PASS, - status[0], - "VM creation failed" - ) + PASS, + status[0], + "VM creation failed" + ) # Verifying that the size of the list is 1 self.assertEquals( - 1, - len(list_vms_after), - "VM list count is not matching" - ) - # Verifying that the Security Groups's in VM created are same as provided + 1, + len(list_vms_after), + "VM list count is not matching" + ) + # Verifying that the Security Groups's in VM created are same as + # provided vm_securitygroups = vm_created.securitygroup # Verifying that the size of security groups is 2 self.assertEquals( - 2, - len(vm_securitygroups), - "Security Groups count in VM created is not matching" - ) + 2, + len(vm_securitygroups), + "Security Groups count in VM created is not matching" + ) # Verifying that Security Group network ID's are as expected vm_securitygroups_flag = True for i in range(0, len(vm_securitygroups)): - if ((vm_securitygroups[i].id != security_groups_list[0].id) and\ - (vm_securitygroups[i].id != security_groups_list[1].id)): + if ((vm_securitygroups[i].id != security_groups_list[0].id) and + (vm_securitygroups[i].id != security_groups_list[1].id)): vm_securitygroups_flag = False break self.assertEquals( - True, - vm_securitygroups_flag, - "Security Groups in VM are not same as created" - ) + True, + vm_securitygroups_flag, + "Security Groups in VM are not same as created" + ) return @attr(tags=["advanced"], required_hardware="false") @@ -3598,19 +3703,19 @@ class TestInstances(cloudstackTestCase): """ # Listing Network Offerings network_offerings_list = NetworkOffering.list( - self.apiClient, - forvpc="false", - guestiptype="Isolated", - state="Enabled", - supportedservices="SourceNat", - zoneid=self.zone.id - ) + self.apiClient, + forvpc="false", + guestiptype="Isolated", + state="Enabled", + supportedservices="SourceNat", + zoneid=self.zone.id + ) status = validateList(network_offerings_list) self.assertEquals( - PASS, - status[0], - "Isolated Network Offerings with sourceNat enabled are not found" - ) + PASS, + status[0], + "Isolated Network Offerings with sourceNat enabled are not found" + ) """ Create Isolated netwrok with ip range """ @@ -3623,38 +3728,38 @@ class TestInstances(cloudstackTestCase): Creating isolated/guest network with ip range """ network = Network.create( - self.userapiclient, - self.services["network"], - accountid=self.account.name, - domainid=self.domain.id, - networkofferingid=network_offerings_list[0].id, - zoneid=self.zone.id - ) + self.userapiclient, + self.services["network"], + accountid=self.account.name, + domainid=self.domain.id, + networkofferingid=network_offerings_list[0].id, + zoneid=self.zone.id + ) self.assertIsNotNone( - network, - "Network creation failed" - ) + network, + "Network creation failed" + ) # Deploying a VM vm_created = VirtualMachine.create( - self.userapiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - networkids=network.id, - ipaddress=vm_ip, - serviceofferingid=self.service_offering.id, - ) + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + networkids=network.id, + ipaddress=vm_ip, + serviceofferingid=self.service_offering.id, + ) self.assertIsNotNone( - vm_created, - "VM creation failed" - ) + vm_created, + "VM creation failed" + ) # self.cleanup.append(vm_created) self.cleanup.append(network) # Listing all the VMs for a user again vm_response = VirtualMachine.list( - self.userapiclient, - id=vm_created.id, - ) + self.userapiclient, + id=vm_created.id, + ) status = validateList(vm_response) self.assertEquals( PASS, @@ -3663,10 +3768,10 @@ class TestInstances(cloudstackTestCase): ) # Verifying that the size of the list is 1 self.assertEquals( - 1, - len(vm_response), - "VM list count is not matching" - ) + 1, + len(vm_response), + "VM list count is not matching" + ) # Verifying that the NIC's in VM created are same as provided vm_nics = vm_created.nic status = validateList(vm_nics) @@ -3677,18 +3782,18 @@ class TestInstances(cloudstackTestCase): ) # Verifying that the size of nics is 1 self.assertEquals( - 1, - len(vm_nics), - "VM is created with more than one nic which is not expected" - ) + 1, + len(vm_nics), + "VM is created with more than one nic which is not expected" + ) """ Verifying that NIC IP address is as expected """ self.assertEquals( - str(vm_nics[0].ipaddress), - vm_ip, - "VM is not created with static ip address used in vm deployment" - ) + str(vm_nics[0].ipaddress), + vm_ip, + "VM is not created with static ip address used in vm deployment" + ) try: vm_created.delete(self.apiClient, expunge=True) except Exception as e: @@ -3698,13 +3803,17 @@ class TestInstances(cloudstackTestCase): @attr(tags=["advanced"], required_hardware="false") def test_25_ip_reallocation_ES1377(self): """ - @Desc: Test to verify dnsmasq dhcp conflict issue due to /ect/hosts not getting udpated + @Desc: Test to verify dnsmasq dhcp conflict issue due to + /ect/hosts not getting udpated @Steps: Step1: Create a network for the user Step2: List the network and check that it is created for the user - Step3: Deploy vm1 with hostname hostA and ip address IP A in the above network - Step4: List the vm and verify the ip address in the response and verify ssh access to vm - Step5: Deploy vm2 with hostname hostB and ip address IP B in the same network + Step3: Deploy vm1 with hostname hostA and ip address IP A in the + above network + Step4: List the vm and verify the ip address in the response and + verify ssh access to vm + Step5: Deploy vm2 with hostname hostB and ip address IP B in the + same network Step6: Repeat step4 Step7: Destroy vm1 and vm2 Step8: Deploy vm3 with hostname hostA and ip address IP B @@ -3763,18 +3872,17 @@ class TestInstances(cloudstackTestCase): ipaddress=vm_ip1, serviceofferingid=self.service_offering.id, mode="advanced", - ) - self.assertIsNotNone( - vm1, - "VM1 creation failed with ip address %s and host name %s" % (vm_ip1, name1) ) + self.assertIsNotNone( + vm1, "VM1 creation failed with ip address %s and host name %s" % + (vm_ip1, name1)) # self.cleanup.append(vm_created) self.cleanup.append(network) # Listing all the VMs for a user again vm_response = VirtualMachine.list( self.userapiclient, id=vm1.id, - ) + ) status = validateList(vm_response) self.assertEquals( PASS, @@ -3800,7 +3908,7 @@ class TestInstances(cloudstackTestCase): ipaddress=vm_ip2, serviceofferingid=self.service_offering.id, mode="advanced", - ) + ) self.assertIsNotNone( vm2, "VM2 creation failed" @@ -3808,7 +3916,7 @@ class TestInstances(cloudstackTestCase): vm_response = VirtualMachine.list( self.userapiclient, id=vm2.id, - ) + ) status = validateList(vm_response) self.assertEquals( PASS, @@ -3827,9 +3935,10 @@ class TestInstances(cloudstackTestCase): except Exception as e: raise Exception("Warning: Exception in expunging vms : %s" % e) """ - Deploy vm3 with ip address of vm1 and host name of vm2 so both the vm1 and vm2 entries - would be deleted from dhcphosts file on VR becase dhcprelease matches entries with - host name and ip address so it matches both the entries. + Deploy vm3 with ip address of vm1 and host name of vm2 so both the vm1 + and vm2 entries would be deleted from dhcphosts file on VR becase + dhcprelease matches entries with host name and ip address so it + matches both the entries. """ # Deploying a VM self.services["virtual_machine"]["name"] = name2 @@ -3842,7 +3951,7 @@ class TestInstances(cloudstackTestCase): ipaddress=vm_ip1, serviceofferingid=self.service_offering.id, mode="advanced", - ) + ) self.assertIsNotNone( vm3, "VM3 creation failed" @@ -3850,7 +3959,7 @@ class TestInstances(cloudstackTestCase): vm_response = VirtualMachine.list( self.userapiclient, id=vm3.id, - ) + ) status = validateList(vm_response) self.assertEquals( PASS, @@ -3865,8 +3974,9 @@ class TestInstances(cloudstackTestCase): ) # Deploying a VM """ - Deploy vm4 with ip address of vm2. dnsmasq and dhcprelase should be in sync. - We should not see dhcp lease block due to IP reallocation. + Deploy vm4 with ip address of vm2. dnsmasq and dhcprelase + should be in sync. We should not see dhcp lease block due to IP + reallocation. """ name3 = "hostC" self.services["virtual_machine"]["name"] = name3 @@ -3879,7 +3989,7 @@ class TestInstances(cloudstackTestCase): ipaddress=vm_ip2, serviceofferingid=self.service_offering.id, mode="advanced", - ) + ) self.assertIsNotNone( vm4, "VM4 creation failed" @@ -3887,7 +3997,7 @@ class TestInstances(cloudstackTestCase): vm_response = VirtualMachine.list( self.userapiclient, id=vm4.id, - ) + ) status = validateList(vm_response) self.assertEquals( PASS, @@ -3904,5 +4014,7 @@ class TestInstances(cloudstackTestCase): vm3.delete(self.apiClient, expunge=True) vm4.delete(self.apiClient, expunge=True) except Exception as e: - raise Exception("Warning: Exception in expunging vms vm3 and vm4 : %s" % e) + raise Exception( + "Warning: Exception in expunging vms vm3 and vm4 : %s" % + e) return