From 0e7f1ea9b819de197e70a088e92d7ffb7016d063 Mon Sep 17 00:00:00 2001 From: Bharat Kumar Date: Wed, 22 Oct 2014 11:29:22 +0530 Subject: [PATCH 01/26] CLOUDSTACK-7763 Reservations for VMware VMs remain after dynamic scaling --- .../com/cloud/hypervisor/vmware/resource/VmwareResource.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java index 085b6bbed49..fa667696ea7 100755 --- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java @@ -1281,7 +1281,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa VmwareHypervisorHost hyperHost = getHyperHost(context); VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(cmd.getVmName()); VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec(); - int ramMb = (int)(vmSpec.getMinRam() / (1024 * 1024)); + int ramMb = getReservedMemoryMb(vmSpec); long hotaddIncrementSizeInMb; long hotaddMemoryLimitInMb; long requestedMaxMemoryInMb = vmSpec.getMaxRam() / (1024 * 1024); From 310bb255acd74b6347bd778590e15543eef7333b Mon Sep 17 00:00:00 2001 From: Bharat Kumar Date: Fri, 17 Oct 2014 11:24:40 +0530 Subject: [PATCH 02/26] CLOUDSTACK-7760 Data disk size is not considering for primary storage resource limit check --- server/src/com/cloud/vm/UserVmManagerImpl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 1a024a3da9d..28ec6ecd91f 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -2682,6 +2682,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir throw new InvalidParameterValueException("VM Creation failed. Volume size: " + diskSize + "GB is out of allowed range. Max: " + customDiskOfferingMaxSize + " Min:" + customDiskOfferingMinSize); } + size=size+diskSize*(1024*1024*1024); } size += _diskOfferingDao.findById(diskOfferingId).getDiskSize(); } From 34f31f90331d0027b133ccdc8fdb65ab86ce26cc Mon Sep 17 00:00:00 2001 From: Damodar Date: Thu, 6 Nov 2014 12:04:30 +0530 Subject: [PATCH 03/26] CLOUDSTACK-7851:MS does not start after the VM it is running on is rebooted --- packaging/centos63/cloud-management.rc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packaging/centos63/cloud-management.rc b/packaging/centos63/cloud-management.rc index eaabd30d593..6d2874854ee 100755 --- a/packaging/centos63/cloud-management.rc +++ b/packaging/centos63/cloud-management.rc @@ -87,7 +87,8 @@ handle_pid_file() { } start() { - source $(dirname $0)/tomcat.sh + readpath=$(readlink -f $0) + source `dirname $readpath`/tomcat.sh } # See how we were called. From cdabb2407a0761939d5159fd2317ebd7dcca4eb7 Mon Sep 17 00:00:00 2001 From: Damodar Date: Wed, 5 Nov 2014 17:19:46 +0530 Subject: [PATCH 04/26] CLOUDSTACK-7843: sync Job Failures always reported as success on Event Bus --- .../cloudstack/framework/jobs/impl/AsyncJobManagerImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/framework/jobs/src/org/apache/cloudstack/framework/jobs/impl/AsyncJobManagerImpl.java b/framework/jobs/src/org/apache/cloudstack/framework/jobs/impl/AsyncJobManagerImpl.java index 91516d51238..d5f7f9df107 100644 --- a/framework/jobs/src/org/apache/cloudstack/framework/jobs/impl/AsyncJobManagerImpl.java +++ b/framework/jobs/src/org/apache/cloudstack/framework/jobs/impl/AsyncJobManagerImpl.java @@ -253,7 +253,6 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, if (s_logger.isDebugEnabled()) { s_logger.debug("Publish async job-" + jobId + " complete on message bus"); } - publishOnEventBus(job, "complete"); // publish before the instance type and ID are wiped out if (s_logger.isDebugEnabled()) { s_logger.debug("Wake up jobs related to job-" + jobId); @@ -291,6 +290,8 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, } }); + publishOnEventBus(job, "complete"); // publish before the instance type and ID are wiped out + // // disable wakeup scheduling now, since all API jobs are currently using block-waiting for sub-jobs // From 36fd780482dbd65ef9328f630d0af0793d0fed2e Mon Sep 17 00:00:00 2001 From: Damodar Date: Mon, 10 Nov 2014 14:40:36 +0530 Subject: [PATCH 05/26] CLOUDSTACK-7830: Usage Job fails with "Data too long for column 'user_name'" --- setup/db/db/schema-441to450.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/setup/db/db/schema-441to450.sql b/setup/db/db/schema-441to450.sql index 1d2bbb6af9a..0aa95e89ac5 100644 --- a/setup/db/db/schema-441to450.sql +++ b/setup/db/db/schema-441to450.sql @@ -754,3 +754,5 @@ DELETE t1 FROM guest_os_hypervisor t1, guest_os_hypervisor t2 WHERE (t1.hypervis -- Set as removed built-in CentOS 5.3 template (if any) for XenServer, since CentOS 5.6 template already exists UPDATE `cloud`.`vm_template` SET removed=NOW() WHERE unique_name="centos53-x86_64" AND hypervisor_type="XenServer"; + +ALTER TABLE `cloud_usage`.`usage_vpn_user` CHANGE `user_name` `user_name` VARCHAR(255); From 0bd34d389f93b56e74a6bb04054c8e419bf8571e Mon Sep 17 00:00:00 2001 From: Jayapal Date: Fri, 7 Nov 2014 09:37:32 +0530 Subject: [PATCH 06/26] CLOUDSTACK-7872: network getting shutdown inspite of running VM's in the network --- .../com/cloud/network/dao/NetworkDaoImpl.java | 2 -- .../schema/src/com/cloud/vm/dao/NicDao.java | 2 ++ .../src/com/cloud/vm/dao/NicDaoImpl.java | 22 +++++++++++++++++++ .../com/cloud/network/NetworkModelImpl.java | 7 ++++++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/engine/schema/src/com/cloud/network/dao/NetworkDaoImpl.java b/engine/schema/src/com/cloud/network/dao/NetworkDaoImpl.java index 0c556c843d9..4a07455832a 100644 --- a/engine/schema/src/com/cloud/network/dao/NetworkDaoImpl.java +++ b/engine/schema/src/com/cloud/network/dao/NetworkDaoImpl.java @@ -244,7 +244,6 @@ public class NetworkDaoImpl extends GenericDaoBase implements N GarbageCollectedSearch = createSearchBuilder(Long.class); GarbageCollectedSearch.selectFields(GarbageCollectedSearch.entity().getId()); SearchBuilder join7 = _ntwkOpDao.createSearchBuilder(); - join7.and("activenics", join7.entity().getActiveNicsCount(), Op.EQ); join7.and("gc", join7.entity().isGarbageCollected(), Op.EQ); join7.and("check", join7.entity().isCheckForGc(), Op.EQ); GarbageCollectedSearch.join("ntwkOpGC", join7, GarbageCollectedSearch.entity().getId(), join7.entity().getId(), JoinBuilder.JoinType.INNER); @@ -438,7 +437,6 @@ public class NetworkDaoImpl extends GenericDaoBase implements N public List findNetworksToGarbageCollect() { SearchCriteria sc = GarbageCollectedSearch.create(); sc.setJoinParameters("ntwkOffGC", "isPersistent", false); - sc.setJoinParameters("ntwkOpGC", "activenics", 0); sc.setJoinParameters("ntwkOpGC", "gc", true); sc.setJoinParameters("ntwkOpGC", "check", true); return customSearch(sc, null); diff --git a/engine/schema/src/com/cloud/vm/dao/NicDao.java b/engine/schema/src/com/cloud/vm/dao/NicDao.java index a7ad01692cf..9f153f8eeb4 100644 --- a/engine/schema/src/com/cloud/vm/dao/NicDao.java +++ b/engine/schema/src/com/cloud/vm/dao/NicDao.java @@ -74,4 +74,6 @@ public interface NicDao extends GenericDao { List listByNetworkIdTypeAndGatewayAndBroadcastUri(long networkId, VirtualMachine.Type vmType, String gateway, URI broadcastUri); int countNicsForStartingVms(long networkId); + + int countNicsForRunningVms(long networkId); } diff --git a/engine/schema/src/com/cloud/vm/dao/NicDaoImpl.java b/engine/schema/src/com/cloud/vm/dao/NicDaoImpl.java index 2a9a6025071..ca44b631e4f 100644 --- a/engine/schema/src/com/cloud/vm/dao/NicDaoImpl.java +++ b/engine/schema/src/com/cloud/vm/dao/NicDaoImpl.java @@ -46,6 +46,7 @@ public class NicDaoImpl extends GenericDaoBase implements NicDao { private SearchBuilder NonReleasedSearch; private GenericSearchBuilder CountBy; private GenericSearchBuilder CountByForStartingVms; + private GenericSearchBuilder CountByForRunningVms; @Inject VMInstanceDao _vmDao; @@ -95,6 +96,17 @@ public class NicDaoImpl extends GenericDaoBase implements NicDao { join1.and("state", join1.entity().getState(), Op.EQ); CountByForStartingVms.join("vm", join1, CountByForStartingVms.entity().getInstanceId(), join1.entity().getId(), JoinBuilder.JoinType.INNER); CountByForStartingVms.done(); + + CountByForRunningVms = createSearchBuilder(Integer.class); + CountByForRunningVms.select(null, Func.COUNT, CountByForRunningVms.entity().getId()); + CountByForRunningVms.and("networkId", CountByForRunningVms.entity().getNetworkId(), Op.EQ); + CountByForRunningVms.and("removed", CountByForRunningVms.entity().getRemoved(), Op.NULL); + SearchBuilder join2 = _vmDao.createSearchBuilder(); + join2.and("state", join2.entity().getState(), Op.EQ); + join2.and("type", join2.entity().getType(), Op.EQ); + CountByForRunningVms.join("vm", join2, CountByForRunningVms.entity().getInstanceId(), join2.entity().getId(), JoinBuilder.JoinType.INNER); + CountByForRunningVms.done(); + } @Override @@ -291,4 +303,14 @@ public class NicDaoImpl extends GenericDaoBase implements NicDao { List results = customSearch(sc, null); return results.get(0); } + + @Override + public int countNicsForRunningVms(long networkId) { + SearchCriteria sc = CountByForRunningVms.create(); + sc.setParameters("networkId", networkId); + sc.setJoinParameters("vm", "state", VirtualMachine.State.Running); + sc.setJoinParameters("vm", "type", VirtualMachine.Type.User); + List results = customSearch(sc, null); + return results.get(0); + } } diff --git a/server/src/com/cloud/network/NetworkModelImpl.java b/server/src/com/cloud/network/NetworkModelImpl.java index 1dc81bd945b..2edf9708ad0 100755 --- a/server/src/com/cloud/network/NetworkModelImpl.java +++ b/server/src/com/cloud/network/NetworkModelImpl.java @@ -2232,6 +2232,13 @@ public class NetworkModelImpl extends ManagerBase implements NetworkModel { return false; } + // Due to VMSync issue, there can be cases where nic count is zero, but there can be VM's running in the network + // so add extra guard to check if network GC is actially required. + if (_nicDao.countNicsForRunningVms(networkId) > 0) { + s_logger.debug("Network id=" + networkId + " is not ready for GC as it has vms that are Running at the moment"); + return false; + } + return true; } From 3e00f99c535e318faab4c09ac943fd8540f81d17 Mon Sep 17 00:00:00 2001 From: Gaurav Aradhye Date: Mon, 10 Nov 2014 11:58:18 +0530 Subject: [PATCH 07/26] CLOUDSTACK-7866: Passing type value to list_hosts method so as to avoid listing SSVM and CPVM Correcting hostid attribute Signed-off-by: SrikanteswaraRao Talluri --- .../maint/test_host_high_availability.py | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/test/integration/component/maint/test_host_high_availability.py b/test/integration/component/maint/test_host_high_availability.py index ecc23f75cd4..0d76f817024 100644 --- a/test/integration/component/maint/test_host_high_availability.py +++ b/test/integration/component/maint/test_host_high_availability.py @@ -19,11 +19,20 @@ """ #Import Local Modules from nose.plugins.attrib import attr -from marvin.cloudstackTestCase import * -from marvin.cloudstackAPI import * -from marvin.lib.utils import * -from marvin.lib.base import * -from marvin.lib.common import * +from marvin.cloudstackTestCase import cloudstackTestCase +from marvin.cloudstackAPI import (migrateVirtualMachine, + prepareHostForMaintenance, + cancelHostMaintenance) +from marvin.lib.utils import cleanup_resources +from marvin.lib.base import (Account, + VirtualMachine, + ServiceOffering) +from marvin.lib.common import (get_zone, + get_domain, + get_template, + list_hosts, + list_virtual_machines, + list_service_offering) import time @@ -490,6 +499,7 @@ class TestHostHighAvailability(cloudstackTestCase): #Find out Non-Suitable host for VM migration list_hosts_response = list_hosts( self.apiclient, + type="Routing" ) self.assertEqual( isinstance(list_hosts_response, list), @@ -505,7 +515,7 @@ class TestHostHighAvailability(cloudstackTestCase): notSuitableHost = None for host in list_hosts_response: - if not host.suitableformigration and host.hostid != vm.hostid: + if not host.suitableformigration and host.id != vm.hostid: notSuitableHost = host break From f78defda0fa1c07d440b484c414b16a09e58433a Mon Sep 17 00:00:00 2001 From: Chandan Purushothama Date: Fri, 7 Nov 2014 15:32:45 -0800 Subject: [PATCH 08/26] CLOUDSTACK-7863: Fix the script 'test_vpc_vms_deployment.py' - Test Cases failing on Simulator as Testcases try to ssh to the VMs Signed-off-by: SrikanteswaraRao Talluri --- test/integration/component/test_vpc_vms_deployment.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/integration/component/test_vpc_vms_deployment.py b/test/integration/component/test_vpc_vms_deployment.py index e61b2f80f0c..f8aa556fea2 100644 --- a/test/integration/component/test_vpc_vms_deployment.py +++ b/test/integration/component/test_vpc_vms_deployment.py @@ -1798,7 +1798,7 @@ class TestVMDeployVPC(cloudstackTestCase): ) return - @attr(tags=["advanced", "intervlan"], required_hardware="false") + @attr(tags=["advanced", "intervlan"], required_hardware="true") def test_07_delete_network_with_rules(self): """ Test delete network that has PF/staticNat/LB rules/Network Acl """ @@ -2352,7 +2352,7 @@ class TestVMDeployVPC(cloudstackTestCase): ) return - @attr(tags=["advanced", "intervlan"], required_hardware="false") + @attr(tags=["advanced", "intervlan"], required_hardware="true") def test_08_ip_reallocation_CS5986(self): """ @Desc: Test to verify dnsmasq dhcp conflict issue due to /ect/hosts not getting udpated From 2f7959d2190d3afbd71f42a84725b75107f925d8 Mon Sep 17 00:00:00 2001 From: Chandan Purushothama Date: Fri, 7 Nov 2014 15:00:03 -0800 Subject: [PATCH 09/26] CLOUDSTACK-7862: Fixed the script 'maint/test_high_availability.py' - Test Cases failing on Simulator as Testcases try to ssh to the VMs Signed-off-by: SrikanteswaraRao Talluri --- test/integration/component/maint/test_high_availability.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/integration/component/maint/test_high_availability.py b/test/integration/component/maint/test_high_availability.py index cc687f83ea7..3e69fd50a7f 100644 --- a/test/integration/component/maint/test_high_availability.py +++ b/test/integration/component/maint/test_high_availability.py @@ -165,7 +165,7 @@ class TestHighAvailability(cloudstackTestCase): raise Exception("Warning: Exception during cleanup : %s" % e) return - @attr(tags = ["advanced", "advancedns", "multihost"]) + @attr(tags = ["advanced", "advancedns", "multihost"], required_hardware="true") def test_01_host_maintenance_mode(self): """Test host maintenance mode """ @@ -556,7 +556,7 @@ class TestHighAvailability(cloudstackTestCase): ) return - @attr(tags = ["advanced", "advancedns", "multihost"]) + @attr(tags = ["advanced", "advancedns", "multihost"], required_hardware="true") def test_02_host_maintenance_mode_with_activities(self): """Test host maintenance mode with activities """ From 23df5f22ac96bf8032d10a5b65c6016534d67fcb Mon Sep 17 00:00:00 2001 From: Gaurav Aradhye Date: Thu, 6 Nov 2014 18:23:08 +0530 Subject: [PATCH 10/26] CLOUDSTACK-7856: test_vpc_network_pf_rules.py - Check if httpd service is running or not, if not, start it Signed-off-by: SrikanteswaraRao Talluri --- .../component/test_vpc_network_pfrules.py | 51 +++++++++++++------ 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/test/integration/component/test_vpc_network_pfrules.py b/test/integration/component/test_vpc_network_pfrules.py index c3a81614c18..e49642b427c 100644 --- a/test/integration/component/test_vpc_network_pfrules.py +++ b/test/integration/component/test_vpc_network_pfrules.py @@ -18,7 +18,7 @@ """ Component tests for VPC network functionality - Port Forwarding Rules. """ from nose.plugins.attrib import attr -from marvin.cloudstackTestCase import cloudstackTestCase, unittest +from marvin.cloudstackTestCase import cloudstackTestCase from marvin.lib.base import (stopRouter, startRouter, Account, @@ -327,20 +327,31 @@ class TestVPCNetworkPFRules(cloudstackTestCase): else: self.debug("Failed to SSH into VM - %s" % (public_ip.ipaddress.ipaddress)) - def check_wget_from_vm(self, vm, public_ip, testnegative=False): + def check_wget_from_vm(self, vm, public_ip, network=None, testnegative=False, isVmAccessible=True): import urllib self.debug("Checking if we can wget from a VM=%s http server on public_ip=%s" % (vm.name, public_ip.ipaddress.ipaddress)) try: + if not isVmAccessible: + self.create_natrule(vm, public_ip, network) + # Start httpd service on VM first + sshClient = vm.get_ssh_client() + sshClient.execute("service httpd start") + time.sleep(5) + ssh_response = str(sshClient.execute("service httpd status")).lower() + self.debug("httpd service status is: %s" % ssh_response) + if not "running" in ssh_response: + raise Exception("Failed to start httpd service") + urllib.urlretrieve("http://%s/test.html" % public_ip.ipaddress.ipaddress, filename="test.html") if not testnegative: self.debug("Successesfull to wget from VM=%s http server on public_ip=%s" % (vm.name, public_ip.ipaddress.ipaddress)) else: self.fail("Successesfull to wget from VM=%s http server on public_ip=%s" % (vm.name, public_ip.ipaddress.ipaddress)) - except: + except Exception as e: if not testnegative: - self.fail("Failed to wget from VM=%s http server on public_ip=%s" % (vm.name, public_ip.ipaddress.ipaddress)) + self.fail("Failed to wget from VM=%s http server on public_ip=%s: %s" % (vm.name, public_ip.ipaddress.ipaddress, e)) else: - self.debug("Failed to wget from VM=%s http server on public_ip=%s" % (vm.name, public_ip.ipaddress.ipaddress)) + self.debug("Failed to wget from VM=%s http server on public_ip=%s: %s" % (vm.name, public_ip.ipaddress.ipaddress, e)) def create_natrule(self, vm, public_ip, network, services=None): self.debug("Creating NAT rule in network for vm with public IP") @@ -687,7 +698,8 @@ class TestVPCNetworkPFRules(cloudstackTestCase): nat_rule.delete(self.apiclient) self.start_vpcrouter(router) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=True) - self.check_wget_from_vm(vm_1, public_ip_1, testnegative=True) + self.check_wget_from_vm(vm_1, public_ip_1, testnegative=True, + isVmAccessible=False, network=network_1) return @attr(tags=["advanced", "intervlan"], required_hardware="true") @@ -717,7 +729,8 @@ class TestVPCNetworkPFRules(cloudstackTestCase): http_rule.delete(self.apiclient) nat_rule.delete(self.apiclient) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=True) - self.check_wget_from_vm(vm_1, public_ip_1, testnegative=True) + self.check_wget_from_vm(vm_1, public_ip_1, testnegative=True, + isVmAccessible=False, network=network_1) return @attr(tags=["advanced", "intervlan"], required_hardware="true") @@ -781,10 +794,14 @@ class TestVPCNetworkPFRules(cloudstackTestCase): self.check_ssh_into_vm(vm_2, public_ip_2, testnegative=True) self.check_ssh_into_vm(vm_3, public_ip_3, testnegative=True) self.check_ssh_into_vm(vm_4, public_ip_4, testnegative=True) - self.check_wget_from_vm(vm_1, public_ip_1, testnegative=True) - self.check_wget_from_vm(vm_2, public_ip_2, testnegative=True) - self.check_wget_from_vm(vm_3, public_ip_3, testnegative=True) - self.check_wget_from_vm(vm_4, public_ip_4, testnegative=True) + self.check_wget_from_vm(vm_1, public_ip_1, testnegative=True, + isVmAccessible=False, network=network_1) + self.check_wget_from_vm(vm_2, public_ip_2, testnegative=True, + isVmAccessible=False, network=network_1) + self.check_wget_from_vm(vm_3, public_ip_3, testnegative=True, + isVmAccessible=False, network=network_2) + self.check_wget_from_vm(vm_4, public_ip_4, testnegative=True, + isVmAccessible=False, network=network_2) return @attr(tags=["advanced", "intervlan"], required_hardware="true") @@ -843,8 +860,12 @@ class TestVPCNetworkPFRules(cloudstackTestCase): self.check_ssh_into_vm(vm_2, public_ip_2, testnegative=True) self.check_ssh_into_vm(vm_3, public_ip_3, testnegative=True) self.check_ssh_into_vm(vm_4, public_ip_4, testnegative=True) - self.check_wget_from_vm(vm_1, public_ip_1, testnegative=True) - self.check_wget_from_vm(vm_2, public_ip_2, testnegative=True) - self.check_wget_from_vm(vm_3, public_ip_3, testnegative=True) - self.check_wget_from_vm(vm_4, public_ip_4, testnegative=True) + self.check_wget_from_vm(vm_1, public_ip_1, testnegative=True, + isVmAccessible=False, network=network_1) + self.check_wget_from_vm(vm_2, public_ip_2, testnegative=True, + isVmAccessible=False, network=network_1) + self.check_wget_from_vm(vm_3, public_ip_3, testnegative=True, + isVmAccessible=False, network=network_2) + self.check_wget_from_vm(vm_4, public_ip_4, testnegative=True, + isVmAccessible=False, network=network_2) return From 53694133d8848d56cdf10bf756022b3f2e9cf8d0 Mon Sep 17 00:00:00 2001 From: Gaurav Aradhye Date: Fri, 31 Oct 2014 11:52:44 +0530 Subject: [PATCH 11/26] CLOUDSTACK-7823: test_snapshots.py - remove test case dependency on each other Signed-off-by: SrikanteswaraRao Talluri --- test/integration/component/test_snapshots.py | 46 +++++++++----------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/test/integration/component/test_snapshots.py b/test/integration/component/test_snapshots.py index 0811eb123fe..62f2f06fb82 100644 --- a/test/integration/component/test_snapshots.py +++ b/test/integration/component/test_snapshots.py @@ -186,37 +186,17 @@ class TestSnapshots(cloudstackTestCase): cls.services["zoneid"] = cls.zone.id cls.services["diskoffering"] = cls.disk_offering.id - # Create VMs, NAT Rules etc - cls.account = Account.create( - cls.api_client, - cls.services["account"], - domainid=cls.domain.id - ) - - cls.services["account"] = cls.account.name - cls.service_offering = ServiceOffering.create( cls.api_client, cls.services["service_offering"] ) - cls.virtual_machine = cls.virtual_machine_with_disk = \ - VirtualMachine.create( - cls.api_client, - cls.services["server_with_disk"], - templateid=cls.template.id, - accountid=cls.account.name, - domainid=cls.account.domainid, - serviceofferingid=cls.service_offering.id, - mode=cls.services["mode"] - ) # Get Hypervisor Type cls.hypervisor = (get_hypervisor_type(cls.api_client)).lower() cls._cleanup = [ cls.service_offering, - cls.disk_offering, - cls.account, + cls.disk_offering ] return @@ -233,7 +213,25 @@ class TestSnapshots(cloudstackTestCase): self.apiclient = self.testClient.getApiClient() self.hypervisor = str(self.testClient.getHypervisorInfo()).lower() self.dbclient = self.testClient.getDbConnection() - self.cleanup = [] + + # Create VMs, NAT Rules etc + self.account = Account.create( + self.apiclient, + self.services["account"], + domainid=self.domain.id + ) + + self.virtual_machine = self.virtual_machine_with_disk = \ + VirtualMachine.create( + self.api_client, + self.services["server_with_disk"], + templateid=self.template.id, + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + mode=self.services["mode"] + ) + self.cleanup = [self.account, ] return def tearDown(self): @@ -853,8 +851,6 @@ class TestSnapshots(cloudstackTestCase): serviceofferingid=self.service_offering.id, mode=self.services["mode"] ) - self.cleanup.append(new_virtual_machine) - try: #Login to VM & mount directory ssh = new_virtual_machine.get_ssh_client() @@ -942,8 +938,6 @@ class TestCreateVMSnapshotTemplate(cloudstackTestCase): domainid=cls.domain.id ) - cls.services["account"] = cls.account.name - cls.service_offering = ServiceOffering.create( cls.api_client, cls.services["service_offering"] From 85ac979f72e7ea4b65f466429e786fe468a03646 Mon Sep 17 00:00:00 2001 From: Gaurav Aradhye Date: Thu, 30 Oct 2014 18:05:41 +0530 Subject: [PATCH 12/26] CLOUDSTACK-7818: Fixing test_escalations_instances.py, Removing dependency of test cases on each other Signed-off-by: SrikanteswaraRao Talluri --- .../component/test_escalations_instances.py | 4422 +++++++++-------- 1 file changed, 2267 insertions(+), 2155 deletions(-) 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 From c401dbc8f986563159f49f5c419ad31437ef9d04 Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Mon, 10 Nov 2014 17:51:25 +0530 Subject: [PATCH 13/26] CLOUDSTACK-7871: allow VM and template details update using update APIs Allows updating details (key/value) pair which updatse entries invm_template_details and user_vm_details tables using updateVM and updateTemplate APIs. This allows sys admins to update nics, controllers etc without DB hacking. Signed-off-by: Rohit Yadav (cherry picked from commit 97fa4a023e2346b3b9f56bf213ed4125c371ca6d) Signed-off-by: Rohit Yadav --- .../api/BaseUpdateTemplateOrIsoCmd.java | 17 ++++++++++++++++- .../api/command/user/vm/UpdateVMCmd.java | 16 ++++++++++++++++ .../com/cloud/template/TemplateManagerImpl.java | 8 +++++++- server/src/com/cloud/vm/UserVmManagerImpl.java | 6 ++++++ 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/api/src/org/apache/cloudstack/api/BaseUpdateTemplateOrIsoCmd.java b/api/src/org/apache/cloudstack/api/BaseUpdateTemplateOrIsoCmd.java index 2350f6b3892..2754b254e50 100644 --- a/api/src/org/apache/cloudstack/api/BaseUpdateTemplateOrIsoCmd.java +++ b/api/src/org/apache/cloudstack/api/BaseUpdateTemplateOrIsoCmd.java @@ -22,6 +22,9 @@ import org.apache.cloudstack.api.command.user.iso.UpdateIsoCmd; import org.apache.cloudstack.api.response.GuestOSResponse; import org.apache.cloudstack.api.response.TemplateResponse; +import java.util.Collection; +import java.util.Map; + public abstract class BaseUpdateTemplateOrIsoCmd extends BaseCmd { public static final Logger s_logger = Logger.getLogger(UpdateIsoCmd.class.getName()); @@ -64,6 +67,9 @@ public abstract class BaseUpdateTemplateOrIsoCmd extends BaseCmd { @Parameter(name = ApiConstants.ROUTING, type = CommandType.BOOLEAN, description = "true if the template type is routing i.e., if template is used to deploy router") protected Boolean isRoutingType; + @Parameter(name = ApiConstants.DETAILS, type = CommandType.MAP, description = "Details in key/value pairs.") + protected Map details; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -107,4 +113,13 @@ public abstract class BaseUpdateTemplateOrIsoCmd extends BaseCmd { public Boolean isRoutingType() { return isRoutingType; } -} + + public Map getDetails() { + if (this.details == null || this.details.isEmpty()) { + return null; + } + + Collection paramsCollection = this.details.values(); + return (Map) (paramsCollection.toArray())[0]; + } +} \ No newline at end of file diff --git a/api/src/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java b/api/src/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java index d185b9114f5..6954832a9f6 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java @@ -38,6 +38,9 @@ import com.cloud.user.Account; import com.cloud.uservm.UserVm; import com.cloud.vm.VirtualMachine; +import java.util.Collection; +import java.util.Map; + @APICommand(name = "updateVirtualMachine", description="Updates properties of a virtual machine. The VM has to be stopped and restarted for the " + "new properties to take effect. UpdateVirtualMachine does not first check whether the VM is stopped. " + "Therefore, stop the VM manually before issuing this call.", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class}, @@ -90,6 +93,9 @@ public class UpdateVMCmd extends BaseCustomIdCmd { @Parameter(name = ApiConstants.INSTANCE_NAME, type = CommandType.STRING, description = "instance name of the user vm", since = "4.4", authorized = {RoleType.Admin}) private String instanceName; + @Parameter(name = ApiConstants.DETAILS, type = CommandType.MAP, description = "Details in key/value pairs.") + protected Map details; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -129,6 +135,16 @@ public class UpdateVMCmd extends BaseCustomIdCmd { public String getInstanceName() { return instanceName; } + + public Map getDetails() { + if (this.details == null || this.details.isEmpty()) { + return null; + } + + Collection paramsCollection = this.details.values(); + return (Map) (paramsCollection.toArray())[0]; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// diff --git a/server/src/com/cloud/template/TemplateManagerImpl.java b/server/src/com/cloud/template/TemplateManagerImpl.java index c7d228355a5..5641f577f3a 100755 --- a/server/src/com/cloud/template/TemplateManagerImpl.java +++ b/server/src/com/cloud/template/TemplateManagerImpl.java @@ -1776,6 +1776,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager, Boolean isRoutingTemplate = cmd.isRoutingType(); Boolean bootable = cmd.isBootable(); Integer sortKey = cmd.getSortKey(); + Map details = cmd.getDetails(); Account account = CallContext.current().getCallingAccount(); // verify that template exists @@ -1798,7 +1799,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager, boolean updateNeeded = !(name == null && displayText == null && format == null && guestOSId == null && passwordEnabled == null && bootable == null && sortKey == null && - isDynamicallyScalable == null && isRoutingTemplate == null); + isDynamicallyScalable == null && isRoutingTemplate == null && details == null); if (!updateNeeded) { return template; } @@ -1858,6 +1859,11 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager, } } + if (details != null && !details.isEmpty()) { + template.setDetails(details); + _tmpltDao.saveDetails(template); + } + _tmpltDao.update(id, template); return _tmpltDao.findById(id); diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 28ec6ecd91f..77ace7a5f6c 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -1899,6 +1899,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir String userData = cmd.getUserData(); Boolean isDynamicallyScalable = cmd.isDynamicallyScalable(); String hostName = cmd.getHostName(); + Map details = cmd.getDetails(); Account caller = CallContext.current().getCallingAccount(); // Input validation and permission checks @@ -1938,6 +1939,11 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir } + if (details != null && !details.isEmpty()) { + vmInstance.setDetails(details); + _vmDao.saveDetails(vmInstance); + } + return updateVirtualMachine(id, displayName, group, ha, isDisplayVm, osTypeId, userData, isDynamicallyScalable, cmd.getHttpMethod(), cmd.getCustomId(), hostName, cmd.getInstanceName()); } From c916f30574ebd3e909be3dc0e8ca74ae9ef7c5ce Mon Sep 17 00:00:00 2001 From: Santhosh Edukulla Date: Mon, 3 Nov 2014 12:40:13 +0530 Subject: [PATCH 14/26] CLOUDSTACK-7828.Avoid marking IPs already in Allocated as Allocated again. Use row lock to ensure that prev state is either Allocating or Free. This will inturn avoid logging duplicate events --- .../cloud/network/IpAddressManagerImpl.java | 44 +++++++++---------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/server/src/com/cloud/network/IpAddressManagerImpl.java b/server/src/com/cloud/network/IpAddressManagerImpl.java index 016d297d41f..43353491b18 100644 --- a/server/src/com/cloud/network/IpAddressManagerImpl.java +++ b/server/src/com/cloud/network/IpAddressManagerImpl.java @@ -807,32 +807,32 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage @Override public void markPublicIpAsAllocated(final IPAddressVO addr) { - assert (addr.getState() == IpAddress.State.Allocating || addr.getState() == IpAddress.State.Free) : "Unable to transition from state " + addr.getState() + " to " - + IpAddress.State.Allocated; Transaction.execute(new TransactionCallbackNoReturn() { @Override public void doInTransactionWithoutResult(TransactionStatus status) { - Account owner = _accountMgr.getAccount(addr.getAllocatedToAccountId()); - - addr.setState(IpAddress.State.Allocated); - _ipAddressDao.update(addr.getId(), addr); - - // Save usage event - if (owner.getAccountId() != Account.ACCOUNT_ID_SYSTEM) { - VlanVO vlan = _vlanDao.findById(addr.getVlanId()); - - String guestType = vlan.getVlanType().toString(); - - if (!isIpDedicated(addr)) { - UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NET_IP_ASSIGN, owner.getId(), addr.getDataCenterId(), addr.getId(), addr.getAddress().toString(), - addr.isSourceNat(), guestType, addr.getSystem(), addr.getClass().getName(), addr.getUuid()); - } - - if (updateIpResourceCount(addr)) { - _resourceLimitMgr.incrementResourceCount(owner.getId(), ResourceType.public_ip); + Account owner = _accountMgr.getAccount(addr.getAllocatedToAccountId()); + synchronized (this) { + if (_ipAddressDao.lockRow(addr.getId(),true) != null) { + IPAddressVO userIp = _ipAddressDao.findById(addr.getId()); + if (userIp.getState() == IpAddress.State.Allocating || addr.getState() == IpAddress.State.Free) { + addr.setState(IpAddress.State.Allocated); + _ipAddressDao.update(addr.getId(), addr); + // Save usage event + if (owner.getAccountId() != Account.ACCOUNT_ID_SYSTEM) { + VlanVO vlan = _vlanDao.findById(addr.getVlanId()); + String guestType = vlan.getVlanType().toString(); + if (!isIpDedicated(addr)) { + UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NET_IP_ASSIGN, owner.getId(), addr.getDataCenterId(), addr.getId(), addr.getAddress().toString(), + addr.isSourceNat(), guestType, addr.getSystem(), addr.getClass().getName(), addr.getUuid()); + } + if (updateIpResourceCount(addr)) { + _resourceLimitMgr.incrementResourceCount(owner.getId(), ResourceType.public_ip); + } + } + } + } } } - } }); } @@ -922,7 +922,6 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage public boolean applyIpAssociations(Network network, boolean continueOnError) throws ResourceUnavailableException { List userIps = _ipAddressDao.listByAssociatedNetwork(network.getId(), null); boolean success = true; - // CloudStack will take a lazy approach to associate an acquired public IP to a network service provider as // it will not know what service an acquired IP will be used for. An IP is actually associated with a provider when first // rule is applied. Similarly when last rule on the acquired IP is revoked, IP is not associated with any provider @@ -941,7 +940,6 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage } } } - return success; } From 32dc5243b6bfa0f51ffb3eeaf49e4b7fef5edf55 Mon Sep 17 00:00:00 2001 From: Santhosh Edukulla Date: Mon, 10 Nov 2014 20:05:32 +0530 Subject: [PATCH 15/26] CLOUDSTACK-7873 Fixed the user vm details length issue for higher key lengths --- engine/schema/src/com/cloud/vm/UserVmDetailVO.java | 2 +- setup/db/create-schema.sql | 2 +- setup/db/db/schema-441to450.sql | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/engine/schema/src/com/cloud/vm/UserVmDetailVO.java b/engine/schema/src/com/cloud/vm/UserVmDetailVO.java index d1a6e63fbc4..2b169a38272 100644 --- a/engine/schema/src/com/cloud/vm/UserVmDetailVO.java +++ b/engine/schema/src/com/cloud/vm/UserVmDetailVO.java @@ -39,7 +39,7 @@ public class UserVmDetailVO implements ResourceDetail { @Column(name = "name") private String name; - @Column(name = "value", length = 1024) + @Column(name = "value", length = 5120) private String value; @Column(name = "display") diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index f95b02f6ce2..b4786c0f68c 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -1140,7 +1140,7 @@ CREATE TABLE `cloud`.`user_vm_details` ( `id` bigint unsigned NOT NULL auto_increment, `vm_id` bigint unsigned NOT NULL COMMENT 'vm id', `name` varchar(255) NOT NULL, - `value` varchar(1024) NOT NULL, + `value` varchar(5120) NOT NULL, PRIMARY KEY (`id`), CONSTRAINT `fk_user_vm_details__vm_id` FOREIGN KEY `fk_user_vm_details__vm_id`(`vm_id`) REFERENCES `vm_instance`(`id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/setup/db/db/schema-441to450.sql b/setup/db/db/schema-441to450.sql index 0aa95e89ac5..61721b77774 100644 --- a/setup/db/db/schema-441to450.sql +++ b/setup/db/db/schema-441to450.sql @@ -756,3 +756,7 @@ DELETE t1 FROM guest_os_hypervisor t1, guest_os_hypervisor t2 WHERE (t1.hypervis UPDATE `cloud`.`vm_template` SET removed=NOW() WHERE unique_name="centos53-x86_64" AND hypervisor_type="XenServer"; ALTER TABLE `cloud_usage`.`usage_vpn_user` CHANGE `user_name` `user_name` VARCHAR(255); + +--Increase key value size generated from RSA-8192 to be stored. +ALTER TABLE `cloud`.`user_vm_details` MODIFY `value` VARCHAR(5120); + From 6d268db217a0c9dd0701a85f4d0244461c9ebd0b Mon Sep 17 00:00:00 2001 From: Koushik Das Date: Tue, 11 Nov 2014 16:32:20 +0530 Subject: [PATCH 16/26] CLOUDSTACK-7880: Creating shared network results in exception This is due to event publish being wrapped in a transaction, moved it outside of transaction scope. --- .../orchestration/NetworkOrchestrator.java | 9 -- .../com/cloud/network/NetworkServiceImpl.java | 92 +++++++++++-------- 2 files changed, 55 insertions(+), 46 deletions(-) diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java index 553bca16959..17a2a9b7269 100755 --- a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java +++ b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java @@ -39,7 +39,6 @@ import javax.naming.ConfigurationException; import org.apache.log4j.Logger; import org.apache.cloudstack.acl.ControlledEntity.ACLType; -import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.engine.cloud.entity.api.db.VMNetworkMapVO; import org.apache.cloudstack.engine.cloud.entity.api.db.dao.VMNetworkMapDao; @@ -676,14 +675,6 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra if (domainId != null && aclType == ACLType.Domain) { _networksDao.addDomainToNetwork(id, domainId, subdomainAccess == null ? true : subdomainAccess); - //send event for storing the domain wide resource access - Map params = new HashMap(); - params.put(ApiConstants.ENTITY_TYPE, Network.class); - params.put(ApiConstants.ENTITY_ID, id); - params.put(ApiConstants.DOMAIN_ID, domainId); - params.put(ApiConstants.SUBDOMAIN_ACCESS, subdomainAccess == null ? true : subdomainAccess); - _messageBus.publish(_name, EntityManager.MESSAGE_ADD_DOMAIN_WIDE_ENTITY_EVENT, - PublishScope.LOCAL, params); } } }); diff --git a/server/src/com/cloud/network/NetworkServiceImpl.java b/server/src/com/cloud/network/NetworkServiceImpl.java index 9f34d1f661e..1b243d074dc 100755 --- a/server/src/com/cloud/network/NetworkServiceImpl.java +++ b/server/src/com/cloud/network/NetworkServiceImpl.java @@ -150,8 +150,10 @@ import com.cloud.vm.dao.NicSecondaryIpDao; import com.cloud.vm.dao.NicSecondaryIpVO; import com.cloud.vm.dao.UserVmDao; import com.cloud.vm.dao.VMInstanceDao; + import org.apache.cloudstack.acl.ControlledEntity.ACLType; import org.apache.cloudstack.acl.SecurityChecker.AccessType; +import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.command.admin.network.CreateNetworkCmdByAdmin; import org.apache.cloudstack.api.command.admin.network.DedicateGuestVlanRangeCmd; import org.apache.cloudstack.api.command.admin.network.ListDedicatedGuestVlanRangesCmd; @@ -163,12 +165,15 @@ import org.apache.cloudstack.api.command.user.vm.ListNicsCmd; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; +import org.apache.cloudstack.framework.messagebus.MessageBus; +import org.apache.cloudstack.framework.messagebus.PublishScope; import org.apache.cloudstack.network.element.InternalLoadBalancerElementService; import org.apache.log4j.Logger; import javax.ejb.Local; import javax.inject.Inject; import javax.naming.ConfigurationException; + import java.net.Inet6Address; import java.net.InetAddress; import java.net.URI; @@ -318,6 +323,9 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService { @Inject public SecurityGroupService _securityGroupService; + @Inject + MessageBus _messageBus; + int _cidrLimit; boolean _allowSubdomainNetworkAccess; @@ -1328,70 +1336,80 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService { final String ip6Cidr, final Boolean displayNetwork, final Long aclId, final String isolatedPvlan, final NetworkOfferingVO ntwkOff, final PhysicalNetwork pNtwk, final ACLType aclType, final Account ownerFinal, final String cidr, final boolean createVlan) throws InsufficientCapacityException, ResourceAllocationException { try { - return Transaction.execute(new TransactionCallbackWithException() { + Network network = Transaction.execute(new TransactionCallbackWithException() { @Override public Network doInTransaction(TransactionStatus status) throws InsufficientCapacityException, ResourceAllocationException { Account owner = ownerFinal; Boolean subdomainAccess = subdomainAccessFinal; - Long sharedDomainId = null; - if (isDomainSpecific) { - if (domainId != null) { - sharedDomainId = domainId; - } else { - sharedDomainId = _domainMgr.getDomain(Domain.ROOT_DOMAIN).getId(); - subdomainAccess = true; - } - } + Long sharedDomainId = null; + if (isDomainSpecific) { + if (domainId != null) { + sharedDomainId = domainId; + } else { + sharedDomainId = _domainMgr.getDomain(Domain.ROOT_DOMAIN).getId(); + subdomainAccess = true; + } + } - // default owner to system if network has aclType=Domain - if (aclType == ACLType.Domain) { - owner = _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM); - } + // default owner to system if network has aclType=Domain + if (aclType == ACLType.Domain) { + owner = _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM); + } - //Create guest network - Network network = null; - if (vpcId != null) { + // Create guest network + Network network = null; + if (vpcId != null) { if (!_configMgr.isOfferingForVpc(ntwkOff)) { - throw new InvalidParameterValueException("Network offering can't be used for VPC networks"); - } + throw new InvalidParameterValueException("Network offering can't be used for VPC networks"); + } if (aclId != null) { - NetworkACL acl = _networkACLDao.findById(aclId); + NetworkACL acl = _networkACLDao.findById(aclId); if (acl == null) { - throw new InvalidParameterValueException("Unable to find specified NetworkACL"); - } + throw new InvalidParameterValueException("Unable to find specified NetworkACL"); + } if (aclId != NetworkACL.DEFAULT_DENY && aclId != NetworkACL.DEFAULT_ALLOW) { - //ACL is not default DENY/ALLOW - // ACL should be associated with a VPC + // ACL is not default DENY/ALLOW + // ACL should be associated with a VPC if (!vpcId.equals(acl.getVpcId())) { throw new InvalidParameterValueException("ACL: " + aclId + " do not belong to the VPC"); - } - } - } + } + } + } network = _vpcMgr.createVpcGuestNetwork(networkOfferingId, name, displayText, gateway, cidr, vlanId, networkDomain, owner, sharedDomainId, pNtwk, zoneId, aclType, subdomainAccess, vpcId, aclId, caller, displayNetwork); - } else { + } else { if (_configMgr.isOfferingForVpc(ntwkOff)) { - throw new InvalidParameterValueException("Network offering can be used for VPC networks only"); - } - if (ntwkOff.getInternalLb()) { - throw new InvalidParameterValueException("Internal Lb can be enabled on vpc networks only"); - } + throw new InvalidParameterValueException("Network offering can be used for VPC networks only"); + } + if (ntwkOff.getInternalLb()) { + throw new InvalidParameterValueException("Internal Lb can be enabled on vpc networks only"); + } network = _networkMgr.createGuestNetwork(networkOfferingId, name, displayText, gateway, cidr, vlanId, networkDomain, owner, sharedDomainId, pNtwk, zoneId, aclType, subdomainAccess, vpcId, ip6Gateway, ip6Cidr, displayNetwork, isolatedPvlan); - } + } - if (_accountMgr.isRootAdmin(caller.getId()) && createVlan && network != null) { - // Create vlan ip range + if (_accountMgr.isRootAdmin(caller.getId()) && createVlan && network != null) { + // Create vlan ip range _configMgr.createVlanAndPublicIpRange(pNtwk.getDataCenterId(), network.getId(), physicalNetworkId, false, null, startIP, endIP, gateway, netmask, vlanId, null, startIPv6, endIPv6, ip6Gateway, ip6Cidr); - } + } return network; } }); + if (domainId != null && aclType == ACLType.Domain) { + // send event for storing the domain wide resource access + Map params = new HashMap(); + params.put(ApiConstants.ENTITY_TYPE, Network.class); + params.put(ApiConstants.ENTITY_ID, network.getId()); + params.put(ApiConstants.DOMAIN_ID, domainId); + params.put(ApiConstants.SUBDOMAIN_ACCESS, subdomainAccessFinal == null ? true : subdomainAccessFinal); + _messageBus.publish(_name, EntityManager.MESSAGE_ADD_DOMAIN_WIDE_ENTITY_EVENT, PublishScope.LOCAL, params); + } + return network; } catch (Exception e) { ExceptionUtil.rethrowRuntime(e); ExceptionUtil.rethrow(e, InsufficientCapacityException.class); From 7efc4c388fc96bb76acd1dbc0c2d344ddc23f2d1 Mon Sep 17 00:00:00 2001 From: SrikanteswaraRao Talluri Date: Tue, 11 Nov 2014 19:18:59 +0530 Subject: [PATCH 17/26] CLOUDSTACK-7865: fixed pep8 errors and errors in wrong references to the variables --- test/integration/component/maint/test_bugs.py | 463 +++++++++--------- 1 file changed, 233 insertions(+), 230 deletions(-) diff --git a/test/integration/component/maint/test_bugs.py b/test/integration/component/maint/test_bugs.py index a543aa714fb..24dbee2d62f 100644 --- a/test/integration/component/maint/test_bugs.py +++ b/test/integration/component/maint/test_bugs.py @@ -27,9 +27,7 @@ from marvin.codes import * from nose.plugins.attrib import attr - class Test42xBugsMgmtSvr(cloudstackTestCase): - @classmethod def setUpClass(cls): try: @@ -40,37 +38,41 @@ class Test42xBugsMgmtSvr(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.pod = get_pod(cls.apiClient,zone_id=cls.zone.id) + cls.zone = get_zone(cls.api_client, + cls.testClient.getZoneForTests()) + cls.pod = get_pod(cls.apiClient, zone_id=cls.zone.id) cls.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) + cls.api_client, + cls.zone.id, + cls.services["ostype"] + ) cls.services['mode'] = cls.zone.networktype cls.services["hypervisor"] = cls.testClient.getHypervisorInfo() # Creating Disk offering, Service Offering and Account cls.service_offering = ServiceOffering.create( - cls.apiClient, - cls.services["service_offerings"] - ) + cls.apiClient, + cls.services["service_offerings"] + ) cls.account = Account.create( - cls.api_client, - cls.services["account"], - domainid=cls.domain.id - ) + cls.api_client, + cls.services["account"], + domainid=cls.domain.id + ) # Create account cls.account_2 = Account.create( - cls.api_client, - cls.services["account2"], - domainid=cls.domain.id - ) + cls.api_client, + cls.services["account2"], + 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) - #add objects created in setUpCls to the _cleanup list + cls.userapiclient = cls.testClient.getUserApiClient( + cls.user.username, + cls.domain.name + ) + # add objects created in setUpCls to the _cleanup list cls._cleanup = [cls.account, cls.account_2, cls.service_offering] @@ -99,28 +101,34 @@ class Test42xBugsMgmtSvr(cloudstackTestCase): return - @attr(tags=["advanced", "basic", "tested"]) @attr(required_hardware="false") @attr(configuration='apply.allocation.algorithm.to.pods') def test_es_1223_apply_algo_to_pods(self): """ - @Desc: Test VM creation while "apply.allocation.algorithm.to.pods" is set to true + @Desc: Test VM creation while "apply.allocation.algorithm.to.pods" is + set to true @Reference: https://issues.apache.org/jira/browse/CLOUDSTACK-4947 @Steps: - Step1: Set global configuration "apply.allocation.algorithm.to.pods" to true + Step1: Set global configuration "apply.allocation.algorithm.to.pods" + to true Step2: Restart management server Step3: Verifying that VM creation is successful """ - #Step1: set global configuration "apply.allocation.algorithm.to.pods" to true - # Configurations.update(self.apiClient, "apply.allocation.algorithm.to.pods", "true") + # Step1: set global configuration + # "apply.allocation.algorithm.to.pods" to true + # Configurations.update(self.apiClient, + # "apply.allocation.algorithm.to.pods", "true") # TODO: restart management server - if not is_config_suitable(apiclient=self.apiClient, name='apply.allocation.algorithm.to.pods', value='true'): - self.skipTest('apply.allocation.algorithm.to.pods should be true. skipping') - #TODO:Step2: Restart management server + if not is_config_suitable(apiclient=self.apiClient, + name='apply.allocation.algorithm.to.pods', + value='true'): + self.skipTest('apply.allocation.algorithm.to.pods ' + 'should be true. skipping') + # TODO:Step2: Restart management server self.services["virtual_machine"]["zoneid"] = self.zone.id self.services["virtual_machine"]["template"] = self.template.id - #Step3: Verifying that VM creation is successful + # Step3: Verifying that VM creation is successful virtual_machine = VirtualMachine.create( self.apiClient, self.services["virtual_machine2"], @@ -131,44 +139,53 @@ class Test42xBugsMgmtSvr(cloudstackTestCase): self.cleanup.append(virtual_machine) # Verify VM state self.assertEqual( - virtual_machine.state, - 'Running', - "Check VM state is Running or not" - ) + virtual_machine.state, + 'Running', + "Check VM state is Running or not" + ) - #cleanup: set global configuration "apply.allocation.algorithm.to.pods" back to false - Configurations.update(self.apiClient, "apply.allocation.algorithm.to.pods", "false") - #TODO:cleanup: Restart management server + # cleanup: set global configuration + # "apply.allocation.algorithm.to.pods" back to false + Configurations.update( + self.apiClient, + "apply.allocation.algorithm.to.pods", + "false" + ) + # TODO:cleanup: Restart management server return - @attr(tags=["advanced", "basic","tested"]) + @attr(tags=["advanced", "basic", "tested"]) @attr(required_hardware="false") def test_local_storage_data_disk_tag(self): """ - @Desc: Test whether tags are honoured while creating data disks on local storage + @Desc: Test whether tags are honoured while creating + data disks on local storage @Steps: This test needs multiple local storages Step1: create a tag 'loc' on the local storage Step2: create a disk offering with this storage tag 'loc' - Step3: create a VM and create disk by selecting the disk offering created in step2 - step4: check whether the data disk created in step3 is created on local storage with tag 'loc' + Step3: create a VM and create disk by selecting the disk offering + created in step2 + step4: check whether the data disk created in step3 is created on + local storage with tag 'loc' """ - if self.zone.localstorageenabled != True: - self.skipTest('Local storage is not enable for this zone. skipping') + if self.zone.localstorageenabled: + self.skipTest('Local storage is not enable for this ' + 'zone. skipping') local_storages = StoragePool.list(self.apiClient, zoneid=self.zone.id, scope='HOST') self.assertEqual( - isinstance(local_storages, list), - True, - "Check list response returns a valid list" - ) + isinstance(local_storages, list), + True, + "Check list response returns a valid list" + ) self.assertNotEqual( - local_storages, - None, - "Check if local storage pools exists in ListStoragePools" - ) + local_storages, + None, + "Check if local storage pools exists in ListStoragePools" + ) cmd = updateStoragePool.updateStoragePoolCmd() cmd.zoneid = self.zone.id @@ -179,12 +196,12 @@ class Test42xBugsMgmtSvr(cloudstackTestCase): self.services["disk_offering"]["storagetype"] = 'local' self.services["disk_offering"]["tags"] = 'loc' disk_offering = DiskOffering.create( - self.apiClient, - self.services["disk_offering"] - ) + self.apiClient, + self.services["disk_offering"] + ) self.services["virtual_machine"]["zoneid"] = self.zone.id self.services["virtual_machine"]["template"] = self.template.id - #Step3: Verifying that VM creation is successful + # Step3: Verifying that VM creation is successful virtual_machine = VirtualMachine.create( self.apiClient, self.services["virtual_machine"], @@ -192,60 +209,60 @@ class Test42xBugsMgmtSvr(cloudstackTestCase): domainid=self.account.domainid, serviceofferingid=self.service_offering.id, mode=self.services["mode"] - ) + ) self.cleanup.append(virtual_machine) self.cleanup.append(disk_offering) # Verify VM state self.assertEqual( - virtual_machine.state, - 'Running', - "Check VM state is Running or not" - ) - self.volume = Volume.create(self.apiClient,self.services["volume"], - zoneid=self.zone.id, - account=self.account.name, - domainid=self.account.domainid, - diskofferingid=disk_offering.id - ) - - + virtual_machine.state, + 'Running', + "Check VM state is Running or not" + ) + self.volume = Volume.create( + self.apiClient, + self.services["volume"], + zoneid=self.zone.id, + account=self.account.name, + domainid=self.account.domainid, + diskofferingid=disk_offering.id + ) virtual_machine.attach_volume(self.apiClient, self.volume) self.attached = True list_volume_response = Volume.list( - self.apiClient, - id=self.volume.id - ) + self.apiClient, + id=self.volume.id + ) self.assertEqual( - isinstance(list_volume_response, list), - True, - "Check list response returns a valid list" - ) + isinstance(list_volume_response, list), + True, + "Check list response returns a valid list" + ) self.assertNotEqual( - list_volume_response, - None, - "Check if volume exists in ListVolumes" - ) + list_volume_response, + None, + "Check if volume exists in ListVolumes" + ) volume = list_volume_response[0] self.assertNotEqual( - volume.virtualmachineid, - None, - "Check if volume state (attached) is reflected" - ) + volume.virtualmachineid, + None, + "Check if volume state (attached) is reflected" + ) storage_pool = StoragePool.list(self.apiClient, id=volume.storageid) self.assertEqual( - volume.storagetype, - 'local', - "Check list storage pool response has local as storage type" - ) + volume.storagetype, + 'local', + "Check list storage pool response has local as storage type" + ) self.assertEqual( - storage_pool[0].tags, - 'loc', - "Check list storage pool response has tag" - ) + storage_pool[0].tags, + 'loc', + "Check list storage pool response has tag" + ) return @attr(tags=["advanced", "basic"]) @@ -258,50 +275,23 @@ class Test42xBugsMgmtSvr(cloudstackTestCase): Step2: It should return a commit hash """ # Step1: run cloudstack-sccs on management server - mgmt_ssh = SshClient(self.apiClient.connection.mgtSvr, - 22, - self.apiClient.connection.user, - self.apiClient.connection.passwd - ) + mgmt_ssh = SshClient( + self.apiClient.connection.mgtSvr, + 22, + self.apiClient.connection.user, + self.apiClient.connection.passwd + ) res = mgmt_ssh.execute("cloudstack-sccs") # Step2: It should return a commit hash return - @attr(tags=["advanced", "basic"]) - @attr(required_hardware="true") - def test_add_cluster_datacenter_spaces(self): - """ - @Desc: Add VmWare cluster to the CS with the data center name contains space in between - @Steps: - Step1: Add VmWare cluster to the CS with the data center name contains space in between. - """ - if self.hypervisor.lower() != 'vmware': - self.skipTest('Can be run only on vmware zone. skipping') - cmd = addCluster.addClusterCmd() - cmd.zoneid = self.zone.id - cmd.hypervisor = self.hypervisor - cmd.clustertype= self.services["vmware_cluster"]["clustertype"] - cmd.podId = self.pod.id - cmd.username = self.services["vmware_cluster"]["username"] - cmd.password = self.services["vmware_cluster"]["password"] - cmd.publicswitchtype = 'vmwaredvs' - cmd.guestswitchtype = 'vmwaredvs' - cmd.url = self.services["vmware_cluster"]["url"] - cmd.clustername = self.services["vmware_cluster"]["url"] - - self.apiClient.addCluster(cmd) - - return - - - @attr(tags=["advanced", "basic"]) @attr(required_hardware="false") @attr(storage="s3") def test_es_1863_register_template_s3_domain_admin_user(self): """ - @Desc: Test whether cloudstack allows Domain admin or user to register a template using - S3/Swift object store. + @Desc: Test whether cloudstack allows Domain admin or user + to register a template using S3/Swift object store. @Steps: Step1: create a Domain and users in it. Step2: Register a template as Domain admin. @@ -310,9 +300,9 @@ class Test42xBugsMgmtSvr(cloudstackTestCase): """ # Step1: create a Domain and users in it. self.newdomain = Domain.create(self.apiClient, - self.services["domain"]) + self.services["domain"]) - #create account in the domain + # create account in the domain self.account_domain = Account.create( self.apiClient, self.services["account"], @@ -322,18 +312,20 @@ class Test42xBugsMgmtSvr(cloudstackTestCase): self.cleanup.append(self.newdomain) # Getting authentication for user in newly created Account in domain self.domain_user = self.account_domain.user[0] - self.domain_userapiclient = self.testClient.getUserApiClient(self.domain_user.username, self.newdomain.name) + self.domain_userapiclient = self.testClient.getUserApiClient( + self.domain_user.username, self.newdomain.name + ) # Step2: Register a template as Domain admin. self.services["templateregister"]["ostype"] = self.services["ostype"] self.domain_template = Template.register( - self.apiClient, - self.services["templateregister"], - zoneid=self.zone.id, - account=self.account_domain.name, - domainid=self.newdomain.id, - hypervisor=self.hypervisor - ) + self.apiClient, + self.services["templateregister"], + zoneid=self.zone.id, + account=self.account_domain.name, + domainid=self.newdomain.id, + hypervisor=self.hypervisor + ) # Wait for template to download self.domain_template.download(self.api_client) @@ -341,20 +333,20 @@ class Test42xBugsMgmtSvr(cloudstackTestCase): time.sleep(60) # Step3: Register a template as Domain user. self.domain_user_template = Template.register( - self.domain_userapiclient, - self.services["templateregister"], - zoneid=self.zone.id, - account=self.account_domain.name, - domainid=self.newdomain.id, - hypervisor=self.hypervisor - ) + self.domain_userapiclient, + self.services["templateregister"], + zoneid=self.zone.id, + account=self.account_domain.name, + domainid=self.newdomain.id, + hypervisor=self.hypervisor + ) # Wait for template to download self.domain_user_template.download(self.api_client) # Wait for template status to be changed across time.sleep(60) - #TODO: Step4: Template should be registered successfully. + # TODO: Step4: Template should be registered successfully. return @attr(tags=["advanced", "basic"]) @@ -365,17 +357,18 @@ class Test42xBugsMgmtSvr(cloudstackTestCase): @Desc: Test root volume resize of stopped VM @Reference: https://issues.apache.org/jira/browse/CLOUDSTACK-6181 @Steps: - Step1: Deploy VM in stopped state (startvm=false), resize via 'resizeVolume', start VM. Root is new size. + Step1: Deploy VM in stopped state (startvm=false), + resize via 'resizeVolume', start VM. Root is new size. """ # Check whether usage server is running or not - if (self.hypervisor.lower() != 'kvm'): + if self.hypervisor.lower() != 'kvm': self.skipTest("Test can be run only on KVM hypervisor") - # deploy virtural machine in stopped state + # deploy virtual machine in stopped state self.services["virtual_machine"]["zoneid"] = self.zone.id self.services["virtual_machine"]["template"] = self.template.id - #Step3: Verifying that VM creation is successful + # Step3: Verifying that VM creation is successful virtual_machine = VirtualMachine.create( self.apiClient, self.services["virtual_machine"], @@ -383,22 +376,22 @@ class Test42xBugsMgmtSvr(cloudstackTestCase): domainid=self.account.domainid, serviceofferingid=self.service_offering.id, startvm=False - ) + ) self.cleanup.append(virtual_machine) # Verify VM state self.assertEqual( - virtual_machine.state, - 'Stopped', - "Check VM state is Stopped or not" - ) + virtual_machine.state, + 'Stopped', + "Check VM state is Stopped or not" + ) volumes = list_volumes( - self.apiClient, - virtualmachineid=self.virtual_machine.id, - type='ROOT', - listall=True - ) + self.apiClient, + virtualmachineid=virtual_machine.id, + type='ROOT', + listall=True + ) - self.assertIsNotNone(volumes,"root volume is not returned properly") + self.assertIsNotNone(volumes, "root volume is not returned properly") newrootsize = (self.template.size >> 30) + 2 cmd = resizeVolume.resizeVolumeCmd() cmd.id = volumes[0].id @@ -408,11 +401,11 @@ class Test42xBugsMgmtSvr(cloudstackTestCase): virtual_machine.start(self.apiClient) volumes_after_resize = list_volumes( - self.apiClient, - virtualmachineid=self.virtual_machine.id, - type='ROOT', - listall=True - ) + self.apiClient, + virtualmachineid=virtual_machine.id, + type='ROOT', + listall=True + ) rootvolume = volumes_after_resize[0] success = False @@ -420,10 +413,10 @@ class Test42xBugsMgmtSvr(cloudstackTestCase): success = True self.assertEqual( - success, - True, - "Check if the root volume resized appropriately" - ) + success, + True, + "Check if the root volume resized appropriately" + ) return @attr(tags=["advanced", "basic"]) @@ -438,13 +431,13 @@ class Test42xBugsMgmtSvr(cloudstackTestCase): """ # Check whether usage server is running or not - if (self.hypervisor.lower() != 'kvm'): + if self.hypervisor.lower() != 'kvm': self.skipTest("Test can be run only on KVM hypervisor") - # deploy virtural machine in stopped state + # deploy virtual machine in stopped state self.services["virtual_machine"]["zoneid"] = self.zone.id self.services["virtual_machine"]["template"] = self.template.id - #Step3: Verifying that VM creation is successful + # Step3: Verifying that VM creation is successful virtual_machine = VirtualMachine.create( self.apiClient, self.services["virtual_machine"], @@ -455,18 +448,18 @@ class Test42xBugsMgmtSvr(cloudstackTestCase): self.cleanup.append(virtual_machine) # Verify VM state self.assertEqual( - virtual_machine.state, - 'Running', - "Check VM state is Running or not" - ) + virtual_machine.state, + 'Running', + "Check VM state is Running or not" + ) volumes = list_volumes( - self.apiClient, - virtualmachineid=self.virtual_machine.id, - type='ROOT', - listall=True - ) + self.apiClient, + virtualmachineid=virtual_machine.id, + type='ROOT', + listall=True + ) - self.assertIsNotNone(volumes,"root volume is not returned properly") + self.assertIsNotNone(volumes, "root volume is not returned properly") newrootsize = (self.template.size >> 30) + 2 cmd = resizeVolume.resizeVolumeCmd() cmd.id = volumes[0].id @@ -474,11 +467,11 @@ class Test42xBugsMgmtSvr(cloudstackTestCase): self.apiClient.resizeVolume(cmd) volumes_after_resize = list_volumes( - self.apiClient, - virtualmachineid=self.virtual_machine.id, - type='ROOT', - listall=True - ) + self.apiClient, + virtualmachineid=virtual_machine.id, + type='ROOT', + listall=True + ) rootvolume = volumes_after_resize[0] success = False @@ -486,10 +479,10 @@ class Test42xBugsMgmtSvr(cloudstackTestCase): success = True self.assertEqual( - success, - True, - "Check if the root volume resized appropriately" - ) + success, + True, + "Check if the root volume resized appropriately" + ) return @unittest.skip('In progress') @@ -497,13 +490,15 @@ class Test42xBugsMgmtSvr(cloudstackTestCase): @attr(required_hardware="false") def test_CLOUDSTACK_5023(self): """ - @Desc: Test whether we are able to delete PF rule while rabbit mq is collecting usage events. + @Desc: Test whether we are able to delete PF rule while + rabbit mq is collecting usage events. @Steps: step1. Run Usage server - step2. Delete a PF rule and check whether it is succesful and usage event is generated + step2. Delete a PF rule and check whether it is + successful and usage event is generated Configure RabbitMQ for usage event generation """ - #TBA + # TBA return @attr(tags=["advanced", "basic"]) @@ -511,25 +506,25 @@ class Test42xBugsMgmtSvr(cloudstackTestCase): @attr(configuration='apply.allocation.algorithm.to.pods') def test_es_47_list_os_types_win_2012(self): """ - @Desc: Test VM creation while "apply.allocation.algorithm.to.pods" is set to true + @Desc: Test VM creation while "apply.allocation.algorithm.to.pods" + is set to true @Reference: https://issues.apache.org/jira/browse/CLOUDSTACK-4947 @Steps: Step1: register windows 2012 VM template as windows 8 template - Step2: deploy a VM with windows2012 template and Verify that VM creation is successful + Step2: deploy a VM with windows2012 template and Verify + that VM creation is successful """ # register windows 2012 VM template as windows 8 template self.win2012_template = Template.register( - self.apiClient, - self.services["win2012template"], - zoneid=self.zone.id, - account=self.account.name, - domainid=self.domain.id, - hypervisor=self.hypervisor - ) - - + self.apiClient, + self.services["win2012template"], + zoneid=self.zone.id, + account=self.account.name, + domainid=self.domain.id, + hypervisor=self.hypervisor + ) # Wait for template to download self.win2012_template.download(self.apiClient) self.cleanup.append(self.win2012_template) @@ -545,24 +540,26 @@ class Test42xBugsMgmtSvr(cloudstackTestCase): self.services["virtual_machine"], accountid=self.account.name, domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - ) + serviceofferingid=self.service_offering.id + ) self.cleanup.append(vm1) # Verify VM state self.assertEqual( - vm1.state, - 'Running', - "Check VM state is Running or not" - ) + vm1.state, + 'Running', + "Check VM state is Running or not" + ) return @attr(tags=["advanced", "basic", "test"]) @attr(required_hardware="true") def test_secondary_storage_stats(self): """ - @Desc: Dashboard is not showing correct secondary storage statistics + @Desc: Dashboard is not showing correct secondary + storage statistics @Steps: - Step1: listCapacity api should show correct secondary storage statistics + Step1: listCapacity api should show correct secondary + storage statistics """ cmd = listCapacity.listCapacityCmd() cmd.type = 6 @@ -570,17 +567,20 @@ class Test42xBugsMgmtSvr(cloudstackTestCase): response = self.apiClient.listCapacity(cmd) self.assertEqual( - isinstance(response, list), - True, - "Check list response returns a valid list" - ) + isinstance(response, list), + True, + "Check list response returns a valid list" + ) self.assertNotEqual( - response, - None, - "Check if listCapacity has returned properly" - ) - self.assertNotEqual(response[0].capacitytotal, 0, "check the total capacity of secondary storage returned") - + response, + None, + "Check if listCapacity has returned properly" + ) + self.assertNotEqual( + response[0].capacitytotal, + 0, + "check the total capacity of secondary storage returned" + ) return @attr(tags=["advanced", "basic"]) @@ -593,11 +593,12 @@ class Test42xBugsMgmtSvr(cloudstackTestCase): and see that it times out with in 30seconds """ # Step1: run cloudstack-sccs on management server - mgmt_ssh = SshClient(self.apiClient.connection.mgtSvr, - 22, - self.apiClient.connection.user, - self.apiClient.connection.passwd - ) + mgmt_ssh = SshClient( + self.apiClient.connection.mgtSvr, + 22, + self.apiClient.connection.user, + self.apiClient.connection.passwd + ) res = mgmt_ssh.execute("time telnet localhost 8250") # Step2: It should return a commit hash @@ -607,16 +608,18 @@ class Test42xBugsMgmtSvr(cloudstackTestCase): @attr(required_hardware="true") def test_add_cluster_datacenter_spaces(self): """ - @Desc: Add VmWare cluster to the CS with the data center name contains space in between + @Desc: Add VmWare cluster to the CS with the data center + name contains space in between @Steps: - Step1: Add VmWare cluster to the CS with the data center name contains space in between. + Step1: Add VmWare cluster to the CS with the data center + name contains space in between. """ if self.hypervisor.lower() != 'vmware': self.skipTest('Can be run only on vmware zone. skipping') cmd = addCluster.addClusterCmd() cmd.zoneid = self.zone.id cmd.hypervisor = self.hypervisor - cmd.clustertype= self.services["vmware_cluster"]["clustertype"] + cmd.clustertype = self.services["vmware_cluster"]["clustertype"] cmd.podId = self.pod.id cmd.username = self.services["vmware_cluster"]["username"] cmd.password = self.services["vmware_cluster"]["password"] From f2cedda9efece05ef702170d5b6d3858a44de3f9 Mon Sep 17 00:00:00 2001 From: Min Chen Date: Fri, 31 Oct 2014 17:20:16 -0700 Subject: [PATCH 18/26] CLOUDSTACK-7884: Cloudstack MS is not responding (happening randomly) after some restart. --- .../cloudstack/framework/jobs/impl/AsyncJobManagerImpl.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/framework/jobs/src/org/apache/cloudstack/framework/jobs/impl/AsyncJobManagerImpl.java b/framework/jobs/src/org/apache/cloudstack/framework/jobs/impl/AsyncJobManagerImpl.java index d5f7f9df107..0e00a88b75a 100644 --- a/framework/jobs/src/org/apache/cloudstack/framework/jobs/impl/AsyncJobManagerImpl.java +++ b/framework/jobs/src/org/apache/cloudstack/framework/jobs/impl/AsyncJobManagerImpl.java @@ -61,6 +61,7 @@ import com.cloud.cluster.ManagementServerHost; import com.cloud.utils.DateUtil; import com.cloud.utils.Pair; import com.cloud.utils.Predicate; +import com.cloud.utils.component.ComponentLifecycle; import com.cloud.utils.component.ManagerBase; import com.cloud.utils.concurrency.NamedThreadFactory; import com.cloud.utils.db.DB; @@ -1035,7 +1036,9 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, private GenericSearchBuilder JoinJobTimeSearch; protected AsyncJobManagerImpl() { - + // override default run level for manager components to start this early, otherwise, VirtualMachineManagerImpl will + // get stuck in non-initializing job queue + setRunLevel(ComponentLifecycle.RUN_LEVEL_FRAMEWORK); } private void publishOnEventBus(AsyncJob job, String jobEvent) { From 0c45c96ec718edf29ba55fea7dbfda04cc3495e5 Mon Sep 17 00:00:00 2001 From: Min Chen Date: Tue, 11 Nov 2014 10:38:46 -0800 Subject: [PATCH 19/26] CLOUDSTACK-7864: CPVM continues to be in Stopped state after a failure to start because of a management server restart. Added optimization to purge queue items for cancelled jobs. --- .../jobs/impl/AsyncJobManagerImpl.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/framework/jobs/src/org/apache/cloudstack/framework/jobs/impl/AsyncJobManagerImpl.java b/framework/jobs/src/org/apache/cloudstack/framework/jobs/impl/AsyncJobManagerImpl.java index 0e00a88b75a..2ba5d1e7d3b 100644 --- a/framework/jobs/src/org/apache/cloudstack/framework/jobs/impl/AsyncJobManagerImpl.java +++ b/framework/jobs/src/org/apache/cloudstack/framework/jobs/impl/AsyncJobManagerImpl.java @@ -981,13 +981,20 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, // purge sync queue item running on this ms node _queueMgr.cleanupActiveQueueItems(msid, true); // reset job status for all jobs running on this ms node - _jobDao.resetJobProcess(msid, ApiErrorCode.INTERNAL_ERROR.getHttpCode(), "job cancelled because of management server restart or shutdown"); - // purge those queue items for those cancelled jobs above, which may not be picked up by any MS node yet - List cancelJobs = _jobDao.getResetJobs(msid); - for (AsyncJobVO job : cancelJobs){ + List jobs = _jobDao.getResetJobs(msid); + for (AsyncJobVO job : jobs) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("Cancel left-over job-" + job.getId()); + } + job.setStatus(JobInfo.Status.FAILED); + job.setResultCode(ApiErrorCode.INTERNAL_ERROR.getHttpCode()); + job.setResult("job cancelled because of management server restart or shutdown"); + _jobDao.update(job.getId(), job); + if (s_logger.isDebugEnabled()) { + s_logger.debug("Purge queue item for cancelled job-" + job.getId()); + } _queueMgr.purgeAsyncJobQueueItemId(job.getId()); } - } }); } catch (Throwable e) { From f1361796bf1fc73a65c47583dd0a5d6ef2dc3c27 Mon Sep 17 00:00:00 2001 From: Damodar Date: Tue, 11 Nov 2014 18:16:06 +0530 Subject: [PATCH 20/26] CLOUDSTACK-7886: cloudstackoperations like deployvm,deleteNW are failing if CS fail to contact rabbit mq server. This is happening in case of Async API calls. Signed-off-by: Koushik Das --- server/src/com/cloud/api/ApiServer.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/server/src/com/cloud/api/ApiServer.java b/server/src/com/cloud/api/ApiServer.java index e29ddd30512..2156d60e99c 100755 --- a/server/src/com/cloud/api/ApiServer.java +++ b/server/src/com/cloud/api/ApiServer.java @@ -304,11 +304,8 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer try { eventBus.publish(event); } catch (EventBusException evx) { - String errMsg = "F" + - "" + - "ailed to publish async job event on the the event bus."; + String errMsg = "Failed to publish async job event on the the event bus."; s_logger.warn(errMsg, evx); - throw new CloudRuntimeException(errMsg); } } From d82e556dcd980bac50f27eaca284983808e04b1c Mon Sep 17 00:00:00 2001 From: Mihaela Stoica Date: Tue, 11 Nov 2014 17:34:50 +0000 Subject: [PATCH 21/26] CLOUDSTACK-7645: [UI] Fixed incorrect label issues caused the dictionary split In some cases the UI does not display the correct text, displaying 'label.xyz' instead of the localized string. This appears to be due to the dictionary split: entries in dictionary2.jsp are not found because the dictionary has not been extended with dictionary2 as expected. In this fix: - Instead of extending the dictionary, we leave it as it is and change the localization function to look in the dictionary first and, if the item is not found there, then look in dictionary2. - This way we are not depending on the extent() function to be called at the 'right' time; In turn, the localization function will be aware of both dictionaries. - In the future, when we add another dictionary, we will have to modify this function only. --- ui/scripts/cloudStack.js | 9 +++------ ui/scripts/sharedFunctions.js | 4 +--- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/ui/scripts/cloudStack.js b/ui/scripts/cloudStack.js index c5aa89c146d..a76e10169c4 100644 --- a/ui/scripts/cloudStack.js +++ b/ui/scripts/cloudStack.js @@ -407,14 +407,11 @@ // Localization if (!$.isFunction(cloudStack.localizationFn)) { // i.e., localize is overridden by a plugin/module cloudStack.localizationFn = function(str) { - return dictionary[str]; + // look in dictionary first; if not found, try dictionary2 + var localized = dictionary[str]; + return localized ? localized : dictionary2[str]; }; } - - //added for dictionary split up - if (dictionary != undefined && dictionary2 != undefined) { - $.extend(dictionary,dictionary2); - } // Localize validation messages cloudStack.localizeValidatorMessages(); diff --git a/ui/scripts/sharedFunctions.js b/ui/scripts/sharedFunctions.js index cba6fc6e4b8..6bcc50e6729 100644 --- a/ui/scripts/sharedFunctions.js +++ b/ui/scripts/sharedFunctions.js @@ -1454,9 +1454,7 @@ var processPropertiesInImagestoreObject = function(jsonObj) { } return vmName; } - -var dictionary = {}, dictionary2 = {}; //for globalization - + var timezoneMap = new Object(); timezoneMap["Etc/GMT+12"] = "Etc/GMT+12 [GMT-12:00]"; timezoneMap["Etc/GMT+11"] = "Etc/GMT+11 [GMT-11:00]"; From 4e820b37b0b8f5318e992330a3a9a7f6f9998cff Mon Sep 17 00:00:00 2001 From: Mihaela Stoica Date: Tue, 4 Nov 2014 16:22:20 +0000 Subject: [PATCH 22/26] CLOUDSTACK-7645 [UI] Fix incorrect strings 'label.no' and 'label.added.network.offering' Conflicts: ui/dictionary2.jsp --- ui/dictionary2.jsp | 3 +++ ui/scripts/configuration.js | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ui/dictionary2.jsp b/ui/dictionary2.jsp index 8f2a378de81..28b4f05787b 100644 --- a/ui/dictionary2.jsp +++ b/ui/dictionary2.jsp @@ -1010,5 +1010,8 @@ dictionary2 = { 'label.agent.state': '', 'label.duration.in.sec': '', 'state.detached': '', +'label.na': '', +'label.added.network.offering': '', +'label.no': '' }; diff --git a/ui/scripts/configuration.js b/ui/scripts/configuration.js index f88ba851597..2a9829d47be 100644 --- a/ui/scripts/configuration.js +++ b/ui/scripts/configuration.js @@ -3167,7 +3167,7 @@ messages: { notification: function(args) { - return 'label.added.network.offering'; + return 'label.add.network.offering'; } } } From a4b92e908aa6271d3aa94656ca5d4d1ac6fd5c6c Mon Sep 17 00:00:00 2001 From: Prachi Damle Date: Tue, 11 Nov 2014 19:25:46 -0800 Subject: [PATCH 23/26] CLOUDSTACK-7590 Deletion of Account is not deleting the account from the database Revert "CLOUDSTACK-7073: Added domainId field to the user table in order to restrict duplicated users creation on the db level" This reverts commit 5a96d8ef5cbc88df366016ae9dd7ee46e4ca417a. Conflicts: setup/db/db/schema-440to450.sql --- engine/schema/src/com/cloud/user/UserVO.java | 6 ------ .../schema/src/com/cloud/user/dao/UserDaoImpl.java | 13 ------------- setup/db/db/schema-441to450.sql | 6 ------ 3 files changed, 25 deletions(-) diff --git a/engine/schema/src/com/cloud/user/UserVO.java b/engine/schema/src/com/cloud/user/UserVO.java index 8ab450d877a..68879f6f807 100644 --- a/engine/schema/src/com/cloud/user/UserVO.java +++ b/engine/schema/src/com/cloud/user/UserVO.java @@ -97,9 +97,6 @@ public class UserVO implements User, Identity, InternalIdentity { @Column(name = "default") boolean isDefault; - @Column(name = "domain_id") - private long domainId; - public UserVO() { this.uuid = UUID.randomUUID().toString(); } @@ -273,7 +270,4 @@ public class UserVO implements User, Identity, InternalIdentity { return isDefault; } - public void setDomainId(long domainId) { - this.domainId = domainId; - } } diff --git a/engine/schema/src/com/cloud/user/dao/UserDaoImpl.java b/engine/schema/src/com/cloud/user/dao/UserDaoImpl.java index d39177eb67b..6ac398d81c2 100644 --- a/engine/schema/src/com/cloud/user/dao/UserDaoImpl.java +++ b/engine/schema/src/com/cloud/user/dao/UserDaoImpl.java @@ -19,11 +19,9 @@ package com.cloud.user.dao; import java.util.List; import javax.ejb.Local; -import javax.inject.Inject; import org.springframework.stereotype.Component; -import com.cloud.user.Account; import com.cloud.user.UserVO; import com.cloud.utils.db.DB; import com.cloud.utils.db.GenericDaoBase; @@ -42,9 +40,6 @@ public class UserDaoImpl extends GenericDaoBase implements UserDao protected SearchBuilder SecretKeySearch; protected SearchBuilder RegistrationTokenSearch; - @Inject - AccountDao _accountDao; - protected UserDaoImpl() { UsernameSearch = createSearchBuilder(); UsernameSearch.and("username", UsernameSearch.entity().getUsername(), SearchCriteria.Op.EQ); @@ -133,12 +128,4 @@ public class UserDaoImpl extends GenericDaoBase implements UserDao return listBy(sc); } - @Override - @DB - public UserVO persist(UserVO user) { - Account account = _accountDao.findById(user.getAccountId()); - user.setDomainId(account.getDomainId()); - return super.persist(user); - } - } diff --git a/setup/db/db/schema-441to450.sql b/setup/db/db/schema-441to450.sql index 61721b77774..1f0e2266031 100644 --- a/setup/db/db/schema-441to450.sql +++ b/setup/db/db/schema-441to450.sql @@ -278,12 +278,6 @@ CREATE TABLE `cloud`.`brocade_network_vlan_map` ( /* As part of the separation of Xen and XenServer, update the column for the network labels */ ALTER TABLE `cloud`.`physical_network_traffic_types` CHANGE `xen_network_label` `xenserver_network_label` varchar(255) COMMENT 'The network name label of the physical device dedicated to this traffic on a XenServer host'; -/*Adding domainId field to the user table in order to restrict duplicated users creation on the db level*/ -ALTER TABLE `cloud`.`user` ADD COLUMN domain_id bigint(20) unsigned DEFAULT NULL; -ALTER TABLE `cloud`.`user` ADD CONSTRAINT `fk_user__domain_id` FOREIGN KEY `fk_user__domain_id`(`domain_id`) REFERENCES `domain`(`id`) ON DELETE CASCADE; -UPDATE `cloud`.`user` SET `cloud`.`user`.domain_id=(SELECT `cloud`.`account`.domain_id FROM `cloud`.`account` WHERE `cloud`.`account`.id=`cloud`.`user`.account_id) where id > 0; -ALTER TABLE `cloud`.`user` ADD UNIQUE KEY `username_domain_id` (`username`,`domain_id`); - ALTER TABLE `cloud`.`volumes` CHANGE COLUMN `iso_id` `iso_id` bigint(20) unsigned COMMENT 'The id of the iso from which the volume was created'; DROP VIEW IF EXISTS `cloud`.`storage_pool_view`; From 6c955a3a472da1308a5336a48b29514b78c543e4 Mon Sep 17 00:00:00 2001 From: Pierre-Luc Dion Date: Wed, 12 Nov 2014 19:18:37 -0500 Subject: [PATCH 24/26] CLOUDSTACK-7887: change int to str into swiftxen --- scripts/vm/hypervisor/xenserver/swiftxen | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/vm/hypervisor/xenserver/swiftxen b/scripts/vm/hypervisor/xenserver/swiftxen index 8342238ad82..f56d5ad7ff0 100644 --- a/scripts/vm/hypervisor/xenserver/swiftxen +++ b/scripts/vm/hypervisor/xenserver/swiftxen @@ -69,7 +69,7 @@ def upload(args): if size > MAX_SEG_SIZE : segment = 1 if segment : - cmd = [SWIFT, "-A", url, "-U", account + ":" + username, "-K", key, "upload", "-S", MAX_SEG_SIZE, container, lfilename] + cmd = [SWIFT, "-A", url, "-U", account + ":" + username, "-K", key, "upload", "-S", str(MAX_SEG_SIZE), container, lfilename] else : cmd = [SWIFT, "-A", url ,"-U", account + ":" + username, "-K", key, "upload", container, lfilename] util.pread2(cmd) From 9809164654159fd1cea4842d76a6a0b97fc72e54 Mon Sep 17 00:00:00 2001 From: Jessica Wang Date: Wed, 12 Nov 2014 16:24:15 -0800 Subject: [PATCH 25/26] CLOUDSTACK-7896: UI > network > Add Guest Network > when zone dropdown is empty, do not make API call to get physical networks. --- ui/scripts/sharedFunctions.js | 76 ++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/ui/scripts/sharedFunctions.js b/ui/scripts/sharedFunctions.js index 6bcc50e6729..1adab5b47d2 100644 --- a/ui/scripts/sharedFunctions.js +++ b/ui/scripts/sharedFunctions.js @@ -262,7 +262,7 @@ var addGuestNetworkDialog = { if (items != null) { for (var i = 0; i < items.length; i++) { if (items[i].networktype == 'Advanced') { - addGuestNetworkDialog.zoneObjs.push(items[i]); + addGuestNetworkDialog.zoneObjs.push(items[i]); } } } @@ -288,42 +288,44 @@ var addGuestNetworkDialog = { if ('physicalNetworks' in args.context) { //Infrastructure menu > zone detail > guest traffic type > network tab (only shown in advanced zone) > add guest network dialog addGuestNetworkDialog.physicalNetworkObjs = args.context.physicalNetworks; } else { //Network menu > guest network section > add guest network dialog - var selectedZoneId = args.$form.find('.form-item[rel=zoneId]').find('select').val(); - $.ajax({ - url: createURL('listPhysicalNetworks'), - data: { - zoneid: selectedZoneId - }, - async: false, - success: function(json) { - var items = []; - var physicalnetworks = json.listphysicalnetworksresponse.physicalnetwork; - if (physicalnetworks != null) { - for (var i = 0; i < physicalnetworks.length; i++) { - $.ajax({ - url: createURL('listTrafficTypes'), - data: { - physicalnetworkid: physicalnetworks[i].id - }, - async: false, - success: function(json) { - var traffictypes = json.listtraffictypesresponse.traffictype; - if (traffictypes != null) { - for (var k = 0; k < traffictypes.length; k++) { - if (traffictypes[k].traffictype == 'Guest') { - items.push(physicalnetworks[i]); - break; - } - } - } - } - }); - } - } - - addGuestNetworkDialog.physicalNetworkObjs = items; - } - }); + var selectedZoneId = args.$form.find('.form-item[rel=zoneId]').find('select').val(); + if (selectedZoneId != undefined && selectedZoneId.length > 0) { + $.ajax({ + url: createURL('listPhysicalNetworks'), + data: { + zoneid: selectedZoneId + }, + async: false, + success: function(json) { + var items = []; + var physicalnetworks = json.listphysicalnetworksresponse.physicalnetwork; + if (physicalnetworks != null) { + for (var i = 0; i < physicalnetworks.length; i++) { + $.ajax({ + url: createURL('listTrafficTypes'), + data: { + physicalnetworkid: physicalnetworks[i].id + }, + async: false, + success: function(json) { + var traffictypes = json.listtraffictypesresponse.traffictype; + if (traffictypes != null) { + for (var k = 0; k < traffictypes.length; k++) { + if (traffictypes[k].traffictype == 'Guest') { + items.push(physicalnetworks[i]); + break; + } + } + } + } + }); + } + } + + addGuestNetworkDialog.physicalNetworkObjs = items; + } + }); + } } var items = []; if (addGuestNetworkDialog.physicalNetworkObjs != null) { From 8b7c1d7c5e1d7b4396c57d4cf20b24217335bc8e Mon Sep 17 00:00:00 2001 From: Mike Tutkowski Date: Wed, 12 Nov 2014 21:03:03 -0700 Subject: [PATCH 26/26] CLOUDSTACK-7898: Add properties file in same folder as template --- .../Xenserver625StorageProcessor.java | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/Xenserver625StorageProcessor.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/Xenserver625StorageProcessor.java index 20baffd6bf4..eec01db832a 100644 --- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/Xenserver625StorageProcessor.java +++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/Xenserver625StorageProcessor.java @@ -904,10 +904,29 @@ public class Xenserver625StorageProcessor extends XenServerStorageProcessor { } destVdi = VDI.getByUuid(conn, destVdiUuid); - String templatePath = destDir + "/" + destVdiUuid + ".vhd"; - templatePath = templatePath.replaceAll("//","/"); + + // scan makes XenServer pick up VDI physicalSize + destSr.scan(conn); + + String templateUuid = destVdi.getUuid(conn); + String templateFilename = templateUuid + ".vhd"; + long virtualSize = destVdi.getVirtualSize(conn); + long physicalSize = destVdi.getPhysicalUtilisation(conn); + + String templatePath = destNfsPath + "/" + destDir; + + templatePath = templatePath.replaceAll("//", "/"); + + result = hypervisorResource.postCreatePrivateTemplate(conn, templatePath, templateFilename, templateUuid, nameLabel, null, + physicalSize, virtualSize, destObj.getId()); + + if (!result) { + throw new CloudRuntimeException("Could not create the template.properties file on secondary storage dir"); + } + TemplateObjectTO newTemplate = new TemplateObjectTO(); - newTemplate.setPath(templatePath); + + newTemplate.setPath(destDir + "/" + templateFilename); newTemplate.setFormat(Storage.ImageFormat.VHD); newTemplate.setSize(destVdi.getVirtualSize(conn)); newTemplate.setPhysicalSize(destVdi.getPhysicalUtilisation(conn));