Do not allow to modify access for public volume type

Now public volume type can be added/removed project access, but when
listing access, cinder returns 'Access list not available for public
volume types.' It's weird for users experience.

We should check if a type is public and do not allow public volume type
to modify project access.

APIImpact
When modifying access for public volume type, API will return 400 and message:
"Invalid volume type: Type access modification is not applicable to public
volume type."

Closes-Bug: #1467808

Change-Id: Id03eb3649ce02549c131c85697d8431c3f8c04dd
This commit is contained in:
wanghao
2015-06-23 16:38:29 +08:00
parent 87016e624b
commit 88e43aa7c4
2 changed files with 34 additions and 2 deletions

View File

@@ -182,11 +182,21 @@ def get_volume_type_extra_specs(volume_type_id, key=False):
return extra_specs
def is_public_volume_type(context, volume_type_id):
"""Return is_public boolean value of volume type"""
volume_type = db.volume_type_get(context, volume_type_id)
return volume_type['is_public']
def add_volume_type_access(context, volume_type_id, project_id):
"""Add access to volume type for project_id."""
if volume_type_id is None:
msg = _("volume_type_id cannot be None")
raise exception.InvalidVolumeType(reason=msg)
if is_public_volume_type(context, volume_type_id):
msg = _("Type access modification is not applicable to public volume "
"type.")
raise exception.InvalidVolumeType(reason=msg)
return db.volume_type_access_add(context, volume_type_id, project_id)
@@ -195,6 +205,10 @@ def remove_volume_type_access(context, volume_type_id, project_id):
if volume_type_id is None:
msg = _("volume_type_id cannot be None")
raise exception.InvalidVolumeType(reason=msg)
if is_public_volume_type(context, volume_type_id):
msg = _("Type access modification is not applicable to public volume "
"type.")
raise exception.InvalidVolumeType(reason=msg)
return db.volume_type_access_remove(context, volume_type_id, project_id)