1+ import fauxfactory
12import pytest
23from widgetastic .utils import partial_match
4+ from wrapanapi .exceptions import ImageNotFoundError
35
46from cfme import test_requirements
57from cfme .cloud .provider .azure import AzureProvider
8+ from cfme .cloud .provider .ec2 import EC2Provider
69from 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
811from cfme .utils .appliance .implementations .ui import navigate_to
12+ from cfme .utils .log import logger
913from cfme .utils .wait import wait_for
1014
1115pytestmark = [
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
0 commit comments