Merge "Add 'description' for cinder volume type"

This commit is contained in:
Jenkins 2015-06-09 14:40:19 +00:00 committed by Gerrit Code Review
commit 364a864d03
2 changed files with 30 additions and 5 deletions

View File

@ -44,9 +44,9 @@ class CinderVolumeType(resource.Resource):
support_status = support.SupportStatus(version='2015.1') support_status = support.SupportStatus(version='2015.1')
PROPERTIES = ( PROPERTIES = (
NAME, METADATA, IS_PUBLIC, NAME, METADATA, IS_PUBLIC, DESCRIPTION,
) = ( ) = (
'name', 'metadata', 'is_public', 'name', 'metadata', 'is_public', 'description',
) )
properties_schema = { properties_schema = {
@ -66,12 +66,19 @@ class CinderVolumeType(resource.Resource):
default=True, default=True,
support_status=support.SupportStatus(version='2015.2'), 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): def handle_create(self):
args = { args = {
'name': self.properties[self.NAME], '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) volume_type = self.cinder().volume_types.create(**args)
@ -81,7 +88,13 @@ class CinderVolumeType(resource.Resource):
volume_type.set_keys(vtype_metadata) volume_type.set_keys(vtype_metadata)
def handle_update(self, json_snippet, tmpl_diff, prop_diff): 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: if self.METADATA in prop_diff:
volume_type = self.cinder().volume_types.get(self.resource_id) volume_type = self.cinder().volume_types.get(self.resource_id)
old_keys = volume_type.get_keys() old_keys = volume_type.get_keys()

View File

@ -67,7 +67,7 @@ class CinderVolumeTypeTest(common.HeatTestCase):
self.my_volume_type.t['Properties']['is_public'] = is_public self.my_volume_type.t['Properties']['is_public'] = is_public
self.my_volume_type.handle_create() self.my_volume_type.handle_create()
self.volume_types.create.assert_called_once_with( 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( value.set_keys.assert_called_once_with(
{'volume_backend_name': 'lvmdriver'}) {'volume_backend_name': 'lvmdriver'})
self.assertEqual(volume_type_id, self.my_volume_type.resource_id) 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): def test_volume_type_handle_create_not_public(self):
self._test_handle_create(is_public=False) 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): def test_volume_type_handle_update_matadata(self):
value = mock.MagicMock() value = mock.MagicMock()
self.volume_types.get.return_value = value self.volume_types.get.return_value = value