Before calling update_consistencygroup, a validation is done if volumes
are in valid states for action.
Divide the states allowed for adding and removing volumes from a CG,
and allow volume removal in states error and error_deleting.
Also added missing verification in manager update_consistencygroup in
case state has changed from cinder-api to cinder-volume.
Change-Id: I6f5fa8e9af67e17ab49e7f3423d4469640df790c
Closes-Bug: #
1519377
LOG = logging.getLogger(__name__)
CGQUOTAS = quota.CGQUOTAS
-VALID_REMOVE_VOL_FROM_CG_STATUS = (c_fields.ConsistencyGroupStatus.AVAILABLE,
- c_fields.ConsistencyGroupStatus.IN_USE)
+VALID_REMOVE_VOL_FROM_CG_STATUS = (
+ 'available',
+ 'in-use',
+ 'error',
+ 'error_deleting')
+VALID_ADD_VOL_TO_CG_STATUS = (
+ 'available',
+ 'in-use')
def wrap_check_policy(func):
'volume_type': add_vol_type_id})
raise exception.InvalidVolume(reason=msg)
if (add_vol_ref['status'] not in
- VALID_REMOVE_VOL_FROM_CG_STATUS):
+ VALID_ADD_VOL_TO_CG_STATUS):
msg = (_("Cannot add volume %(volume_id)s to consistency "
"group %(group_id)s because volume is in an "
"invalid state: %(status)s. Valid states are: "
{'volume_id': add_vol_ref['id'],
'group_id': group.id,
'status': add_vol_ref['status'],
- 'valid': VALID_REMOVE_VOL_FROM_CG_STATUS})
+ 'valid': VALID_ADD_VOL_TO_CG_STATUS})
raise exception.InvalidVolume(reason=msg)
# group.host and add_vol_ref['host'] are in this format:
remove_volume_id2 = utils.create_volume(
self.ctxt,
volume_type_id=volume_type_id,
- consistencygroup_id=consistencygroup.id)['id']
+ consistencygroup_id=consistencygroup.id,
+ status='error')['id']
+ remove_volume_id3 = utils.create_volume(
+ self.ctxt,
+ volume_type_id=volume_type_id,
+ consistencygroup_id=consistencygroup.id,
+ status='error_deleting')['id']
self.assertEqual(fields.ConsistencyGroupStatus.AVAILABLE,
consistencygroup.status)
cg_vol_ids = [cg_vol['id'] for cg_vol in cg_volumes]
self.assertIn(remove_volume_id, cg_vol_ids)
self.assertIn(remove_volume_id2, cg_vol_ids)
+ self.assertIn(remove_volume_id3, cg_vol_ids)
add_volume_id = utils.create_volume(
self.ctxt,
name = 'newcg'
description = 'New Consistency Group Description'
add_volumes = add_volume_id + "," + add_volume_id2
- remove_volumes = remove_volume_id + "," + remove_volume_id2
+ remove_volumes = ','.join(
+ [remove_volume_id, remove_volume_id2, remove_volume_id3])
body = {"consistencygroup": {"name": name,
"description": description,
"add_volumes": add_volumes,
QUOTAS = quota.QUOTAS
CGQUOTAS = quota.CGQUOTAS
-VALID_REMOVE_VOL_FROM_CG_STATUS = ('available', 'in-use',)
+VALID_REMOVE_VOL_FROM_CG_STATUS = (
+ 'available',
+ 'in-use',
+ 'error',
+ 'error_deleting')
+VALID_ADD_VOL_TO_CG_STATUS = (
+ 'available',
+ 'in-use')
VALID_CREATE_CG_SRC_SNAP_STATUS = ('available',)
VALID_CREATE_CG_SRC_CG_STATUS = ('available',)
resource={'type': 'consistency_group',
'id': group.id})
raise
- if add_vol_ref['status'] not in ['in-use', 'available']:
+ if add_vol_ref['status'] not in VALID_ADD_VOL_TO_CG_STATUS:
msg = (_("Cannot add volume %(volume_id)s to consistency "
"group %(group_id)s because volume is in an invalid "
"state: %(status)s. Valid states are: %(valid)s.") %
{'volume_id': add_vol_ref['id'],
'group_id': group.id,
'status': add_vol_ref['status'],
- 'valid': VALID_REMOVE_VOL_FROM_CG_STATUS})
+ 'valid': VALID_ADD_VOL_TO_CG_STATUS})
raise exception.InvalidVolume(reason=msg)
# self.host is 'host@backend'
# volume_ref['host'] is 'host@backend#pool'
resource={'type': 'consistency_group',
'id': group.id})
raise
+ if remove_vol_ref['status'] not in VALID_REMOVE_VOL_FROM_CG_STATUS:
+ msg = (_("Cannot remove volume %(volume_id)s from consistency "
+ "group %(group_id)s because volume is in an invalid "
+ "state: %(status)s. Valid states are: %(valid)s.") %
+ {'volume_id': remove_vol_ref['id'],
+ 'group_id': group.id,
+ 'status': remove_vol_ref['status'],
+ 'valid': VALID_REMOVE_VOL_FROM_CG_STATUS})
+ raise exception.InvalidVolume(reason=msg)
remove_volumes_ref.append(remove_vol_ref)
self._notify_about_consistencygroup_usage(
--- /dev/null
+---
+fixes:
+ - Previously the only way to remove volumes in error
+ states from a consistency-group was to delete the
+ consistency group and create it again. Now it is
+ possible to remove volumes in error and error_deleting
+ states.