[ 
https://issues.apache.org/jira/browse/CLOUDSTACK-9606?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16314761#comment-16314761
 ] 

ASF GitHub Bot commented on CLOUDSTACK-9606:
--------------------------------------------

rhtyd closed pull request #1775: CLOUDSTACK-9606: While IP address is released, 
tag are not deleted.
URL: https://github.com/apache/cloudstack/pull/1775
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/server/src/com/cloud/network/IpAddressManagerImpl.java 
b/server/src/com/cloud/network/IpAddressManagerImpl.java
old mode 100644
new mode 100755
index 7961d07fc6c..0cfd9bb4122
--- a/server/src/com/cloud/network/IpAddressManagerImpl.java
+++ b/server/src/com/cloud/network/IpAddressManagerImpl.java
@@ -173,6 +173,8 @@
 import com.cloud.vm.dao.NicSecondaryIpDao;
 import com.cloud.vm.dao.UserVmDao;
 import com.cloud.vm.dao.VMInstanceDao;
+import com.cloud.server.ResourceTag;
+import com.cloud.tags.dao.ResourceTagDao;
 
 public class IpAddressManagerImpl extends ManagerBase implements 
IpAddressManager, Configurable {
     private static final Logger s_logger = 
Logger.getLogger(IpAddressManagerImpl.class);
@@ -288,6 +290,8 @@
     DataCenterIpAddressDao _privateIPAddressDao;
     @Inject
     HostPodDao _hpDao;
+    @Inject
+    ResourceTagDao _resourceTagDao;
 
     SearchBuilder<IPAddressVO> AssignIpAddressSearch;
     SearchBuilder<IPAddressVO> AssignIpAddressFromPodVlanSearch;
@@ -595,6 +599,10 @@ protected boolean cleanupIpResources(long ipId, long 
userId, Account caller) {
             success = false;
         }
 
+        //Remove the tags corresponding to IP.
+        if(success) {
+            _resourceTagDao.removeByIdAndType(ipId, 
ResourceTag.ResourceObjectType.PublicIpAddress);
+        }
         return success;
     }
 
diff --git a/test/integration/component/test_tags.py 
b/test/integration/component/test_tags.py
index f9b0655016d..f9755b882aa 100644
--- a/test/integration/component/test_tags.py
+++ b/test/integration/component/test_tags.py
@@ -2543,3 +2543,163 @@ def test_24_public_IP_tag(self):
             "List tags should return empty response"
         )
         return
+
+    @attr(tags=["advanced"], required_hardware="false")
+    def test_25_CLOUDSTACK_9606(self):
+            """ Test for checking automatic tag removal on released Public IP
+            """
+
+            # 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. Release the respective public IP address without deleting 
tags.
+            # 4. Verify that tags does not exists on the released public IP.
+
+            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)
+            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
+            )
+            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"
+            )
+
+            # release public IP address""
+            ip_id = public_ip.ipaddress.id
+            public_ip.delete(self.apiclient)
+
+            retriesCount = 10
+            isIpAddressDisassociated = False
+
+            while retriesCount > 0:
+                listResponse = list_publicIP(
+                    self.apiclient,
+                    id=ip_id
+                )
+                if listResponse is None:
+                    isIpAddressDisassociated = True
+                    break
+                retriesCount -= 1
+                time.sleep(60)
+            # End while
+
+            self.assertTrue(
+                isIpAddressDisassociated,
+                "Failed to disassociate IP address")
+
+            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


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> While IP address is released, tag are not deleted
> -------------------------------------------------
>
>                 Key: CLOUDSTACK-9606
>                 URL: https://issues.apache.org/jira/browse/CLOUDSTACK-9606
>             Project: CloudStack
>          Issue Type: Bug
>      Security Level: Public(Anyone can view this level - this is the 
> default.) 
>            Reporter: Priyank Parihar
>            Assignee: Priyank Parihar
>
> IP address release API call (disassociateIpAddress) does not have any 
> mechanism to remove the tags.
> All though the IP address is not allocated, corresponding tag still exists.
> REPRO STEPS
> ==================
> 1. Acquire an IP address by Domain-Admin account A. 
> 2. Add tag to the target IP address by Domain-Admin account A. 
> 3. Release the target IP address without deleting the tag. 
> ⇒We found out that the state of the IP address is "Free" at this point, 
> but the tag which added by Domain-Admin account A still remains. 
> 4. Acquire the target IP address by Domain-Admin account B. 
> ⇒The tag still remains without change. 
> If account B tries to delete the tag, in our lab we can delete the tag as 
> domain admin. Although customer reported that they can't complete it because 
> of authority error.
> EXPECTED BEHAVIOR
> ==================
> When we release an IP address, the corresponding tags should be removed from 
> related tables
> ACTUAL BEHAVIOR
> ==================
> When we release an IP address, the corresponding tags are not removed from 
> related tables



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to