Browse Source

Avoid changing name of existing ports

In before, we renamed existing neutron ports in order to make
the ports searchable by using endpoint_id.
However, user experience is bad on such renaming because the original
name is lost. This commit proposes to use tagging approach instead.
In particular, we tag the endpoint_id to the existing ports so that
the ports are still searchable by using tags.

Closes-Bug: #1810219
Change-Id: I9930f3bcc3a6dbf4b23bf8488f08655bc43b5ba8
Hongbin Lu 3 months ago
parent
commit
a9a70b3178

+ 45
- 13
kuryr_libnetwork/controllers.py View File

@@ -225,8 +225,8 @@ def _get_neutron_port_from_docker_endpoint(endpoint_id):
225 225
 
226 226
 def _get_neutron_port_status_from_docker_endpoint(endpoint_id):
227 227
     response_port_status = {}
228
-    port_name = utils.get_neutron_port_name(endpoint_id)
229
-    filtered_ports = _get_ports_by_attrs(name=port_name)
228
+    neutron_port_identifier = _make_port_identifier(endpoint_id)
229
+    filtered_ports = _get_ports_by_identifier(neutron_port_identifier)
230 230
     if filtered_ports:
231 231
         response_port_status['status'] = filtered_ports[0]['status']
232 232
     return response_port_status
@@ -313,7 +313,9 @@ def _create_or_update_port(neutron_network_id, endpoint_id,
313 313
         port = filtered_ports['ports'][0]
314 314
         port_driver = get_driver(port)
315 315
         response_port = port_driver.update_port(port, endpoint_id,
316
-                                                interface_mac)
316
+                                                interface_mac,
317
+                                                tags=app.tag)
318
+        _neutron_port_add_tags(port, endpoint_id)
317 319
     # For the container boot from dual-net, request_address will
318 320
     # create two ports(v4 and v6 address), we should only allow one
319 321
     # for port bind.
@@ -333,7 +335,9 @@ def _create_or_update_port(neutron_network_id, endpoint_id,
333 335
             else:
334 336
                 port_driver = get_driver(port)
335 337
                 response_port = port_driver.update_port(port, endpoint_id,
336
-                                                        interface_mac)
338
+                                                        interface_mac,
339
+                                                        tags=app.tag)
340
+                _neutron_port_add_tags(port, endpoint_id)
337 341
         if not response_port:
338 342
             fixed_ips = (
339 343
                 lib_utils.get_dict_format_fixed_ips_from_kv_format(fixed_ips))
@@ -388,10 +392,24 @@ def _neutron_port_add_tag(port, tag):
388 392
     _neutron_add_tag('ports', port, tag)
389 393
 
390 394
 
395
+def _neutron_port_add_tags(port, tag):
396
+    if app.tag:
397
+        tags = utils.create_port_tags(tag)
398
+        for tag in tags:
399
+            _neutron_port_add_tag(port, tag)
400
+
401
+
391 402
 def _neutron_port_remove_tag(port, tag):
392 403
     _neutron_remove_tag('ports', port, tag)
393 404
 
394 405
 
406
+def _neutron_port_remove_tags(port, tag):
407
+    if app.tag:
408
+        tags = utils.create_port_tags(tag)
409
+        for tag in tags:
410
+            _neutron_port_remove_tag(port, tag)
411
+
412
+
395 413
 def _neutron_add_tag(resource_type, resource, tag):
396 414
     if tag not in resource['tags']:
397 415
         try:
@@ -419,6 +437,18 @@ def _get_networks_by_identifier(identifier):
419 437
     return _get_networks_by_attrs(name=identifier)
420 438
 
421 439
 
440
+def _make_port_identifier(endpoint_id):
441
+    if app.tag:
442
+        return utils.make_port_tags(endpoint_id)
443
+    return utils.get_neutron_port_name(endpoint_id)
444
+
445
+
446
+def _get_ports_by_identifier(identifier):
447
+    if app.tag:
448
+        return _get_ports_by_attrs(tags=identifier)
449
+    return _get_ports_by_attrs(name=identifier)
450
+
451
+
422 452
 def _program_expose_ports(options, port_id):
423 453
     exposed_ports = options.get(const.DOCKER_EXPOSED_PORTS_OPTION)
424 454
     if not exposed_ports:
@@ -1237,12 +1267,12 @@ def network_driver_delete_endpoint():
1237 1267
             .format(neutron_network_identifier)
