From ac776608645a211328b7d5cb4865c798251aae87 Mon Sep 17 00:00:00 2001 From: Gaurav Aradhye Date: Sun, 18 Aug 2013 23:28:50 -0400 Subject: [PATCH] CLOUDSTACK-4356: Added code for checking empty host, skip the test if no empty host found Signed-off-by: Prasanna Santhanam --- .../component/test_implicit_planner.py | 44 +++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/test/integration/component/test_implicit_planner.py b/test/integration/component/test_implicit_planner.py index 854b48148c6..f233ba9791e 100644 --- a/test/integration/component/test_implicit_planner.py +++ b/test/integration/component/test_implicit_planner.py @@ -104,8 +104,7 @@ class TestImplicitPlanner(cloudstackTestCase): cls.zone.id, cls.services["ostype"] ) - # Set Zones and disk offerings - cls.services["small"]["zoneid"] = cls.zone.id + # Set template id cls.services["small"]["template"] = template.id # Create VMs, NAT Rules etc @@ -154,6 +153,45 @@ class TestImplicitPlanner(cloudstackTestCase): # host that is empty (not running vms of any other account) # 2. Deploy another vm it should get deployed on the same host. + # list and find an empty host + all_hosts = list_hosts( + self.apiclient, + type='Routing', + ) + + empty_host = None + for host in all_hosts: + vms_on_host = list_virtual_machines( + self.api_client, + hostid=host.id, + listall=True) + + # If no user vms on host, then further check for any System vms running + if vms_on_host is None: + ssvms_on_host = list_ssvms( + self.api_client, + hostid=host.id, + listall=True) + + # If no ssvms running on host, then further check for routers + if ssvms_on_host is None: + routers_on_host = list_routers( + self.api_client, + hostid=host.id, + listall=True) + + # If no routers are running on host, then this host can be considered + # as empty for implicit dedication + + if routers_on_host is None: + empty_host = host + self.services["small"]["zoneid"] = host.zoneid + break + + #If no empty host is found, return + if empty_host is None: + self.skipTest("Did not find any empty hosts, Skipping") + #create a virtual machine virtual_machine_1 = VirtualMachine.create( self.api_client, @@ -226,4 +264,4 @@ class TestImplicitPlanner(cloudstackTestCase): vm_response_2.hostid, "Check both vms have the same host id" ) - return \ No newline at end of file + return