From 4aa1d2187565206a6188697859d93f881b8b13e8 Mon Sep 17 00:00:00 2001 From: huangtianhua Date: Mon, 8 Jun 2015 11:17:26 +0800 Subject: [PATCH] Add 'description' for cinder volume type Add property 'description' for OS::Cinder::VolumeType. Change-Id: I90fb93f1e8f27bab492c88d9026a6330c1cda5df --- .../openstack/cinder/cinder_volume_type.py | 21 +++++++++++++++---- heat/tests/test_cinder_volume_type.py | 14 ++++++++++++- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/heat/engine/resources/openstack/cinder/cinder_volume_type.py b/heat/engine/resources/openstack/cinder/cinder_volume_type.py index 9c5fe20400..6b4538a2ba 100644 --- a/heat/engine/resources/openstack/cinder/cinder_volume_type.py +++ b/heat/engine/resources/openstack/cinder/cinder_volume_type.py @@ -44,9 +44,9 @@ class CinderVolumeType(resource.Resource): support_status = support.SupportStatus(version='2015.1') PROPERTIES = ( - NAME, METADATA, IS_PUBLIC, + NAME, METADATA, IS_PUBLIC, DESCRIPTION, ) = ( - 'name', 'metadata', 'is_public', + 'name', 'metadata', 'is_public', 'description', ) properties_schema = { @@ -66,12 +66,19 @@ class CinderVolumeType(resource.Resource): default=True, support_status=support.SupportStatus(version='2015.2'), ), + DESCRIPTION: properties.Schema( + properties.Schema.STRING, + _('Description of the volume type.'), + update_allowed=True, + support_status=support.SupportStatus(version='2015.2'), + ), } def handle_create(self): args = { 'name': self.properties[self.NAME], - 'is_public': self.properties[self.IS_PUBLIC] + 'is_public': self.properties[self.IS_PUBLIC], + 'description': self.properties[self.DESCRIPTION] } volume_type = self.cinder().volume_types.create(**args) @@ -81,7 +88,13 @@ class CinderVolumeType(resource.Resource): volume_type.set_keys(vtype_metadata) def handle_update(self, json_snippet, tmpl_diff, prop_diff): - """Update the key-value pairs of cinder volume type.""" + """Update the name, description and metadata for volume type.""" + + # Update the description of cinder volume type + if self.DESCRIPTION in prop_diff: + self.cinder().volume_types.update( + self.resource_id, description=prop_diff.get(self.DESCRIPTION)) + # Update the key-value pairs of cinder volume type. if self.METADATA in prop_diff: volume_type = self.cinder().volume_types.get(self.resource_id) old_keys = volume_type.get_keys() diff --git a/heat/tests/test_cinder_volume_type.py b/heat/tests/test_cinder_volume_type.py index fe2cb7fd0f..93b16f9c18 100644 --- a/heat/tests/test_cinder_volume_type.py +++ b/heat/tests/test_cinder_volume_type.py @@ -67,7 +67,7 @@ class CinderVolumeTypeTest(common.HeatTestCase): self.my_volume_type.t['Properties']['is_public'] = is_public self.my_volume_type.handle_create() self.volume_types.create.assert_called_once_with( - name='volumeBackend', is_public=is_public) + name='volumeBackend', is_public=is_public, description=None) value.set_keys.assert_called_once_with( {'volume_backend_name': 'lvmdriver'}) self.assertEqual(volume_type_id, self.my_volume_type.resource_id) @@ -78,6 +78,18 @@ class CinderVolumeTypeTest(common.HeatTestCase): def test_volume_type_handle_create_not_public(self): self._test_handle_create(is_public=False) + def test_volume_type_handle_update_description(self): + volume_type_id = '927202df-1afb-497f-8368-9c2d2f26e5db' + self.my_volume_type.resource_id = volume_type_id + update_description = 'update' + prop_diff = {'description': update_description} + self.my_volume_type.handle_update(json_snippet=None, + tmpl_diff=None, + prop_diff=prop_diff) + self.volume_types.update.assert_called_once_with( + volume_type_id, + description=update_description) + def test_volume_type_handle_update_matadata(self): value = mock.MagicMock() self.volume_types.get.return_value = value