Skip to content

Commit

Permalink
Fix update_device_up method of linuxbridge plugin
Browse files Browse the repository at this point in the history
Also add unit tests covering update_device_up and update_device_down
methods

Change-Id: I97f2f9249b684aa5350b3f0621754543e80bec70
Closes-Bug: #1241602
  • Loading branch information
eugene64 committed Oct 25, 2013
1 parent 84a8474 commit 01e4559
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
2 changes: 1 addition & 1 deletion neutron/plugins/linuxbridge/lb_neutron_plugin.py
Expand Up @@ -144,7 +144,7 @@ def update_device_up(self, rpc_context, **kwargs):
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()
Expand Down
51 changes: 50 additions & 1 deletion neutron/tests/unit/linuxbridge/test_linuxbridge_plugin.py
Expand Up @@ -13,12 +13,18 @@
# 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')

Expand Down Expand Up @@ -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')

0 comments on commit 01e4559

Please sign in to comment.