]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix update_device_up method of linuxbridge plugin
authorEugene Nikanorov <enikanorov@mirantis.com>
Sat, 19 Oct 2013 12:06:03 +0000 (16:06 +0400)
committerEugene Nikanorov <enikanorov@mirantis.com>
Fri, 25 Oct 2013 14:40:17 +0000 (18:40 +0400)
Also add unit tests covering update_device_up and update_device_down
methods

Change-Id: I97f2f9249b684aa5350b3f0621754543e80bec70
Closes-Bug: #1241602

neutron/plugins/linuxbridge/lb_neutron_plugin.py
neutron/tests/unit/linuxbridge/test_linuxbridge_plugin.py

index 1920d0e8d96243fa77a9e6ecd12d27735a346794..68bfd4113eb7012dd0011cc9960852cc3b989534 100644 (file)
@@ -144,7 +144,7 @@ class LinuxBridgeRpcCallbacks(dhcp_rpc_base.DhcpRpcCallbackMixin,
         agent_id = kwargs.get('agent_id')
         device = kwargs.get('device')
         host = kwargs.get('host')
-        port = self.get_port_from_device.get_port(device)
+        port = self.get_port_from_device(device)
         LOG.debug(_("Device %(device)s up on %(agent_id)s"),
                   {'device': device, 'agent_id': agent_id})
         plugin = manager.NeutronManager.get_plugin()
index 078971ba631cc961039f9685868c04c182e15acf..5ef072b1a557bcd591dee0fb95b38e89a5e7a502 100644 (file)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import contextlib
+
+import mock
+
+from neutron.common import constants as q_const
 from neutron.extensions import portbindings
+from neutron import manager
+from neutron.plugins.linuxbridge import lb_neutron_plugin
 from neutron.tests.unit import _test_extension_portbindings as test_bindings
 from neutron.tests.unit import test_db_plugin as test_plugin
 from neutron.tests.unit import test_security_groups_rpc as test_sg_rpc
 
-
 PLUGIN_NAME = ('neutron.plugins.linuxbridge.'
                'lb_neutron_plugin.LinuxBridgePluginV2')
 
@@ -75,3 +81,46 @@ class TestLinuxBridgePortBindingHost(
     LinuxBridgePluginV2TestCase,
     test_bindings.PortBindingsHostTestCaseMixin):
     pass
+
+
+class TestLinuxBridgePluginRpcCallbacks(test_plugin.NeutronDbPluginV2TestCase):
+    def setUp(self):
+        super(TestLinuxBridgePluginRpcCallbacks, self).setUp(PLUGIN_NAME)
+        self.callbacks = lb_neutron_plugin.LinuxBridgeRpcCallbacks()
+
+    def test_update_device_down(self):
+        with contextlib.nested(
+            mock.patch.object(self.callbacks, "get_port_from_device",
+                              return_value=None),
+            mock.patch.object(manager.NeutronManager, "get_plugin")
+        ) as (gpfd, gp):
+            self.assertEqual(
+                self.callbacks.update_device_down("fake_context",
+                                                  agent_id="123",
+                                                  device="device",
+                                                  host="host"),
+                {'device': 'device', 'exists': False}
+            )
+            gpfd.return_value = {'id': 'fakeid',
+                                 'status': q_const.PORT_STATUS_ACTIVE}
+            self.assertEqual(
+                self.callbacks.update_device_down("fake_context",
+                                                  agent_id="123",
+                                                  device="device",
+                                                  host="host"),
+                {'device': 'device', 'exists': True}
+            )
+
+    def test_update_device_up(self):
+        with contextlib.nested(
+            mock.patch.object(self.callbacks, "get_port_from_device",
+                              return_value=None),
+            mock.patch.object(manager.NeutronManager, "get_plugin")
+        ) as (gpfd, gp):
+            gpfd.return_value = {'id': 'fakeid',
+                                 'status': q_const.PORT_STATUS_ACTIVE}
+            self.callbacks.update_device_up("fake_context",
+                                            agent_id="123",
+                                            device="device",
+                                            host="host")
+            gpfd.assert_called_once_with('device')