def test_create_delete_consistencygroup_update_quota(self): ctxt = context.RequestContext('fake', 'fake', auth_token=True) name = 'mycg' description = 'consistency group 1' fake_type = {'id': '1', 'name': 'fake_type'} self.stubs.Set(db, 'volume_types_get_by_name_or_id', mock.Mock(return_value=[fake_type])) self.stubs.Set(self.cg_api, '_cast_create_consistencygroup', mock.Mock()) self.stubs.Set(self.cg_api, 'update_quota', mock.Mock()) cg = self.cg_api.create(ctxt, name, description, fake_type['name']) self.cg_api.update_quota.assert_called_once_with( ctxt, cg['id'], 1) self.assertEqual(cg['status'], 'creating') self.assertEqual(cg['host'], None) self.cg_api.update_quota.reset_mock() cg['status'] = 'error' self.cg_api.delete(ctxt, cg) self.cg_api.update_quota.assert_called_once_with( ctxt, cg['id'], -1, ctxt.project_id) cg = db.consistencygroup_get( context.get_admin_context(read_deleted='yes'), cg['id']) self.assertEqual(cg['status'], 'deleted')
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)
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)
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)
def test_create_delete_consistencygroup_update_quota(self): ctxt = context.RequestContext("fake", "fake", auth_token=True) name = "mycg" description = "consistency group 1" fake_type = {"id": "1", "name": "fake_type"} self.stubs.Set(db, "volume_types_get_by_name_or_id", mock.Mock(return_value=[fake_type])) self.stubs.Set(self.cg_api, "_cast_create_consistencygroup", mock.Mock()) self.stubs.Set(self.cg_api, "update_quota", mock.Mock()) cg = self.cg_api.create(ctxt, name, description, fake_type["name"]) self.cg_api.update_quota.assert_called_once_with(ctxt, cg["id"], 1) self.assertEqual(cg["status"], "creating") self.assertEqual(cg["host"], None) self.cg_api.update_quota.reset_mock() cg["status"] = "error" self.cg_api.delete(ctxt, cg) self.cg_api.update_quota.assert_called_once_with(ctxt, cg["id"], -1, ctxt.project_id) cg = db.consistencygroup_get(context.get_admin_context(read_deleted="yes"), cg["id"]) self.assertEqual(cg["status"], "deleted")
def test_create_delete_consistencygroup_update_quota(self): ctxt = context.RequestContext('fake', 'fake', auth_token=True) name = 'mycg' description = 'consistency group 1' fake_type = {'id': '1', 'name': 'fake_type'} self.stubs.Set(db, 'volume_types_get_by_name_or_id', mock.Mock(return_value=[fake_type])) self.stubs.Set(self.cg_api, '_cast_create_consistencygroup', mock.Mock()) self.stubs.Set(self.cg_api, 'update_quota', mock.Mock()) cg = self.cg_api.create(ctxt, name, description, fake_type['name']) self.cg_api.update_quota.assert_called_once_with(ctxt, cg['id'], 1) self.assertEqual(cg['status'], 'creating') self.assertEqual(cg['host'], None) self.cg_api.update_quota.reset_mock() cg['status'] = 'error' self.cg_api.delete(ctxt, cg) self.cg_api.update_quota.assert_called_once_with( ctxt, cg['id'], -1, ctxt.project_id) cg = db.consistencygroup_get( context.get_admin_context(read_deleted='yes'), cg['id']) self.assertEqual(cg['status'], 'deleted')
def _get_consistencygroup_attrib(consistencygroup_id, attrib_name): return db.consistencygroup_get(context.get_admin_context(), consistencygroup_id)[attrib_name]
def get_by_id(cls, context, id): db_consistencygroup = db.consistencygroup_get(context, id) return cls._from_db_object(context, cls(context), db_consistencygroup)