forked from SatelliteQE/robottelo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_registration.py
More file actions
892 lines (776 loc) · 33.5 KB
/
Copy pathtest_registration.py
File metadata and controls
892 lines (776 loc) · 33.5 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
"""Tests for registration.
:Requirement: Registration
:CaseComponent: Registration
:CaseAutomation: Automated
:CaseImportance: Critical
:Team: Proton
"""
from datetime import datetime
import re
from airgun.exceptions import DisabledWidgetError
from fauxfactory import gen_string
import pytest
from robottelo import constants
from robottelo.config import settings
from robottelo.constants import (
FAKE_1_CUSTOM_PACKAGE,
FAKE_7_CUSTOM_PACKAGE,
REPO_TYPE,
)
from robottelo.utils.issue_handlers import is_open
def test_positive_verify_default_values_for_global_registration(
module_target_sat,
default_org,
):
"""Check for all the Default values pre-populated in the global registration template
:id: 34122bf3-ae23-47ca-ba3d-da0653d8fd33
:expectedresults: Default fields in the form should be auto-populated
e.g. organization, location, rex, insights setup, etc
:steps:
1. Check for the default values in the global registration template
"""
module_target_sat.cli_factory.make_activation_key(
{'organization-id': default_org.id, 'name': gen_string('alpha')}
)
with module_target_sat.ui_session() as session:
cmd = session.host.get_register_command(
full_read=True,
)
assert cmd['general']['organization'] == 'Default Organization'
assert cmd['general']['location'] == 'Default Location'
assert cmd['general']['capsule'] == 'Nothing to select.'
assert cmd['general']['operating_system'] == ''
assert cmd['general']['host_group'] == 'Nothing to select.'
assert cmd['general']['insecure'] is False
assert cmd['advanced']['setup_rex'] == 'Inherit from host parameter (yes)'
assert cmd['advanced']['setup_insights'] == 'Inherit from host parameter (yes)'
assert cmd['advanced']['token_life_time'] == '4'
assert cmd['advanced']['rex_pull_mode'] == 'Inherit from host parameter (no)'
assert cmd['advanced']['update_packages'] is False
assert cmd['advanced']['ignore_error'] is False
assert cmd['advanced']['force'] is False
def test_positive_org_loc_change_for_registration(
module_activation_key,
module_sca_manifest_org,
module_location,
module_target_sat,
):
"""Changing the organization and location to check if correct org and loc is updated on the global registration page as well as in the command
:id: e83ed6bc-ceae-4021-87fe-3ecde1cbf347
:expectedresults: organization and location is updated correctly on the global registration page as well as in the command.
:CaseImportance: Medium
"""
new_org = module_target_sat.api.Organization().create()
new_loc = module_target_sat.api.Location().create()
ak = module_target_sat.api.ActivationKey(organization=new_org).create()
with module_target_sat.ui_session() as session:
session.organization.select(org_name=module_sca_manifest_org.name)
session.location.select(loc_name=module_location.name)
cmd = session.host.get_register_command(
{
'general.activation_keys': module_activation_key.name,
'general.insecure': True,
}
)
expected_pairs = [
f'organization_id={module_sca_manifest_org.id}',
f'location_id={module_location.id}',
]
for pair in expected_pairs:
assert pair in cmd
# changing the org and loc to check if correct org and loc is updated on the registration command
session.organization.select(org_name=new_org.name)
session.location.select(loc_name=new_loc.name)
cmd = session.host.get_register_command(
{
'general.activation_keys': ak.name,
'general.insecure': True,
}
)
expected_pairs = [
f'organization_id={new_org.id}',
f'location_id={new_loc.id}',
]
for pair in expected_pairs:
assert pair in cmd
def test_negative_global_registration_without_ak(
module_target_sat, function_org, function_location
):
"""Attempt to register a host without ActivationKey
:id: 34122bf3-ae23-47ca-ba3d-da0653d8fd36
:expectedresults: Generate command is disabled without ActivationKey
"""
with module_target_sat.ui_session() as session:
session.organization.select(org_name=function_org.name)
session.location.select(loc_name=function_location.name)
with pytest.raises(DisabledWidgetError) as context:
session.host.get_register_command()
assert 'Generate registration command button is disabled' in str(context.value)
@pytest.mark.e2e
@pytest.mark.no_containers
@pytest.mark.pit_client
@pytest.mark.rhel_ver_match(r'^(?!.*fips).*$')
def test_positive_global_registration_end_to_end(
module_activation_key,
module_org,
smart_proxy_location,
default_os,
default_smart_proxy,
rhel_contenthost,
module_target_sat,
):
"""Host registration form produces a correct registration command and host is
registered successfully with it, remote execution and insights are set up
:id: a02658bf-097e-47a8-8472-5d9f649ba07a
:customerscenario: true
:BZ: 1993874
:expectedresults: Host is successfully registered, remote execution and insights
client work out of the box
:parametrized: yes
"""
# Adding IPv6 proxy for IPv6 communication
rhel_contenthost.enable_ipv6_dnf_and_rhsm_proxy()
# make sure global parameters for rex and insights are set to true
insights_cp = (
module_target_sat.api.CommonParameter()
.search(query={'search': 'name=host_registration_insights'})[0]
.read()
)
rex_cp = (
module_target_sat.api.CommonParameter()
.search(query={'search': 'name=host_registration_remote_execution'})[0]
.read()
)
if not insights_cp.value:
module_target_sat.api.CommonParameter(id=insights_cp.id, value=1).update(['value'])
if not rex_cp.value:
module_target_sat.api.CommonParameter(id=rex_cp.id, value=1).update(['value'])
# rex interface
iface = 'enp3s0' if rhel_contenthost.os_version.major >= 10 else 'eth0'
# fill in the global registration form
with module_target_sat.ui_session() as session:
session.organization.select(org_name=module_org.name)
session.location.select(loc_name=smart_proxy_location.name)
cmd = session.host.get_register_command(
{
'general.activation_keys': module_activation_key.name,
'advanced.update_packages': True,
'advanced.rex_interface': iface,
'general.insecure': True,
}
)
expected_pairs = [
f'organization_id={module_org.id}',
f'activation_keys={module_activation_key.name}',
f'location_id={smart_proxy_location.id}',
f'{default_smart_proxy.name}',
'insecure',
'update_packages=true',
]
for pair in expected_pairs:
assert pair in cmd
# rhel repo required for insights client installation,
# syncing it to the satellite would take too long
rhelver = rhel_contenthost.os_version.major
if rhelver > 7:
rhel_contenthost.create_custom_repos(**settings.repos[f'rhel{rhelver}_os'])
else:
rhel_contenthost.create_custom_repos(
**{f'rhel{rhelver}_os': settings.repos[f'rhel{rhelver}_os']}
)
# make sure there will be package available for update
if rhel_contenthost.os_version.major == '6':
package = FAKE_1_CUSTOM_PACKAGE
repo_url = settings.repos.yum_1['url']
else:
package = FAKE_7_CUSTOM_PACKAGE
repo_url = settings.repos.yum_3['url']
rhel_contenthost.create_custom_repos(fake_yum=repo_url)
rhel_contenthost.execute(f"yum install -y {package}")
# run curl
result = rhel_contenthost.execute(cmd)
assert result.status == 0
result = rhel_contenthost.execute('subscription-manager identity')
assert result.status == 0
# Assert that a yum update was made this day ("Update" or "I, U" in history)
timezone_offset = rhel_contenthost.execute('date +"%:z"').stdout.strip()
tzinfo = datetime.strptime(timezone_offset, '%z').tzinfo
result = rhel_contenthost.execute('yum history | grep -E "I|U"')
assert result.status == 0
assert datetime.now(tzinfo).strftime('%Y-%m-%d') in result.stdout
# Set "Connect to host using IP address"
module_target_sat.api.Parameter(
host=rhel_contenthost.hostname,
name='remote_execution_connect_by_ip',
parameter_type='boolean',
value='True',
).create()
# run insights-client via REX
command = "insights-client --status"
invocation_command = module_target_sat.cli_factory.job_invocation(
{
'job-template': 'Run Command - Script Default',
'inputs': f'command={command}',
'search-query': f"name ~ {rhel_contenthost.hostname}",
}
)
# results provide all info but job invocation might not be finished yet
result = (
module_target_sat.api.JobInvocation()
.search(
query={'search': f'id={invocation_command["id"]} and host={rhel_contenthost.hostname}'}
)[0]
.read()
)
# make sure that task is finished
task_result = module_target_sat.wait_for_tasks(
search_query=(f'id = {result.task.id}'), search_rate=2, max_tries=60
)
assert task_result[0].result == 'success'
host = (
module_target_sat.api.Host()
.search(query={'search': f'name={rhel_contenthost.hostname}'})[0]
.read()
)
for interface in host.interface:
interface_result = module_target_sat.api.Interface(host=host.id).search(
query={'search': f'{interface.id}'}
)[0]
# more interfaces can be inside the host
if interface_result.identifier == iface:
assert interface_result.execution
def test_global_registration_form_populate(
function_sca_manifest_org,
function_activation_key,
default_architecture,
default_os,
target_sat,
):
"""Host registration form should be populated automatically based on the host-group
:id: b949e010-36b8-48b8-9907-36138342c72b
:expectedresults: Some of the fields in the form should be populated based on host-group
e.g. activation key, operating system, life-cycle environment, host parameters for
remote-execution, insights setup.
:steps:
1. create and sync repository
2. create the content view and activation-key
3. create the host-group with activation key, operating system, host-parameters
4. create a nested host-group to inherit values
5. open the global registration form and select the same host-group
6. check host registration form should be populated automatically based on the host-group
:BZ: 2056469, 1994654, 1955421
:customerscenario: true
"""
hg_name = gen_string('alpha')
hg_nested_name = gen_string('alpha')
iface = gen_string('alpha')
group_params = {'name': 'host_packages', 'value': constants.FAKE_0_CUSTOM_PACKAGE}
parent_hg = target_sat.api.HostGroup(
name=hg_name,
organization=[function_sca_manifest_org],
lifecycle_environment=function_sca_manifest_org.library.id,
architecture=default_architecture,
operatingsystem=default_os,
content_view=function_sca_manifest_org.default_content_view.id,
group_parameters_attributes=[group_params],
).create()
target_sat.api.HostGroup(name=hg_nested_name, parent=parent_hg).create()
new_org = target_sat.api.Organization().create()
new_ak = target_sat.api.ActivationKey(
content_view=new_org.default_content_view,
environment=target_sat.api.LifecycleEnvironment(id=new_org.library.id),
organization=new_org,
).create()
with target_sat.ui_session() as session:
session.organization.select(org_name=function_sca_manifest_org.name)
session.hostgroup.update(
f'{hg_name}/{hg_nested_name}',
{
'activation_keys.activation_keys': function_activation_key.name,
},
)
cmd = session.host.get_register_command(
{
'general.host_group': f'{hg_name}/{hg_nested_name}',
'advanced.rex_interface': iface,
'general.insecure': True,
},
full_read=True,
)
assert hg_nested_name in cmd['general']['host_group']
assert function_activation_key.name in cmd['general']['activation_key_helper']
assert constants.FAKE_0_CUSTOM_PACKAGE in cmd['advanced']['install_packages_helper']
session.organization.select(org_name=new_org.name)
session.browser.refresh()
registration_opts = {
'general.insecure': True,
'advanced.force': True,
}
# Select activation key explicitly due to SAT-27348
if is_open('SAT-27348'):
registration_opts['general.activation_keys'] = new_ak.name
cmd = session.host.get_register_command(
registration_opts,
full_read=True,
)
assert new_org.name in cmd['general']['organization']
assert new_ak.name in cmd['general']['activation_keys']
@pytest.mark.pit_client
@pytest.mark.rhel_ver_list([settings.content_host.default_rhel_version])
@pytest.mark.no_containers
def test_global_registration_with_gpg_repo_and_default_package(
module_activation_key, rhel_contenthost, target_sat, module_org
):
"""Host registration form produces a correct registration command and host is
registered successfully with gpg repo enabled and have default package
installed.
:id: b5738b20-e281-4d0b-ac78-dcdc177b8c9f
:expectedresults: Host is successfully registered, gpg repo is enabled
and default package is installed.
:steps:
1. create and sync repository
2. create the content view and activation-key
3. update the 'host_packages' parameter in organization with package name e.g. zsh
4. open the global registration form and update the gpg repo and key
5. check host is registered successfully with installed same package
6. check gpg repo is exist in registered host
:parametrized: yes
"""
# Adding IPv6 proxy for IPv6 communication
rhel_contenthost.enable_ipv6_dnf_and_rhsm_proxy()
client = rhel_contenthost
repo_name = 'foreman_register'
repo_url = settings.repos.gr_yum_repo.url
repo_gpg_url = settings.repos.gr_yum_repo.gpg_url
with target_sat.ui_session() as session:
session.organization.select(org_name=module_org.name)
cmd = session.host.get_register_command(
{
'general.activation_keys': module_activation_key.name,
'general.insecure': True,
'advanced.force': True,
'advanced.install_packages': 'vim-enhanced zsh',
'advanced.repository': repo_url,
'advanced.repository_gpg_key_url': repo_gpg_url,
}
)
# rhel repo required for insights client installation,
# syncing it to the satellite would take too long
rhelver = client.os_version.major
if rhelver > 7:
repos = settings.repos[f'rhel{rhelver}_os']
else:
repos = {
'rhel7_os': settings.repos['rhel7_os'],
'rhel7_extras': settings.repos['rhel7_extras'],
}
client.create_custom_repos(**repos)
# run curl
result = client.execute(cmd)
assert result.status == 0
result = client.execute('dnf list installed | grep -E "vim-enhanced|zsh"')
assert result.status == 0
assert all(pkg in result.stdout for pkg in ['vim-enhanced', 'zsh'])
result = client.execute('yum -v repolist')
assert result.status == 0
assert repo_name in result.stdout
assert repo_url in result.stdout
@pytest.mark.rhel_ver_list([settings.content_host.default_rhel_version])
def test_global_re_registration_host_with_force_ignore_error_options(
module_activation_key, rhel_contenthost, module_target_sat, module_org
):
"""If the ignore_error and force checkbox is checked then registered host can
get re-registered without any error.
:id: 8f0ecc13-5d18-4adb-acf5-3f3276dccbb7
:expectedresults: Verify the force and ignore checkbox options
:steps:
1. create and sync repository
2. create the content view and activation-key
3. open the global registration form and select --force and --Ignore Errors option
4. registered the host with generated curl command
5. re-register the same host again and check it is getting registered
:parametrized: yes
"""
client = rhel_contenthost
with module_target_sat.ui_session() as session:
session.organization.select(org_name=module_org.name)
cmd = session.host.get_register_command(
{
'general.activation_keys': module_activation_key.name,
'general.insecure': True,
'advanced.force': True,
'advanced.ignore_error': True,
}
)
client.execute(cmd)
result = client.execute('subscription-manager identity')
assert result.status == 0
# rerun the register command
client.execute(cmd)
result = client.execute('subscription-manager identity')
assert result.status == 0
@pytest.mark.rhel_ver_list([settings.content_host.default_rhel_version])
def test_global_registration_token_restriction(
module_activation_key, rhel_contenthost, module_target_sat, module_org
):
"""Global registration token should be only used for registration call, it
should be restricted for any other api calls.
:id: 4528b5c6-0a6d-40cd-857a-68b76db2179b
:expectedresults: global registration token should be restricted for any api calls
other than the registration
:steps:
1. open the global registration form and generate the curl token
2. use that curl token to execute other api calls e.g. GET /hosts, /users
:parametrized: yes
"""
client = rhel_contenthost
with module_target_sat.ui_session() as session:
session.organization.select(org_name=module_org.name)
cmd = session.host.get_register_command(
{
'general.activation_keys': module_activation_key.name,
'general.insecure': True,
}
)
pattern = re.compile("Authorization.*(?=')")
auth_header = re.search(pattern, cmd).group()
# build curl
curl_users = f'curl -X GET -k -H {auth_header} -i {module_target_sat.url}/api/users/'
curl_hosts = f'curl -X GET -k -H {auth_header} -i {module_target_sat.url}/api/hosts/'
for curl_cmd in (curl_users, curl_hosts):
result = client.execute(curl_cmd)
assert result.status == 0
assert 'Unable to authenticate user' in result.stdout
@pytest.mark.rhel_ver_list([settings.content_host.default_rhel_version])
def test_positive_host_registration_with_non_admin_user(
test_name,
module_sca_manifest_org,
module_location,
module_target_sat,
rhel_contenthost,
module_activation_key,
):
"""Register hosts from a non-admin user with only register_hosts, edit_hosts
and view_organization permissions
:id: 35458bbc-4556-41b9-ba26-ae0b15179731
:expectedresults: User with register hosts permission able to register hosts.
"""
user_password = gen_string('alpha')
org = module_sca_manifest_org
role = module_target_sat.api.Role(organization=[org]).create()
user_permissions = {
'Organization': ['view_organizations'],
'Host': ['view_hosts'],
}
module_target_sat.api_factory.create_role_permissions(role, user_permissions)
user = module_target_sat.api.User(
role=[role],
admin=False,
password=user_password,
organization=[org],
location=[module_location],
default_organization=org,
default_location=module_location,
).create()
role = module_target_sat.cli.Role.info({'name': 'Register hosts'})
module_target_sat.cli.User.add_role({'id': user.id, 'role-id': role['id']})
with module_target_sat.ui_session(
test_name, user=user.login, password=user_password
) as session:
cmd = session.host_new.get_register_command(
{
'general.insecure': True,
'general.activation_keys': module_activation_key.name,
'advanced.setup_insights': 'No (override)',
}
)
result = rhel_contenthost.execute(cmd)
assert result.status == 0, f'Failed to register host: {result.stderr}'
# Verify server.hostname and server.port from subscription-manager config
assert (
module_target_sat.hostname == rhel_contenthost.subscription_config['server']['hostname']
)
assert rhel_contenthost.subscription_config['server']['port'] == constants.CLIENT_PORT
def test_positive_global_registration_form(
module_activation_key, module_org, smart_proxy_location, default_os, target_sat
):
"""Host registration form produces a correct curl command for various inputs
:id: f81c2ec4-85b1-4372-8e63-464ddbf70296
:customerscenario: true
:expectedresults: The curl command contains all required parameters
"""
# rex and insights parameters are only specified in curl when differing from
# inherited parameters
result = (
target_sat.api.CommonParameter()
.search(query={'search': 'name=host_registration_remote_execution'})[0]
.read()
)
rex_value = not result.value
result = (
target_sat.api.CommonParameter()
.search(query={'search': 'name=host_registration_insights'})[0]
.read()
)
insights_value = not result.value
hostgroup = target_sat.api.HostGroup(
organization=[module_org], location=[smart_proxy_location]
).create()
iface = 'eth0'
with target_sat.ui_session() as session:
session.organization.select(org_name=module_org.name)
session.location.select(loc_name=smart_proxy_location.name)
cmd = session.host.get_register_command(
{
'advanced.setup_insights': 'Yes (override)' if insights_value else 'No (override)',
'advanced.setup_rex': 'Yes (override)' if rex_value else 'No (override)',
'general.insecure': True,
'general.host_group': hostgroup.name,
'general.operating_system': default_os.title,
'general.activation_keys': module_activation_key.name,
'advanced.update_packages': True,
'advanced.rex_interface': iface,
}
)
expected_pairs = [
f'organization_id={module_org.id}',
f'activation_keys={module_activation_key.name}',
f'hostgroup_id={hostgroup.id}',
f'location_id={smart_proxy_location.id}',
f'operatingsystem_id={default_os.id}',
f'remote_execution_interface={iface}',
f'setup_insights={"true" if insights_value else "false"}',
f'setup_remote_execution={"true" if rex_value else "false"}',
f'{target_sat.hostname}',
'insecure',
'update_packages=true',
]
for pair in expected_pairs:
assert pair in cmd
@pytest.mark.rhel_ver_list([settings.content_host.default_rhel_version])
def test_global_registration_with_capsule_host(
capsule_configured,
rhel_contenthost,
module_org,
module_location,
module_product,
default_os,
module_lce_library,
target_sat,
):
"""Host registration form produces a correct registration command and host is
registered successfully with selected capsule from form.
:id: 6356c6d0-ee45-4ad7-8a0e-484d3490bc58
:expectedresults: Host is successfully registered with capsule host,
remote execution and insights client work out of the box
:steps:
1. create and sync repository
2. create the content view and activation-key
3. integrate capsule and sync content
4. open the global registration form and select the same capsule
5. check host is registered successfully with selected capsule
:parametrized: yes
:CaseAutomation: Automated
"""
client = rhel_contenthost
repo = target_sat.api.Repository(
url=settings.repos.yum_1.url,
content_type=REPO_TYPE['yum'],
product=module_product,
).create()
# Sync all repositories in the product
module_product.sync()
capsule = target_sat.api.Capsule(id=capsule_configured.nailgun_capsule.id).search(
query={'search': f'name={capsule_configured.hostname}'}
)[0]
module_org = target_sat.api.Organization(id=module_org.id).read()
module_org.smart_proxy.append(capsule)
module_location = target_sat.api.Location(id=module_location.id).read()
module_location.smart_proxy.append(capsule)
module_org.update(['smart_proxy'])
module_location.update(['smart_proxy'])
# Associate the lifecycle environment with the capsule
capsule.content_add_lifecycle_environment(data={'environment_id': module_lce_library.id})
result = capsule.content_lifecycle_environments()
# TODO result is not used, please add assert once you fix the test
# Create a content view with the repository
cv = target_sat.api.ContentView(organization=module_org, repository=[repo]).create()
# Publish new version of the content view
cv.publish()
cv = cv.read()
assert len(cv.version) == 1
activation_key = target_sat.api.ActivationKey(
content_view=cv, environment=module_lce_library, organization=module_org
).create()
# Assert that a task to sync lifecycle environment to the capsule
# is started (or finished already)
sync_status = capsule.content_get_sync()
assert len(sync_status['active_sync_tasks']) >= 1 or sync_status['last_sync_time']
# Wait till capsule sync finishes
for task in sync_status['active_sync_tasks']:
target_sat.api.ForemanTask(id=task['id']).poll()
with target_sat.ui_session() as session:
session.organization.select(org_name=module_org.name)
session.location.select(loc_name=module_location.name)
cmd = session.host.get_register_command(
{
'general.organization': module_org.name,
'general.location': module_location.name,
'general.operating_system': default_os.title,
'general.capsule': capsule_configured.hostname,
'general.activation_keys': activation_key.name,
'general.insecure': True,
}
)
client.create_custom_repos(rhel7=settings.repos.rhel7_os)
# run curl
client.execute(cmd)
result = client.execute('subscription-manager identity')
assert result.status == 0
assert module_lce_library.name in result.stdout
assert module_org.name in result.stdout
@pytest.mark.rhel_ver_match('[^6].*')
def test_subscription_manager_install_from_repository(
module_activation_key, module_os, rhel_contenthost, target_sat, module_org
):
"""Host registration form produces a correct registration command and
subscription-manager can be installed from a custom repository before
registration is completed.
:id: b7a44f32-90b2-4fd6-b65b-5a3d2a5c5deb
:customerscenario: true
:expectedresults: Host is successfully registered, repo is enabled
on advanced tab and subscription-manager is installed.
:steps:
1. Create activation-key
2. Open the global registration form, add repo and activation key
3. Add 'subscription-manager' to install packages field
4. Check subscription-manager was installed from repo_name
:parametrized: yes
:BZ: 1923320
"""
# Adding IPv6 proxy for IPv6 communication
rhel_contenthost.enable_ipv6_dnf_and_rhsm_proxy()
client = rhel_contenthost
repo_name = 'foreman_register'
rhel_ver = rhel_contenthost.os_version.major
repo_url = settings.repos.get(f'rhel{rhel_ver}_os')
if isinstance(repo_url, dict):
repo_url = repo_url['baseos']
# Ensure subs-man is installed from repo_name by removing existing package.
result = client.execute('rpm --erase --nodeps subscription-manager')
assert result.status == 0
with target_sat.ui_session() as session:
session.organization.select(org_name=module_org.name)
cmd = session.host.get_register_command(
{
'general.operating_system': module_os.title,
'general.activation_keys': module_activation_key.name,
'general.insecure': True,
'advanced.force': True,
'advanced.install_packages': 'subscription-manager',
'advanced.repository': repo_url,
'advanced.setup_insights': 'No (override)',
}
)
# run curl
result = client.execute(cmd)
assert result.status == 0
result = client.execute('yum repolist')
assert repo_name in result.stdout
assert result.status == 0
@pytest.mark.rhel_ver_list([settings.content_host.default_rhel_version])
def test_registering_with_title_using_global_registration_parameter(
module_target_sat,
rhel_contenthost,
module_sca_manifest_org,
module_location,
module_activation_key,
default_os,
):
"""Verify after updating the curl command that the parameter with the name host is registered successfully. Also, verify that the host is successfully registered with setup_insights=true and does not remain in build mode.
:id: 60061546-c3b2-11ef-b570-6c240829b295
:expectedresults:
1. The host is successfully registering using the label/name instead of the ID, and this applies to the following parameters:
1. Organization
2. Location
3. Host group
4. Operating System
2. No options should leave the host in build mode at the end of successful registration, specifically not insights configuration/setup.
:steps:
1. Generate a curl command which should have setup_insights=true in it
2. Before registering the host, update the command
3. Register host with the updated command
:Verifies: SAT-28832, SAT-26417
:customerscenario: true
"""
rhel_ver = rhel_contenthost.os_version.major
repo_url = getattr(settings.repos, f'rhel{rhel_ver}_os', None)
rhel_contenthost.create_custom_repos(**repo_url)
hostgroup = module_target_sat.api.HostGroup(
organization=[module_sca_manifest_org], location=[module_location]
).create()
with module_target_sat.ui_session() as session:
session.organization.select(module_sca_manifest_org.name)
session.location.select(module_location.name)
cmd = session.host.get_register_command(
{
'general.host_group': hostgroup.name,
'general.operating_system': default_os.title,
'general.activation_keys': module_activation_key.name,
'advanced.setup_insights': 'Yes (override)',
'general.insecure': True,
}
)
result = cmd[cmd.find('hostgroup_id=') : cmd.find('&update_packages=')]
if ' ' in default_os.title:
new_os_title = default_os.title.replace(' ', '+')
new_data = f'hostgroup={hostgroup.name}&location={module_location.name}&operatingsystem={new_os_title}&organization={module_sca_manifest_org.name}'
updated_cmd = cmd.replace(result, new_data)
assert new_data in updated_cmd
result = rhel_contenthost.execute(updated_cmd)
assert result.status == 0, f'Failed to register host: {result.stderr}'
assert (
f'Host {[rhel_contenthost.hostname]} successfully configured, but failed to set built status.'
not in result.stdout
)
status = session.host_new.get_host_statuses(rhel_contenthost.hostname)
assert status['Build']['Status'] == 'Installed'
assert status['Red Hat Lightspeed']['Status'] == 'Reporting'
facts = session.host_new.get_host_facts(rhel_contenthost.hostname, 'insights_client')
for fact in facts:
assert (
fact['Name'] == 'insights_clienthostname'
if fact['Name'] == 'insights_clienthostname'
else 'incorrect name'
)
assert (
fact['Value'] == rhel_contenthost.hostname
if fact['Value'] == rhel_contenthost.hostname
else 'incorrect value'
)
assert 'Successfully updated the system facts' in result.stdout
def test_negative_register_page_access_to_non_admin(request, module_target_sat):
"""Check non admin users can't access Hosts -> Register tab
:id: 89aff060-3308-11f0-bfec-6c240829b295
:customerscenario: true
:Verifies: SAT-31655
:customerscenario: true
:steps:
1. Login with non admin user
2. Navigate to /hosts/register in url
3. Check message permission denied is present
:expectedresults: Non-admin users should not have access to the registration page by navigating to /hosts/register via the URL.
"""
login = gen_string('alpha')
password = gen_string('alpha')
user = module_target_sat.api.User(admin=False, login=login, password=password).create()
request.addfinalizer(user.delete)
with module_target_sat.ui_session(
user=login, password=password, url='/hosts/register'
) as session:
result = session.host.permission_denied()
assert (
result == 'Permission Denied You are not authorized to perform this action. '
'Please request one of the required permissions listed below '
'from a Satellite administrator: register_hosts'
)