]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Drop RpcProxy usage from l2population code
authorRussell Bryant <rbryant@redhat.com>
Mon, 24 Nov 2014 20:50:03 +0000 (20:50 +0000)
committerRussell Bryant <rbryant@redhat.com>
Wed, 26 Nov 2014 15:55:42 +0000 (15:55 +0000)
This patch removes usage of the RpcProxy compatibility class from the
l2population code.  The equivalent oslo.messaging APIs are now used
instead.

Part of blueprint drop-rpc-compat.

Change-Id: Ie6d45f1871c2dba603bc17851b753bb960a9ca2b

neutron/plugins/ml2/drivers/l2pop/rpc.py
neutron/tests/unit/ml2/drivers/test_l2population.py

index 71e34af2f48c3d14d9ec3f18a80a3117d03cca43..f56abd5ce7ae14d1a31607dbbbb5f04f73634203 100644 (file)
@@ -16,6 +16,8 @@
 import collections
 import copy
 
+from oslo import messaging
+
 from neutron.common import rpc as n_rpc
 from neutron.common import topics
 from neutron.openstack.common import log as logging
@@ -27,16 +29,15 @@ LOG = logging.getLogger(__name__)
 PortInfo = collections.namedtuple("PortInfo", "mac_address ip_address")
 
 
-class L2populationAgentNotifyAPI(n_rpc.RpcProxy):
-    BASE_RPC_API_VERSION = '1.0'
+class L2populationAgentNotifyAPI(object):
 
     def __init__(self, topic=topics.AGENT):
-        super(L2populationAgentNotifyAPI, self).__init__(
-            topic=topic, default_version=self.BASE_RPC_API_VERSION)
-
+        self.topic = topic
         self.topic_l2pop_update = topics.get_topic_name(topic,
                                                         topics.L2POPULATION,
                                                         topics.UPDATE)
+        target = messaging.Target(topic=topic, version='1.0')
+        self.client = n_rpc.get_client(target)
 
     def _notification_fanout(self, context, method, fdb_entries):
         LOG.debug('Fanout notify l2population agents at %(topic)s '
@@ -46,10 +47,8 @@ class L2populationAgentNotifyAPI(n_rpc.RpcProxy):
                    'fdb_entries': fdb_entries})
 
         marshalled_fdb_entries = self._marshall_fdb_entries(fdb_entries)
-        self.fanout_cast(context,
-                         self.make_msg(method,
-                                       fdb_entries=marshalled_fdb_entries),
-                         topic=self.topic_l2pop_update)
+        cctxt = self.client.prepare(topic=self.topic_l2pop_update, fanout=True)
+        cctxt.cast(context, method, fdb_entries=marshalled_fdb_entries)
 
     def _notification_host(self, context, method, fdb_entries, host):
         LOG.debug('Notify l2population agent %(host)s at %(topic)s the '
@@ -58,11 +57,10 @@ class L2populationAgentNotifyAPI(n_rpc.RpcProxy):
                    'topic': self.topic,
                    'method': method,
                    'fdb_entries': fdb_entries})
+
         marshalled_fdb_entries = self._marshall_fdb_entries(fdb_entries)
-        self.cast(context,
-                  self.make_msg(method,
-                                fdb_entries=marshalled_fdb_entries),
-                  topic='%s.%s' % (self.topic_l2pop_update, host))
+        cctxt = self.client.prepare(topic=self.topic_l2pop_update, server=host)
+        cctxt.cast(context, method, fdb_entries=marshalled_fdb_entries)
 
     def add_fdb_entries(self, context, fdb_entries, host=None):
         if fdb_entries:
