def test_delete_exeption_HTTPNotFound_db_securitygroup_id_not_found(self): self.mox.StubOutWithMock(db, "securitygroup_get_by_securitygroup_id") db.securitygroup_get_by_securitygroup_id( IsA(context.RequestContext), GID, SECURITYGROUP_ID)\ .AndReturn({"processes": [], "neutron_securitygroup_id": "fake_id"}) self.mox.StubOutWithMock(manager.ResourceOperator, "securitygroup_delete") manager.ResourceOperator.securitygroup_delete( IsA(context.RequestContext), "fake_id") self.mox.StubOutWithMock(db, "securitygroup_delete") db.securitygroup_delete(IsA(context.RequestContext), GID, SECURITYGROUP_ID)\ .AndRaise(exception.SecuritygroupNotFound( securitygroup_id=SECURITYGROUP_ID)) self.mox.ReplayAll() url = get_base_url(GID) + "/" + SECURITYGROUP_ID req = get_request(url, "DELETE") res = req.get_response(self.app) self.assertEqual(res.status_code, 404)
def test_show_manager_exception(self): self.mox.StubOutWithMock(db, "securitygroup_get_by_securitygroup_id") db.securitygroup_get_by_securitygroup_id(IsA( context.RequestContext), GID, SECURITYGROUP_ID1).AndRaise( exception.SecuritygroupNotFound( securitygroup_id=SECURITYGROUP_ID1)) self.mox.ReplayAll() url = get_base_url(GID) + "/" + SECURITYGROUP_ID1 req = get_request(url, 'GET') res = req.get_response(self.app) self.assertEqual(res.status_code, 404)
def test_delete_exeption_HTTPNotFound_securitygroup_not_found(self): self.mox.StubOutWithMock(db, "securitygroup_get_by_securitygroup_id") db.securitygroup_get_by_securitygroup_id( IsA(context.RequestContext), GID, SECURITYGROUP_ID)\ .AndRaise(exception.SecuritygroupNotFound( securitygroup_id=SECURITYGROUP_ID)) self.mox.ReplayAll() url = get_base_url(GID) + "/" + SECURITYGROUP_ID req = get_request(url, "DELETE") res = req.get_response(self.app) self.assertEqual(res.status_code, 404)
def securitygroup_update(context, gid, securitygroup_id, values): session = get_session() securitygroup_ref = session.query(models.Securitygroup). \ filter_by(deleted=0). \ filter_by(gid=gid). \ filter_by(securitygroup_id=securitygroup_id). \ first() if securitygroup_ref is None: raise exception.SecuritygroupNotFound( securitygroup_id=securitygroup_id) securitygroup_ref.update(values) securitygroup_ref.save(session) return dict(securitygroup_ref)
def securitygroup_get_by_securitygroup_id(context, gid, securitygroup_id): session = get_session() securitygroup = session.query(models.Securitygroup)\ .filter_by(deleted=0)\ .filter_by(gid=gid)\ .filter_by(securitygroup_id=securitygroup_id)\ .first() if not securitygroup: raise exception.SecuritygroupNotFound( securitygroup_id=securitygroup_id) securitygroup_dict = dict(securitygroup) securitygroup_dict.update( dict(processes=[dict(process) for process in securitygroup.processes])) return securitygroup_dict
def test_update_NotFound_db_securitygroup_create(self): self.mox.StubOutWithMock(db, "securitygroup_update") db.securitygroup_update( IsA(context.RequestContext), GID, SECURITYGROUP_ID, IsA(dict))\ .AndRaise(exception.SecuritygroupNotFound( securitygroup_id=SECURITYGROUP_ID)) self.mox.ReplayAll() request_body = {"securitygroup": {"is_default": "true"}} url = get_base_url(GID) + "/" + SECURITYGROUP_ID req = get_request(url, 'PUT', request_body) res = req.get_response(self.app) self.assertEqual(res.status_code, 404)
def _uuid_check(self, gid=None, pid=None, keypair_id=None, securitygroup_id=None): if gid: if not uuidutils.is_uuid_like(gid): raise exception.GroupNotFound(gid=gid) if pid: if not uuidutils.is_uuid_like(pid): raise exception.ProcessNotFound(pid=pid) if keypair_id: if not uuidutils.is_uuid_like(keypair_id): raise exception.KeypairNotFound(keypair_id=keypair_id) if securitygroup_id: if not uuidutils.is_uuid_like(securitygroup_id): raise exception.SecuritygroupNotFound( securitygroup_id=securitygroup_id)
def process_create(context, values, network_ids, securitygroup_ids): session = get_session() with session.begin(): process_ref = models.Process(**values) session.add(process_ref) try: if network_ids: for network_id in network_ids: network_ref = session.query(models.Network)\ .filter_by(deleted=0)\ .filter_by(gid=values["gid"])\ .filter_by(network_id=network_id)\ .first() if network_ref is None: raise exception.NetworkNotFound(network_id=network_id) session.add( models.ProcessNetwork( pid=values["pid"], network_id=network_ref.network_id)) if securitygroup_ids: for securitygroup_id in securitygroup_ids: securitygroup_ref = session.query(models.Securitygroup)\ .filter_by(deleted=0)\ .filter_by(gid=values["gid"])\ .filter_by(securitygroup_id=securitygroup_id)\ .first() if securitygroup_ref is None: raise exception.SecuritygroupNotFound( securitygroup_id=securitygroup_id) session.add( models.ProcessSecuritygroup( pid=values["pid"], securitygroup_id=securitygroup_ref.securitygroup_id )) session.flush() except db_exc.DBDuplicateEntry: msg = _("securitygroup or network is duplicated") raise exception.InvalidInput(reason=msg) return _get_process_dict(process_ref)
def securitygroup_delete(context, gid, securitygroup_id): session = get_session() securitygroup_ref = session.query(models.Securitygroup). \ filter_by(deleted=0). \ filter_by(gid=gid). \ filter_by(securitygroup_id=securitygroup_id). \ first() if securitygroup_ref is None: raise exception.SecuritygroupNotFound( securitygroup_id=securitygroup_id) securitygroup_ref.update({ "deleted": 1, 'deleted_at': timeutils.utcnow(), "status": "DELETING" }) securitygroup_ref.save(session) return dict(securitygroup_ref)
def fake_securitygroup_get_by_securitygroup_id(context, gid, securitygroup_id): securitygroup_list = _base_securitygroup_get_response(context) for securitygroup in securitygroup_list: if securitygroup["securitygroup_id"] == securitygroup_id: return securitygroup raise exception.SecuritygroupNotFound(securitygroup_id=securitygroup_id)