#
import sqlalchemy as sa
+
+from oslo_db import exception as db_exc
from sqlalchemy import orm
from neutron.api.v2 import attributes as attr
allowed_address_pairs):
if not attr.is_attr_set(allowed_address_pairs):
return []
- with context.session.begin(subtransactions=True):
- for address_pair in allowed_address_pairs:
- # use port.mac_address if no mac address in address pair
- if 'mac_address' not in address_pair:
- address_pair['mac_address'] = port['mac_address']
- db_pair = AllowedAddressPair(
- port_id=port['id'],
- mac_address=address_pair['mac_address'],
- ip_address=address_pair['ip_address'])
- context.session.add(db_pair)
+ try:
+ with context.session.begin(subtransactions=True):
+ for address_pair in allowed_address_pairs:
+ # use port.mac_address if no mac address in address pair
+ if 'mac_address' not in address_pair:
+ address_pair['mac_address'] = port['mac_address']
+ db_pair = AllowedAddressPair(
+ port_id=port['id'],
+ mac_address=address_pair['mac_address'],
+ ip_address=address_pair['ip_address'])
+ context.session.add(db_pair)
+ except db_exc.DBDuplicateEntry:
+ raise addr_pair.DuplicateAddressPairInRequest(
+ mac_address=address_pair['mac_address'],
+ ip_address=address_pair['ip_address'])
return allowed_address_pairs
res = req.get_response(self.api)
self.assertEqual(409, res.status_int)
+ def test_update_with_none_and_own_mac_for_duplicate_ip(self):
+ with self.network() as net:
+ res = self._create_port(self.fmt, net['network']['id'])
+ port = self.deserialize(self.fmt, res)
+ mac_address = port['port']['mac_address']
+ address_pairs = [{'ip_address': '10.0.0.1'},
+ {'mac_address': mac_address,
+ 'ip_address': '10.0.0.1'}]
+ update_port = {'port': {addr_pair.ADDRESS_PAIRS:
+ address_pairs}}
+ req = self.new_update_request('ports', update_port,
+ port['port']['id'])
+ res = req.get_response(self.api)
+ self.assertEqual(400, res.status_int)
+
def test_create_port_remove_allowed_address_pairs(self):
with self.network() as net:
address_pairs = [{'mac_address': '00:00:00:00:00:01',