forked from SatelliteQE/robottelo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_contentview.py
More file actions
2749 lines (2323 loc) · 113 KB
/
Copy pathtest_contentview.py
File metadata and controls
2749 lines (2323 loc) · 113 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
"""Unit tests for the ``content_views`` paths.
:Requirement: Contentview
:CaseAutomation: Automated
:CaseComponent: ContentViews
:team: Artemis
:CaseImportance: High
"""
from copy import deepcopy
from datetime import UTC, datetime, timedelta
import random
import time
from fauxfactory import gen_integer, gen_string, gen_utf8
import pytest
from requests.exceptions import HTTPError
from robottelo.config import settings, user_nailgun_config
from robottelo.constants import (
CUSTOM_RPM_SHA_512_FEED_COUNT,
DEFAULT_ARCHITECTURE,
FAKE_1_CUSTOM_PACKAGE,
FAKE_1_CUSTOM_PACKAGE_NAME,
FAKE_1_ERRATA_ID,
FAKE_2_CUSTOM_PACKAGE,
PERMISSIONS,
PRDS,
REPOS,
REPOSET,
TIMESTAMP_FMT_ZONE,
DataFile,
)
from robottelo.constants.repos import CUSTOM_RPM_SHA_512, FEDORA_OSTREE_REPO
from robottelo.utils.datafactory import (
invalid_names_list,
parametrized,
valid_data_list,
)
# Some tests repeatedly publish content views or promote content view versions.
# How many times should that be done? A higher number means a more interesting
# but longer test.
REPEAT = 3
@pytest.fixture(scope='class')
def class_cv(module_org, class_target_sat):
return class_target_sat.api.ContentView(organization=module_org).create()
@pytest.fixture(scope='class')
def class_published_cv(class_cv):
class_cv.publish()
return class_cv.read()
@pytest.fixture(scope='class')
def class_promoted_cv(class_published_cv, module_lce):
class_published_cv.version[0].promote(data={'environment_ids': module_lce.id})
return class_published_cv.read()
@pytest.fixture(scope='class')
def class_cloned_cv(class_cv, class_target_sat):
copied_cv_id = class_target_sat.api.ContentView(id=class_cv.id).copy(
data={'name': gen_string('alpha', gen_integer(3, 30))}
)['id']
return class_target_sat.api.ContentView(id=copied_cv_id).read()
@pytest.fixture(scope='class')
def class_published_cloned_cv(class_cloned_cv, class_target_sat):
class_cloned_cv.publish()
return class_target_sat.api.ContentView(id=class_cloned_cv.id).read()
@pytest.fixture
def content_view(module_org, module_target_sat):
return module_target_sat.api.ContentView(organization=module_org).create()
def apply_package_filter(content_view, repo, package, target_sat, inclusion=True):
"""Apply package filter on content view
:param content_view: entity content view
:param repo: entity repository
:param str package: package name to filter
:param bool inclusion: True/False based on include or exclude filter
:return list : list of content view versions
"""
cv_filter = target_sat.api.RPMContentViewFilter(
content_view=content_view, inclusion=inclusion, repository=[repo]
).create()
cv_filter_rule = target_sat.api.ContentViewFilterRule(
content_view_filter=cv_filter, name=package
).create()
assert cv_filter.id == cv_filter_rule.content_view_filter.id
content_view.publish()
content_view = content_view.read()
return content_view.version[0].read()
class TestContentView:
@pytest.mark.upgrade
def test_positive_subscribe_host(
self, class_cv, class_promoted_cv, module_lce, module_org, module_target_sat
):
"""Subscribe a host to a content view
:id: b5a08369-bf92-48ab-b9aa-10f5b9774b79
:expectedresults: It is possible to create a host and set its
'content_view_id' facet attribute
:CaseAutomation: Automated
:CaseImportance: High
"""
# organization
# ├── lifecycle environment
# └── content view
# Check that no host associated to just created content view
assert class_cv.content_host_count == 0
assert len(class_promoted_cv.version) == 1
host = module_target_sat.api.Host(
content_facet_attributes={
'content_view_id': class_cv.id,
'lifecycle_environment_id': module_lce.id,
},
organization=module_org.id,
).create()
assert host.content_facet_attributes['content_view']['id'] == class_cv.id
assert host.content_facet_attributes['lifecycle_environment']['id'] == module_lce.id
assert class_cv.read().content_host_count == 1
def test_positive_clone_within_same_env(self, class_published_cloned_cv, module_lce):
"""attempt to create, publish and promote new content view
based on existing view within the same environment as the
original content view
:id: a7be5dc1-26c1-4354-99a1-1cbc90c89c64
:expectedresults: Cloned content view can be published and promoted to
the same environment as the original content view
:CaseImportance: High
"""
class_published_cloned_cv.read().version[0].promote(data={'environment_ids': module_lce.id})
@pytest.mark.upgrade
def test_positive_clone_with_diff_env(
self, module_org, class_published_cloned_cv, module_target_sat
):
"""attempt to create, publish and promote new content
view based on existing view but promoted to a
different environment
:id: a4d21c85-a77c-4664-95ba-3d32c3ad1663
:expectedresults: Cloned content view can be published and promoted to
a different environment as the original content view
:CaseImportance: Medium
"""
le_clone = module_target_sat.api.LifecycleEnvironment(organization=module_org).create()
class_published_cloned_cv.read().version[0].promote(data={'environment_ids': le_clone.id})
def test_positive_add_custom_content(self, module_product, module_org, module_target_sat):
"""Associate custom content in a view
:id: db452e0c-0c17-40f2-bab4-8467e7a875f1
:expectedresults: Custom content assigned and present in content view
:CaseImportance: Critical
"""
yum_repo = module_target_sat.api.Repository(product=module_product).create()
yum_repo.sync()
content_view = module_target_sat.api.ContentView(organization=module_org.id).create()
assert len(content_view.repository) == 0
content_view.repository = [yum_repo]
content_view = content_view.update(['repository'])
assert len(content_view.repository) == 1
assert content_view.repository[0].read().name == yum_repo.name
def test_negative_add_dupe_repos(
self, content_view, module_product, module_org, module_target_sat
):
"""Attempt to associate the same repo multiple times within a
content view
:id: 9e3dff38-fdcc-4483-9844-0619797cf1d5
:expectedresults: User cannot add repos multiple times to the view
:CaseImportance: Low
"""
yum_repo = module_target_sat.api.Repository(product=module_product).create()
yum_repo.sync()
assert len(content_view.repository) == 0
content_view.repository = [yum_repo, yum_repo]
with pytest.raises(HTTPError):
content_view.update(['repository'])
assert len(content_view.read().repository) == 0
@pytest.mark.pit_server
@pytest.mark.skipif(
(not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url'
)
def test_positive_add_sha512_rpm(self, content_view, module_org, module_target_sat):
"""Associate sha512 RPM content in a view
:id: 1f473b02-5e2b-41ff-a706-c0635abc2476
:expectedresults: Custom sha512 assigned and present in content view
:CaseComponent: Pulp
:team: Artemis
:CaseImportance: Medium
:customerscenario: true
:BZ: 1639406
"""
product = module_target_sat.api.Product(organization=module_org).create()
yum_sha512_repo = module_target_sat.api.Repository(
product=product, url=CUSTOM_RPM_SHA_512
).create()
yum_sha512_repo.sync()
repo_content = yum_sha512_repo.read()
# Assert that the repository content was properly synced
assert repo_content.content_counts['rpm'] == CUSTOM_RPM_SHA_512_FEED_COUNT['rpm']
assert repo_content.content_counts['erratum'] == CUSTOM_RPM_SHA_512_FEED_COUNT['errata']
content_view.repository = [yum_sha512_repo]
content_view = content_view.update(['repository'])
content_view.publish()
content_view = content_view.read()
assert len(content_view.repository) == 1
assert len(content_view.version) == 1
content_view_version = content_view.version[0].read()
assert content_view_version.package_count == CUSTOM_RPM_SHA_512_FEED_COUNT['rpm']
assert (
content_view_version.errata_counts['total'] == CUSTOM_RPM_SHA_512_FEED_COUNT['errata']
)
def test_ccv_promote_registry_name_change(self, module_target_sat, module_sca_manifest_org):
"""Testing CCV promotion scenarios where the registry_name has been changed to some
specific value.
:id: 41641d4a-d144-4833-869a-284624df2410
:steps:
1) Sync a RH Repo
2) Create a CV, add the repo and publish it
3) Create a CCV and add the CV version to it, then publish it
4) Create LCEs with the specific value for registry_name
5) Promote the CCV to both LCEs
:expectedresults: CCV can be promoted to both LCEs without issue.
:CaseImportance: High
:customerscenario: true
:BZ: 2153523
"""
rh_repo_id = module_target_sat.api_factory.enable_rhrepo_and_fetchid(
basearch=DEFAULT_ARCHITECTURE,
org_id=module_sca_manifest_org.id,
product=REPOS['kickstart']['rhel8_aps']['product'],
repo=REPOS['kickstart']['rhel8_aps']['name'],
reposet=REPOS['kickstart']['rhel8_aps']['reposet'],
releasever=REPOS['kickstart']['rhel8_aps']['version'],
)
repo = module_target_sat.api.Repository(id=rh_repo_id).read()
repo.sync(timeout=600)
cv = module_target_sat.api.ContentView(organization=module_sca_manifest_org).create()
cv = module_target_sat.api.ContentView(id=cv.id, repository=[repo]).update(["repository"])
cv.publish()
cv = cv.read()
composite_cv = module_target_sat.api.ContentView(
organization=module_sca_manifest_org, composite=True
).create()
composite_cv.component = [cv.version[0]]
composite_cv = composite_cv.update(['component'])
composite_cv.publish()
composite_cv = composite_cv.read()
# Create LCEs with the specific registry value
lce1 = module_target_sat.api.LifecycleEnvironment(
organization=module_sca_manifest_org,
registry_name_pattern='<%= repository.name %>',
).create()
lce2 = module_target_sat.api.LifecycleEnvironment(
organization=module_sca_manifest_org,
registry_name_pattern='<%= lifecycle_environment.label %>/<%= repository.name %>',
).create()
version = composite_cv.version[0].read()
assert 'success' in version.promote(data={'environment_ids': lce1.id})['result']
assert 'success' in version.promote(data={'environment_ids': lce2.id})['result']
def test_content_view_environment_id_and_label_search(
self, module_target_sat, module_org, module_lce
):
"""Verify that `GET katello/api/content_view_environments returns results with an `id`
field and that it responds to searches by label.
:id: 462bff2a-6515-4dc0-bf87-df18e0ac0e31
:steps:
1. Sync a repo and add it to a content view.
2. Publish the content view and promote the first version to an LCE.
3. Query the content view environments API endpoint for content view environments.
associated with the LCE.
4. Assert that the result contains an `id` field.
5. Query the endpoint again and search for the label of the content view environment
from the previous response.
6. Assert that the label field in the new response matches the label field of the
previous response.
:expectedresults:
1. Results in the API response contain an ID field.
2. A search query to the endpoint scoped by `label` is successful.
:CaseImportance: Medium
:verifies: SAT-34301
"""
repo_id = module_target_sat.api_factory.create_sync_custom_repo(org_id=module_org.id)
repo = module_target_sat.api.Repository(id=repo_id).read()
repo.sync()
cv = module_target_sat.api.ContentView(organization=module_org).create()
cv = module_target_sat.api.ContentView(id=cv.id, repository=[repo]).update(["repository"])
cv.publish()
cv = cv.read()
module_target_sat.api.ContentViewVersion(id=cv.version[0].id).promote(
data={'environment_ids': module_lce.id}
)
cv_env = module_target_sat.api.ContentViewEnvironment()
response = cv_env.list_content_view_environments(
params={'lifecycle_environment_id': module_lce.id}
)
assert 'id' in response['results'][0]
label = response['results'][0]['label']
response = cv_env.list_content_view_environments(params={'search': f'label="{label}"'})
assert response['search'] == f'label="{label}"'
assert response['results'][0]['label'] == label
class TestRollingContentView:
"""Testing for rolling content views."""
def test_negative_create_update_with_invalid_params(self, target_sat):
"""Cannot create or update rolling content view providing an invalid configuration.
:id: b38b866e-786c-4be0-b4cb-64432dcbad45
:steps:
1) try to create a Composite rolling content view
2) try to create a dependancy-solving rolling content view
3) try to create an auto-publish (and Composite) rolling content view
4) create a valid rolling content view
5) try to update the valid rolling cv with the invalid params
:expectedresults:
1) Invalid Rolling Content View is not created
2) Invalid Update for Rolling Content View is not executed
:CaseImportance: High
"""
with pytest.raises(HTTPError):
target_sat.api.ContentView(rolling=True, composite=True).create()
with pytest.raises(HTTPError):
target_sat.api.ContentView(rolling=True, solve_dependencies=True).create()
with pytest.raises(HTTPError):
target_sat.api.ContentView(rolling=True, composite=True, auto_publish=True).create()
rolling_cv = target_sat.api.ContentView(rolling=True).create()
rolling_cv.composite = True
rolling_cv.update(['composite'])
assert not rolling_cv.read().composite
rolling_cv.auto_publish = True
with pytest.raises(HTTPError):
rolling_cv.update(['auto_publish'])
rolling_cv.solve_dependencies = True
with pytest.raises(HTTPError):
rolling_cv.update(['solve_dependencies'])
def test_negative_publish_rolling(self, target_sat):
"""Cannot publish the rolling content view.
:id: a838316d-265d-4152-a472-8371b4480379
:expectedresults: Rolling Content View is not published
:CaseImportance: Critical
"""
rolling_cv = target_sat.api.ContentView(rolling=True).create()
with pytest.raises(HTTPError):
target_sat.api.ContentView(id=rolling_cv.id).publish()
assert rolling_cv.version == target_sat.api.ContentView(id=rolling_cv.id).read().version
def test_negative_convert_to_rolling(self, target_sat):
"""Cannot convert a normal content view into a rolling content view.
:id: 78dba0fe-617d-4f52-96c9-dea66b1bfdf3
:expectedresults: Original Content View is not converted to Rolling
:CaseImportance: Critical
"""
normal_cv = target_sat.api.ContentView().create()
normal_cv = normal_cv.read()
assert not normal_cv.rolling
normal_cv.rolling = True
normal_cv.update(['rolling'])
assert not normal_cv.read().rolling
def test_negative_promote_rolling_version(self, target_sat, module_org, module_lce):
"""Cannot promote the version of the rolling content view to any environment.
:id: b4987bb2-560a-4ead-9c98-48336504a7ba
:expectedresults:
1) Rolling Content View has no environments by default.
2) Rolling Content View Version is not promoted.
:CaseImportance: Critical
"""
rolling_cv = target_sat.api.ContentView(rolling=True, organization=module_org).create()
assert rolling_cv.environment == []
for lce_id in [module_org.library.id, module_lce.id]:
with pytest.raises(HTTPError) as e:
target_sat.api.ContentViewVersion(id=rolling_cv.version[0].id).promote(
data={'environment_ids': lce_id}
)
assert "It's not possible to promote a rolling content view." in e.value.response.text
assert rolling_cv.read().environment == []
def test_negative_change_rolling_version(self, target_sat):
"""Cannot update the rolling content view with another version.
:id: f16dbe19-29ea-41f1-89e2-fd99aa07857f
:expectedresults: Rolling Content View is not updated
:CaseImportance: Critical
:BlockedBy: SAT-41460
"""
rolling_cv = target_sat.api.ContentView(rolling=True).create()
normal_cv = target_sat.api.ContentView().create()
normal_cv.publish()
normal_cv = normal_cv.read()
rolling_version = rolling_cv.version[0].read()
normal_version = normal_cv.version[0].read()
# try with a single different version
rolling_cv.version = [normal_version]
with pytest.raises(HTTPError):
rolling_cv.update(['version'])
# try in addition to the rolling version
rolling_cv.version = [rolling_version, normal_version]
with pytest.raises(HTTPError):
rolling_cv.update(['version'])
# try with just the initial rolling version
rolling_cv.version = [rolling_version]
with pytest.raises(HTTPError):
rolling_cv.update(['version'])
# version remains unchanged
assert rolling_cv.read().version[0].read() == rolling_version
def test_negative_delete_rolling_version(self, target_sat):
"""Cannot delete the version of the rolling content view.
:id: 6b1f3f0e-3f4e-4d1c-8f7a-2e5a5f3c8e2b
:expectedresults: Rolling Content View Version is not deleted.
:CaseImportance: Critical
"""
rolling_cv = target_sat.api.ContentView(rolling=True).create()
initial_version = rolling_cv.version[0].read()
with pytest.raises(HTTPError) as e:
target_sat.api.ContentViewVersion(id=rolling_cv.version[0].id).delete()
assert (
"It's not possible to destroy a version of a rolling content view."
in e.value.response.text
)
assert len(rolling_cv.read().version) == 1
assert rolling_cv.read().version[0].read() == initial_version
def test_negative_clone_rolling(self, target_sat):
"""Cannot create a copy of the rolling content view.
:id: ef64fa8b-2cc9-4d14-b6a2-735996c659f0
:expectedresults: Rolling Content View is not cloned
:CaseImportance: High
"""
rolling_cv = target_sat.api.ContentView(rolling=True).create()
with pytest.raises(HTTPError):
target_sat.api.ContentView(
id=rolling_cv.copy(data={'name': gen_string('alpha', gen_integer(3, 30))})['id']
).read_json()
def test_negative_filter_rolling(self, target_sat, module_org, module_product):
"""Cannot add a content filter to the rolling content view.
:id: 83f37cd8-e2ef-47e4-bad1-1c230aa7bc70
:setup: Sync and add a custom repository containing 'walrus' package version(s).
:expectedresults: Rolling Content View is not filtered.
:CaseImportance: Critical
"""
# Create and sync single custom repo containing 'walrus' versions
repo = target_sat.api.Repository(
content_type='yum', product=module_product, url=settings.repos.yum_9.url
).create()
repo.sync()
# Rolling CV created with the repo
rolling_cv = target_sat.api.ContentView(
repository=[repo.read()], organization=module_org, rolling=True
).create()
# Try to filter the 'walrus' packages
with pytest.raises(HTTPError):
apply_package_filter(rolling_cv, repo, 'walrus', target_sat, inclusion=False)
# no filter present, version unchanged
assert not rolling_cv.read().version[0].read().filters_applied
assert rolling_cv.read().version == rolling_cv.version
def test_negative_duplicate_repos(self, target_sat, module_org, module_product):
"""Cannot add multiple copies of the exact same repository to rolling content view.
:id: b3d70168-6b0d-4a8f-81f3-57ca991a8ab7
:expectedresults: Cannot create or update rolling content view with duplicate repositories.
:CaseImportance: Critical
"""
repo = target_sat.api.Repository(
content_type='yum', product=module_product, url=settings.repos.yum_9.url
).create()
repo.sync()
# cannot create CV with multiple copies of same repo
with pytest.raises(HTTPError):
target_sat.api.ContentView(
repository=[repo.read(), repo.read()], organization=module_org, rolling=True
).create()
# cannot update CV with a repo already contained
rolling_cv = target_sat.api.ContentView(
repository=[repo.read()], organization=module_org, rolling=True
).create()
rolling_cv.repository.append(repo.read())
with pytest.raises(HTTPError):
rolling_cv.update(['repository'])
@pytest.mark.upgrade
def test_positive_CRUD_rolling(self, target_sat, function_org):
"""Create, read, update, and delete the rolling content view.
It has the expected attributes for a rolling content view.
:id: e0b296c6-5fb2-48dd-b324-709fb515dd88
:steps:
1) Create new empty Rolling CV and check its attributes
2) Update rolling CV with Library environment and description
3) Try to delete the CV while it is still in Library
4) Remove Rolling CV from Library, then delete it
:expectedresults:
1) We can create, read, and update the rolling CV.
2) We cannot Delete the rolling CV, until it's removed/deleted from environment(s).
:CaseImportance: Critical
"""
# Create new empty Rolling CV and check its attributes
rolling_cv = target_sat.api.ContentView(organization=function_org, rolling=True).create()
assert all([rolling_cv.rolling, rolling_cv.read().rolling])
read_cv = target_sat.api.ContentView(id=rolling_cv.id).read()
assert not rolling_cv.needs_publish
assert not rolling_cv.auto_publish
assert read_cv == rolling_cv
# Update rolling CV with Library environment and description
cv_desc = valid_data_list()['utf8']
rolling_cv.description = cv_desc
rolling_cv.environment = [function_org.library]
update_cv = rolling_cv.update(['description', 'environment'])
assert update_cv == (rolling_cv := rolling_cv.read())
assert rolling_cv.description == cv_desc
assert len(rolling_cv.environment) == 1
assert rolling_cv.environment[0] == function_org.library
# Try to delete the CV while it is still in Library
with pytest.raises(HTTPError) as e:
rolling_cv.delete()
assert (
f"Cannot delete '{rolling_cv.name}' due to associated environments: Library."
in e.value.response.text
)
# Remove Rolling CV from Library, then delete it
rolling_cv.delete_from_environment(rolling_cv.environment[0].id)
rolling_cv.delete()
with pytest.raises(HTTPError):
rolling_cv.read()
@pytest.mark.upgrade
def test_positive_content_types_in_rolling(self, target_sat, module_org, module_product):
"""Can upload and use the different content types with the rolling content view.
TODO:
- Packages, Package Groups, Module Streams, Errata.
- Other content types (File, Docker, Ansible Collection)
:id: c9fb36e2-5241-44c2-8f7b-1069ccec5617
:CaseImportance: Critical
"""
rolling_cv = target_sat.api.ContentView(organization=module_org, rolling=True).create()
initial_version = rolling_cv.version[0].read()
custom_repos = [
settings.repos.yum_0.url,
settings.repos.yum_3.url,
settings.repos.yum_6.url,
settings.repos.yum_9.url,
]
for _url in custom_repos:
(repo := target_sat.api.Repository(product=module_product, url=_url).create()).sync()
rolling_cv.repository.append(repo.read())
# update rolling cv with the custom repos and Library
rolling_cv.environment = [module_org.library]
rolling_cv.update(['repository', 'environment'])
rolling_cv = rolling_cv.read()
assert len(rolling_cv.repository) == len(custom_repos)
assert initial_version != (rolling_version := rolling_cv.version[0].read())
assert rolling_version.yum_repository_count == len(custom_repos)
# errata now present from added repos
assert rolling_version.errata_counts['total'] == 37
assert rolling_version.errata_counts['bugfix'] == 8
assert rolling_version.errata_counts['security'] == 16
assert rolling_version.errata_counts['enhancement'] == 13
# packages, module streams, and package groups present
# TODO: fails: expect the version shows updated counts
"""assert rolling_version.package_count > 0
assert rolling_version.package_group_count > 0
assert rolling_version.module_stream_count > 0"""
@pytest.mark.upgrade
def test_positive_rolling_with_activation_keys(self, module_org, module_ak, target_sat):
"""We can use the rolling content view with one or more associated activation keys.
:id: b0510759-cee9-4f2e-a34c-dd495a34778c
:expectedresults:
1) We can use and delete activation keys associated to a rolling content view.
2) We cannot delete the rolling content view, until it is unassociated from activation key(s),
and removed from environment(s).
:CaseImportance: Critical
"""
rolling_cv = target_sat.api.ContentView(organization=module_org, rolling=True).create()
rolling_cv.environment = [module_org.library]
rolling_cv.update(['environment'])
library = module_org.library.read()
# Create new activation key providing rolling CV
ak = target_sat.api.ActivationKey(
organization=module_org,
content_view=rolling_cv,
environment=library,
).create()
assert ak.content_view.read() == rolling_cv
assert ak.environment.read() == library
# Update an existing activation key with CVE
module_ak.content_view = rolling_cv
module_ak.environment = library
module_ak.update(['content_view', 'environment'])
module_ak = module_ak.read()
assert module_ak.content_view.read() == rolling_cv
assert module_ak.environment.read() == library
# Can't delete until unassociated from AK's, removed from Library
with pytest.raises(HTTPError):
rolling_cv.delete_from_environment(library.id)
with pytest.raises(HTTPError):
rolling_cv.delete()
ak.delete()
module_ak.content_view = module_ak.environment = None
module_ak.update(['content_view', 'environment'])
rolling_cv.delete_from_environment(library.id)
rolling_cv.delete()
with pytest.raises(HTTPError):
rolling_cv.read()
@pytest.mark.upgrade
def test_positive_rolling_version(self, target_sat, module_org, module_product):
"""The rolling content view always has a single version, which is updated automatically.
:id: 3f0b3645-2eca-4cdc-89bc-0b5222bc1350
:steps:
1) Create new empty rolling CV
2) Inspect its first empty version
3) Add a repository with small amount of content to rolling CV
4) Update the CV, inspect the latest version again
:expectedresults:
1) After creating and updating the rolling CV, only a single version is present.
2) The single rolling version is always up to date, always published, and in Library.
3) When new repository content is added to rolling CV, the rolling version is updated with the content.
:CaseImportance: Critical
"""
rolling_cv = target_sat.api.ContentView(
organization=module_org,
rolling=True,
).create()
rolling_cv.environment = [module_org.library]
rolling_cv.update(['environment'])
assert rolling_cv.read().rolling
assert len(rolling_cv.version) == 1
rolling_version = deepcopy(
target_sat.api.ContentViewVersion(id=rolling_cv.version[0].id).read()
)
initial_version_publish = deepcopy(rolling_cv.last_published)
assert rolling_version.content_view.read() == rolling_cv
assert rolling_cv.version[0].read() == rolling_version
assert rolling_cv.environment == rolling_version.environment
assert rolling_version.version == '1.0'
assert rolling_version.major == 1
assert rolling_version.minor == 0
# check for empty content in version's attributes
version_content_empty = [
'docker_repository_count',
'file_count',
'file_repository_count',
'module_stream_count',
'package_count',
'package_group_count',
'yum_repository_count',
]
for key in version_content_empty:
assert getattr(rolling_version, key) == 0
for key in rolling_version.errata_counts:
assert rolling_version.errata_counts[f'{key}'] == 0
# create, sync, and add a custom repo with some fake content
repo = target_sat.api.Repository(
product=module_product, url=settings.repos.yum_0.url
).create()
repo.sync()
rolling_cv.repository = [repo.read()]
rolling_cv.update(['repository'])
rolling_cv = rolling_cv.read()
# last_published times do not change after rolling cv updates
assert datetime.strptime(
rolling_cv.last_published, TIMESTAMP_FMT_ZONE
) == datetime.strptime(initial_version_publish, TIMESTAMP_FMT_ZONE)
# check newly updated version
new_rolling_version = target_sat.api.ContentViewVersion(id=rolling_cv.version[0].id).read()
assert new_rolling_version != rolling_version
assert new_rolling_version.content_view.read() == rolling_cv
assert rolling_cv.version[0].read() == new_rolling_version
assert rolling_cv.environment == new_rolling_version.environment
assert new_rolling_version.version == '1.0'
assert new_rolling_version.major == 1
assert new_rolling_version.minor == 0
# check the new content (errata) is now present in version
assert new_rolling_version.yum_repository_count == 1
# TODO: fails, package counts not updated in rolling CVV
"""assert new_rolling_version.package_count > 0
assert new_rolling_version.package_group_count > 0"""
assert all(
[
new_rolling_version.errata_counts['security'],
new_rolling_version.errata_counts['total'],
]
)
# version's :id and some other attrs remain the same
assert new_rolling_version.id == rolling_version.id
assert new_rolling_version.name == rolling_version.name
assert new_rolling_version.version == rolling_version.version
assert new_rolling_version.description == rolling_version.description
assert new_rolling_version.environment == rolling_version.environment
assert new_rolling_version.content_view == rolling_version.content_view
@pytest.mark.upgrade
def test_positive_sync_repo_updates_rolling_content(
self, target_sat, module_org, module_product
):
"""When a repository associated to the rolling content view is synced with updated content,
the content contained within the rolling cv and version is updated as expected.
:id: 1a5f3b1c-2dcb-4e7b-8f3a-5c3e4f6d7e8f
:steps:
1) create a rolling cv with one un-synced custom repository
2) check the initial empty version for rolling cv
3) sync the repository, new content is present
4) check the updated version and content for rolling cv
:expectedresults:
1) The initial version of the rolling cv is empty.
2) After syncing the repository, the version of the rolling cv is updated with the new content.
:CaseImportance: Critical
"""
# create one repo, but do not sync it
repo = target_sat.api.Repository(
product=module_product, url=settings.repos.yum_6.url
).create()
# create rolling cv with the empty repo
rolling_cv = target_sat.api.ContentView(
organization=module_org, repository=[repo.read()], rolling=True
).create()
rolling_cv.environment = [module_org.library]
rolling_cv.update(['environment'])
rolling_cv = rolling_cv.read()
# initial version is empty
rolling_version = rolling_cv.version[0].read()
assert rolling_version.content_view.read() == rolling_cv
assert rolling_version.yum_repository_count == 1
assert rolling_version.version == '1.0'
assert rolling_version.package_count == 0
assert all(count == 0 for count in rolling_version.errata_counts.values())
# sync the repo
repo.sync()
repo = repo.read()
# list of single version remains unchanged
assert rolling_cv.read().version == rolling_cv.version
rolling_cv = rolling_cv.read()
new_rolling_version = rolling_cv.version[0].read()
# version updated is different but id and number is the same
assert new_rolling_version != rolling_version
assert new_rolling_version.id == rolling_version.id
assert new_rolling_version.name == rolling_version.name
assert new_rolling_version.content_view.read() == rolling_cv
assert new_rolling_version.yum_repository_count == 1
assert new_rolling_version.version == '1.0'
# packages and errata now present, match repo's content
# TODO: fails, expect matching counts
"""assert (
new_rolling_version.package_count == repo.content_counts['rpm']
)
assert new_rolling_version.package_group_count == repo.content_counts['package_group']
assert (
new_rolling_version.module_stream_count == repo.content_counts['module_stream']
)"""
assert new_rolling_version.errata_counts['total'] == repo.content_counts['erratum']
@pytest.mark.e2e
@pytest.mark.upgrade
def test_positive_add_remove_repos_from_rolling(
self, module_target_sat, module_sca_manifest_org, module_product
):
"""Can add and remove one or multiple repositories from the rolling content view.
We can remove the rolling cv from Library and delete it, with repos still added.
For RedHat and Custom repositories added.
:id: 623798f0-0974-4119-986e-a6b756e9d9d0
:setup:
1) An organization with uploaded Manifest.
2) A product for custom repos.
:steps:
1) Create and sync one custom repository, create a Rolling CV with it.
2) Create, sync and add additional custom repos to the Rolling CV via update.
3) Enable, sync and add two Red Hat repositories to the Rolling CV.
4) Remove a single RedHat repository from the Rolling CV.
5) Remove a single custom repository from the Rolling CV.
6) Delete the Rolling CV with custom and RH repos still added.
:expectedresults:
1) We can create a Rolling CV providing a repository.
2) We can add and remove Custom and RedHat repositories.
3) (SAT-37282) We can delete the Rolling CV with some repos still added to it.
:CaseImportance: High
:Verifies: SAT-37282
"""
org = module_sca_manifest_org
# Create and sync one custom repository, create a rolling cv with it
repo = module_target_sat.api.Repository(
product=module_product, url=settings.repos.yum_3.url
).create()
repo.sync()
rolling_cv = module_target_sat.api.ContentView(
organization=org, repository=[repo], rolling=True
).create()
# Create, sync and add additional custom repos to the Rolling CV via update
for _url in [settings.repos.yum_6.url, settings.repos.yum_9.url]:
repo = module_target_sat.api.Repository(product=module_product, url=_url).create()
repo.sync()
rolling_cv.repository.append(repo)
rolling_cv.update(['repository'])
rolling_cv = rolling_cv.read()
# Enable, sync and add two Red Hat repositories to the Rolling CV
rhel_major = settings.content_host.default_rhel_version
for repo_tail in ['bos', 'aps']:
_repo = f'rhel{rhel_major}_{repo_tail}' # 'rhel9_bos', 'rhel9_aps', etc
rh_repo_id = module_target_sat.api_factory.enable_sync_redhat_repo(
rh_repo=REPOS[f'{_repo}'],
org_id=org.id,
timeout=2400,
)
rh_repo = module_target_sat.api.Repository(id=rh_repo_id, organization=org).read()
rolling_cv.repository.append(rh_repo)
rolling_cv.update(['repository'])
rolling_cv = rolling_cv.read()
rolling_repos = deepcopy(rolling_cv.repository)
# Remove a single RedHat repository from the Rolling CV (tail)
_remove_this = rolling_cv.repository[-1]
rolling_cv.repository.remove(_remove_this)
rolling_cv.update(['repository'])
rolling_cv = rolling_cv.read()
assert _remove_this not in rolling_cv.repository
# Remove a single custom repository from the Rolling CV (head)
_remove_this = rolling_cv.repository[0]
rolling_cv.repository.remove(_remove_this)
rolling_cv.update(['repository'])
rolling_cv = rolling_cv.read()
assert _remove_this not in rolling_cv.repository
assert len(rolling_cv.repository) == len(rolling_repos) - 2
# Delete the Rolling CV with custom and RH repos still added
rolling_cv.delete()
# can't read the deleted cv
with pytest.raises(HTTPError):
rolling_cv.read()
# can still access repos
for repo in rolling_repos:
repo = repo.read()
repo.sync(timeout=2400)
def test_positive_multi_contentview(self, target_sat, module_org, module_product):
"""Can use the rolling content view with multiple published content views present.
:id: 5af10680-1c0c-47b7-98d3-dd9064be930f
:steps:
1) Create several Normal, Published content views with custom repositories.
2) Create several Rolling content views with different custom repositories.
3) Add a Rolling content view's repository to each Normal content view, publish them.
4) Add a Normal content view's repository to each Rolling content view.
:expectedresults:
1) Adding a Rolling CV's repository to a Normal CV did not change the Rolling CV or its Version.
2) Publishing the Normal CVs did not change the Rolling CV or its Version.
3) Adding a Normal CV's repository to a Rolling CV did not modify the Normal CVs,
but it updated the Rolling CV and its Version.
:caseimportance: High
"""
# TODO add assertions for content counts in-between key steps
normal_cv_urls = [
settings.repos.yum_0.url,
settings.repos.yum_1.url,
settings.repos.yum_2.url,
]
rolling_cv_urls = [
settings.repos.yum_3.url,
settings.repos.yum_6.url,
settings.repos.yum_9.url,
]
normal_repos = []