CLOUDSTACK-4356: Added code for checking empty host, skip the test if no empty host found

Signed-off-by: Prasanna Santhanam <tsp@apache.org>
This commit is contained in:
Gaurav Aradhye 2013-08-18 23:28:50 -04:00 committed by Prasanna Santhanam
parent 9ed5083f9b
commit ac77660864

View File

@ -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
return