You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ta...@apache.org on 2014/03/10 06:48:57 UTC

git commit: updated refs/heads/master to 3b3ae02

Repository: cloudstack
Updated Branches:
  refs/heads/master 09c375379 -> 3b3ae0245


CLOUDSTACK-5626: Simplifying VM Migrate code

Signed-off-by: SrikanteswaraRao Talluri <ta...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/3b3ae024
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/3b3ae024
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/3b3ae024

Branch: refs/heads/master
Commit: 3b3ae024591fae4db9a6ca991d4838d98b96154e
Parents: 09c3753
Author: Gaurav Aradhye <ga...@clogeny.com>
Authored: Thu Mar 6 21:38:41 2014 -0500
Committer: SrikanteswaraRao Talluri <ta...@apache.org>
Committed: Mon Mar 10 11:18:26 2014 +0530

----------------------------------------------------------------------
 .../component/test_cpu_domain_limits.py         |  11 +-
 test/integration/component/test_cpu_limits.py   |  15 ++-
 .../component/test_cpu_project_limits.py        |   7 +-
 .../integration/component/test_memory_limits.py |  15 ++-
 .../component/test_mm_domain_limits.py          |   7 +-
 .../component/test_mm_project_limits.py         |   7 +-
 .../component/test_vpc_vm_life_cycle.py         | 108 ++++---------------
 tools/marvin/marvin/codes.py                    |   1 +
 tools/marvin/marvin/integration/lib/common.py   |  25 +++--
 9 files changed, 80 insertions(+), 116 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b3ae024/test/integration/component/test_cpu_domain_limits.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_cpu_domain_limits.py b/test/integration/component/test_cpu_domain_limits.py
