Merge pull request #2631 from kislyuk/patch-2

Batch: computeResources.instanceRole is an instance profile
This commit is contained in:
Mike Grima 2019-12-14 13:46:08 -08:00 committed by GitHub
commit 7b63b2818e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 7 deletions

View File

@ -854,8 +854,10 @@ class BatchBackend(BaseBackend):
raise InvalidParameterValueException(
"computeResources must contain {0}".format(param)
)
if self.iam_backend.get_role_by_arn(cr["instanceRole"]) is None:
for profile in self.iam_backend.get_instance_profiles():
if profile.arn == cr["instanceRole"]:
break
else:
raise InvalidParameterValueException(
"could not find instanceRole {0}".format(cr["instanceRole"])
)

View File

@ -55,6 +55,10 @@ def _setup(ec2_client, iam_client):
RoleName="TestRole", AssumeRolePolicyDocument="some_policy"
)
iam_arn = resp["Role"]["Arn"]
iam_client.create_instance_profile(InstanceProfileName="TestRole")
iam_client.add_role_to_instance_profile(
InstanceProfileName="TestRole", RoleName="TestRole"
)
return vpc_id, subnet_id, sg_id, iam_arn
@ -83,7 +87,7 @@ def test_create_managed_compute_environment():
"subnets": [subnet_id],
"securityGroupIds": [sg_id],
"ec2KeyPair": "string",
"instanceRole": iam_arn,
"instanceRole": iam_arn.replace("role", "instance-profile"),
"tags": {"string": "string"},
"bidPercentage": 123,
"spotIamFleetRole": "string",
@ -209,7 +213,7 @@ def test_delete_managed_compute_environment():
"subnets": [subnet_id],
"securityGroupIds": [sg_id],
"ec2KeyPair": "string",
"instanceRole": iam_arn,
"instanceRole": iam_arn.replace("role", "instance-profile"),
"tags": {"string": "string"},
"bidPercentage": 123,
"spotIamFleetRole": "string",

View File

@ -51,6 +51,10 @@ def _setup(ec2_client, iam_client):
RoleName="TestRole", AssumeRolePolicyDocument="some_policy"
)
iam_arn = resp["Role"]["Arn"]
iam_client.create_instance_profile(InstanceProfileName="TestRole")
iam_client.add_role_to_instance_profile(
InstanceProfileName="TestRole", RoleName="TestRole"
)
return vpc_id, subnet_id, sg_id, iam_arn
@ -78,7 +82,7 @@ def test_create_env_cf():
"InstanceTypes": ["optimal"],
"Subnets": [subnet_id],
"SecurityGroupIds": [sg_id],
"InstanceRole": iam_arn,
"InstanceRole": iam_arn.replace("role", "instance-profile"),
},
"ServiceRole": iam_arn,
},
@ -129,7 +133,7 @@ def test_create_job_queue_cf():
"InstanceTypes": ["optimal"],
"Subnets": [subnet_id],
"SecurityGroupIds": [sg_id],
"InstanceRole": iam_arn,
"InstanceRole": iam_arn.replace("role", "instance-profile"),
},
"ServiceRole": iam_arn,
},
@ -195,7 +199,7 @@ def test_create_job_def_cf():
"InstanceTypes": ["optimal"],
"Subnets": [subnet_id],
"SecurityGroupIds": [sg_id],
"InstanceRole": iam_arn,
"InstanceRole": iam_arn.replace("role", "instance-profile"),
},
"ServiceRole": iam_arn,
},