Browse Source

Remove unnecessary port update

Kuryr update pre-created neutron port twice. The first one is in
'ipam_request_address' and it updates the following attributes:
* name
* admin_state_up
* mac_address

The second port update is in 'network_driver_create_endpoint' and
several attributes are written including name and mac_address.
This commit remove the first port update to optimize the performance.
The update of admin_state_up will be moved to the second port update.

Change-Id: I743b2088366d910902775cabefa43be2865e37c5
Partial-Bug: #1809306
Hongbin Lu 4 months ago
parent
commit
610fd5f024

+ 1
- 30
kuryr_libnetwork/controllers.py View File

@@ -517,33 +517,6 @@ def _get_cidr_from_subnetpool(**kwargs):
517 517
             .format(kwargs))
518 518
 
519 519
 
520
-def _update_existing_port(existing_port, fixed_ip, mac_address):
521
-    host = existing_port.get('binding:host_id')
522
-    vif_type = existing_port.get('binding:vif_type')
523
-    if not host and vif_type == 'unbound':
524
-        updated_port = {
525
-            'name': const.NEUTRON_UNBOUND_PORT,
526
-            'admin_state_up': True,
527
-        }
528
-        if mac_address:
529
-            updated_port['mac_address'] = mac_address
530
-        updated_port_resp = app.neutron.update_port(
531
-            existing_port['id'],
532
-            {'port': updated_port})
533
-        existing_port = updated_port_resp['port']
534
-    else:
535
-        port_name = existing_port.get('name', '')
536
-        if (str(port_name) != const.NEUTRON_UNBOUND_PORT or
537
-                len(existing_port['fixed_ips']) <= 1 or
538
-                host != lib_utils.get_hostname()):
539
-            raise exceptions.AddressInUseException(
540
-                "Requested ip address {0} already belongs to "
541
-                "a bound Neutron port: {1}".format(fixed_ip,
542
-                                                   existing_port['id']))
543
-
544
-    return existing_port
545
-
546
-
547 520
 def revoke_expose_ports(port_id):
548 521
     sgs = app.neutron.list_security_groups(
549 522
         name=utils.get_sg_expose_name(port_id))
@@ -1735,9 +1708,7 @@ def ipam_request_address():
1735 1708
                 fixed_ips.append(fixed_ip)
1736 1709
 
1737 1710
                 if num_ports:
1738
-                    existing_port = filtered_ports[0]
1739
-                    created_port = _update_existing_port(
1740
-                        existing_port, fixed_ip, req_mac_address)
1711
+                    created_port = filtered_ports[0]
1741 1712
                     # REVISIT(yedongcan) For tag-ext extension not
1742 1713
                     # supported, the Neutron existing port still can not
1743 1714
                     # be deleted in ipam_release_address.

+ 1
- 0
kuryr_libnetwork/port_driver/driver.py View File

@@ -134,6 +134,7 @@ class Driver(object):
134 134
                 'name': port['name'],
135 135
                 'device_owner': lib_const.DEVICE_OWNER,
136 136
                 'binding:host_id': lib_utils.get_hostname(),
137
+                'admin_state_up': True,
137 138
             }
138 139
             if not port.get('device_id'):
139 140
                 updated_port['device_id'] = endpoint_id

+ 6
- 3
kuryr_libnetwork/tests/unit/port_driver/drivers/test_veth.py View File

@@ -114,7 +114,8 @@ class TestVethDriver(base.TestKuryrBase):
114 114
                 'name': fake_port_name,
115 115
                 'device_owner': lib_const.DEVICE_OWNER,
116 116
                 'binding:host_id': lib_utils.get_hostname(),
117
-                'mac_address': fake_mac_address2
117
+                'mac_address': fake_mac_address2,
118
+                'admin_state_up': True,
118 119
             }
119 120
         }
120 121
         mock_update_port.assert_called_with(fake_neutron_port_id,
@@ -145,7 +146,8 @@ class TestVethDriver(base.TestKuryrBase):
145 146
             'port': {
146 147
                 'name': fake_port_name,
147 148
                 'device_owner': lib_const.DEVICE_OWNER,
148
-                'binding:host_id': lib_utils.get_hostname()
149
+                'binding:host_id': lib_utils.get_hostname(),
150
+                'admin_state_up': True,
149 151
             }
150 152
         }
151 153
         mock_update_port.assert_called_with(fake_neutron_port_id,
@@ -183,7 +185,8 @@ class TestVethDriver(base.TestKuryrBase):
183 185
                 'device_owner': lib_const.DEVICE_OWNER,
184 186
                 'binding:host_id': lib_utils.get_hostname(),
185 187
                 'device_id': fake_endpoint_id,
186
-                'mac_address': fake_mac_address2
188
+                'mac_address': fake_mac_address2,
189
+                'admin_state_up': True,
187 190
             }
188 191
         }
189 192
         mock_update_port.assert_called_with(fake_neutron_port_id,

+ 2
- 1
kuryr_libnetwork/tests/unit/port_driver/drivers/test_vlan.py View File

@@ -303,7 +303,8 @@ class TestVlanDriver(base.TestKuryrBase):
303 303
                     'name': fake_port_name,
304 304
                     'device_owner': lib_const.DEVICE_OWNER,
305 305
                     'binding:host_id': lib_utils.get_hostname(),
306
-                    'mac_address': fake_neutron_mac_address2
306
+                    'mac_address': fake_neutron_mac_address2,
307
+                    'admin_state_up': True,
307 308
                 }})
