Re-use rpc engine client
We don't need to create a new rpc client for each implementation. Instead share it when possible. Change-Id: I167828333c7fd2d9371bf564685ca58c5ee0a964
This commit is contained in:
parent
855f0f7acf
commit
e24bc0658f
|
@ -745,7 +745,7 @@ class Controller(object):
|
|||
|
||||
def __init__(self, options):
|
||||
self.options = options
|
||||
self.rpc_client = rpc_client.EngineClient()
|
||||
self.rpc_client = rpc_client.get_engine_client()
|
||||
|
||||
def __getattribute__(self, key):
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ class TrustMiddleware(wsgi.Middleware):
|
|||
:param req: The WSGI request object.
|
||||
:return: ID of the trust or exception of InternalError.
|
||||
"""
|
||||
rpcc = rpc.EngineClient()
|
||||
rpcc = rpc.get_engine_client()
|
||||
|
||||
ctx = req.context
|
||||
params = {'user': ctx.user_id, 'project': ctx.project_id}
|
||||
|
|
|
@ -50,7 +50,7 @@ class WebhookMiddleware(wsgi.Middleware):
|
|||
|
||||
obj = util.parse_request(
|
||||
'ReceiverGetRequest', req, {'identity': receiver_id})
|
||||
rpcc = rpc.EngineClient()
|
||||
rpcc = rpc.get_engine_client()
|
||||
receiver = rpcc.call(ctx, 'receiver_get', obj)
|
||||
|
||||
svc_ctx = context.get_service_credentials()
|
||||
|
|
|
@ -27,7 +27,7 @@ class BuildInfoController(wsgi.Controller):
|
|||
|
||||
def __init__(self, options):
|
||||
self.options = options
|
||||
self.rpc_client = rpc_client.EngineClient()
|
||||
self.rpc_client = rpc_client.get_engine_client()
|
||||
|
||||
@util.policy_enforce
|
||||
def build_info(self, req):
|
||||
|
|
|
@ -292,7 +292,7 @@ class HealthCheck(object):
|
|||
|
||||
def __init__(self, ctx, engine_id, cluster_id, check_type, interval,
|
||||
node_update_timeout, params, enabled):
|
||||
self.rpc_client = rpc_client.EngineClient()
|
||||
self.rpc_client = rpc_client.get_engine_client()
|
||||
self.ctx = ctx
|
||||
self.engine_id = engine_id
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ class HeatNotificationEndpoint(base.Endpoints):
|
|||
publisher_id='^orchestration.*',
|
||||
event_type='^orchestration\.stack\..*',
|
||||
context={'project_id': '^%s$' % project_id})
|
||||
self.rpc = rpc_client.EngineClient()
|
||||
self.rpc = rpc_client.get_engine_client()
|
||||
self.target = messaging.Target(
|
||||
topic=cfg.CONF.health_manager.heat_notification_topic,
|
||||
exchange=cfg.CONF.health_manager.heat_control_exchange,
|
||||
|
|
|
@ -40,7 +40,7 @@ class NovaNotificationEndpoint(base.Endpoints):
|
|||
publisher_id='^compute.*',
|
||||
event_type='^compute\.instance\..*',
|
||||
context={'project_id': '^%s$' % project_id})
|
||||
self.rpc = rpc_client.EngineClient()
|
||||
self.rpc = rpc_client.get_engine_client()
|
||||
self.target = messaging.Target(
|
||||
topic=cfg.CONF.health_manager.nova_notification_topic,
|
||||
exchange=cfg.CONF.health_manager.nova_control_exchange,
|
||||
|
|
|
@ -20,6 +20,15 @@ from senlin.common import consts
|
|||
from senlin.common import messaging
|
||||
from senlin.objects import base as object_base
|
||||
|
||||
_CLIENT = None
|
||||
|
||||
|
||||
def get_engine_client():
|
||||
global _CLIENT
|
||||
if not _CLIENT:
|
||||
_CLIENT = EngineClient()
|
||||
return _CLIENT
|
||||
|
||||
|
||||
class EngineClient(object):
|
||||
"""Client side of the senlin engine rpc API.
|
||||
|
|
|
@ -212,7 +212,7 @@ class ResourceTest(base.SenlinTestCase):
|
|||
|
||||
class ControllerTest(base.SenlinTestCase):
|
||||
|
||||
@mock.patch('senlin.rpc.client.EngineClient')
|
||||
@mock.patch('senlin.rpc.client.get_engine_client')
|
||||
def test_init(self, mock_client):
|
||||
x_client = mock.Mock()
|
||||
mock_client.return_value = x_client
|
||||
|
|
|
@ -30,7 +30,7 @@ class TestTrustMiddleware(base.SenlinTestCase):
|
|||
self.req.context = self.context
|
||||
self.middleware = trust.TrustMiddleware(None)
|
||||
|
||||
@mock.patch("senlin.rpc.client.EngineClient")
|
||||
@mock.patch("senlin.rpc.client.get_engine_client")
|
||||
def test_get_trust_already_exists(self, mock_rpc):
|
||||
x_cred = {'trust': 'FAKE_TRUST_ID'}
|
||||
x_rpc = mock.Mock()
|
||||
|
@ -50,7 +50,7 @@ class TestTrustMiddleware(base.SenlinTestCase):
|
|||
|
||||
@mock.patch.object(context, "get_service_credentials")
|
||||
@mock.patch("senlin.drivers.base.SenlinDriver")
|
||||
@mock.patch("senlin.rpc.client.EngineClient")
|
||||
@mock.patch("senlin.rpc.client.get_engine_client")
|
||||
def test_get_trust_bad(self, mock_rpc, mock_driver, mock_creds):
|
||||
x_cred = {'foo': 'bar'}
|
||||
x_rpc = mock.Mock()
|
||||
|
@ -98,7 +98,7 @@ class TestTrustMiddleware(base.SenlinTestCase):
|
|||
|
||||
@mock.patch.object(context, "get_service_credentials")
|
||||
@mock.patch("senlin.drivers.base.SenlinDriver")
|
||||
@mock.patch("senlin.rpc.client.EngineClient")
|
||||
@mock.patch("senlin.rpc.client.get_engine_client")
|
||||
def test_get_trust_not_found(self, mock_rpc, mock_driver, mock_creds):
|
||||
x_rpc = mock.Mock()
|
||||
x_rpc.call.return_value = None
|
||||
|
@ -136,7 +136,7 @@ class TestTrustMiddleware(base.SenlinTestCase):
|
|||
|
||||
@mock.patch.object(context, "get_service_credentials")
|
||||
@mock.patch("senlin.drivers.base.SenlinDriver")
|
||||
@mock.patch("senlin.rpc.client.EngineClient")
|
||||
@mock.patch("senlin.rpc.client.get_engine_client")
|
||||
def test_get_trust_do_create(self, mock_rpc, mock_driver, mock_creds):
|
||||
x_rpc = mock.Mock()
|
||||
x_rpc.call.return_value = None
|
||||
|
@ -178,7 +178,7 @@ class TestTrustMiddleware(base.SenlinTestCase):
|
|||
|
||||
@mock.patch.object(context, "get_service_credentials")
|
||||
@mock.patch("senlin.drivers.base.SenlinDriver")
|
||||
@mock.patch("senlin.rpc.client.EngineClient")
|
||||
@mock.patch("senlin.rpc.client.get_engine_client")
|
||||
def test_get_trust_fatal(self, mock_rpc, mock_driver, mock_creds):
|
||||
x_rpc = mock.Mock()
|
||||
x_rpc.call.return_value = None
|
||||
|
|
|
@ -142,7 +142,7 @@ class TestWebhookMiddleware(base.SenlinTestCase):
|
|||
|
||||
@mock.patch.object(common_util, 'parse_request')
|
||||
@mock.patch.object(context, 'RequestContext')
|
||||
@mock.patch.object(rpc, 'EngineClient')
|
||||
@mock.patch.object(rpc, 'get_engine_client')
|
||||
def test_process_request(self, mock_client, mock_ctx, mock_parse):
|
||||
cfg.CONF.set_override('auth_url', 'AUTH_URL', group='authentication')
|
||||
cfg.CONF.set_override('service_username', 'USERNAME',
|
||||
|
|
|
@ -20,7 +20,7 @@ from senlin.tests.unit.common import base
|
|||
|
||||
@mock.patch('oslo_messaging.NotificationFilter')
|
||||
class TestHeatNotificationEndpoint(base.SenlinTestCase):
|
||||
@mock.patch('senlin.rpc.client.EngineClient')
|
||||
@mock.patch('senlin.rpc.client.get_engine_client')
|
||||
def test_init(self, mock_rpc, mock_filter):
|
||||
x_filter = mock_filter.return_value
|
||||
event_map = {
|
||||
|
@ -45,7 +45,7 @@ class TestHeatNotificationEndpoint(base.SenlinTestCase):
|
|||
self.assertEqual('CLUSTER_ID', endpoint.cluster_id)
|
||||
|
||||
@mock.patch.object(context.RequestContext, 'from_dict')
|
||||
@mock.patch('senlin.rpc.client.EngineClient')
|
||||
@mock.patch('senlin.rpc.client.get_engine_client')
|
||||
def test_info(self, mock_rpc, mock_context, mock_filter):
|
||||
x_rpc = mock_rpc.return_value
|
||||
recover_action = {'operation': 'REBUILD'}
|
||||
|
@ -85,7 +85,7 @@ class TestHeatNotificationEndpoint(base.SenlinTestCase):
|
|||
}
|
||||
self.assertEqual(expected_params, req.params)
|
||||
|
||||
@mock.patch('senlin.rpc.client.EngineClient')
|
||||
@mock.patch('senlin.rpc.client.get_engine_client')
|
||||
def test_info_event_type_not_interested(self, mock_rpc, mock_filter):
|
||||
x_rpc = mock_rpc.return_value
|
||||
recover_action = {'operation': 'REBUILD'}
|
||||
|
@ -103,7 +103,7 @@ class TestHeatNotificationEndpoint(base.SenlinTestCase):
|
|||
self.assertIsNone(res)
|
||||
self.assertEqual(0, x_rpc.node_recover.call_count)
|
||||
|
||||
@mock.patch('senlin.rpc.client.EngineClient')
|
||||
@mock.patch('senlin.rpc.client.get_engine_client')
|
||||
def test_info_no_tag(self, mock_rpc, mock_filter):
|
||||
x_rpc = mock_rpc.return_value
|
||||
recover_action = {'operation': 'REBUILD'}
|
||||
|
@ -120,7 +120,7 @@ class TestHeatNotificationEndpoint(base.SenlinTestCase):
|
|||
self.assertIsNone(res)
|
||||
self.assertEqual(0, x_rpc.node_recover.call_count)
|
||||
|
||||
@mock.patch('senlin.rpc.client.EngineClient')
|
||||
@mock.patch('senlin.rpc.client.get_engine_client')
|
||||
def test_info_empty_tag(self, mock_rpc, mock_filter):
|
||||
x_rpc = mock_rpc.return_value
|
||||
recover_action = {'operation': 'REBUILD'}
|
||||
|
@ -137,7 +137,7 @@ class TestHeatNotificationEndpoint(base.SenlinTestCase):
|
|||
self.assertIsNone(res)
|
||||
self.assertEqual(0, x_rpc.node_recover.call_count)
|
||||
|
||||
@mock.patch('senlin.rpc.client.EngineClient')
|
||||
@mock.patch('senlin.rpc.client.get_engine_client')
|
||||
def test_info_no_cluster_in_tag(self, mock_rpc, mock_filter):
|
||||
x_rpc = mock_rpc.return_value
|
||||
recover_action = {'operation': 'REBUILD'}
|
||||
|
@ -154,7 +154,7 @@ class TestHeatNotificationEndpoint(base.SenlinTestCase):
|
|||
self.assertIsNone(res)
|
||||
self.assertEqual(0, x_rpc.node_recover.call_count)
|
||||
|
||||
@mock.patch('senlin.rpc.client.EngineClient')
|
||||
@mock.patch('senlin.rpc.client.get_engine_client')
|
||||
def test_info_no_node_in_tag(self, mock_rpc, mock_filter):
|
||||
x_rpc = mock_rpc.return_value
|
||||
recover_action = {'operation': 'REBUILD'}
|
||||
|
@ -171,7 +171,7 @@ class TestHeatNotificationEndpoint(base.SenlinTestCase):
|
|||
self.assertIsNone(res)
|
||||
self.assertEqual(0, x_rpc.node_recover.call_count)
|
||||
|
||||
@mock.patch('senlin.rpc.client.EngineClient')
|
||||
@mock.patch('senlin.rpc.client.get_engine_client')
|
||||
def test_info_cluster_id_not_match(self, mock_rpc, mock_filter):
|
||||
x_rpc = mock_rpc.return_value
|
||||
recover_action = {'operation': 'REBUILD'}
|
||||
|
@ -192,7 +192,7 @@ class TestHeatNotificationEndpoint(base.SenlinTestCase):
|
|||
self.assertEqual(0, x_rpc.node_recover.call_count)
|
||||
|
||||
@mock.patch.object(context.RequestContext, 'from_dict')
|
||||
@mock.patch('senlin.rpc.client.EngineClient')
|
||||
@mock.patch('senlin.rpc.client.get_engine_client')
|
||||
def test_info_default_values(self, mock_rpc, mock_context, mock_filter):
|
||||
x_rpc = mock_rpc.return_value
|
||||
recover_action = {'operation': 'REBUILD'}
|
||||
|
|
|
@ -20,7 +20,7 @@ from senlin.tests.unit.common import base
|
|||
|
||||
@mock.patch('oslo_messaging.NotificationFilter')
|
||||
class TestNovaNotificationEndpoint(base.SenlinTestCase):
|
||||
@mock.patch('senlin.rpc.client.EngineClient')
|
||||
@mock.patch('senlin.rpc.client.get_engine_client')
|
||||
def test_init(self, mock_rpc, mock_filter):
|
||||
x_filter = mock_filter.return_value
|
||||
event_map = {
|
||||
|
@ -49,7 +49,7 @@ class TestNovaNotificationEndpoint(base.SenlinTestCase):
|
|||
self.assertEqual('CLUSTER_ID', endpoint.cluster_id)
|
||||
|
||||
@mock.patch.object(context.RequestContext, 'from_dict')
|
||||
@mock.patch('senlin.rpc.client.EngineClient')
|
||||
@mock.patch('senlin.rpc.client.get_engine_client')
|
||||
def test_info(self, mock_rpc, mock_context, mock_filter):
|
||||
x_rpc = mock_rpc.return_value
|
||||
recover_action = {'operation': 'REBUILD'}
|
||||
|
@ -89,7 +89,7 @@ class TestNovaNotificationEndpoint(base.SenlinTestCase):
|
|||
}
|
||||
self.assertEqual(expected_params, req.params)
|
||||
|
||||
@mock.patch('senlin.rpc.client.EngineClient')
|
||||
@mock.patch('senlin.rpc.client.get_engine_client')
|
||||
def test_info_no_metadata(self, mock_rpc, mock_filter):
|
||||
x_rpc = mock_rpc.return_value
|
||||
recover_action = {'operation': 'REBUILD'}
|
||||
|
@ -106,7 +106,7 @@ class TestNovaNotificationEndpoint(base.SenlinTestCase):
|
|||
self.assertIsNone(res)
|
||||
self.assertEqual(0, x_rpc.node_recover.call_count)
|
||||
|
||||
@mock.patch('senlin.rpc.client.EngineClient')
|
||||
@mock.patch('senlin.rpc.client.get_engine_client')
|
||||
def test_info_no_cluster_in_metadata(self, mock_rpc, mock_filter):
|
||||
x_rpc = mock_rpc.return_value
|
||||
recover_action = {'operation': 'REBUILD'}
|
||||
|
@ -123,7 +123,7 @@ class TestNovaNotificationEndpoint(base.SenlinTestCase):
|
|||
self.assertIsNone(res)
|
||||
self.assertEqual(0, x_rpc.node_recover.call_count)
|
||||
|
||||
@mock.patch('senlin.rpc.client.EngineClient')
|
||||
@mock.patch('senlin.rpc.client.get_engine_client')
|
||||
def test_info_cluster_id_not_match(self, mock_rpc, mock_filter):
|
||||
x_rpc = mock_rpc.return_value
|
||||
recover_action = {'operation': 'REBUILD'}
|
||||
|
@ -140,7 +140,7 @@ class TestNovaNotificationEndpoint(base.SenlinTestCase):
|
|||
self.assertIsNone(res)
|
||||
self.assertEqual(0, x_rpc.node_recover.call_count)
|
||||
|
||||
@mock.patch('senlin.rpc.client.EngineClient')
|
||||
@mock.patch('senlin.rpc.client.get_engine_client')
|
||||
def test_info_event_type_not_interested(self, mock_rpc, mock_filter):
|
||||
x_rpc = mock_rpc.return_value
|
||||
recover_action = {'operation': 'REBUILD'}
|
||||
|
@ -157,7 +157,7 @@ class TestNovaNotificationEndpoint(base.SenlinTestCase):
|
|||
self.assertIsNone(res)
|
||||
self.assertEqual(0, x_rpc.node_recover.call_count)
|
||||
|
||||
@mock.patch('senlin.rpc.client.EngineClient')
|
||||
@mock.patch('senlin.rpc.client.get_engine_client')
|
||||
def test_info_no_node_id(self, mock_rpc, mock_filter):
|
||||
x_rpc = mock_rpc.return_value
|
||||
recover_action = {'operation': 'REBUILD'}
|
||||
|
@ -175,7 +175,7 @@ class TestNovaNotificationEndpoint(base.SenlinTestCase):
|
|||
self.assertEqual(0, x_rpc.node_recover.call_count)
|
||||
|
||||
@mock.patch.object(context.RequestContext, 'from_dict')
|
||||
@mock.patch('senlin.rpc.client.EngineClient')
|
||||
@mock.patch('senlin.rpc.client.get_engine_client')
|
||||
def test_info_default_values(self, mock_rpc, mock_context, mock_filter):
|
||||
x_rpc = mock_rpc.return_value
|
||||
recover_action = {'operation': 'REBUILD'}
|
||||
|
|
|
@ -54,7 +54,7 @@ class TestChaseUp(base.SenlinTestCase):
|
|||
@mock.patch('oslo_messaging.NotificationFilter')
|
||||
class TestNovaNotificationEndpoint(base.SenlinTestCase):
|
||||
|
||||
@mock.patch('senlin.rpc.client.EngineClient')
|
||||
@mock.patch('senlin.rpc.client.get_engine_client')
|
||||
def test_init(self, mock_rpc, mock_filter):
|
||||
x_filter = mock_filter.return_value
|
||||
event_map = {
|
||||
|
@ -83,7 +83,7 @@ class TestNovaNotificationEndpoint(base.SenlinTestCase):
|
|||
self.assertEqual('CLUSTER_ID', endpoint.cluster_id)
|
||||
|
||||
@mock.patch.object(context.RequestContext, 'from_dict')
|
||||
@mock.patch('senlin.rpc.client.EngineClient')
|
||||
@mock.patch('senlin.rpc.client.get_engine_client')
|
||||
def test_info(self, mock_rpc, mock_context, mock_filter):
|
||||
x_rpc = mock_rpc.return_value
|
||||
recover_action = {'operation': 'REBUILD'}
|
||||
|
@ -123,7 +123,7 @@ class TestNovaNotificationEndpoint(base.SenlinTestCase):
|
|||
}
|
||||
self.assertEqual(expected_params, req.params)
|
||||
|
||||
@mock.patch('senlin.rpc.client.EngineClient')
|
||||
@mock.patch('senlin.rpc.client.get_engine_client')
|
||||
def test_info_no_metadata(self, mock_rpc, mock_filter):
|
||||
x_rpc = mock_rpc.return_value
|
||||
recover_action = {'operation': 'REBUILD'}
|
||||
|
@ -140,7 +140,7 @@ class TestNovaNotificationEndpoint(base.SenlinTestCase):
|
|||
self.assertIsNone(res)
|
||||
self.assertEqual(0, x_rpc.node_recover.call_count)
|
||||
|
||||
@mock.patch('senlin.rpc.client.EngineClient')
|
||||
@mock.patch('senlin.rpc.client.get_engine_client')
|
||||
def test_info_no_cluster_in_metadata(self, mock_rpc, mock_filter):
|
||||
x_rpc = mock_rpc.return_value
|
||||
recover_action = {'operation': 'REBUILD'}
|
||||
|
@ -157,7 +157,7 @@ class TestNovaNotificationEndpoint(base.SenlinTestCase):
|
|||
self.assertIsNone(res)
|
||||
self.assertEqual(0, x_rpc.node_recover.call_count)
|
||||
|
||||
@mock.patch('senlin.rpc.client.EngineClient')
|
||||
@mock.patch('senlin.rpc.client.get_engine_client')
|
||||
def test_info_cluster_id_not_match(self, mock_rpc, mock_filter):
|
||||
x_rpc = mock_rpc.return_value
|
||||
recover_action = {'operation': 'REBUILD'}
|
||||
|
@ -174,7 +174,7 @@ class TestNovaNotificationEndpoint(base.SenlinTestCase):
|
|||
self.assertIsNone(res)
|
||||
self.assertEqual(0, x_rpc.node_recover.call_count)
|
||||
|
||||
@mock.patch('senlin.rpc.client.EngineClient')
|
||||
@mock.patch('senlin.rpc.client.get_engine_client')
|
||||
def test_info_event_type_not_interested(self, mock_rpc, mock_filter):
|
||||
x_rpc = mock_rpc.return_value
|
||||
recover_action = {'operation': 'REBUILD'}
|
||||
|
@ -191,7 +191,7 @@ class TestNovaNotificationEndpoint(base.SenlinTestCase):
|
|||
self.assertIsNone(res)
|
||||
self.assertEqual(0, x_rpc.node_recover.call_count)
|
||||
|
||||
@mock.patch('senlin.rpc.client.EngineClient')
|
||||
@mock.patch('senlin.rpc.client.get_engine_client')
|
||||
def test_info_no_node_id(self, mock_rpc, mock_filter):
|
||||
x_rpc = mock_rpc.return_value
|
||||
recover_action = {'operation': 'REBUILD'}
|
||||
|
@ -209,7 +209,7 @@ class TestNovaNotificationEndpoint(base.SenlinTestCase):
|
|||
self.assertEqual(0, x_rpc.node_recover.call_count)
|
||||
|
||||
@mock.patch.object(context.RequestContext, 'from_dict')
|
||||
@mock.patch('senlin.rpc.client.EngineClient')
|
||||
@mock.patch('senlin.rpc.client.get_engine_client')
|
||||
def test_info_default_values(self, mock_rpc, mock_context, mock_filter):
|
||||
x_rpc = mock_rpc.return_value
|
||||
recover_action = {'operation': 'REBUILD'}
|
||||
|
@ -756,7 +756,7 @@ class TestHealthCheck(base.SenlinTestCase):
|
|||
super(TestHealthCheck, self).setUp()
|
||||
ctx = mock.Mock()
|
||||
self.fake_rpc = mock.Mock()
|
||||
with mock.patch.object(rpc_client, 'EngineClient',
|
||||
with mock.patch.object(rpc_client, 'get_engine_client',
|
||||
return_value=self.fake_rpc):
|
||||
self.hc = hm.HealthCheck(
|
||||
ctx=ctx,
|
||||
|
|
|
@ -61,7 +61,7 @@ class TestHealthPolicy(base.SenlinTestCase):
|
|||
fake_cluster = mock.Mock(id='CLUSTER_ID', nodes=[fake_node],
|
||||
rt={'profile': fake_profile})
|
||||
self.cluster = fake_cluster
|
||||
self.patch('senlin.rpc.client.EngineClient')
|
||||
self.patch('senlin.rpc.client.get_engine_client')
|
||||
self.hp = health_policy.HealthPolicy('test-policy', self.spec)
|
||||
|
||||
def test_policy_init(self):
|
||||
|
|
Loading…
Reference in New Issue