Skip to content
This repository was archived by the owner on Apr 7, 2022. It is now read-only.

Commit 5072ffe

Browse files
authored
Merge pull request #8543 from mshriver/rlbabyuk-test-map-tagging
[1LP][RFR] Tests tagging on provider side
2 parents b310219 + 676e900 commit 5072ffe

5 files changed

Lines changed: 191 additions & 31 deletions

File tree

cfme/common/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ def get_tags(self, tenant="My Company Tags"):
435435
ItemNotFound: when nav destination DNE, or times out on wait (is_displayed was false)
436436
"""
437437
try:
438-
view = navigate_to(self, 'Details')
438+
view = navigate_to(self, 'Details', force=True)
439439
except (NavigationDestinationNotFound, DestinationNotFound):
440440
raise ItemNotFound('Details page does not exist for: {}'.format(self))
441441
except TimedOutError:

cfme/configure/configuration/region_settings.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,6 @@ class MapTag(BaseEntity, Pretty, Updateable):
388388
entity_type: Name of the tag
389389
label: Tag display name
390390
category: Tags Category
391-
392391
"""
393392
pretty_attrs = ['entity_type', 'label', 'category']
394393

@@ -402,7 +401,7 @@ def update(self, updates, cancel=False):
402401
Args:
403402
updates: tag map data that should be changed
404403
cancel: True - if you want to cancel map edition,
405-
by defaul map will be updated
404+
by default map will be updated
406405
"""
407406
view = navigate_to(self, 'Edit')
408407
# only category can be updated, as other fields disabled by default
@@ -427,7 +426,7 @@ def delete(self, cancel=False):
427426
'True' - map will not be deleted
428427
"""
429428
view = navigate_to(self.parent, 'All')
430-
row = view.table.row(tag_category=self.category)
429+
row = view.table.row(tag_category=self.category, resource_label=self.label)
431430
row.actions.click()
432431
view.browser.handle_alert(cancel=cancel)
433432

cfme/tests/cloud/test_tag_mapping.py

Lines changed: 144 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1+
import fauxfactory
12
import pytest
23
from widgetastic.utils import partial_match
4+
from wrapanapi.exceptions import ImageNotFoundError
35

46
from cfme import test_requirements
57
from cfme.cloud.provider.azure import AzureProvider
8+
from cfme.cloud.provider.ec2 import EC2Provider
69
from cfme.exceptions import ItemNotFound
7-
from cfme.markers.env_markers.provider import ONE_PER_CATEGORY
10+
from cfme.markers.env_markers.provider import ONE_PER_TYPE
811
from cfme.utils.appliance.implementations.ui import navigate_to
12+
from cfme.utils.log import logger
913
from cfme.utils.wait import wait_for
1014

1115
pytestmark = [
12-
pytest.mark.provider([AzureProvider], selector=ONE_PER_CATEGORY, scope='function'),
13-
pytest.mark.usefixtures('setup_provider')
16+
pytest.mark.provider([EC2Provider], scope='function'),
17+
pytest.mark.usefixtures('setup_provider', 'refresh_provider')
1418
]
1519

1620

@@ -24,7 +28,7 @@ def map_tags(appliance, provider, request):
2428

2529

2630
@pytest.fixture(scope='function')
27-
def vm(appliance, provider):
31+
def tagged_vm(provider):
2832
# cu-24x7 vm is tagged with test:testing in provider
2933
tag_vm = provider.data.cap_and_util.capandu_vm
3034
collection = provider.appliance.provider_based_collection(provider)
@@ -41,8 +45,35 @@ def refresh_provider(provider):
4145
return True
4246

4347

48+
@pytest.fixture(params=['instances', 'images'])
49+
def tag_mapping_items(request, appliance, provider):
50+
entity_type = request.param
51+
collection = getattr(appliance.collections, 'cloud_{}'.format(entity_type))
52+
collection.filters = {'provider': provider}
53+
view = navigate_to(collection, 'AllForProvider')
54+
name = view.entities.get_first_entity().name
55+
try:
56+
mgmt_item = (
57+
provider.mgmt.get_template(name)
58+
if entity_type == 'images'
59+
else provider.mgmt.get_vm(name)
60+
)
61+
except ImageNotFoundError:
62+
msg = 'Failed looking up template [{}] from CFME on provider: {}'.format(name, provider)
63+
logger.exception(msg)
64+
pytest.skip(msg)
65+
return collection.instantiate(name=name, provider=provider), mgmt_item, entity_type
66+
67+
68+
def tag_components():
69+
# Return tuple with random tag_label and tag_value
70+
return ('tag_label_{}'.format(fauxfactory.gen_alphanumeric()),
71+
'tag_value_{}'.format(fauxfactory.gen_alphanumeric()))
72+
73+
4474
@test_requirements.tag
45-
def test_tag_mapping_azure_instances(vm, map_tags, refresh_provider):
75+
@pytest.mark.provider([AzureProvider], selector=ONE_PER_TYPE, scope='function', override=True)
76+
def test_tag_mapping_azure_instances(tagged_vm, map_tags):
4677
""""
4778
Polarion:
4879
assignee: anikifor
@@ -60,7 +91,7 @@ def test_tag_mapping_azure_instances(vm, map_tags, refresh_provider):
6091
3.
6192
4. Field value is "My Company Tags Testing: testing"
6293
"""
63-
view = navigate_to(vm, 'Details')
94+
view = navigate_to(tagged_vm, 'Details')
6495

