-
Notifications
You must be signed in to change notification settings - Fork 138
Expand file tree
/
Copy pathtest_hostgroup.py
More file actions
410 lines (339 loc) · 15.4 KB
/
Copy pathtest_hostgroup.py
File metadata and controls
410 lines (339 loc) · 15.4 KB
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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
"""Test class for Host Group UI
:Requirement: Hostgroup
:CaseAutomation: Automated
:CaseComponent: HostGroup
:Team: Proton
:CaseImportance: High
"""
from fauxfactory import gen_string
import pytest
from robottelo.config import settings
from robottelo.constants import DEFAULT_CV, ENVIRONMENT
@pytest.mark.e2e
def test_positive_end_to_end(session, module_org, module_location, module_target_sat):
"""Perform end to end testing for host group component
:id: 537d95f2-fe32-4e06-a2cb-21c80fe8e2e2
:expectedresults: All expected CRUD actions finished successfully
:CaseImportance: Critical
"""
name = gen_string('alpha')
new_name = gen_string('alpha')
description = gen_string('alpha')
architecture = module_target_sat.api.Architecture().create()
os = module_target_sat.api.OperatingSystem(architecture=[architecture]).create()
os_name = f'{os.name} {os.major}'
domain = module_target_sat.api.Domain(
organization=[module_org], location=[module_location]
).create()
with session:
# Create host group with some data
session.hostgroup.create(
{
'host_group.name': name,
'host_group.description': description,
'host_group.lce': ENVIRONMENT,
'host_group.content_view': DEFAULT_CV,
'network.domain': domain.name,
'operating_system.architecture': architecture.name,
'operating_system.operating_system': os_name,
}
)
hostgroup_values = session.hostgroup.read(name)
assert hostgroup_values['host_group']['name'] == name
assert hostgroup_values['host_group']['description'] == description
assert hostgroup_values['host_group']['lce'] == ENVIRONMENT
assert hostgroup_values['host_group']['content_view'] == DEFAULT_CV
assert hostgroup_values['operating_system']['architecture'] == architecture.name
assert hostgroup_values['operating_system']['operating_system'] == os_name
# Update host group with new name
session.hostgroup.update(name, {'host_group.name': new_name})
assert session.hostgroup.search(new_name)[0]['Name'] == new_name
# Delete host group
session.hostgroup.delete(new_name)
assert not module_target_sat.api.HostGroup().search(query={'search': f'name={new_name}'})
def test_negative_delete_with_discovery_rule(
session, module_org, module_location, module_target_sat
):
"""Attempt to delete hostgroup which has dependent discovery rule
:id: bd046e9a-f0d0-4110-8f94-fd04193cb3af
:customerscenario: true
:BZ: 1254102
:expectedresults: Hostgroup was not deleted. Informative error message
was shown
:CaseImportance: High
"""
hostgroup = module_target_sat.api.HostGroup(
organization=[module_org], location=[module_location]
).create()
module_target_sat.api.DiscoveryRule(
hostgroup=hostgroup, organization=[module_org], location=[module_location]
).create()
with session:
assert session.hostgroup.search(hostgroup.name)[0]['Name'] == hostgroup.name
# Make an attempt to delete host group that associated with discovery rule
with pytest.raises(AssertionError) as context:
session.hostgroup.delete(hostgroup.name)
assert "Cannot delete record because dependent discovery rules exist" in str(context.value)
assert session.hostgroup.search(hostgroup.name)[0]['Name'] == hostgroup.name
def test_create_with_config_group(module_puppet_org, module_puppet_loc, session_puppet_enabled_sat):
"""Create new host group with assigned config group to it
:id: 05a64d6b-113b-4652-86bf-19bc65b70131
:CaseImportance: Medium
:expectedresults: Host group created and contains proper config group
"""
name = gen_string('alpha')
environment = session_puppet_enabled_sat.api.Environment(
organization=[module_puppet_org], location=[module_puppet_loc]
).create()
config_group = session_puppet_enabled_sat.api.ConfigGroup().create()
with session_puppet_enabled_sat.ui_session() as session:
# Create host group with config group
session.organization.select(org_name=module_puppet_org.name)
session.location.select(loc_name=module_puppet_loc.name)
session.hostgroup.create(
{
'host_group.name': name,
'host_group.puppet_environment': environment.name,
'puppet_enc.config_groups.assigned': [config_group.name],
}
)
hostgroup_values = session.hostgroup.read(name, widget_names='puppet_enc')
assert len(hostgroup_values['puppet_enc']['config_groups']['assigned']) == 1
assert hostgroup_values['puppet_enc']['config_groups']['assigned'][0] == config_group.name
@pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url')
def test_create_with_puppet_class(module_puppet_org, module_puppet_loc, session_puppet_enabled_sat):
"""Create new host group with assigned puppet class to it
:id: 166ca6a6-c0f7-4fa0-a3f2-b0d6980cf50d
:CaseImportance: Medium
:expectedresults: Host group created and contains proper puppet class
"""
name = gen_string('alpha')
pc_name = 'generic_1'
env_name = session_puppet_enabled_sat.create_custom_environment(repo=pc_name)
env = (
session_puppet_enabled_sat.api.Environment()
.search(query={'search': f'name={env_name}'})[0]
.read()
)
env = session_puppet_enabled_sat.api.Environment(
id=env.id,
location=[module_puppet_loc],
organization=[module_puppet_org],
).update(['location', 'organization'])
env = session_puppet_enabled_sat.api.Environment(
id=env.id, location=[module_puppet_loc]
).update(['location'])
with session_puppet_enabled_sat.ui_session() as session:
session.organization.select(org_name=module_puppet_org.name)
session.location.select(loc_name=module_puppet_loc.name)
# Create host group with puppet class
session.hostgroup.create(
{
'host_group.name': name,
'host_group.puppet_environment': env.name,
'puppet_enc.classes.assigned': [pc_name],
}
)
hostgroup_values = session.hostgroup.read(name, widget_names='puppet_enc')
assert len(hostgroup_values['puppet_enc']['classes']['assigned']) == 1
assert hostgroup_values['puppet_enc']['classes']['assigned'][0] == pc_name
def test_positive_create_new_host(
session,
target_sat,
module_org,
smart_proxy_location,
host_ui_options,
):
"""Verify that content source field automatically populates when creating new host from host
group.
:id: 49704437-5ca1-46cb-b74e-de58396add37
:steps:
1. Create hostgroup with the Content Source field populated.
2. Create host from Hosts > Create Host, selecting the hostgroup in the Host Group field.
:expectedresults: The host's Content source field is automatically populated from the selected
hostgroup.
:BZ: 1866746
:customerscenario: true
"""
name = gen_string('alpha')
description = gen_string('alpha')
capsule = target_sat.nailgun_smart_proxy
capsule.location = [smart_proxy_location]
capsule.update(['location'])
capsule.organization = [module_org]
capsule.update(['organization'])
with target_sat.ui_session() as session:
session.organization.select(module_org.name)
session.location.select(smart_proxy_location.name)
# Create host group with some data
session.hostgroup.create(
{
'host_group.name': name,
'host_group.description': description,
'host_group.content_source': capsule.name,
'locations.resources.assigned': [smart_proxy_location.name],
'organizations.resources.assigned': [module_org.name],
}
)
values, host_name = host_ui_options
values['host.hostgroup'] = name
session.host.create(values)
values = session.host.read(host_name, widget_names='host')
assert values['host']['name'] == host_name.partition('.')[0]
assert values['host']['content_source'] == capsule.name
def test_positive_nested_host_groups(
session, module_org, module_lce, module_published_cv, module_ak_cv_lce, target_sat
):
"""Verify create, update and delete operation for nested host-groups
:id: 547f8e72-df65-48eb-aeb1-6b5fd3cbf4e5
:steps:
1. Create the parent host-group.
2. Create, Update and Delete the nested host-group.
:CaseImportance: High
:expectedresults: Crud operations with nest host-group should work as expected.
:BZ: 1996077
:customerscenario: true
"""
parent_hg_name = gen_string('alpha')
child_hg_name = gen_string('alpha')
description = gen_string('alpha')
architecture = target_sat.api.Architecture().create()
os = target_sat.api.OperatingSystem(architecture=[architecture]).create()
os_name = f'{os.name} {os.major}'
with session:
# Create parent host-group with default lce and content view
session.hostgroup.create(
{
'host_group.name': parent_hg_name,
'host_group.description': description,
'host_group.lce': ENVIRONMENT,
'host_group.content_view': DEFAULT_CV,
'operating_system.architecture': architecture.name,
'operating_system.operating_system': os_name,
}
)
assert target_sat.api.HostGroup().search(query={'search': f'name={parent_hg_name}'})
# Create nested host group
session.hostgroup.create(
{
'host_group.parent_name': parent_hg_name,
'host_group.name': child_hg_name,
}
)
assert target_sat.api.HostGroup().search(query={'search': f'name={child_hg_name}'})
child_hostgroup_values = session.hostgroup.read(f'{parent_hg_name}/{child_hg_name}')
assert parent_hg_name in child_hostgroup_values['host_group']['parent_name']
assert ENVIRONMENT in child_hostgroup_values['host_group']['lce']
assert DEFAULT_CV in child_hostgroup_values['host_group']['content_view']
# Update nested host group
session.hostgroup.update(
f'{parent_hg_name}/{child_hg_name}',
{
'host_group.lce': module_lce.name,
'host_group.content_view': module_published_cv.name,
'activation_keys.activation_keys': module_ak_cv_lce.name,
},
)
child_hostgroup_values = session.hostgroup.read(f'{parent_hg_name}/{child_hg_name}')
assert parent_hg_name in child_hostgroup_values['host_group']['parent_name']
assert module_lce.name in child_hostgroup_values['host_group']['lce']
assert module_published_cv.name in child_hostgroup_values['host_group']['content_view']
# Delete nested host group
session.hostgroup.delete(f'{parent_hg_name}/{child_hg_name}')
assert not target_sat.api.HostGroup().search(query={'search': f'name={child_hg_name}'})
def test_positive_clone_host_groups(
session, module_org, module_lce, module_published_cv, module_ak_cv_lce, target_sat
):
"""Verify create, update and delete operation for clone host-group
:id: 9f02dcc5-98aa-48bd-8114-edd3a0be65c1
:steps:
1. Create the host-group.
2. Clone the host-group created in step 1
3. Update and Delete the cloned host-group.
:CaseImportance: High
:expectedresults: Crud operations with cloned host-group should work as expected.
:BZ: 2122261
:BlockedBy: SAT-20435
:customerscenario: true
"""
parent_hg_name = gen_string('alpha')
clone_hg_name = gen_string('alpha')
description = gen_string('alpha')
architecture = target_sat.api.Architecture().create()
os = target_sat.api.OperatingSystem(architecture=[architecture]).create()
os_name = f'{os.name} {os.major}'
with session:
# Create host-group with lce and content view
session.hostgroup.create(
{
'host_group.name': parent_hg_name,
'host_group.description': description,
'host_group.lce': module_lce.name,
'host_group.content_view': module_published_cv.name,
'operating_system.architecture': architecture.name,
'operating_system.operating_system': os_name,
'activation_keys.activation_keys': module_ak_cv_lce.name,
}
)
assert target_sat.api.HostGroup().search(query={'search': f'name={parent_hg_name}'})
# Clone host group of name
session.hostgroup.clone(
parent_hg_name,
{
'host_group.name': clone_hg_name,
},
)
assert target_sat.api.HostGroup().search(query={'search': f'name={clone_hg_name}'})
clone_hostgroup_values = session.hostgroup.read(clone_hg_name)
assert module_lce.name in clone_hostgroup_values['host_group']['lce']
assert module_published_cv.name in clone_hostgroup_values['host_group']['content_view']
assert (
module_ak_cv_lce.name in clone_hostgroup_values['activation_keys']['ak_chip_group'][0]
)
assert os_name in clone_hostgroup_values['operating_system']['operating_system']
assert architecture.name in clone_hostgroup_values['operating_system']['architecture']
# Update clone host group
session.hostgroup.update(
clone_hg_name,
{
'host_group.lce': ENVIRONMENT,
'host_group.content_view': DEFAULT_CV,
},
)
clone_hostgroup_values = session.hostgroup.read(clone_hg_name)
assert ENVIRONMENT in clone_hostgroup_values['host_group']['lce']
assert DEFAULT_CV in clone_hostgroup_values['host_group']['content_view']
# Delete parent and clone host group
session.hostgroup.delete(parent_hg_name)
assert target_sat.api.HostGroup().search(query={'search': f'name={clone_hg_name}'})
session.hostgroup.delete(clone_hg_name)
assert not target_sat.api.HostGroup().search(query={'search': f'name={clone_hg_name}'})
def test_positive_non_admin_viewer_role_read(
test_name,
module_target_sat,
module_org,
module_location,
module_hostgroup_with_org_loc,
module_user_viewer,
):
"""Verify that a non-admin user with Viewer role assigned is able to see a host group created by admin user.
:ID: c4f5e236-0bfb-11f1-acba-000c29a0e355
:CaseImportance: High
:Setup:
1. Create new host group as admin.
2. Create new non-admin user with Viewer role assigned.
:Steps:
1. Log in as the user with Viewer role and go to the Configure->Host Groups page.
:ExpectedResults: The page is displayed correctly, i.e., no error is shown. User sees the host group in the list.
:Verifies: SAT-38451
:CustomerScenario: true
"""
with module_target_sat.ui_session(
test_name, module_user_viewer.login, module_user_viewer.password
) as session:
session.organization.select(org_name=module_org.name)
session.location.select(loc_name=module_location.name)
assert (
session.hostgroup.search(module_hostgroup_with_org_loc.name)[0]['Name']
== module_hostgroup_with_org_loc.name
)