From 597676c59c229819b3da1abaaeb48a3020374e13 Mon Sep 17 00:00:00 2001 From: dbfr3qs Date: Mon, 15 Jan 2018 21:52:32 +1300 Subject: [PATCH 1/2] add tags when creating ebs volume --- moto/ec2/responses/elastic_block_store.py | 13 ++++++++++++ tests/test_ec2/test_tags.py | 26 ++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/moto/ec2/responses/elastic_block_store.py b/moto/ec2/responses/elastic_block_store.py index 37b3e9a07..333642247 100644 --- a/moto/ec2/responses/elastic_block_store.py +++ b/moto/ec2/responses/elastic_block_store.py @@ -32,10 +32,13 @@ class ElasticBlockStore(BaseResponse): size = self._get_param('Size') zone = self._get_param('AvailabilityZone') snapshot_id = self._get_param('SnapshotId') + tags = self._parse_tag_specification("TagSpecification") + volume_tags = tags.get('image', {}) encrypted = self._get_param('Encrypted', if_none=False) if self.is_not_dryrun('CreateVolume'): volume = self.ec2_backend.create_volume( size, zone, snapshot_id, encrypted) + volume.add_tags(volume_tags) template = self.response_template(CREATE_VOLUME_RESPONSE) return template.render(volume=volume) @@ -139,6 +142,16 @@ CREATE_VOLUME_RESPONSE = """ Date: Thu, 18 Jan 2018 19:40:24 +1300 Subject: [PATCH 2/2] hack tests now that boto get_templates returns ordered dicts --- .../test_cloudformation_stack_crud_boto3.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/test_cloudformation/test_cloudformation_stack_crud_boto3.py b/tests/test_cloudformation/test_cloudformation_stack_crud_boto3.py index 1f3bfdec7..781e89e2b 100644 --- a/tests/test_cloudformation/test_cloudformation_stack_crud_boto3.py +++ b/tests/test_cloudformation/test_cloudformation_stack_crud_boto3.py @@ -160,7 +160,7 @@ def test_boto3_create_stack(): TemplateBody=dummy_template_json, ) - cf_conn.get_template(StackName="test_stack")['TemplateBody'].should.equal( + json.loads(json.dumps(cf_conn.get_template(StackName="test_stack")['TemplateBody'])).should.equal( dummy_template) @@ -270,9 +270,10 @@ def test_create_stack_from_s3_url(): StackName='stack_from_url', TemplateURL=key_url, ) - - cf_conn.get_template(StackName="stack_from_url")[ - 'TemplateBody'].should.equal(dummy_template) + # from IPython import embed + # embed() + json.loads(json.dumps(cf_conn.get_template(StackName="stack_from_url")[ + 'TemplateBody'])).should.equal(dummy_template) @mock_cloudformation @@ -306,8 +307,8 @@ def test_update_stack_from_s3_url(): TemplateURL=key_url, ) - cf_conn.get_template(StackName="update_stack_from_url")[ - 'TemplateBody'].should.equal(dummy_update_template) + json.loads(json.dumps(cf_conn.get_template(StackName="update_stack_from_url")[ + 'TemplateBody'])).should.equal(dummy_update_template) @mock_cloudformation