From c38a2a02820a342bbb80fab41d763a0f9c7cd062 Mon Sep 17 00:00:00 2001 From: huangtianhua Date: Tue, 23 Sep 2014 12:04:37 +0800 Subject: [PATCH] Add two attributes for cinder volume Add 'encrypted' and 'attachments' attributes for cinder volume resource. Change-Id: I920f97d196e5f4bed7bc8186b7d12157ee25edea --- heat/engine/resources/volume.py | 12 ++++++++++-- heat/tests/test_volume.py | 5 ++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/heat/engine/resources/volume.py b/heat/engine/resources/volume.py index 1daf03edf..3cea3151f 100644 --- a/heat/engine/resources/volume.py +++ b/heat/engine/resources/volume.py @@ -458,10 +458,12 @@ class CinderVolume(Volume): AVAILABILITY_ZONE_ATTR, SIZE_ATTR, SNAPSHOT_ID_ATTR, DISPLAY_NAME, DISPLAY_DESCRIPTION, VOLUME_TYPE_ATTR, METADATA_ATTR, SOURCE_VOLID_ATTR, STATUS, CREATED_AT, BOOTABLE, METADATA_VALUES_ATTR, + ENCRYPTED_ATTR, ATTACHMENTS, ) = ( 'availability_zone', 'size', 'snapshot_id', 'display_name', 'display_description', 'volume_type', 'metadata', 'source_volid', 'status', 'created_at', 'bootable', 'metadata_values', + 'encrypted', 'attachments', ) properties_schema = { @@ -564,6 +566,12 @@ class CinderVolume(Volume): METADATA_VALUES_ATTR: attributes.Schema( _('Key/value pairs associated with the volume in raw dict form.') ), + ENCRYPTED_ATTR: attributes.Schema( + _('Boolean indicating if the volume is encrypted or not.') + ), + ATTACHMENTS: attributes.Schema( + _('The list of attachments of the volume.') + ), } _volume_creating_status = ['creating', 'restoring-backup', 'downloading'] @@ -596,9 +604,9 @@ class CinderVolume(Volume): def _resolve_attribute(self, name): vol = self.cinder().volumes.get(self.resource_id) - if name == 'metadata': + if name == self.METADATA_ATTR: return unicode(json.dumps(vol.metadata)) - elif name == 'metadata_values': + elif name == self.METADATA_VALUES_ATTR: return vol.metadata return unicode(getattr(vol, name)) diff --git a/heat/tests/test_volume.py b/heat/tests/test_volume.py index 80519b999..c26a61286 100644 --- a/heat/tests/test_volume.py +++ b/heat/tests/test_volume.py @@ -816,7 +816,8 @@ class CinderVolumeTest(BaseVolumeTest): display_description='desc', volume_type='lvm', metadata={'key': 'value'}, source_volid=None, status='available', bootable=False, - created_at='2013-02-25T02:40:21.000000') + created_at='2013-02-25T02:40:21.000000', + encrypted=False, attachments=[]) stack_name = 'test_volume_stack' self._mock_create_volume(fv, stack_name) @@ -842,6 +843,8 @@ class CinderVolumeTest(BaseVolumeTest): self.assertEqual(u'2013-02-25T02:40:21.000000', rsrc.FnGetAtt('created_at')) self.assertEqual(u'False', rsrc.FnGetAtt('bootable')) + self.assertEqual(u'False', rsrc.FnGetAtt('encrypted')) + self.assertEqual(u'[]', rsrc.FnGetAtt('attachments')) error = self.assertRaises(exception.InvalidTemplateAttribute, rsrc.FnGetAtt, 'unknown') self.assertEqual(