FIX:Ec2:Added:Tags for EIP (#3505)

* FIX:Ec2:Added:Tags for EIP

* removed files

* Fix tests
This commit is contained in:
usmangani1 2020-12-06 05:34:46 +05:30 committed by GitHub
parent 8f83f51897
commit cfaaa70ea9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 1 deletions

View File

@ -226,7 +226,9 @@ class StateReason(object):
class TaggedEC2Resource(BaseModel):
def get_tags(self, *args, **kwargs):
tags = self.ec2_backend.describe_tags(filters={"resource-id": [self.id]})
tags = []
if self.id:
tags = self.ec2_backend.describe_tags(filters={"resource-id": [self.id]})
return tags
def add_tag(self, key, value):

View File

@ -151,6 +151,16 @@ DESCRIBE_ADDRESS_RESPONSE = """<DescribeAddressesResponse xmlns="http://ec2.amaz
{% if address.association_id %}
<associationId>{{ address.association_id }}</associationId>
{% endif %}
<tagSet>
{% for tag in address.get_tags() %}
<item>
<resourceId>{{ tag.resource_id }}</resourceId>
<resourceType>{{ tag.resource_type }}</resourceType>
<key>{{ tag.key }}</key>
<value>{{ tag.value }}</value>
</item>
{% endfor %}
</tagSet>
</item>
{% endfor %}
</addressesSet>

View File

@ -581,3 +581,18 @@ def test_eip_tags():
)
# Expected total is 2, one with and one without tags
len(addresses).should.equal(2)
@mock_ec2
def test_describe_addresses_tags():
client = boto3.client("ec2", region_name="us-west-1")
alloc_tags = client.allocate_address(Domain="vpc")
client.create_tags(
Resources=[alloc_tags["AllocationId"]],
Tags=[{"Key": "ManagedBy", "Value": "MyCode"}],
)
addresses_with_tags = client.describe_addresses()
assert addresses_with_tags.get("Addresses")[0].get("Tags") == [
{"Key": "ManagedBy", "Value": "MyCode"}
]