self._update_port_dict_binding(port, binding)
binding.host = attrs and attrs.get(portbindings.HOST_ID)
+ binding.router_id = attrs and attrs.get('device_id')
def update_dvr_port_binding(self, context, id, port):
attrs = port['port']
session = context.session
binding = db.get_dvr_port_binding_by_host(session, id, host)
- if (not binding or
- binding.vif_type == portbindings.VIF_TYPE_BINDING_FAILED):
+ device_id = attrs and attrs.get('device_id')
+ router_id = binding and binding.get('router_id')
+ update_required = (not binding or
+ binding.vif_type == portbindings.VIF_TYPE_BINDING_FAILED or
+ router_id != device_id)
+ if update_required:
with session.begin(subtransactions=True):
if not binding:
binding = db.ensure_dvr_port_binding(
- session, id, host, router_id=attrs['device_id'])
+ session, id, host, router_id=device_id)
orig_port = super(Ml2Plugin, self).get_port(context, id)
network = self.get_network(context, orig_port['network_id'])
mech_context = driver_context.DvrPortContext(self,
from neutron.plugins.ml2 import driver_api
from neutron.plugins.ml2 import driver_context
from neutron.plugins.ml2.drivers import type_vlan
+from neutron.plugins.ml2 import models
from neutron.plugins.ml2 import plugin as ml2_plugin
from neutron.tests.unit import _test_extension_portbindings as test_bindings
from neutron.tests.unit.ml2.drivers import mechanism_logger as mech_logger
port = self._show('ports', port_id)['port']
self._check_port_binding_profile(port, profile)
+ def test_process_dvr_port_binding_update_router_id(self):
+ host_id = 'host'
+ binding = models.DVRPortBinding(
+ port_id='port_id',
+ host=host_id,
+ router_id='old_router_id',
+ vif_type=portbindings.VIF_TYPE_OVS,
+ vnic_type=portbindings.VNIC_NORMAL,
+ cap_port_filter=False,
+ status=constants.PORT_STATUS_DOWN)
+ plugin = manager.NeutronManager.get_plugin()
+ mock_network = {'id': 'net_id'}
+ context = mock.Mock()
+ new_router_id = 'new_router'
+ attrs = {'device_id': new_router_id, portbindings.HOST_ID: host_id}
+ with mock.patch.object(plugin, '_update_port_dict_binding'):
+ with mock.patch.object(ml2_db, 'get_network_segments',
+ return_value=[]):
+ mech_context = driver_context.DvrPortContext(
+ self, context, 'port', mock_network, binding)
+ plugin._process_dvr_port_binding(mech_context, context, attrs)
+ self.assertEqual(new_router_id,
+ mech_context._binding.router_id)
+ self.assertEqual(host_id, mech_context._binding.host)
+
class TestMl2PortBindingNoSG(TestMl2PortBinding):
HAS_PORT_FILTER = False