index 92f133e6a52335e7e3925a99762f6727dab70284..90a6c0a91c5c3fea29cee84d3db1d81fdc6a0035 100644 (file)
@@ -93,8 +93,6 @@ L2_AGENT_5 = {
 NOTIFIER = 'neutron.plugins.ml2.rpc.AgentNotifierApi'
 DEVICE_OWNER_COMPUTE = 'compute:None'
 
-FLOODING_ENTRY_AS_LIST = list(constants.FLOODING_ENTRY)
-
 
 class TestL2PopulationRpcTestCase(test_plugin.Ml2PluginV2TestCase):
     _mechanism_drivers = ['openvswitch', 'linuxbridge',
@@ -131,11 +129,13 @@ class TestL2PopulationRpcTestCase(test_plugin.Ml2PluginV2TestCase):
         self.fanout_topic = topics.get_topic_name(topics.AGENT,
                                                   topics.L2POPULATION,
                                                   topics.UPDATE)
-        fanout = ('neutron.common.rpc.RpcProxy.fanout_cast')
+        fanout = ('neutron.plugins.ml2.drivers.l2pop.rpc.'
+                  'L2populationAgentNotifyAPI._notification_fanout')
         fanout_patch = mock.patch(fanout)
         self.mock_fanout = fanout_patch.start()
 
-        cast = ('neutron.common.rpc.RpcProxy.cast')
+        cast = ('neutron.plugins.ml2.drivers.l2pop.rpc.'
+                'L2populationAgentNotifyAPI._notification_host')
         cast_patch = mock.patch(cast)
         self.mock_cast = cast_patch.start()
 
@@ -226,20 +226,17 @@ class TestL2PopulationRpcTestCase(test_plugin.Ml2PluginV2TestCase):
                                                     device=device)
 
                     p1_ips = [p['ip_address'] for p in p1['fixed_ips']]
-                    expected = {'args':
-                                {'fdb_entries':
-                                 {p1['network_id']:
-                                  {'ports':
-                                   {'20.0.0.1': [FLOODING_ENTRY_AS_LIST,
-                                                 [p1['mac_address'],
-                                                  p1_ips[0]]]},
-                                   'network_type': 'vxlan',
-                                   'segment_id': 1}}},
-                                'namespace': None,
-                                'method': 'add_fdb_entries'}
+                    expected = {p1['network_id']:
+                                {'ports':
+                                 {'20.0.0.1': [constants.FLOODING_ENTRY,
+                                               l2pop_rpc.PortInfo(
+                                                   p1['mac_address'],
+                                                   p1_ips[0])]},
+                                 'network_type': 'vxlan',
+                                 'segment_id': 1}}
 
                     self.mock_fanout.assert_called_with(
-                        mock.ANY, expected, topic=self.fanout_topic)
+                        mock.ANY, 'add_fdb_entries', expected)
 
     def test_fdb_add_not_called_type_local(self):
         self._register_ml2_agents()
@@ -286,20 +283,17 @@ class TestL2PopulationRpcTestCase(test_plugin.Ml2PluginV2TestCase):
                                                     device=device)
 
                     p1_ips = [p['ip_address'] for p in p1['fixed_ips']]
-                    expected = {'args':
-                                {'fdb_entries':
-                                 {p1['network_id']:
-                                  {'ports':
-                                   {'20.0.0.5': [FLOODING_ENTRY_AS_LIST,
-                                                 [p1['mac_address'],
-                                                  p1_ips[0]]]},
-                                   'network_type': 'vlan',
-                                   'segment_id': 2}}},
-                                'namespace': None,
-                                'method': 'add_fdb_entries'}
+                    expected = {p1['network_id']:
+                                {'ports':
+                                 {'20.0.0.5': [constants.FLOODING_ENTRY,
+                                               l2pop_rpc.PortInfo(
+                                                   p1['mac_address'],
+                                                   p1_ips[0])]},
+                                 'network_type': 'vlan',
+                                 'segment_id': 2}}
 
                     self.mock_fanout.assert_called_with(
-                        mock.ANY, expected, topic=self.fanout_topic)
+                        mock.ANY, 'add_fdb_entries', expected)
 
     def test_fdb_add_two_agents(self):
         self._register_ml2_agents()
@@ -332,41 +326,30 @@ class TestL2PopulationRpcTestCase(test_plugin.Ml2PluginV2TestCase):
                     p1_ips = [p['ip_address'] for p in p1['fixed_ips']]
                     p2_ips = [p['ip_address'] for p in p2['fixed_ips']]
 
