forked from SatelliteQE/robottelo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_esx_sca.py
More file actions
728 lines (651 loc) · 31.7 KB
/
Copy pathtest_esx_sca.py
File metadata and controls
728 lines (651 loc) · 31.7 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
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
"""Test class for Virtwho Configure UI
:Requirement: Virt-whoConfigurePlugin
:CaseAutomation: Automated
:CaseComponent: Virt-whoConfigurePlugin
:team: Proton
"""
from datetime import UTC, datetime, timedelta
from airgun.session import Session
from fauxfactory import gen_string
import pytest
from wait_for import wait_for
from robottelo.config import settings
from robottelo.utils.datafactory import valid_emails_list
from robottelo.utils.io import get_report_data
from robottelo.utils.virtwho import (
ETC_VIRTWHO_CONFIG,
add_configure_option,
delete_configure_option,
deploy_configure_by_command,
deploy_configure_by_command_check,
get_configure_command,
get_configure_file,
get_configure_id,
get_configure_option,
get_virtwho_status,
hypervisor_guest_mapping_newcontent_ui,
restart_virtwho_service,
update_configure_option,
)
@pytest.mark.usefixtures('delete_host')
class TestVirtwhoConfigforEsx:
@pytest.mark.upgrade
@pytest.mark.parametrize('deploy_type_ui', ['id', 'script'], indirect=True)
def test_positive_deploy_configure_by_id_script(
self,
module_sca_manifest_org,
org_session,
form_data_ui,
deploy_type_ui,
default_location,
):
"""Verify configure created and deployed with id.
:id: 867e109f-3ecc-4631-b6fb-085a1142473a
:expectedresults:
1. Config can be created and deployed by command or script
2. No error msg in /var/log/rhsm/rhsm.log
3. Report is sent to satellite
4. Subscription Status set to 'Simple Content Access', and generate mapping in Legacy UI
5. Check Hypervisor host subscription status and hypervisor host and virtual guest mapping in UI
6. Config can be deleted
:CaseImportance: High
"""
hypervisor_name, guest_name = deploy_type_ui
# Check virt-who config status
assert org_session.virtwho_configure.search(form_data_ui['name'])[0]['Status'] == 'ok'
# Check Hypervisor host subscription status and hypervisor host and virtual guest mapping in UI
hypervisor_guest_mapping_newcontent_ui(
org_session, default_location, hypervisor_name, guest_name
)
def test_positive_debug_option(
self, module_sca_manifest_org, virtwho_config_ui, org_session, form_data_ui, target_sat
):
"""Verify debug checkbox and the value changes of VIRTWHO_DEBUG
:id: 71e675b5-16ae-423a-9162-cd10a7a6a5eb
:expectedresults:
1. if debug is checked, VIRTWHO_DEBUG=1 in /etc/sysconfig/virt-who
2. if debug is unchecked, VIRTWHO_DEBUG=0 in /etc/sysconfig/virt-who
:CaseImportance: Medium
"""
name = form_data_ui['name']
config_id = get_configure_id(name)
config_command = get_configure_command(config_id, module_sca_manifest_org.name)
deploy_configure_by_command(
config_command,
form_data_ui['hypervisor_type'],
org=module_sca_manifest_org.label,
target_sat=target_sat,
)
assert get_configure_option('debug', ETC_VIRTWHO_CONFIG) == '1'
org_session.virtwho_configure.edit(name, {'debug': False})
results = org_session.virtwho_configure.read(name)
assert results['overview']['debug'] is False
deploy_configure_by_command(
config_command,
form_data_ui['hypervisor_type'],
org=module_sca_manifest_org.label,
target_sat=target_sat,
)
assert get_configure_option('debug', ETC_VIRTWHO_CONFIG) == '0'
def test_positive_interval_option(
self, module_sca_manifest_org, virtwho_config_ui, org_session, form_data_ui, target_sat
):
"""Verify interval dropdown options and the value changes of VIRTWHO_INTERVAL.
:id: 22fe4e66-5a73-4fa5-866e-c5664aabfa23
:expectedresults:
VIRTWHO_INTERVAL can be changed in /etc/sysconfig/virt-who if the
dropdown option is selected to Every 2/4/8/12/24 hours, Every 2/3 days.
:CaseImportance: Medium
"""
name = form_data_ui['name']
config_id = get_configure_id(name)
config_command = get_configure_command(config_id, module_sca_manifest_org.name)
intervals = {
'Every hour': '3600',
'Every 2 hours': '7200',
'Every 4 hours': '14400',
'Every 8 hours': '28800',
'Every 12 hours': '43200',
'Every 24 hours': '86400',
'Every 2 days': '172800',
'Every 3 days': '259200',
}
for option, value in intervals.items():
org_session.virtwho_configure.edit(name, {'interval': option})
results = org_session.virtwho_configure.read(name)
assert results['overview']['interval'] == option
deploy_configure_by_command(
config_command,
form_data_ui['hypervisor_type'],
org=module_sca_manifest_org.label,
target_sat=target_sat,
)
assert get_configure_option('interval', ETC_VIRTWHO_CONFIG) == value
def test_positive_hypervisor_id_option(
self, module_sca_manifest_org, virtwho_config_ui, org_session, form_data_ui, target_sat
):
"""Verify Hypervisor ID dropdown options.
:id: b9767319-ab81-425c-bebe-0701d5e91332
:expectedresults:
hypervisor_id can be changed in virt-who-config-{}.conf if the
dropdown option is selected to uuid/hwuuid/hostname.
:CaseImportance: Medium
"""
name = form_data_ui['name']
config_id = get_configure_id(name)
config_command = get_configure_command(config_id, module_sca_manifest_org.name)
config_file = get_configure_file(config_id)
# esx and rhevm support hwuuid option
for value in ['uuid', 'hostname', 'hwuuid']:
org_session.virtwho_configure.edit(name, {'hypervisor_id': value})
results = org_session.virtwho_configure.read(name)
assert results['overview']['hypervisor_id'] == value
deploy_configure_by_command(
config_command,
form_data_ui['hypervisor_type'],
org=module_sca_manifest_org.label,
target_sat=target_sat,
)
assert get_configure_option('hypervisor_id', config_file) == value
@pytest.mark.parametrize('filter_type', ['whitelist', 'blacklist'])
@pytest.mark.parametrize('option_type', ['edit', 'create'])
def test_positive_filtering_option(
self,
module_sca_manifest_org,
org_session,
form_data_ui,
filter_type,
option_type,
target_sat,
):
"""Verify Filtering dropdown options.
:id: 8e5fa139-8e79-4dd4-85f2-5565ec4b39f1
:expectedresults:
1. Edit virtwho config if filtering is selected to Whitelist,
'Filter hosts' can be set.
2. Edit virtwho config if filtering is selected to Blacklist,
'Exclude hosts' can be set.
3. Create virtwho config if filtering is selected to Whitelist,
'Filter hosts' can be set.
4. Create virtwho config if filtering is selected to Blacklist,
'Exclude hosts' can be set.
:CaseImportance: Medium
:BZ: 1735670
:customerscenario: true
"""
name = gen_string('alpha')
form_data_ui['name'] = name
regex = '.*redhat.com'
with org_session:
if option_type == "edit":
org_session.virtwho_configure.create(form_data_ui)
config_id = get_configure_id(name)
config_command = get_configure_command(config_id, module_sca_manifest_org.name)
config_file = get_configure_file(config_id)
if filter_type == "whitelist":
whitelist = {'filtering': 'Whitelist', 'filtering_content.filter_hosts': regex}
# esx support filter-host-parents and exclude-host-parents options
whitelist['filtering_content.filter_host_parents'] = regex
# Update Whitelist and check the result
org_session.virtwho_configure.edit(name, whitelist)
results = org_session.virtwho_configure.read(name)
assert results['overview']['filter_hosts'] == regex
assert results['overview']['filter_host_parents'] == regex
elif filter_type == "blacklist":
blacklist = {'filtering': 'Blacklist', 'filtering_content.exclude_hosts': regex}
blacklist['filtering_content.exclude_host_parents'] = regex
org_session.virtwho_configure.edit(name, blacklist)
results = org_session.virtwho_configure.read(name)
assert results['overview']['exclude_hosts'] == regex
assert results['overview']['exclude_host_parents'] == regex
deploy_configure_by_command(
config_command,
form_data_ui['hypervisor_type'],
org=module_sca_manifest_org.label,
target_sat=target_sat,
)
if filter_type == "whitelist":
assert regex == get_configure_option('filter_hosts', config_file)
assert regex == get_configure_option('filter_host_parents', config_file)
elif filter_type == "blacklist":
assert regex == get_configure_option('exclude_hosts', config_file)
assert regex == get_configure_option('exclude_host_parents', config_file)
org_session.virtwho_configure.delete(name)
assert not org_session.virtwho_configure.search(name)
elif option_type == "create":
if filter_type == "whitelist":
form_data_ui['filtering'] = "Whitelist"
form_data_ui['filtering_content.filter_hosts'] = regex
form_data_ui['filtering_content.filter_host_parents'] = regex
elif filter_type == "blacklist":
form_data_ui['filtering'] = "Blacklist"
form_data_ui['filtering_content.exclude_hosts'] = regex
form_data_ui['filtering_content.exclude_host_parents'] = regex
org_session.virtwho_configure.create(form_data_ui)
config_id = get_configure_id(name)
command = get_configure_command(config_id, module_sca_manifest_org.name)
deploy_configure_by_command(
command,
form_data_ui['hypervisor_type'],
org=module_sca_manifest_org.label,
target_sat=target_sat,
)
config_file = get_configure_file(config_id)
results = org_session.virtwho_configure.read(name)
if filter_type == "whitelist":
assert results['overview']['filter_hosts'] == regex
assert results['overview']['filter_host_parents'] == regex
assert regex == get_configure_option('filter_hosts', config_file)
assert regex == get_configure_option('filter_host_parents', config_file)
elif filter_type == "blacklist":
assert results['overview']['exclude_hosts'] == regex
assert results['overview']['exclude_host_parents'] == regex
assert regex == get_configure_option('exclude_hosts', config_file)
assert regex == get_configure_option('exclude_host_parents', config_file)
def test_positive_remove_env_option(
self, module_sca_manifest_org, virtwho_config_ui, form_data_ui, target_sat, org_session
):
"""remove option 'env=' from the virt-who configuration file and without any error
:id: 779a37fb-1245-4b01-920f-7c28a96a5fe0
:expectedresults:
1. the option "env=" should be removed from etc/virt-who.d/virt-who.conf
2. /var/log/messages should not display warning message
:CaseImportance: Medium
:BZ: 1834897
:customerscenario: true
"""
name = form_data_ui['name']
values = org_session.virtwho_configure.read(name)
command = values['deploy']['command']
deploy_configure_by_command(
command,
form_data_ui['hypervisor_type'],
debug=True,
org=module_sca_manifest_org.label,
target_sat=target_sat,
)
assert org_session.virtwho_configure.search(name)[0]['Status'] == 'ok'
# Check the option "env=" should be removed from etc/virt-who.d/virt-who.conf
option = "env"
config_id = get_configure_id(name)
config_file = get_configure_file(config_id)
env_error = f"option {{'{option}'}} is not exist or not be enabled in {{'{config_file}'}}"
with pytest.raises(Exception) as exc_info: # noqa: PT011 - TODO determine better exception
get_configure_option({option}, {config_file})
assert str(exc_info.value) == env_error
# Check /var/log/messages should not display warning message
env_warning = f"Ignoring unknown configuration option \"{option}\""
result = target_sat.execute(f'grep "{env_warning}" /var/log/messages')
assert result.status == 1
def test_positive_virtwho_roles(self, org_session):
"""Verify the default roles for virtwho configure
:id: 3c2501d5-c122-49f0-baa4-4c0d678cb6fc
:expectedresults:
'Virt-who Manager', 'Virt-who Reporter', 'Virt-who Viewer' existing
:CaseImportance: Low
"""
roles = {
'Virt-who Manager': {
'Satellite virt who configure/config': [
'view_virt_who_config',
'create_virt_who_config',
'edit_virt_who_config',
'destroy_virt_who_config',
]
},
'Virt-who Reporter': {
'Host': ['create_hosts', 'edit_hosts'],
'Lifecycle Environment': ['view_lifecycle_environments'],
'(Miscellaneous)': ['my_organizations'],
},
'Virt-who Viewer': {'Satellite virt who configure/config': ['view_virt_who_config']},
}
with org_session:
for role_name, role_filters in roles.items():
assert org_session.role.search(role_name)[0]['Name'] == role_name
assigned_permissions = org_session.filter.read_permissions(role_name)
assert sorted(assigned_permissions) == sorted(role_filters)
def test_positive_delete_configure(
self, module_sca_manifest_org, org_session, form_data_ui, target_sat
):
"""Verify when a config is deleted the associated user is deleted.
:id: efc7253d-f455-4dc3-ae03-3ed5e215bd11
:steps:
1. Create a virt-who configuration and deploy it to a
virt-who server.
2. Delete the configuration on the Satellite.
:expectedresults:
1. Verify the virt-who server can no longer connect to the
Satellite.
:CaseImportance: Low
"""
name = gen_string('alpha')
form_data_ui['name'] = name
with org_session:
org_session.virtwho_configure.create(form_data_ui)
config_id = get_configure_id(name)
config_command = get_configure_command(config_id, module_sca_manifest_org.name)
deploy_configure_by_command(
config_command,
form_data_ui['hypervisor_type'],
org=module_sca_manifest_org.label,
target_sat=target_sat,
)
assert org_session.virtwho_configure.search(name)[0]['Status'] == 'ok'
org_session.virtwho_configure.delete(name)
assert not org_session.virtwho_configure.search(name)
restart_virtwho_service()
assert get_virtwho_status() == 'logerror'
def test_positive_virtwho_reporter_role(
self, module_sca_manifest_org, org_session, test_name, form_data_ui, target_sat
):
"""Verify the virt-who reporter role can TRULY work.
:id: eacb6efc-7bcb-4837-9d88-e242cfb3eaae
:expectedresults:
Virt-who Reporter Role granting minimal set of permissions for virt-who
to upload the report, it can be used if you configure virt-who manually
and want to use user that has locked down account.
:CaseImportance: Low
"""
username = gen_string('alpha')
password = gen_string('alpha')
config_name = gen_string('alpha')
with org_session:
# Create an user
org_session.user.create(
{
'user.login': username,
'user.mail': valid_emails_list()[0],
'user.auth': 'INTERNAL',
'user.password': password,
'user.confirm': password,
}
)
# Create a virt-who config plugin
form_data_ui['name'] = config_name
org_session.virtwho_configure.create(form_data_ui)
values = org_session.virtwho_configure.read(config_name)
command = values['deploy']['command']
deploy_configure_by_command(
command,
form_data_ui['hypervisor_type'],
org=module_sca_manifest_org.label,
target_sat=target_sat,
)
assert org_session.virtwho_configure.search(config_name)[0]['Status'] == 'ok'
# Update the virt-who config file
config_id = get_configure_id(config_name)
config_file = get_configure_file(config_id)
update_configure_option('rhsm_username', username, config_file)
delete_configure_option('rhsm_encrypted_password', config_file)
add_configure_option('rhsm_password', password, config_file)
restart_virtwho_service()
assert get_virtwho_status() == 'logerror'
# Check the permissioin of Virt-who Reporter
org_session.user.update(username, {'roles.resources.assigned': ['Virt-who Reporter']})
assert org_session.user.search(username)[0]['Username'] == username
user = org_session.user.read(username)
assert user['roles']['resources']['assigned'] == ['Virt-who Reporter']
restart_virtwho_service()
assert get_virtwho_status() == 'running'
with Session(test_name, username, password) as newsession:
assert not newsession.virtwho_configure.check_create_permission()['can_view']
org_session.user.delete(username)
assert not org_session.user.search(username)
def test_positive_virtwho_viewer_role(
self, module_sca_manifest_org, org_session, test_name, form_data_ui, target_sat
):
"""Verify the virt-who viewer role can TRULY work.
:id: 6619a1e8-5cd4-4fe8-a318-95499aeb7552
:expectedresults:
Virt-who Viewer Role granting permissions to see all configurations
including their configuration scripts, which means viewers could still
deploy the virt-who instances for existing virt-who configurations.
:CaseImportance: Low
"""
username = gen_string('alpha')
password = gen_string('alpha')
config_name = gen_string('alpha')
with org_session:
# Create an user
org_session.user.create(
{
'user.login': username,
'user.mail': valid_emails_list()[0],
'user.auth': 'INTERNAL',
'user.password': password,
'user.confirm': password,
}
)
# Create a virt-who config plugin
form_data_ui['name'] = config_name
org_session.virtwho_configure.create(form_data_ui)
values = org_session.virtwho_configure.read(config_name)
command = values['deploy']['command']
deploy_configure_by_command(
command,
form_data_ui['hypervisor_type'],
org=module_sca_manifest_org.label,
target_sat=target_sat,
)
assert org_session.virtwho_configure.search(config_name)[0]['Status'] == 'ok'
# Check the permissioin of Virt-who Viewer
org_session.user.update(username, {'roles.resources.assigned': ['Virt-who Viewer']})
user = org_session.user.read(username)
assert user['roles']['resources']['assigned'] == ['Virt-who Viewer']
# Update the virt-who config file
config_id = get_configure_id(config_name)
config_file = get_configure_file(config_id)
update_configure_option('rhsm_username', username, config_file)
delete_configure_option('rhsm_encrypted_password', config_file)
add_configure_option('rhsm_password', password, config_file)
restart_virtwho_service()
assert get_virtwho_status() == 'logerror'
with Session(test_name, username, password) as newsession:
create_permission = newsession.virtwho_configure.check_create_permission()
update_permission = newsession.virtwho_configure.check_update_permission(
config_name
)
assert create_permission['can_view']
assert not create_permission['can_create']
assert not update_permission['can_delete']
assert not update_permission['can_edit']
newsession.virtwho_configure.read(config_name)
# Delete the created user
org_session.user.delete(username)
assert not org_session.user.search(username)
def test_positive_virtwho_manager_role(
self, module_sca_manifest_org, org_session, test_name, form_data_ui, target_sat
):
"""Verify the virt-who manager role can TRULY work.
:id: ddaf44cc-10fb-402a-9b97-fe8692404031
:expectedresults:
Virt-who Manager Role granting all permissions to manage virt-who configurations,
user needs this role to create, delete or update configurations.
:CaseImportance: Low
"""
username = gen_string('alpha')
password = gen_string('alpha')
config_name = gen_string('alpha')
with org_session:
# Create an user
org_session.user.create(
{
'user.login': username,
'user.mail': valid_emails_list()[0],
'user.auth': 'INTERNAL',
'user.password': password,
'user.confirm': password,
}
)
# Create a virt-who config plugin
form_data_ui['name'] = config_name
org_session.virtwho_configure.create(form_data_ui)
values = org_session.virtwho_configure.read(config_name)
command = values['deploy']['command']
deploy_configure_by_command(
command,
form_data_ui['hypervisor_type'],
org=module_sca_manifest_org.label,
target_sat=target_sat,
)
assert org_session.virtwho_configure.search(config_name)[0]['Status'] == 'ok'
# Check the permissioin of Virt-who Manager
org_session.user.update(username, {'roles.resources.assigned': ['Virt-who Manager']})
user = org_session.user.read(username)
assert user['roles']['resources']['assigned'] == ['Virt-who Manager']
with Session(test_name, username, password) as newsession:
# create_virt_who_config
new_virt_who_name = gen_string('alpha')
form_data_ui['name'] = new_virt_who_name
newsession.virtwho_configure.create(form_data_ui)
# view_virt_who_config
values = newsession.virtwho_configure.read(new_virt_who_name)
command = values['deploy']['command']
deploy_configure_by_command(
command,
form_data_ui['hypervisor_type'],
org=module_sca_manifest_org.label,
target_sat=target_sat,
)
assert newsession.virtwho_configure.search(new_virt_who_name)[0]['Status'] == 'ok'
# edit_virt_who_config
modify_name = gen_string('alpha')
newsession.virtwho_configure.edit(new_virt_who_name, {'name': modify_name})
newsession.virtwho_configure.search(modify_name)
# destroy_virt_who_config
newsession.virtwho_configure.delete(modify_name)
assert not newsession.virtwho_configure.search(modify_name)
# Delete the created user
org_session.user.delete(username)
assert not org_session.user.search(username)
def test_positive_deploy_configure_hypervisor_password_with_special_characters(
self, module_sca_manifest_org, form_data_ui, target_sat, org_session
):
"""Verify " hammer virt-who-config deploy hypervisor with special characters"
:id: 0cefdbb3-fc23-49c4-b1fb-78004db1c7bc
:expectedresults: Config can be created and deployed without any error
:CaseImportance: High
:BZ: 1870816,1959136
:customerscenario: true
"""
name = gen_string('alpha')
form_data_ui['name'] = name
with org_session:
# check the hypervisor password contains single quotes
form_data_ui['hypervisor_content.password'] = "Tes't"
org_session.virtwho_configure.create(form_data_ui)
values = org_session.virtwho_configure.read(name)
command = values['deploy']['command']
config_id = get_configure_id(name)
deploy_status = deploy_configure_by_command_check(command)
assert deploy_status == 'Finished successfully'
config_file = get_configure_file(config_id)
assert get_configure_option('rhsm_hostname', config_file) == target_sat.hostname
assert (
get_configure_option('username', config_file)
== settings.virtwho.esx.hypervisor_username
)
org_session.virtwho_configure.delete(name)
assert not org_session.virtwho_configure.search(name)
# check the hypervisor password contains backtick
form_data_ui['hypervisor_content.password'] = "my`password"
org_session.virtwho_configure.create(form_data_ui)
values = org_session.virtwho_configure.read(name)
command = values['deploy']['command']
config_id = get_configure_id(name)
deploy_status = deploy_configure_by_command_check(command)
assert deploy_status == 'Finished successfully'
config_file = get_configure_file(config_id)
assert get_configure_option('rhsm_hostname', config_file) == target_sat.hostname
assert (
get_configure_option('username', config_file)
== settings.virtwho.esx.hypervisor_username
)
org_session.virtwho_configure.delete(name)
assert not org_session.virtwho_configure.search(name)
def test_positive_hypervisor_password_option(
self, module_sca_manifest_org, virtwho_config_ui, org_session, form_data_ui, target_sat
):
"""Verify Hypervisor password.
:id: 8362955a-4daa-4332-9559-b526d9095a61
:expectedresults:
hypervisor_password has been set in virt-who-config-{}.conf
hypervisor_password has been encrypted in satellite WEB UI Edit page
hypervisor_password has been encrypted in satellite WEB UI Details page
:CaseImportance: Medium
:BZ: 2256927
"""
name = form_data_ui['name']
config_id = get_configure_id(name)
config_command = get_configure_command(config_id, module_sca_manifest_org.name)
deploy_configure_by_command(
config_command,
form_data_ui['hypervisor_type'],
org=module_sca_manifest_org.label,
target_sat=target_sat,
)
config_file = get_configure_file(config_id)
assert get_configure_option('encrypted_password', config_file)
res = org_session.virtwho_configure.read_edit(name)
assert 'encrypted-' in res['hypervisor_content']['password']
org_session.virtwho_configure.edit(name, {'hypervisor_password': gen_string('alpha')})
results = org_session.virtwho_configure.read(name)
assert 'encrypted_password=$cr_password' in results['deploy']['script']
@pytest.mark.parametrize('deploy_type_ui', ['id'], indirect=True)
def test_positive_minimal_report_hypervisor(
self, module_sca_manifest_org, org_session, form_data_ui, deploy_type_ui, module_target_sat
):
"""Verify that the Minimal data collection report contains the proper fields for a configured hypervisor
:id: 75fc7cc1-af73-4877-b443-d8298dccabdf
:steps:
1. Go to Insights > Inventory upload > enable “Minimal data collection” setting
2. Generate report after enabling the setting
3. Check if hostnames are NOT in generated report
4. Check if ipv4 addresses are NOT in generated report
5. Check if hypervisor_type and hypervisor_version fields are IN report
:CaseImportance: High
:Verifies: SAT-31467
"""
hypervisor_name, guest_name = deploy_type_ui
# Check virt-who config status
assert org_session.virtwho_configure.search(form_data_ui['name'])[0]['Status'] == 'ok'
org_session.cloudinventory.update(
{
'data_collection': 'Minimal data collectionOnly send the minimum required data to Red Hat cloud, obfuscation settings are disabled'
}
)
timestamp = (datetime.now(UTC) - timedelta(minutes=2)).strftime('%Y-%m-%d %H:%M')
org_session.cloudinventory.generate_and_upload_report(module_sca_manifest_org.name)
# wait_for_tasks report generation task to finish
wait_for(
lambda: (
module_target_sat.api.ForemanTask()
.search(
query={
'search': f'label = ForemanInventoryUpload::Async::HostInventoryReportJob '
f'and started_at >= "{timestamp}"'
}
)[0]
.result
== 'success'
),
timeout=400,
delay=15,
silent_failure=True,
handle_exception=True,
)
# download report
report_path = org_session.cloudinventory.download_report_only(module_sca_manifest_org.name)
json_data = get_report_data(report_path)
host_data = [item for item in json_data['hosts']]
# Verify that guest hostname is NOT in report
hostnames = [item['fqdn'] for item in host_data if 'fqdn' in item]
assert guest_name not in hostnames, f"'guest hostname' found in: {hostnames}"
# Verify that ip addresses are NOT in report
ip_address = [item['ip_addresses'] for item in host_data if 'ip_addresses' in item]
assert not ip_address, f"'ip_addresses' found in: {ip_address}"
# Verify that hypervisor_type and hypervisor_version are IN report
assert any(
'hypervisor_type' in item and 'hypervisor_version' in item for item in host_data
), "'hypervisor_type' and 'hypervisor_version' not found"