Change ctxt to context to for consistency

rename ctxt in all files under magnum/

Closes-Bug: #1416922
Change-Id: I28870d1381bd7107d431d5d3c76ad636f6d1d90a
This commit is contained in:
Davanum Srinivas 2015-02-08 21:56:25 -05:00
parent 33d1084d7a
commit 6a84010253
21 changed files with 173 additions and 172 deletions

View File

@ -237,11 +237,11 @@ class BaysController(rest.RestController):
raise exception.OperationNotPermitted
bay_dict = bay.as_dict()
ctxt = pecan.request.context
auth_token = ctxt.auth_token_info['token']
context = pecan.request.context
auth_token = context.auth_token_info['token']
bay_dict['project_id'] = auth_token['project']['id']
bay_dict['user_id'] = auth_token['user']['id']
new_bay = objects.Bay(ctxt, **bay_dict)
new_bay = objects.Bay(context, **bay_dict)
res_bay = pecan.request.rpcapi.bay_create(new_bay)
# Set the HTTP Location Header

View File

@ -230,11 +230,11 @@ class BayModelsController(rest.RestController):
raise exception.OperationNotPermitted
baymodel_dict = baymodel.as_dict()
ctxt = pecan.request.context
auth_token = ctxt.auth_token_info['token']
context = pecan.request.context
auth_token = context.auth_token_info['token']
baymodel_dict['project_id'] = auth_token['project']['id']
baymodel_dict['user_id'] = auth_token['user']['id']
new_baymodel = objects.BayModel(ctxt, **baymodel_dict)
new_baymodel = objects.BayModel(context, **baymodel_dict)
new_baymodel.create()
# Set the HTTP Location Header
pecan.response.location = link.build_url('baymodels',

View File

@ -26,7 +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 context as magnum_context
from magnum.common import exception
from magnum.conductor import api
from magnum import objects
@ -121,7 +121,7 @@ class ContainerCollection(collection.Collection):
sample.containers = [Container.sample(expand=False)]
return sample
backend_api = api.API(context=context.RequestContext())
backend_api = api.API(context=magnum_context.RequestContext())
class StartController(object):
@ -305,11 +305,11 @@ class ContainersController(rest.RestController):
raise exception.OperationNotPermitted
container_dict = container.as_dict()
ctxt = pecan.request.context
auth_token = ctxt.auth_token_info['token']
context = pecan.request.context
auth_token = context.auth_token_info['token']
container_dict['project_id'] = auth_token['project']['id']
container_dict['user_id'] = auth_token['user']['id']
new_container = objects.Container(ctxt, **container_dict)
new_container = objects.Container(context, **container_dict)
new_container.create()
res_container = backend_api.container_create(new_container.name,
new_container.uuid,

View File

@ -211,11 +211,11 @@ class NodesController(rest.RestController):
raise exception.OperationNotPermitted
node_dict = node.as_dict()
ctxt = pecan.request.context
auth_token = ctxt.auth_token_info['token']
context = pecan.request.context
auth_token = context.auth_token_info['token']
node_dict['project_id'] = auth_token['project']['id']
node_dict['user_id'] = auth_token['user']['id']
new_node = objects.Node(ctxt, **node_dict)
new_node = objects.Node(context, **node_dict)
new_node.create()
# Set the HTTP Location Header
pecan.response.location = link.build_url('nodes', new_node.uuid)

View File

@ -232,11 +232,11 @@ class PodsController(rest.RestController):
pod.parse_manifest()
pod_dict = pod.as_dict()
ctxt = pecan.request.context
auth_token = ctxt.auth_token_info['token']
context = pecan.request.context
auth_token = context.auth_token_info['token']
pod_dict['project_id'] = auth_token['project']['id']
pod_dict['user_id'] = auth_token['user']['id']
pod_obj = objects.Pod(ctxt, **pod_dict)
pod_obj = objects.Pod(context, **pod_dict)
new_pod = pecan.request.rpcapi.pod_create(pod_obj)
# Set the HTTP Location Header
pecan.response.location = link.build_url('pods', new_pod.uuid)

View File

@ -241,11 +241,11 @@ class ReplicationControllersController(rest.RestController):
rc.parse_manifest()
rc_dict = rc.as_dict()
ctxt = pecan.request.context
auth_token = ctxt.auth_token_info['token']
context = pecan.request.context
auth_token = context.auth_token_info['token']
rc_dict['project_id'] = auth_token['project']['id']
rc_dict['user_id'] = auth_token['user']['id']
rc_obj = objects.ReplicationController(ctxt, **rc_dict)
rc_obj = objects.ReplicationController(context, **rc_dict)
new_rc = pecan.request.rpcapi.rc_create(rc_obj)
# Set the HTTP Location Header
pecan.response.location = link.build_url('rcs', new_rc.uuid)

View File

@ -249,11 +249,11 @@ class ServicesController(rest.RestController):
service.parse_manifest()
service_dict = service.as_dict()
ctxt = pecan.request.context
auth_token = ctxt.auth_token_info['token']
context = pecan.request.context
auth_token = context.auth_token_info['token']
service_dict['project_id'] = auth_token['project']['id']
service_dict['user_id'] = auth_token['user']['id']
service_obj = objects.Service(ctxt, **service_dict)
service_obj = objects.Service(context, **service_dict)
new_service = pecan.request.rpcapi.service_create(service_obj)
# Set the HTTP Location Header
pecan.response.location = link.build_url('services', new_service.uuid)

View File

@ -19,7 +19,7 @@ from keystoneclient.v3 import client as kc_v3
from oslo_config import cfg
from oslo_utils import importutils
from magnum.common import context
from magnum.common import context as magnum_context
from magnum.common import exception
from magnum.openstack.common._i18n import _
from magnum.openstack.common import log as logging
@ -179,7 +179,7 @@ class KeystoneClientV3(object):
impersonation=True,
role_names=roles)
trust_context = context.RequestContext.from_dict(
trust_context = magnum_context.RequestContext.from_dict(
self.context.to_dict())
trust_context.trust_id = trust.id
return trust_context

View File

@ -18,7 +18,7 @@ import eventlet
from oslo_config import cfg
import oslo_messaging as messaging
import magnum.common.context
from magnum.common import context as magnum_context
from magnum.objects import base as objects_base
@ -58,7 +58,7 @@ class RequestContextSerializer(messaging.Serializer):
return context.to_dict()
def deserialize_context(self, context):
return magnum.common.context.RequestContext.from_dict(context)
return magnum_context.RequestContext.from_dict(context)
class Service(object):

View File

@ -31,17 +31,18 @@ class API(rpc_service.API):
# Bay Model Operations
def baymodel_create(self, ctxt, baymodel):
return baymodel.create(ctxt)
def baymodel_create(self, context, baymodel):
return baymodel.create(context)
def baymodel_list(self, ctxt, limit, marker, sort_key, sort_dir):
return objects.BayModel.list(ctxt, limit, marker, sort_key, sort_dir)
def baymodel_list(self, context, limit, marker, sort_key, sort_dir):
return objects.BayModel.list(context, limit, marker,
sort_key, sort_dir)
def baymodel_delete(self, ctxt, uuid):
def baymodel_delete(self, context, uuid):
baymodel = objects.BayModel.get_by_uuid(uuid)
return baymodel.destroy()
def baymodel_show(self, ctxt, uuid):
def baymodel_show(self, context, uuid):
return objects.BayModel.get_by_uuid(uuid)
# Bay Operations
@ -55,8 +56,8 @@ class API(rpc_service.API):
def bay_delete(self, uuid):
return self._call('bay_delete', uuid=uuid)
def bay_show(self, ctxt, uuid):
return objects.Bay.get_by_uuid(ctxt, uuid)
def bay_show(self, context, uuid):
return objects.Bay.get_by_uuid(context, uuid)
# Service Operations
@ -71,8 +72,8 @@ class API(rpc_service.API):
def service_delete(self, uuid):
return self._call('service_delete', uuid=uuid)
def service_show(self, ctxt, uuid):
return objects.Service.get_by_uuid(ctxt, uuid)
def service_show(self, context, uuid):
return objects.Service.get_by_uuid(context, uuid)
# Pod Operations
@ -85,8 +86,8 @@ class API(rpc_service.API):
def pod_delete(self, uuid):
return self._call('pod_delete', uuid=uuid)
def pod_show(self, ctxt, uuid):
return objects.Pod.get_by_uuid(ctxt, uuid)
def pod_show(self, context, uuid):
return objects.Pod.get_by_uuid(context, uuid)
# ReplicationController Operations
@ -100,8 +101,8 @@ class API(rpc_service.API):
def rc_delete(self, uuid):
return self._call('rc_delete', uuid=uuid)
def rc_show(self, ctxt, uuid):
return objects.ReplicationController.get_by_uuid(ctxt, uuid)
def rc_show(self, context, uuid):
return objects.ReplicationController.get_by_uuid(context, uuid)
# Container operations

View File

@ -28,18 +28,18 @@ class Handler(object):
# Bay Operations
def bay_create(self, ctxt, bay):
def bay_create(self, context, bay):
LOG.debug('ironic bay_create')
bay.create()
return bay
def bay_delete(self, ctxt, uuid):
def bay_delete(self, context, uuid):
LOG.debug('ironic bay_delete')
bay = objects.Bay.get_by_uuid(ctxt, uuid)
bay = objects.Bay.get_by_uuid(context, uuid)
bay.destroy()
return None
def bay_show(self, ctxt, uuid):
def bay_show(self, context, uuid):
LOG.debug('ironic bay_show')
bay = objects.Bay.get_by_uuid(ctxt, uuid)
bay = objects.Bay.get_by_uuid(context, uuid)
return bay

View File

@ -65,8 +65,8 @@ def _extract_bay_definition(baymodel):
return bay_definition
def _create_stack(ctxt, osc, bay):
baymodel = objects.BayModel.get_by_uuid(ctxt, bay.baymodel_id)
def _create_stack(context, osc, bay):
baymodel = objects.BayModel.get_by_uuid(context, bay.baymodel_id)
bay_definition = _extract_bay_definition(baymodel)
if bay.node_count:
@ -109,12 +109,12 @@ class Handler(object):
# Bay Operations
def bay_create(self, ctxt, bay):
def bay_create(self, context, bay):
LOG.debug('k8s_heat bay_create')
osc = clients.OpenStackClients(ctxt)
osc = clients.OpenStackClients(context)
created_stack = _create_stack(ctxt, osc, bay)
created_stack = _create_stack(context, osc, bay)
bay.stack_id = created_stack['stack']['id']
bay.create()
@ -126,10 +126,10 @@ class Handler(object):
return bay
def bay_delete(self, ctxt, uuid):
def bay_delete(self, context, uuid):
LOG.debug('k8s_heat bay_delete')
osc = clients.OpenStackClients(ctxt)
bay = objects.Bay.get_by_uuid(ctxt, uuid)
osc = clients.OpenStackClients(context)
bay = objects.Bay.get_by_uuid(context, uuid)
stack_id = bay.stack_id
# TODO(yuanying): handle stack status DELETE_IN_PROGRESS
#

View File

@ -74,7 +74,7 @@ class Handler(object):
# Container operations
def container_create(self, ctxt, name, container_uuid, container):
def container_create(self, context, name, container_uuid, container):
image_id = container.image_id
LOG.debug('Creating container with image %s name %s'
% (image_id, name))
@ -88,7 +88,7 @@ class Handler(object):
except errors.APIError as api_error:
raise Exception("Docker API Error : %s" % str(api_error))
def container_list(self, ctxt):
def container_list(self, context):
LOG.debug("container_list")
try:
container_list = self.docker.containers()
@ -96,7 +96,7 @@ class Handler(object):
except errors.APIError as api_error:
raise Exception("Docker API Error : %s" % str(api_error))
def container_delete(self, ctxt, container_uuid):
def container_delete(self, context, container_uuid):
LOG.debug("container_delete %s" % container_uuid)
try:
docker_id = self._find_container_by_name(container_uuid)
@ -104,7 +104,7 @@ class Handler(object):
except errors.APIError as api_error:
raise Exception("Docker API Error : %s" % str(api_error))
def container_show(self, ctxt, container_uuid):
def container_show(self, context, container_uuid):
LOG.debug("container_show %s" % container_uuid)
try:
docker_id = self._find_container_by_name(container_uuid)
@ -112,7 +112,7 @@ class Handler(object):
except errors.APIError as api_error:
raise Exception("Docker API Error : %s" % str(api_error))
def container_reboot(self, ctxt, container_uuid):
def container_reboot(self, context, container_uuid):
LOG.debug("container_reboot %s" % container_uuid)
try:
docker_id = self._find_container_by_name(container_uuid)
@ -120,7 +120,7 @@ class Handler(object):
except errors.APIError as api_error:
raise Exception("Docker API Error : %s" % str(api_error))
def container_stop(self, ctxt, container_uuid):
def container_stop(self, context, container_uuid):
LOG.debug("container_stop %s" % container_uuid)
try:
docker_id = self._find_container_by_name(container_uuid)
@ -128,7 +128,7 @@ class Handler(object):
except errors.APIError as api_error:
raise Exception("Docker API Error : %s" % str(api_error))
def container_start(self, ctxt, container_uuid):
def container_start(self, context, container_uuid):
LOG.debug("Starting container %s" % container_uuid)
try:
docker_id = self._find_container_by_name(container_uuid)
@ -137,7 +137,7 @@ class Handler(object):
except errors.APIError as api_error:
raise Exception("Docker API Error : %s" % str(api_error))
def container_pause(self, ctxt, container_uuid):
def container_pause(self, context, container_uuid):
LOG.debug("container_pause %s" % container_uuid)
try:
docker_id = self._find_container_by_name(container_uuid)
@ -145,7 +145,7 @@ class Handler(object):
except errors.APIError as api_error:
raise Exception("Docker API Error : %s" % str(api_error))
def container_unpause(self, ctxt, container_uuid):
def container_unpause(self, context, container_uuid):
LOG.debug("container_unpause %s" % container_uuid)
try:
docker_id = self._find_container_by_name(container_uuid)
@ -153,7 +153,7 @@ class Handler(object):
except errors.APIError as api_error:
raise Exception("Docker API Error : %s" % str(api_error))
def container_logs(self, ctxt, container_uuid):
def container_logs(self, context, container_uuid):
LOG.debug("container_logs %s" % container_uuid)
try:
docker_id = self._find_container_by_name(container_uuid)
@ -161,7 +161,7 @@ class Handler(object):
except errors.APIError as api_error:
raise Exception("Docker API Error : %s" % str(api_error))
def container_execute(self, ctxt, container_uuid, command):
def container_execute(self, context, container_uuid, command):
LOG.debug("container_execute %s command %s" %
(container_uuid, command))
try:

View File

@ -37,21 +37,21 @@ kubernetes_opts = [
cfg.CONF.register_opts(kubernetes_opts, group='kubernetes')
def _retrieve_bay(ctxt, obj):
def _retrieve_bay(context, obj):
bay_uuid = obj.bay_uuid
return objects.Bay.get_by_uuid(ctxt, bay_uuid)
return objects.Bay.get_by_uuid(context, bay_uuid)
def _retrieve_baymodel(ctxt, obj):
return objects.BayModel.get_by_uuid(ctxt, obj.baymodel_id)
def _retrieve_baymodel(context, obj):
return objects.BayModel.get_by_uuid(context, obj.baymodel_id)
def _retrieve_k8s_master_url(ctxt, obj):
def _retrieve_k8s_master_url(context, obj):
apiserver_port = cfg.CONF.kubernetes.k8s_port
if hasattr(obj, 'bay_uuid'):
obj = _retrieve_bay(ctxt, obj)
obj = _retrieve_bay(context, obj)
baymodel = _retrieve_baymodel(ctxt, obj)
baymodel = _retrieve_baymodel(context, obj)
if baymodel.apiserver_port is not None:
apiserver_port = baymodel.apiserver_port
@ -63,10 +63,10 @@ def _retrieve_k8s_master_url(ctxt, obj):
return "%(k8s_protocol)s://%(master_address)s:%(k8s_port)s" % params
def _object_has_stack(ctxt, obj):
osc = clients.OpenStackClients(ctxt)
def _object_has_stack(context, obj):
osc = clients.OpenStackClients(context)
if hasattr(obj, 'bay_uuid'):
obj = _retrieve_bay(ctxt, obj)
obj = _retrieve_bay(context, obj)
stack = osc.heat().stacks.get(obj.stack_id)
if (stack.stack_status == 'DELETE_COMPLETE' or
@ -89,44 +89,44 @@ class Handler(object):
super(Handler, self).__init__()
self.kube_cli = kube_utils.KubeClient()
def service_create(self, ctxt, service):
def service_create(self, context, service):
LOG.debug("service_create")
k8s_master_url = _retrieve_k8s_master_url(ctxt, service)
k8s_master_url = _retrieve_k8s_master_url(context, service)
# trigger a kubectl command
status = self.kube_cli.service_create(k8s_master_url, service)
if not status:
return None
# call the service object to persist in db
service.create(ctxt)
service.create(context)
return service
def service_update(self, ctxt, service):
def service_update(self, context, service):
LOG.debug("service_update")
# trigger a kubectl command
status = self.kube_cli.service_update(service)
if not status:
return None
# call the service object to persist in db
service.refresh(ctxt)
service.refresh(context)
return service
def service_list(self, ctxt):
def service_list(self, context):
LOG.debug("service_list")
return self.kube_cli.service_list()
def service_delete(self, ctxt, uuid):
def service_delete(self, context, uuid):
LOG.debug("service_delete")
service = objects.Service.get_by_uuid(ctxt, uuid)
k8s_master_url = _retrieve_k8s_master_url(ctxt, service)
if _object_has_stack(ctxt, service):
service = objects.Service.get_by_uuid(context, uuid)
k8s_master_url = _retrieve_k8s_master_url(context, service)
if _object_has_stack(context, service):
# trigger a kubectl command
status = self.kube_cli.service_delete(k8s_master_url, service.name)
if not status:
return None
# call the service object to persist in db
service.destroy(ctxt)
service.destroy(context)
def service_get(self, ctxt, uuid):
def service_get(self, context, uuid):
LOG.debug("service_get")
return self.kube_cli.service_get(uuid)
@ -135,9 +135,9 @@ class Handler(object):
return self.kube_cli.service_show(uuid)
# Pod Operations
def pod_create(self, ctxt, pod):
def pod_create(self, context, pod):
LOG.debug("pod_create")
k8s_master_url = _retrieve_k8s_master_url(ctxt, pod)
k8s_master_url = _retrieve_k8s_master_url(context, pod)
# trigger a kubectl command
status = self.kube_cli.pod_create(k8s_master_url, pod)
# TODO(yuanying): Is this correct location of updating status?
@ -154,70 +154,70 @@ class Handler(object):
pod.create()
return pod
def pod_update(self, ctxt, pod):
def pod_update(self, context, pod):
LOG.debug("pod_update")
# trigger a kubectl command
status = self.kube_cli.pod_update(pod)
if not status:
return None
# call the pod object to persist in db
pod.refresh(ctxt)
pod.refresh(context)
return pod
def pod_list(self, ctxt):
def pod_list(self, context):
LOG.debug("pod_list")
return self.kube_cli.pod_list()
def pod_delete(self, ctxt, uuid):
def pod_delete(self, context, uuid):
LOG.debug("pod_delete ")
# trigger a kubectl command
pod = objects.Pod.get_by_uuid(ctxt, uuid)
k8s_master_url = _retrieve_k8s_master_url(ctxt, pod)
if _object_has_stack(ctxt, pod):
pod = objects.Pod.get_by_uuid(context, uuid)
k8s_master_url = _retrieve_k8s_master_url(context, pod)
if _object_has_stack(context, pod):
status = self.kube_cli.pod_delete(k8s_master_url, pod.name)
if not status:
return None
# call the pod object to persist in db
pod.destroy(ctxt)
pod.destroy(context)
def pod_get(self, ctxt, uuid):
def pod_get(self, context, uuid):
LOG.debug("pod_get")
return self.kube_cli.pod_get(uuid)
def pod_show(self, ctxt, uuid):
def pod_show(self, context, uuid):
LOG.debug("pod_show")
return self.kube_cli.pod_show(uuid)
# Replication Controller Operations
def rc_create(self, ctxt, rc):
def rc_create(self, context, rc):
LOG.debug("rc_create")
k8s_master_url = _retrieve_k8s_master_url(ctxt, rc)
k8s_master_url = _retrieve_k8s_master_url(context, rc)
# trigger a kubectl command
status = self.kube_cli.rc_create(k8s_master_url, rc)
if not status:
return None
# call the rc object to persist in db
rc.create(ctxt)
rc.create(context)
return rc
def rc_update(self, ctxt, rc):
def rc_update(self, context, rc):
LOG.debug("rc_update")
# trigger a kubectl command
status = self.kube_cli.rc_update(rc)
if not status:
return None
# call the rc object to persist in db
rc.refresh(ctxt)
rc.refresh(context)
return rc
def rc_delete(self, ctxt, uuid):
def rc_delete(self, context, uuid):
LOG.debug("rc_delete ")
rc = objects.ReplicationController.get_by_uuid(ctxt, uuid)
k8s_master_url = _retrieve_k8s_master_url(ctxt, rc)
if _object_has_stack(ctxt, rc):
rc = objects.ReplicationController.get_by_uuid(context, uuid)
k8s_master_url = _retrieve_k8s_master_url(context, rc)
if _object_has_stack(context, rc):
# trigger a kubectl command
status = self.kube_cli.pod_delete(k8s_master_url, rc.name)
if not status:
return None
# call the rc object to persist in db
rc.destroy(ctxt)
rc.destroy(context)

View File

@ -17,7 +17,7 @@
import collections
import copy
from oslo_context import context
from oslo_context import context as oslo_context
import oslo_messaging as messaging
import six
@ -121,26 +121,26 @@ def remotable_classmethod(fn):
def remotable(fn):
"""Decorator for remotable object methods."""
def wrapper(self, *args, **kwargs):
ctxt = self._context
context = self._context
try:
if isinstance(args[0], (context.RequestContext)):
ctxt = args[0]
if isinstance(args[0], (oslo_context.RequestContext)):
context = args[0]
args = args[1:]
except IndexError:
pass
if ctxt is None:
if context is None:
raise exception.OrphanedObjectError(method=fn.__name__,
objtype=self.obj_name())
if MagnumObject.indirection_api:
updates, result = MagnumObject.indirection_api.object_action(
ctxt, self, fn.__name__, args, kwargs)
context, self, fn.__name__, args, kwargs)
for key, value in updates.iteritems():
if key in self.fields:
self[key] = self._attr_from_primitive(key, value)
self._changed_fields = set(updates.get('obj_what_changed', []))
return result
else:
return fn(self, ctxt, *args, **kwargs)
return fn(self, context, *args, **kwargs)
return wrapper

View File

@ -21,7 +21,7 @@ import oslo_messaging as messaging
from magnum.api.controllers import root
from magnum.api import hooks
from magnum.common import context
from magnum.common import context as magnum_context
from magnum.tests.api import base as api_base
from magnum.tests import base
from magnum.tests import fakes
@ -38,7 +38,7 @@ class TestContextHook(base.BaseTestCase):
hook = hooks.ContextHook()
hook.before(state)
ctx = state.request.context
self.assertIsInstance(ctx, context.RequestContext)
self.assertIsInstance(ctx, magnum_context.RequestContext)
self.assertEqual(ctx.auth_token,
fakes.fakeAuthTokenHeaders['X-Auth-Token'])
self.assertEqual(ctx.project_id,
@ -59,7 +59,7 @@ class TestContextHook(base.BaseTestCase):
hook = hooks.ContextHook()
hook.before(state)
ctx = state.request.context
self.assertIsInstance(ctx, context.RequestContext)
self.assertIsInstance(ctx, magnum_context.RequestContext)
self.assertEqual(fakes.fakeAuthTokenHeaders['X-Auth-Token'],
ctx.auth_token)
self.assertEqual('assert_this', ctx.auth_token_info)
@ -72,7 +72,7 @@ class TestNoExceptionTracebackHook(api_base.FunctionalTest):
' line 434, in _process_data\\n **args)',
u' File "/opt/stack/magnum/magnum/openstack/common/rpc/'
'dispatcher.py", line 172, in dispatch\\n result ='
' getattr(proxyobj, method)(ctxt, **kwargs)']
' getattr(proxyobj, method)(context, **kwargs)']
MSG_WITHOUT_TRACE = "Test exception message."
MSG_WITH_TRACE = MSG_WITHOUT_TRACE + "\n" + "\n".join(TRACE)

View File

@ -75,12 +75,12 @@ class TestCase(base.BaseTestCase):
if not kwargs.get('user_id'):
kwargs['user_id'] = 'fake_user'
ctxt = magnum_context.RequestContext(*args, **kwargs)
return magnum_context.RequestContext.from_dict(ctxt.to_dict())
context = magnum_context.RequestContext(*args, **kwargs)
return magnum_context.RequestContext.from_dict(context.to_dict())
p = mock.patch.object(magnum_context, 'make_context',
side_effect=make_context)
self.mock_make_ctxt = p.start()
self.mock_make_context = p.start()
self.addCleanup(p.stop)
self.useFixture(conf_fixture.ConfFixture(cfg.CONF))

View File

@ -12,28 +12,28 @@
# License for the specific language governing permissions and limitations
# under the License.
from magnum.common import context
from magnum.common import context as magnum_context
from magnum.tests import base
class ContextTestCase(base.TestCase):
def _create_context(self):
return context.RequestContext(auth_token='auth_token1',
auth_url='auth_url1',
domain_id='domain_id1',
domain_name='domain_name1',
user='user1',
user_id='user-id1',
project='tenant1',
project_id='tenant-id1',
is_admin=True,
is_public_api=True,
read_only=True,
show_deleted=True,
request_id='request_id1',
trust_id='trust_id1',
auth_token_info='auth_token_info1')
return magnum_context.RequestContext(auth_token='auth_token1',
auth_url='auth_url1',
domain_id='domain_id1',
domain_name='domain_name1',
user='user1',
user_id='user-id1',
project='tenant1',
project_id='tenant-id1',
is_admin=True,
is_public_api=True,
read_only=True,
show_deleted=True,
request_id='request_id1',
trust_id='trust_id1',
auth_token_info='token_info1')
def test_context(self):
ctx = self._create_context()
@ -52,11 +52,11 @@ class ContextTestCase(base.TestCase):
self.assertTrue(ctx.show_deleted)
self.assertEqual("request_id1", ctx.request_id)
self.assertEqual("trust_id1", ctx.trust_id)
self.assertEqual("auth_token_info1", ctx.auth_token_info)
self.assertEqual("token_info1", ctx.auth_token_info)
def test_to_dict_from_dict(self):
ctx = self._create_context()
ctx2 = context.RequestContext.from_dict(ctx.to_dict())
ctx2 = magnum_context.RequestContext.from_dict(ctx.to_dict())
self.assertEqual(ctx.auth_token, ctx2.auth_token)
self.assertEqual(ctx.auth_url, ctx2.auth_url)

View File

@ -20,7 +20,7 @@ import netaddr
from oslo_utils import timeutils
import six
from magnum.common import context
from magnum.common import context as magnum_context
from magnum.common import exception
from magnum.objects import base
from magnum.objects import utils
@ -321,10 +321,10 @@ class _TestObject(object):
base.MagnumObject.obj_class_from_name, 'foo', '1.0')
def test_with_alternate_context(self):
ctxt1 = context.RequestContext('foo', 'foo')
ctxt2 = context.RequestContext('bar', project_id='alternate')
obj = MyObj.query(ctxt1)
obj.update_test(ctxt2)
context1 = magnum_context.RequestContext('foo', 'foo')
context2 = magnum_context.RequestContext('bar', project_id='alternate')
obj = MyObj.query(context1)
obj.update_test(context2)
self.assertEqual('alternate-context', obj.bar)
self.assertRemotes()

View File

@ -18,7 +18,7 @@ from magnum import objects
from magnum.tests.db import utils as db_utils
def get_test_baymodel(ctxt, **kw):
def get_test_baymodel(context, **kw):
"""Return a BayModel object with appropriate attributes.
NOTE: The object leaves the attributes marked as changed, such
@ -28,24 +28,24 @@ def get_test_baymodel(ctxt, **kw):
# Let DB generate ID if it isn't specified explicitly
if 'id' not in kw:
del db_baymodel['id']
baymodel = objects.BayModel(ctxt)
baymodel = objects.BayModel(context)
for key in db_baymodel:
setattr(baymodel, key, db_baymodel[key])
return baymodel
def create_test_baymodel(ctxt, **kw):
def create_test_baymodel(context, **kw):
"""Create and return a test baymodel object.
Create a baymodel in the DB and return a BayModel object with appropriate
attributes.
"""
baymodel = get_test_baymodel(ctxt, **kw)
baymodel = get_test_baymodel(context, **kw)
baymodel.create()
return baymodel
def get_test_bay(ctxt, **kw):
def get_test_bay(context, **kw):
"""Return a Bay object with appropriate attributes.
NOTE: The object leaves the attributes marked as changed, such
@ -55,24 +55,24 @@ def get_test_bay(ctxt, **kw):
# Let DB generate ID if it isn't specified explicitly
if 'id' not in kw:
del db_bay['id']
bay = objects.Bay(ctxt)
bay = objects.Bay(context)
for key in db_bay:
setattr(bay, key, db_bay[key])
return bay
def create_test_bay(ctxt, **kw):
def create_test_bay(context, **kw):
"""Create and return a test bay object.
Create a bay in the DB and return a Bay object with appropriate
attributes.
"""
bay = get_test_bay(ctxt, **kw)
bay = get_test_bay(context, **kw)
bay.create()
return bay
def get_test_pod(ctxt, **kw):
def get_test_pod(context, **kw):
"""Return a Pod object with appropriate attributes.
NOTE: The object leaves the attributes marked as changed, such
@ -82,24 +82,24 @@ def get_test_pod(ctxt, **kw):
# Let DB generate ID if it isn't specified explicitly
if 'id' not in kw:
del db_pod['id']
pod = objects.Pod(ctxt)
pod = objects.Pod(context)
for key in db_pod:
setattr(pod, key, db_pod[key])
return pod
def create_test_pod(ctxt, **kw):
def create_test_pod(context, **kw):
"""Create and return a test pod object.
Create a pod in the DB and return a Pod object with appropriate
attributes.
"""
pod = get_test_pod(ctxt, **kw)
pod = get_test_pod(context, **kw)
pod.create()
return pod
def get_test_service(ctxt, **kw):
def get_test_service(context, **kw):
"""Return a Service object with appropriate attributes.
NOTE: The object leaves the attributes marked as changed, such
@ -109,24 +109,24 @@ def get_test_service(ctxt, **kw):
# Let DB generate ID if it isn't specified explicitly
if 'id' not in kw:
del db_service['id']
service = objects.Service(ctxt)
service = objects.Service(context)
for key in db_service:
setattr(service, key, db_service[key])
return service
def create_test_service(ctxt, **kw):
def create_test_service(context, **kw):
"""Create and return a test service object.
Create a service in the DB and return a Service object with appropriate
attributes.
"""
service = get_test_service(ctxt, **kw)
service = get_test_service(context, **kw)
service.create()
return service
def get_test_rc(ctxt, **kw):
def get_test_rc(context, **kw):
"""Return a ReplicationController object with appropriate attributes.
NOTE: The object leaves the attributes marked as changed, such
@ -136,24 +136,24 @@ def get_test_rc(ctxt, **kw):
# Let DB generate ID if it isn't specified explicitly
if 'id' not in kw:
del db_rc['id']
rc = objects.ReplicationController(ctxt)
rc = objects.ReplicationController(context)
for key in db_rc:
setattr(rc, key, db_rc[key])
return rc
def create_test_rc(ctxt, **kw):
def create_test_rc(context, **kw):
"""Create and return a test ReplicationController object.
Create a replication controller in the DB and return a
ReplicationController object with appropriate attributes.
"""
rc = get_test_rc(ctxt, **kw)
rc = get_test_rc(context, **kw)
rc.create()
return rc
def get_test_node(ctxt, **kw):
def get_test_node(context, **kw):
"""Return a Node object with appropriate attributes.
NOTE: The object leaves the attributes marked as changed, such
@ -163,18 +163,18 @@ def get_test_node(ctxt, **kw):
# Let DB generate ID if it isn't specified explicitly
if 'id' not in kw:
del db_node['id']
node = objects.Node(ctxt)
node = objects.Node(context)
for key in db_node:
setattr(node, key, db_node[key])
return node
def create_test_node(ctxt, **kw):
def create_test_node(context, **kw):
"""Create and return a test Node object.
Create a node in the DB and return a Node object with appropriate
attributes.
"""
node = get_test_node(ctxt, **kw)
node = get_test_node(context, **kw)
node.create()
return node

View File

@ -18,7 +18,7 @@ import fixtures
from oslo_config import cfg
from oslo_db import options
from magnum.common import context
from magnum.common import context as magnum_context
from magnum.db import api as db_api
from magnum.db.sqlalchemy import api as sql_api
@ -26,7 +26,7 @@ CONF = cfg.CONF
def dummy_context(user='test_username', project_id='test_tenant_id'):
return context.RequestContext(user=user, project_id=project_id)
return magnum_context.RequestContext(user=user, project_id=project_id)
class Database(fixtures.Fixture):