308 309
 
309 310
 

+ 2
- 22
kuryr_libnetwork/tests/unit/test_kuryr_ipam.py View File

@@ -811,14 +811,13 @@ class TestKuryrIpam(base.TestKuryrBase):
811 811
 
812 812
     @mock.patch('kuryr_libnetwork.controllers._neutron_port_add_tag')
813 813
     @mock.patch('kuryr_libnetwork.controllers.app.neutron.create_port')
814
-    @mock.patch('kuryr_libnetwork.controllers.app.neutron.update_port')
815 814
     @mock.patch('kuryr_libnetwork.controllers.app.neutron.list_ports')
816 815
     @mock.patch('kuryr_libnetwork.controllers.app.neutron.list_subnets')
817 816
     @mock.patch('kuryr_libnetwork.controllers.app')
818 817
     @ddt.data((False), (True))
819 818
     def test_ipam_driver_request_specific_address_existing_port(self,
820 819
             use_tag_ext, mock_app, mock_list_subnets, mock_list_ports,
821
-            mock_update_port, mock_create_port, mock_port_add_tag):
820
+            mock_create_port, mock_port_add_tag):
822 821
         mock_app.tag_ext = use_tag_ext
823 822
         # faking list_subnets
824 823
         neutron_network_id = uuidutils.generate_uuid()
@@ -876,13 +875,6 @@ class TestKuryrIpam(base.TestKuryrBase):
876 875
         mock_list_ports.side_effect = [
877 876
             fake_ports_response, fake_ports_response_2]
878 877
 
879
-        update_port = {
880
-            'name': const.NEUTRON_UNBOUND_PORT,
881
-            'admin_state_up': True,
882
-            'mac_address': requested_mac_address,
883
-        }
884
-        mock_update_port.return_value = fake_port
885
-
886 878
         # Testing container ip allocation
887 879
         fake_request = {
888 880
             'PoolID': fake_kuryr_subnetpool_id,
@@ -917,8 +909,6 @@ class TestKuryrIpam(base.TestKuryrBase):
917 909
         mock_list_ports.assert_has_calls([
918 910
             mock.call(fixed_ips=fixed_ip_existing),
919 911
             mock.call(fixed_ips=fixed_ipv6_existing)])
920
-        mock_update_port.assert_called_with(fake_neutron_port_id,
921
-            {'port': update_port})
922 912
         if mock_app.tag_ext:
923 913
             self.assertEqual(2, mock_port_add_tag.call_count)
924 914
         else:
@@ -926,14 +916,13 @@ class TestKuryrIpam(base.TestKuryrBase):
926 916
 
927 917
     @mock.patch('kuryr_libnetwork.controllers._neutron_port_add_tag')
928 918
     @mock.patch('kuryr_libnetwork.controllers.app.neutron.create_port')
929
-    @mock.patch('kuryr_libnetwork.controllers.app.neutron.update_port')
930 919
     @mock.patch('kuryr_libnetwork.controllers.app.neutron.list_ports')
931 920
     @mock.patch('kuryr_libnetwork.controllers.app.neutron.list_subnets')
932 921
     @mock.patch('kuryr_libnetwork.controllers.app')
933 922
     @ddt.data((False), (True))
934 923
     def test_ipam_driver_request_specific_mac_address_existing_port(self,
935 924
             use_tag_ext, mock_app, mock_list_subnets, mock_list_ports,
936
-            mock_update_port, mock_create_port, mock_port_add_tag):
925
+            mock_create_port, mock_port_add_tag):
937 926
         mock_app.tag_ext = use_tag_ext
938 927
         # faking list_subnets
939 928
         neutron_network_id = uuidutils.generate_uuid()
@@ -991,13 +980,6 @@ class TestKuryrIpam(base.TestKuryrBase):
991 980
         mock_list_ports.side_effect = [
992 981
             fake_ports_response, fake_ports_response_2]
993 982
 
994
-        update_port = {
995
-            'name': const.NEUTRON_UNBOUND_PORT,
996
-            'admin_state_up': True,
997
-            'mac_address': requested_mac_address,
998
-        }
999
-        mock_update_port.return_value = fake_port
1000
-
1001 983
         # Testing container ip allocation
1002 984
         fake_request = {
1003 985
             'PoolID': fake_kuryr_subnetpool_id,
@@ -1034,8 +1016,6 @@ class TestKuryrIpam(base.TestKuryrBase):
1034 1016
                       fixed_ips='subnet_id=%s' % subnet_v4_id),
1035 1017
             mock.call(mac_address=requested_mac_address,
1036 1018
                       fixed_ips='subnet_id=%s' % subnet_v6_id)])
1037
-        mock_update_port.assert_called_with(fake_neutron_port_id,
1038
-            {'port': update_port})
1039 1019
         if mock_app.tag_ext:
1040 1020
             self.assertEqual(2, mock_port_add_tag.call_count)
1041 1021
         else:

Loading…
Cancel
Save