Skip to content

Commit c50a767

Browse files
hanwen-clusterhanwen-pcluste
authored andcommitted
[integ-test] Use the right partitions ARN
Signed-off-by: Hanwen <hanwenli@amazon.com>
1 parent 435a8d3 commit c50a767

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

cloudformation/ad/ad-integration.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,8 @@ Resources:
337337
Service: ec2.amazonaws.com
338338
Version: "2012-10-17"
339339
ManagedPolicyArns:
340-
- arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore
341-
- arn:aws:iam::aws:policy/AmazonSSMDirectoryServiceAccess
340+
- !Sub arn:${AWS::Partition}:iam::aws:policy/AmazonSSMManagedInstanceCore
341+
- !Sub arn:${AWS::Partition}:iam::aws:policy/AmazonSSMDirectoryServiceAccess
342342
Policies:
343343
- PolicyDocument:
344344
Statement:

tests/integration-tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,10 +1775,10 @@ def _open_zfs_volume_factory(root_volume_id, num_volumes=1):
17751775

17761776

17771777
@pytest.fixture(scope="class")
1778-
def snapshots_factory():
1778+
def snapshots_factory(region):
17791779
factory = EBSSnapshotsFactory()
17801780
yield factory
1781-
factory.release_all()
1781+
factory.release_all(region)
17821782

17831783

17841784
@pytest.fixture(scope="class")

tests/integration-tests/tests/createami/test_createami/test_build_image_custom_components/image.config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Build:
66
# Test script custom component with combination (ap-southeast-2, c5.xlarge, centos7) and (ap-southeast-2, c5.xlarge, ubuntu2004)
77
{% if region == "eu-west-1" %}
88
- Type: arn
9-
Value: arn:aws:imagebuilder:eu-west-1:aws:component/stig-build-linux-high/2024.2.3/1
9+
Value: arn:{{ partition }}:imagebuilder:{{ region }}:aws:component/stig-build-linux-high/2024.2.3/1
1010
{% else %}
1111
- Type: script
1212
Value: s3://{{ bucket_name }}/scripts/custom_script.sh

tests/integration-tests/tests/storage/snapshots_factory.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from fabric import Connection
1919
from retrying import retry
2020
from time_utils import minutes, seconds
21-
from utils import random_alphanumeric
21+
from utils import get_arn_partition, random_alphanumeric
2222

2323
SnapshotConfig = namedtuple("ClusterConfig", ["ssh_key", "key_name", "vpc_id", "head_node_subnet_id"])
2424

@@ -98,7 +98,7 @@ def _create_volume_process(self, region, snapshot_config):
9898

9999
# Create a new volume and attach to the instance
100100
self.volume = self._create_volume(subnet)
101-
self.instance = self._launch_instance(ami_id, subnet)
101+
self.instance = self._launch_instance(ami_id, subnet, region)
102102
self._attach_volume()
103103
# Open ssh connection
104104
self.ssh_conn = self._open_ssh_connection()
@@ -212,7 +212,7 @@ def _get_security_group_id(self):
212212

213213
return security_group_id
214214

215-
def _create_snapshot_instance_profile(self):
215+
def _create_snapshot_instance_profile(self, region):
216216
iam_resources_suffix = random_alphanumeric()
217217
snapshot_instance_role_name = f"SnapshotInstanceRole-{iam_resources_suffix}"
218218
snapshot_instance_profile_name = f"SnapshotInstanceProfile-{iam_resources_suffix}"
@@ -230,7 +230,8 @@ def _create_snapshot_instance_profile(self):
230230
)
231231
if not self._snapshot_instance_profile:
232232
self.iam.attach_role_policy(
233-
RoleName=snapshot_instance_role_name, PolicyArn="arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
233+
RoleName=snapshot_instance_role_name,
234+
PolicyArn=f"arn:{get_arn_partition(region)}:iam::aws:policy/AmazonSSMManagedInstanceCore",
234235
)
235236
logging.info("Creating profile (%s).", snapshot_instance_profile_name)
236237
self._snapshot_instance_profile = self.iam.create_instance_profile(
@@ -243,8 +244,8 @@ def _create_snapshot_instance_profile(self):
243244
InstanceProfileName=snapshot_instance_profile_name, RoleName=snapshot_instance_role_name
244245
)
245246

246-
def _launch_instance(self, ami_id, subnet):
247-
self._create_snapshot_instance_profile()
247+
def _launch_instance(self, ami_id, subnet, region):
248+
self._create_snapshot_instance_profile(region)
248249
instance = retry(stop_max_attempt_number=5, wait_fixed=minutes(1))(self.ec2_resource.create_instances)(
249250
ImageId=ami_id,
250251
KeyName=self.config.key_name,
@@ -290,10 +291,10 @@ def _get_amazonlinux2_ami(self):
290291
amis = sorted(response["Images"], key=lambda x: x["CreationDate"], reverse=True)
291292
return amis[0]["ImageId"]
292293

293-
def release_all(self):
294+
def release_all(self, region):
294295
"""Release all resources"""
295296
self._release_instance()
296-
self._release_instance_iam()
297+
self._release_instance_iam(region)
297298
self._release_security_group()
298299
self._release_volume()
299300
self._release_snapshot()
@@ -317,13 +318,14 @@ def _release_instance(self):
317318

318319
self.instance = None
319320

320-
def _release_instance_iam(self):
321+
def _release_instance_iam(self, region):
321322
instance_profile_name = self._snapshot_instance_profile["InstanceProfile"]["InstanceProfileName"]
322323
instance_role_name = self._snapshot_instance_role["Role"]["RoleName"]
323324
if self._snapshot_instance_role:
324325
role_name = self._snapshot_instance_role["Role"]["RoleName"]
325326
self.iam.detach_role_policy(
326-
RoleName=instance_role_name, PolicyArn="arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
327+
RoleName=instance_role_name,
328+
PolicyArn=f"arn:{get_arn_partition(region)}:iam::aws:policy/AmazonSSMManagedInstanceCore",
327329
)
328330
logging.info("Deleting role: %s", role_name)
329331
self.iam.remove_role_from_instance_profile(

0 commit comments

Comments
 (0)