Skip to content

Commit c072dda

Browse files
committed
Merge remote-tracking branch 'origin/4.12'
2 parents 501aa7c + 31e677f commit c072dda

4 files changed

Lines changed: 98 additions & 10 deletions

File tree

server/src/main/java/com/cloud/network/router/VpcNetworkHelperImpl.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,15 @@ public void reallocateRouterNetworks(final RouterDeploymentDefinition vpcRouterD
154154
publicVlans.add(publicIp.getVlanTag());
155155
}
156156
}
157-
if (publicNetwork != null) {
158-
if (networks.get(publicNetwork) != null) {
159-
@SuppressWarnings("unchecked") final List<NicProfile> publicNicProfiles = (List<NicProfile>)networks.get(publicNetwork);
160-
publicNicProfiles.addAll(publicNics);
161-
networks.put(publicNetwork, publicNicProfiles);
162-
} else {
163-
networks.put(publicNetwork, publicNics);
164-
}
157+
}
158+
if (publicNetwork != null) {
159+
if (networks.get(publicNetwork) != null) {
160+
@SuppressWarnings("unchecked")
161+
final List<NicProfile> publicNicProfiles = (List<NicProfile>)networks.get(publicNetwork);
162+
publicNicProfiles.addAll(publicNics);
163+
networks.put(publicNetwork, publicNicProfiles);
164+
} else {
165+
networks.put(publicNetwork, publicNics);
165166
}
166167
}
167168

@@ -187,4 +188,4 @@ public LinkedHashMap<Network, List<? extends NicProfile>> configureDefaultNics(f
187188

188189
return networks;
189190
}
190-
}
191+
}

server/src/main/java/com/cloud/tags/TaggedResourceManagerImpl.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585

8686
import javax.inject.Inject;
8787
import javax.naming.ConfigurationException;
88+
import javax.persistence.EntityExistsException;
8889
import java.util.ArrayList;
8990
import java.util.HashMap;
9091
import java.util.List;
@@ -314,7 +315,11 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
314315
}
315316

316317
ResourceTagVO resourceTag = new ResourceTagVO(key, value, accountDomainPair.first(), accountDomainPair.second(), id, resourceType, customer, resourceUuid);
317-
resourceTag = _resourceTagDao.persist(resourceTag);
318+
try {
319+
resourceTag = _resourceTagDao.persist(resourceTag);
320+
} catch (EntityExistsException e) {
321+
throw new CloudRuntimeException(String.format("tag %s already on %s with id %s", resourceTag.getKey(), resourceType.toString(), resourceId),e);
322+
}
318323
resourceTags.add(resourceTag);
319324
}
320325
}

test/integration/component/test_tags.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2989,3 +2989,83 @@ def test_32_user_a_doesnt_have_access_to_user_b_tags(self):
29892989
self.fail("User1 has access to create tags for User2.")
29902990

29912991
return
2992+
2993+
@attr(tags=["advanced", "basic"], required_hardware="false")
2994+
def test_33_duplicate_vm_tag(self):
2995+
"""
2996+
Test creation of a duplicate tag on UserVM and verify error return.
2997+
cleanup by deleting
2998+
"""
2999+
# Validate the following
3000+
# 1. Create a tag on VM using createTags API
3001+
# 2. Create the same tag on VM using createTags API
3002+
# 3. check the return for the right error message
3003+
3004+
tag_key = 'scope'
3005+
tag_value = 'test_33_duplicate_vm_tag'
3006+
3007+
self.debug("Creating a tag for user VM")
3008+
# use vm_2 as vm_1 is deleted in other tests :(
3009+
tag = Tag.create(
3010+
self.apiclient,
3011+
resourceIds=self.vm_2.id,
3012+
resourceType='userVM',
3013+
tags={tag_key: tag_value}
3014+
)
3015+
self.debug("Tag created: %s" % tag.__dict__)
3016+
3017+
self.debug("Trying second tag witgh the same key for user VM")
3018+
try:
3019+
erronousTag = Tag.create(
3020+
self.apiclient,
3021+
resourceIds=self.vm_2.id,
3022+
resourceType='userVM',
3023+
tags={tag_key: tag_value}
3024+
)
3025+
except Exception as e:
3026+
# verify e.message
3027+
assert "tag scope already on UserVm with id" in e.message, \
3028+
"neat error message missing from error result"
3029+
pass
3030+
3031+
3032+
# we should still find the tag
3033+
vms = VirtualMachine.list(
3034+
self.apiclient,
3035+
listall=True,
3036+
key=tag_key,
3037+
value=tag_value
3038+
)
3039+
3040+
self.assertEqual(
3041+
isinstance(vms, list),
3042+
True,
3043+
"Tag based VMs listing failed")
3044+
3045+
self.debug("Deleting the created tag..")
3046+
try:
3047+
Tag.delete(
3048+
self.apiclient,
3049+
resourceIds=self.vm_2.id,
3050+
resourceType='userVM',
3051+
tags={tag_key: tag_value}
3052+
)
3053+
except Exception as e:
3054+
self.fail("Failed to delete the tag - %s" % e)
3055+
3056+
self.debug("Verifying if tag is actually deleted!")
3057+
tags = Tag.list(
3058+
self.apiclient,
3059+
listall=True,
3060+
resourceType='userVM',
3061+
account=self.account.name,
3062+
domainid=self.account.domainid,
3063+
key=tag_key,
3064+
value=tag_value
3065+
)
3066+
self.assertEqual(
3067+
tags,
3068+
None,
3069+
"List tags should return empty response"
3070+
)
3071+
return

ui/scripts/ui/widgets/listView.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2497,6 +2497,8 @@
24972497
this.data('view-args').sections[activeSection].listView :
24982498
this.data('view-args').listView;
24992499

2500+
toggleMultiSelectActions(this, false);
2501+
25002502
loadBody(
25012503
this.find('table:last'),
25022504
listViewArgs.dataProvider,

0 commit comments

Comments
 (0)