Fix incorrectly passing ext_ips as gateway ips
An event will be sent out after creating router gateway. Within the event, ext_ips is sent incorrectly while gw_ips is expected. Project neutron-dynamic-routing subscribes the topic and will process the event. But it can't process ext_ips. This commit gets the gw_ips through the ext_ips and sends gw_ips out. Co-Authored-By: Allain Legacy<Allain.legacy@windriver.com> Change-Id: I9b67b58e87faa9cbb8ed4cd03c74f467ca20d73f Closes-Bug: #1796629
This commit is contained in:
parent
f719d1f087
commit
221f386029
|
@ -493,11 +493,14 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
|
|||
include_gateway=True)
|
||||
self._create_router_gw_port(context, router,
|
||||
new_network_id, ext_ips)
|
||||
|
||||
gw_ips = [x['ip_address'] for x in router.gw_port['fixed_ips']]
|
||||
|
||||
registry.notify(resources.ROUTER_GATEWAY,
|
||||
events.AFTER_CREATE,
|
||||
self._create_gw_port,
|
||||
context=context,
|
||||
gw_ips=ext_ips,
|
||||
gw_ips=gw_ips,
|
||||
network_id=new_network_id,
|
||||
router_id=router_id)
|
||||
|
||||
|
|
|
@ -23,11 +23,13 @@ from neutron_lib import context
|
|||
from neutron_lib import exceptions as n_exc
|
||||
from neutron_lib.exceptions import l3 as l3_exc
|
||||
from neutron_lib.plugins import directory
|
||||
from neutron_lib.plugins import utils as plugin_utils
|
||||
from oslo_utils import uuidutils
|
||||
import testtools
|
||||
|
||||
from neutron.db import l3_db
|
||||
from neutron.db.models import l3 as l3_models
|
||||
from neutron.objects import base as base_obj
|
||||
from neutron.objects import router as l3_obj
|
||||
from neutron.tests import base
|
||||
|
||||
|
@ -281,6 +283,44 @@ class TestL3_NAT_dbonly_mixin(base.BaseTestCase):
|
|||
resources.ROUTER_INTERFACE, events.BEFORE_CREATE, self.db,
|
||||
**kwargs)
|
||||
|
||||
def test__create_gw_port(self):
|
||||
router_id = '2afb8434-7380-43a2-913f-ba3a5ad5f349'
|
||||
router = l3_models.Router(id=router_id)
|
||||
new_network_id = 'net-id'
|
||||
ext_ips = [{'subnet_id': 'subnet-id', 'ip_address': '1.1.1.1'}]
|
||||
gw_port = {'fixed_ips': [{'subnet_id': 'subnet-id',
|
||||
'ip_address': '1.1.1.1'}],
|
||||
'id': '8742d007-6f05-4b7e-abdb-11818f608959'}
|
||||
ctx = context.get_admin_context()
|
||||
|
||||
with mock.patch.object(directory, 'get_plugin') as get_p, \
|
||||
mock.patch.object(get_p(), 'get_subnets_by_network',
|
||||
return_value=mock.ANY), \
|
||||
mock.patch.object(get_p(), '_get_port',
|
||||
return_value=gw_port), \
|
||||
mock.patch.object(l3_db.L3_NAT_dbonly_mixin,
|
||||
'_check_for_dup_router_subnets') as cfdrs,\
|
||||
mock.patch.object(plugin_utils, 'create_port',
|
||||
return_value=gw_port), \
|
||||
mock.patch.object(ctx.session, 'add'), \
|
||||
mock.patch.object(base_obj.NeutronDbObject, 'create'), \
|
||||
mock.patch.object(l3_db.registry, 'notify') as mock_notify:
|
||||
|
||||
self.db._create_gw_port(ctx, router_id=router_id,
|
||||
router=router,
|
||||
new_network_id=new_network_id,
|
||||
ext_ips=ext_ips)
|
||||
|
||||
expected_gw_ips = ['1.1.1.1']
|
||||
|
||||
self.assertTrue(cfdrs.called)
|
||||
mock_notify.assert_called_with(
|
||||
resources.ROUTER_GATEWAY, events.AFTER_CREATE,
|
||||
self.db._create_gw_port, context=ctx,
|
||||
gw_ips=expected_gw_ips, network_id=new_network_id,
|
||||
router_id=router_id
|
||||
)
|
||||
|
||||
|
||||
class L3_NAT_db_mixin(base.BaseTestCase):
|
||||
def setUp(self):
|
||||
|
|
|
@ -1930,19 +1930,30 @@ class L3NatTestCaseBase(L3NatTestCaseMixin):
|
|||
|
||||
def test_router_add_gateway_notifications(self):
|
||||
call_count_total = 3
|
||||
|
||||
with self.router() as r:
|
||||
with self.network() as n:
|
||||
self._set_net_external(n['network']['id'])
|
||||
with mock.patch.object(registry, 'notify') as notify:
|
||||
self._add_external_gateway_to_router(
|
||||
r['router']['id'], n['network']['id'])
|
||||
self.assertEqual(call_count_total, notify.call_count)
|
||||
expected = [mock.call(
|
||||
resources.ROUTER_GATEWAY,
|
||||
events.AFTER_CREATE, mock.ANY,
|
||||
context=mock.ANY, gw_ips=mock.ANY,
|
||||
network_id=mock.ANY, router_id=mock.ANY)]
|
||||
notify.assert_has_calls(expected)
|
||||
with self.subnet(network=n) as s:
|
||||
self._set_net_external(n['network']['id'])
|
||||
with mock.patch.object(registry, 'notify') as notify:
|
||||
res = self._add_external_gateway_to_router(
|
||||
r['router']['id'], n['network']['id'],
|
||||
ext_ips=[{'subnet_id': s['subnet']['id'],
|
||||
'ip_address': '10.0.0.4'}])
|
||||
self.assertEqual(call_count_total,
|
||||
notify.call_count)
|
||||
|
||||
gw_info = res['router']['external_gateway_info']
|
||||
ext_ips = gw_info['external_fixed_ips'][0]
|
||||
expected_gw_ips = [ext_ips['ip_address']]
|
||||
expected = [mock.call(
|
||||
resources.ROUTER_GATEWAY,
|
||||
events.AFTER_CREATE, mock.ANY,
|
||||
context=mock.ANY,
|
||||
gw_ips=expected_gw_ips,
|
||||
network_id=n['network']['id'],
|
||||
router_id=r['router']['id'])]
|
||||
notify.assert_has_calls(expected)
|
||||
|
||||
def test_router_remove_interface_inuse_returns_409(self):
|
||||
with self.router() as r:
|
||||
|
|
Loading…
Reference in New Issue