From f029fe672d2bc9c23fb5ae18ced2bb2f4fe78399 Mon Sep 17 00:00:00 2001 From: Bobby Impollonia Date: Thu, 4 Sep 2014 12:38:09 -0700 Subject: [PATCH] Add support for getting spot instance request tags --- moto/ec2/models.py | 2 +- moto/ec2/responses/spot_instances.py | 10 ++++++++++ tests/test_ec2/test_spot_instances.py | 21 +++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/moto/ec2/models.py b/moto/ec2/models.py index bab604890..b22d68fe9 100644 --- a/moto/ec2/models.py +++ b/moto/ec2/models.py @@ -1211,7 +1211,7 @@ class VPCGatewayAttachmentBackend(object): return attachment -class SpotInstanceRequest(BotoSpotRequest): +class SpotInstanceRequest(BotoSpotRequest, TaggedEC2Instance): def __init__(self, spot_request_id, price, image_id, type, valid_from, valid_until, launch_group, availability_zone_group, key_name, security_groups, user_data, instance_type, placement, kernel_id, diff --git a/moto/ec2/responses/spot_instances.py b/moto/ec2/responses/spot_instances.py index fd848093c..4bc9b943e 100644 --- a/moto/ec2/responses/spot_instances.py +++ b/moto/ec2/responses/spot_instances.py @@ -186,6 +186,16 @@ DESCRIBE_SPOT_INSTANCES_TEMPLATE = """ {% endif %} + + {% for tag in request.get_tags() %} + + {{ tag.resource_id }} + {{ tag.resource_type }} + {{ tag.key }} + {{ tag.value }} + + {% endfor %} + {% if request.launch_group %} {{ request.launch_group }} {% endif %} diff --git a/tests/test_ec2/test_spot_instances.py b/tests/test_ec2/test_spot_instances.py index a79b70e0a..d28b96b81 100644 --- a/tests/test_ec2/test_spot_instances.py +++ b/tests/test_ec2/test_spot_instances.py @@ -125,3 +125,24 @@ def test_request_spot_instances_fulfilled(): request = requests[0] request.state.should.equal("active") + + +@mock_ec2 +def test_tag_spot_instance_request(): + """ + Test that moto correctly tags a spot instance request + """ + conn = boto.connect_ec2() + + request = conn.request_spot_instances( + price=0.5, image_id='ami-abcd1234', + ) + request[0].add_tag('tag1', 'value1') + request[0].add_tag('tag2', 'value2') + + requests = conn.get_all_spot_instance_requests() + requests.should.have.length_of(1) + request = requests[0] + + tag_dict = dict(request.tags) + tag_dict.should.equal({'tag1' : 'value1', 'tag2' : 'value2'})