Skip to content

Commit 40943e8

Browse files
author
sanjeev
committed
Hosts without tag are not listed while listing the hosts for migration for instance with tag
1 parent cb2b9e8 commit 40943e8

File tree

1 file changed

+98
-3
lines changed

1 file changed

+98
-3
lines changed

test/integration/component/test_tags.py

Lines changed: 98 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# Import Local Modules
2020
from nose.plugins.attrib import attr
2121
from marvin.cloudstackTestCase import cloudstackTestCase
22-
from marvin.lib.utils import cleanup_resources
22+
from marvin.lib.utils import cleanup_resources, validateList
2323
from marvin.lib.base import (Tag,
2424
Account,
2525
VirtualMachine,
@@ -40,8 +40,9 @@
4040
from marvin.lib.common import (get_zone,
4141
get_domain,
4242
get_template,
43-
find_storage_pool_type)
44-
from marvin.codes import FAILED
43+
find_storage_pool_type,
44+
list_clusters)
45+
from marvin.codes import FAILED, PASS
4546
import time
4647

4748

@@ -2304,3 +2305,97 @@ def test_22_create_tag_destroyed_vm(self):
23042305
self.fail("Failed to delete the tag - %s" % e)
23052306

23062307
return
2308+
2309+
@attr(tags=["advanced", "basic"], required_hardware="false")
2310+
def test_23_list_untagged_host_for_vm_migration(self):
2311+
"""
2312+
@Hosts without tag are not listed while listing the hosts for migration for instance with tag
2313+
Steps:
2314+
1.Add tag say "tag1" to host1 in a cluster with min of two hosts
2315+
2.Create compute offering with host tag "tag1"
2316+
3.Deploy vm with the above offering
2317+
4.list hosts for migration for the above deployed vm
2318+
5.All untagged hosts in the cluster must be listed as available hosts for vm migration
2319+
"""
2320+
tag = "tag1"
2321+
clusters = list_clusters(self.apiclient, zoneid=self.zone.id)
2322+
self.assertEqual(
2323+
validateList(clusters)[0],
2324+
PASS,
2325+
"list clusters returned invalid response"
2326+
)
2327+
hosts = Host.list(
2328+
self.apiclient,
2329+
clusterid=clusters[0].id)
2330+
self.assertEqual(
2331+
validateList(hosts)[0],
2332+
PASS,
2333+
"list hosts returned invalid response"
2334+
)
2335+
if len(hosts) < 2:
2336+
self.skipTest("Need min of two hosts to run this test")
2337+
try:
2338+
Host.update(
2339+
self.apiclient,
2340+
id=hosts[0].id,
2341+
hosttags=tag
2342+
)
2343+
except Exception as e:
2344+
self.fail("Updating host with tags failed with error : {}".format(e))
2345+
host_res = Host.list(
2346+
self.apiclient,
2347+
id=hosts[0].id
2348+
)
2349+
self.assertEqual(validateList(host_res)[0], PASS, "Invalid list host response")
2350+
self.assertEqual(
2351+
host_res[0].hosttags,
2352+
tag,
2353+
"host is updated with wrong tag"
2354+
)
2355+
self.so_with_tag = ServiceOffering.create(
2356+
self.apiclient,
2357+
self.services["service_offering"],
2358+
hosttags=tag
2359+
)
2360+
self.so_res = ServiceOffering.list(
2361+
self.apiclient,
2362+
id=self.so_with_tag.id
2363+
)
2364+
self.assertEqual(validateList(self.so_res)[0], PASS, "Invalid service offering response")
2365+
self.assertEqual(
2366+
self.so_res[0].hosttags,
2367+
tag,
2368+
"Service offering has not been created with host tags"
2369+
)
2370+
self.vm = VirtualMachine.create(
2371+
self.api_client,
2372+
self.services["virtual_machine"],
2373+
accountid=self.account.name,
2374+
domainid=self.account.domainid,
2375+
serviceofferingid=self.so_with_tag.id
2376+
)
2377+
self.cleanup.append(self.vm)
2378+
self.cleanup.append(self.so_with_tag)
2379+
self.assertEqual(
2380+
self.vm.hostid,
2381+
hosts[0].id,
2382+
"vm deployed on wrong host"
2383+
)
2384+
hosts_for_migration = Host.listForMigration(
2385+
self.apiclient,
2386+
virtualmachineid=self.vm.id
2387+
)
2388+
self.assertEqual(
2389+
validateList(hosts_for_migration)[0],
2390+
PASS,
2391+
"Untagged hosts are not returned as suitable hosts for vm migration\
2392+
if it is deployed on a tagged host"
2393+
)
2394+
host_ids_for_migration = [host.id for host in hosts_for_migration]
2395+
#Remove host on which vm was deployed (tagged host) from the hosts list
2396+
hosts.pop(0)
2397+
host_ids = [host.id for host in hosts]
2398+
for id in host_ids:
2399+
if not id in host_ids_for_migration:
2400+
self.fail("Not all hosts are available for vm migration")
2401+
return

0 commit comments

Comments
 (0)