index c427e4f..1247a79 100644
--- a/test/integration/component/test_cpu_domain_limits.py
+++ b/test/integration/component/test_cpu_domain_limits.py
@@ -30,10 +30,11 @@ from marvin.integration.lib.base import (
 from marvin.integration.lib.common import (get_domain,
                                         get_zone,
                                         get_template,
-                                        find_suitable_host,
+                                        findSuitableHostForMigration,
                                         get_resource_type
                                         )
 from marvin.integration.lib.utils import cleanup_resources
+from marvin.codes import ERROR_NO_HOST_FOR_MIGRATION
 
 class Services:
     """Test resource limit services
@@ -329,7 +330,9 @@ class TestDomainCPULimitsUpdateResources(cloudstackTestCase):
             self.assertEqual(resource_count, expected_resource_count,
                 "Initial resource count should match with the expected resource count")
 
-            host = find_suitable_host(self.apiclient, vm)
+            host = findSuitableHostForMigration(self.apiclient, vm.id)
+            if host is None:
+                self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
             self.debug("Migrating instance: %s to host: %s" %
                        (vm.name, host.name))
             try:
@@ -477,7 +480,9 @@ class TestDomainCPULimitsUpdateResources(cloudstackTestCase):
             self.assertEqual(resource_count_after_delete, expected_resource_count,
                 "Resource count should match with the expected count")
 
-            host = find_suitable_host(self.apiclient, vm_2)
+            host = findSuitableHostForMigration(self.apiclient, vm_2.id)
+            if host is None:
+                self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
             self.debug("Migrating instance: %s to host: %s" % (vm_2.name,
                                                                host.name))
             try:

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b3ae024/test/integration/component/test_cpu_limits.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_cpu_limits.py b/test/integration/component/test_cpu_limits.py
index bdf2869..f043773 100644
--- a/test/integration/component/test_cpu_limits.py
+++ b/test/integration/component/test_cpu_limits.py
@@ -30,10 +30,11 @@ from marvin.integration.lib.base import (
 from marvin.integration.lib.common import (get_domain,
                                         get_zone,
                                         get_template,
-                                        find_suitable_host,
+                                        findSuitableHostForMigration,
                                         get_resource_type
                                         )
 from marvin.integration.lib.utils import cleanup_resources
+from marvin.codes import ERROR_NO_HOST_FOR_MIGRATION
 
 
 class Services:
@@ -251,7 +252,9 @@ class TestCPULimits(cloudstackTestCase):
         self.assertEqual(resource_count, expected_resource_count,
                          "Resource count should match with the expected resource count")
 
-        host = find_suitable_host(self.apiclient, self.vm)
+        host = findSuitableHostForMigration(self.apiclient, self.vm.id)
+        if host is None:
+            self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
         self.debug("Migrating instance: %s to host: %s" % (self.vm.name, host.name))
         try:
             self.vm.migrate(self.apiclient, host.id)
@@ -570,7 +573,9 @@ class TestDomainCPULimitsConfiguration(cloudstackTestCase):
         self.assertEqual(resource_count, expected_resource_count,
             "Initial resource count should with the expected resource count")
 
-        host = find_suitable_host(self.apiclient, vm)
+        host = findSuitableHostForMigration(self.apiclient, vm.id)
+        if host is None:
+            self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
         self.debug("Migrating instance: %s to host: %s" %
                    (vm.name, host.name))
         try:
@@ -725,7 +730,9 @@ class TestDomainCPULimitsConfiguration(cloudstackTestCase):
             self.assertEqual(resource_count_after_delete, expected_resource_count,
                 "Resource count should be less than before after deleting the instance")
 
-            host = find_suitable_host(self.apiclient, vm_2)
+            host = findSuitableHostForMigration(self.apiclient, vm_2.id)
+            if host is None:
+                self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
             self.debug("Migrating instance: %s to host: %s" % (vm_2.name,
                                                                host.name))
             try:

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b3ae024/test/integration/component/test_cpu_project_limits.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_cpu_project_limits.py b/test/integration/component/test_cpu_project_limits.py
index a8a1b3c..ed7cd88 100644
--- a/test/integration/component/test_cpu_project_limits.py
+++ b/test/integration/component/test_cpu_project_limits.py
@@ -30,10 +30,11 @@ from marvin.integration.lib.base import (
 from marvin.integration.lib.common import (get_domain,
                                         get_zone,
                                         get_template,
-                                        find_suitable_host,
+                                        findSuitableHostForMigration,
                                         get_resource_type
                                         )
 from marvin.integration.lib.utils import cleanup_resources
+from marvin.codes import ERROR_NO_HOST_FOR_MIGRATION
 
 class Services:
     """Test resource limit services
@@ -291,7 +292,9 @@ class TestProjectsCPULimits(cloudstackTestCase):
         self.assertEqual(resource_count, expected_resource_count,
                          "Resource count should match with the expected resource count")
 
-        host = find_suitable_host(self.apiclient, self.vm)
+        host = findSuitableHostForMigration(self.apiclient, self.vm.id)
+        if host is None:
+            self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
         self.debug("Migrating instance: %s to host: %s" %
                                                     (self.vm.name, host.name))
         try:

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b3ae024/test/integration/component/test_memory_limits.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_memory_limits.py b/test/integration/component/test_memory_limits.py
index 7921e4b..231307f 100644
--- a/test/integration/component/test_memory_limits.py
+++ b/test/integration/component/test_memory_limits.py
@@ -30,10 +30,11 @@ from marvin.integration.lib.common import (get_domain,
                                         get_zone,
                                         get_template,
                                         wait_for_cleanup,
-                                        find_suitable_host,
+                                        findSuitableHostForMigration,
                                         get_resource_type
                                         )
 from marvin.integration.lib.utils import cleanup_resources
+from marvin.codes import ERROR_NO_HOST_FOR_MIGRATION
 
 class Services:
     """Test memory resource limit services
@@ -248,7 +249,9 @@ class TestMemoryLimits(cloudstackTestCase):
         self.assertEqual(resource_count, expected_resource_count,
                          "Resource count should match with the expected resource count")
 
-        host = find_suitable_host(self.apiclient, self.vm)
+        host = findSuitableHostForMigration(self.apiclient, self.vm.id)
+        if host is None:
+            self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
         self.debug("Migrating instance: %s to host: %s" % (self.vm.name, host.name))
         try:
             self.vm.migrate(self.apiclient, host.id)
@@ -587,7 +590,9 @@ class TestDomainMemoryLimitsConfiguration(cloudstackTestCase):
             self.assertEqual(resource_count, expected_resource_count,
                          "Initial resource count should with the expected resource count")
 
-            host = find_suitable_host(self.apiclient, vm)
+            host = findSuitableHostForMigration(self.apiclient, vm.id)
+            if host is None:
+                self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
             self.debug("Migrating instance: %s to host: %s" %
                                                         (vm.name, host.name))
             try:
@@ -743,7 +748,9 @@ class TestDomainMemoryLimitsConfiguration(cloudstackTestCase):
             self.assertEqual(resource_count_after_delete, expected_resource_count,
                          "Resource count should match with the expected resource count")
 
-            host = find_suitable_host(self.apiclient, vm_2)
+            host = findSuitableHostForMigration(self.apiclient, vm_2.id)
+            if host is None:
+                self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
             self.debug("Migrating instance: %s to host: %s" % (vm_2.name,
                                                                host.name))
             try:

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b3ae024/test/integration/component/test_mm_domain_limits.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_mm_domain_limits.py b/test/integration/component/test_mm_domain_limits.py
index 68660c1..a2b7395 100644
--- a/test/integration/component/test_mm_domain_limits.py
+++ b/test/integration/component/test_mm_domain_limits.py
@@ -30,11 +30,12 @@ from marvin.integration.lib.common import (get_domain,
                                         get_zone,
                                         get_template,
 					                    wait_for_cleanup,
-                                        find_suitable_host,
+                                        findSuitableHostForMigration,
                                         get_resource_type,
                                         update_resource_count
                                         )
 from marvin.integration.lib.utils import cleanup_resources
+from marvin.codes import ERROR_NO_HOST_FOR_MIGRATION
 
 class Services:
     """Test memory resource limit services
@@ -388,7 +389,9 @@ class TestDomainMemoryLimits(cloudstackTestCase):
             self.assertEqual(resource_count, expected_resource_count,
                          "Resource count should match with the expected resource count")
 
-            host = find_suitable_host(self.apiclient, vm)
+            host = findSuitableHostForMigration(self.apiclient, vm.id)
+            if host is None:
+                self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
             self.debug("Migrating instance: %s to host: %s" %
                                                         (vm.name, host.name))
             try:

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b3ae024/test/integration/component/test_mm_project_limits.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_mm_project_limits.py b/test/integration/component/test_mm_project_limits.py
index c314011..29a3b54 100644
--- a/test/integration/component/test_mm_project_limits.py
+++ b/test/integration/component/test_mm_project_limits.py
@@ -30,10 +30,11 @@ from marvin.integration.lib.common import (get_domain,
                                         get_zone,
                                         get_template,
 					                    wait_for_cleanup,
-                                        find_suitable_host,
+                                        findSuitableHostForMigration,
                                         get_resource_type
                                         )
 from marvin.integration.lib.utils import cleanup_resources
+from marvin.codes import ERROR_NO_HOST_FOR_MIGRATION
 
 class Services:
     """Test memory resource limit services
@@ -291,7 +292,9 @@ class TestProjectsMemoryLimits(cloudstackTestCase):
         resource_count = project_list[0].memorytotal
         self.debug(resource_count)
 
-        host = find_suitable_host(self.apiclient, self.vm)
+        host = findSuitableHostForMigration(self.apiclient, self.vm.id)
+        if host is None:
+            self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
         self.debug("Migrating instance: %s to host: %s" %
                                                     (self.vm.name, host.name))
         try:

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b3ae024/test/integration/component/test_vpc_vm_life_cycle.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_vpc_vm_life_cycle.py b/test/integration/component/test_vpc_vm_life_cycle.py
index 01373ac..e40067e 100644
--- a/test/integration/component/test_vpc_vm_life_cycle.py
+++ b/test/integration/component/test_vpc_vm_life_cycle.py
@@ -41,9 +41,10 @@ from marvin.integration.lib.common import (get_domain,
                                            get_free_vlan,
                                            wait_for_cleanup,
                                            list_virtual_machines,
-                                           list_hosts)
+                                           list_hosts,
+                                           findSuitableHostForMigration)
 
-from marvin.codes import PASS
+from marvin.codes import PASS, ERROR_NO_HOST_FOR_MIGRATION
 
 import time
 
@@ -715,35 +716,13 @@ class TestVMLifeCycleVPC(cloudstackTestCase):
         #    works as expected.
         # 3. Make sure that we are able to access google.com from this user Vm
 
-        vm_list = VirtualMachine.list(self.apiclient, id=self.vm_1.id)
-        self.assertEqual(validateList(vm_list)[0], PASS, "vm list validation failed, vm list is %s" % vm_list)
-
-        vm_hostid = vm_list[0].hostid
-
-        self.debug("Checking if the host is available for migration?")
-        hosts = Host.list(
-                          self.apiclient,
-                          zoneid=self.zone.id,
-                          type='Routing'
-                          )
-
-        self.assertEqual(
-                         isinstance(hosts, list),
-                         True,
-                         "List hosts should return a valid list"
-                         )
-        if len(hosts) < 2:
-            raise unittest.SkipTest(
-            "No host available for migration. Test requires atleast 2 hosts")
-
-        # Remove the host of current VM from the hosts list
-        hosts[:] = [host for host in hosts if host.id != vm_hostid]
-
-        host = hosts[0]
-
         self.debug("Validating if the network rules work properly or not?")
         self.validate_network_rules()
 
+        host = findSuitableHostForMigration(self.apiclient, self.vm_1.id)
+        if host is None:
+            self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
+
         self.debug("Migrating VM-ID: %s to Host: %s" % (
                                                         self.vm_1.id,
                                                         host.id
@@ -1506,30 +1485,13 @@ class TestVMLifeCycleSharedNwVPC(cloudstackTestCase):
         #    works as expected.
         # 3. Make sure that we are able to access google.com from this user Vm
 
-        self.debug("Checking if the host is available for migration?")
-        hosts = Host.list(
-                          self.apiclient,
-                          zoneid=self.zone.id,
-                          type='Routing'
-                          )
-
-        self.assertEqual(
-                         isinstance(hosts, list),
-                         True,
-                         "List hosts should return a valid list"
-                         )
-        if len(hosts) < 2:
-            raise unittest.SkipTest(
-            "No host available for migration. Test requires atleast 2 hosts")
-
-        # Remove the host of current VM from the hosts list
-        hosts[:] = [host for host in hosts if host.id != self.vm_1.hostid]
-
-        host = hosts[0]
-
         self.debug("Validating if network rules are coonfigured properly?")
         self.validate_network_rules()
 
+        host = findSuitableHostForMigration(self.apiclient, self.vm_1.id)
+        if host is None:
+            self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
+
         self.debug("Migrating VM-ID: %s to Host: %s" % (
                                                         self.vm_1.id,
                                                         host.id
@@ -2559,30 +2521,13 @@ class TestVMLifeCycleStoppedVPCVR(cloudstackTestCase):
         #    works as expected.
         # 3. Make sure that we are able to access google.com from this user Vm
 
-        self.debug("Checking if the host is available for migration?")
-        hosts = Host.list(
-                          self.apiclient,
-                          zoneid=self.zone.id,
-                          type='Routing'
-                          )
-
-        self.assertEqual(
-                         isinstance(hosts, list),
-                         True,
-                         "List hosts should return a valid list"
-                         )
-        if len(hosts) < 2:
-            raise unittest.SkipTest(
-            "No host available for migration. Test requires atleast 2 hosts")
-
-        # Remove the host of current VM from the hosts list
-        hosts[:] = [host for host in hosts if host.id != self.vm_1.hostid]
-
-        host = hosts[0]
-
         self.debug("Validating if the network rules work properly or not?")
         self.validate_network_rules()
 
+        host = findSuitableHostForMigration(self.apiclient, self.vm_1.id)
+        if host is None:
+            self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
+
         self.debug("Migrating VM-ID: %s on Host: %s to Host: %s" % (
                                                         self.vm_1.id,
                                                         self.vm_1.hostid,
@@ -3459,28 +3404,13 @@ class TestVMLifeCycleDiffHosts(cloudstackTestCase):
         #    works as expected.
         # 3. Make sure that we are able to access google.com from this user Vm
 
-        self.debug("Checking if the host is available for migration?")
-        hosts = Host.listForMigration(
-                          self.apiclient,
-                          virtualmachineid=self.vm_1.id,
-                          )
-        self.debug("Hosts vm can be migrated to are : %s" %(hosts))
-        self.assertEqual(
-                         isinstance(hosts, list),
-                         True,
-                         "List hosts should return a valid list"
-                         )
-        # Remove the host of current VM from the hosts list
-        hosts[:] = [host for host in hosts if host.id != self.vm_1.hostid]
-        if len(hosts) <= 0:
-            self.skipTest(
-            "No host available for migration. Test requires atleast 2 hosts tagged with host1")
-
-        host = hosts[0]
-
         self.debug("Validating if the network rules work properly or not?")
         self.validate_network_rules()
 
+        host = findSuitableHostForMigration(self.apiclient, self.vm_1.id)
+        if host is None:
+            self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
+
         self.debug("Migrating VM-ID: %s to Host: %s" % (
                                                         self.vm_1.id,
                                                         host.id

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b3ae024/tools/marvin/marvin/codes.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/codes.py b/tools/marvin/marvin/codes.py
index 3882f0d..e4a0f6a 100644
--- a/tools/marvin/marvin/codes.py
+++ b/tools/marvin/marvin/codes.py
@@ -51,3 +51,4 @@ BASIC_ZONE = "basic"
 ISOLATED_NETWORK = "ISOLATED"
 SHARED_NETWORK = "SHARED"
 VPC_NETWORK = "VPC"
+ERROR_NO_HOST_FOR_MIGRATION = "Could not find suitable host for migration, please ensure setup has required no. of hosts"

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3b3ae024/tools/marvin/marvin/integration/lib/common.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/integration/lib/common.py b/tools/marvin/marvin/integration/lib/common.py
index b2da3ff..d3d634b 100644
--- a/tools/marvin/marvin/integration/lib/common.py
+++ b/tools/marvin/marvin/integration/lib/common.py
@@ -712,18 +712,23 @@ def update_resource_count(apiclient, domainid, accountid=None,
                               )
         return
 
-def find_suitable_host(apiclient, vm):
-        """Returns a suitable host for VM migration"""
+def findSuitableHostForMigration(apiclient, vmid):
+    """Returns a suitable host for VM migration"""
+    suitableHost = None
+    try:
+        hosts = Host.listForMigration(apiclient, virtualmachineid=vmid,
+                )
+    except Exception as e:
+        raise Exception("Exception while getting hosts list suitable for migration: %s" % e)
 
-        hosts = Host.list(apiclient,
-                          virtualmachineid=vm.id,
-                          listall=True)
+    suitablehosts = []
+    if isinstance(hosts, list) and len(hosts) > 0:
+        suitablehosts = [host for host in hosts if (str(host.resourcestate).lower() == "enabled"\
+                and str(host.state).lower() == "up")]
+        if len(suitablehosts)>0:
+            suitableHost = suitablehosts[0]
 
-        if isinstance(hosts, list):
-            assert len(hosts) > 0, "List host should return valid response"
-        else:
-            raise Exception("Exception: List host should return valid response")
-        return hosts[0]
+    return suitableHost
 
 def get_resource_type(resource_id):
         """Returns resource type"""