12
12
from iib .workers .tasks import build
13
13
from iib .workers .tasks .utils import RequestConfigAddRm
14
14
from iib .workers .config import get_worker_config
15
+ from iib .common .pydantic_models import AddPydanticModel , RmPydanticModel
15
16
from operator_manifest .operator import ImageName
16
17
17
18
worker_config = get_worker_config ()
@@ -622,7 +623,9 @@ def test_buildah_fail_max_retries(mock_run_cmd: mock.MagicMock) -> None:
622
623
@mock .patch ('iib.workers.tasks.build._get_present_bundles' )
623
624
@mock .patch ('iib.workers.tasks.build.set_registry_token' )
624
625
@mock .patch ('iib.workers.tasks.build.is_image_fbc' )
626
+ @mock .patch ('iib.common.pydantic_models.binary_image_check' )
625
627
def test_handle_add_request (
628
+ mock_binary_image_check ,
626
629
mock_iifbc ,
627
630
mock_srt ,
628
631
mock_gpb ,
@@ -692,24 +695,24 @@ def side_effect(*args, base_dir, **kwargs):
692
695
mock_ors .return_value = (port , my_mock )
693
696
mock_run_cmd .return_value = '{"packageName": "package1", "version": "v1.0", \
694
697
"bundlePath": "bundle1"\n }'
695
-
696
- build .handle_add_request (
697
- bundles ,
698
- 3 ,
699
- binary_image ,
700
- 'from-index:latest' ,
701
- ['s390x' ],
702
- cnr_token ,
703
- organization ,
704
- force_backport ,
705
- False ,
706
- None ,
707
- None ,
708
- greenwave_config ,
709
- binary_image_config = binary_image_config ,
698
+ add_pydantic_model = AddPydanticModel .model_construct (
699
+ bundles = bundles ,
700
+ binary_image = binary_image ,
701
+ from_index = 'from_index:latest' ,
702
+ cnr_token = cnr_token ,
703
+ organization = organization ,
704
+ force_backport = force_backport ,
705
+ overwrite_from_index = False ,
706
+ overwrite_from_index_token = None ,
710
707
deprecation_list = deprecation_list ,
711
708
build_tags = ["extra_tag1" , "extra_tag2" ],
712
709
)
710
+ build .handle_add_request (
711
+ payload = add_pydantic_model ,
712
+ request_id = 3 ,
713
+ greenwave_config = greenwave_config ,
714
+ binary_image_config = binary_image_config ,
715
+ )
713
716
714
717
mock_ors .assert_called_once ()
715
718
mock_run_cmd .assert_called_once ()
@@ -778,21 +781,24 @@ def side_effect(*args, base_dir, **kwargs):
778
781
def test_handle_add_request_raises (mock_iifbc , mock_runcmd , mock_c ):
779
782
mock_iifbc .return_value = True
780
783
with pytest .raises (IIBError ):
781
- build . handle_add_request (
784
+ add_pydantic_model = AddPydanticModel . model_construct (
782
785
bundles = ['some-bundle:2.3-1' , 'some-deprecation-bundle:1.1-1' ],
783
- request_id = 3 ,
784
786
binary_image = 'binary-image:latest' ,
785
- from_index = 'from-index:latest' ,
786
787
add_arches = ['s390x' ],
788
+ from_index = 'from_index:latest' ,
787
789
cnr_token = 'token' ,
788
790
organization = 'org' ,
789
791
force_backport = True ,
790
792
overwrite_from_index = False ,
791
793
overwrite_from_index_token = None ,
792
794
distribution_scope = None ,
795
+ deprecation_list = [],
796
+ )
797
+ build .handle_add_request (
798
+ payload = add_pydantic_model ,
799
+ request_id = 3 ,
793
800
greenwave_config = {'some_key' : 'other_value' },
794
801
binary_image_config = {'prod' : {'v4.5' : 'some_image' }},
795
- deprecation_list = [],
796
802
)
797
803
798
804
@@ -897,21 +903,24 @@ def deprecate_bundles_mock(*args, **kwargs):
897
903
]
898
904
mock_sqlite .execute .return_value = 200
899
905
906
+ add_pydantic_model = AddPydanticModel .model_construct (
907
+ bundles = bundles ,
908
+ binary_image = 'binary-image:latest' ,
909
+ add_arches = ['s390x' ],
910
+ from_index = 'from_index:latest' ,
911
+ cnr_token = cnr_token ,
912
+ organization = organization ,
913
+ force_backport = True ,
914
+ overwrite_from_index = False ,
915
+ overwrite_from_index_token = None ,
916
+ distribution_scope = None ,
917
+ deprecation_list = deprecation_list ,
918
+ )
900
919
build .handle_add_request (
901
- bundles ,
902
- 3 ,
903
- 'binary-image:latest' ,
904
- 'from-index:latest' ,
905
- ['s390x' ],
906
- cnr_token ,
907
- organization ,
908
- True ,
909
- False ,
910
- None ,
911
- None ,
912
- greenwave_config ,
920
+ payload = add_pydantic_model ,
921
+ request_id = 3 ,
922
+ greenwave_config = greenwave_config ,
913
923
binary_image_config = binary_image_config ,
914
- deprecation_list = deprecation_list ,
915
924
)
916
925
917
926
mock_ors .assert_called_once ()
@@ -983,19 +992,21 @@ def test_handle_add_request_gating_failure(
983
992
organization = 'org'
984
993
greenwave_config = {'some_key' : 'other_value' }
985
994
with pytest .raises (IIBError , match = error_msg ):
995
+ add_pydantic_model = AddPydanticModel .model_construct (
996
+ bundles = bundles ,
997
+ binary_image = 'binary-image:latest' ,
998
+ add_arches = ['s390x' ],
999
+ from_index = 'from_index:latest' ,
1000
+ cnr_token = cnr_token ,
1001
+ organization = organization ,
1002
+ overwrite_from_index = False ,
1003
+ overwrite_from_index_token = None ,
1004
+ distribution_scope = None ,
1005
+ )
986
1006
build .handle_add_request (
987
- bundles ,
988
- 'binary-image:latest' ,
989
- 3 ,
990
- 'from-index:latest' ,
991
- ['s390x' ],
992
- cnr_token ,
993
- organization ,
994
- None ,
995
- False ,
996
- None ,
997
- None ,
998
- greenwave_config ,
1007
+ payload = add_pydantic_model ,
1008
+ request_id = 3 ,
1009
+ greenwave_config = greenwave_config ,
999
1010
)
1000
1011
assert mock_cleanup .call_count == 1
1001
1012
mock_srs2 .assert_called_once ()
@@ -1014,17 +1025,20 @@ def test_handle_add_request_bundle_resolution_failure(mock_grb, mock_srs, mock_c
1014
1025
organization = 'org'
1015
1026
greenwave_config = {'some_key' : 'other_value' }
1016
1027
with pytest .raises (IIBError , match = error_msg ):
1028
+ add_pydantic_model = AddPydanticModel .model_construct (
1029
+ bundles = bundles ,
1030
+ binary_image = 'binary-image:latest' ,
1031
+ add_arches = ['s390x' ],
1032
+ from_index = 'from_index:latest' ,
1033
+ cnr_token = cnr_token ,
1034
+ organization = organization ,
1035
+ force_backport = False ,
1036
+ overwrite_from_index = False ,
1037
+ overwrite_from_index_token = None ,
1038
+ )
1017
1039
build .handle_add_request (
1018
- bundles ,
1019
- 'binary-image:latest' ,
1020
- 3 ,
1021
- 'from-index:latest' ,
1022
- ['s390x' ],
1023
- cnr_token ,
1024
- organization ,
1025
- False ,
1026
- False ,
1027
- None ,
1040
+ payload = add_pydantic_model ,
1041
+ request_id = 3 ,
1028
1042
greenwave_config = greenwave_config ,
1029
1043
)
1030
1044
assert mock_cleanup .call_count == 1
@@ -1073,11 +1087,14 @@ def test_handle_rm_request(
1073
1087
'distribution_scope' : 'PROD' ,
1074
1088
}
1075
1089
binary_image_config = {'prod' : {'v4.6' : 'some_image' }}
1090
+ rm_pydantic_model = RmPydanticModel .model_construct (
1091
+ operators = ['some_operator' ],
1092
+ from_index = 'from-index:latest' ,
1093
+ binary_image = binary_image ,
1094
+ )
1076
1095
build .handle_rm_request (
1077
- ['some-operator' ],
1078
- 3 ,
1079
- 'from-index:latest' ,
1080
- binary_image ,
1096
+ payload = rm_pydantic_model ,
1097
+ request_id = 3 ,
1081
1098
binary_image_config = binary_image_config ,
1082
1099
)
1083
1100
@@ -1162,11 +1179,14 @@ def test_handle_rm_request_fbc(
1162
1179
mock_om .return_value = "/tmp/xyz/catalog"
1163
1180
mock_orrf .return_value = "/tmp/fbc_dir" , "/tmp/cache_dir"
1164
1181
mock_gcd .return_value = "/some/path"
1165
- build .handle_rm_request (
1166
- operators = ['some-operator' ],
1167
- request_id = 5 ,
1182
+ rm_pydantic_model = RmPydanticModel .model_construct (
1183
+ operators = ['some_operator' ],
1168
1184
from_index = 'from-index:latest' ,
1169
1185
binary_image = 'binary-image:latest' ,
1186
+ )
1187
+ build .handle_rm_request (
1188
+ payload = rm_pydantic_model ,
1189
+ request_id = 5 ,
1170
1190
binary_image_config = {'prod' : {'v4.6' : 'some_image' }},
1171
1191
)
1172
1192
mock_prfb .assert_called_once_with (
@@ -1446,9 +1466,8 @@ def test_handle_add_request_check_related_images_fail(
1446
1466
mock_grb .return_value = ['some-bundle@sha256:123' ]
1447
1467
mock_iri .side_effect = IIBError (error_msg )
1448
1468
with pytest .raises (IIBError , match = re .escape (error_msg )):
1449
- build . handle_add_request (
1469
+ add_pydantic_model = AddPydanticModel . model_construct (
1450
1470
bundles = bundles ,
1451
- request_id = 3 ,
1452
1471
binary_image = 'binary-image:latest' ,
1453
1472
from_index = 'from-index:latest' ,
1454
1473
add_arches = ['s390x' ],
@@ -1458,13 +1477,17 @@ def test_handle_add_request_check_related_images_fail(
1458
1477
overwrite_from_index = False ,
1459
1478
overwrite_from_index_token = None ,
1460
1479
distribution_scope = None ,
1461
- greenwave_config = None ,
1462
- binary_image_config = {'prod' : {'v4.5' : 'some_image' }},
1463
1480
deprecation_list = [],
1464
1481
build_tags = None ,
1465
1482
graph_update_mode = None ,
1466
1483
check_related_images = True ,
1467
1484
)
1485
+ build .handle_add_request (
1486
+ payload = add_pydantic_model ,
1487
+ request_id = 3 ,
1488
+ greenwave_config = None ,
1489
+ binary_image_config = {'prod' : {'v4.5' : 'some_image' }},
1490
+ )
1468
1491
assert mock_cleanup .call_count == 1
1469
1492
mock_srs .assert_called_once ()
1470
1493
mock_grb .assert_called_once_with (bundles )
0 commit comments