-                    expected1 = {'args':
-                                 {'fdb_entries':
-                                  {p1['network_id']:
-                                   {'ports':
-                                    {'20.0.0.2': [FLOODING_ENTRY_AS_LIST,
-                                                  [p2['mac_address'],
-                                                   p2_ips[0]]]},
-                                    'network_type': 'vxlan',
-                                    'segment_id': 1}}},
-                                 'namespace': None,
-                                 'method': 'add_fdb_entries'}
-
-                    topic = topics.get_topic_name(topics.AGENT,
-                                                  topics.L2POPULATION,
-                                                  topics.UPDATE,
-                                                  HOST)
+                    expected1 = {p1['network_id']:
+                                 {'ports':
+                                  {'20.0.0.2': [constants.FLOODING_ENTRY,
+                                                l2pop_rpc.PortInfo(
+                                                    p2['mac_address'],
+                                                    p2_ips[0])]},
+                                  'network_type': 'vxlan',
+                                  'segment_id': 1}}
 
                     self.mock_cast.assert_called_with(mock.ANY,
-                                                      expected1,
-                                                      topic=topic)
-
-                    expected2 = {'args':
-                                 {'fdb_entries':
-                                  {p1['network_id']:
-                                   {'ports':
-                                    {'20.0.0.1': [FLOODING_ENTRY_AS_LIST,
-                                                  [p1['mac_address'],
-                                                   p1_ips[0]]]},
-                                    'network_type': 'vxlan',
-                                    'segment_id': 1}}},
-                                 'namespace': None,
-                                 'method': 'add_fdb_entries'}
+                                                      'add_fdb_entries',
+                                                      expected1, HOST)
+
+                    expected2 = {p1['network_id']:
+                                 {'ports':
+                                  {'20.0.0.1': [constants.FLOODING_ENTRY,
+                                                l2pop_rpc.PortInfo(
+                                                    p1['mac_address'],
+                                                    p1_ips[0])]},
+                                  'network_type': 'vxlan',
+                                  'segment_id': 1}}
 
                     self.mock_fanout.assert_called_with(
-                        mock.ANY, expected2, topic=self.fanout_topic)
+                        mock.ANY, 'add_fdb_entries', expected2)
 
     def test_fdb_add_called_two_networks(self):
         self._register_ml2_agents()
@@ -400,46 +383,34 @@ class TestL2PopulationRpcTestCase(test_plugin.Ml2PluginV2TestCase):
 
                             p1_ips = [p['ip_address']
                                       for p in p1['fixed_ips']]
-                            expected1 = {'args':
-                                         {'fdb_entries':
-                                          {p1['network_id']:
-                                           {'ports':
-                                            {'20.0.0.2':
-                                             [FLOODING_ENTRY_AS_LIST,
-                                              [p1['mac_address'],
-                                               p1_ips[0]]]},
-                                            'network_type': 'vxlan',
-                                            'segment_id': 1}}},
-                                         'namespace': None,
-                                         'method': 'add_fdb_entries'}
-
-                            topic = topics.get_topic_name(topics.AGENT,
-                                                          topics.L2POPULATION,
-                                                          topics.UPDATE,
-                                                          HOST)
-
-                            self.mock_cast.assert_called_with(mock.ANY,
-                                                              expected1,
-                                                              topic=topic)
+                            expected1 = {p1['network_id']:
+                                         {'ports':
+                                          {'20.0.0.2':
+                                           [constants.FLOODING_ENTRY,
+                                            l2pop_rpc.PortInfo(
+                                                p1['mac_address'],
+                                                p1_ips[0])]},
+                                         'network_type': 'vxlan',
+                                         'segment_id': 1}}
+
+                            self.mock_cast.assert_called_with(
+                                    mock.ANY, 'add_fdb_entries', expected1,
+                                    HOST)
 
                             p3_ips = [p['ip_address']
                                       for p in p3['fixed_ips']]
-                            expected2 = {'args':
-                                         {'fdb_entries':
-                                          {p1['network_id']:
-                                           {'ports':
-                                            {'20.0.0.1':
-                                             [FLOODING_ENTRY_AS_LIST,
-                                              [p3['mac_address'],
-                                               p3_ips[0]]]},
-                                            'network_type': 'vxlan',
-                                            'segment_id': 1}}},
-                                         'namespace': None,
-                                         'method': 'add_fdb_entries'}
+                            expected2 = {p1['network_id']:
+                                         {'ports':
+                                          {'20.0.0.1':
+                                           [constants.FLOODING_ENTRY,
+                                            l2pop_rpc.PortInfo(
+                                                p3['mac_address'],
+                                                p3_ips[0])]},
+                                         'network_type': 'vxlan',
+                                         'segment_id': 1}}
 
                             self.mock_fanout.assert_called_with(
-                                mock.ANY, expected2,
-                                topic=self.fanout_topic)
+                                mock.ANY, 'add_fdb_entries', expected2)
 
     def test_update_port_down(self):
         self._register_ml2_agents()
@@ -474,19 +445,16 @@ class TestL2PopulationRpcTestCase(test_plugin.Ml2PluginV2TestCase):
                                                       device=device2)
 
                     p2_ips = [p['ip_address'] for p in p2['fixed_ips']]
-                    expected = {'args':
-                                {'fdb_entries':
-                                 {p2['network_id']:
-                                  {'ports':
-                                   {'20.0.0.1': [[p2['mac_address'],
-                                                  p2_ips[0]]]},
-                                   'network_type': 'vxlan',
-                                   'segment_id': 1}}},
-                                'namespace': None,
-                                'method': 'remove_fdb_entries'}
+                    expected = {p2['network_id']:
+                                {'ports':
+                                 {'20.0.0.1': [l2pop_rpc.PortInfo(
+                                               p2['mac_address'],
+                                               p2_ips[0])]},
+                                 'network_type': 'vxlan',
+                                 'segment_id': 1}}
 
                     self.mock_fanout.assert_called_with(
-                        mock.ANY, expected, topic=self.fanout_topic)
+                        mock.ANY, 'remove_fdb_entries', expected)
 
     def test_update_port_down_last_port_up(self):
         self._register_ml2_agents()
@@ -514,20 +482,17 @@ class TestL2PopulationRpcTestCase(test_plugin.Ml2PluginV2TestCase):
                                                       device=device2)
 
                     p2_ips = [p['ip_address'] for p in p2['fixed_ips']]
-                    expected = {'args':
-                                {'fdb_entries':
-                                 {p2['network_id']:
-                                  {'ports':
-                                   {'20.0.0.1': [FLOODING_ENTRY_AS_LIST,
-                                                 [p2['mac_address'],
-                                                  p2_ips[0]]]},
-                                   'network_type': 'vxlan',
-                                   'segment_id': 1}}},
-                                'namespace': None,
-                                'method': 'remove_fdb_entries'}
+                    expected = {p2['network_id']:
+                                {'ports':
+                                 {'20.0.0.1': [constants.FLOODING_ENTRY,
+                                               l2pop_rpc.PortInfo(
+                                                    p2['mac_address'],
+                                                    p2_ips[0])]},
+                                 'network_type': 'vxlan',
+                                 'segment_id': 1}}
 
                     self.mock_fanout.assert_called_with(
-                        mock.ANY, expected, topic=self.fanout_topic)
+                        mock.ANY, 'remove_fdb_entries', expected)
 
     def test_delete_port(self):
         self._register_ml2_agents()
@@ -559,19 +524,16 @@ class TestL2PopulationRpcTestCase(test_plugin.Ml2PluginV2TestCase):
                                                     device=device1)
                 self._delete('ports', port2['port']['id'])
                 p2_ips = [p['ip_address'] for p in p2['fixed_ips']]
