From 81f7347b53af8812d404df9f90a76d579cf3f0fb Mon Sep 17 00:00:00 2001 From: Boden R Date: Tue, 10 Apr 2018 13:29:52 -0600 Subject: [PATCH] remove rpc create_connection The neutron.common.rpc.create_connection function is just a reference to the Connection class constructor. This patch removes create_connection and replaces all uses with Connection instead. NeutronLibImpact Change-Id: I2f4b24ba732be47fc9911be1e24406fb1ffe821e --- neutron/agent/l3/extensions/fip_qos.py | 2 +- neutron/agent/resource_cache.py | 2 +- neutron/agent/rpc.py | 2 +- neutron/common/rpc.py | 6 +----- neutron/plugins/ml2/plugin.py | 4 ++-- neutron/services/l3_router/l3_router_plugin.py | 2 +- neutron/services/logapi/rpc/server.py | 2 +- neutron/services/metering/metering_plugin.py | 2 +- neutron/services/trunk/rpc/agent.py | 2 +- neutron/services/trunk/rpc/server.py | 2 +- neutron/tests/unit/agent/l3/extensions/test_fip_qos.py | 2 +- neutron/tests/unit/agent/test_rpc.py | 4 ++-- 12 files changed, 14 insertions(+), 18 deletions(-) diff --git a/neutron/agent/l3/extensions/fip_qos.py b/neutron/agent/l3/extensions/fip_qos.py index e3c7156b053..e690afda958 100644 --- a/neutron/agent/l3/extensions/fip_qos.py +++ b/neutron/agent/l3/extensions/fip_qos.py @@ -172,7 +172,7 @@ class FipQosAgentExtension(l3_extension.L3AgentExtension): def _register_rpc_consumers(self): registry.register(self._handle_notification, resources.QOS_POLICY) - self._connection = n_rpc.create_connection() + self._connection = n_rpc.Connection() endpoints = [resources_rpc.ResourcesPushRpcCallback()] topic = resources_rpc.resource_type_versioned_topic( resources.QOS_POLICY) diff --git a/neutron/agent/resource_cache.py b/neutron/agent/resource_cache.py index 24e2d8a168a..1e90ad14c22 100644 --- a/neutron/agent/resource_cache.py +++ b/neutron/agent/resource_cache.py @@ -238,7 +238,7 @@ class RemoteResourceWatcher(object): def _init_rpc_listeners(self): endpoints = [resources_rpc.ResourcesPushRpcCallback()] - self._connection = n_rpc.create_connection() + self._connection = n_rpc.Connection() for rtype in self.rcache.resource_types: registry_rpc.register(self.resource_change_handler, rtype) topic = resources_rpc.resource_type_versioned_topic(rtype) diff --git a/neutron/agent/rpc.py b/neutron/agent/rpc.py index aab8cab8d44..eb0110e8ab2 100644 --- a/neutron/agent/rpc.py +++ b/neutron/agent/rpc.py @@ -47,7 +47,7 @@ def create_consumers(endpoints, prefix, topic_details, start_listening=True): :returns: A common Connection. """ - connection = n_rpc.create_connection() + connection = n_rpc.Connection() for details in topic_details: topic, operation, node_name = itertools.islice( itertools.chain(details, [None]), 3) diff --git a/neutron/common/rpc.py b/neutron/common/rpc.py index 743fd631bfc..73ed735657c 100644 --- a/neutron/common/rpc.py +++ b/neutron/common/rpc.py @@ -279,7 +279,7 @@ class Service(service.Service): def start(self): super(Service, self).start() - self.conn = create_connection() + self.conn = Connection() LOG.debug("Creating Consumer connection for Service %s", self.topic) @@ -327,7 +327,3 @@ class Connection(object): server.stop() for server in self.servers: server.wait() - - -# TODO(boden): remove create_connection -create_connection = Connection diff --git a/neutron/plugins/ml2/plugin.py b/neutron/plugins/ml2/plugin.py index bd1953f8b19..e89591aee1c 100644 --- a/neutron/plugins/ml2/plugin.py +++ b/neutron/plugins/ml2/plugin.py @@ -279,7 +279,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, """Start the RPC loop to let the plugin communicate with agents.""" self._setup_rpc() self.topic = topics.PLUGIN - self.conn = n_rpc.create_connection() + self.conn = n_rpc.Connection() self.conn.create_consumer(self.topic, self.endpoints, fanout=False) self.conn.create_consumer( topics.SERVER_RESOURCE_VERSIONS, @@ -292,7 +292,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, return self.conn.consume_in_threads() def start_rpc_state_reports_listener(self): - self.conn_reports = n_rpc.create_connection() + self.conn_reports = n_rpc.Connection() self.conn_reports.create_consumer(topics.REPORTS, [agents_db.AgentExtRpcCallback()], fanout=False) diff --git a/neutron/services/l3_router/l3_router_plugin.py b/neutron/services/l3_router/l3_router_plugin.py index 524bb566fd8..fca0e1fd0cd 100644 --- a/neutron/services/l3_router/l3_router_plugin.py +++ b/neutron/services/l3_router/l3_router_plugin.py @@ -118,7 +118,7 @@ class L3RouterPlugin(service_base.ServicePluginBase, def start_rpc_listeners(self): # RPC support self.topic = topics.L3PLUGIN - self.conn = n_rpc.create_connection() + self.conn = n_rpc.Connection() self.endpoints = [l3_rpc.L3RpcCallback()] self.conn.create_consumer(self.topic, self.endpoints, fanout=False) diff --git a/neutron/services/logapi/rpc/server.py b/neutron/services/logapi/rpc/server.py index 3de4b07a062..c0805ab7e47 100644 --- a/neutron/services/logapi/rpc/server.py +++ b/neutron/services/logapi/rpc/server.py @@ -33,7 +33,7 @@ class LoggingApiSkeleton(object): version='1.0', namespace=log_const.RPC_NAMESPACE_LOGGING) def __init__(self): - self.conn = n_rpc.create_connection() + self.conn = n_rpc.Connection() self.conn.create_consumer(log_const.LOGGING_PLUGIN, [self], fanout=False) diff --git a/neutron/services/metering/metering_plugin.py b/neutron/services/metering/metering_plugin.py index 2d51ca526e2..76b9f1754c2 100644 --- a/neutron/services/metering/metering_plugin.py +++ b/neutron/services/metering/metering_plugin.py @@ -37,7 +37,7 @@ class MeteringPlugin(metering_db.MeteringDbMixin): def start_rpc_listeners(self): self.endpoints = [metering_rpc.MeteringRpcCallbacks(self)] - self.conn = n_rpc.create_connection() + self.conn = n_rpc.Connection() self.conn.create_consumer( topics.METERING_PLUGIN, self.endpoints, fanout=False) return self.conn.consume_in_threads() diff --git a/neutron/services/trunk/rpc/agent.py b/neutron/services/trunk/rpc/agent.py index 40cd52d68c9..950150716e5 100644 --- a/neutron/services/trunk/rpc/agent.py +++ b/neutron/services/trunk/rpc/agent.py @@ -45,7 +45,7 @@ class TrunkSkeleton(object): registry.register(self.handle_trunks, resources.TRUNK) registry.register(self.handle_subports, resources.SUBPORT) - self._connection = n_rpc.create_connection() + self._connection = n_rpc.Connection() endpoints = [resources_rpc.ResourcesPushRpcCallback()] topic = resources_rpc.resource_type_versioned_topic(resources.SUBPORT) self._connection.create_consumer(topic, endpoints, fanout=True) diff --git a/neutron/services/trunk/rpc/server.py b/neutron/services/trunk/rpc/server.py index 1da96befff5..7004632257e 100644 --- a/neutron/services/trunk/rpc/server.py +++ b/neutron/services/trunk/rpc/server.py @@ -67,7 +67,7 @@ class TrunkSkeleton(object): def __init__(self): # Used to provide trunk lookups for the agent. registry.provide(trunk_by_port_provider, resources.TRUNK) - self._connection = n_rpc.create_connection() + self._connection = n_rpc.Connection() self._connection.create_consumer( constants.TRUNK_BASE_TOPIC, [self], fanout=False) self._connection.consume_in_threads() diff --git a/neutron/tests/unit/agent/l3/extensions/test_fip_qos.py b/neutron/tests/unit/agent/l3/extensions/test_fip_qos.py index 346e4539638..1a93c607fc3 100644 --- a/neutron/tests/unit/agent/l3/extensions/test_fip_qos.py +++ b/neutron/tests/unit/agent/l3/extensions/test_fip_qos.py @@ -141,7 +141,7 @@ class FipQosExtensionInitializeTestCase(QosExtensionBaseTestCase): @mock.patch.object(registry, 'register') @mock.patch.object(resources_rpc, 'ResourcesPushRpcCallback') def test_initialize_subscribed_to_rpc(self, rpc_mock, subscribe_mock): - call_to_patch = 'neutron.common.rpc.create_connection' + call_to_patch = 'neutron.common.rpc.Connection' with mock.patch(call_to_patch, return_value=self.connection) as create_connection: self.fip_qos_ext.initialize( diff --git a/neutron/tests/unit/agent/test_rpc.py b/neutron/tests/unit/agent/test_rpc.py index 8270b685606..cfbb56e3b04 100644 --- a/neutron/tests/unit/agent/test_rpc.py +++ b/neutron/tests/unit/agent/test_rpc.py @@ -116,7 +116,7 @@ class AgentRPCMethods(base.BaseTestCase): def _test_create_consumers( self, endpoints, method, expected, topics, listen): - call_to_patch = 'neutron.common.rpc.create_connection' + call_to_patch = 'neutron.common.rpc.Connection' with mock.patch(call_to_patch) as create_connection: rpc.create_consumers( endpoints, method, topics, start_listening=listen) @@ -158,7 +158,7 @@ class AgentRPCMethods(base.BaseTestCase): mock.call().consume_in_threads() ] - call_to_patch = 'neutron.common.rpc.create_connection' + call_to_patch = 'neutron.common.rpc.Connection' with mock.patch(call_to_patch) as create_connection: rpc.create_consumers(endpoints, 'foo', [('topic', 'op', 'node1')]) create_connection.assert_has_calls(expected)