1238 1268
         })
1239 1269
     else:
1240
-        neutron_port_name = utils.get_neutron_port_name(endpoint_id)
1241
-        filtered_ports = _get_ports_by_attrs(name=neutron_port_name)
1270
+        neutron_port_identifier = _make_port_identifier(endpoint_id)
1271
+        filtered_ports = _get_ports_by_identifier(neutron_port_identifier)
1242 1272
         if not filtered_ports:
1243 1273
             raise exceptions.NoResourceException(
1244
-                "The port doesn't exist for the name {0}"
1245
-                .format(neutron_port_name))
1274
+                "The port doesn't exist for the identifier {0}"
1275
+                .format(neutron_port_identifier))
1246 1276
         neutron_port = filtered_ports[0]
1247 1277
 
1248 1278
         try:
@@ -1264,6 +1294,8 @@ def network_driver_delete_endpoint():
1264 1294
             with excutils.save_and_reraise_exception():
1265 1295
                 LOG.error('Error while removing the interface: %s', ex)
1266 1296
 
1297
+        _neutron_port_remove_tags(neutron_port, endpoint_id)
1298
+
1267 1299
     return flask.jsonify(const.SCHEMA['SUCCESS'])
1268 1300
 
1269 1301
 
@@ -1321,12 +1353,12 @@ def network_driver_join():
1321 1353
     else:
1322 1354
         neutron_network_id = filtered_networks[0]['id']
1323 1355
 
1324
-        neutron_port_name = utils.get_neutron_port_name(endpoint_id)
1325
-        filtered_ports = _get_ports_by_attrs(name=neutron_port_name)
1356
+        neutron_port_identifier = _make_port_identifier(endpoint_id)
1357
+        filtered_ports = _get_ports_by_identifier(neutron_port_identifier)
1326 1358
         if not filtered_ports:
1327 1359
             raise exceptions.NoResourceException(
1328
-                "The port doesn't exist for the name {0}"
1329
-                .format(neutron_port_name))
1360
+                "The port doesn't exist for the identifier {0}"
1361
+                .format(neutron_port_identifier))
1330 1362
         neutron_port = filtered_ports[0]
1331 1363
         all_subnets = _get_subnets_by_attrs(network_id=neutron_network_id)
1332 1364
         kuryr_subnets = []
@@ -1871,7 +1903,7 @@ def ipam_release_address():
1871 1903
                     if (port['fixed_ips'][0]['subnet_id'] == tmp_subnet['id']):
1872 1904
                         app.neutron.delete_port(port['id'])
1873 1905
             elif tags and const.KURYR_EXISTING_NEUTRON_PORT in tags:
