@@ -864,3 +864,69 @@ def command_call(_: str):
864864 assert len (roles ) == 1
865865 assert len (roles [0 ].paths ) == 2
866866 external_locations .snapshot .assert_called_once ()
867+
868+
869+ def test_delete_uc_roles (mock_ws , installation_multiple_roles , backend , locations ):
870+ aws = create_autospec (AWSResources )
871+ aws .validate_connection .return_value = {}
872+ aws_resource_permissions = AWSResourcePermissions (installation_multiple_roles , mock_ws , aws , locations )
873+ mock_ws .storage_credentials .list .return_value = [
874+ StorageCredentialInfo (
875+ id = "1" ,
876+ name = "cred1" ,
877+ aws_iam_role = AwsIamRoleResponse ("arn:aws:iam::12345:role/uc-role1" ),
878+ )
879+ ]
880+ role_creation = IamRoleCreation (installation_multiple_roles , mock_ws , aws_resource_permissions )
881+ prompts = MockPrompts ({"Select the list of roles *" : "1" , "The above storage credential will be impacted *" : "Yes" })
882+ role_creation .delete_uc_roles (prompts )
883+ calls = [call ("uc-role1" ), call ("uc-rolex" )]
884+ assert aws .delete_role .mock_calls == calls
885+
886+
887+ def test_delete_uc_roles_not_present (mock_ws , installation_no_roles , backend , locations ):
888+ aws = create_autospec (AWSResources )
889+ aws .validate_connection .return_value = {}
890+ aws .delete_role .return_value = []
891+ aws_resource_permissions = AWSResourcePermissions (installation_no_roles , mock_ws , aws , locations )
892+ mock_ws .storage_credentials .list .return_value = [
893+ StorageCredentialInfo (
894+ id = "1" ,
895+ name = "cred1" ,
896+ aws_iam_role = AwsIamRoleResponse ("arn:aws:iam::12345:role/uc-role1" ),
897+ )
898+ ]
899+ role_creation = IamRoleCreation (installation_no_roles , mock_ws , aws_resource_permissions )
900+ aws .list_all_uc_roles .return_value = [AWSRole ("" , "uc-role1" , "123" , "arn:aws:iam::12345:role/uc-role1" )]
901+ aws .get_role_policy .side_effect = [
902+ [
903+ AWSPolicyAction (
904+ resource_type = "s3" ,
905+ privilege = "READ_FILES" ,
906+ resource_path = "s3://bucket1" ,
907+ )
908+ ]
909+ ]
910+ aws .list_role_policies .return_value = ["Policy1" ]
911+ aws .list_all_uc_roles .return_value = [
912+ AWSRole (path = '/' , role_name = 'uc-role1' , role_id = '12345' , arn = 'arn:aws:iam::12345:role/uc-role1' )
913+ ]
914+ prompts = MockPrompts ({"Select the list of roles *" : "1" , "The above storage credential will be impacted *" : "Yes" })
915+ role_creation .delete_uc_roles (prompts )
916+ calls = [call ("uc-role1" )]
917+ assert aws .delete_role .mock_calls == calls
918+
919+
920+ def test_delete_role (mock_ws , installation_no_roles , backend , mocker ):
921+ command_calls = []
922+ mocker .patch ("shutil.which" , return_value = "/path/aws" )
923+
924+ def command_call (cmd : str ):
925+ command_calls .append (cmd )
926+ return 0 , '{"account":"1234"}' , ""
927+
928+ aws = AWSResources ("profile" , command_call )
929+ external_locations = ExternalLocations (mock_ws , backend , 'ucx' )
930+ resource_permissions = AWSResourcePermissions (installation_no_roles , mock_ws , aws , external_locations )
931+ resource_permissions .delete_uc_role ("uc_role_1" )
932+ assert '/path/aws iam delete-role --role-name uc_role_1 --profile profile --output json' in command_calls
0 commit comments