Merge "Prevent volume already in CG to be added to another"
This commit is contained in:
commit
7ea6f03740
@ -611,6 +611,19 @@ class API(base.Base):
|
|||||||
{'volume_id': add_vol,
|
{'volume_id': add_vol,
|
||||||
'group_id': group.id})
|
'group_id': group.id})
|
||||||
raise exception.InvalidVolume(reason=msg)
|
raise exception.InvalidVolume(reason=msg)
|
||||||
|
orig_group = add_vol_ref.get('consistencygroup_id', None)
|
||||||
|
if orig_group:
|
||||||
|
# If volume to be added is already in the group to be updated,
|
||||||
|
# it should have been removed from the add_volumes_list in the
|
||||||
|
# beginning of this function. If we are here, it means it is
|
||||||
|
# in a different group.
|
||||||
|
msg = (_("Cannot add volume %(volume_id)s to consistency "
|
||||||
|
"group %(group_id)s because it is already in "
|
||||||
|
"consistency group %(orig_group)s.") %
|
||||||
|
{'volume_id': add_vol_ref['id'],
|
||||||
|
'group_id': group.id,
|
||||||
|
'orig_group': orig_group})
|
||||||
|
raise exception.InvalidVolume(reason=msg)
|
||||||
if add_vol_ref:
|
if add_vol_ref:
|
||||||
add_vol_type_id = add_vol_ref.get('volume_type_id', None)
|
add_vol_type_id = add_vol_ref.get('volume_type_id', None)
|
||||||
if not add_vol_type_id:
|
if not add_vol_type_id:
|
||||||
|
@ -671,6 +671,31 @@ class ConsistencyGroupsAPITestCase(test.TestCase):
|
|||||||
|
|
||||||
consistencygroup.destroy()
|
consistencygroup.destroy()
|
||||||
|
|
||||||
|
def test_update_consistencygroup_add_volume_already_in_cg(self):
|
||||||
|
consistencygroup = self._create_consistencygroup(ctxt=self.ctxt,
|
||||||
|
status='available')
|
||||||
|
add_volume_id = utils.create_volume(
|
||||||
|
self.ctxt,
|
||||||
|
consistencygroup_id='some_other_cg')['id']
|
||||||
|
req = webob.Request.blank('/v2/fake/consistencygroups/%s/update' %
|
||||||
|
consistencygroup.id)
|
||||||
|
req.method = 'PUT'
|
||||||
|
req.headers['Content-Type'] = 'application/json'
|
||||||
|
add_volumes = add_volume_id
|
||||||
|
body = {"consistencygroup": {"name": "cg1",
|
||||||
|
"description": "",
|
||||||
|
"add_volumes": add_volumes,
|
||||||
|
"remove_volumes": None, }}
|
||||||
|
req.body = json.dumps(body)
|
||||||
|
res = req.get_response(fakes.wsgi_app())
|
||||||
|
res_dict = json.loads(res.body)
|
||||||
|
|
||||||
|
self.assertEqual(400, res.status_int)
|
||||||
|
self.assertEqual(400, res_dict['badRequest']['code'])
|
||||||
|
self.assertIsNotNone(res_dict['badRequest']['message'])
|
||||||
|
|
||||||
|
consistencygroup.destroy()
|
||||||
|
|
||||||
def test_update_consistencygroup_invalid_state(self):
|
def test_update_consistencygroup_invalid_state(self):
|
||||||
wrong_status = 'wrong_status'
|
wrong_status = 'wrong_status'
|
||||||
consistencygroup = self._create_consistencygroup(status=wrong_status,
|
consistencygroup = self._create_consistencygroup(status=wrong_status,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user