Merge "Ensure that subnet_id is on correct network."
This commit is contained in:
commit
95c9163986
@ -344,6 +344,11 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
|
|||||||
raise q_exc.InvalidInput(error_message=msg)
|
raise q_exc.InvalidInput(error_message=msg)
|
||||||
else:
|
else:
|
||||||
subnet = self._get_subnet(context, fixed['subnet_id'])
|
subnet = self._get_subnet(context, fixed['subnet_id'])
|
||||||
|
if subnet['network_id'] != network_id:
|
||||||
|
msg = _('Failed to create port on network %s, '
|
||||||
|
'because fixed_ips included invalid subnet '
|
||||||
|
'%s') % (network_id, fixed['subnet_id'])
|
||||||
|
raise q_exc.InvalidInput(error_message=msg)
|
||||||
subnet_id = subnet['id']
|
subnet_id = subnet['id']
|
||||||
|
|
||||||
if 'ip_address' in fixed:
|
if 'ip_address' in fixed:
|
||||||
|
@ -425,6 +425,24 @@ class TestPortsV2(QuantumDbPluginV2TestCase):
|
|||||||
self.assertEquals(ips[0]['ip_address'], '10.0.0.3')
|
self.assertEquals(ips[0]['ip_address'], '10.0.0.3')
|
||||||
self.assertEquals(ips[0]['subnet_id'], subnet['subnet']['id'])
|
self.assertEquals(ips[0]['subnet_id'], subnet['subnet']['id'])
|
||||||
|
|
||||||
|
def test_requested_subnet_id_not_on_network(self):
|
||||||
|
fmt = 'json'
|
||||||
|
with self.subnet() as subnet:
|
||||||
|
with self.port(subnet=subnet) as port:
|
||||||
|
# Create new network
|
||||||
|
res = self._create_network(fmt=fmt, name='net2',
|
||||||
|
admin_status_up=True)
|
||||||
|
network2 = self.deserialize(fmt, res)
|
||||||
|
subnet2 = self._make_subnet(fmt, network2, "1.1.1.1",
|
||||||
|
"1.1.1.0/24", 4)
|
||||||
|
net_id = port['port']['network_id']
|
||||||
|
# Request a IP from specific subnet
|
||||||
|
kwargs = {"fixed_ips": [{'subnet_id':
|
||||||
|
subnet2['subnet']['id']}]}
|
||||||
|
net_id = port['port']['network_id']
|
||||||
|
res = self._create_port(fmt, net_id=net_id, **kwargs)
|
||||||
|
self.assertEquals(res.status_int, 400)
|
||||||
|
|
||||||
def test_requested_subnet_id_v4_and_v6(self):
|
def test_requested_subnet_id_v4_and_v6(self):
|
||||||
fmt = 'json'
|
fmt = 'json'
|
||||||
with self.subnet() as subnet:
|
with self.subnet() as subnet:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user