-                expected = {'args':
-                            {'fdb_entries':
-                             {p2['network_id']:
-                              {'ports':
-                               {'20.0.0.1': [[p2['mac_address'],
-                                              p2_ips[0]]]},
-                               'network_type': 'vxlan',
-                               'segment_id': 1}}},
-                            'namespace': None,
-                            'method': 'remove_fdb_entries'}
+                expected = {p2['network_id']:
+                            {'ports':
+                             {'20.0.0.1': [l2pop_rpc.PortInfo(
+                                           p2['mac_address'],
+                                           p2_ips[0])]},
+                             'network_type': 'vxlan',
+                             'segment_id': 1}}
 
                 self.mock_fanout.assert_any_call(
-                    mock.ANY, expected, topic=self.fanout_topic)
+                    mock.ANY, 'remove_fdb_entries', expected)
 
     def test_delete_port_last_port_up(self):
         self._register_ml2_agents()
@@ -595,20 +557,17 @@ class TestL2PopulationRpcTestCase(test_plugin.Ml2PluginV2TestCase):
                                                     device=device)
                 self._delete('ports', port['port']['id'])
                 p1_ips = [p['ip_address'] for p in p1['fixed_ips']]
-                expected = {'args':
-                            {'fdb_entries':
-                             {p1['network_id']:
-                              {'ports':
-                               {'20.0.0.1': [FLOODING_ENTRY_AS_LIST,
-                                             [p1['mac_address'],
-                                              p1_ips[0]]]},
-                               'network_type': 'vxlan',
-                               'segment_id': 1}}},
-                            'namespace': None,
-                            'method': 'remove_fdb_entries'}
+                expected = {p1['network_id']:
+                            {'ports':
+                             {'20.0.0.1': [constants.FLOODING_ENTRY,
+                                           l2pop_rpc.PortInfo(
+                                               p1['mac_address'],
+                                               p1_ips[0])]},
+                             'network_type': 'vxlan',
+                             'segment_id': 1}}
 
                 self.mock_fanout.assert_any_call(
-                    mock.ANY, expected, topic=self.fanout_topic)
+                    mock.ANY, 'remove_fdb_entries', expected)
 
     def test_fixed_ips_changed(self):
         self._register_ml2_agents()
@@ -636,18 +595,14 @@ class TestL2PopulationRpcTestCase(test_plugin.Ml2PluginV2TestCase):
                 ips = res['port']['fixed_ips']
                 self.assertEqual(len(ips), 2)
 
-                add_expected = {'args':
-                                {'fdb_entries':
-                                 {'chg_ip':
-                                  {p1['network_id']:
-                                   {'20.0.0.1':
-                                    {'after': [(p1['mac_address'],
-                                                '10.0.0.10')]}}}}},
-                                'namespace': None,
-                                'method': 'update_fdb_entries'}
+                add_expected = {'chg_ip':
+                                {p1['network_id']:
+                                 {'20.0.0.1':
+                                  {'after': [(p1['mac_address'],
+                                              '10.0.0.10')]}}}}
 
                 self.mock_fanout.assert_any_call(
-                    mock.ANY, add_expected, topic=self.fanout_topic)
+                    mock.ANY, 'update_fdb_entries', add_expected)
 
                 self.mock_fanout.reset_mock()
 
@@ -658,20 +613,16 @@ class TestL2PopulationRpcTestCase(test_plugin.Ml2PluginV2TestCase):
                 ips = res['port']['fixed_ips']
                 self.assertEqual(len(ips), 2)
 
-                upd_expected = {'args':
-                                {'fdb_entries':
-                                 {'chg_ip':
-                                  {p1['network_id']:
-                                   {'20.0.0.1':
-                                    {'before': [(p1['mac_address'],
-                                                 '10.0.0.10')],
-                                     'after': [(p1['mac_address'],
-                                                '10.0.0.16')]}}}}},
-                                'namespace': None,
-                                'method': 'update_fdb_entries'}
+                upd_expected = {'chg_ip':
+                                {p1['network_id']:
+                                 {'20.0.0.1':
+                                  {'before': [(p1['mac_address'],
+                                               '10.0.0.10')],
+                                   'after': [(p1['mac_address'],
+                                              '10.0.0.16')]}}}}
 
                 self.mock_fanout.assert_any_call(
-                    mock.ANY, upd_expected, topic=self.fanout_topic)
+                    mock.ANY, 'update_fdb_entries', upd_expected)
 
                 self.mock_fanout.reset_mock()
 
