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_id = utils.create_cgsnapshot( 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": 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.cgsnapshot_destroy(self.ctxt.elevated(), cgsnapshot_id) db.volume_destroy(self.ctxt.elevated(), volume_id) 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_id = utils.create_cgsnapshot( 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": 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.cgsnapshot_destroy(self.ctxt.elevated(), cgsnapshot_id) db.volume_destroy(self.ctxt.elevated(), volume_id) consistencygroup.destroy()
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_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_delete_cgsnapshot_available(self): consistencygroup_id = utils.create_consistencygroup(self.context)['id'] volume_id = utils.create_volume( self.context, consistencygroup_id=consistencygroup_id)['id'] cgsnapshot_id = self._create_cgsnapshot( consistencygroup_id=consistencygroup_id, status='available') 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()) self.assertEqual(res.status_int, 202) self.assertEqual(self._get_cgsnapshot_attrib(cgsnapshot_id, 'status'), 'deleting') db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id) db.volume_destroy(context.get_admin_context(), volume_id) db.consistencygroup_destroy(context.get_admin_context(), consistencygroup_id)
def test_create_consistencygroup_from_src_create_volume_failed(self, mock_create): 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"] snapshot_id = utils.create_snapshot(ctxt, volume_id, cgsnapshot_id=cgsnapshot_id, status="available")["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 = _("Create volume failed.") self.assertEqual(msg, res_dict["badRequest"]["message"]) db.snapshot_destroy(ctxt.elevated(), snapshot_id) db.cgsnapshot_destroy(ctxt.elevated(), cgsnapshot_id) db.volume_destroy(ctxt.elevated(), volume_id) db.consistencygroup_destroy(ctxt.elevated(), consistencygroup_id)
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_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_delete_cgsnapshot_with_Invalidcgsnapshot(self): consistencygroup_id = utils.create_consistencygroup(self.context)['id'] volume_id = utils.create_volume( self.context, consistencygroup_id=consistencygroup_id)['id'] cgsnapshot_id = self._create_cgsnapshot( 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 = json.loads(res.body) self.assertEqual(res.status_int, 400) self.assertEqual(res_dict['badRequest']['code'], 400) self.assertEqual(res_dict['badRequest']['message'], 'Invalid cgsnapshot') db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id) db.volume_destroy(context.get_admin_context(), volume_id) db.consistencygroup_destroy(context.get_admin_context(), consistencygroup_id)
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_delete_cgsnapshot_available(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, status="available") 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()) self.assertEqual(202, res.status_int) self.assertEqual("deleting", self._get_cgsnapshot_attrib(cgsnapshot_id, "status")) db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id) db.volume_destroy(context.get_admin_context(), 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_id = self._create_cgsnapshot(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 = json.loads(res.body) self.assertEqual(400, res.status_int) self.assertEqual(400, res_dict["badRequest"]["code"]) self.assertEqual("Invalid cgsnapshot", res_dict["badRequest"]["message"]) db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id) db.volume_destroy(context.get_admin_context(), volume_id) consistencygroup.destroy()
def test_show_cgsnapshot_xml_content_type(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/xml" req.headers["Accept"] = "application/xml" res = req.get_response(fakes.wsgi_app()) self.assertEqual(200, res.status_int) dom = minidom.parseString(res.body) cgsnapshot = dom.getElementsByTagName("cgsnapshot") name = cgsnapshot.item(0).getAttribute("name") self.assertEqual("test_cgsnapshot", name.strip()) db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id) db.volume_destroy(context.get_admin_context(), volume_id) consistencygroup.destroy()
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_delete_cgsnapshot_available(self): consistencygroup_id = utils.create_consistencygroup(self.context)['id'] volume_id = utils.create_volume( self.context, consistencygroup_id=consistencygroup_id)['id'] cgsnapshot_id = self._create_cgsnapshot( consistencygroup_id=consistencygroup_id, status='available') 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()) self.assertEqual(res.status_int, 202) self.assertEqual(self._get_cgsnapshot_attrib(cgsnapshot_id, 'status'), 'deleting') db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id) db.volume_destroy(context.get_admin_context(), volume_id) db.consistencygroup_destroy(context.get_admin_context(), consistencygroup_id)
def test_show_cgsnapshot_xml_content_type(self): consistencygroup_id = utils.create_consistencygroup(self.context)['id'] 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/xml' req.headers['Accept'] = 'application/xml' res = req.get_response(fakes.wsgi_app()) self.assertEqual(res.status_int, 200) dom = minidom.parseString(res.body) cgsnapshot = dom.getElementsByTagName('cgsnapshot') name = cgsnapshot.item(0).getAttribute('name') self.assertEqual(name.strip(), "test_cgsnapshot") db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id) db.volume_destroy(context.get_admin_context(), volume_id) db.consistencygroup_destroy(context.get_admin_context(), consistencygroup_id)
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_id = utils.create_cgsnapshot( self.ctxt, consistencygroup_id=consistencygroup.id)['id'] snapshot_id = utils.create_snapshot(self.ctxt, volume_id, cgsnapshot_id=cgsnapshot_id, status='available')['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(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() db.snapshot_destroy(self.ctxt.elevated(), snapshot_id) db.cgsnapshot_destroy(self.ctxt.elevated(), cgsnapshot_id) db.volume_destroy(self.ctxt.elevated(), volume_id) 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_id = utils.create_cgsnapshot( self.ctxt, consistencygroup_id=consistencygroup.id)['id'] snapshot_id = utils.create_snapshot( self.ctxt, volume_id, cgsnapshot_id=cgsnapshot_id, status='available')['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(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() db.snapshot_destroy(self.ctxt.elevated(), snapshot_id) db.cgsnapshot_destroy(self.ctxt.elevated(), cgsnapshot_id) db.volume_destroy(self.ctxt.elevated(), volume_id) consistencygroup.destroy()
def test_delete_cgsnapshot_with_Invalidcgsnapshot(self): consistencygroup_id = utils.create_consistencygroup(self.context)['id'] volume_id = utils.create_volume( self.context, consistencygroup_id=consistencygroup_id)['id'] cgsnapshot_id = self._create_cgsnapshot( 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 = json.loads(res.body) self.assertEqual(res.status_int, 400) self.assertEqual(res_dict['badRequest']['code'], 400) self.assertEqual(res_dict['badRequest']['message'], 'Invalid cgsnapshot') db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id) db.volume_destroy(context.get_admin_context(), volume_id) db.consistencygroup_destroy(context.get_admin_context(), consistencygroup_id)
def test_list_cgsnapshots_json(self): consistencygroup_id = utils.create_consistencygroup(self.context)['id'] volume_id = utils.create_volume( self.context, consistencygroup_id=consistencygroup_id)['id'] cgsnapshot_id1 = self._create_cgsnapshot( consistencygroup_id=consistencygroup_id) cgsnapshot_id2 = self._create_cgsnapshot( consistencygroup_id=consistencygroup_id) cgsnapshot_id3 = self._create_cgsnapshot( consistencygroup_id=consistencygroup_id) req = webob.Request.blank('/v2/fake/cgsnapshots') req.method = 'GET' req.headers['Content-Type'] = 'application/json' res = req.get_response(fakes.wsgi_app()) res_dict = json.loads(res.body) self.assertEqual(res.status_int, 200) self.assertEqual(res_dict['cgsnapshots'][0]['id'], cgsnapshot_id1) self.assertEqual(res_dict['cgsnapshots'][0]['name'], 'test_cgsnapshot') self.assertEqual(res_dict['cgsnapshots'][1]['id'], cgsnapshot_id2) self.assertEqual(res_dict['cgsnapshots'][1]['name'], 'test_cgsnapshot') self.assertEqual(res_dict['cgsnapshots'][2]['id'], cgsnapshot_id3) self.assertEqual(res_dict['cgsnapshots'][2]['name'], 'test_cgsnapshot') db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id3) db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id2) db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id1) db.volume_destroy(context.get_admin_context(), volume_id) db.consistencygroup_destroy(context.get_admin_context(), consistencygroup_id)
def test_list_cgsnapshots_xml(self): consistencygroup_id = utils.create_consistencygroup(self.context)["id"] volume_id = utils.create_volume(self.context, consistencygroup_id=consistencygroup_id)["id"] cgsnapshot_id1 = self._create_cgsnapshot(consistencygroup_id=consistencygroup_id) cgsnapshot_id2 = self._create_cgsnapshot(consistencygroup_id=consistencygroup_id) cgsnapshot_id3 = self._create_cgsnapshot(consistencygroup_id=consistencygroup_id) req = webob.Request.blank("/v2/fake/cgsnapshots") req.method = "GET" req.headers["Content-Type"] = "application/xml" req.headers["Accept"] = "application/xml" res = req.get_response(fakes.wsgi_app()) self.assertEqual(res.status_int, 200) dom = minidom.parseString(res.body) cgsnapshot_list = dom.getElementsByTagName("cgsnapshot") self.assertEqual(cgsnapshot_list.item(0).getAttribute("id"), cgsnapshot_id1) self.assertEqual(cgsnapshot_list.item(1).getAttribute("id"), cgsnapshot_id2) self.assertEqual(cgsnapshot_list.item(2).getAttribute("id"), cgsnapshot_id3) db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id3) db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id2) db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id1) db.volume_destroy(context.get_admin_context(), volume_id) db.consistencygroup_destroy(context.get_admin_context(), consistencygroup_id)
def test_list_cgsnapshots_detail_json(self): consistencygroup_id = utils.create_consistencygroup(self.context)["id"] volume_id = utils.create_volume(self.context, consistencygroup_id=consistencygroup_id)["id"] cgsnapshot_id1 = self._create_cgsnapshot(consistencygroup_id=consistencygroup_id) cgsnapshot_id2 = self._create_cgsnapshot(consistencygroup_id=consistencygroup_id) cgsnapshot_id3 = self._create_cgsnapshot(consistencygroup_id=consistencygroup_id) req = webob.Request.blank("/v2/fake/cgsnapshots/detail") req.method = "GET" 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, 200) self.assertEqual(res_dict["cgsnapshots"][0]["description"], "this is a test cgsnapshot") self.assertEqual(res_dict["cgsnapshots"][0]["name"], "test_cgsnapshot") self.assertEqual(res_dict["cgsnapshots"][0]["id"], cgsnapshot_id1) self.assertEqual(res_dict["cgsnapshots"][0]["status"], "creating") self.assertEqual(res_dict["cgsnapshots"][1]["description"], "this is a test cgsnapshot") self.assertEqual(res_dict["cgsnapshots"][1]["name"], "test_cgsnapshot") self.assertEqual(res_dict["cgsnapshots"][1]["id"], cgsnapshot_id2) self.assertEqual(res_dict["cgsnapshots"][1]["status"], "creating") self.assertEqual(res_dict["cgsnapshots"][2]["description"], "this is a test cgsnapshot") self.assertEqual(res_dict["cgsnapshots"][2]["name"], "test_cgsnapshot") self.assertEqual(res_dict["cgsnapshots"][2]["id"], cgsnapshot_id3) self.assertEqual(res_dict["cgsnapshots"][2]["status"], "creating") db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id3) db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id2) db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id1) db.volume_destroy(context.get_admin_context(), volume_id) db.consistencygroup_destroy(context.get_admin_context(), consistencygroup_id)
def test_list_cgsnapshots_xml(self): consistencygroup_id = utils.create_consistencygroup(self.context)['id'] volume_id = utils.create_volume( self.context, consistencygroup_id=consistencygroup_id)['id'] cgsnapshot_id1 = self._create_cgsnapshot( consistencygroup_id=consistencygroup_id) cgsnapshot_id2 = self._create_cgsnapshot( consistencygroup_id=consistencygroup_id) cgsnapshot_id3 = self._create_cgsnapshot( consistencygroup_id=consistencygroup_id) req = webob.Request.blank('/v2/fake/cgsnapshots') 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) cgsnapshot_list = dom.getElementsByTagName('cgsnapshot') self.assertEqual( cgsnapshot_list.item(0).getAttribute('id'), cgsnapshot_id1) self.assertEqual( cgsnapshot_list.item(1).getAttribute('id'), cgsnapshot_id2) self.assertEqual( cgsnapshot_list.item(2).getAttribute('id'), cgsnapshot_id3) db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id3) db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id2) db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id1) db.volume_destroy(context.get_admin_context(), volume_id) db.consistencygroup_destroy(context.get_admin_context(), consistencygroup_id)
def test_create_cgsnapshot_json(self): cgsnapshot_id = "1" consistencygroup_id = utils.create_consistencygroup(self.context)["id"] utils.create_volume(self.context, consistencygroup_id=consistencygroup_id)["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) LOG.info(res_dict) self.assertEqual(res.status_int, 202) self.assertIn("id", res_dict["cgsnapshot"]) db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id)
def test_list_cgsnapshots_detail_xml(self): consistencygroup_id = utils.create_consistencygroup(self.context)['id'] volume_id = utils.create_volume(self.context, consistencygroup_id= consistencygroup_id)['id'] cgsnapshot_id1 = self._create_cgsnapshot(consistencygroup_id= consistencygroup_id) cgsnapshot_id2 = self._create_cgsnapshot(consistencygroup_id= consistencygroup_id) cgsnapshot_id3 = self._create_cgsnapshot(consistencygroup_id= consistencygroup_id) req = webob.Request.blank('/v2/fake/cgsnapshots/detail') 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) cgsnapshot_detail = dom.getElementsByTagName('cgsnapshot') self.assertEqual('this is a test cgsnapshot', cgsnapshot_detail.item(0).getAttribute('description')) self.assertEqual('test_cgsnapshot', cgsnapshot_detail.item(0).getAttribute('name')) self.assertEqual(cgsnapshot_detail.item(0).getAttribute('id'), cgsnapshot_id1) self.assertEqual('creating', cgsnapshot_detail.item(0).getAttribute('status')) self.assertEqual(cgsnapshot_detail.item(1).getAttribute('description'), 'this is a test cgsnapshot') self.assertEqual('test_cgsnapshot', cgsnapshot_detail.item(1).getAttribute('name')) self.assertEqual(cgsnapshot_detail.item(1).getAttribute('id'), cgsnapshot_id2) self.assertEqual('creating', cgsnapshot_detail.item(1).getAttribute('status')) self.assertEqual(cgsnapshot_detail.item(2).getAttribute('description'), 'this is a test cgsnapshot') self.assertEqual('test_cgsnapshot', cgsnapshot_detail.item(2).getAttribute('name')) self.assertEqual(cgsnapshot_detail.item(2).getAttribute('id'), cgsnapshot_id3) self.assertEqual('creating', cgsnapshot_detail.item(2).getAttribute('status')) db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id3) db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id2) db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id1) db.volume_destroy(context.get_admin_context(), volume_id) db.consistencygroup_destroy(context.get_admin_context(), consistencygroup_id)
def test_create_consistencygroup_from_src_both_snap_cg(self): self.stubs.Set(volume_api.API, "create", stubs.stub_volume_create) 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'] snapshot_id = utils.create_snapshot( ctxt, volume_id, cgsnapshot_id=cgsnapshot_id, status='available')['id'] 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 = 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.snapshot_destroy(ctxt.elevated(), snapshot_id) db.cgsnapshot_destroy(ctxt.elevated(), cgsnapshot_id) db.volume_destroy(ctxt.elevated(), volume_id) db.consistencygroup_destroy(ctxt.elevated(), consistencygroup_id)
def test_create_consistencygroup_from_src_both_snap_cg(self): self.stubs.Set(volume_api.API, "create", stubs.stub_volume_create) 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'] snapshot_id = utils.create_snapshot(ctxt, volume_id, cgsnapshot_id=cgsnapshot_id, status='available')['id'] 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 = 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.snapshot_destroy(ctxt.elevated(), snapshot_id) db.cgsnapshot_destroy(ctxt.elevated(), cgsnapshot_id) db.volume_destroy(ctxt.elevated(), volume_id) db.consistencygroup_destroy(ctxt.elevated(), consistencygroup_id)
def test_show_cgsnapshot_xml_content_type(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/xml' req.headers['Accept'] = 'application/xml' res = req.get_response(fakes.wsgi_app()) self.assertEqual(200, res.status_int) dom = minidom.parseString(res.body) cgsnapshot = dom.getElementsByTagName('cgsnapshot') name = cgsnapshot.item(0).getAttribute('name') self.assertEqual('test_cgsnapshot', name.strip()) db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id) db.volume_destroy(context.get_admin_context(), volume_id) consistencygroup.destroy()
def test_list_cgsnapshots_detail_json(self): consistencygroup_id = utils.create_consistencygroup(self.context)['id'] volume_id = utils.create_volume(self.context, consistencygroup_id= consistencygroup_id)['id'] cgsnapshot_id1 = self._create_cgsnapshot(consistencygroup_id= consistencygroup_id) cgsnapshot_id2 = self._create_cgsnapshot(consistencygroup_id= consistencygroup_id) cgsnapshot_id3 = self._create_cgsnapshot(consistencygroup_id= consistencygroup_id) req = webob.Request.blank('/v2/fake/cgsnapshots/detail') req.method = 'GET' 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, 200) self.assertEqual(res_dict['cgsnapshots'][0]['description'], 'this is a test cgsnapshot') self.assertEqual(res_dict['cgsnapshots'][0]['name'], 'test_cgsnapshot') self.assertEqual(res_dict['cgsnapshots'][0]['id'], cgsnapshot_id1) self.assertEqual(res_dict['cgsnapshots'][0]['status'], 'creating') self.assertEqual(res_dict['cgsnapshots'][1]['description'], 'this is a test cgsnapshot') self.assertEqual(res_dict['cgsnapshots'][1]['name'], 'test_cgsnapshot') self.assertEqual(res_dict['cgsnapshots'][1]['id'], cgsnapshot_id2) self.assertEqual(res_dict['cgsnapshots'][1]['status'], 'creating') self.assertEqual(res_dict['cgsnapshots'][2]['description'], 'this is a test cgsnapshot') self.assertEqual(res_dict['cgsnapshots'][2]['name'], 'test_cgsnapshot') self.assertEqual(res_dict['cgsnapshots'][2]['id'], cgsnapshot_id3) self.assertEqual(res_dict['cgsnapshots'][2]['status'], 'creating') db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id3) db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id2) db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id1) db.volume_destroy(context.get_admin_context(), volume_id) db.consistencygroup_destroy(context.get_admin_context(), consistencygroup_id)
def test_list_cgsnapshots_json(self): consistencygroup = utils.create_consistencygroup(self.context) volume_id = utils.create_volume(self.context, consistencygroup_id= consistencygroup.id)['id'] cgsnapshot_id1 = self._create_cgsnapshot( consistencygroup_id=consistencygroup.id) cgsnapshot_id2 = self._create_cgsnapshot( consistencygroup_id=consistencygroup.id) cgsnapshot_id3 = self._create_cgsnapshot( consistencygroup_id=consistencygroup.id) req = webob.Request.blank('/v2/fake/cgsnapshots') 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(cgsnapshot_id1, res_dict['cgsnapshots'][0]['id']) self.assertEqual('test_cgsnapshot', res_dict['cgsnapshots'][0]['name']) self.assertEqual(cgsnapshot_id2, res_dict['cgsnapshots'][1]['id']) self.assertEqual('test_cgsnapshot', res_dict['cgsnapshots'][1]['name']) self.assertEqual(cgsnapshot_id3, res_dict['cgsnapshots'][2]['id']) self.assertEqual('test_cgsnapshot', res_dict['cgsnapshots'][2]['name']) db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id3) db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id2) db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id1) db.volume_destroy(context.get_admin_context(), volume_id) consistencygroup.destroy()
def destroy(self): with self.obj_as_admin(): db.cgsnapshot_destroy(self._context, self.id)
def destroy(self): with self.obj_as_admin(): db.cgsnapshot_destroy(self._context, self.id)
def destroy(self): with self.obj_as_admin(): updated_values = db.cgsnapshot_destroy(self._context, self.id) self.update(updated_values) self.obj_reset_changes(updated_values.keys())
def destroy(self): with self.obj_as_admin(): updated_values = db.cgsnapshot_destroy(self._context, self.id) self.update(updated_values) self.obj_reset_changes(updated_values.keys())