6596
def my_company_tags():
6697
return view.tag.get_text_of('My Company Tags') != 'No My Company Tags have been assigned'
@@ -73,32 +104,120 @@ def my_company_tags():
73104
assert view.tag.get_text_of('My Company Tags')[0] == 'Testing: testing'
74105

75106

76-
@pytest.mark.manual
77-
@pytest.mark.tier(2)
78-
def test_ec2_tags_mapping():
107+
@test_requirements.tag
108+
# TODO: Azure needs tagging support in wrapanapi
109+
def test_labels_update(provider, tag_mapping_items, soft_assert):
110+
"""" Test updates of tag labels on entity details
111+
112+
Polarion:
113+
assignee: anikifor
114+
casecomponent: Cloud
115+
caseimportance: high
116+
initialEstimate: 1/12h
117+
testSteps:
118+
1. Set a tag through provider mgmt interface
119+
2. Refresh Provider
120+
3. Go to entity details and get labels
121+
4. unset tag through provider mgmt interface
122+
5. Go to entity details and get labels
123+
expectedResults:
124+
1.
125+
2.
126+
3. labels includes label + tag
127+
4.
128+
5. labels should not include tag label
79129
"""
80-
Requirement: Have an ec2 provider
130+
entity, mgmt_entity, entity_type = tag_mapping_items
131+
tag_label, tag_value = tag_components()
132+
mgmt_entity.set_tag(tag_label, tag_value)
133+
provider.refresh_provider_relationships(method='ui')
134+
view = navigate_to(entity, 'Details')
135+
# get_tags() doesn't work here as we're looking at labels, not smart management
136+
current_tag_value = view.entities.summary('Labels').get_text_of(tag_label)
137+
soft_assert(
138+
current_tag_value == tag_value, (
139+
'Tag values is not that expected, actual - {}, expected - {}'.format(
140+
current_tag_value, tag_value
141+
)
142+
)
143+
)
144+
mgmt_entity.unset_tag(tag_label, tag_value)
145+
provider.refresh_provider_relationships(method='ui')
146+
view = navigate_to(entity, 'Details', force=True)
147+
fields = view.entities.summary('Labels').fields
148+
soft_assert(
149+
tag_label not in fields,
150+
'{} label was not removed from details page'.format(tag_label)
151+
)
152+
81153

154+
@test_requirements.tag
155+
# TODO: Azure needs tagging support in wrapanapi
156+
def test_mapping_tags(
157+
appliance, provider, tag_mapping_items, soft_assert, category, request
158+
):
159+
"""Test mapping tags on provider instances and images
82160
Polarion:
83161
assignee: anikifor
84162
casecomponent: Cloud
85-
caseimportance: medium
86-
initialEstimate: 1/5h
87-
startsin: 5.8
163+
caseimportance: high
164+
initialEstimate: 1/12h
88165
testSteps:
89-
1. Create an instance and tag it with test:testing
90-
2. Go to Configuration -> CFME Region -> Map Tags
91-
3. Add a tag:
92-
Entity: Instance (Amazon)
93-
Label: test
94-
Category: Testing
95-
4. Refresh provider
96-
5. Go to summary of that instance
97-
6. In Smart Management field should be:
98-
My Company Tags testing: Testing
99-
7. Delete that instance
166+
1. Set a tag through provider mgmt interface
167+
2. create a CFME tag map for entity type
168+
3. Go to entity details and get smart management table
169+
4. Delete the tag map
170+
5. Go to entity details and get smart management table
171+
expectedResults:
172+
1.
173+
2.
174+
3. smart management should include category name and tag
175+
4.
176+
5. smart management table should NOT include category name and tag
100177
"""
101-
pass
178+
entity, mgmt_entity, entity_type = tag_mapping_items
179+
tag_label, tag_value = tag_components()
180+
mgmt_entity.set_tag(tag_label, tag_value)
181+
request.addfinalizer(
182+
lambda: mgmt_entity.unset_tag(tag_label, tag_value)
183+
)
184+
185+
provider_type = provider.discover_name.split(' ')[0]
186+
# Check the add form to find the correct resource entity type selection string
187+
view = navigate_to(appliance.collections.map_tags, 'Add')
188+
select_text = None # init this since we set it within if, and reference it in for/else:
189+
options = [] # track the option strings for logging in failure
190+
for option in view.resource_entity.all_options:
191+
option_text = option.text # read it once since its used multiple times
192+
options.append(option_text)
193+
if provider_type in option_text and entity_type.capitalize()[:-1] in option_text:
194+
select_text = option_text
195+
break
196+
else:
197+
# no match / break for select_text
198+
if select_text is None:
199+
pytest.fail(
200+
'Failed to match the entity type [{e}] and provider type [{p}] in options: [{o}]'
201+
.format(e=entity_type, p=provider_type, o=options)
202+
)
203+
view.cancel_button.click() # close the open form
204+
205+
map_tag = appliance.collections.map_tags.create(
206+
entity_type=select_text,
207+
label=tag_label,
208+
category=category.name
209+
)
210+
211+
# check the tag shows up
212+
provider.refresh_provider_relationships(method='ui')
213+
soft_assert('{}: {}'.format(category.name, tag_value) in entity.get_tags())
214+
215+
# delete it
216+
map_tag.delete()
217+
218+
# check the tag goes away
219+
provider.refresh_provider_relationships(method='ui')
220+
soft_assert(not '{}: {}'.format(category.name, tag_value) in entity.get_tags())
102221

