Skip to content

Commit 9df4a7e

Browse files
rubasovkatonalala
authored andcommitted
Do not ignore attributes in bulk port create
With unit tests that would have caught the bug. Change-Id: Ia4a68bdccecfbcb9d1aa49e2b14e06d139891c0f Closes-Bug: #2003553 (cherry picked from commit ed68ba4) (cherry picked from commit 1b086f1)
1 parent 5206387 commit 9df4a7e

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

neutron/plugins/ml2/plugin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,13 +1717,13 @@ def _create_port_bulk(self, context, port_list, network_cache):
17171717
self._process_port_binding(mech_context, port_dict)
17181718

17191719
# process allowed address pairs
1720-
db_port_obj[addr_apidef.ADDRESS_PAIRS] = (
1720+
port_dict[addr_apidef.ADDRESS_PAIRS] = (
17211721
self._process_create_allowed_address_pairs(
17221722
context, port_dict,
1723-
port_dict.get(addr_apidef.ADDRESS_PAIRS)))
1723+
pdata.get(addr_apidef.ADDRESS_PAIRS)))
17241724

17251725
# handle DHCP setup
1726-
dhcp_opts = port_dict.get(edo_ext.EXTRADHCPOPTS, [])
1726+
dhcp_opts = pdata.get(edo_ext.EXTRADHCPOPTS, [])
17271727
self._process_port_create_extra_dhcp_opts(context, port_dict,
17281728
dhcp_opts)
17291729
# send PRECOMMIT_CREATE notification

neutron/tests/unit/plugins/ml2/test_plugin.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,6 +1688,55 @@ def test_create_ports_bulk_ip_allocation_without_mac_no_net(self):
16881688
ctx, ports
16891689
)
16901690

1691+
def test_create_ports_bulk_with_allowed_address_pairs(self):
1692+
ctx = context.get_admin_context()
1693+
with self.network() as net:
1694+
1695+
aap = [{
1696+
'ip_address': '1.2.3.4',
1697+
'mac_address': '01:23:45:67:89:ab',
1698+
}]
1699+
ports_in = {
1700+
'ports': [{'port': {
1701+
'allowed_address_pairs': aap,
1702+
'network_id': net['network']['id'],
1703+
'project_id': self._tenant_id,
1704+
1705+
'admin_state_up': True,
1706+
'device_id': '',
1707+
'device_owner': '',
1708+
'fixed_ips': constants.ATTR_NOT_SPECIFIED,
1709+
'name': '',
1710+
'security_groups': constants.ATTR_NOT_SPECIFIED,
1711+
}}]}
1712+
ports_out = self.plugin.create_port_bulk(ctx, ports_in)
1713+
self.assertEqual(aap, ports_out[0]['allowed_address_pairs'])
1714+
1715+
def test_create_ports_bulk_with_extra_dhcp_opts(self):
1716+
ctx = context.get_admin_context()
1717+
with self.network() as net:
1718+
1719+
edo = [{
1720+
'opt_name': 'domain-name-servers',
1721+
'opt_value': '10.0.0.1',
1722+
'ip_version': 4,
1723+
}]
1724+
ports_in = {
1725+
'ports': [{'port': {
1726+
'extra_dhcp_opts': edo,
1727+
'network_id': net['network']['id'],
1728+
'project_id': self._tenant_id,
1729+
1730+
'admin_state_up': True,
1731+
'device_id': '',
1732+
'device_owner': '',
1733+
'fixed_ips': constants.ATTR_NOT_SPECIFIED,
1734+
'name': '',
1735+
'security_groups': constants.ATTR_NOT_SPECIFIED,
1736+
}}]}
1737+
ports_out = self.plugin.create_port_bulk(ctx, ports_in)
1738+
self.assertEqual(edo, ports_out[0]['extra_dhcp_opts'])
1739+
16911740
def test_delete_port_no_notify_in_disassociate_floatingips(self):
16921741
ctx = context.get_admin_context()
16931742
plugin = directory.get_plugin()

0 commit comments

Comments
 (0)