-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Weisu Yin
authored
Mar 17, 2023
1 parent
ca3d2f4
commit bf44dac
Showing
3 changed files
with
81 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import boto3 | ||
from moto import mock_iam | ||
|
||
from autogluon.cloud.utils.iam import ( | ||
add_role_to_instance_profile, | ||
attach_iam_policy, | ||
create_iam_policy, | ||
create_iam_role, | ||
create_instance_profile, | ||
) | ||
|
||
|
||
@mock_iam | ||
def test_iam_utils(): | ||
iam_client = boto3.client("iam") | ||
dummy_role = "dummy_role" | ||
dummy_trust_relationship = {} | ||
dummy_role_arn = create_iam_role(dummy_role, dummy_trust_relationship) | ||
assert dummy_role_arn is not None | ||
create_iam_role(dummy_role, dummy_trust_relationship) # check for recreation | ||
dummy_policy = { | ||
"Version": "2012-10-17", | ||
"Statement": [{"Effect": "Allow", "Action": "none:null", "Resource": "*"}], | ||
} | ||
dummy_policy_arn = create_iam_policy("dommy_policy", dummy_policy) | ||
assert dummy_policy_arn is not None | ||
attach_iam_policy(dummy_role, dummy_policy_arn) | ||
attached_policy = iam_client.list_attached_role_policies(RoleName=dummy_role)["AttachedPolicies"] | ||
assert attached_policy[0]["PolicyArn"] == dummy_policy_arn | ||
dummy_instance_profile = "dummy_instance_profile" | ||
create_instance_profile(dummy_instance_profile) | ||
add_role_to_instance_profile(dummy_instance_profile, dummy_role) | ||
instance_profile = iam_client.get_instance_profile(InstanceProfileName=dummy_instance_profile)["InstanceProfile"] | ||
assert instance_profile["Roles"][0]["Arn"] == dummy_role_arn |