def test_attach_with_invalid_arguments(self): # Invalid request to attach volume an invalid target body = {"os-attach": {"mountpoint": "/dev/vdc"}} req = webob.Request.blank("/v2/fake/volumes/1/action") req.method = "POST" req.headers["content-type"] = "application/json" req.body = jsonutils.dumps(body) res = req.get_response(fakes.wsgi_app()) self.assertEqual(res.status_int, 400) # Invalid request to attach volume to an instance and a host body = {"os-attach": {"instance_uuid": "fake", "host_name": "fake_host", "mountpoint": "/dev/vdc"}} req = webob.Request.blank("/v2/fake/volumes/1/action") req.method = "POST" req.headers["content-type"] = "application/json" req.body = jsonutils.dumps(body) res = req.get_response(fakes.wsgi_app()) self.assertEqual(res.status_int, 400) # Invalid request to attach volume with an invalid mode body = {"os-attach": {"instance_uuid": "fake", "mountpoint": "/dev/vdc", "mode": "rr"}} req = webob.Request.blank("/v2/fake/volumes/1/action") req.method = "POST" req.headers["content-type"] = "application/json" req.body = jsonutils.dumps(body) res = req.get_response(fakes.wsgi_app()) self.assertEqual(res.status_int, 400) body = {"os-attach": {"host_name": "fake_host", "mountpoint": "/dev/vdc", "mode": "ww"}} req = webob.Request.blank("/v2/fake/volumes/1/action") req.method = "POST" req.headers["content-type"] = "application/json" req.body = jsonutils.dumps(body) res = req.get_response(fakes.wsgi_app()) self.assertEqual(res.status_int, 400)
def test_attach_to_instance(self): body = {'os-attach': {'instance_uuid': fake.INSTANCE_ID, 'mountpoint': '/dev/vdc', 'mode': 'rw'}} req = webob.Request.blank('/v2/%s/volumes/%s/action' % (fake.PROJECT_ID, fake.VOLUME_ID)) req.method = "POST" req.body = jsonutils.dump_as_bytes(body) req.headers["content-type"] = "application/json" res = req.get_response(fakes.wsgi_app( fake_auth_context=self.context)) self.assertEqual(202, res.status_int) body = {'os-attach': {'instance_uuid': fake.INSTANCE_ID, 'host_name': 'fake_host', 'mountpoint': '/dev/vdc'}} req = webob.Request.blank('/v2/%s/volumes/%s/action' % (fake.PROJECT_ID, fake.VOLUME_ID)) req.method = "POST" req.headers["content-type"] = "application/json" req.body = jsonutils.dump_as_bytes(body) res = req.get_response(fakes.wsgi_app( fake_auth_context=self.context)) self.assertEqual(202, res.status_int)
def test_attach_with_invalid_arguments(self): # Invalid request to attach volume an invalid target body = {'os-attach': {'mountpoint': '/dev/vdc'}} req = webob.Request.blank('/v2/fake/volumes/1/action') req.method = "POST" req.headers["content-type"] = "application/json" req.body = jsonutils.dump_as_bytes(body) res = req.get_response(fakes.wsgi_app()) self.assertEqual(400, res.status_int) # Invalid request to attach volume with an invalid mode body = {'os-attach': {'instance_uuid': 'fake', 'mountpoint': '/dev/vdc', 'mode': 'rr'}} req = webob.Request.blank('/v2/fake/volumes/1/action') req.method = "POST" req.headers["content-type"] = "application/json" req.body = jsonutils.dump_as_bytes(body) res = req.get_response(fakes.wsgi_app()) self.assertEqual(400, res.status_int) body = {'os-attach': {'host_name': 'fake_host', 'mountpoint': '/dev/vdc', 'mode': 'ww'}} req = webob.Request.blank('/v2/fake/volumes/1/action') req.method = "POST" req.headers["content-type"] = "application/json" req.body = jsonutils.dump_as_bytes(body) res = req.get_response(fakes.wsgi_app()) self.assertEqual(400, res.status_int)
def test_delete_transfer_awaiting_transfer(self): volume_id = self._create_volume() transfer = self._create_transfer(volume_id) req = webob.Request.blank('/v2/%s/os-volume-transfer/%s' % ( fake.PROJECT_ID, transfer['id'])) req.method = 'DELETE' req.headers['Content-Type'] = 'application/json' res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_ctxt)) self.assertEqual(202, res.status_int) # verify transfer has been deleted req = webob.Request.blank('/v2/%s/os-volume-transfer/%s' % ( fake.PROJECT_ID, transfer['id'])) req.method = 'GET' req.headers['Content-Type'] = 'application/json' res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) self.assertEqual(404, res.status_int) self.assertEqual(404, res_dict['itemNotFound']['code']) self.assertEqual('Transfer %s could not be found.' % transfer['id'], res_dict['itemNotFound']['message']) self.assertEqual(db.volume_get(context.get_admin_context(), volume_id)['status'], 'available') db.volume_destroy(context.get_admin_context(), volume_id)
def test_list_consistencygroups_xml(self): consistencygroup_id1 = self._create_consistencygroup() consistencygroup_id2 = self._create_consistencygroup() consistencygroup_id3 = self._create_consistencygroup() req = webob.Request.blank('/v2/fake/consistencygroups') req.method = 'GET' req.headers['Content-Type'] = 'application/xml' req.headers['Accept'] = 'application/xml' res = req.get_response(fakes.wsgi_app()) self.assertEqual(200, res.status_int) dom = minidom.parseString(res.body) consistencygroup_list = dom.getElementsByTagName('consistencygroup') self.assertEqual(consistencygroup_id1, consistencygroup_list.item(0).getAttribute('id')) self.assertEqual(consistencygroup_id2, consistencygroup_list.item(1).getAttribute('id')) self.assertEqual(consistencygroup_id3, consistencygroup_list.item(2).getAttribute('id')) db.consistencygroup_destroy(context.get_admin_context(), consistencygroup_id3) db.consistencygroup_destroy(context.get_admin_context(), consistencygroup_id2) db.consistencygroup_destroy(context.get_admin_context(), consistencygroup_id1)
def test_update_consistencygroup_add_volume_invalid_volume_type(self): ctxt = context.RequestContext('fake', 'fake') consistencygroup_id = self._create_consistencygroup(status='available') wrong_type = 'wrong-volume-type-id' add_volume_id = utils.create_volume( ctxt, volume_type_id=wrong_type)['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": "", "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']) msg = (_("Invalid volume: Cannot add volume %(volume_id)s " "to consistency group %(group_id)s because volume type " "%(volume_type)s is not supported by the group.") % {'volume_id': add_volume_id, 'group_id': consistencygroup_id, 'volume_type': wrong_type}) self.assertEqual(msg, res_dict['badRequest']['message']) db.consistencygroup_destroy(ctxt.elevated(), consistencygroup_id)
def test_list_consistencygroups_json(self): consistencygroup_id1 = self._create_consistencygroup() consistencygroup_id2 = self._create_consistencygroup() consistencygroup_id3 = self._create_consistencygroup() req = webob.Request.blank('/v2/fake/consistencygroups') req.method = 'GET' req.headers['Content-Type'] = 'application/json' res = req.get_response(fakes.wsgi_app()) res_dict = json.loads(res.body) self.assertEqual(200, res.status_int) self.assertEqual(consistencygroup_id1, res_dict['consistencygroups'][0]['id']) self.assertEqual('test_consistencygroup', res_dict['consistencygroups'][0]['name']) self.assertEqual(consistencygroup_id2, res_dict['consistencygroups'][1]['id']) self.assertEqual('test_consistencygroup', res_dict['consistencygroups'][1]['name']) self.assertEqual(consistencygroup_id3, res_dict['consistencygroups'][2]['id']) self.assertEqual('test_consistencygroup', res_dict['consistencygroups'][2]['name']) db.consistencygroup_destroy(context.get_admin_context(), consistencygroup_id3) db.consistencygroup_destroy(context.get_admin_context(), consistencygroup_id2) db.consistencygroup_destroy(context.get_admin_context(), consistencygroup_id1)
def test_create_consistencygroup_from_src_cg(self): self.mock_object(volume_api.API, "create", stubs.stub_volume_create) source_cg = utils.create_consistencygroup(self.ctxt) volume_id = utils.create_volume(self.ctxt, consistencygroup_id=source_cg.id)["id"] test_cg_name = "test cg" body = { "consistencygroup-from-src": { "name": test_cg_name, "description": "Consistency Group 1", "source_cgid": source_cg.id, } } req = webob.Request.blank("/v2/fake/consistencygroups/create_from_src") 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(202, res.status_int) self.assertIn("id", res_dict["consistencygroup"]) self.assertEqual(test_cg_name, res_dict["consistencygroup"]["name"]) cg = objects.ConsistencyGroup.get_by_id(self.ctxt, res_dict["consistencygroup"]["id"]) cg.destroy db.volume_destroy(self.ctxt.elevated(), volume_id) source_cg.destroy()
def test_create_with_keys_case_insensitive(self): # If the keys in uppercase_and_lowercase, should return the one # which server added self.stubs.Set(volume.API, 'get_volume_image_metadata', return_empty_image_metadata) self.stubs.Set(db, 'volume_metadata_update', fake_create_volume_metadata) body = { "os-set_image_metadata": { "metadata": { "Image_Id": "someid", "image_name": "fake", "Kernel_id": "somekernel", "ramdisk_id": "someramdisk" }, }, } req = webob.Request.blank('/v2/fake/volumes/1/action') req.method = 'POST' req.body = jsonutils.dumps(body) req.headers["content-type"] = "application/json" res = req.get_response(fakes.wsgi_app()) self.assertEqual(200, res.status_int) self.assertEqual(fake_image_metadata, json.loads(res.body)["metadata"])
def test_create_consistencygroup_from_src_cgsnapshot_empty(self): ctxt = context.RequestContext('fake', 'fake', auth_token=True) consistencygroup_id = utils.create_consistencygroup( ctxt)['id'] volume_id = utils.create_volume( ctxt, consistencygroup_id=consistencygroup_id)['id'] cgsnapshot_id = utils.create_cgsnapshot( ctxt, consistencygroup_id=consistencygroup_id)['id'] test_cg_name = 'test cg' body = {"consistencygroup-from-src": {"name": test_cg_name, "description": "Consistency Group 1", "cgsnapshot_id": cgsnapshot_id}} req = webob.Request.blank('/v2/fake/consistencygroups/create_from_src') req.method = 'POST' req.headers['Content-Type'] = 'application/json' 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']) msg = _("Invalid ConsistencyGroup: Cgsnahost is empty. No " "consistency group will be created.") self.assertIn(msg, res_dict['badRequest']['message']) db.cgsnapshot_destroy(ctxt.elevated(), cgsnapshot_id) db.volume_destroy(ctxt.elevated(), volume_id) db.consistencygroup_destroy(ctxt.elevated(), consistencygroup_id)
def test_accept_transfer_with_VolumeLimitExceeded(self): def fake_transfer_api_accept_throwing_VolumeLimitExceeded(cls, context, transfer, volume_id): raise exception.VolumeLimitExceeded(allowed=1) self.stubs.Set(cinder.transfer.API, 'accept', fake_transfer_api_accept_throwing_VolumeLimitExceeded) volume_id = self._create_volume() transfer = self._create_transfer(volume_id) body = {"accept": {"id": transfer['id'], "auth_key": transfer['auth_key']}} req = webob.Request.blank('/v2/%s/os-volume-transfer/%s/accept' % ( fake.PROJECT_ID, transfer['id'])) req.method = 'POST' req.headers['Content-Type'] = 'application/json' req.body = jsonutils.dump_as_bytes(body) res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) self.assertEqual(413, res.status_int) self.assertEqual(413, res_dict['overLimit']['code']) self.assertEqual("VolumeLimitExceeded: Maximum number of volumes " "allowed (1) exceeded for quota 'volumes'.", res_dict['overLimit']['message'])
def test_update_consistencygroup_add_volume_invalid_volume_type(self): consistencygroup = self._create_consistencygroup(ctxt=self.ctxt, status=fields.ConsistencyGroupStatus.AVAILABLE) wrong_type = "wrong-volume-type-id" add_volume_id = utils.create_volume(self.ctxt, volume_type_id=wrong_type)["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 = 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"]) msg = _( "Invalid volume: Cannot add volume %(volume_id)s " "to consistency group %(group_id)s because volume type " "%(volume_type)s is not supported by the group." ) % {"volume_id": add_volume_id, "group_id": consistencygroup.id, "volume_type": wrong_type} self.assertEqual(msg, res_dict["badRequest"]["message"]) consistencygroup.destroy()
def test_create_consistencygroup_from_src(self, mock_validate): self.stubs.Set(volume_api.API, "create", stubs.stub_volume_create) consistencygroup = utils.create_consistencygroup(self.ctxt) volume_id = utils.create_volume(self.ctxt, consistencygroup_id=consistencygroup.id)["id"] cgsnapshot = utils.create_cgsnapshot(self.ctxt, consistencygroup_id=consistencygroup.id) snapshot = utils.create_snapshot(self.ctxt, volume_id, cgsnapshot_id=cgsnapshot.id, status="available") test_cg_name = "test cg" body = { "consistencygroup-from-src": { "name": test_cg_name, "description": "Consistency Group 1", "cgsnapshot_id": cgsnapshot.id, } } req = webob.Request.blank("/v2/fake/consistencygroups/create_from_src") 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(202, res.status_int) self.assertIn("id", res_dict["consistencygroup"]) self.assertEqual(test_cg_name, res_dict["consistencygroup"]["name"]) self.assertTrue(mock_validate.called) cg_ref = objects.ConsistencyGroup.get_by_id(self.ctxt.elevated(), res_dict["consistencygroup"]["id"]) cg_ref.destroy() snapshot.destroy() db.volume_destroy(self.ctxt.elevated(), volume_id) consistencygroup.destroy() cgsnapshot.destroy()
def test_update_consistencygroup_remove_volume_not_found(self): consistencygroup = self._create_consistencygroup(ctxt=self.ctxt, status=fields.ConsistencyGroupStatus.AVAILABLE) req = webob.Request.blank("/v2/fake/consistencygroups/%s/update" % consistencygroup.id) req.method = "PUT" req.headers["Content-Type"] = "application/json" body = { "consistencygroup": { "name": None, "description": "new description", "add_volumes": None, "remove_volumes": "fake-volume-uuid", } } 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"]) msg = _( "Invalid volume: Cannot remove volume fake-volume-uuid " "from consistency group %(group_id)s because it is not " "in the group." ) % {"group_id": consistencygroup.id} self.assertEqual(msg, res_dict["badRequest"]["message"]) consistencygroup.destroy()
def test_accept_transfer_with_VolumeSizeExceedsAvailableQuota(self): def fake_transfer_api_accept_throwing_VolumeSizeExceedsAvailableQuota( cls, context, transfer, volume_id): raise exception.VolumeSizeExceedsAvailableQuota(requested='2', consumed='2', quota='3') self.stubs.Set( cinder.transfer.API, 'accept', fake_transfer_api_accept_throwing_VolumeSizeExceedsAvailableQuota) volume_id = self._create_volume() transfer = self._create_transfer(volume_id) body = {"accept": {"id": transfer['id'], "auth_key": transfer['auth_key']}} req = webob.Request.blank('/v2/%s/os-volume-transfer/%s/accept' % ( fake.PROJECT_ID, transfer['id'])) req.method = 'POST' req.headers['Content-Type'] = 'application/json' req.body = jsonutils.dump_as_bytes(body) res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) self.assertEqual(413, res.status_int) self.assertEqual(413, res_dict['overLimit']['code']) self.assertEqual('Requested volume or snapshot exceeds allowed ' 'gigabytes quota. Requested 2G, quota is 3G and ' '2G has been consumed.', res_dict['overLimit']['message'])
def test_update_consistencygroup_add_volume_invalid_state(self): volume_type_id = "123456" consistencygroup = self._create_consistencygroup(ctxt=self.ctxt, status=fields.ConsistencyGroupStatus.AVAILABLE) add_volume_id = utils.create_volume(self.ctxt, volume_type_id=volume_type_id, status="wrong_status")["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 = 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"]) msg = _( "Invalid volume: Cannot add volume %(volume_id)s " "to consistency group %(group_id)s because volume is in an " "invalid state: %(status)s. Valid states are: ('available', " "'in-use')." ) % {"volume_id": add_volume_id, "group_id": consistencygroup.id, "status": "wrong_status"} self.assertEqual(msg, res_dict["badRequest"]["message"]) consistencygroup.destroy()
def test_create_cgsnapshot_json(self, mock_validate): cgsnapshot_id = "1" consistencygroup = utils.create_consistencygroup(self.context) utils.create_volume( self.context, 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 = json.dumps(body) res = req.get_response(fakes.wsgi_app()) res_dict = json.loads(res.body) self.assertEqual(202, res.status_int) self.assertIn('id', res_dict['cgsnapshot']) self.assertTrue(mock_validate.called) db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id) consistencygroup.destroy()
def test_create_cgsnapshot_from_empty_consistencygroup( self, mock_cgsnapshot_create): consistencygroup = utils.create_consistencygroup(self.context) 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 ConsistencyGroup: Consistency group is ' 'empty. No cgsnapshot will be created.', res_dict['badRequest']['message']) # If failed to create cgsnapshot, its DB object should not be created self.assertFalse(mock_cgsnapshot_create.called) consistencygroup.destroy()
def test_create_consistencygroup_from_src_cgsnapshot_notfound(self): consistencygroup = utils.create_consistencygroup(self.ctxt) volume_id = utils.create_volume(self.ctxt, consistencygroup_id=consistencygroup.id)["id"] test_cg_name = "test cg" body = { "consistencygroup-from-src": { "name": test_cg_name, "description": "Consistency Group 1", "cgsnapshot_id": "fake_cgsnap", } } req = webob.Request.blank("/v2/fake/consistencygroups/create_from_src") 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(404, res.status_int) self.assertEqual(404, res_dict["itemNotFound"]["code"]) self.assertIsNotNone(res_dict["itemNotFound"]["message"]) db.volume_destroy(self.ctxt.elevated(), volume_id) consistencygroup.destroy()
def test_delete_cgsnapshot_with_Invalidcgsnapshot(self): consistencygroup = utils.create_consistencygroup(self.context) volume_id = utils.create_volume( self.context, consistencygroup_id=consistencygroup.id)['id'] cgsnapshot = utils.create_cgsnapshot( self.context, consistencygroup_id=consistencygroup.id, status='invalid') req = webob.Request.blank('/v2/fake/cgsnapshots/%s' % cgsnapshot.id) req.method = 'DELETE' req.headers['Content-Type'] = 'application/json' 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 cgsnapshot', res_dict['badRequest']['message']) cgsnapshot.destroy() db.volume_destroy(context.get_admin_context(), volume_id) consistencygroup.destroy()
def test_create_consistencygroup_from_src_cg(self): self.mock_object(volume_api.API, "create", stubs.stub_volume_create) source_cg = utils.create_consistencygroup(self.ctxt) volume_id = utils.create_volume( self.ctxt, consistencygroup_id=source_cg.id)['id'] test_cg_name = 'test cg' body = {"consistencygroup-from-src": {"name": test_cg_name, "description": "Consistency Group 1", "source_cgid": source_cg.id}} req = webob.Request.blank('/v2/fake/consistencygroups/create_from_src') req.method = 'POST' req.headers['Content-Type'] = 'application/json' req.body = json.dumps(body) res = req.get_response(fakes.wsgi_app()) res_dict = json.loads(res.body) self.assertEqual(202, res.status_int) self.assertIn('id', res_dict['consistencygroup']) self.assertEqual(test_cg_name, res_dict['consistencygroup']['name']) cg = objects.ConsistencyGroup.get_by_id( self.ctxt, res_dict['consistencygroup']['id']) cg.destroy db.volume_destroy(self.ctxt.elevated(), volume_id) source_cg.destroy()
def test_update_consistencygroup_add_volume_invalid_state(self): volume_type_id = '123456' consistencygroup = self._create_consistencygroup( ctxt=self.ctxt, status=fields.ConsistencyGroupStatus.AVAILABLE) add_volume_id = utils.create_volume( self.ctxt, volume_type_id=volume_type_id, status='wrong_status')['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']) msg = (_("Invalid volume: Cannot add volume %(volume_id)s " "to consistency group %(group_id)s because volume is in an " "invalid state: %(status)s. Valid states are: ('available', " "'in-use').") % {'volume_id': add_volume_id, 'group_id': consistencygroup.id, 'status': 'wrong_status'}) self.assertEqual(msg, res_dict['badRequest']['message']) consistencygroup.destroy()
def test_update_consistencygroup_add_volume_already_in_cg(self): consistencygroup = self._create_consistencygroup( ctxt=self.ctxt, status=fields.ConsistencyGroupStatus.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_create_consistencygroup_json(self, mock_validate): group_id = "1" # Create volume type vol_type = 'test' db.volume_type_create(context.get_admin_context(), {'name': vol_type, 'extra_specs': {}}) body = {"consistencygroup": {"name": "cg1", "volume_types": vol_type, "description": "Consistency Group 1", }} req = webob.Request.blank('/v2/fake/consistencygroups') req.method = 'POST' req.headers['Content-Type'] = 'application/json' req.body = json.dumps(body) res = req.get_response(fakes.wsgi_app()) res_dict = json.loads(res.body) self.assertEqual(202, res.status_int) self.assertIn('id', res_dict['consistencygroup']) self.assertTrue(mock_validate.called) group_id = res_dict['consistencygroup']['id'] cg = objects.ConsistencyGroup.get_by_id(context.get_admin_context(), group_id) cg.destroy()
def test_update_consistencygroup_remove_volume_not_found(self): consistencygroup = self._create_consistencygroup( ctxt=self.ctxt, status=fields.ConsistencyGroupStatus.AVAILABLE) req = webob.Request.blank('/v2/fake/consistencygroups/%s/update' % consistencygroup.id) req.method = 'PUT' req.headers['Content-Type'] = 'application/json' body = {"consistencygroup": {"name": None, "description": "new description", "add_volumes": None, "remove_volumes": "fake-volume-uuid", }} 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']) msg = (_("Invalid volume: Cannot remove volume fake-volume-uuid " "from consistency group %(group_id)s because it is not " "in the group.") % {'group_id': consistencygroup.id}) self.assertEqual(msg, res_dict['badRequest']['message']) consistencygroup.destroy()
def test_create_consistencygroup_from_src_cgsnapshot_empty(self): consistencygroup = utils.create_consistencygroup(self.ctxt) volume_id = utils.create_volume( self.ctxt, consistencygroup_id=consistencygroup.id)['id'] cgsnapshot = utils.create_cgsnapshot( self.ctxt, consistencygroup_id=consistencygroup.id) test_cg_name = 'test cg' body = {"consistencygroup-from-src": {"name": test_cg_name, "description": "Consistency Group 1", "cgsnapshot_id": cgsnapshot.id}} req = webob.Request.blank('/v2/fake/consistencygroups/create_from_src') req.method = 'POST' req.headers['Content-Type'] = 'application/json' 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']) db.volume_destroy(self.ctxt.elevated(), volume_id) consistencygroup.destroy() cgsnapshot.destroy()
def test_create_consistencygroup_from_src_no_host(self): consistencygroup = utils.create_consistencygroup(self.ctxt, host=None) volume_id = utils.create_volume(self.ctxt, consistencygroup_id=consistencygroup.id)["id"] cgsnapshot = utils.create_cgsnapshot(self.ctxt, consistencygroup_id=consistencygroup.id) snapshot = utils.create_snapshot(self.ctxt, volume_id, cgsnapshot_id=cgsnapshot.id, status="available") test_cg_name = "test cg" body = { "consistencygroup-from-src": { "name": test_cg_name, "description": "Consistency Group 1", "cgsnapshot_id": cgsnapshot.id, } } req = webob.Request.blank("/v2/fake/consistencygroups/create_from_src") 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"]) msg = _("Invalid ConsistencyGroup: No host to create consistency " "group") self.assertIn(msg, res_dict["badRequest"]["message"]) snapshot.destroy() db.volume_destroy(self.ctxt.elevated(), volume_id) consistencygroup.destroy() cgsnapshot.destroy()
def test_list_transfers_detail_json(self): volume_id_1 = self._create_volume(size=5) volume_id_2 = self._create_volume(size=5) transfer1 = self._create_transfer(volume_id_1) transfer2 = self._create_transfer(volume_id_2) req = webob.Request.blank('/v2/%s/os-volume-transfer/detail' % fake.PROJECT_ID) req.method = 'GET' req.headers['Content-Type'] = 'application/json' req.headers['Accept'] = 'application/json' res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) self.assertEqual(200, res.status_int) self.assertEqual(5, len(res_dict['transfers'][0])) self.assertEqual('test_transfer', res_dict['transfers'][0]['name']) self.assertEqual(transfer1['id'], res_dict['transfers'][0]['id']) self.assertEqual(volume_id_1, res_dict['transfers'][0]['volume_id']) self.assertEqual(5, len(res_dict['transfers'][1])) self.assertEqual('test_transfer', res_dict['transfers'][1]['name']) self.assertEqual(transfer2['id'], res_dict['transfers'][1]['id']) self.assertEqual(volume_id_2, res_dict['transfers'][1]['volume_id']) db.transfer_destroy(context.get_admin_context(), transfer2['id']) db.transfer_destroy(context.get_admin_context(), transfer1['id']) db.volume_destroy(context.get_admin_context(), volume_id_2) db.volume_destroy(context.get_admin_context(), volume_id_1)
def test_show_cgsnapshot(self): consistencygroup = utils.create_consistencygroup(self.context) volume_id = utils.create_volume(self.context, consistencygroup_id= consistencygroup.id)['id'] cgsnapshot_id = self._create_cgsnapshot( consistencygroup_id=consistencygroup.id) req = webob.Request.blank('/v2/fake/cgsnapshots/%s' % cgsnapshot_id) req.method = 'GET' req.headers['Content-Type'] = 'application/json' res = req.get_response(fakes.wsgi_app()) res_dict = json.loads(res.body) self.assertEqual(200, res.status_int) self.assertEqual('this is a test cgsnapshot', res_dict['cgsnapshot']['description']) self.assertEqual('test_cgsnapshot', res_dict['cgsnapshot']['name']) self.assertEqual('creating', res_dict['cgsnapshot']['status']) db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id) db.volume_destroy(context.get_admin_context(), volume_id) consistencygroup.destroy()
def test_create_consistencygroup_from_src_both_snap_cg(self): self.stubs.Set(volume_api.API, "create", stubs.stub_volume_create) consistencygroup = utils.create_consistencygroup(self.ctxt) volume_id = utils.create_volume(self.ctxt, consistencygroup_id=consistencygroup.id)["id"] cgsnapshot_id = utils.create_cgsnapshot(self.ctxt, consistencygroup_id=consistencygroup.id)["id"] snapshot = utils.create_snapshot(self.ctxt, volume_id, cgsnapshot_id=cgsnapshot_id, status="available") test_cg_name = "test cg" body = { "consistencygroup-from-src": { "name": test_cg_name, "description": "Consistency Group 1", "cgsnapshot_id": cgsnapshot_id, "source_cgid": consistencygroup.id, } } req = webob.Request.blank("/v2/fake/consistencygroups/create_from_src") 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.assertIsNotNone(res_dict["badRequest"]["message"]) snapshot.destroy() db.cgsnapshot_destroy(self.ctxt.elevated(), cgsnapshot_id) db.volume_destroy(self.ctxt.elevated(), volume_id) consistencygroup.destroy()
def test_attach_to_instance(self): body = { 'os-attach': { 'instance_uuid': 'fake', 'mountpoint': '/dev/vdc', 'mode': 'rw' } } req = webob.Request.blank('/v2/fake/volumes/1/action') req.method = "POST" req.body = jsonutils.dumps(body) req.headers["content-type"] = "application/json" res = req.get_response(fakes.wsgi_app()) self.assertEqual(202, res.status_int)
def test_delete_transfer_with_transfer_NotFound(self): req = webob.Request.blank('/v2/%s/os-volume-transfer/%s' % (fake.PROJECT_ID, fake.WILL_NOT_BE_FOUND_ID)) req.method = 'DELETE' req.headers['Content-Type'] = 'application/json' res = req.get_response( fakes.wsgi_app(fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) self.assertEqual(http_client.NOT_FOUND, res.status_int) self.assertEqual(http_client.NOT_FOUND, res_dict['itemNotFound']['code']) self.assertEqual( 'Transfer %s could not be found.' % fake.WILL_NOT_BE_FOUND_ID, res_dict['itemNotFound']['message'])
def test_volume_upload_image_without_type(self): id = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' vol = { "container_format": 'bare', "disk_format": 'raw', "image_name": None, "force": True } body = {"": vol} req = webob.Request.blank('/v2/tenant1/volumes/%s/action' % id) req.method = 'POST' req.headers['Content-Type'] = 'application/json' req.body = json.dumps(body) res = req.get_response(fakes.wsgi_app()) self.assertEqual(400, res.status_int)
def test_create_transfer_with_VolumeNotFound(self): body = {"transfer": {"name": "transfer1", "volume_id": 1234}} req = webob.Request.blank('/v2/fake/os-volume-transfer') 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(404, res.status_int) self.assertEqual(404, res_dict['itemNotFound']['code']) self.assertEqual('Volume 1234 could not be found.', res_dict['itemNotFound']['message'])
def test_volume_creation_with_scheduler_hints(self): vol = self._vol_in_request_body(availability_zone=None) vol.pop('group_id') body = {"volume": vol, "OS-SCH-HNT:scheduler_hints": { 'different_host': [fake.UUID1, fake.UUID2]}} req = webob.Request.blank('/v3/%s/volumes' % fake.PROJECT_ID) req.method = 'POST' req.headers['Content-Type'] = 'application/json' req.body = jsonutils.dump_as_bytes(body) res = req.get_response(fakes.wsgi_app( fake_auth_context=self.ctxt)) res_dict = jsonutils.loads(res.body) self.assertEqual(http_client.ACCEPTED, res.status_int) self.assertIn('id', res_dict['volume'])
def test_index_bad_volume_id(self): bad_volume_id = fake.WILL_NOT_BE_FOUND_ID req = webob.Request.blank('/v2/%s/volumes/%s/encryption' % (fake.PROJECT_ID, bad_volume_id)) res = req.get_response(fakes.wsgi_app(fake_auth_context=self.ctxt)) self.assertEqual(HTTPStatus.NOT_FOUND, res.status_code) res_dict = jsonutils.loads(res.body) expected = { 'itemNotFound': { 'code': HTTPStatus.NOT_FOUND, 'message': 'Volume %s could not be found.' % bad_volume_id } } self.assertEqual(expected, res_dict)
def test_show_cgsnapshot_with_cgsnapshot_NotFound(self): req = webob.Request.blank('/v2/%s/cgsnapshots/%s' % (fake.PROJECT_ID, fake.WILL_NOT_BE_FOUND_ID)) req.method = 'GET' req.headers['Content-Type'] = 'application/json' res = req.get_response( fakes.wsgi_app(fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) self.assertEqual(http_client.NOT_FOUND, res.status_int) self.assertEqual(http_client.NOT_FOUND, res_dict['itemNotFound']['code']) self.assertEqual( 'GroupSnapshot %s could not be found.' % fake.WILL_NOT_BE_FOUND_ID, res_dict['itemNotFound']['message'])
def test_create_image_metadata(self): self.stubs.Set(volume.API, 'get_volume_image_metadata', return_empty_image_metadata) self.stubs.Set(db, 'volume_metadata_update', fake_create_volume_metadata) body = {"os-set_image_metadata": {"metadata": fake_image_metadata}} req = webob.Request.blank('/v2/fake/volumes/1/action') req.method = "POST" req.body = jsonutils.dumps(body) req.headers["content-type"] = "application/json" res = req.get_response(fakes.wsgi_app()) self.assertEqual(200, res.status_int) self.assertEqual(fake_image_metadata, json.loads(res.body)["metadata"])
def test_attach_to_host(self): # using 'read-write' mode attach volume by default body = { 'os-attach': { 'host_name': 'fake_host', 'mountpoint': '/dev/vdc' } } req = webob.Request.blank('/v2/fake/volumes/1/action') req.method = "POST" req.body = jsonutils.dumps(body) req.headers["content-type"] = "application/json" res = req.get_response(fakes.wsgi_app()) self.assertEqual(202, res.status_int)
def test_show_transfer(self): volume_id = self._create_volume(size=5) transfer = self._create_transfer(volume_id) req = webob.Request.blank('/v3/%s/volume-transfers/%s' % (fake.PROJECT_ID, transfer['id'])) req.method = 'GET' req.headers = mv.get_mv_header(self.microversion) req.headers['Content-Type'] = 'application/json' res = req.get_response( fakes.wsgi_app(fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) self.assertEqual(http_client.OK, res.status_int) self.assertEqual('test_transfer', res_dict['transfer']['name']) self.assertEqual(transfer['id'], res_dict['transfer']['id']) self.assertEqual(volume_id, res_dict['transfer']['volume_id'])
def test_create_transfer_with_no_body(self): req = webob.Request.blank('/v2/fake/os-volume-transfer') req.body = json.dumps(None) req.method = 'POST' req.headers['Content-Type'] = 'application/json' req.headers['Accept'] = 'application/json' res = req.get_response(fakes.wsgi_app()) res_dict = json.loads(res.body) self.assertEqual(res.status_int, 400) self.assertEqual(res_dict['badRequest']['code'], 400) self.assertEqual( res_dict['badRequest']['message'], 'The server could not comply with the request since' ' it is either malformed or otherwise incorrect.')
def setUp(self): super(SchedulerHintsTestCase, self).setUp() self.fake_instance = v2_fakes.create_fake_volume(fake.VOLUME_ID, uuid=UUID) self.fake_instance['created_at'] =\ datetime.datetime(2013, 1, 1, 1, 1, 1) self.fake_instance['launched_at'] =\ datetime.datetime(2013, 1, 1, 1, 1, 1) self.flags( osapi_volume_extension=[ 'cinder.api.contrib.select_extensions'], osapi_volume_ext_list=['Scheduler_hints']) self.user_ctxt = context.RequestContext( fake.USER_ID, fake.PROJECT_ID, auth_token=True) self.app = fakes.wsgi_app(fake_auth_context=self.user_ctxt)
def test_create_transfer_with_body_KeyError(self): body = {"transfer": {"name": "transfer1"}} req = webob.Request.blank('/v2/%s/os-volume-transfer' % fake.PROJECT_ID) req.method = 'POST' req.headers['Content-Type'] = 'application/json' req.body = jsonutils.dump_as_bytes(body) res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) self.assertEqual(400, res.status_int) self.assertEqual(400, res_dict['badRequest']['code']) self.assertEqual('Incorrect request body format', res_dict['badRequest']['message'])
def test_show_bad_tenant_id(self): req = webob.Request.blank('/v2/%s/volumes/%s/encryption/' 'encryption_key_id' % (fake.WILL_NOT_BE_FOUND_ID, self.volume_id)) res = req.get_response(fakes.wsgi_app(fake_auth_context=self.ctxt)) self.assertEqual(400, res.status_code) res_dict = jsonutils.loads(res.body) expected = { 'badRequest': { 'code': 400, 'message': 'Malformed request url' } } self.assertEqual(expected, res_dict)
def test_extend_volume_invalid_status(self): def fake_extend_volume(*args, **kwargs): msg = "Volume status must be available" raise exception.InvalidVolume(reason=msg) self.stubs.Set(volume.API, 'extend', fake_extend_volume) body = {'os-extend': {'new_size': 5}} req = webob.Request.blank('/v2/fake/volumes/1/action') req.method = "POST" req.body = jsonutils.dumps(body) req.headers["content-type"] = "application/json" res = req.get_response(fakes.wsgi_app()) self.assertEqual(400, res.status_int)
def test_create_consistencygroup_with_no_body(self): # omit body from the request req = webob.Request.blank('/v2/fake/consistencygroups') req.body = json.dumps(None) req.method = 'POST' req.headers['Content-Type'] = 'application/json' req.headers['Accept'] = 'application/json' 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.assertEqual( "Missing required element 'consistencygroup' in " "request body.", res_dict['badRequest']['message'])
def test_show_consistencygroup_xml_content_type(self): consistencygroup_id = self._create_consistencygroup() req = webob.Request.blank('/v2/fake/consistencygroups/%s' % consistencygroup_id) req.method = 'GET' req.headers['Content-Type'] = 'application/xml' req.headers['Accept'] = 'application/xml' res = req.get_response(fakes.wsgi_app()) self.assertEqual(200, res.status_int) dom = minidom.parseString(res.body) consistencygroup = dom.getElementsByTagName('consistencygroup') name = consistencygroup.item(0).getAttribute('name') self.assertEqual("test_consistencygroup", name.strip()) db.consistencygroup_destroy(context.get_admin_context(), consistencygroup_id)
def test_index(self): req = webob.Request.blank('/v2/%s/volumes/%s/encryption' % (fake.PROJECT_ID, self.volume_id)) res = req.get_response(fakes.wsgi_app(fake_auth_context=self.ctxt)) self.assertEqual(200, res.status_code) res_dict = jsonutils.loads(res.body) expected = { "encryption_key_id": fake.ENCRYPTION_KEY_ID, "control_location": "front-end", "cipher": "cipher", "provider": "nova.volume.encryptors.base.VolumeEncryptor", "key_size": 256, } self.assertEqual(expected, res_dict)
def test_create_transfer_with_invalid_volume_id_value(self): body = {"transfer": {"name": "transfer1", "volume_id": 1234}} req = webob.Request.blank('/v2/%s/os-volume-transfer' % fake.PROJECT_ID) req.method = 'POST' req.headers['Content-Type'] = 'application/json' req.body = jsonutils.dump_as_bytes(body) res = req.get_response( fakes.wsgi_app(fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) self.assertEqual(http_client.BAD_REQUEST, res.status_int) self.assertEqual(http_client.BAD_REQUEST, res_dict['badRequest']['code'])
def test_delete(self): self.mock_object(db, 'volume_metadata_delete', volume_metadata_delete) body = {"os-unset_image_metadata": { "key": "ramdisk_id"} } req = webob.Request.blank('/v2/%s/volumes/%s/action' % ( fake.PROJECT_ID, fake.VOLUME_ID)) req.method = 'POST' req.body = jsonutils.dump_as_bytes(body) req.headers["content-type"] = "application/json" res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_ctxt)) self.assertEqual(http_client.OK, res.status_int)
def test_index_bad_tenant_id(self): self.stubs.Set(volume_types, 'is_encrypted', lambda *a, **kw: True) req = webob.Request.blank('/v2/%s/volumes/%s/encryption' % ('bad-tenant-id', self.volume_id)) res = req.get_response(fakes.wsgi_app(fake_auth_context=self.ctxt)) self.assertEqual(400, res.status_code) res_dict = json.loads(res.body) expected = { 'badRequest': { 'code': 400, 'message': 'Malformed request url' } } self.assertEqual(expected, res_dict)
def test_create_transfer_with_no_body(self): req = webob.Request.blank('/v2/%s/os-volume-transfer' % fake.PROJECT_ID) req.body = jsonutils.dump_as_bytes(None) req.method = 'POST' req.headers['Content-Type'] = 'application/json' req.headers['Accept'] = 'application/json' res = req.get_response( fakes.wsgi_app(fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) self.assertEqual(400, res.status_int) self.assertEqual(400, res_dict['badRequest']['code']) self.assertEqual( "Missing required element 'transfer' in " "request body.", res_dict['badRequest']['message'])
def test_delete_consistencygroup_no_host(self): consistencygroup = self._create_consistencygroup( host=None, status=fields.ConsistencyGroupStatus.ERROR) req = webob.Request.blank('/v2/fake/consistencygroups/%s/delete' % consistencygroup.id) req.method = 'POST' req.headers['Content-Type'] = 'application/json' body = {"consistencygroup": {"force": True}} req.body = json.dumps(body) res = req.get_response(fakes.wsgi_app()) self.assertEqual(202, res.status_int) cg = objects.ConsistencyGroup.get_by_id( context.get_admin_context(read_deleted='yes'), consistencygroup.id) self.assertEqual(fields.ConsistencyGroupStatus.DELETED, cg.status) self.assertIsNone(cg.host)
def test_create_transfer_with_InvalidVolume(self): volume_id = self._create_volume(status='attached') body = {"transfer": {"name": "transfer1", "volume_id": volume_id}} req = webob.Request.blank('/v2/fake/os-volume-transfer') req.method = 'POST' req.headers['Content-Type'] = 'application/json' 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.assertEqual('Invalid volume: status must be available', res_dict['badRequest']['message']) db.volume_destroy(context.get_admin_context(), volume_id)
def test_create_consistencygroup_with_no_body(self): # omit body from the request req = webob.Request.blank('/v2/fake/consistencygroups') req.body = json.dumps(None) req.method = 'POST' req.headers['Content-Type'] = 'application/json' req.headers['Accept'] = 'application/json' 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.assertEqual( 'The server could not comply with the request since' ' it is either malformed or otherwise incorrect.', res_dict['badRequest']['message'])
def _get_response(self, volume_type, admin=True, url='/v2/fake/types/%s/encryption', req_method='GET', req_body=None, req_headers=None): ctxt = context.RequestContext('fake', 'fake', is_admin=admin) req = webob.Request.blank(url % volume_type['id']) req.method = req_method req.body = req_body if req_headers: req.headers['Content-Type'] = req_headers return req.get_response(fakes.wsgi_app(fake_auth_context=ctxt))
def test_show_transfer(self): volume_id = self._create_volume(size=5) transfer = self._create_transfer(volume_id) req = webob.Request.blank('/v2/fake/os-volume-transfer/%s' % transfer['id']) req.method = 'GET' req.headers['Content-Type'] = 'application/json' res = req.get_response(fakes.wsgi_app()) res_dict = jsonutils.loads(res.body) self.assertEqual(200, res.status_int) self.assertEqual('test_transfer', res_dict['transfer']['name']) self.assertEqual(transfer['id'], res_dict['transfer']['id']) self.assertEqual(volume_id, res_dict['transfer']['volume_id']) db.transfer_destroy(context.get_admin_context(), transfer['id']) db.volume_destroy(context.get_admin_context(), volume_id)
def test_update_snapshot_status(self, metadata_get, *args): body = { 'os-update_snapshot_status': { 'status': fields.SnapshotStatus.AVAILABLE } } req = webob.Request.blank('/v2/%s/snapshots/%s/action' % (fake.PROJECT_ID, fake.SNAPSHOT_ID)) req.method = "POST" req.body = jsonutils.dump_as_bytes(body) req.headers["content-type"] = "application/json" res = req.get_response( fakes.wsgi_app(fake_auth_context=self.user_ctxt)) self.assertEqual(202, res.status_int)
def test_index_volume_not_encrypted_type(self): self.stubs.Set(db.sqlalchemy.api, 'volume_type_encryption_get', lambda *args, **kwargs: None) volume_id = self._create_volume(self.ctxt, encryption_key_id=None) self.addCleanup(db.volume_destroy, self.ctxt.elevated(), volume_id) req = webob.Request.blank('/v2/%s/volumes/%s/encryption' % (fake.PROJECT_ID, volume_id)) res = req.get_response(fakes.wsgi_app(fake_auth_context=self.ctxt)) self.assertEqual(200, res.status_code) res_dict = jsonutils.loads(res.body) expected = {'encryption_key_id': None} self.assertEqual(expected, res_dict)
def test_delete_consistencygroup_no_host(self): consistencygroup_id = self._create_consistencygroup(host=None, status='error') req = webob.Request.blank('/v2/fake/consistencygroups/%s/delete' % consistencygroup_id) req.method = 'POST' req.headers['Content-Type'] = 'application/json' body = {"consistencygroup": {"force": True}} req.body = json.dumps(body) res = req.get_response(fakes.wsgi_app()) self.assertEqual(res.status_int, 202) cg = db.consistencygroup_get( context.get_admin_context(read_deleted='yes'), consistencygroup_id) self.assertEqual(cg['status'], 'deleted') self.assertEqual(cg['host'], None)