Extend the DESCRIBE_SNAPSHOTS_RESPONSE to include the tagSet as documented by AWS. Also refactor the names of the tests I introduced in previous commits to be more descriptive. Finally some code cleanup, removing the get_tags method from classes and instead inherit from the TaggedEC2Resource class.
This commit is contained in:
		
							parent
							
								
									17356fe56c
								
							
						
					
					
						commit
						2f1f993793
					
				| @ -109,7 +109,7 @@ class StateReason(object): | |||||||
| 
 | 
 | ||||||
| class TaggedEC2Resource(object): | class TaggedEC2Resource(object): | ||||||
|     def get_tags(self, *args, **kwargs): |     def get_tags(self, *args, **kwargs): | ||||||
|         tags = self.ec2_backend.describe_tags(filters={'resource-id': [self.id]}) |         tags = ec2_backend.describe_tags(filters={'resource-id': [self.id]}) | ||||||
|         return tags |         return tags | ||||||
| 
 | 
 | ||||||
|     def get_filter_value(self, filter_name): |     def get_filter_value(self, filter_name): | ||||||
| @ -383,10 +383,6 @@ class Instance(BotoInstance, TaggedEC2Resource): | |||||||
|         self._reason = "" |         self._reason = "" | ||||||
|         self._state_reason = StateReason() |         self._state_reason = StateReason() | ||||||
| 
 | 
 | ||||||
|     def get_tags(self): |  | ||||||
|         tags = self.ec2_backend.describe_tags(filters={'resource-id': [self.id]}) |  | ||||||
|         return tags |  | ||||||
| 
 |  | ||||||
|     @property |     @property | ||||||
|     def dynamic_group_list(self): |     def dynamic_group_list(self): | ||||||
|         if self.nics: |         if self.nics: | ||||||
| @ -1227,7 +1223,7 @@ class VolumeAttachment(object): | |||||||
|         return attachment |         return attachment | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class Volume(object): | class Volume(TaggedEC2Resource): | ||||||
|     def __init__(self, volume_id, size, zone): |     def __init__(self, volume_id, size, zone): | ||||||
|         self.id = volume_id |         self.id = volume_id | ||||||
|         self.size = size |         self.size = size | ||||||
| @ -1255,12 +1251,8 @@ class Volume(object): | |||||||
|         else: |         else: | ||||||
|             return 'available' |             return 'available' | ||||||
| 
 | 
 | ||||||
|     def get_tags(self): |  | ||||||
|         tags = ec2_backend.describe_tags(filters={'resource-id': [self.id]}) |  | ||||||
|         return tags |  | ||||||
| 
 | 
 | ||||||
| 
 | class Snapshot(TaggedEC2Resource): | ||||||
| class Snapshot(object): |  | ||||||
|     def __init__(self, snapshot_id, volume, description): |     def __init__(self, snapshot_id, volume, description): | ||||||
|         self.id = snapshot_id |         self.id = snapshot_id | ||||||
|         self.volume = volume |         self.volume = volume | ||||||
|  | |||||||
| @ -197,6 +197,14 @@ DESCRIBE_SNAPSHOTS_RESPONSE = """<DescribeSnapshotsResponse xmlns="http://ec2.am | |||||||
|              <volumeSize>{{ snapshot.volume.size }}</volumeSize> |              <volumeSize>{{ snapshot.volume.size }}</volumeSize> | ||||||
|              <description>{{ snapshot.description }}</description> |              <description>{{ snapshot.description }}</description> | ||||||
|              <tagSet> |              <tagSet> | ||||||
|  |                {% for tag in snapshot.get_tags() %} | ||||||
|  |                  <item> | ||||||
|  |                    <resourceId>{{ tag.resource_id }}</resourceId> | ||||||
|  |                    <resourceType>{{ tag.resource_type }}</resourceType> | ||||||
|  |                    <key>{{ tag.key }}</key> | ||||||
|  |                    <value>{{ tag.value }}</value> | ||||||
|  |                  </item> | ||||||
|  |                {% endfor %} | ||||||
|              </tagSet> |              </tagSet> | ||||||
|           </item> |           </item> | ||||||
|       {% endfor %} |       {% endfor %} | ||||||
|  | |||||||
| @ -257,7 +257,7 @@ def test_get_all_tags_value_filter(): | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @mock_ec2 | @mock_ec2 | ||||||
| def test_create_tags_must_set_tags_on_retrieved_instances(): | def test_retrieved_instances_must_contain_their_tags(): | ||||||
|     tag_key = 'Tag name' |     tag_key = 'Tag name' | ||||||
|     tag_value = 'Tag value' |     tag_value = 'Tag value' | ||||||
|     tags_to_be_set = {tag_key: tag_value} |     tags_to_be_set = {tag_key: tag_value} | ||||||
| @ -288,7 +288,7 @@ def test_create_tags_must_set_tags_on_retrieved_instances(): | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @mock_ec2 | @mock_ec2 | ||||||
| def test_create_tags_must_set_tags_on_retrieved_volumes(): | def test_retrieved_volumes_must_contain_their_tags(): | ||||||
|     tag_key = 'Tag name' |     tag_key = 'Tag name' | ||||||
|     tag_value = 'Tag value' |     tag_value = 'Tag value' | ||||||
|     tags_to_be_set = {tag_key: tag_value} |     tags_to_be_set = {tag_key: tag_value} | ||||||
| @ -308,3 +308,25 @@ def test_create_tags_must_set_tags_on_retrieved_volumes(): | |||||||
| 
 | 
 | ||||||
|     #Check whether tag is present with correct value |     #Check whether tag is present with correct value | ||||||
|     retrieved_tags[tag_key].should.equal(tag_value) |     retrieved_tags[tag_key].should.equal(tag_value) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | @mock_ec2 | ||||||
|  | def test_retrieved_snapshots_must_contain_their_tags(): | ||||||
|  |     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") | ||||||
|  |     snapshot = conn.create_snapshot(volume.id) | ||||||
|  |     conn.create_tags([snapshot.id], tags_to_be_set) | ||||||
|  | 
 | ||||||
|  |     #Fetch the snapshot again | ||||||
|  |     all_snapshots = conn.get_all_snapshots() | ||||||
|  |     snapshot = all_snapshots[0] | ||||||
|  |     retrieved_tags = snapshot.tags | ||||||
|  | 
 | ||||||
|  |     conn.delete_snapshot(snapshot.id) | ||||||
|  |     volume.delete() | ||||||
|  | 
 | ||||||
|  |     #Check whether tag is present with correct value | ||||||
|  |     retrieved_tags[tag_key].should.equal(tag_value) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user