Use router tenant for interface attach

When trying to add interface from a shared network by other tenant to
router, internal server will be raised.
Should use router tenant id instead of subnet tenant id to create port
when adding interface to router. And from the user's perspective the
port created should belong to the user who created it.

Change-Id: Ib124bbc85b9289940eb3de75a222196479e48e6b
Closes-bug: #1673696
This commit is contained in:
liyingjun 2017-03-17 15:55:36 +08:00
parent 3d5d9e8957
commit 5554d9c5b0
3 changed files with 6 additions and 6 deletions

View File

@ -775,7 +775,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
port['port_id'], {'port':
{'fixed_ips': fixed_ips}}), [subnet], False
port_data = {'tenant_id': subnet['tenant_id'],
port_data = {'tenant_id': router.tenant_id,
'network_id': subnet['network_id'],
'fixed_ips': [fixed_ip],
'admin_state_up': True,

View File

@ -1011,10 +1011,10 @@ class L3NatTestCaseBase(L3NatTestCaseMixin):
self.assertIn('id', payload)
self.assertEqual(payload['id'], router['router']['id'])
self.assertIn('tenant_id', payload)
stid = subnet['subnet']['tenant_id']
rtid = router['router']['tenant_id']
# tolerate subnet tenant deliberately set to '' in the
# nsx metadata access case
self.assertIn(payload['tenant_id'], [stid, ''], msg)
self.assertIn(payload['tenant_id'], [rtid, ''], msg)
def test_router_add_interface_bad_values(self):
with self.router() as r:

View File

@ -700,7 +700,7 @@ class TestMl2PortsV2(test_plugin.TestPortsV2, Ml2PluginV2TestCase):
method='create_port_postcommit')):
l3_plugin = directory.get_plugin(constants.L3)
data = {'router': {'name': 'router', 'admin_state_up': True,
'tenant_id': self.context.tenant_id}}
'tenant_id': 'fake_tenant'}}
r = l3_plugin.create_router(self.context, data)
with self.subnet() as s:
data = {'subnet_id': s['subnet']['id']}
@ -717,7 +717,7 @@ class TestMl2PortsV2(test_plugin.TestPortsV2, Ml2PluginV2TestCase):
method='_bind_port_if_needed')):
l3_plugin = directory.get_plugin(constants.L3)
data = {'router': {'name': 'router', 'admin_state_up': True,
'tenant_id': self.context.tenant_id}}
'tenant_id': 'fake_tenant'}}
r = l3_plugin.create_router(self.context, data)
with self.subnet() as s:
data = {'subnet_id': s['subnet']['id']}
@ -1398,7 +1398,7 @@ class TestMl2DvrPortsV2(TestMl2PortsV2):
r = plugin.create_router(
self.context,
{'router': {'name': 'router', 'admin_state_up': True,
'tenant_id': self.context.tenant_id}})
'tenant_id': 'fake_tenant'}})
with self.subnet() as s:
p = plugin.add_router_interface(self.context, r['id'],
{'subnet_id': s['subnet']['id']})