Use get_admin_context() to create the context object
The current code uses RequestContext() call directly to create a context object. Now this is changed to use get_admin_context() to create the object. Closes-bug: #1516812 Co-Authored-By: Vladyslav Drok <vdrok@mirantis.com> Change-Id: I1235fe5feac4a9aa224599ca70def1434a3b9bcb
This commit is contained in:
parent
0607226fc4
commit
2bbc1ce33d
@ -72,7 +72,7 @@ class RPCService(service.Service):
|
||||
|
||||
def start(self):
|
||||
super(RPCService, self).start()
|
||||
admin_context = context.RequestContext('admin', 'admin', is_admin=True)
|
||||
admin_context = context.get_admin_context()
|
||||
|
||||
target = messaging.Target(topic=self.topic, server=self.host)
|
||||
endpoints = [self.manager]
|
||||
|
@ -13,14 +13,48 @@
|
||||
import mock
|
||||
from oslo_concurrency import processutils
|
||||
from oslo_config import cfg
|
||||
import oslo_messaging
|
||||
from oslo_service import service as base_service
|
||||
|
||||
from ironic.common import context
|
||||
from ironic.common import exception
|
||||
from ironic.common import rpc
|
||||
from ironic.common import service
|
||||
from ironic.conductor import manager
|
||||
from ironic.objects import base as objects_base
|
||||
from ironic.tests import base
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
@mock.patch.object(base_service.Service, '__init__', lambda *_, **__: None)
|
||||
class TestRPCService(base.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestRPCService, self).setUp()
|
||||
host = "fake_host"
|
||||
mgr_module = "ironic.conductor.manager"
|
||||
mgr_class = "ConductorManager"
|
||||
self.rpc_svc = service.RPCService(host, mgr_module, mgr_class)
|
||||
|
||||
@mock.patch.object(oslo_messaging, 'Target', autospec=True)
|
||||
@mock.patch.object(objects_base, 'IronicObjectSerializer', autospec=True)
|
||||
@mock.patch.object(rpc, 'get_server', autospec=True)
|
||||
@mock.patch.object(manager.ConductorManager, 'init_host', autospec=True)
|
||||
@mock.patch.object(context, 'get_admin_context', autospec=True)
|
||||
def test_start(self, mock_ctx, mock_init_method,
|
||||
mock_rpc, mock_ios, mock_target):
|
||||
mock_rpc.return_value.start = mock.MagicMock()
|
||||
self.rpc_svc.handle_signal = mock.MagicMock()
|
||||
self.rpc_svc.start()
|
||||
mock_ctx.assert_called_once_with()
|
||||
mock_target.assert_called_once_with(topic=self.rpc_svc.topic,
|
||||
server="fake_host")
|
||||
mock_ios.assert_called_once_with()
|
||||
mock_init_method.assert_called_once_with(self.rpc_svc.manager,
|
||||
mock_ctx.return_value)
|
||||
|
||||
|
||||
class TestWSGIService(base.TestCase):
|
||||
@mock.patch.object(service.wsgi, 'Server')
|
||||
def test_workers_set_default(self, wsgi_server):
|
||||
|
Loading…
Reference in New Issue
Block a user