Skip to content

Conversation

@hanwen-pcluste
Copy link
Contributor

This PR will complete the leftover from #2304. In that PR, we duplicated code for IAM policies, IAM roles creation. We didn't clean up the duplication to limit the scale of that PR.
Moreover, this PR will scope the fixtures for IAM policies, IAM roles, KMS keys to session, allowing reusing of the resources across tests. Note that the resources are not reused across parallel test runs.

This PR is verified by the following integration tests:

test-suites:
  storage:
    test_ebs.py::test_ebs_single:
      dimensions:
        - regions: ["eu-west-3"]
          instances: {{ common.INSTANCES_DEFAULT_X86 }}
          oss: ["centos7", "centos8"]
          schedulers: ["sge"]
  iam:
    test_iam.py::test_iam_roles:
      dimensions:
        - regions: ["us-east-2"]
          schedulers: ["awsbatch", "slurm", "sge"]
          oss: ["alinux2"]
          instances: {{ common.INSTANCES_DEFAULT_X86 }}

Signed-off-by: Hanwen hanwenli@amazon.com

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@codecov
Copy link

codecov bot commented Dec 21, 2020

Codecov Report

Merging #2325 (48b84ee) into develop (df73a35) will increase coverage by 0.05%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2325      +/-   ##
===========================================
+ Coverage    61.77%   61.83%   +0.05%     
===========================================
  Files           40       40              
  Lines         6180     6186       +6     
===========================================
+ Hits          3818     3825       +7     
+ Misses        2362     2361       -1     
Impacted Files Coverage Δ
cli/src/pcluster/utils.py 67.47% <0.00%> (+0.48%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update df73a35...48b84ee. Read the comment docs.

@hanwen-pcluste hanwen-pcluste added the skip-changelog-update Disables the check that enforces changelog updates in PRs label Dec 21, 2020
@hanwen-pcluste hanwen-pcluste force-pushed the develop branch 3 times, most recently from c0f9c49 to 48b84ee Compare December 21, 2020 15:37
Copy link
Contributor

@chenwany chenwany left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have been test_ebs_single be tested with different schedulers?

assert_that(target["IpRanges"][0]["CidrIp"]).is_equal_to(expected_cidr)


def get_arn_partition(region):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a function in our code, get_partition(), can we simplify our code here like that?
def get_partition():

    """Get partition for the AWS_DEFAULT_REGION set in the environment."""
    region = get_region()
    return next(("aws-" + partition for partition in ["us-gov", "cn"] if region.startswith(partition)), "aws")

user_iam_role = self.role_factory(
region, "ec2", [policies["awsbatch_instance_policy"], policies["traditional_instance_policy"]]
)
self.kms_key_id = self._create_kms_key(region, user_iam_role)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You define self.kms_key_id here, why removing self.kms_key_id = None in __init__?

region, "ec2", [policies["awsbatch_instance_policy"], policies["traditional_instance_policy"]]
)
self.kms_key_id = self._create_kms_key(region, user_iam_role)
self.key_and_role_by_region[region] = (self.kms_key_id, user_iam_role)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: it will be more clear for me to understand it is the combination of key id and role name if we name it self.key_id_and_role_by_region, since we have lots of role arn, role name, key name, key id here

env = Environment(loader=file_loader, trim_blocks=True, lstrip_blocks=True)
key_policy = env.get_template("key_policy.json").render(
partition=self.partition, account_id=self.account_id, iam_role_name=self.iam_role
partition=partition, account_id=account_id, iam_role_name=user_iam_role
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: we can write here as partition=get_arn_partition(region) and remove line 64

iam_client.detach_role_policy(RoleName=role_name, PolicyArn=policy)
logging.info(f"Deleting iam role {role_name}")
iam_client.delete_role(RoleName=role_name)
time.sleep(60)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a explanation for the time.sleep here?

@hanwen-pcluste hanwen-pcluste marked this pull request as draft January 5, 2021 17:41
@hanwen-pcluste hanwen-pcluste marked this pull request as ready for review January 5, 2021 17:41
@hanwen-pcluste hanwen-pcluste marked this pull request as draft January 5, 2021 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-changelog-update Disables the check that enforces changelog updates in PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants