Merge "Migrate device_owner for router's interface"
This commit is contained in:
commit
4735c6b64c
|
@ -1847,6 +1847,13 @@ class L3_NAT_db_mixin(L3_NAT_dbonly_mixin, L3RpcNotifierMixin):
|
|||
super(L3_NAT_db_mixin, self).notify_routers_updated(
|
||||
context, list(router_ids), 'disassociate_floatingips', {})
|
||||
|
||||
def _migrate_router_ports(
|
||||
self, context, router_db, old_owner, new_owner):
|
||||
"""Update the model to support the dvr case of a router."""
|
||||
for rp in router_db.attached_ports.filter_by(port_type=old_owner):
|
||||
rp.port_type = new_owner
|
||||
rp.port.device_owner = new_owner
|
||||
|
||||
|
||||
def _prevent_l3_port_delete_callback(resource, event, trigger, **kwargs):
|
||||
context = kwargs['context']
|
||||
|
|
|
@ -123,16 +123,6 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
|
|||
raise l3.RouterInUse(router_id=router_db['id'],
|
||||
reason=e)
|
||||
|
||||
def _update_distributed_attr(
|
||||
self, context, router_id, router_db, data):
|
||||
"""Update the model to support the dvr case of a router."""
|
||||
if data.get('distributed'):
|
||||
old_owner = const.DEVICE_OWNER_ROUTER_INTF
|
||||
new_owner = const.DEVICE_OWNER_DVR_INTERFACE
|
||||
for rp in router_db.attached_ports.filter_by(port_type=old_owner):
|
||||
rp.port_type = new_owner
|
||||
rp.port.device_owner = new_owner
|
||||
|
||||
def _update_router_db(self, context, router_id, data):
|
||||
with context.session.begin(subtransactions=True):
|
||||
router_db = super(
|
||||
|
@ -143,8 +133,11 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
|
|||
data.get('distributed') is True)
|
||||
self._validate_router_migration(context, router_db, data)
|
||||
router_db.extra_attributes.update(data)
|
||||
self._update_distributed_attr(
|
||||
context, router_id, router_db, data)
|
||||
if data.get('distributed'):
|
||||
self._migrate_router_ports(
|
||||
context, router_db,
|
||||
old_owner=const.DEVICE_OWNER_ROUTER_INTF,
|
||||
new_owner=const.DEVICE_OWNER_DVR_INTERFACE)
|
||||
if migrating_to_distributed:
|
||||
cur_agents = self.list_l3_agents_hosting_router(
|
||||
context, router_db['id'])['agents']
|
||||
|
|
|
@ -529,6 +529,10 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin,
|
|||
# deleted. the core plugin will stop us if its in use
|
||||
self.safe_delete_ha_network(context, ha_network,
|
||||
router_db.tenant_id)
|
||||
self._migrate_router_ports(
|
||||
context, router_db,
|
||||
old_owner=constants.DEVICE_OWNER_HA_REPLICATED_INT,
|
||||
new_owner=constants.DEVICE_OWNER_ROUTER_INTF)
|
||||
|
||||
self.schedule_router(context, router_id)
|
||||
router_db = super(L3_HA_NAT_db_mixin, self)._update_router_db(
|
||||
|
|
|
@ -112,7 +112,7 @@ class L3DvrTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase):
|
|||
self.assertFalse(router_db.extra_attributes.distributed)
|
||||
self.mixin._get_router = mock.Mock(return_value=router_db)
|
||||
self.mixin._validate_router_migration = mock.Mock()
|
||||
self.mixin._update_distributed_attr = mock.Mock()
|
||||
self.mixin._migrate_router_ports = mock.Mock()
|
||||
self.mixin.list_l3_agents_hosting_router = mock.Mock(
|
||||
return_value={'agents': [agent]})
|
||||
self.mixin._unbind_router = mock.Mock()
|
||||
|
@ -121,7 +121,7 @@ class L3DvrTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase):
|
|||
# Assert that the DB value has changed
|
||||
self.assertTrue(router_db.extra_attributes.distributed)
|
||||
self.assertEqual(1,
|
||||
self.mixin._update_distributed_attr.call_count)
|
||||
self.mixin._migrate_router_ports.call_count)
|
||||
|
||||
def _test_get_device_owner(self, is_distributed=False,
|
||||
expected=const.DEVICE_OWNER_ROUTER_INTF,
|
||||
|
|
|
@ -1204,6 +1204,27 @@ class L3HAModeDbTestCase(L3HATestFramework):
|
|||
self.assertFalse(l3_hamode_db.is_ha_router_port(
|
||||
self.admin_ctx, port['device_owner'], port['device_id']))
|
||||
|
||||
def test_migration_from_ha(self):
|
||||
router = self._create_router()
|
||||
self.assertTrue(router['ha'])
|
||||
|
||||
network_id = self._create_network(self.core_plugin, self.admin_ctx)
|
||||
subnet = self._create_subnet(self.core_plugin, self.admin_ctx,
|
||||
network_id)
|
||||
interface_info = {'subnet_id': subnet['id']}
|
||||
self.plugin.add_router_interface(self.admin_ctx,
|
||||
router['id'],
|
||||
interface_info)
|
||||
|
||||
router = self._migrate_router(router['id'], False)
|
||||
|
||||
self.assertFalse(router.extra_attributes['ha'])
|
||||
for routerport in router.attached_ports.all():
|
||||
self.assertEqual(constants.DEVICE_OWNER_ROUTER_INTF,
|
||||
routerport.port_type)
|
||||
self.assertEqual(constants.DEVICE_OWNER_ROUTER_INTF,
|
||||
routerport.port.device_owner)
|
||||
|
||||
|
||||
class L3HAUserTestCase(L3HATestFramework):
|
||||
|
||||
|
|
Loading…
Reference in New Issue