Browse Source

Search ports with matching subnet

On ipam_request_address, it will try to find existing Neutron
ports if any. If there is no existing Neutron ports, kuryr will
create one. Kuryr will search ports with matching IP address first.
If the first search is not successful, it will do a second search
to find ports with matching mac address.
This commit improve the second search by matching the subnet_id
as well as the mac address. This is because things will go wrong
if the port is in a different subnet (e.g. an ipv6 address is
requested while the port is in a v4 subnet).

Change-Id: I1eaa9c87079f1c57babbe08ae52ed69a44cfa9aa
Related-Bug: #1800375
Hongbin Lu 5 months ago
parent
commit
542cb5aabd
2 changed files with 8 additions and 3 deletions
  1. 1
    0
      kuryr_libnetwork/controllers.py
  2. 7
    3
      kuryr_libnetwork/tests/unit/test_kuryr_ipam.py

+ 1
- 0
kuryr_libnetwork/controllers.py View File

@@ -1716,6 +1716,7 @@ def ipam_request_address():
1716 1716
                         fixed_ips=fixed_ip_existing).get('ports', [])
1717 1717
                 if not filtered_ports:
1718 1718
                     filtered_ports = app.neutron.list_ports(
1719
+                        fixed_ips='subnet_id=%s' % subnet['id'],
1719 1720
                         mac_address=req_mac_address).get('ports', [])
1720 1721
 
1721 1722
                 num_ports = len(filtered_ports)

+ 7
- 3
kuryr_libnetwork/tests/unit/test_kuryr_ipam.py View File

@@ -798,7 +798,9 @@ class TestKuryrIpam(base.TestKuryrBase):
798 798
             subnetpool_id=fake_kuryr_subnetpool_id)
799 799
         mock_list_ports.assert_has_calls([
800 800
             mock.call(fixed_ips=fixed_ip_existing),
801
-            mock.call(mac_address=fake_mac_address)])
801
+            mock.call(
802
+                mac_address=fake_mac_address,
803
+                fixed_ips='subnet_id=%s' % fake_v4_subnet['subnet']['id'])])
802 804
         mock_create_port.assert_called_with({'port': port_request})
803 805
         if mock_app.tag_ext:
804 806
             mock_port_add_tag.assert_called()
@@ -1030,8 +1032,10 @@ class TestKuryrIpam(base.TestKuryrBase):
1030 1032
             mock.call(subnetpool_id=fake_kuryr_subnetpool_id),
1031 1033
             mock.call(subnetpool_id=fake_kuryr_subnetpool_v6_id)])
1032 1034
         mock_list_ports.assert_has_calls([
1033
-            mock.call(mac_address=requested_mac_address),
1034
-            mock.call(mac_address=requested_mac_address)])
1035
+            mock.call(mac_address=requested_mac_address,
1036
+                      fixed_ips='subnet_id=%s' % subnet_v4_id),
1037
+            mock.call(mac_address=requested_mac_address,
1038
+                      fixed_ips='subnet_id=%s' % subnet_v6_id)])
1035 1039
         mock_update_port.assert_called_with(fake_neutron_port_id,
1036 1040
             {'port': update_port})
1037 1041
         if mock_app.tag_ext:

Loading…
Cancel
Save