From 53fdf330ee05289879d427d65cf368fdda47d292 Mon Sep 17 00:00:00 2001 From: Peter Van Bouwel Date: Sat, 8 Nov 2014 12:12:20 +0100 Subject: [PATCH] Tests are added that verify that when a tag is being set on an (EBS) volume or on an instance that upon retrieval from the resource, the tag are set on the instance. Important is that the tags are set using create_tags but that the presence is validated by getting the resource using either (get_all_volumes or get_all_instances). When running the tests using nosetests it shows that the tags for the instances are correctly retrieved but the tags for the volume are missing --- tests/test_ec2/test_tags.py | 55 +++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/tests/test_ec2/test_tags.py b/tests/test_ec2/test_tags.py index 69bae7410..1dcb75d34 100644 --- a/tests/test_ec2/test_tags.py +++ b/tests/test_ec2/test_tags.py @@ -3,6 +3,7 @@ import itertools import boto from boto.exception import EC2ResponseError +from boto.ec2.instance import Reservation import sure # noqa from moto import mock_ec2 @@ -253,3 +254,57 @@ def test_get_all_tags_value_filter(): tags = conn.get_all_tags(filters={'value': '*value\*\?'}) tags.should.have.length_of(1) + + +@mock_ec2 +def test_create_tags_must_set_tags_on_retrieved_instances(): + tag_key = 'Tag name' + tag_value = 'Tag value' + tags_to_be_set = {tag_key: tag_value} + + conn = boto.connect_ec2('the_key', 'the_secret') + reservation = conn.run_instances('ami-1234abcd') + reservation.should.be.a(Reservation) + reservation.instances.should.have.length_of(1) + instance = reservation.instances[0] + + reservations = conn.get_all_instances() + reservations.should.have.length_of(1) + reservations[0].id.should.equal(reservation.id) + instances = reservations[0].instances + instances.should.have.length_of(1) + instances[0].id.should.equal(instance.id) + + conn.create_tags([instance.id], tags_to_be_set) + reservations = conn.get_all_instances() + instance = reservations[0].instances[0] + retrieved_tags = instance.tags + + #Cleanup of instance + conn.terminate_instances([instances[0].id]) + + #Check whether tag is present with correct value + retrieved_tags[tag_key].should.equal(tag_value) + + +@mock_ec2 +def test_create_tags_must_set_tags_on_retrieved_volumes(): + tag_key = 'Tag name' + tag_value = 'Tag value' + tags_to_be_set = {tag_key: tag_value} + conn = boto.connect_ec2('the_key', 'the_secret') + volume = conn.create_volume(80, "us-east-1a") + + all_volumes = conn.get_all_volumes() + volume = all_volumes[0] + conn.create_tags([volume.id], tags_to_be_set) + + #Fetch the volume again + all_volumes = conn.get_all_volumes() + volume = all_volumes[0] + retrieved_tags = volume.tags + + volume.delete() + + #Check whether tag is present with correct value + retrieved_tags[tag_key].should.equal(tag_value) \ No newline at end of file