if snapshot_id:
snapshot = self.volume_api.get_snapshot(context, snapshot_id)
+ if volume_id != snapshot.volume_id:
+ msg = (_('Volume %(vol1)s does not match with '
+ 'snapshot.volume_id %(vol2)s.')
+ % {'vol1': volume_id,
+ 'vol2': snapshot.volume_id})
+ raise exception.InvalidVolume(reason=msg)
if volume['status'] not in ["available", "in-use"]:
msg = (_('Volume to be backed up must be available '
'or in-use, but the current status is "%s".')
db.volume_destroy(context.get_admin_context(), volume_id)
+ def test_create_backup_snapshot_with_inconsistent_volume(self):
+ volume_id = utils.create_volume(self.context, size=5,
+ status='available')['id']
+ volume_id2 = utils.create_volume(self.context, size=5,
+ status='available')['id']
+ snapshot_id = utils.create_snapshot(self.context,
+ volume_id,
+ status='available')['id']
+
+ self.addCleanup(db.volume_destroy,
+ self.context.elevated(),
+ volume_id)
+ self.addCleanup(db.volume_destroy,
+ self.context.elevated(),
+ volume_id2)
+ self.addCleanup(db.snapshot_destroy,
+ self.context.elevated(),
+ snapshot_id)
+ body = {"backup": {"display_name": "nightly001",
+ "display_description":
+ "Nightly Backup 03-Sep-2012",
+ "volume_id": volume_id2,
+ "snapshot_id": snapshot_id,
+ "container": "nightlybackups",
+ }
+ }
+ req = webob.Request.blank('/v2/fake/backups')
+ 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.assertIsNotNone(res_dict['badRequest']['message'])
+
@mock.patch('cinder.db.service_get_all_by_topic')
@mock.patch(
'cinder.api.openstack.wsgi.Controller.validate_name_and_description')