Merge "BigSwitch: Fix tenant_id for shared net requests"

This commit is contained in:
Jenkins 2014-02-27 00:16:38 +00:00 committed by Gerrit Code Review
commit fe6320c2af
2 changed files with 39 additions and 10 deletions

View File

@ -312,6 +312,11 @@ class NeutronRestProxyV2Base(db_base_plugin_v2.NeutronDbPluginV2,
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,
@ -505,8 +510,7 @@ class NeutronRestProxyV2(NeutronRestProxyV2Base,
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'
@ -514,7 +518,7 @@ class NeutronRestProxyV2(NeutronRestProxyV2Base,
# 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
@ -589,9 +593,11 @@ class NeutronRestProxyV2(NeutronRestProxyV2Base,
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)
@ -621,15 +627,14 @@ class NeutronRestProxyV2(NeutronRestProxyV2Base,
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):

View File

@ -118,6 +118,30 @@ class TestBigSwitchProxyPortsV2(test_plugin.TestPortsV2,
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,