-
Notifications
You must be signed in to change notification settings - Fork 138
Expand file tree
/
Copy pathtest_host.py
More file actions
4399 lines (3773 loc) · 173 KB
/
Copy pathtest_host.py
File metadata and controls
4399 lines (3773 loc) · 173 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
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""Test class for Hosts UI
:Requirement: Host
:CaseAutomation: Automated
:CaseComponent: Hosts
:Team: Proton
:CaseImportance: High
"""
from contextlib import contextmanager
import copy
import csv
from datetime import UTC, datetime, timedelta
import json
import re
import time
from airgun.exceptions import DisabledWidgetError, NoSuchElementException
from box import Box
import pytest
from wait_for import wait_for
import yaml
from robottelo.config import settings
from robottelo.constants import (
ANY_CONTEXT,
DEFAULT_ARCHITECTURE,
DEFAULT_CV,
DEFAULT_LOC,
DEFAULT_ORG,
ENVIRONMENT,
FAKE_1_CUSTOM_PACKAGE,
FAKE_7_CUSTOM_PACKAGE,
FAKE_8_CUSTOM_PACKAGE,
FAKE_8_CUSTOM_PACKAGE_NAME,
FOREMAN_PROVIDERS,
OSCAP_PERIOD,
OSCAP_WEEKDAY,
REPO_TYPE,
REPOS,
ROLES,
)
from robottelo.constants.repos import CUSTOM_FILE_REPO
from robottelo.exceptions import APIResponseError
from robottelo.logging import logger
from robottelo.utils.datafactory import gen_string
from tests.foreman.api.test_errata import cv_publish_promote
def _get_set_from_list_of_dict(value):
"""Returns a set of tuples representation of each dict sorted by keys
:param list value: a list of simple dict.
"""
return {tuple(sorted(list(global_param.items()), key=lambda t: t[0])) for global_param in value}
@contextmanager
def mock_service_as_rebootable(contenthost, service_name):
"""Context manager to temporarily make a service require reboot instead of restart.
Modifies the katello tracer's STATIC_SERVICES list on the content host to include
the specified service, causing tracer to classify it as type='static' (reboot required)
instead of type='daemon' (restart required).
This is useful for testing reboot-required trace scenarios without needing to
actually downgrade kernel or systemd packages.
:param contenthost: ContentHost instance to modify
:param service_name: Name of the service to mark as reboot-required
Usage:
with mock_service_as_rebootable(rhel_contenthost, 'robottelo-mock-service'):
rhel_contenthost.execute('yum -y downgrade robottelo-mock-service')
"""
# Dynamically find the katello tracer dnf.py file (Python version agnostic)
find_cmd = 'python3 -c "import katello.tracer.dnf; print(katello.tracer.dnf.__file__)"'
find_result = contenthost.execute(find_cmd)
if find_result.status != 0:
raise RuntimeError(
f'Failed to locate katello tracer module on {contenthost.hostname}: {find_result.stderr}'
)
tracer_file = find_result.stdout.strip()
backup_path = '/tmp/katello_tracer_dnf.py.backup'
# Create backup
backup_result = contenthost.execute(f'cp {tracer_file} {backup_path}')
if backup_result.status != 0:
logger.warning(f'Failed to backup tracer file: {backup_result.stderr}')
# Add service to STATIC_SERVICES list
# In the ../tracer/dnf.py it looks like this:
# STATIC_SERVICES = [
# "systemd",
# "dbus",
# ]
add_cmd = f'''python3 << 'EOFPYTHON'
import re
with open('{tracer_file}', 'r') as f:
content = f.read()
# Find STATIC_SERVICES list and add service before the closing bracket
pattern = r'(STATIC_SERVICES = \\[.*?)(\\])'
replacement = r'\\1 "{service_name}",\\n\\2'
modified_content = re.sub(pattern, replacement, content, flags=re.DOTALL)
with open('{tracer_file}', 'w') as f:
f.write(modified_content)
print("Service added successfully")
EOFPYTHON
'''
add_result = contenthost.execute(add_cmd)
if add_result.status != 0:
logger.error(f'Failed to add service to STATIC_SERVICES: {add_result.stderr}')
# Restore backup
contenthost.execute(f'mv {backup_path} {tracer_file}')
raise RuntimeError(f'Failed to modify tracer configuration: {add_result.stderr}')
try:
# Verify the modification
verify_result = contenthost.execute(f'grep "{service_name}" {tracer_file}')
if verify_result.status == 0:
logger.info(
f'Successfully added {service_name} to STATIC_SERVICES on {contenthost.hostname}'
)
yield
finally:
# Cleanup: Restore original file
restore_result = contenthost.execute(f'mv {backup_path} {tracer_file}')
if restore_result.status == 0:
logger.info(f'Restored original tracer configuration on {contenthost.hostname}')
else:
logger.warning(
f'Failed to restore tracer file on {contenthost.hostname}: {restore_result.stderr}'
)
# this fixture inherits the fixture called ui_user in confest.py, method name has to be same
@pytest.fixture(scope='module')
def ui_user(ui_user, smart_proxy_location, module_target_sat):
module_target_sat.api.User(
id=ui_user.id,
default_location=smart_proxy_location,
).update(['default_location'])
return ui_user
@pytest.fixture
def ui_admin_user(target_sat):
"""Admin user."""
admin_user = target_sat.api.User().search(
query={'search': f'login={settings.server.admin_username}'}
)[0]
admin_user.password = settings.server.admin_password
return admin_user
@pytest.fixture
def host_ui_default(target_sat):
settings_object = target_sat.api.Setting().search(query={'search': 'name=host_details_ui'})[0]
settings_object.value = 'No'
settings_object.update({'value'})
yield
settings_object.value = 'Yes'
settings_object.update({'value'})
@pytest.fixture
def ui_view_hosts_user(target_sat, current_sat_org, current_sat_location, expected_permissions):
"""User with View hosts role."""
role = target_sat.api.Role(organization=[current_sat_org]).create()
target_sat.api_factory.create_role_permissions(
role,
{
'Host': ['view_hosts'],
'Organization': expected_permissions['Organization'],
'Location': expected_permissions['Location'],
},
)
password = gen_string('alphanumeric')
user = target_sat.api.User(
admin=False,
location=[current_sat_location],
organization=[current_sat_org],
role=[role],
password=password,
).create()
user.password = password
yield user
user.delete()
@pytest.fixture(params=['ui_admin_user', 'ui_view_hosts_user'])
def ui_hosts_columns_user(request):
"""Parametrized fixture returning defined users for the UI session."""
return request.getfixturevalue(request.param)
@pytest.fixture
def scap_policy(scap_content, target_sat):
return target_sat.cli_factory.make_scap_policy(
{
'name': gen_string('alpha'),
'deploy-by': 'ansible',
'scap-content-id': scap_content["scap_id"],
'scap-content-profile-id': scap_content["scap_profile_id"],
'period': OSCAP_PERIOD['weekly'].lower(),
'weekday': OSCAP_WEEKDAY['friday'].lower(),
}
)
second_scap_policy = scap_policy
@pytest.fixture(scope='module')
def module_global_params(module_target_sat):
"""Create 3 global parameters and clean up at teardown"""
global_parameters = []
for _ in range(3):
global_parameter = module_target_sat.api.CommonParameter(
name=gen_string('alpha'), value=gen_string('alphanumeric')
).create()
global_parameters.append(global_parameter)
yield global_parameters
# cleanup global parameters
for global_parameter in global_parameters:
global_parameter.delete()
@pytest.fixture
def tracer_install_host(rex_contenthost, target_sat):
"""This fixture automatically configures IPv6 support based on the host's network type and creates
version-appropriate repositories.
:param rex_contenthost: Remote execution enabled content host
:param target_sat: Target Satellite server
:return: ContentHost with tracer tools installed and configured
"""
# add IPv6 proxy for IPv6 communication based on network type
if not rex_contenthost.network_type.has_ipv4:
rex_contenthost.enable_ipv6_dnf_and_rhsm_proxy()
rex_contenthost.enable_ipv6_system_proxy()
# create a custom, rhel version-specific OS repo
rhelver = rex_contenthost.os_version.major
if rhelver > 7:
# RHEL 8, 9 and 10 use the same repository structure
rex_contenthost.create_custom_repos(**settings.repos[f'rhel{rhelver}_os'])
else:
# RHEL 7 has different repository structure
rex_contenthost.create_custom_repos(
**{f'rhel{rhelver}_os': settings.repos[f'rhel{rhelver}_os']}
)
return rex_contenthost
@pytest.fixture
def tracer_hosts(rex_contenthosts, target_sat):
"""Fixture that provides two tracer hosts with mock service installed.
Similar to the tracer_host and tracer_install_host fixtures but provides multiple hosts for bulk operations testing.
"""
for host in rex_contenthosts:
# add IPv6 proxy for IPv6 communication based on network type
if not host.network_type.has_ipv4:
host.enable_ipv6_dnf_and_rhsm_proxy()
host.enable_ipv6_system_proxy()
# create a custom, rhel version-specific OS repo
rhelver = host.os_version.major
if rhelver > 7:
# RHEL 8, 9 and 10 use the same repository structure
host.create_custom_repos(**settings.repos[f'rhel{rhelver}_os'])
else:
# RHEL 7 has different repository structure
host.create_custom_repos(**{f'rhel{rhelver}_os': settings.repos[f'rhel{rhelver}_os']})
# Install tracer
host.install_tracer()
# Install mock service repository and package
host.create_custom_repos(
**{f'mock_service_rhel{rhelver}': settings.repos['MOCK_SERVICE_REPO'][f'rhel{rhelver}']}
)
assert host.execute(f'yum -y install {settings.repos["MOCK_SERVICE_RPM"]}').status == 0
assert host.execute(f'rpm -q {settings.repos["MOCK_SERVICE_RPM"]}').status == 0
host.execute(f'systemctl start {settings.repos["MOCK_SERVICE_RPM"]}')
return rex_contenthosts
@pytest.mark.e2e
def test_positive_end_to_end(module_global_params, target_sat, host_ui_options, request, ui_user):
"""Create a new Host with parameters, config group. Check host presence on
the dashboard. Update name with 'new' prefix and delete.
:id: d2f86309-1a6d-42dc-a865-9e607cd25ae5
:expectedresults: Host is created with parameters, config group. Updated
and deleted.
:BZ: 1419161
"""
api_values, host_name = host_ui_options
global_params = [
global_param.to_json_dict(lambda attr, field: attr in ['name', 'value'])
for global_param in module_global_params
]
host_parameters = []
for _ in range(2):
host_parameters.append(dict(name=gen_string('alpha'), value=gen_string('alphanumeric')))
expected_host_parameters = copy.deepcopy(host_parameters)
# override the first global parameter
overridden_global_parameter = {'name': global_params[0]['name'], 'value': gen_string('alpha')}
expected_host_parameters.append(overridden_global_parameter)
expected_global_parameters = copy.deepcopy(global_params)
for global_param in expected_global_parameters:
# update with overridden expected value
if global_param['name'] == overridden_global_parameter['name']:
global_param['overridden'] = True
else:
global_param['overridden'] = False
new_name = f"new{gen_string('alpha').lower()}"
new_host_name = f"{new_name}.{api_values['interfaces.interface.domain']}"
stripped_headers = None
@request.addfinalizer
def _finalize():
# Get table to original state
with target_sat.ui_session(user=ui_user.login, password=ui_user.password) as session:
session.organization.select(api_values['host.organization'])
session.location.select(api_values['host.location'])
session.all_hosts.manage_table_columns({header: True for header in stripped_headers})
with target_sat.ui_session(user=ui_user.login, password=ui_user.password) as session:
session.organization.select(api_values['host.organization'])
session.location.select(api_values['host.location'])
api_values.update(
{
'parameters.host_params': host_parameters,
'parameters.global_params': [overridden_global_parameter],
}
)
session.host.create(api_values)
assert session.host.search(host_name)[0]['Name'] == host_name
values = session.host.read(host_name, widget_names=['parameters'])
assert _get_set_from_list_of_dict(
values['parameters']['host_params']
) == _get_set_from_list_of_dict(expected_host_parameters)
assert _get_set_from_list_of_dict(expected_global_parameters).issubset(
_get_set_from_list_of_dict(values['parameters']['global_params'])
)
# check host presence on the dashboard
dashboard_values = session.dashboard.read('NewHosts')['hosts']
displayed_host = [row for row in dashboard_values if row['Host'] == host_name][0]
assert api_values['operating_system.operating_system'] in displayed_host['Operating System']
assert displayed_host['Installed'] == 'N/A'
# update
session.host.update(host_name, {'host.name': new_name})
assert session.host.search(host_name)[0][0] == 'No Results'
assert session.host.search(new_host_name)[0]['Name'] == new_host_name
# delete
headers = session.all_hosts.get_displayed_table_headers()
stripped_headers = tuple(
header for header in headers if header is not None and header != 'Name'
)
wait_for(lambda: session.browser.refresh(), timeout=5)
# Make sure there is only Name column displayed
session.all_hosts.manage_table_columns({header: False for header in stripped_headers})
assert session.all_hosts.delete(new_host_name)
assert not target_sat.api.Host().search(query={'search': f'name="{new_host_name}"'})
def test_positive_read_from_details_page(target_sat, module_host_template, ui_user):
"""Create new Host and read all its content through details page
:id: ffba5d40-918c-440e-afbb-6b910db3a8fb
:expectedresults: Host is created and has expected content
"""
template = module_host_template
template.name = gen_string('alpha').lower()
host = template.create()
os_name = f'{template.operatingsystem.name} {template.operatingsystem.major}'
host_name = host.name
with target_sat.ui_session(user=ui_user.login, password=ui_user.password) as session:
assert session.host_new.search(host_name)[0]['Name'] == host_name
values = session.host_new.get_details(host_name)
assert values['overview']['host_status']['status'] == 'All statuses OK'
assert (
values['details']['system_properties']['sys_properties']['domain']
== template.domain.name
)
assert values['overview']['details']['details']['mac_address'] == host.mac
assert values['details']['operating_system']['architecture'] == template.architecture.name
assert values['details']['operating_system']['os'] == os_name
assert (
values['details']['system_properties']['sys_properties']['location']
== template.location.name
)
assert (
values['details']['system_properties']['sys_properties']['organization']
== template.organization.name
)
assert (
'Admin User' in values['details']['system_properties']['sys_properties']['host_owner']
)
def test_read_host_with_ics_domain(
session, module_host_template, smart_proxy_location, module_org, module_target_sat
):
"""Create new Host with ics domain name and verify that it can be read
:id: 54e3db92-16c2-412b-bf68-44d479c5987b
:steps:
1. Create a host with a domain ending in .ics
2. Read the host's details through the UI
:expectedresults: Host ending with ics domain name can be accessed through Host UI
:customerscenario: true
:Verifies: SAT-26202
"""
template = module_host_template
template.name = gen_string('alpha').lower()
ics_domain = module_target_sat.api.Domain(
location=[smart_proxy_location],
organization=[module_org],
name=gen_string('alpha').lower() + '.ics',
).create()
template.domain = ics_domain
host = template.create()
host_name = host.name
with module_target_sat.ui_session() as session:
session.organization.select(module_org.name)
session.location.select(smart_proxy_location.name)
values = session.host_new.get_details(host_name, widget_names='details')
assert (
values['details']['system_properties']['sys_properties']['domain']
== template.domain.name
)
assert values['details']['system_properties']['sys_properties']['name'] == host_name
def test_positive_read_from_edit_page(target_sat, ui_user, host_ui_options):
"""Create new Host and read all its content through edit page
:id: 758fcab3-b363-4bfc-8f5d-173098a7e72d
:expectedresults: Host is created and has expected content
"""
api_values, host_name = host_ui_options
with target_sat.ui_session(user=ui_user.login, password=ui_user.password) as session:
session.organization.select(api_values['host.organization'])
session.location.select(api_values['host.location'])
session.host.create(api_values)
assert session.host.search(host_name)[0]['Name'] == host_name
values = session.host.read(host_name)
assert values['host']['name'] == host_name.partition('.')[0]
assert values['host']['organization'] == api_values['host.organization']
assert (
values['operating_system']['architecture']
== api_values['operating_system.architecture']
)
assert (
values['operating_system']['operating_system']
== api_values['operating_system.operating_system']
)
assert values['operating_system']['media_type'] == 'All Media'
assert values['operating_system']['media'] == api_values['operating_system.media']
assert values['operating_system']['ptable'] == api_values['operating_system.ptable']
assert (
values['interfaces']['interfaces_list'][0]['Identifier']
== api_values['interfaces.interface.device_identifier']
)
assert values['interfaces']['interfaces_list'][0]['Type'] == 'Interface physical'
assert (
values['interfaces']['interfaces_list'][0]['MAC Address']
== api_values['interfaces.interface.mac']
)
assert values['interfaces']['interfaces_list'][0]['FQDN'] == host_name
assert session._user in values['additional_information']['owned_by']
assert values['additional_information']['enabled'] is True
def test_positive_assign_taxonomies(
module_org,
smart_proxy_location,
target_sat,
function_org,
function_location_with_org,
ui_user,
host_ui_options,
):
"""Ensure Host organization and Location can be assigned.
:id: 52466df5-6f56-4faa-b0f8-42b63731f494
:expectedresults: Host Assign Organization and Location actions are
working as expected.
"""
host = target_sat.api.Host(organization=module_org, location=smart_proxy_location).create()
with target_sat.ui_session(user=ui_user.login, password=ui_user.password) as session:
session.organization.select(host_ui_options[0]['host.organization'])
session.location.select(host_ui_options[0]['host.location'])
assert session.all_hosts.search(host.name)[0]['Name'] == host.name
session.all_hosts.change_associations_organization(
host_names=[host.name],
new_organization=function_org.name,
)
assert not target_sat.api.Host(organization=module_org).search(
query={'search': f'name="{host.name}"'}
)
assert (
len(
target_sat.api.Host(organization=function_org).search(
query={'search': f'name="{host.name}"'}
)
)
== 1
)
session.organization.select(org_name=function_org.name)
assert session.all_hosts.search(host.name)[0]['Name'] == host.name
session.all_hosts.change_associations_location(
host_names=[host.name],
new_location=function_location_with_org.name,
)
assert not target_sat.api.Host(location=smart_proxy_location).search(
query={'search': f'name="{host.name}"'}
)
assert (
len(
target_sat.api.Host(location=function_location_with_org).search(
query={'search': f'name="{host.name}"'}
)
)
== 1
)
session.location.select(loc_name=function_location_with_org.name)
assert session.all_hosts.search(host.name)[0]['Name'] == host.name
values = session.host_new.get_details(host.name)
assert (
values['details']['system_properties']['sys_properties']['location']
== function_location_with_org.name
)
assert (
values['details']['system_properties']['sys_properties']['organization']
== function_org.name
)
@pytest.mark.skipif(
(settings.ui.webdriver != 'chrome'), reason='Currently only chrome is supported'
)
def test_positive_export_selected_columns(request, target_sat, current_sat_location):
"""Select certain columns in the hosts table and check that they are exported in the CSV file.
:id: 2b65c1d6-0b94-11ef-a4b7-000c2989e153
:steps:
1. Select different columns to be displayed in the hosts table.
2. Export the hosts into CSV file.
:expectedresults: All columns selected in the UI table should be exported in the CSV file.
:BZ: 2167146
:Verifies: SAT-38427
:customerscenario: true
"""
columns = (
Box(ui='Power', csv='Power Status', displayed=True),
Box(ui='Name', csv='Name', displayed=True),
Box(ui='OS', csv='Operatingsystem', displayed=True),
Box(ui='Owner', csv='Owner', displayed=True),
Box(ui='Host group', csv='Hostgroup', displayed=True),
Box(ui='Boot time', csv='Reported Data - Boot Time', displayed=True),
Box(ui='Last report', csv='Last Report', displayed=True),
Box(ui='Comment', csv='Comment', displayed=True),
Box(ui='IPv4', csv='Ip', displayed=True),
Box(ui='IPv6', csv='Ip6', displayed=True),
Box(ui='MAC', csv='Mac', displayed=True),
Box(ui='Model', csv='Compute Resource Or Model', displayed=True),
Box(ui='Sockets', csv='Reported Data - Sockets', displayed=True),
Box(ui='Cores', csv='Reported Data - Cores', displayed=True),
Box(ui='RAM', csv='Reported Data - Ram', displayed=True),
Box(ui='Virtual', csv='Virtual', displayed=True),
Box(ui='Total disk space', csv='Reported Data - Disks Total', displayed=True),
Box(ui='Kernel version', csv='Reported Data - Kernel Version', displayed=True),
Box(ui='BIOS vendor', csv='Reported Data - Bios Vendor', displayed=True),
Box(ui='BIOS release date', csv='Reported Data - Bios Release Date', displayed=True),
Box(ui='BIOS version', csv='Reported Data - Bios Version', displayed=True),
Box(ui='RHEL Lifecycle status', csv='Rhel Lifecycle Status', displayed=True),
Box(ui='Installable updates', csv='Installable updates', displayed=False),
Box(ui='Last seen', csv='Last Checkin', displayed=True),
Box(ui='Lifecycle environment', csv='Lifecycle Environment', displayed=True),
Box(ui='Content view', csv='Content View', displayed=True),
Box(ui='Registered at', csv='Registered', displayed=True),
Box(ui='Recommendations', csv='Recommendations', displayed=True),
)
with target_sat.ui_session() as session:
session.location.select(loc_name=current_sat_location.name)
# Save original column settings
original_headers = session.all_hosts.get_displayed_table_headers()
original_columns = {header: True for header in original_headers if header is not None}
def restore_columns():
"""Restore original column settings after test"""
with target_sat.ui_session() as restore_session:
restore_session.location.select(loc_name=current_sat_location.name)
wait_for(lambda: restore_session.browser.refresh(), timeout=5)
all_possible_columns = {column.ui: False for column in columns}
all_possible_columns.update(original_columns)
restore_session.all_hosts.manage_table_columns(all_possible_columns)
request.addfinalizer(restore_columns)
# Set test-specific columns
session.all_hosts.manage_table_columns({column.ui: column.displayed for column in columns})
file_path = session.all_hosts.export()
with open(file_path, newline='') as fh:
csvfile = csv.DictReader(fh)
assert set(csvfile.fieldnames) == set(
[column.csv for column in columns if column.displayed]
)
def test_positive_create_with_inherited_params(
target_sat, function_org, function_location_with_org
):
"""Create a new Host in organization and location with parameters
:BZ: 1287223
:id: 628122f2-bda9-4aa1-8833-55debbd99072
:expectedresults: Host has inherited parameters from organization and
location
:CaseImportance: High
"""
org_param = dict(name=gen_string('alphanumeric'), value=gen_string('alphanumeric'))
loc_param = dict(name=gen_string('alphanumeric'), value=gen_string('alphanumeric'))
host_template = target_sat.api.Host(
organization=function_org, location=function_location_with_org
)
host_template.create_missing()
host = host_template.create()
host_name = host.name
with target_sat.ui_session() as session:
session.organization.select(org_name=function_org.name)
session.location.select(loc_name=function_location_with_org.name)
session.organization.update(function_org.name, {'parameters.resources': org_param})
session.location.update(
function_location_with_org.name, {'parameters.resources': loc_param}
)
session.organization.select(org_name=function_org.name)
session.location.select(loc_name=function_location_with_org.name)
values = session.host.read(host_name, 'parameters')
expected_params = {
(org_param['name'], org_param['value']),
(loc_param['name'], loc_param['value']),
}
assert expected_params.issubset(
{(param['name'], param['value']) for param in values['parameters']['global_params']}
)
def test_negative_delete_primary_interface(module_target_sat, host_ui_options, ui_user):
"""Attempt to delete primary interface of a host
:id: bc747e2c-38d9-4920-b4ae-6010851f704e
:customerscenario: true
:BZ: 1417119
:expectedresults: Interface was not deleted
"""
values, host_name = host_ui_options
interface_id = values['interfaces.interface.device_identifier']
with module_target_sat.ui_session(user=ui_user.login, password=ui_user.password) as session:
session.location.select(values['host.location'])
session.host.create(values)
with pytest.raises(DisabledWidgetError) as context:
session.host.delete_interface(host_name, interface_id)
assert 'Interface Delete button is disabled' in str(context.value)
def test_positive_view_hosts_with_non_admin_user(
test_name, module_org, smart_proxy_location, target_sat, host_ui_default
):
"""View hosts and content hosts as a non-admin user with only view_hosts, edit_hosts
and view_organization permissions
:BZ: 1642076, 1801630
:customerscenario: true
:id: 19a07026-0550-11ea-bfdc-98fa9b6ecd5a
:expectedresults: user with only view_hosts, edit_hosts and view_organization permissions
is able to read content hosts and hosts
"""
user_password = gen_string('alpha')
role = target_sat.api.Role(organization=[module_org]).create()
target_sat.api_factory.create_role_permissions(
role, {'Organization': ['view_organizations'], 'Host': ['view_hosts']}
)
user = target_sat.api.User(
role=[role],
admin=False,
password=user_password,
organization=[module_org],
location=[smart_proxy_location],
default_organization=module_org,
default_location=smart_proxy_location,
).create()
created_host = target_sat.api.Host(
location=smart_proxy_location, organization=module_org
).create()
with target_sat.ui_session(test_name, user=user.login, password=user_password) as session:
host = session.host_new.get_details(created_host.name, widget_names='breadcrumb')
assert host['breadcrumb'] == created_host.name
def test_positive_remove_parameter_non_admin_user(
test_name, module_org, smart_proxy_location, target_sat, host_ui_default, expected_permissions
):
"""Remove a host parameter as a non-admin user with enough permissions
:BZ: 1996035
:id: 598111c1-fdb6-42e9-8c28-fae999b5d112
:expectedresults: user with sufficient permissions may remove host
parameter
"""
user_password = gen_string('alpha')
parameter = {'name': gen_string('alpha'), 'value': gen_string('alpha')}
role = target_sat.api.Role(organization=[module_org]).create()
target_sat.api_factory.create_role_permissions(
role,
{
'Parameter': expected_permissions['Parameter'],
'Host': expected_permissions['Host'],
'Operatingsystem': ['view_operatingsystems'],
'Organization': expected_permissions['Organization'],
'Location': expected_permissions['Location'],
},
)
user = target_sat.api.User(
role=[role],
admin=False,
password=user_password,
organization=[module_org],
location=[smart_proxy_location],
default_organization=module_org,
default_location=smart_proxy_location,
).create()
host = target_sat.api.Host(
location=smart_proxy_location,
organization=module_org,
host_parameters_attributes=[parameter],
).create()
with target_sat.ui_session(
testname=test_name, user=user.login, password=user_password
) as session:
read_parameters = session.host_new.get_parameters(host.name)
parameters_table = read_parameters.get('parameters_table', [])
assert any(
row.get('Name') == parameter['name'] and row.get('Value') == parameter['value']
for row in parameters_table
), f'Parameter {parameter["name"]} not found in parameters table.'
session.host_new.delete_parameter(host.name, parameter['name'])
read_parameters = session.host_new.get_parameters(host.name)
parameters_table = read_parameters.get('parameters_table', [])
assert all(row.get('Name') != parameter['name'] for row in parameters_table), (
f'Parameter {parameter["name"]} still present after delete.'
)
def test_negative_remove_parameter_non_admin_user(
test_name, module_org, smart_proxy_location, module_target_sat, expected_permissions
):
"""Attempt to remove host parameter as a non-admin user with
insufficient permissions
:BZ: 1317868
:id: 78fd230e-2ec4-4158-823b-ddbadd5e232f
:customerscenario: true
:expectedresults: user with insufficient permissions is unable to
remove host parameter, 'Remove' link is not visible for him
"""
user_password = gen_string('alpha')
parameter = {'name': gen_string('alpha'), 'value': gen_string('alpha')}
role = module_target_sat.api.Role(organization=[module_org]).create()
module_target_sat.api_factory.create_role_permissions(
role,
{
'Parameter': ['view_params'],
'Host': ['view_hosts'],
'Operatingsystem': ['view_operatingsystems'],
'Organization': expected_permissions['Organization'],
'Location': expected_permissions['Location'],
},
)
user = module_target_sat.api.User(
role=[role],
admin=False,
password=user_password,
organization=[module_org],
location=[smart_proxy_location],
default_organization=module_org,
default_location=smart_proxy_location,
).create()
host = module_target_sat.api.Host(
content_facet_attributes={
'content_view_id': module_org.default_content_view.id,
'lifecycle_environment_id': module_org.library.id,
},
location=smart_proxy_location,
organization=module_org,
host_parameters_attributes=[parameter],
).create()
with module_target_sat.ui_session(
testname=test_name, user=user.login, password=user_password
) as session:
read_parameters = session.host_new.get_parameters(host.name)
parameters_table = read_parameters.get('parameters_table', [])
assert any(
row.get('Name') == parameter['name'] and row.get('Value') == parameter['value']
for row in parameters_table
), f'Parameter {parameter["name"]} not found in parameters table.'
with pytest.raises(NoSuchElementException):
session.host_new.delete_parameter(host.name, parameter['name'])
def test_positive_check_permissions_affect_create_procedure(
test_name, smart_proxy_location, target_sat, function_org, function_role, expected_permissions
):
"""Verify whether user permissions affect what entities can be selected
when host is created
:id: 4502f99d-86fb-4655-a9dc-b2612cf849c6
:customerscenario: true
:expectedresults: user with specific permissions can choose only
entities for create host procedure that he has access to
:BZ: 1293716
"""
# Create two lifecycle environments
lc_env = target_sat.api.LifecycleEnvironment(organization=function_org).create()
filter_lc_env = target_sat.api.LifecycleEnvironment(organization=function_org).create()
# Create two content views and promote them to one lifecycle
# environment which will be used in filter
cv = target_sat.api.ContentView(organization=function_org).create()
filter_cv = target_sat.api.ContentView(organization=function_org).create()
for content_view in [cv, filter_cv]:
content_view.publish()
content_view = content_view.read()
content_view.version[0].promote(data={'environment_ids': filter_lc_env.id})
# Create two host groups
hg = target_sat.api.HostGroup(
organization=[function_org], location=[smart_proxy_location]
).create()
filter_hg = target_sat.api.HostGroup(
organization=[function_org], location=[smart_proxy_location]
).create()
# Create lifecycle environment permissions and select one specific
# environment user will have access to
target_sat.api_factory.create_role_permissions(
function_role,
{
'Katello::KTEnvironment': [
'promote_or_remove_content_views_to_environments',
'view_lifecycle_environments',
]
},
# allow access only to the mentioned here environment
search=f'name = {filter_lc_env.name}',
)
# Add necessary permissions for content view as we did for lce
target_sat.api_factory.create_role_permissions(
function_role,
{
'Katello::ContentView': [
'promote_or_remove_content_views',
'view_content_views',
'publish_content_views',
]
},
# allow access only to the mentioned here cv
search=f'name = {filter_cv.name}',
)
# Add necessary permissions for hosts as we did for lce
target_sat.api_factory.create_role_permissions(
function_role,
{'Host': ['create_hosts', 'view_hosts']},
# allow access only to the mentioned here host group
search=f'hostgroup_fullname = {filter_hg.name}',
)
# Add necessary permissions for host groups as we did for lce
target_sat.api_factory.create_role_permissions(
function_role,
{'Hostgroup': ['view_hostgroups']},
# allow access only to the mentioned here host group
search=f'name = {filter_hg.name}',
)
# Add permissions for Organization and Location
target_sat.api_factory.create_role_permissions(
function_role,
{
'Organization': expected_permissions['Organization'],
'Location': expected_permissions['Location'],
},
)
# Create new user with a configured role
user_password = gen_string('alpha')
user = target_sat.api.User(
role=[function_role],
admin=False,
password=user_password,
organization=[function_org],
location=[smart_proxy_location],
default_organization=function_org,
default_location=smart_proxy_location,
).create()
host_fields = [
{'name': 'host.hostgroup', 'unexpected_value': hg.name, 'expected_value': filter_hg.name},
{
'name': 'host.lce',
'unexpected_value': lc_env.name,
'expected_value': filter_lc_env.name,
},
{
'name': 'host.content_view',
'unexpected_value': cv.name,
'expected_value': filter_cv.name,
# content view selection needs the right lce to be selected
'other_fields_values': {'host.lce': filter_lc_env.name},
},
]
with target_sat.ui_session(test_name, user=user.login, password=user_password) as session:
for host_field in host_fields:
values = {host_field['name']: host_field['unexpected_value']}
values.update(host_field.get('other_fields_values', {}))
with pytest.raises(NoSuchElementException) as context:
session.host.helper.read_create_view(values)
error_message = str(context.value)
assert host_field['unexpected_value'] in error_message
# After the NoSuchElementException from FilteredDropdown, airgun is not able to
# navigate to other locations, Note in normal situation we should send Escape key to
# browser.
session.browser.refresh()
values = {host_field['name']: host_field['expected_value']}
values.update(host_field.get('other_fields_values', {}))
create_values = session.host.helper.read_create_view(values, host_field['name'])
tab_name, field_name = host_field['name'].split('.')
assert create_values[tab_name][field_name] == host_field['expected_value']
def test_positive_search_by_parameter(session, module_org, smart_proxy_location, target_sat):
"""Search for the host by global parameter assigned to it
:id: 8e61127c-d0a0-4a46-a3c6-22d3b2c5457c