From fa29190557e65bc44b420a78890ec956143683f1 Mon Sep 17 00:00:00 2001 From: "OTSUKA, Yuanying" Date: Fri, 26 Dec 2014 14:18:06 +0900 Subject: [PATCH] Fix context is not set correctly Closes-Bug: #1406539 Change-Id: I4dac11e3f15ba51502c08b66299cc75f8fd45dec --- magnum/api/controllers/v1/bay.py | 9 ++------- magnum/api/controllers/v1/pod.py | 11 +++-------- magnum/api/controllers/v1/service.py | 12 ++++-------- 3 files changed, 9 insertions(+), 23 deletions(-) diff --git a/magnum/api/controllers/v1/bay.py b/magnum/api/controllers/v1/bay.py index 5e2b8286b8..01f2559cc3 100644 --- a/magnum/api/controllers/v1/bay.py +++ b/magnum/api/controllers/v1/bay.py @@ -26,9 +26,7 @@ from magnum.api.controllers import link from magnum.api.controllers.v1 import collection from magnum.api.controllers.v1 import types from magnum.api.controllers.v1 import utils as api_utils -from magnum.common import context from magnum.common import exception -from magnum.conductor import api from magnum import objects @@ -88,7 +86,6 @@ class Bay(base.APIBase): def __init__(self, **kwargs): super(Bay, self).__init__() - self.backend_api = api.API(context=context.RequestContext()) self.fields = [] fields = list(objects.Bay.fields) @@ -154,7 +151,6 @@ class BayCollection(collection.Collection): def __init__(self, **kwargs): self._type = 'bays' - self.backend_api = api.API(context=context.RequestContext()) @staticmethod def convert_with_links(rpc_bays, limit, url=None, expand=False, **kwargs): @@ -175,7 +171,6 @@ class BaysController(rest.RestController): """REST controller for Bays.""" def __init__(self): super(BaysController, self).__init__() - self.backend_api = api.API(context=context.RequestContext()) from_bays = False """A flag to indicate if the requests to this controller are coming @@ -197,7 +192,7 @@ class BaysController(rest.RestController): marker_obj = objects.Bay.get_by_uuid(pecan.request.context, marker) - bays = self.backend_api.bay_list(pecan.request.context, limit, + bays = pecan.request.rpcapi.bay_list(pecan.request.context, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) @@ -266,7 +261,7 @@ class BaysController(rest.RestController): raise exception.OperationNotPermitted new_bay = objects.Bay(pecan.request.context, **bay.as_dict()) - res_bay = self.backend_api.bay_create(new_bay) + res_bay = pecan.request.rpcapi.bay_create(new_bay) # Set the HTTP Location Header pecan.response.location = link.build_url('bays', res_bay.uuid) diff --git a/magnum/api/controllers/v1/pod.py b/magnum/api/controllers/v1/pod.py index 352b2e3b1a..2a41c6042a 100644 --- a/magnum/api/controllers/v1/pod.py +++ b/magnum/api/controllers/v1/pod.py @@ -24,9 +24,7 @@ from magnum.api.controllers import link from magnum.api.controllers.v1 import collection from magnum.api.controllers.v1 import types from magnum.api.controllers.v1 import utils as api_utils -from magnum.common import context from magnum.common import exception -from magnum.conductor import api from magnum import objects @@ -98,7 +96,6 @@ class Pod(base.APIBase): def __init__(self, **kwargs): super(Pod, self).__init__() - self.backend_api = api.API(context=context.RequestContext()) self.fields = [] fields = list(objects.Pod.fields) @@ -166,7 +163,6 @@ class PodCollection(collection.Collection): def __init__(self, **kwargs): self._type = 'pods' - self.backend_api = api.API(context=context.RequestContext()) @staticmethod def convert_with_links(rpc_pods, limit, url=None, expand=False, **kwargs): @@ -188,7 +184,6 @@ class PodsController(rest.RestController): def __init__(self): super(PodsController, self).__init__() - self.backend_api = api.API(context=context.RequestContext()) from_pods = False """A flag to indicate if the requests to this controller are coming @@ -210,7 +205,7 @@ class PodsController(rest.RestController): marker_obj = objects.Pod.get_by_uuid(pecan.request.context, marker) - pods = self.backend_api.pod_list(pecan.request.context, limit, + pods = pecan.request.rpcapi.pod_list(pecan.request.context, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) @@ -280,7 +275,7 @@ class PodsController(rest.RestController): pod_obj = objects.Pod(pecan.request.context, **pod.as_dict()) - new_pod = self.backend_api.pod_create(pod_obj) + new_pod = pecan.request.rpcapi.pod_create(pod_obj) # Set the HTTP Location Header pecan.response.location = link.build_url('pods', new_pod.uuid) return Pod.convert_with_links(new_pod) @@ -337,4 +332,4 @@ class PodsController(rest.RestController): rpc_pod = objects.Pod.get_by_uuid(pecan.request.context, pod_uuid) - self.backend_api.pod_delete(rpc_pod) + pecan.request.rpcapi.pod_delete(rpc_pod) diff --git a/magnum/api/controllers/v1/service.py b/magnum/api/controllers/v1/service.py index ce8935dba2..f78d11ed26 100644 --- a/magnum/api/controllers/v1/service.py +++ b/magnum/api/controllers/v1/service.py @@ -23,9 +23,7 @@ from magnum.api.controllers import link from magnum.api.controllers.v1 import collection from magnum.api.controllers.v1 import types from magnum.api.controllers.v1 import utils as api_utils -from magnum.common import context from magnum.common import exception -from magnum.conductor import api from magnum import objects @@ -86,7 +84,6 @@ class Service(base.APIBase): def __init__(self, **kwargs): super(Service, self).__init__() - self.backend_api = api.API(context=context.RequestContext()) self.fields = [] fields = list(objects.Service.fields) @@ -145,7 +142,6 @@ class ServiceCollection(collection.Collection): def __init__(self, **kwargs): self._type = 'services' - self.backend_api = api.API(context=context.RequestContext()) @staticmethod def convert_with_links(rpc_services, limit, url=None, @@ -168,7 +164,6 @@ class ServicesController(rest.RestController): def __init__(self): super(ServicesController, self).__init__() - self.backend_api = api.API(context=context.RequestContext()) from_services = False """A flag to indicate if the requests to this controller are coming @@ -190,7 +185,7 @@ class ServicesController(rest.RestController): marker_obj = objects.Service.get_by_uuid(pecan.request.context, marker) - services = self.backend_api.service_list(pecan.request.context, + services = pecan.request.rpcapi.service_list(pecan.request.context, limit, marker_obj, sort_key=sort_key, @@ -261,9 +256,10 @@ class ServicesController(rest.RestController): """ if self.from_services: raise exception.OperationNotPermitted + service_obj = objects.Service(pecan.request.context, **service.as_dict()) - new_service = self.backend_api.service_create(service_obj) + new_service = pecan.request.rpcapi.service_create(service_obj) # Set the HTTP Location Header pecan.response.location = link.build_url('services', new_service.uuid) return Service.convert_with_links(new_service) @@ -318,4 +314,4 @@ class ServicesController(rest.RestController): rpc_service = objects.Service.get_by_uuid(pecan.request.context, service_uuid) - self.backend_api.service_delete(rpc_service) + pecan.request.rpcapi.service_delete(rpc_service) \ No newline at end of file