From 8b523c3fe1e99c5af3fbe7db56ab4c46683a8ed0 Mon Sep 17 00:00:00 2001 From: khneal <40273388+khneal@users.noreply.github.com> Date: Fri, 23 Apr 2021 07:20:36 -0700 Subject: [PATCH] EMR and SWF - add arn to response (#3873) * emr: add ClusterArn to describe_cluster response * emr: add ClusterArn to list_clusters response * emr: add ClusterArn to put_auto_scaling_policy response * emr: add ClusterArn to run_job_flow response * emr: rename property "cluster_arn" to simply "arn" * emr: generalize arn for account_id and region * swf: add arn to list_domains response * black reformat source code * fix double import * swf: require region on Domain object Co-authored-by: Kevin Neal --- moto/emr/models.py | 8 ++++++- moto/emr/responses.py | 9 ++++++- moto/swf/models/__init__.py | 7 +++++- moto/swf/models/domain.py | 8 +++++-- tests/test_emr/test_emr_boto3.py | 30 +++++++++++++++++++----- tests/test_swf/models/test_domain.py | 26 +++++++++++++------- tests/test_swf/responses/test_domains.py | 4 ++++ tests/test_swf/utils.py | 2 +- 8 files changed, 73 insertions(+), 21 deletions(-) diff --git a/moto/emr/models.py b/moto/emr/models.py index 1f2459d6..6f9963df 100644 --- a/moto/emr/models.py +++ b/moto/emr/models.py @@ -7,7 +7,7 @@ import warnings import pytz from boto3 import Session from dateutil.parser import parse as dtparse -from moto.core import BaseBackend, BaseModel +from moto.core import ACCOUNT_ID, BaseBackend, BaseModel from moto.emr.exceptions import EmrError, InvalidRequestException from .utils import ( random_instance_group_id, @@ -272,6 +272,12 @@ class FakeCluster(BaseModel): ) self.kerberos_attributes = kerberos_attributes + @property + def arn(self): + return "arn:aws:elasticmapreduce:{0}:{1}:cluster/{2}".format( + self.emr_backend.region_name, ACCOUNT_ID, self.id + ) + @property def instance_groups(self): return self.emr_backend.get_instance_groups(self.instance_group_ids) diff --git a/moto/emr/responses.py b/moto/emr/responses.py index 3eaa3b49..9ef59364 100644 --- a/moto/emr/responses.py +++ b/moto/emr/responses.py @@ -529,13 +529,16 @@ class ElasticMapReduceResponse(BaseResponse): @generate_boto3_response("PutAutoScalingPolicy") def put_auto_scaling_policy(self): cluster_id = self._get_param("ClusterId") + cluster = self.backend.get_cluster(cluster_id) instance_group_id = self._get_param("InstanceGroupId") auto_scaling_policy = self._get_param("AutoScalingPolicy") instance_group = self.backend.put_auto_scaling_policy( instance_group_id, auto_scaling_policy ) template = self.response_template(PUT_AUTO_SCALING_POLICY) - return template.render(cluster_id=cluster_id, instance_group=instance_group) + return template.render( + cluster_id=cluster_id, cluster=cluster, instance_group=instance_group + ) @generate_boto3_response("RemoveAutoScalingPolicy") def remove_auto_scaling_policy(self): @@ -691,6 +694,7 @@ DESCRIBE_CLUSTER_TEMPLATE = """ {{ cluster.id }} + {{ cluster.arn }} 8296d8b8-ed85-11dd-9877-6fad448a8419 @@ -1378,6 +1384,7 @@ PUT_AUTO_SCALING_POLICY = """