return v
return False
+ def _get_port_net_tenantid(self, context, port):
+ net = super(NeutronRestProxyV2Base,
+ self).get_network(context, port["network_id"])
+ return net['tenant_id']
+
class NeutronRestProxyV2(NeutronRestProxyV2Base,
extradhcpopt_db.ExtraDhcpOptMixin,
self._process_port_create_extra_dhcp_opts(context, new_port,
dhcp_opts)
new_port = self._extend_port_dict_binding(context, new_port)
- net = super(NeutronRestProxyV2,
- self).get_network(context, new_port["network_id"])
+ net_tenant_id = self._get_port_net_tenantid(context, new_port)
if self.add_meta_server_route:
if new_port['device_owner'] == 'network:dhcp':
destination = METADATA_SERVER_IP + '/32'
# create on network ctrl
mapped_port = self._map_state_and_status(new_port)
- self.servers.rest_create_port(net["tenant_id"],
+ self.servers.rest_create_port(net_tenant_id,
new_port["network_id"],
mapped_port)
return new_port
ctrl_update_required = True
if ctrl_update_required:
+ # tenant_id must come from network in case network is shared
+ net_tenant_id = self._get_port_net_tenantid(context, new_port)
new_port = self._extend_port_dict_binding(context, new_port)
mapped_port = self._map_state_and_status(new_port)
- self.servers.rest_update_port(new_port["tenant_id"],
+ self.servers.rest_update_port(net_tenant_id,
new_port["network_id"],
mapped_port)
def _delete_port(self, context, port_id):
port = super(NeutronRestProxyV2, self).get_port(context, port_id)
- tenant_id = port['tenant_id']
- net_id = port['network_id']
- if tenant_id == '':
- net = super(NeutronRestProxyV2, self).get_network(context, net_id)
- tenant_id = net['tenant_id']
+
+ # Tenant ID must come from network in case the network is shared
+ tenant_id = self._get_port_net_tenantid(context, port)
+
# Delete from DB
ret_val = super(NeutronRestProxyV2,
self)._delete_port(context, port_id)
- self.servers.rest_delete_port(tenant_id, net_id, port_id)
+ self.servers.rest_delete_port(tenant_id, port['network_id'], port_id)
return ret_val
def create_subnet(self, context, subnet):
port = self._get_ports(n['network']['id'])[0]
self.assertEqual('ACTIVE', port['status'])
+ def test_correct_shared_net_tenant_id(self):
+ # tenant_id in port requests should match network tenant_id instead
+ # of port tenant_id
+ def rest_port_op(self, ten_id, netid, port):
+ if ten_id != 'SHARED':
+ raise Exception('expecting tenant_id SHARED. got %s' % ten_id)
+ with self.network(tenant_id='SHARED', shared=True) as net:
+ with self.subnet(network=net) as sub:
+ pref = 'neutron.plugins.bigswitch.servermanager.ServerPool.%s'
+ tomock = [pref % 'rest_create_port',
+ pref % 'rest_update_port',
+ pref % 'rest_delete_port']
+ patches = [patch(f, create=True, new=rest_port_op)
+ for f in tomock]
+ for restp in patches:
+ restp.start()
+ with self.port(subnet=sub, tenant_id='port-owner') as port:
+ data = {'port': {'binding:host_id': 'someotherhost',
+ 'device_id': 'override_dev'}}
+ req = self.new_update_request('ports', data,
+ port['port']['id'])
+ res = req.get_response(self.api)
+ self.assertEqual(res.status_int, 200)
+
class TestBigSwitchProxyPortsV2IVS(test_plugin.TestPortsV2,
BigSwitchProxyPluginV2TestCase,