Fixes consistency snapshot creation
This fixes the bug where creation of consistency snapshot would pass
even if the volume is in error state. Also adding unit test to
ensure that the creation of consistency snapshot fails when
volume is in error status.
Made minor changes to unit test for cherry-pick to mitaka.
Closes-Bug: #1592451
Change-Id: I482a7e01f32d72196568348225eb3c77a432a539
Signed-off-by: Nitin Madhok <nmadhok@g.clemson.edu>
(cherry-picked from commit fb3a51a2b4
)
This commit is contained in:
parent
2a7da4f627
commit
de954d04c2
|
@ -329,6 +329,38 @@ class CgsnapshotsAPITestCase(test.TestCase):
|
|||
context.get_admin_context(), res_dict['cgsnapshot']['id'])
|
||||
cgsnapshot.destroy()
|
||||
|
||||
@mock.patch(
|
||||
'cinder.api.openstack.wsgi.Controller.validate_name_and_description')
|
||||
def test_create_cgsnapshot_when_volume_in_error_status(self,
|
||||
mock_validate):
|
||||
consistencygroup = utils.create_consistencygroup(self.context)
|
||||
utils.create_volume(
|
||||
self.context,
|
||||
status='error',
|
||||
consistencygroup_id=consistencygroup.id
|
||||
)
|
||||
body = {"cgsnapshot": {"name": "cg1",
|
||||
"description":
|
||||
"CG Snapshot 1",
|
||||
"consistencygroup_id": consistencygroup.id}}
|
||||
req = webob.Request.blank('/v2/fake/cgsnapshots')
|
||||
req.method = 'POST'
|
||||
req.headers['Content-Type'] = 'application/json'
|
||||
req.body = jsonutils.dump_as_bytes(body)
|
||||
res = req.get_response(fakes.wsgi_app())
|
||||
res_dict = jsonutils.loads(res.body)
|
||||
|
||||
self.assertEqual(400, res.status_int)
|
||||
self.assertEqual(400, res_dict['badRequest']['code'])
|
||||
self.assertEqual(
|
||||
"Invalid volume: The snapshot cannot be created when the volume "
|
||||
"is in error status.",
|
||||
res_dict['badRequest']['message']
|
||||
)
|
||||
self.assertTrue(mock_validate.called)
|
||||
|
||||
consistencygroup.destroy()
|
||||
|
||||
def test_create_cgsnapshot_with_no_body(self):
|
||||
# omit body from the request
|
||||
req = webob.Request.blank('/v2/fake/cgsnapshots')
|
||||
|
|
|
@ -821,6 +821,11 @@ class API(base.Base):
|
|||
snapshot_list = []
|
||||
for volume in volume_list:
|
||||
self._create_snapshot_in_db_validate(context, volume, force)
|
||||
if volume['status'] == 'error':
|
||||
msg = _("The snapshot cannot be created when the volume is "
|
||||
"in error status.")
|
||||
LOG.error(msg)
|
||||
raise exception.InvalidVolume(reason=msg)
|
||||
|
||||
reservations = self._create_snapshots_in_db_reserve(
|
||||
context, volume_list)
|
||||
|
|
Loading…
Reference in New Issue