forked from SatelliteQE/robottelo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_hostgroup.py
More file actions
860 lines (699 loc) · 33.8 KB
/
Copy pathtest_hostgroup.py
File metadata and controls
860 lines (699 loc) · 33.8 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
"""Tests for the ``hostgroups`` paths.
:Requirement: Hostgroup
:CaseAutomation: Automated
:CaseComponent: HostGroup
:Team: Proton
:CaseImportance: High
"""
from copy import copy
from random import randint
from fauxfactory import gen_string
from nailgun import client, entity_fields
import pytest
from requests.exceptions import HTTPError
from robottelo.config import get_credentials
from robottelo.constants import DEFAULT_ARCHITECTURE, REPOS
from robottelo.utils.datafactory import (
invalid_values_list,
parametrized,
valid_hostgroups_list,
)
@pytest.fixture
def hostgroup(module_org, module_location, module_target_sat):
return module_target_sat.api.HostGroup(
location=[module_location], organization=[module_org]
).create()
@pytest.fixture
def puppet_hostgroup(module_puppet_org, module_puppet_loc, session_puppet_enabled_sat):
return session_puppet_enabled_sat.api.HostGroup(
location=[module_puppet_loc], organization=[module_puppet_org]
).create()
class TestHostGroup:
"""Tests for host group entity."""
@pytest.mark.upgrade
def test_inherit_puppetclass(self, session_puppet_enabled_sat):
"""Host that created from HostGroup entity with PuppetClass
assigned to it should inherit such puppet class information under
'all_puppetclasses' field
:id: 7b840f3d-413c-40bb-9a7d-cd9dad3c0737
:expectedresults: Host inherited 'all_puppetclasses' details from
HostGroup that was used for such Host create procedure
:BZ: 1107708, 1222118, 1487586
"""
# Creating entities like organization, content view and lifecycle_env
# with not utf-8 names for easier interaction with puppet environment
# further in test
org = session_puppet_enabled_sat.api.Organization(name=gen_string('alpha')).create()
location = session_puppet_enabled_sat.api.Location(organization=[org]).create()
# Working with 'api_test_classparameters' module as we know for sure that it contains
# at least few puppet classes, the name of the repo is the same as the name of puppet_class
repo = puppet_class = 'api_test_classparameters'
env_name = session_puppet_enabled_sat.create_custom_environment(repo=repo)
content_view = session_puppet_enabled_sat.api.ContentView(
name=gen_string('alpha'), organization=org
).create()
content_view.publish()
content_view = content_view.read()
lc_env = session_puppet_enabled_sat.api.LifecycleEnvironment(
name=gen_string('alpha'), organization=org
).create()
content_view.version[0].promote(data={'environment_ids': lc_env.id, 'force': False})
content_view = content_view.read()
assert len(content_view.version) == 1
# Get environments that contains chosen puppet module
environment = session_puppet_enabled_sat.api.Environment().search(
query={'search': f'name={env_name}'}
)
assert len(environment) == 1
environment = environment[0]
environment.location = [location]
environment.organization = [org]
environment.update()
# Create a host group and it dependencies.
mac = entity_fields.MACAddressField().gen_value()
root_pass = entity_fields.StringField(length=(8, 30)).gen_value()
domain = session_puppet_enabled_sat.api.Domain().create()
architecture = session_puppet_enabled_sat.api.Architecture().create()
ptable = session_puppet_enabled_sat.api.PartitionTable().create()
operatingsystem = session_puppet_enabled_sat.api.OperatingSystem(
architecture=[architecture], ptable=[ptable]
).create()
medium = session_puppet_enabled_sat.api.Media(operatingsystem=[operatingsystem]).create()
hostgroup = session_puppet_enabled_sat.api.HostGroup(
architecture=architecture,
domain=domain,
environment=environment,
location=[location.id],
medium=medium,
name=gen_string('alpha'),
operatingsystem=operatingsystem,
organization=[org.id],
ptable=ptable,
).create()
assert len(hostgroup.read_json()['all_puppetclasses']) == 0
# Get puppet class id for ntp module
response = client.get(
environment.path('self') + '/puppetclasses',
auth=get_credentials(),
verify=False,
)
response.raise_for_status()
results = response.json()['results']
puppet_class_id = results[puppet_class][0]['id']
# Assign puppet class
client.post(
hostgroup.path('self') + '/puppetclass_ids',
data={'puppetclass_id': puppet_class_id},
auth=get_credentials(),
verify=False,
).raise_for_status()
hostgroup_attrs = hostgroup.read_json()
assert len(hostgroup_attrs['all_puppetclasses']) == 1
assert hostgroup_attrs['all_puppetclasses'][0]['name'] == puppet_class
# Create Host entity using HostGroup
host = session_puppet_enabled_sat.api.Host(
hostgroup=hostgroup,
mac=mac,
root_pass=root_pass,
environment=environment,
location=location,
organization=org,
content_facet_attributes={
'content_view_id': content_view.id,
'lifecycle_environment_id': lc_env.id,
},
name=gen_string('alpha'),
).create(False)
host_attrs = host.read_json()
assert len(host_attrs['all_puppetclasses']) == 1
assert host_attrs['all_puppetclasses'][0]['name'] == puppet_class
@pytest.mark.upgrade
def test_rebuild_config(self, module_org, module_location, hostgroup, module_target_sat):
"""'Rebuild orchestration config' of an existing host group
:id: 58bf7015-18fc-4d25-9b64-7f2dd6dde425
:expectedresults: rebuild hostgroup orchestration configs successfully.
:CaseImportance: Medium
"""
lce = module_target_sat.api.LifecycleEnvironment(organization=module_org).create()
content_view = module_target_sat.api.ContentView(organization=module_org).create()
content_view.publish()
content_view = content_view.read()
content_view.version[0].promote(data={'environment_ids': lce.id, 'force': False})
module_target_sat.api.Host(
hostgroup=hostgroup,
location=module_location,
organization=module_org,
managed=True,
content_facet_attributes={
'content_view_id': content_view.id,
'lifecycle_environment_id': lce.id,
},
).create()
# TODO: use host that can also rebuild the SSH_Nic, SSH_Host, and Content_Host_Status
# config
assert (
hostgroup.rebuild_config(data={'only': 'DNS,DHCP,TFTP'})['message']
== 'Configuration successfully rebuilt.'
)
@pytest.mark.parametrize('name', **parametrized(valid_hostgroups_list()))
def test_positive_create_with_name(self, name, module_org, module_location, module_target_sat):
"""Create a hostgroup with different names
:id: fd5d353c-fd0c-4752-8a83-8f399b4c3416
:parametrized: yes
:expectedresults: A hostgroup is created with expected name
:CaseImportance: Critical
"""
hostgroup = module_target_sat.api.HostGroup(
location=[module_location], name=name, organization=[module_org]
).create()
assert name == hostgroup.name
def test_positive_clone(self, hostgroup, target_sat):
"""Create a hostgroup by cloning an existing one
:id: 44ac8b3b-9cb0-4a9e-ad9b-2c67b2411922
:expectedresults: A hostgroup is cloned with same parameters
:CaseImportance: Critical
"""
hostgroup_cloned_name = gen_string('alpha')
hostgroup_cloned = target_sat.api.HostGroup(id=hostgroup.id).clone(
data={'name': hostgroup_cloned_name}
)
hostgroup_origin = hostgroup.read_json()
# remove unset and unique values before comparison
unique_keys = ('updated_at', 'created_at', 'title', 'id', 'name')
hostgroup_cloned_reduced = {
k: v
for k, v in hostgroup_cloned.items()
if k in hostgroup_origin and k not in unique_keys
}
assert hostgroup_cloned_reduced.items() <= hostgroup_origin.items()
def test_positive_create_with_properties(
self, module_puppet_org, module_puppet_loc, session_puppet_enabled_sat
):
"""Create a hostgroup with properties
:id: 528afd01-356a-4082-9e88-a5b2a715a792
:expectedresults: A hostgroup is created with expected properties,
updated and deleted
:CaseImportance: High
"""
env = session_puppet_enabled_sat.api.Environment(
location=[module_puppet_loc], organization=[module_puppet_org]
).create()
parent_hostgroup = session_puppet_enabled_sat.api.HostGroup(
location=[module_puppet_loc], organization=[module_puppet_org]
).create()
arch = session_puppet_enabled_sat.api.Architecture().create()
ptable = session_puppet_enabled_sat.api.PartitionTable().create()
os = session_puppet_enabled_sat.api.OperatingSystem(
architecture=[arch], ptable=[ptable]
).create()
media = session_puppet_enabled_sat.api.Media(
operatingsystem=[os], location=[module_puppet_loc], organization=[module_puppet_org]
).create()
proxy = session_puppet_enabled_sat.api.SmartProxy().search(
query={'search': f'url = {session_puppet_enabled_sat.url}:9090'}
)[0]
subnet = session_puppet_enabled_sat.api.Subnet(
location=[module_puppet_loc], organization=[module_puppet_org]
).create()
domain = session_puppet_enabled_sat.api.Domain(
location=[module_puppet_loc], organization=[module_puppet_org]
).create()
content_view = session_puppet_enabled_sat.api.ContentView(
organization=module_puppet_org
).create()
content_view.publish()
content_view = content_view.read()
lce = session_puppet_enabled_sat.api.LifecycleEnvironment(
organization=module_puppet_org
).create()
content_view.version[0].promote(data={'environment_ids': lce.id, 'force': False})
hostgroup = session_puppet_enabled_sat.api.HostGroup(
architecture=arch,
content_source=proxy,
content_view=content_view,
domain=domain,
environment=env,
lifecycle_environment=lce,
location=[module_puppet_loc],
medium=media,
operatingsystem=os,
organization=[module_puppet_org],
parent=parent_hostgroup,
ptable=ptable,
puppet_ca_proxy=proxy,
puppet_proxy=proxy,
subnet=subnet,
).create()
assert hostgroup.environment.read().name == env.name
assert hostgroup.parent.read().name == parent_hostgroup.name
assert hostgroup.architecture.read().name == arch.name
assert hostgroup.operatingsystem.read().name == os.name
assert hostgroup.medium.read().name == media.name
assert hostgroup.ptable.read().name == ptable.name
assert hostgroup.puppet_ca_proxy.read().name == proxy.name
assert hostgroup.subnet.read().name == subnet.name
assert hostgroup.domain.read().name == domain.name
assert hostgroup.puppet_proxy.read().name == proxy.name
assert hostgroup.content_source.read().name == proxy.name
assert hostgroup.content_view.read().name == content_view.name
assert hostgroup.lifecycle_environment.read().name == lce.name
# create new properties for update
new_org = session_puppet_enabled_sat.api.Organization().create()
new_loc = session_puppet_enabled_sat.api.Location(organization=[new_org]).create()
new_arch = session_puppet_enabled_sat.api.Architecture().create()
new_ptable = session_puppet_enabled_sat.api.PartitionTable().create()
new_parent = session_puppet_enabled_sat.api.HostGroup(
location=[new_loc], organization=[new_org]
).create()
new_env = session_puppet_enabled_sat.api.Environment(
location=[new_loc], organization=[new_org]
).create()
new_os = session_puppet_enabled_sat.api.OperatingSystem(
architecture=[new_arch], ptable=[new_ptable]
).create()
new_subnet = session_puppet_enabled_sat.api.Subnet(
location=[new_loc], organization=[new_org]
).create()
new_domain = session_puppet_enabled_sat.api.Domain(
location=[new_loc], organization=[new_org]
).create()
new_cv = session_puppet_enabled_sat.api.ContentView(organization=new_org).create()
new_cv.publish()
new_cv = new_cv.read()
new_lce = session_puppet_enabled_sat.api.LifecycleEnvironment(organization=new_org).create()
new_media = session_puppet_enabled_sat.api.Media(
operatingsystem=[os], location=[new_loc], organization=[new_org]
).create()
new_cv.version[0].promote(data={'environment_ids': new_lce.id, 'force': False})
# update itself
hostgroup.organization = [new_org]
hostgroup.location = [new_loc]
hostgroup.lifecycle_environment = new_lce
hostgroup.content_view = new_cv
hostgroup.domain = new_domain
hostgroup.architecture = new_arch
hostgroup.operatingsystem = new_os
hostgroup.environment = new_env
hostgroup.parent = new_parent
hostgroup.ptable = new_ptable
hostgroup.subnet = new_subnet
hostgroup.medium = new_media
hostgroup = hostgroup.update(
[
'parent',
'environment',
'operatingsystem',
'architecture',
'ptable',
'subnet',
'domain',
'content_view',
'lifecycle_environment',
'location',
'organization',
'medium',
]
)
assert hostgroup.parent.read().name == new_parent.name
assert hostgroup.environment.read().name == new_env.name
assert hostgroup.operatingsystem.read().name == new_os.name
assert hostgroup.architecture.read().name == new_arch.name
assert hostgroup.ptable.read().name == new_ptable.name
assert hostgroup.subnet.read().name == new_subnet.name
assert hostgroup.domain.read().name == new_domain.name
assert hostgroup.content_view.read().name == new_cv.name
assert hostgroup.lifecycle_environment.read().name == new_lce.name
assert new_loc.name in [location.read().name for location in hostgroup.location]
assert new_org.name in [org.read().name for org in hostgroup.organization]
assert hostgroup.medium.read().name == new_media.name
# delete
hostgroup.delete()
with pytest.raises(HTTPError):
hostgroup.read()
@pytest.mark.stubbed('Remove stub once proper infrastructure will be created')
def test_positive_create_with_realm(self, module_org, module_location, target_sat):
"""Create a hostgroup with realm specified
:id: 4f07ff8d-746f-4ab5-ae0b-03d629f6296c
:CaseImportance: Medium
:expectedresults: A hostgroup is created with expected realm assigned
"""
realm = target_sat.api.Realm(
location=[module_location],
organization=[module_org],
realm_proxy=target_sat.api.SmartProxy().search(
query={'search': f'url = {target_sat.url}:9090'}
)[0],
).create()
hostgroup = target_sat.api.HostGroup(
location=[module_location], organization=[module_org], realm=realm
).create()
assert hostgroup.realm.read().name == realm.name
def test_positive_create_with_locs(self, module_org, module_target_sat):
"""Create a hostgroup with multiple locations specified
:id: 0c2ee2ff-9e7a-4931-8cea-f4eecbd8c4c0
:CaseImportance: Medium
:expectedresults: A hostgroup is created with expected multiple
locations assigned
"""
locs = [
module_target_sat.api.Location(organization=[module_org]).create()
for _ in range(randint(3, 5))
]
hostgroup = module_target_sat.api.HostGroup(
location=locs, organization=[module_org]
).create()
assert {loc.name for loc in locs} == {loc.read().name for loc in hostgroup.location}
def test_positive_create_with_orgs(self, target_sat):
"""Create a hostgroup with multiple organizations specified
:id: 09642238-cf0d-469a-a0b5-c167b1b8edf5
:CaseImportance: Medium
:expectedresults: A hostgroup is created with expected multiple
organizations assigned
"""
orgs = [target_sat.api.Organization().create() for _ in range(randint(3, 5))]
hostgroup = target_sat.api.HostGroup(organization=orgs).create()
assert {org.name for org in orgs}, {org.read().name for org in hostgroup.organization}
@pytest.mark.parametrize('name', **parametrized(valid_hostgroups_list()))
def test_positive_update_name(self, name, hostgroup):
"""Update a hostgroup with a new name
:id: 8abb151f-a058-4f47-a1c1-f60a32cd7572
:parametrized: yes
:expectedresults: A hostgroup is updated with expected name
:CaseImportance: Critical
"""
hostgroup.name = name
hostgroup = hostgroup.update(['name'])
assert name == hostgroup.name
def test_positive_update_puppet_ca_proxy(self, puppet_hostgroup, session_puppet_enabled_sat):
"""Update a hostgroup with a new puppet CA proxy
:id: fd13ab0e-1a5b-48a0-a852-3fff8306271f
:expectedresults: A hostgroup is updated with expected puppet CA proxy
:CaseImportance: Medium
"""
new_proxy = session_puppet_enabled_sat.api.SmartProxy().search(
query={'search': f'url = {session_puppet_enabled_sat.url}:9090'}
)[0]
puppet_hostgroup.puppet_ca_proxy = new_proxy
puppet_hostgroup = puppet_hostgroup.update(['puppet_ca_proxy'])
assert puppet_hostgroup.puppet_ca_proxy.read().name == new_proxy.name
@pytest.mark.stubbed('Remove stub once proper infrastructure will be created')
def test_positive_update_realm(self, module_org, module_location, target_sat):
"""Update a hostgroup with a new realm
:id: fd9d141f-7a71-4439-92c7-1dbc1eea4772
:CaseImportance: Medium
:expectedresults: A hostgroup is updated with expected realm
"""
realm = target_sat.api.Realm(
location=[module_location],
organization=[module_org],
realm_proxy=target_sat.api.SmartProxy().search(
query={'search': f'url = {target_sat.url}:9090'}
)[0],
).create()
hostgroup = target_sat.api.HostGroup(
location=[module_location], organization=[module_org], realm=realm
).create()
new_realm = target_sat.api.Realm(
location=[module_location],
organization=[module_org],
realm_proxy=target_sat.api.SmartProxy().search(
query={'search': f'url = {target_sat.url}:9090'}
)[0],
).create()
hostgroup.realm = new_realm
hostgroup = hostgroup.update(['realm'])
assert hostgroup.realm.read().name == new_realm.name
def test_positive_update_puppet_proxy(self, puppet_hostgroup, session_puppet_enabled_sat):
"""Update a hostgroup with a new puppet proxy
:id: 86eca603-2cdd-4563-b6f6-aaa5cea1a723
:CaseImportance: Medium
:expectedresults: A hostgroup is updated with expected puppet proxy
"""
new_proxy = session_puppet_enabled_sat.api.SmartProxy().search(
query={'search': f'url = {session_puppet_enabled_sat.url}:9090'}
)[0]
puppet_hostgroup.puppet_proxy = new_proxy
puppet_hostgroup = puppet_hostgroup.update(['puppet_proxy'])
assert puppet_hostgroup.puppet_proxy.read().name == new_proxy.name
def test_positive_update_content_source(self, hostgroup, target_sat):
"""Update a hostgroup with a new puppet proxy
:id: 02ef1340-a21e-41b7-8aa7-d6fdea196c16
:CaseImportance: Medium
:expectedresults: A hostgroup is updated with expected puppet proxy
"""
new_content_source = target_sat.api.SmartProxy().search(
query={'search': f'url = {target_sat.url}:9090'}
)[0]
hostgroup.content_source = new_content_source
hostgroup = hostgroup.update(['content_source'])
assert hostgroup.content_source.read().name == new_content_source.name
def test_positive_update_locs(self, module_org, hostgroup, module_target_sat):
"""Update a hostgroup with new multiple locations
:id: b045f7e8-d7c0-428b-a29c-8d54e53742e2
:CaseImportance: Medium
:expectedresults: A hostgroup is updated with expected locations
"""
new_locs = [
module_target_sat.api.Location(organization=[module_org]).create()
for _ in range(randint(3, 5))
]
hostgroup.location = new_locs
hostgroup = hostgroup.update(['location'])
assert {loc.name for loc in new_locs}, {loc.read().name for loc in hostgroup.location}
def test_positive_update_orgs(self, hostgroup, target_sat):
"""Update a hostgroup with new multiple organizations
:id: 5f6bd4f9-4bd6-4d7e-9a91-de824299020e
:CaseImportance: Medium
:expectedresults: A hostgroup is updated with expected organizations
"""
new_orgs = [target_sat.api.Organization().create() for _ in range(randint(3, 5))]
hostgroup.organization = new_orgs
hostgroup = hostgroup.update(['organization'])
assert {org.name for org in new_orgs} == {org.read().name for org in hostgroup.organization}
@pytest.mark.parametrize('name', **parametrized(invalid_values_list()))
def test_negative_create_with_name(self, name, module_org, module_location, module_target_sat):
"""Attempt to create a hostgroup with invalid names
:id: 3f5aa17a-8db9-4fe9-b309-b8ec5e739da1
:parametrized: yes
:expectedresults: A hostgroup is not created
:CaseImportance: Critical
"""
with pytest.raises(HTTPError):
module_target_sat.api.HostGroup(
location=[module_location], name=name, organization=[module_org]
).create()
@pytest.mark.parametrize('new_name', **parametrized(invalid_values_list()))
def test_negative_update_name(self, new_name, hostgroup):
"""Attempt to update a hostgroup with invalid names
:id: 6d8c4738-a0c4-472b-9a71-27c8a3832335
:parametrized: yes
:expectedresults: A hostgroup is not updated
:CaseImportance: Critical
"""
original_name = hostgroup.name
hostgroup.name = new_name
with pytest.raises(HTTPError):
hostgroup.update(['name'])
assert hostgroup.read().name == original_name
def test_positive_create_with_group_parameters(self, module_org, module_target_sat):
"""Create a hostgroup with 'group parameters' specified
:id: 0959e2a2-d635-482b-9b2e-d33990d6f0dc
:CaseImportance: Medium
:expectedresults: A hostgroup is created with assigned group parameters
:customerscenario: true
:BZ: 1710853
"""
group_params = {'name': gen_string('alpha'), 'value': gen_string('alpha')}
hostgroup = module_target_sat.api.HostGroup(
organization=[module_org], group_parameters_attributes=[group_params]
).create()
assert group_params['name'] == hostgroup.group_parameters_attributes[0]['name']
assert group_params['value'] == hostgroup.group_parameters_attributes[0]['value']
def test_hostgroup_synced_content_inheritance(
self,
module_target_sat,
function_sca_manifest_org,
function_location,
):
"""Verify that changing the operating system for a parent hostgroup also updates the operating system
and kickstart repository for any child hostgroups
:id: a302f425-396e-457b-8502-d0a295c9e601
:Steps:
1. Enable and sync the BaseOS and AppStream kickstart repos for the latest and next-to-latest RHEL y-stream.
2. Create and publish a content view containing the kickstart repos.
3. Create a parent hostgroup associated with the older RHEL version's kickstart repos.
4. Create a child hostgroup with the same data as the parent hostgroup.
5. Update the operating system of the parent hostgroup to the latest RHEL y-stream
:ExpectedResults:
The operating system and the kickstart repository of the child hostgroup are also updated to the latest RHEL y-stream.
:Verifies: SAT-40733
:CustomerScenario: True
"""
NEW_BASEOS = REPOS['kickstart']['rhel10_bos']
NEW_APPSTREAM = REPOS['kickstart']['rhel10_aps']
# Since our repo constants are updated to be current with the latest RHEL y-stream release,
# decrement the version from the constants by 1 to get the names of the old kickstart repos
OLD_BASEOS = copy(NEW_BASEOS)
OLD_APPSTREAM = copy(NEW_APPSTREAM)
for constant in [OLD_BASEOS, OLD_APPSTREAM]:
base_repo_name, y_stream_version = constant['name'].split('.')
y_stream_version = str(int(y_stream_version) - 1)
constant['name'] = base_repo_name + '.' + y_stream_version
constant['version'] = constant['name'].split()[-1]
# Enable and sync old and new kickstart repos
repos = []
for repo in [NEW_BASEOS, NEW_APPSTREAM, OLD_BASEOS, OLD_APPSTREAM]:
repo_id = module_target_sat.api_factory.enable_rhrepo_and_fetchid(
basearch=DEFAULT_ARCHITECTURE,
org_id=function_sca_manifest_org.id,
product=repo['product'],
repo=repo['name'],
reposet=repo['reposet'],
releasever=repo['version'],
)
repo = module_target_sat.api.Repository(id=repo_id).read()
repo.sync()
repos.append(repo)
repos_dict = dict(
zip(['New BaseOS', 'New Appstream', 'Old BaseOS', 'Old AppStream'], repos, strict=True)
)
# Create a content view containing all the synced kickstart repos
cv = module_target_sat.api.ContentView(organization=function_sca_manifest_org).create()
cv = module_target_sat.api.ContentView(id=cv.id, repository=repos).update(['repository'])
cv.publish()
cv = cv.read()
# Get the Library lifecycle environment for the organization
library_lce = module_target_sat.api.LifecycleEnvironment(
organization=function_sca_manifest_org
).search(query={'search': 'name=Library'})[0]
# Get content source, architecture, and operating system objects for hostgroup creation
content_source = module_target_sat.api.SmartProxy().search(
query={'search': f'url = {module_target_sat.url}:9090'}
)[0]
old_os_id = (
module_target_sat.api.OperatingSystem()
.search(
query={
'search': f'name="RedHat" AND major={OLD_BASEOS["version"].split(".")[0]} AND minor={OLD_BASEOS["version"].split(".")[1]}'
}
)[0]
.id
)
old_os = module_target_sat.api.OperatingSystem(id=old_os_id).read()
arch = (
module_target_sat.api.Architecture()
.search(query={'search': f'name="{DEFAULT_ARCHITECTURE}"'})[0]
.read()
)
# Create a parent host group and a child hostgroup
parent_hostgroup = module_target_sat.api.HostGroup(
architecture=arch,
content_source=content_source,
content_view=cv,
lifecycle_environment=library_lce,
kickstart_repository=repos_dict['Old BaseOS'],
location=[function_location],
organization=[function_sca_manifest_org],
operatingsystem=old_os,
).create()
child_hostgroup = module_target_sat.api.HostGroup(
parent=parent_hostgroup,
).create()
# Get the new operating system object and use it to update the hostgroup
new_os_id = (
module_target_sat.api.OperatingSystem()
.search(
query={
'search': f'name="RedHat" AND major={NEW_BASEOS["version"].split(".")[0]} AND minor={NEW_BASEOS["version"].split(".")[1]}'
}
)[0]
.id
)
new_os = module_target_sat.api.OperatingSystem(id=new_os_id).read()
parent_hostgroup.operatingsystem = new_os
parent_hostgroup.update(['operatingsystem'])
# To get the kickstart repository ID from the hostgroup entity, use read_json(), as
# nailgun.HostGroup.read() ignores the kickstart_repository field due to an old bug.
# Additionally, values inherited by child hostgroups from parent hostgroups are returned as nil
# values when the child hostgroup is queried via the API (see SAT-47322). To work around this,
# assert that the child hostgroup operating system has been updated, that the child hostgroup
# kickstart repo is None, and that the parent hostgroup kickstart repo has been updated.
parent_hostgroup_json = module_target_sat.api.HostGroup(id=parent_hostgroup.id).read_json()
child_hostgroup_json = module_target_sat.api.HostGroup(id=child_hostgroup.id).read_json()
kickstart_repo = module_target_sat.api.Repository(
id=parent_hostgroup_json['kickstart_repository_id']
).read()
assert child_hostgroup_json['operatingsystem_name'] == f'RedHat {NEW_BASEOS["version"]}'
assert child_hostgroup_json['kickstart_repository_id'] is None
assert kickstart_repo.name == NEW_BASEOS['name']
class TestHostGroupMissingAttr:
"""Tests to see if the server returns the attributes it should.
Satellite should return a full description of an entity each time an entity
is created, read or updated. These tests verify that certain attributes
really are returned. The ``one_to_*_names`` functions know what names
Satellite may assign to fields.
"""
def test_positive_get_content_source(self, hostgroup, module_target_sat):
"""Read a host group. Inspect the server's response.
:id: 9d42f47a-2f08-45ad-97d0-de94f0f1de2f
:CaseImportance: Medium
:expectedresults: The response contains both values for the
``content_source`` field.
"""
names = module_target_sat.api_factory.one_to_one_names('content_source')
hostgroup_attrs = set(hostgroup.read_json().keys())
assert names.issubset(hostgroup_attrs), (
f'{names.difference(hostgroup_attrs)} not found in {hostgroup_attrs}'
)
def test_positive_get_cv(self, hostgroup, module_target_sat):
"""Read a host group. Inspect the server's response.
:id: 7d36f33e-f161-4d2a-9ee4-8eb949ed4cbf
:CaseImportance: Medium
:expectedresults: The response contains both values for the
``content_view`` field.
"""
names = module_target_sat.api_factory.one_to_one_names('content_view')
hostgroup_attrs = set(hostgroup.read_json().keys())
assert names.issubset(hostgroup_attrs), (
f'{names.difference(hostgroup_attrs)} not found in {hostgroup_attrs}'
)
def test_positive_get_lce(self, hostgroup, module_target_sat):
"""Read a host group. Inspect the server's response.
:id: efa17f59-47f9-40c6-821d-c348c4d852ff
:CaseImportance: Medium
:expectedresults: The response contains both values for the
``lifecycle_environment`` field.
"""
names = module_target_sat.api_factory.one_to_one_names('lifecycle_environment')
hostgroup_attrs = set(hostgroup.read_json().keys())
assert names.issubset(hostgroup_attrs), (
f'{names.difference(hostgroup_attrs)} not found in {hostgroup_attrs}'
)
def test_positive_read_puppet_proxy_name(self, session_puppet_enabled_sat):
"""Read a hostgroup created with puppet proxy and inspect server's
response
:id: f93d0866-0073-4577-8777-6d645b63264f
:CaseImportance: Medium
:expectedresults: Field 'puppet_proxy_name' is returned
:BZ: 1371900
"""
proxy = session_puppet_enabled_sat.api.SmartProxy().search(
query={'search': f'url = {session_puppet_enabled_sat.url}:9090'}
)[0]
hg = session_puppet_enabled_sat.api.HostGroup(puppet_proxy=proxy).create().read_json()
assert 'puppet_proxy_name' in hg
assert proxy.name == hg['puppet_proxy_name']
def test_positive_read_puppet_ca_proxy_name(self, session_puppet_enabled_sat):
"""Read a hostgroup created with puppet ca proxy and inspect server's
response
:id: ab151e09-8e64-4377-95e8-584629750659
:CaseImportance: Medium
:expectedresults: Field 'puppet_ca_proxy_name' is returned
:BZ: 1371900
"""
proxy = session_puppet_enabled_sat.api.SmartProxy().search(
query={'search': f'url = {session_puppet_enabled_sat.url}:9090'}
)[0]
hg = session_puppet_enabled_sat.api.HostGroup(puppet_ca_proxy=proxy).create().read_json()
assert 'puppet_ca_proxy_name' in hg
assert proxy.name == hg['puppet_ca_proxy_name']