This repository has been archived by the owner on Apr 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 164
/
ssui.py
328 lines (250 loc) · 10.4 KB
/
ssui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# TO DO - remove sleep when BZ 1496233 is fixed
import time
from navmazing import NavigateToAttribute, NavigateToSibling
from widgetastic.widget import Text, Select
from widgetastic_patternfly import Input, Button
from cfme.base.ssui import SSUIBaseLoggedInPage
from cfme.common.vm import VM
from cfme.utils.appliance import MiqImplementationContext
from cfme.utils.appliance.implementations.ssui import (
navigator, SSUINavigateStep, navigate_to, ViaSSUI
)
from cfme.utils.wait import wait_for
from widgetastic_manageiq import (SSUIlist, SSUIDropdown, Notification, SSUIAppendToBodyDropdown)
from . import MyService
class MyServicesView(SSUIBaseLoggedInPage):
title = Text(locator='//li[@class="active"]')
service = SSUIlist()
notification = Notification()
@property
def in_myservices(self):
return (
self.logged_in_as_current_user and
self.navigation.currently_selected == ["", "My Services"])
@property
def is_displayed(self):
return self.in_myservices and self.title.text == "My Services"
class DetailsMyServiceView(MyServicesView):
title = Text(locator='//li[@class="active"]')
@property
def is_displayed(self):
return (self.in_myservices and
self.title.text in {self.context['object'].name, 'Service Details'})
notification = Notification()
policy = SSUIDropdown('Policy')
power_operations = SSUIDropdown('Power Operations')
access_dropdown = SSUIAppendToBodyDropdown('Access')
remove_service = Button("Remove Service")
configuration = SSUIDropdown('Configuration')
lifecycle = SSUIDropdown('Lifecycle')
console_button = Button(tooltip="HTML5 console", classes=['open-console-button'])
class ServiceEditForm(MyServicesView):
title = Text(locator='//li[@class="active"]')
name = Input(name='name')
description = Input(name='description')
class SetOwnershipForm(MyServicesView):
select_owner = Select(
locator='.//select[../../../label[normalize-space(text())="Select an Owner"]]')
select_group = Select(
locator='.//select[../../../label[normalize-space(text())="Select a Group"]]')
class EditMyServiceView(ServiceEditForm):
title = Text(locator='//h4[@id="myModalLabel"]')
save_button = Button('Save')
reset_button = Button('Reset')
cancel_button = Button('Cancel')
@property
def is_displayed(self):
return (
self.name.is_displayed and
self.title.text == "Edit Service"
)
class SetOwnershipView(SetOwnershipForm):
title = Text(locator='//*[@id="myModalLabel"]')
save_button = Button('Save')
@property
def is_displayed(self):
return (
self.select_owner.is_displayed and
self.title.text == 'Set Service Ownership')
class TagForm(MyServicesView):
tag_category = Select(locator='.//select[contains(@class, "tag-category-select")]')
tag_name = Select(locator='.//select[contains(@class, "tag-value-select")]')
add_tag = Text(locator='.//a/span[contains(@class, "tag-add")]')
save = Button('Save')
reset = Button('Reset')
cancel = Button('Cancel')
class TagPageView(TagForm):
title = Text(locator='//h4[@id="myModalLabel"]')
@property
def is_displayed(self):
return (
self.title.text == 'Edit Tags' and
self.tag_category.is_displayed and
self.tag_name.is_displayed)
class RemoveServiceView(MyServicesView):
title = Text(locator='//h4[@id="myModalLabel"]')
remove = Button('Yes, Remove Service')
cancel = Button('Cancel')
@property
def is_displayed(self):
return (
self.remove.is_displayed and
self.title.text == 'Remove Service')
class RetireServiceView(MyServicesView):
title = Text(locator='//h4[@id="myModalLabel"]')
retire = Button('Yes, Retire Service Now')
cancel = Button('Cancel')
@property
def is_displayed(self):
return (
self.retire.is_displayed and
self.title.text == 'Retire Service Now')
@MiqImplementationContext.external_for(MyService.update, ViaSSUI)
def update(self, updates):
view = navigate_to(self, 'Edit', wait_for_view=True)
view.fill_with(updates, on_change=view.save_button, no_change=view.cancel_button)
view.flash.assert_no_error()
view = self.create_view(DetailsMyServiceView, override=updates)
# TODO - remove sleep when BZ 1518954 is fixed
time.sleep(10)
assert view.notification.assert_message(
"{} was edited.".format(self.name))
@MiqImplementationContext.external_for(MyService.set_ownership, ViaSSUI)
def set_ownership(self, owner, group):
view = navigate_to(self, 'SetOwnership', wait_for_view=True)
view.fill({'select_owner': owner,
'select_group': group})
view.save_button.click()
view = self.create_view(DetailsMyServiceView)
assert view.is_displayed
# TODO - remove sleep when BZ 1518954 is fixed
time.sleep(10)
if self.appliance.version >= "5.8":
assert view.notification.assert_message("Setting ownership.")
else:
assert view.notification.assert_message("{} ownership was saved."
.format(self.name))
@MiqImplementationContext.external_for(MyService.edit_tags, ViaSSUI)
def edit_tags(self, tag, value):
view = navigate_to(self, 'EditTagsFromDetails', wait_for_view=True)
view.fill({'tag_category': tag,
'tag_name': value})
view.add_tag.click()
view.save.click()
view = self.create_view(DetailsMyServiceView)
assert view.is_displayed
# TODO - remove sleep when BZ 1518954 is fixed
time.sleep(10)
assert view.notification.assert_message("Tagging successful.")
@MiqImplementationContext.external_for(MyService.delete, ViaSSUI)
def delete(self):
view = navigate_to(self, 'Details')
if self.appliance.version >= "5.8":
view.configuration.item_select('Remove')
else:
view.remove_service.click()
view = self.create_view(RemoveServiceView)
view.remove.click()
view = self.create_view(MyServicesView)
wait_for(
lambda: view.is_displayed, delay=15, num_sec=300,
message="waiting for view to be displayed"
)
assert view.is_displayed
# TODO - remove sleep when BZ 1518954 is fixed
time.sleep(10)
assert view.notification.assert_message("{} was removed.".format(self.name))
@MiqImplementationContext.external_for(MyService.launch_vm_console, ViaSSUI)
def launch_vm_console(self, catalog_item):
navigate_to(self, 'VM Console')
# TODO need to remove 0001 from the line below and find correct place/way to put it in code
vm_obj = VM.factory(catalog_item.prov_data['catalog']['vm_name'] + '0001',
catalog_item.provider, template_name=catalog_item.catalog_name)
wait_for(
func=lambda: vm_obj.vm_console, num_sec=30, delay=2, handle_exception=True,
message="waiting for VM Console window to open"
)
return vm_obj
@MiqImplementationContext.external_for(MyService.retire, ViaSSUI)
def retire(self):
view = navigate_to(self, 'Retire', wait_for_view=True)
view.retire.click()
view = self.create_view(MyServicesView)
assert wait_for(
lambda: view.is_displayed, delay=3, num_sec=300,
message="waiting for view to be displayed"
)
# TODO - remove sleep when BZ 1518954 is fixed
time.sleep(10)
assert view.notification.assert_message("{} was retired.".format(self.name))
@MiqImplementationContext.external_for(MyService.service_power, ViaSSUI)
def service_power(self, power=None):
view = navigate_to(self, 'Details', wait_for_view=True)
view.power_operations.item_select(power)
view = self.create_view(DetailsMyServiceView)
wait_for(
lambda: view.is_displayed, delay=3, num_sec=300,
message="waiting for view to be displayed"
)
# TODO - remove sleep when BZ 1518954 is fixed
time.sleep(10)
# TODO - assert vm state through rest api
@navigator.register(MyService, 'All')
class MyServiceAll(SSUINavigateStep):
VIEW = MyServicesView
prerequisite = NavigateToAttribute('appliance.server', 'LoggedIn')
def step(self, *args, **kwargs):
self.prerequisite_view.navigation.select('My Services')
@navigator.register(MyService, 'Details')
class Details(SSUINavigateStep):
VIEW = DetailsMyServiceView
prerequisite = NavigateToSibling('All')
def step(self, *args, **kwargs):
wait_for(
lambda: self.prerequisite_view.service.is_displayed(self.obj.name),
delay=5, num_sec=300,
message="waiting for view to be displayed"
)
self.prerequisite_view.service.click_at(self.obj.name)
@navigator.register(MyService, 'Edit')
class MyServiceEdit(SSUINavigateStep):
VIEW = EditMyServiceView
prerequisite = NavigateToSibling('Details')
def step(self):
self.prerequisite_view.configuration.item_select('Edit')
@navigator.register(MyService, 'VM Console')
class LaunchVMConsole(SSUINavigateStep):
VIEW = EditMyServiceView
def prerequisite(self):
return navigate_to(self.obj, 'Details', wait_for_view=True)
def step(self):
if self.appliance.version < "5.8":
self.prerequisite_view.console_button.click()
else:
self.prerequisite_view.access_dropdown.item_select('VM Console')
@navigator.register(MyService, 'SetOwnership')
class MyServiceSetOwnership(SSUINavigateStep):
VIEW = SetOwnershipView
prerequisite = NavigateToSibling('Details')
def step(self):
# this is mandatory otherwise the locator is not found .
wait_for(
lambda: self.prerequisite_view.configuration.is_displayed, delay=5, num_sec=300,
message="waiting for view to be displayed"
)
self.prerequisite_view.configuration.item_select('Set Ownership')
@navigator.register(MyService, 'EditTagsFromDetails')
class MyServiceEditTags(SSUINavigateStep):
VIEW = TagPageView
prerequisite = NavigateToSibling('Details')
def step(self):
self.prerequisite_view.policy.item_select('Edit Tags')
@navigator.register(MyService, 'Retire')
class MyServiceRetire(SSUINavigateStep):
VIEW = RetireServiceView
prerequisite = NavigateToSibling('Details')
def step(self):
if self.appliance.version >= "5.8":
self.prerequisite_view.lifecycle.item_select('Retire')
else:
self.prerequisite_view.lifecycle.item_select('Retire Now')