diff --git a/heat/engine/resources/openstack/cinder/volume_type.py b/heat/engine/resources/openstack/cinder/volume_type.py index 178626f8c6..75180319dc 100644 --- a/heat/engine/resources/openstack/cinder/volume_type.py +++ b/heat/engine/resources/openstack/cinder/volume_type.py @@ -59,6 +59,7 @@ class CinderVolumeType(resource.Resource): _('Whether the volume type is accessible to the public.'), default=True, support_status=support.SupportStatus(version='5.0.0'), + update_allowed=True ), DESCRIPTION: properties.Schema( properties.Schema.STRING, @@ -106,11 +107,15 @@ class CinderVolumeType(resource.Resource): """Update the name, description and metadata for volume type.""" update_args = {} - # Update the name, description of cinder volume type + # Update the name, description, is_public of cinder volume type + is_public = self.properties[self.IS_PUBLIC] if self.DESCRIPTION in prop_diff: update_args['description'] = prop_diff.get(self.DESCRIPTION) if self.NAME in prop_diff: update_args['name'] = prop_diff.get(self.NAME) + if self.IS_PUBLIC in prop_diff: + is_public = prop_diff.get(self.IS_PUBLIC) + update_args['is_public'] = is_public if update_args: self.client().volume_types.update(self.resource_id, **update_args) # Update the key-value pairs of cinder volume type. @@ -122,7 +127,7 @@ class CinderVolumeType(resource.Resource): if new_keys is not None: volume_type.set_keys(new_keys) # Update the projects access for volume type - if self.PROJECTS in prop_diff: + if self.PROJECTS in prop_diff and not is_public: old_access_list = self.cinder().volume_type_access.list( self.resource_id) old_projects = [ac._info['project_id'] for ac in old_access_list] diff --git a/heat/tests/openstack/cinder/test_volume_type.py b/heat/tests/openstack/cinder/test_volume_type.py index e71c4f4a89..11b64a42d5 100644 --- a/heat/tests/openstack/cinder/test_volume_type.py +++ b/heat/tests/openstack/cinder/test_volume_type.py @@ -127,6 +127,18 @@ class CinderVolumeTypeTest(common.HeatTestCase): update_args = {'name': 'update'} self._test_update(update_args) + def test_volume_type_handle_update_is_public(self): + prop_diff = {'is_public': True, "projects": []} + self.patchobject(self.volume_type_access, 'list') + volume_type_id = '927202df-1afb-497f-8368-9c2d2f26e5db' + self.my_volume_type.resource_id = volume_type_id + 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, is_public=True) + self.volume_type_access.list.assert_not_called() + def test_volume_type_handle_update_metadata(self): new_keys = {'volume_backend_name': 'lvmdriver', 'capabilities:replication': 'True'} @@ -135,7 +147,7 @@ class CinderVolumeTypeTest(common.HeatTestCase): def test_volume_type_update_projects(self): self.my_volume_type.resource_id = '8aeaa446459a4d3196bc573fc252800b' - prop_diff = {'projects': ['id2', 'id3']} + prop_diff = {'projects': ['id2', 'id3'], 'is_public': False} class Access(object): def __init__(self, idx, project):