From 910b08f72bbe001ded808280fbc27223b9d0c0b6 Mon Sep 17 00:00:00 2001 From: dahn Date: Thu, 30 May 2019 07:55:52 +0200 Subject: [PATCH 1/3] server: fix duplicate tag exception as CloudRuntimeException (#3348) See #3339: a runtime exception is thrown but it should be converted to an error return. Wrapping it in a CloudRuntimeException should do the trick. Fixes #3339 --- .../cloud/tags/TaggedResourceManagerImpl.java | 7 +- test/integration/component/test_tags.py | 80 +++++++++++++++++++ 2 files changed, 86 insertions(+), 1 deletion(-) diff --git a/server/src/com/cloud/tags/TaggedResourceManagerImpl.java b/server/src/com/cloud/tags/TaggedResourceManagerImpl.java index 9803ce753a3..f871b6a01d9 100644 --- a/server/src/com/cloud/tags/TaggedResourceManagerImpl.java +++ b/server/src/com/cloud/tags/TaggedResourceManagerImpl.java @@ -85,6 +85,7 @@ import org.apache.commons.collections.MapUtils; import javax.inject.Inject; import javax.naming.ConfigurationException; +import javax.persistence.EntityExistsException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -310,7 +311,11 @@ public class TaggedResourceManagerImpl extends ManagerBase implements TaggedReso } ResourceTagVO resourceTag = new ResourceTagVO(key, value, accountDomainPair.first(), accountDomainPair.second(), id, resourceType, customer, resourceUuid); - resourceTag = _resourceTagDao.persist(resourceTag); + try { + resourceTag = _resourceTagDao.persist(resourceTag); + } catch (EntityExistsException e) { + throw new CloudRuntimeException(String.format("tag %s already on %s with id %s", resourceTag.getKey(), resourceType.toString(), resourceId),e); + } resourceTags.add(resourceTag); } } diff --git a/test/integration/component/test_tags.py b/test/integration/component/test_tags.py index ed1aee7a0ee..efe8a766a42 100644 --- a/test/integration/component/test_tags.py +++ b/test/integration/component/test_tags.py @@ -2974,3 +2974,83 @@ class TestResourceTags(cloudstackTestCase): self.fail("User1 has access to create tags for User2.") return + + @attr(tags=["advanced", "basic"], required_hardware="false") + def test_33_duplicate_vm_tag(self): + """ + Test creation of a duplicate tag on UserVM and verify error return. + cleanup by deleting + """ + # Validate the following + # 1. Create a tag on VM using createTags API + # 2. Create the same tag on VM using createTags API + # 3. check the return for the right error message + + tag_key = 'scope' + tag_value = 'test_33_duplicate_vm_tag' + + self.debug("Creating a tag for user VM") + # use vm_2 as vm_1 is deleted in other tests :( + tag = Tag.create( + self.apiclient, + resourceIds=self.vm_2.id, + resourceType='userVM', + tags={tag_key: tag_value} + ) + self.debug("Tag created: %s" % tag.__dict__) + + self.debug("Trying second tag witgh the same key for user VM") + try: + erronousTag = Tag.create( + self.apiclient, + resourceIds=self.vm_2.id, + resourceType='userVM', + tags={tag_key: tag_value} + ) + except Exception as e: + # verify e.message + assert "tag scope already on UserVm with id" in e.message, \ + "neat error message missing from error result" + pass + + + # we should still find the tag + vms = VirtualMachine.list( + self.apiclient, + listall=True, + key=tag_key, + value=tag_value + ) + + self.assertEqual( + isinstance(vms, list), + True, + "Tag based VMs listing failed") + + self.debug("Deleting the created tag..") + try: + Tag.delete( + self.apiclient, + resourceIds=self.vm_2.id, + resourceType='userVM', + tags={tag_key: tag_value} + ) + 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.apiclient, + listall=True, + resourceType='userVM', + account=self.account.name, + domainid=self.account.domainid, + key=tag_key, + value=tag_value + ) + self.assertEqual( + tags, + None, + "List tags should return empty response" + ) + return From 8e43d258f379cadf51f5b8c00edd63d29f19b076 Mon Sep 17 00:00:00 2001 From: ustcweizhou Date: Thu, 30 May 2019 08:03:03 +0200 Subject: [PATCH 2/3] server: Fail to restart VPC with cleanup if there are multiple public IPs in different subnet" (#3342) If there are multiple IPs in different subnet assigned to a VPC, after restarting VPC with cleanup, the VRs will be FAULT state. Step to reproduce: (1) create vpc, source nat IP is 10.11.118.X (2) assign two public IPs in other subnet to this VPC. 10.11.119.X and 10.11.119.Y (3) deploy two vms in the vpc, and enable static nat 10.11.119.X and 10.11.119.Y to these two vms (4) restart vpc with cleanup. There are more than 1 nic allocated for 10.11.119 to new VRs Logs as below: 2019-05-10 14:12:24,652 DEBUG [o.a.c.e.o.NetworkOrchestrator] (API-Job-Executor-36:ctx-839f6522 job-652 ctx-35fb4667) (logid:1ab7aa37) Allocating nic for vm VM[DomainRouter|r-85-VM] in network Ntwk[200|Public|1] with requested profile NicProfile[0-0-null-10.11.118.157-vlan://untagged 2019-05-10 14:12:24,676 DEBUG [o.a.c.e.o.NetworkOrchestrator] (API-Job-Executor-36:ctx-839f6522 job-652 ctx-35fb4667) (logid:1ab7aa37) Allocating nic for vm VM[DomainRouter|r-85-VM] in network Ntwk[200|Public|1] with requested profile NicProfile[0-0-null-10.11.119.110-vlan://119 2019-05-10 14:12:24,699 DEBUG [o.a.c.e.o.NetworkOrchestrator] (API-Job-Executor-36:ctx-839f6522 job-652 ctx-35fb4667) (logid:1ab7aa37) Allocating nic for vm VM[DomainRouter|r-85-VM] in network Ntwk[200|Public|1] with requested profile NicProfile[0-0-null-10.11.119.110-vlan://119 2019-05-10 14:12:24,723 DEBUG [o.a.c.e.o.NetworkOrchestrator] (API-Job-Executor-36:ctx-839f6522 job-652 ctx-35fb4667) (logid:1ab7aa37) Allocating nic for vm VM[DomainRouter|r-85-VM] in network Ntwk[200|Public|1] with requested profile NicProfile[0-0-null-10.11.119.110-vlan://119 This is a regression issue caused by commit 1d382e0 --- .../network/router/VpcNetworkHelperImpl.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/server/src/com/cloud/network/router/VpcNetworkHelperImpl.java b/server/src/com/cloud/network/router/VpcNetworkHelperImpl.java index b4cf809726d..4e49bd0e0a3 100644 --- a/server/src/com/cloud/network/router/VpcNetworkHelperImpl.java +++ b/server/src/com/cloud/network/router/VpcNetworkHelperImpl.java @@ -154,14 +154,15 @@ public class VpcNetworkHelperImpl extends NetworkHelperImpl { publicVlans.add(publicIp.getVlanTag()); } } - if (publicNetwork != null) { - if (networks.get(publicNetwork) != null) { - @SuppressWarnings("unchecked") final List publicNicProfiles = (List)networks.get(publicNetwork); - publicNicProfiles.addAll(publicNics); - networks.put(publicNetwork, publicNicProfiles); - } else { - networks.put(publicNetwork, publicNics); - } + } + if (publicNetwork != null) { + if (networks.get(publicNetwork) != null) { + @SuppressWarnings("unchecked") + final List publicNicProfiles = (List)networks.get(publicNetwork); + publicNicProfiles.addAll(publicNics); + networks.put(publicNetwork, publicNicProfiles); + } else { + networks.put(publicNetwork, publicNics); } } @@ -187,4 +188,4 @@ public class VpcNetworkHelperImpl extends NetworkHelperImpl { return networks; } -} \ No newline at end of file +} From f1efcc1af6d6d466904780cc42af3dc5ded138fb Mon Sep 17 00:00:00 2001 From: smlshn Date: Thu, 30 May 2019 09:08:14 +0300 Subject: [PATCH 3/3] ui: reset multiselect actions when refreshing listView in Instance page (#3359) Enables the toolbar to reset to its initial state after any multiSelectAction completed. Fixes #3337 --- ui/scripts/ui/widgets/listView.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ui/scripts/ui/widgets/listView.js b/ui/scripts/ui/widgets/listView.js index 688b77df6b0..74c536e652e 100644 --- a/ui/scripts/ui/widgets/listView.js +++ b/ui/scripts/ui/widgets/listView.js @@ -2494,6 +2494,8 @@ this.data('view-args').sections[activeSection].listView : this.data('view-args').listView; + toggleMultiSelectActions(this, false); + loadBody( this.find('table:last'), listViewArgs.dataProvider,