Ejemplo n.º 1
0
 def test_delete_keypair_not_found(self):
     db.process_get_all(IsA(context.RequestContext),
                        GID,
                        filters={"keypair_id": KEYPAIR_ID})\
         .AndReturn([])
     self.mox.StubOutWithMock(db, "keypair_delete")
     db.keypair_delete(IsA(context.RequestContext), GID, KEYPAIR_ID)\
         .AndRaise(exception.KeypairNotFound(keypair_id=KEYPAIR_ID))
     self.mox.ReplayAll()
     url = "/v1/groups/" + GID + "/keypairs/" + KEYPAIR_ID
     req = get_request(url, "DELETE")
     res = req.get_response(self.app)
     self.assertEqual(res.status_code, 404)
Ejemplo n.º 2
0
    def delete(self, req, gid, keypair_id):
        context = req.environ['rack.context']

        try:
            self._uuid_check(gid=gid, keypair_id=keypair_id)
            filters = {"keypair_id": keypair_id}
            processes = db.process_get_all(context, gid, filters=filters)
            if processes:
                raise exception.keypairInUse(keypair_id=keypair_id)

            keypair = db.keypair_get_by_keypair_id(context, gid, keypair_id)
            self.manager.keypair_delete(context, keypair["nova_keypair_id"])
            db.keypair_delete(context, gid, keypair_id)
        except exception.NotFound as e:
            raise webob.exc.HTTPNotFound(explanation=e.format_message())
        except exception.keypairInUse as e:
            raise webob.exc.HTTPConflict(explanation=e.format_message())
Ejemplo n.º 3
0
 def test_keypair_delete(self):
     gid = "12345678-1234-5678-9123-123456789012"
     self._create_group(gid)
     values_before = self._get_base_values(gid)
     keypair = db.keypair_create(self.user_ctxt, values_before)
     keypair_after = db.keypair_delete(
         self.user_ctxt, gid, keypair["keypair_id"])
     self.assertEqual("DELETING", keypair_after["status"])
     self.assertEqual(1, keypair_after["deleted"])
     self.assertIsNotNone(keypair_after.get("deleted_at"))
Ejemplo n.º 4
0
    def delete(self, req, gid, keypair_id):
        context = req.environ["rack.context"]

        try:
            self._uuid_check(gid=gid, keypair_id=keypair_id)
            filters = {"keypair_id": keypair_id}
            processes = db.process_get_all(context, gid, filters=filters)
            if processes:
                raise exception.keypairInUse(keypair_id=keypair_id)
            keypair = db.keypair_delete(context, gid, keypair_id)
            host = self.scheduler_rpcapi.select_destinations(context, request_spec={}, filter_properties={})
            self.operator_rpcapi.keypair_delete(context, host["host"], nova_keypair_id=keypair["nova_keypair_id"])
        except exception.NotFound as e:
            raise webob.exc.HTTPNotFound(explanation=e.format_message())
        except exception.keypairInUse as e:
            raise webob.exc.HTTPConflict(explanation=e.format_message())
        except Exception as e:
            LOG.warn(e)
            raise exception.KeypairDeleteFailed()