103222

104223
@pytest.mark.manual

cfme/tests/configure/test_tag.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
from cfme.rest.gen_data import tags as _tags
1212
from cfme.rest.gen_data import tenants as _tenants
1313
from cfme.rest.gen_data import vm as _vm
14-
from cfme.utils.blockers import BZ
14+
from cfme.utils.appliance.implementations.ui import navigator
15+
from cfme.utils.log import logger
1516
from cfme.utils.rest import assert_response
1617
from cfme.utils.rest import delete_resources_from_collection
1718
from cfme.utils.rest import delete_resources_from_detail
@@ -43,6 +44,7 @@
4344
pytest.mark.usefixtures('setup_provider')
4445
]
4546

47+
4648
@pytest.fixture
4749
def category(appliance):
4850
cg = appliance.collections.categories.create(
@@ -62,6 +64,7 @@ def test_tag_crud(category):
6264
Polarion:
6365
assignee: anikifor
6466
initialEstimate: 1/8h
67+
casecomponent: Tagging
6568
"""
6669
tag = category.collections.tags.create(
6770
name=fauxfactory.gen_alphanumeric(8).lower(),
@@ -72,6 +75,38 @@ def test_tag_crud(category):
7275
tag.delete()
7376

7477

78+
def test_map_tagging_crud(appliance, category, soft_assert):
79+
"""Test map tag crud with flash message assertion
80+
Polarion:
81+
assignee: anikifor
82+
initialEstimate: 1/4h
83+
casecomponent: Tagging
84+
"""
85+
label = fauxfactory.gen_alphanumeric(8)
86+
map_tags_collection = appliance.collections.map_tags
87+
map_tag_entity = map_tags_collection.create('Container Project', label, category.name)
88+
89+
view = appliance.browser.create_view(navigator.get_class(map_tags_collection, 'All').VIEW)
90+
view.flash.assert_success_message('Container Label Tag Mapping "{}" was added'
91+
.format(label)) # use label var to validate create method
92+
93+
with update(map_tag_entity):
94+
map_tag_entity.category = fauxfactory.gen_alphanumeric(8)
95+
96+
view = appliance.browser.create_view(navigator.get_class(map_tags_collection, 'All').VIEW)
97+
view.flash.assert_success_message(
98+
'Container Label Tag Mapping "{}" was saved'
99+
.format(map_tag_entity.label) # use entity label since it may get updated
100+
)
101+
row = next(view.table.rows(resource_label=map_tag_entity.label))
102+
soft_assert(row.tag_category.text == map_tag_entity.category)
103+
104+
map_tag_entity.delete()
105+
view = appliance.browser.create_view(navigator.get_class(map_tags_collection, 'All').VIEW)
106+
view.flash.assert_success_message('Container Label Tag Mapping "{}": Delete successful'
107+
.format(map_tag_entity.label))
108+
109+
75110
class TestTagsViaREST(object):
76111

77112
COLLECTIONS_BULK_TAGS = ("services", "vms")
@@ -284,7 +319,13 @@ def test_assign_and_unassign_tag(self, appliance, tags_mod, provider, services_m
284319
pytest.skip("No available entity in {} to assign tag".format(collection_name))
285320
entity = collection[-1]
286321
tag = tags_mod[0]
287-
entity.tags.action.assign(tag)
322+
try:
323+
entity.tags.action.assign(tag)
324+
except AttributeError:
325+
msg = ('Missing tag attribute in parametrized REST collection {} for entity: {}'
326+
.format(collection_name, entity))
327+
logger.exception(msg)
328+
pytest.fail(msg)
288329
assert_response(appliance)
289330
entity.reload()
290331
assert tag.id in [t.id for t in entity.tags.all]

conf/polarion_tools.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,6 @@ docstrings:
113113
- Services
114114
- SmartState
115115
- Stack
116+
- Tagging
116117
- V2V
117118
- WebUI

0 commit comments

Comments
 (0)