Merge "Adds more validations in create_snapshot"

This commit is contained in:
Zuul 2018-08-31 04:46:33 +00:00 committed by Gerrit Code Review
commit 446a9381eb
1 changed files with 9 additions and 21 deletions

View File

@ -860,29 +860,9 @@ class API(base.Base):
cgsnapshot_id,
commit_quota=True,
group_snapshot_id=None):
context.authorize(snapshot_policy.CREATE_POLICY, target_obj=volume)
self._create_snapshot_in_db_validate(context, volume)
utils.check_metadata_properties(metadata)
if not volume.host:
msg = _("The snapshot cannot be created because volume has "
"not been scheduled to any host.")
raise exception.InvalidVolume(reason=msg)
if volume['status'] == 'maintenance':
LOG.info('Unable to create the snapshot for volume, '
'because it is in maintenance.', resource=volume)
msg = _("The snapshot cannot be created when the volume is in "
"maintenance mode.")
raise exception.InvalidVolume(reason=msg)
if self._is_volume_migrating(volume):
# Volume is migrating, wait until done
msg = _("Snapshot cannot be created while volume is migrating.")
raise exception.InvalidVolume(reason=msg)
if volume['status'].startswith('replica_'):
# Can't snapshot secondary replica
msg = _("Snapshot of secondary replica is not allowed.")
raise exception.InvalidVolume(reason=msg)
valid_status = ["available", "in-use"] if force else ["available"]
@ -993,6 +973,10 @@ class API(base.Base):
def _create_snapshot_in_db_validate(self, context, volume):
context.authorize(snapshot_policy.CREATE_POLICY, target_obj=volume)
if not volume.host:
msg = _("The snapshot cannot be created because volume has "
"not been scheduled to any host.")
raise exception.InvalidVolume(reason=msg)
if volume['status'] == 'maintenance':
LOG.info('Unable to create the snapshot for volume, '
'because it is in maintenance.', resource=volume)
@ -1008,6 +992,10 @@ class API(base.Base):
"in error status.")
LOG.error(msg)
raise exception.InvalidVolume(reason=msg)
if volume['status'].startswith('replica_'):
# Can't snapshot secondary replica
msg = _("Snapshot of secondary replica is not allowed.")
raise exception.InvalidVolume(reason=msg)
def _create_snapshots_in_db_reserve(self, context, volume_list):
reserve_opts_list = []