From 41ce802c939ebdb63eb61a7a3cc06ba6606ac60b Mon Sep 17 00:00:00 2001 From: sanjeevn Date: Wed, 25 Nov 2015 17:30:07 +0530 Subject: [PATCH] Add marvin test for bug CS-38356 Bug-Id: CS-38356 Reviewed-By: Self --- test/integration/component/test_tags.py | 146 +++++++++++++++++++++++- 1 file changed, 144 insertions(+), 2 deletions(-) diff --git a/test/integration/component/test_tags.py b/test/integration/component/test_tags.py index 3552064d180..cf19cd0c35d 100644 --- a/test/integration/component/test_tags.py +++ b/test/integration/component/test_tags.py @@ -36,12 +36,14 @@ from marvin.lib.base import (Tag, Template, Snapshot, ServiceOffering, - Project) + Project, + Domain) from marvin.lib.common import (get_zone, get_domain, get_template, find_storage_pool_type, - list_clusters) + list_clusters, + createEnabledNetworkOffering) from marvin.codes import FAILED, PASS import time @@ -2401,3 +2403,143 @@ class TestResourceTags(cloudstackTestCase): if not id in host_ids_for_migration: self.fail("Not all hosts are available for vm migration") return + + @attr(tags=["advanced"], required_hardware="false") + def test_24_public_IP_tag(self): + """ Testcreation, adding and removing tag on public IP address + """ + # Validate the following + # 1. Create a domain and admin account under the new domain + # 2. Create a tag on acquired public IP address using createTags API + # 3. Delete above created tag using deleteTags API + # 4. Perform steps 3&4 using domain-admin + + self.debug("Creating a sub-domain under: %s" % self.domain.name) + self.child_domain = Domain.create( + self.apiclient, + services=self.services["domain"], + parentdomainid=self.domain.id + ) + self.child_do_admin = Account.create( + self.apiclient, + self.services["account"], + admin=True, + domainid=self.child_domain.id + ) + # Cleanup the resources created at end of test + self.cleanup.append(self.child_do_admin) + self.cleanup.append(self.child_domain) + self.dom_admin_api_client = self.testClient.getUserApiClient( + UserName=self.child_do_admin.name, + DomainName=self.child_do_admin.domain + ) + result = createEnabledNetworkOffering( + self.apiclient, + self.services["network_offering"] + ) + assert result[0] == PASS, \ + "Network offering create/enable failed with error %s" % result[2] + self.network_offering = result[1] + self.network = Network.create( + self.dom_admin_api_client, + self.services["network"], + networkofferingid=self.network_offering.id, + accountid=self.child_do_admin.name, + domainid=self.child_do_admin.domainid, + zoneid=self.zone.id + ) + self.debug("Fetching the network details for account: %s" % + self.child_do_admin.name + ) + networks = Network.list( + self.dom_admin_api_client, + account=self.child_do_admin.name, + domainid=self.child_do_admin.domainid, + listall=True + ) + self.assertEqual( + isinstance(networks, list), + True, + "List networks should not return an empty response" + ) + network = networks[0] + self.debug("Network for the account: %s is %s" % + (self.child_do_admin.name, network.name) + ) + self.debug("Associating public IP for network: %s" % network.id) + public_ip = PublicIPAddress.create( + self.dom_admin_api_client, + accountid=self.child_do_admin.name, + zoneid=self.zone.id, + domainid=self.child_do_admin.domainid, + networkid=network.id + ) + self.debug("Creating a tag for Public IP") + tag = Tag.create( + self.dom_admin_api_client, + resourceIds=public_ip.ipaddress.id, + resourceType='PublicIpAddress', + tags={'region': 'India'} + ) + self.debug("Tag created: %s" % tag.__dict__) + + tags = Tag.list( + self.dom_admin_api_client, + listall=True, + resourceType='PublicIpAddress', + account=self.child_do_admin.name, + domainid=self.child_do_admin.domainid, + key='region', + value='India' + ) + self.assertEqual( + isinstance(tags, list), + True, + "List tags should not return empty response" + ) + self.assertEqual( + tags[0].value, + 'India', + 'The tag should have original value' + ) + publicIps = PublicIPAddress.list( + self.dom_admin_api_client, + account=self.child_do_admin.name, + domainid=self.child_do_admin.domainid, + listall=True, + key='region', + value='India' + ) + self.assertEqual( + isinstance(publicIps, list), + True, + "List Public IPs should not return an empty response" + ) + + self.debug("Deleting the created tag..") + try: + tag.delete( + self.dom_admin_api_client, + resourceIds=public_ip.ipaddress.id, + resourceType='PublicIpAddress', + tags={'region': 'India'} + ) + except Exception as e: + self.fail("Failed to delete the tag - %s" % e) + + self.debug("Verifying if tag is actually deleted!") + tags = Tag.list( + self.dom_admin_api_client, + listall=True, + resourceType='PublicIpAddress', + account=self.child_do_admin.name, + domainid=self.child_do_admin.domainid, + key='region', + value='India' + ) + self.assertEqual( + tags, + None, + "List tags should return empty response" + ) + return