@@ -86,7 +86,12 @@ def _compare_change(source, target):
8686 def _sorting_func (change ):
8787 if change .is_list :
8888 if isinstance (change .new_value , dict ):
89- return change .new_value ["Name" ]
89+ if "Key" in change .new_value :
90+ return change .new_value ["Key" ]
91+ elif "Name" in change .new_value :
92+ return change .new_value ["Name" ]
93+ else :
94+ return "-"
9095 else :
9196 return "-"
9297 else :
@@ -1133,3 +1138,114 @@ def test_patch_check_cluster_resource_bucket(
11331138 line = ["{0}" .format (element ) if isinstance (element , str ) else element for element in line ]
11341139 assert_that (expected_message_rows ).contains (line )
11351140 assert_that (patch_allowed ).is_equal_to (not expected_error_row )
1141+
1142+
1143+ @pytest .mark .parametrize (
1144+ "base_tags, target_tags, expected_changes, expected_policy" ,
1145+ [
1146+ pytest .param (
1147+ [{"Key" : "test1" , "Value" : "val1" }, {"Key" : "test2" , "Value" : "val2" }],
1148+ [{"Key" : "test2" , "Value" : "val2" }, {"Key" : "test1" , "Value" : "val1" }],
1149+ [
1150+ Change (
1151+ [],
1152+ "Tags" ,
1153+ [{"Key" : "test1" , "Value" : "val1" }, {"Key" : "test2" , "Value" : "val2" }],
1154+ [{"Key" : "test2" , "Value" : "val2" }, {"Key" : "test1" , "Value" : "val1" }],
1155+ UpdatePolicy .UNSUPPORTED_ORDER_CHANGE ,
1156+ is_list = True ,
1157+ )
1158+ ],
1159+ UpdatePolicy .UNSUPPORTED_ORDER_CHANGE ,
1160+ id = "order_only_change" ,
1161+ ),
1162+ pytest .param (
1163+ [{"Key" : "test1" , "Value" : "val1" }, {"Key" : "test2" , "Value" : "val2" }],
1164+ [{"Key" : "test1" , "Value" : "val1" }, {"Key" : "test2" , "Value" : "val2" }, {"Key" : "test3" , "Value" : "val3" }],
1165+ [
1166+ Change (
1167+ [],
1168+ "Tags" ,
1169+ None ,
1170+ {"Key" : "test3" , "Value" : "val3" },
1171+ UpdatePolicy .UNSUPPORTED ,
1172+ is_list = True ,
1173+ )
1174+ ],
1175+ UpdatePolicy .UNSUPPORTED ,
1176+ id = "tag_addition" ,
1177+ ),
1178+ pytest .param (
1179+ [{"Key" : "test1" , "Value" : "val1" }, {"Key" : "test2" , "Value" : "val2" }],
1180+ [{"Key" : "test1" , "Value" : "val1" }],
1181+ [
1182+ Change (
1183+ [],
1184+ "Tags" ,
1185+ {"Key" : "test2" , "Value" : "val2" },
1186+ None ,
1187+ UpdatePolicy .UNSUPPORTED ,
1188+ is_list = True ,
1189+ )
1190+ ],
1191+ UpdatePolicy .UNSUPPORTED ,
1192+ id = "tag_removal" ,
1193+ ),
1194+ pytest .param (
1195+ [{"Key" : "test1" , "Value" : "old_value" }],
1196+ [{"Key" : "test1" , "Value" : "new_value" }],
1197+ [
1198+ Change (
1199+ ["Tags[test1]" ],
1200+ "Value" ,
1201+ "old_value" ,
1202+ "new_value" ,
1203+ UpdatePolicy .UNSUPPORTED ,
1204+ is_list = False ,
1205+ )
1206+ ],
1207+ UpdatePolicy .UNSUPPORTED ,
1208+ id = "tag_value_modification" ,
1209+ ),
1210+ pytest .param (
1211+ [{"Key" : "test1" , "Value" : "val1" }, {"Key" : "test2" , "Value" : "val2" }],
1212+ [{"Key" : "test3" , "Value" : "val3" }, {"Key" : "test2" , "Value" : "val2" }, {"Key" : "test1" , "Value" : "val1" }],
1213+ [
1214+ Change (
1215+ [],
1216+ "Tags" ,
1217+ None ,
1218+ {"Key" : "test3" , "Value" : "val3" },
1219+ UpdatePolicy .UNSUPPORTED ,
1220+ is_list = True ,
1221+ )
1222+ ],
1223+ UpdatePolicy .UNSUPPORTED ,
1224+ id = "order_change_plus_addition" ,
1225+ ),
1226+ pytest .param (
1227+ [{"Key" : "test1" , "Value" : "val1" }, {"Key" : "test2" , "Value" : "val2" }],
1228+ [{"Key" : "test1" , "Value" : "val1" }, {"Key" : "test2" , "Value" : "val2" }],
1229+ [],
1230+ UpdatePolicy .SUPPORTED ,
1231+ id = "no_change_identical_tags" ,
1232+ ),
1233+ ],
1234+ )
1235+ def test_tag_updates (
1236+ mocker , test_datadir , pcluster_config_reader , base_tags , target_tags , expected_changes , expected_policy
1237+ ):
1238+ """Test various tag update scenarios including order changes, additions, and modifications."""
1239+ mock_aws_api (mocker )
1240+ dst_config_file = "pcluster.config.dst.yaml"
1241+ _duplicate_config_file (dst_config_file , test_datadir )
1242+
1243+ src_dict = {"tags" : base_tags }
1244+ src_config_file = pcluster_config_reader (** src_dict )
1245+ src_conf = _load_config (src_config_file )
1246+
1247+ dst_dict = {"tags" : target_tags }
1248+ dst_config_file = pcluster_config_reader (dst_config_file , ** dst_dict )
1249+ dst_conf = _load_config (dst_config_file )
1250+
1251+ _check_patch (src_conf .source_config , dst_conf .source_config , expected_changes , expected_policy )
0 commit comments