@@ -681,18 +632,14 @@ class TestL2PopulationRpcTestCase(test_plugin.Ml2PluginV2TestCase):
                 ips = res['port']['fixed_ips']
                 self.assertEqual(len(ips), 1)
 
-                del_expected = {'args':
-                                {'fdb_entries':
-                                 {'chg_ip':
-                                  {p1['network_id']:
-                                   {'20.0.0.1':
-                                    {'before': [(p1['mac_address'],
-                                                 '10.0.0.2')]}}}}},
-                                'namespace': None,
-                                'method': 'update_fdb_entries'}
+                del_expected = {'chg_ip':
+                                {p1['network_id']:
+                                 {'20.0.0.1':
+                                  {'before': [(p1['mac_address'],
+                                               '10.0.0.2')]}}}}
 
                 self.mock_fanout.assert_any_call(
-                    mock.ANY, del_expected, topic=self.fanout_topic)
+                    mock.ANY, 'update_fdb_entries', del_expected)
 
     def test_no_fdb_updates_without_port_updates(self):
         self._register_ml2_agents()
@@ -761,20 +708,17 @@ class TestL2PopulationRpcTestCase(test_plugin.Ml2PluginV2TestCase):
                         device=device1,
                         agent_id=L2_AGENT_2['host'])
                     p1_ips = [p['ip_address'] for p in p1['fixed_ips']]
-                    expected = {'args':
-                                {'fdb_entries':
-                                 {p1['network_id']:
-                                  {'ports':
-                                   {'20.0.0.1': [FLOODING_ENTRY_AS_LIST,
-                                                 [p1['mac_address'],
-                                                  p1_ips[0]]]},
-                                   'network_type': 'vxlan',
-                                   'segment_id': 1}}},
-                                'namespace': None,
-                                'method': 'remove_fdb_entries'}
+                    expected = {p1['network_id']:
+                                {'ports':
+                                 {'20.0.0.1': [constants.FLOODING_ENTRY,
+                                               l2pop_rpc.PortInfo(
+                                                   p1['mac_address'],
+                                                   p1_ips[0])]},
+                                 'network_type': 'vxlan',
+                                 'segment_id': 1}}
 
                     self.mock_fanout.assert_called_with(
-                        mock.ANY, expected, topic=self.fanout_topic)
+                        mock.ANY, 'remove_fdb_entries', expected)
 
     def test_host_changed_twice(self):
         self._register_ml2_agents()
@@ -819,20 +763,17 @@ class TestL2PopulationRpcTestCase(test_plugin.Ml2PluginV2TestCase):
                         device=device1,
                         agent_id=L2_AGENT_4['host'])
                     p1_ips = [p['ip_address'] for p in p1['fixed_ips']]
-                    expected = {'args':
-                                {'fdb_entries':
-                                 {p1['network_id']:
-                                  {'ports':
-                                   {'20.0.0.1': [FLOODING_ENTRY_AS_LIST,
-                                                 [p1['mac_address'],
-                                                  p1_ips[0]]]},
-                                   'network_type': 'vxlan',
-                                   'segment_id': 1}}},
-                                'namespace': None,
-                                'method': 'remove_fdb_entries'}
+                    expected = {p1['network_id']:
+                                {'ports':
+                                 {'20.0.0.1': [constants.FLOODING_ENTRY,
+                                               l2pop_rpc.PortInfo(
+                                                   p1['mac_address'],
+                                                   p1_ips[0])]},
+                                 'network_type': 'vxlan',
+                                 'segment_id': 1}}
 
                     self.mock_fanout.assert_called_with(
-                        mock.ANY, expected, topic=self.fanout_topic)
+                        mock.ANY, 'remove_fdb_entries', expected)
 
     def test_delete_port_invokes_update_device_down(self):
         l2pop_mech = l2pop_mech_driver.L2populationMechanismDriver()