1874
-                updated_port = {'name': '', 'device_owner': '',
1906
+                updated_port = {'device_owner': '',
1875 1907
                                 'binding:host_id': ''}
1876 1908
                 if port['name'].startswith(port['device_id']):
1877 1909
                     updated_port["device_id"] = ''

+ 5
- 3
kuryr_libnetwork/port_driver/driver.py View File

@@ -115,7 +115,7 @@ class Driver(object):
115 115
         """
116 116
         raise NotImplementedError()
117 117
 
118
-    def update_port(self, port, endpoint_id, interface_mac):
118
+    def update_port(self, port, endpoint_id, interface_mac, tags=True):
119 119
         """Updates port information and performs extra driver-specific actions.
120 120
 
121 121
         It returns the updated port dictionary after the required actions
@@ -128,14 +128,16 @@ class Driver(object):
128 128
         :returns: the updated Neutron port id dictionary as returned by
129 129
                   python-neutronclient
130 130
         """
131
-        port['name'] = libnet_utils.get_neutron_port_name(endpoint_id)
132 131
         try:
133 132
             updated_port = {
134
-                'name': port['name'],
135 133
                 'device_owner': lib_const.DEVICE_OWNER,
136 134
                 'binding:host_id': lib_utils.get_hostname(),
137 135
                 'admin_state_up': True,
138 136
             }
137
+            if not tags:
138
+                # rename the port if tagging is not supported
139
+                updated_port['name'] = libnet_utils.get_neutron_port_name(
140
+                    endpoint_id)
139 141
             if not port.get('device_id'):
140 142
                 updated_port['device_id'] = endpoint_id
141 143
             if interface_mac:

+ 4
- 2
kuryr_libnetwork/tests/unit/base.py View File

@@ -218,12 +218,14 @@ class TestKuryrBase(TestCase):
218 218
                         fake_neutron_port_id, neutron_port_status,
219 219
                         fake_neutron_subnet_v4_id, fake_neutron_subnet_v6_id,
220 220
                         neutron_subnet_v4_address="192.168.1.2",
221
-                        neutron_subnet_v6_address="fe80::f816:3eff:fe20:57c4"):
221
+                        neutron_subnet_v6_address="fe80::f816:3eff:fe20:57c4",
222
+                        tags=None):
222 223
         fake_port = cls._get_fake_port(
223 224
             docker_endpoint_id, neutron_network_id,
224 225
             fake_neutron_port_id, neutron_port_status,
225 226
             fake_neutron_subnet_v4_id, fake_neutron_subnet_v6_id,
226
-            neutron_subnet_v4_address, neutron_subnet_v6_address)
227
+            neutron_subnet_v4_address, neutron_subnet_v6_address,
228
+            tags=tags)
227 229
         fake_port = fake_port['port']
228 230
         fake_ports = {
229 231
             'ports': [

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

@@ -111,7 +111,6 @@ class TestVethDriver(base.TestKuryrBase):
111 111
         mock_get_port_name.assert_called_with(fake_endpoint_id)
112 112
         expected_update_port = {
113 113
             'port': {
114
-                'name': fake_port_name,
115 114
                 'device_owner': lib_const.DEVICE_OWNER,
116 115
                 'binding:host_id': lib_utils.get_hostname(),
117 116
                 'mac_address': fake_mac_address2,
@@ -144,7 +143,6 @@ class TestVethDriver(base.TestKuryrBase):
144 143
         mock_get_port_name.assert_called_with(fake_endpoint_id)
145 144
         expected_update_port = {
146 145
             'port': {
147
-                'name': fake_port_name,
148 146
                 'device_owner': lib_const.DEVICE_OWNER,
149 147
                 'binding:host_id': lib_utils.get_hostname(),
150 148
                 'admin_state_up': True,
@@ -181,7 +179,6 @@ class TestVethDriver(base.TestKuryrBase):
181 179
         mock_get_port_name.assert_called_with(fake_endpoint_id)
182 180
         expected_update_port = {
183 181
             'port': {
184
-                'name': fake_port_name,
185 182
                 'device_owner': lib_const.DEVICE_OWNER,
186 183
                 'binding:host_id': lib_utils.get_hostname(),
187 184
                 'device_id': fake_endpoint_id,

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

@@ -300,7 +300,6 @@ class TestVlanDriver(base.TestKuryrBase):
300 300
 
301 301
         mock_update_port.assert_called_with(fake_neutron_port_id,
302 302
                 {'port': {
303
-                    'name': fake_port_name,
304 303
                     'device_owner': lib_const.DEVICE_OWNER,
305 304
                     'binding:host_id': lib_utils.get_hostname(),
306 305
                     'mac_address': fake_neutron_mac_address2,

+ 50
- 35
kuryr_libnetwork/tests/unit/test_kuryr.py View File

@@ -1481,10 +1481,11 @@ class TestKuryr(base.TestKuryrBase):
1481 1481
     @ddt.data(
1482 1482
         (False), (True))
1483 1483
     def test_network_driver_create_endpoint(self, vif_plug_is_fatal,
1484
-            mock_vif, mock_list_subnets, mock_list_ports,
1484
+            mock_app, mock_list_subnets, mock_list_ports,
1485 1485
             mock_update_port, mock_show_port, mock_list_networks,
1486 1486
             mock_create_host_iface):
1487
-        mock_vif.vif_plug_is_fatal = vif_plug_is_fatal
1487
+        mock_app.vif_plug_is_fatal = vif_plug_is_fatal
1488
+        mock_app.tag = True
1488 1489
         fake_docker_network_id = lib_utils.get_hash()
1489 1490
         fake_docker_endpoint_id = lib_utils.get_hash()
1490 1491
         fake_neutron_net_id = uuidutils.generate_uuid()
@@ -1525,7 +1526,8 @@ class TestKuryr(base.TestKuryrBase):
1525 1526
         fake_port_response = self._get_fake_port(
1526 1527
             fake_docker_endpoint_id, fake_neutron_net_id,
1527 1528
             fake_port_id, lib_const.PORT_STATUS_ACTIVE,
1528
-            subnet_v4_id)
1529
+            subnet_v4_id,
1530
+            tags=utils.create_port_tags(fake_docker_endpoint_id))
1529 1531
         fake_ports_response = {
1530 1532
             "ports": [
1531 1533
                 fake_port_response['port']
@@ -1545,7 +1547,8 @@ class TestKuryr(base.TestKuryrBase):
1545 1547
             fake_neutron_ports_response_2 = self._get_fake_port(
1546 1548
                 fake_docker_endpoint_id, fake_neutron_net_id,
1547 1549
                 fake_port_id, lib_const.PORT_STATUS_ACTIVE,
1548
-                subnet_v4_id)
1550
+                subnet_v4_id,
1551
+                tags=utils.create_port_tags(fake_docker_endpoint_id))
1549 1552
             mock_show_port.return_value = fake_neutron_ports_response_2
1550 1553
 
1551 1554
         data = {
@@ -1568,7 +1571,8 @@ class TestKuryr(base.TestKuryrBase):
1568 1571
         mock_list_ports.assert_called_with(fixed_ips=fake_fixed_ips)
1569 1572
         mock_update_port.assert_called_with(fake_port_response['port'],
1570 1573
                                             fake_docker_endpoint_id,
1571
-                                            'fa:16:3e:20:57:c3')
1574
+                                            'fa:16:3e:20:57:c3',
1575
+                                            tags=True)
1572 1576
         mock_list_networks.assert_any_call(tags=t)
1573 1577
         mock_create_host_iface.assert_called_with(fake_docker_endpoint_id,
1574 1578
             fake_updated_port, [fake_v4_subnet['subnet']],
@@ -1744,10 +1748,11 @@ class TestKuryr(base.TestKuryrBase):
1744 1748
         (False), (True))
1745 1749
     def test_network_driver_create_v4_endpoint_in_dual_net(
1746 1750
             self, vif_plug_is_fatal,
1747
-            mock_vif, mock_list_subnets, mock_list_ports, mock_delete_port,
1751
+            mock_app, mock_list_subnets, mock_list_ports, mock_delete_port,
1748 1752
             mock_update_port, mock_show_port, mock_list_networks,
1749 1753
             mock_create_host_iface):
1750
-        mock_vif.vif_plug_is_fatal = vif_plug_is_fatal
1754
+        mock_app.vif_plug_is_fatal = vif_plug_is_fatal
1755
+        mock_app.tag = True
1751 1756
         fake_docker_network_id = lib_utils.get_hash()
1752 1757
         fake_docker_endpoint_id = lib_utils.get_hash()
1753 1758
         fake_neutron_net_id = uuidutils.generate_uuid()
@@ -1799,19 +1804,22 @@ class TestKuryr(base.TestKuryrBase):
1799 1804
         fake_new_port_response = self._get_fake_port(
1800 1805
             fake_docker_endpoint_id, fake_neutron_net_id,
1801 1806
             fake_v4_port_id, lib_const.PORT_STATUS_ACTIVE,
1802
-            subnet_v4_id, neutron_mac_address=fake_mac_address)
1807
+            subnet_v4_id, neutron_mac_address=fake_mac_address,
1808
+            tags=utils.create_port_tags(fake_docker_endpoint_id))
1803 1809
 
1804 1810
         fake_v4_port_response = self._get_fake_port(
1805 1811
             "fake-name1", fake_neutron_net_id,
1806 1812
             fake_v4_port_id, lib_const.PORT_STATUS_DOWN,
1807
-            subnet_v4_id)
1813
+            subnet_v4_id,
1814
+            tags=utils.create_port_tags(fake_docker_endpoint_id))
1808 1815
 
1809 1816
         fake_v6_port_id = uuidutils.generate_uuid()
1810 1817
         fake_v6_port_response = self._get_fake_port(
1811 1818
             "fake-name2", fake_neutron_net_id,
1812 1819
             fake_v6_port_id, lib_const.PORT_STATUS_DOWN,
1813 1820
             subnet_v6_id, name=constants.KURYR_UNBOUND_PORT,
1814
-            neutron_mac_address="fa:16:3e:20:57:c4")
1821
+            neutron_mac_address="fa:16:3e:20:57:c4",
1822
+            tags=utils.create_port_tags(fake_docker_endpoint_id))
1815 1823
 
1816 1824
         fake_ports_response = {
1817 1825
             "ports": [
@@ -1832,7 +1840,8 @@ class TestKuryr(base.TestKuryrBase):
1832 1840
             fake_neutron_ports_response_2 = self._get_fake_port(
1833 1841
                 fake_docker_endpoint_id, fake_neutron_net_id,
1834 1842
                 fake_v4_port_id, lib_const.PORT_STATUS_ACTIVE,
1835
-                subnet_v4_id, subnet_v6_id)
1843
+                subnet_v4_id, subnet_v6_id,
1844
+                tags=utils.create_port_tags(fake_docker_endpoint_id))
1836 1845
             mock_show_port.return_value = fake_neutron_ports_response_2
1837 1846
 
1838 1847
         data = {
@@ -1855,7 +1864,7 @@ class TestKuryr(base.TestKuryrBase):
1855 1864
         mock_delete_port.assert_any_call(fake_v6_port_id)
1856 1865
         mock_update_port.assert_called_with(
1857 1866
             fake_v4_port_response['port'], fake_docker_endpoint_id,
1858
-            fake_mac_address)
1867
+            fake_mac_address, tags=True)
1859 1868
         mock_list_networks.assert_any_call(tags=t)
1860 1869
         mock_create_host_iface.assert_called_with(fake_docker_endpoint_id,
1861 1870
             fake_new_port_response['port'], fake_neutron_subnets,
@@ -1877,10 +1886,11 @@ class TestKuryr(base.TestKuryrBase):
1877 1886
     @ddt.data(
1878 1887
         (False), (True))
1879 1888
     def test_network_driver_create_endpoint_with_no_mac_address(self,
1880
-            vif_plug_is_fatal, mock_vif, mock_list_subnets, mock_list_ports,
1889
+            vif_plug_is_fatal, mock_app, mock_list_subnets, mock_list_ports,
1881 1890
             mock_update_port, mock_show_port, mock_list_networks,
1882 1891
             mock_create_host_iface):
1883
-        mock_vif.vif_plug_is_fatal = vif_plug_is_fatal
1892
+        mock_app.vif_plug_is_fatal = vif_plug_is_fatal
1893
+        mock_app.tag = True
1884 1894
         fake_docker_network_id = lib_utils.get_hash()
1885 1895
         fake_docker_endpoint_id = lib_utils.get_hash()
1886 1896
         fake_neutron_net_id = uuidutils.generate_uuid()
@@ -1936,7 +1946,8 @@ class TestKuryr(base.TestKuryrBase):
1936 1946
         fake_port_response = self._get_fake_port(
1937 1947
             fake_docker_endpoint_id, fake_neutron_net_id,
1938 1948
             fake_port_id, lib_const.PORT_STATUS_ACTIVE,
1939
-            subnet_v4_id, subnet_v6_id, neutron_mac_address=fake_mac_address)
1949
+            subnet_v4_id, subnet_v6_id, neutron_mac_address=fake_mac_address,
1950
+            tags=utils.create_port_tags(fake_docker_endpoint_id))
1940 1951
         fake_ports_response = {
1941 1952
             "ports": [
1942 1953
                 fake_port_response['port']
@@ -1958,7 +1969,8 @@ class TestKuryr(base.TestKuryrBase):
1958 1969
             fake_neutron_ports_response_2 = self._get_fake_port(
1959 1970
                 fake_docker_endpoint_id, fake_neutron_net_id,
1960 1971
                 fake_port_id, lib_const.PORT_STATUS_ACTIVE,
1961
-                subnet_v4_id, subnet_v6_id)
1972
+                subnet_v4_id, subnet_v6_id,
1973
+                tags=utils.create_port_tags(fake_docker_endpoint_id))
1962 1974
             mock_show_port.return_value = fake_neutron_ports_response_2
1963 1975
 
1964 1976
         data = {
@@ -1981,7 +1993,8 @@ class TestKuryr(base.TestKuryrBase):
1981 1993
             network_id=fake_neutron_net_id, cidr='fe80::/64')
1982 1994
         mock_list_ports.assert_called_with(fixed_ips=fake_fixed_ips)
1983 1995
         mock_update_port.assert_called_with(fake_port_response['port'],
1984
-                                            fake_docker_endpoint_id, '')
1996
+                                            fake_docker_endpoint_id, '',
1997
+                                            tags=True)
1985 1998
         mock_list_networks.assert_any_call(tags=t)
1986 1999
         mock_create_host_iface.assert_called_with(fake_docker_endpoint_id,
1987 2000
                                                   fake_updated_port,
@@ -2012,8 +2025,8 @@ class TestKuryr(base.TestKuryrBase):
2012 2025
             decoded_json = jsonutils.loads(response.data)
2013 2026
             self.assertEqual(200, response.status_code)
2014 2027
 
2015
-            port_name = utils.get_neutron_port_name(docker_endpoint_id)
2016
-            mock_list_ports.assert_called_once_with(name=port_name)
2028
+            port_tags = utils.make_port_tags(docker_endpoint_id)
2029
+            mock_list_ports.assert_called_once_with(tags=port_tags)
2017 2030
 
2018 2031
             self.assertEqual({}, decoded_json['Value'])
2019 2032
 
@@ -2045,18 +2058,19 @@ class TestKuryr(base.TestKuryrBase):
2045 2058
             decoded_json = jsonutils.loads(response.data)
2046 2059
             self.assertEqual(200, response.status_code)
2047 2060
 
2048
-            port_name = utils.get_neutron_port_name(docker_endpoint_id)
2049
-            mock_list_ports.assert_called_once_with(name=port_name)
2061
+            port_tags = utils.make_port_tags(docker_endpoint_id)
2062
+            mock_list_ports.assert_called_once_with(tags=port_tags)
2050 2063
 
2051 2064
             self.assertEqual(fake_port_response['ports'][0]['status'],
2052 2065
                              decoded_json['Value']['status'])
2053 2066
 
2067
+    @mock.patch('kuryr_libnetwork.controllers.app.neutron.remove_tag')
2054 2068
     @mock.patch('kuryr_libnetwork.controllers.DEFAULT_DRIVER'
2055 2069
                 '.delete_host_iface')
2056 2070
     @mock.patch('kuryr_libnetwork.controllers.app.neutron.list_ports')
2057 2071
     @mock.patch('kuryr_libnetwork.controllers.app.neutron.list_networks')
2058 2072
     def test_network_driver_delete_endpoint(self, mock_list_networks,
2059
-            mock_list_ports, mock_delete_host_iface):
2073
+            mock_list_ports, mock_delete_host_iface, mock_remove_tag):
2060 2074
         fake_docker_net_id = lib_utils.get_hash()
2061 2075
         fake_docker_endpoint_id = lib_utils.get_hash()
2062 2076
 
@@ -2069,12 +2083,12 @@ class TestKuryr(base.TestKuryrBase):
2069 2083
         fake_neutron_ports_response = self._get_fake_ports(
2070 2084
             fake_docker_endpoint_id, fake_neutron_net_id,
2071 2085
             fake_neutron_port_id, lib_const.PORT_STATUS_ACTIVE,
2072
-            fake_neutron_v4_subnet_id, fake_neutron_v6_subnet_id)
2086
+            fake_neutron_v4_subnet_id, fake_neutron_v6_subnet_id,
2087
+            tags=utils.make_port_tags(fake_docker_endpoint_id))
2073 2088
         fake_neutron_port = fake_neutron_ports_response['ports'][0]
2074 2089
 
2075 2090
         t = utils.make_net_tags(fake_docker_net_id)
2076
-        neutron_port_name = utils.get_neutron_port_name(
2077
-            fake_docker_endpoint_id)
2091
+        port_tags = utils.make_port_tags(fake_docker_endpoint_id)
2078 2092
         mock_list_networks.return_value = self._get_fake_list_network(
2079 2093
             fake_neutron_net_id)
2080 2094
         mock_list_ports.return_value = fake_neutron_ports_response
@@ -2090,7 +2104,7 @@ class TestKuryr(base.TestKuryrBase):
2090 2104
 
2091 2105
         self.assertEqual(200, response.status_code)
2092 2106
         mock_list_networks.assert_called_with(tags=t)
2093
-        mock_list_ports.assert_called_with(name=neutron_port_name)
2107
+        mock_list_ports.assert_called_with(tags=port_tags)
2094 2108
         mock_delete_host_iface.assert_called_with(fake_docker_endpoint_id,
2095 2109
             fake_neutron_port)
2096 2110
         decoded_json = jsonutils.loads(response.data)
@@ -2123,8 +2137,7 @@ class TestKuryr(base.TestKuryrBase):
2123 2137
                     fake_neutron_net_id)
2124 2138
         mock_list_networks.side_effect = mock_network
2125 2139
         fake_neutron_port_id = uuidutils.generate_uuid()
2126
-        neutron_port_name = utils.get_neutron_port_name(
2127
-            fake_docker_endpoint_id)
2140
+        port_tags = utils.make_port_tags(fake_docker_endpoint_id)
2128 2141
         fake_neutron_v4_subnet_id = uuidutils.generate_uuid()
2129 2142
         fake_neutron_v6_subnet_id = uuidutils.generate_uuid()
2130 2143
         fake_neutron_ports_response = self._get_fake_ports(
@@ -2175,7 +2188,7 @@ class TestKuryr(base.TestKuryrBase):
2175 2188
         mock_list_networks.assert_any_call(tags=t)
2176 2189
         mock_get_container_iface_name.assert_called_with(
2177 2190
             fake_neutron_ports_response['ports'][0])
2178
-        mock_list_ports.assert_called_with(name=neutron_port_name)
2191
+        mock_list_ports.assert_called_with(tags=port_tags)
2179 2192
         mock_list_subnets.assert_called_with(network_id=fake_neutron_net_id)
2180 2193
 
2181 2194
         self.assertEqual(expected_response, decoded_json)
@@ -2211,8 +2224,7 @@ class TestKuryr(base.TestKuryrBase):
2211 2224
         mock_list_networks.side_effect = mock_network
2212 2225
         fake_neutron_port_id = uuidutils.generate_uuid()
2213 2226
         fake_neutron_subnetpool_id = uuidutils.generate_uuid()
2214
-        neutron_port_name = utils.get_neutron_port_name(
2215
-            fake_docker_endpoint_id)
2227
+        port_tags = utils.make_port_tags(fake_docker_endpoint_id)
2216 2228
         fake_neutron_v4_subnet_id = uuidutils.generate_uuid()
2217 2229
         fake_neutron_v4_subnet_id_2 = uuidutils.generate_uuid()
2218 2230
         fake_neutron_v6_subnet_id = uuidutils.generate_uuid()
@@ -2293,7 +2305,7 @@ class TestKuryr(base.TestKuryrBase):
2293 2305
         mock_list_networks.assert_any_call(tags=t)
2294 2306
         mock_get_container_iface_name.assert_called_with(
2295 2307
             fake_neutron_ports_response['ports'][0])
2296
-        mock_list_ports.assert_called_with(name=neutron_port_name)
2308
+        mock_list_ports.assert_called_with(tags=port_tags)
2297 2309
         mock_list_subnets.assert_called_with(network_id=fake_neutron_net_id)
2298 2310
 
2299 2311
         self.assertEqual(expected_response, decoded_json)
@@ -2405,9 +2417,12 @@ class TestKuryr(base.TestKuryrBase):
2405 2417
 
2406 2418
         mock_get_container_iface_name.assert_called_with(
2407 2419
             fake_neutron_ports_response['ports'][0])
2408
-        neutron_port_name = utils.get_neutron_port_name(
2409
-            fake_docker_endpoint_id)
2410
-        mock_list_ports.assert_called_with(name=neutron_port_name)
2420
+        if mock_app.tag:
2421
+            port_tags = utils.make_port_tags(fake_docker_endpoint_id)
2422
+            mock_list_ports.assert_called_with(tags=port_tags)
2423
+        else:
2424
+            port_name = utils.get_neutron_port_name(fake_docker_endpoint_id)
2425
+            mock_list_ports.assert_called_once_with(name=port_name)
2411 2426
         mock_list_subnets.assert_called_with(network_id=fake_neutron_net_id)
2412 2427
         self.assertEqual(expected_response, decoded_json)
2413 2428
 

+ 6
- 5
kuryr_libnetwork/tests/unit/test_kuryr_endpoint.py View File

@@ -180,7 +180,8 @@ class TestKuryrEndpointCreateFailures(base.TestKuryrFailures):
180 180
         fake_port_response = self._get_fake_port(
181 181
             fake_docker_endpoint_id, fake_neutron_network_id,
182 182
             fake_neutron_port_id, lib_const.PORT_STATUS_ACTIVE,
183
-            fake_neutron_v4_subnet_id, fake_neutron_v6_subnet_id)
183
+            fake_neutron_v4_subnet_id, fake_neutron_v6_subnet_id,
184
+            tags=utils.create_port_tags(fake_docker_endpoint_id))
184 185
         fake_ports_response = {
185 186
             "ports": [
186 187
                 fake_port_response['port']
@@ -215,7 +216,8 @@ class TestKuryrEndpointCreateFailures(base.TestKuryrFailures):
215 216
         mock_list_ports.assert_called_with(fixed_ips=fake_fixed_ips)
216 217
         mock_update_port.assert_called_with(fake_port_response['port'],
217 218
                                             fake_docker_endpoint_id,
218
-                                            "fa:16:3e:20:57:c3")
219
+                                            "fa:16:3e:20:57:c3",
220
+                                            tags=True)
219 221
         mock_create_host_iface.assert_called_with(
220 222
             fake_docker_endpoint_id, fake_updated_port, fake_neutron_subnets,
221 223
             fake_neutron_network['networks'][0])
@@ -270,8 +272,7 @@ class TestKuryrEndpointDeleteFailures(base.TestKuryrFailures):
270 272
         t = utils.make_net_tags(fake_docker_network_id)
271 273
         mock_list_networks.return_value = self._get_fake_list_network(
272 274
             fake_neutron_network_id)
273
-        neutron_port_name = utils.get_neutron_port_name(
274
-            fake_docker_endpoint_id)
275
+        port_tags = utils.make_port_tags(fake_docker_endpoint_id)
275 276
         fake_neutron_ports_response = self._get_fake_ports(
276 277
             fake_docker_endpoint_id, fake_neutron_network_id,
277 278
             fake_neutron_port_id, lib_const.PORT_STATUS_ACTIVE,
@@ -291,7 +292,7 @@ class TestKuryrEndpointDeleteFailures(base.TestKuryrFailures):
291 292
         self.assertEqual(
292 293
             w_exceptions.InternalServerError.code, response.status_code)
293 294
         mock_list_networks.assert_called_with(tags=t)
294
-        mock_list_ports.assert_called_with(name=neutron_port_name)
295
+        mock_list_ports.assert_called_with(tags=port_tags)
295 296
         mock_delete_host_iface.assert_called_with(fake_docker_endpoint_id,
296 297
             fake_neutron_port)
297 298
         decoded_json = jsonutils.loads(response.data)

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

@@ -1540,7 +1540,7 @@ class TestKuryrIpam(base.TestKuryrBase):
1540 1540
         mock_list_subnets.assert_called_with(
1541 1541
             subnetpool_id=fake_kuryr_subnetpool_id)
1542 1542
         mock_list_ports.assert_called()
1543
-        expect_updated_port = {'name': '', 'device_owner': '',
1543
+        expect_updated_port = {'device_owner': '',
1544 1544
                                'device_id': '', 'binding:host_id': ''}
1545 1545
         mock_update_port.assert_called_with(fake_port['port']['id'],
1546 1546
                                             {'port': expect_updated_port})
@@ -1706,7 +1706,7 @@ class TestKuryrIpam(base.TestKuryrBase):
1706 1706
         mock_list_subnets.assert_called_with(
1707 1707
             subnetpool_id=fake_kuryr_subnetpool_id)
1708 1708
         mock_list_ports.assert_called()
1709
-        expect_updated_port = {'name': '', 'device_owner': '',
1709
+        expect_updated_port = {'device_owner': '',
1710 1710
                                'device_id': '', 'binding:host_id': ''}
1711 1711
         mock_update_port.assert_called_once_with(fake_port['port']['id'],
1712 1712
                                             {'port': expect_updated_port})

+ 14
- 0
kuryr_libnetwork/utils.py View File

@@ -130,6 +130,20 @@ def make_subnet_name(pool_cidr):
130 130
     return const.SUBNET_NAME_PREFIX + pool_cidr
131 131
 
132 132
 
133
+def create_port_tags(tag):
134
+    tags = []
135
+    tags.append(const.NEUTRON_ID_LH_OPTION + ':' + tag[:32])
136
+    if len(tag) > 32:
137
+        tags.append(const.NEUTRON_ID_UH_OPTION + ':' + tag[32:64])
138
+
139
+    return tags
140
+
141
+
142
+def make_port_tags(tag):
143
+    tags = create_port_tags(tag)
144
+    return ','.join(map(str, tags))
145
+
146
+
133 147
 def wait_for_port_active(neutron_client, neutron_port_id, vif_plug_timeout):
134 148
     port_active = False
135 149
     tries = 0

Loading…
Cancel
Save