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
This commit is contained in:
parent
b194b0732f
commit
a9a70b3178
|
@ -225,8 +225,8 @@ def _get_neutron_port_from_docker_endpoint(endpoint_id):
|
|||
|
||||
def _get_neutron_port_status_from_docker_endpoint(endpoint_id):
|
||||
response_port_status = {}
|
||||
port_name = utils.get_neutron_port_name(endpoint_id)
|
||||
filtered_ports = _get_ports_by_attrs(name=port_name)
|
||||
neutron_port_identifier = _make_port_identifier(endpoint_id)
|
||||
filtered_ports = _get_ports_by_identifier(neutron_port_identifier)
|
||||
if filtered_ports:
|
||||
response_port_status['status'] = filtered_ports[0]['status']
|
||||
return response_port_status
|
||||
|
@ -313,7 +313,9 @@ def _create_or_update_port(neutron_network_id, endpoint_id,
|
|||
port = filtered_ports['ports'][0]
|
||||
port_driver = get_driver(port)
|
||||
response_port = port_driver.update_port(port, endpoint_id,
|
||||
interface_mac)
|
||||
interface_mac,
|
||||
tags=app.tag)
|
||||
_neutron_port_add_tags(port, endpoint_id)
|
||||
# For the container boot from dual-net, request_address will
|
||||
# create two ports(v4 and v6 address), we should only allow one
|
||||
# for port bind.
|
||||
|
@ -333,7 +335,9 @@ def _create_or_update_port(neutron_network_id, endpoint_id,
|
|||
else:
|
||||
port_driver = get_driver(port)
|
||||
response_port = port_driver.update_port(port, endpoint_id,
|
||||
interface_mac)
|
||||
interface_mac,
|
||||
tags=app.tag)
|
||||
_neutron_port_add_tags(port, endpoint_id)
|
||||
if not response_port:
|
||||
fixed_ips = (
|
||||
lib_utils.get_dict_format_fixed_ips_from_kv_format(fixed_ips))
|
||||
|
@ -388,10 +392,24 @@ def _neutron_port_add_tag(port, tag):
|
|||
_neutron_add_tag('ports', port, tag)
|
||||
|
||||
|
||||
def _neutron_port_add_tags(port, tag):
|
||||
if app.tag:
|
||||
tags = utils.create_port_tags(tag)
|
||||
for tag in tags:
|
||||
_neutron_port_add_tag(port, tag)
|
||||
|
||||
|
||||
def _neutron_port_remove_tag(port, tag):
|
||||
_neutron_remove_tag('ports', port, tag)
|
||||
|
||||
|
||||
def _neutron_port_remove_tags(port, tag):
|
||||
if app.tag:
|
||||
tags = utils.create_port_tags(tag)
|
||||
for tag in tags:
|
||||
_neutron_port_remove_tag(port, tag)
|
||||
|
||||
|
||||
def _neutron_add_tag(resource_type, resource, tag):
|
||||
if tag not in resource['tags']:
|
||||
try:
|
||||
|
@ -419,6 +437,18 @@ def _get_networks_by_identifier(identifier):
|
|||
return _get_networks_by_attrs(name=identifier)
|
||||
|
||||
|
||||
def _make_port_identifier(endpoint_id):
|
||||
if app.tag:
|
||||
return utils.make_port_tags(endpoint_id)
|
||||
return utils.get_neutron_port_name(endpoint_id)
|
||||
|
||||
|
||||
def _get_ports_by_identifier(identifier):
|
||||
if app.tag:
|
||||
return _get_ports_by_attrs(tags=identifier)
|
||||
return _get_ports_by_attrs(name=identifier)
|
||||
|
||||
|
||||
def _program_expose_ports(options, port_id):
|
||||
exposed_ports = options.get(const.DOCKER_EXPOSED_PORTS_OPTION)
|
||||
if not exposed_ports:
|
||||
|
@ -1237,12 +1267,12 @@ def network_driver_delete_endpoint():
|
|||
.format(neutron_network_identifier)
|
||||
})
|
||||
else:
|
||||
neutron_port_name = utils.get_neutron_port_name(endpoint_id)
|
||||
filtered_ports = _get_ports_by_attrs(name=neutron_port_name)
|
||||
neutron_port_identifier = _make_port_identifier(endpoint_id)
|
||||
filtered_ports = _get_ports_by_identifier(neutron_port_identifier)
|
||||
if not filtered_ports:
|
||||
raise exceptions.NoResourceException(
|
||||
"The port doesn't exist for the name {0}"
|
||||
.format(neutron_port_name))
|
||||
"The port doesn't exist for the identifier {0}"
|
||||
.format(neutron_port_identifier))
|
||||
neutron_port = filtered_ports[0]
|
||||
|
||||
try:
|
||||
|
@ -1264,6 +1294,8 @@ def network_driver_delete_endpoint():
|
|||
with excutils.save_and_reraise_exception():
|
||||
LOG.error('Error while removing the interface: %s', ex)
|
||||
|
||||
_neutron_port_remove_tags(neutron_port, endpoint_id)
|
||||
|
||||
return flask.jsonify(const.SCHEMA['SUCCESS'])
|
||||
|
||||
|
||||
|
@ -1321,12 +1353,12 @@ def network_driver_join():
|
|||
else:
|
||||
neutron_network_id = filtered_networks[0]['id']
|
||||
|
||||
neutron_port_name = utils.get_neutron_port_name(endpoint_id)
|
||||
filtered_ports = _get_ports_by_attrs(name=neutron_port_name)
|
||||
neutron_port_identifier = _make_port_identifier(endpoint_id)
|
||||
filtered_ports = _get_ports_by_identifier(neutron_port_identifier)
|
||||
if not filtered_ports:
|
||||
raise exceptions.NoResourceException(
|
||||
"The port doesn't exist for the name {0}"
|
||||
.format(neutron_port_name))
|
||||
"The port doesn't exist for the identifier {0}"
|
||||
.format(neutron_port_identifier))
|
||||
neutron_port = filtered_ports[0]
|
||||
all_subnets = _get_subnets_by_attrs(network_id=neutron_network_id)
|
||||
kuryr_subnets = []
|
||||
|
@ -1871,7 +1903,7 @@ def ipam_release_address():
|
|||
if (port['fixed_ips'][0]['subnet_id'] == tmp_subnet['id']):
|
||||
app.neutron.delete_port(port['id'])
|
||||
elif tags and const.KURYR_EXISTING_NEUTRON_PORT in tags:
|
||||
updated_port = {'name': '', 'device_owner': '',
|
||||
updated_port = {'device_owner': '',
|
||||
'binding:host_id': ''}
|
||||
if port['name'].startswith(port['device_id']):
|
||||
updated_port["device_id"] = ''
|
||||
|
|
|
@ -115,7 +115,7 @@ class Driver(object):
|
|||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def update_port(self, port, endpoint_id, interface_mac):
|
||||
def update_port(self, port, endpoint_id, interface_mac, tags=True):
|
||||
"""Updates port information and performs extra driver-specific actions.
|
||||
|
||||
It returns the updated port dictionary after the required actions
|
||||
|
@ -128,14 +128,16 @@ class Driver(object):
|
|||
:returns: the updated Neutron port id dictionary as returned by
|
||||
python-neutronclient
|
||||
"""
|
||||
port['name'] = libnet_utils.get_neutron_port_name(endpoint_id)
|
||||
try:
|
||||
updated_port = {
|
||||
'name': port['name'],
|
||||
'device_owner': lib_const.DEVICE_OWNER,
|
||||
'binding:host_id': lib_utils.get_hostname(),
|
||||
'admin_state_up': True,
|
||||
}
|
||||
if not tags:
|
||||
# rename the port if tagging is not supported
|
||||
updated_port['name'] = libnet_utils.get_neutron_port_name(
|
||||
endpoint_id)
|
||||
if not port.get('device_id'):
|
||||
updated_port['device_id'] = endpoint_id
|
||||
if interface_mac:
|
||||
|
|
|
@ -218,12 +218,14 @@ class TestKuryrBase(TestCase):
|
|||
fake_neutron_port_id, neutron_port_status,
|
||||
fake_neutron_subnet_v4_id, fake_neutron_subnet_v6_id,
|
||||
neutron_subnet_v4_address="192.168.1.2",
|
||||
neutron_subnet_v6_address="fe80::f816:3eff:fe20:57c4"):
|
||||
neutron_subnet_v6_address="fe80::f816:3eff:fe20:57c4",
|
||||
tags=None):
|
||||
fake_port = cls._get_fake_port(
|
||||
docker_endpoint_id, neutron_network_id,
|
||||
fake_neutron_port_id, neutron_port_status,
|
||||
fake_neutron_subnet_v4_id, fake_neutron_subnet_v6_id,
|
||||
neutron_subnet_v4_address, neutron_subnet_v6_address)
|
||||
neutron_subnet_v4_address, neutron_subnet_v6_address,
|
||||
tags=tags)
|
||||
fake_port = fake_port['port']
|
||||
fake_ports = {
|
||||
'ports': [
|
||||
|
|
|
@ -111,7 +111,6 @@ class TestVethDriver(base.TestKuryrBase):
|
|||
mock_get_port_name.assert_called_with(fake_endpoint_id)
|
||||
expected_update_port = {
|
||||
'port': {
|
||||
'name': fake_port_name,
|
||||
'device_owner': lib_const.DEVICE_OWNER,
|
||||
'binding:host_id': lib_utils.get_hostname(),
|
||||
'mac_address': fake_mac_address2,
|
||||
|
@ -144,7 +143,6 @@ class TestVethDriver(base.TestKuryrBase):
|
|||
mock_get_port_name.assert_called_with(fake_endpoint_id)
|
||||
expected_update_port = {
|
||||
'port': {
|
||||
'name': fake_port_name,
|
||||
'device_owner': lib_const.DEVICE_OWNER,
|
||||
'binding:host_id': lib_utils.get_hostname(),
|
||||
'admin_state_up': True,
|
||||
|
@ -181,7 +179,6 @@ class TestVethDriver(base.TestKuryrBase):
|
|||
mock_get_port_name.assert_called_with(fake_endpoint_id)
|
||||
expected_update_port = {
|
||||
'port': {
|
||||
'name': fake_port_name,
|
||||
'device_owner': lib_const.DEVICE_OWNER,
|
||||
'binding:host_id': lib_utils.get_hostname(),
|
||||
'device_id': fake_endpoint_id,
|
||||
|
|
|
@ -300,7 +300,6 @@ class TestVlanDriver(base.TestKuryrBase):
|
|||
|
||||
mock_update_port.assert_called_with(fake_neutron_port_id,
|
||||
{'port': {
|
||||
'name': fake_port_name,
|
||||
'device_owner': lib_const.DEVICE_OWNER,
|
||||
'binding:host_id': lib_utils.get_hostname(),
|
||||
'mac_address': fake_neutron_mac_address2,
|
||||
|
|
|
@ -1481,10 +1481,11 @@ class TestKuryr(base.TestKuryrBase):
|
|||
@ddt.data(
|
||||
(False), (True))
|
||||
def test_network_driver_create_endpoint(self, vif_plug_is_fatal,
|
||||
mock_vif, mock_list_subnets, mock_list_ports,
|
||||
mock_app, mock_list_subnets, mock_list_ports,
|
||||
mock_update_port, mock_show_port, mock_list_networks,
|
||||
mock_create_host_iface):
|
||||
mock_vif.vif_plug_is_fatal = vif_plug_is_fatal
|
||||
mock_app.vif_plug_is_fatal = vif_plug_is_fatal
|
||||
mock_app.tag = True
|
||||
fake_docker_network_id = lib_utils.get_hash()
|
||||
fake_docker_endpoint_id = lib_utils.get_hash()
|
||||
fake_neutron_net_id = uuidutils.generate_uuid()
|
||||
|
@ -1525,7 +1526,8 @@ class TestKuryr(base.TestKuryrBase):
|
|||
fake_port_response = self._get_fake_port(
|
||||
fake_docker_endpoint_id, fake_neutron_net_id,
|
||||
fake_port_id, lib_const.PORT_STATUS_ACTIVE,
|
||||
subnet_v4_id)
|
||||
subnet_v4_id,
|
||||
tags=utils.create_port_tags(fake_docker_endpoint_id))
|
||||
fake_ports_response = {
|
||||
"ports": [
|
||||
fake_port_response['port']
|
||||
|
@ -1545,7 +1547,8 @@ class TestKuryr(base.TestKuryrBase):
|
|||
fake_neutron_ports_response_2 = self._get_fake_port(
|
||||
fake_docker_endpoint_id, fake_neutron_net_id,
|
||||
fake_port_id, lib_const.PORT_STATUS_ACTIVE,
|
||||
subnet_v4_id)
|
||||
subnet_v4_id,
|
||||
tags=utils.create_port_tags(fake_docker_endpoint_id))
|
||||
mock_show_port.return_value = fake_neutron_ports_response_2
|
||||
|
||||
data = {
|
||||
|
@ -1568,7 +1571,8 @@ class TestKuryr(base.TestKuryrBase):
|
|||
mock_list_ports.assert_called_with(fixed_ips=fake_fixed_ips)
|
||||
mock_update_port.assert_called_with(fake_port_response['port'],
|
||||
fake_docker_endpoint_id,
|
||||
'fa:16:3e:20:57:c3')
|
||||
'fa:16:3e:20:57:c3',
|
||||
tags=True)
|
||||
mock_list_networks.assert_any_call(tags=t)
|
||||
mock_create_host_iface.assert_called_with(fake_docker_endpoint_id,
|
||||
fake_updated_port, [fake_v4_subnet['subnet']],
|
||||
|
@ -1744,10 +1748,11 @@ class TestKuryr(base.TestKuryrBase):
|
|||
(False), (True))
|
||||
def test_network_driver_create_v4_endpoint_in_dual_net(
|
||||
self, vif_plug_is_fatal,
|
||||
mock_vif, mock_list_subnets, mock_list_ports, mock_delete_port,
|
||||
mock_app, mock_list_subnets, mock_list_ports, mock_delete_port,
|
||||
mock_update_port, mock_show_port, mock_list_networks,
|
||||
mock_create_host_iface):
|
||||
mock_vif.vif_plug_is_fatal = vif_plug_is_fatal
|
||||
mock_app.vif_plug_is_fatal = vif_plug_is_fatal
|
||||
mock_app.tag = True
|
||||
fake_docker_network_id = lib_utils.get_hash()
|
||||
fake_docker_endpoint_id = lib_utils.get_hash()
|
||||
fake_neutron_net_id = uuidutils.generate_uuid()
|
||||
|
@ -1799,19 +1804,22 @@ class TestKuryr(base.TestKuryrBase):
|
|||
fake_new_port_response = self._get_fake_port(
|
||||
fake_docker_endpoint_id, fake_neutron_net_id,
|
||||
fake_v4_port_id, lib_const.PORT_STATUS_ACTIVE,
|
||||
subnet_v4_id, neutron_mac_address=fake_mac_address)
|
||||
subnet_v4_id, neutron_mac_address=fake_mac_address,
|
||||
tags=utils.create_port_tags(fake_docker_endpoint_id))
|
||||
|
||||
fake_v4_port_response = self._get_fake_port(
|
||||
"fake-name1", fake_neutron_net_id,
|
||||
fake_v4_port_id, lib_const.PORT_STATUS_DOWN,
|
||||
subnet_v4_id)
|
||||
subnet_v4_id,
|
||||
tags=utils.create_port_tags(fake_docker_endpoint_id))
|
||||
|
||||
fake_v6_port_id = uuidutils.generate_uuid()
|
||||
fake_v6_port_response = self._get_fake_port(
|
||||
"fake-name2", fake_neutron_net_id,
|
||||
fake_v6_port_id, lib_const.PORT_STATUS_DOWN,
|
||||
subnet_v6_id, name=constants.KURYR_UNBOUND_PORT,
|
||||
neutron_mac_address="fa:16:3e:20:57:c4")
|
||||
neutron_mac_address="fa:16:3e:20:57:c4",
|
||||
tags=utils.create_port_tags(fake_docker_endpoint_id))
|
||||
|
||||
fake_ports_response = {
|
||||
"ports": [
|
||||
|
@ -1832,7 +1840,8 @@ class TestKuryr(base.TestKuryrBase):
|
|||
fake_neutron_ports_response_2 = self._get_fake_port(
|
||||
fake_docker_endpoint_id, fake_neutron_net_id,
|
||||
fake_v4_port_id, lib_const.PORT_STATUS_ACTIVE,
|
||||
subnet_v4_id, subnet_v6_id)
|
||||
subnet_v4_id, subnet_v6_id,
|
||||
tags=utils.create_port_tags(fake_docker_endpoint_id))
|
||||
mock_show_port.return_value = fake_neutron_ports_response_2
|
||||
|
||||
data = {
|
||||
|
@ -1855,7 +1864,7 @@ class TestKuryr(base.TestKuryrBase):
|
|||
mock_delete_port.assert_any_call(fake_v6_port_id)
|
||||
mock_update_port.assert_called_with(
|
||||
fake_v4_port_response['port'], fake_docker_endpoint_id,
|
||||
fake_mac_address)
|
||||
fake_mac_address, tags=True)
|
||||
mock_list_networks.assert_any_call(tags=t)
|
||||
mock_create_host_iface.assert_called_with(fake_docker_endpoint_id,
|
||||
fake_new_port_response['port'], fake_neutron_subnets,
|
||||
|
@ -1877,10 +1886,11 @@ class TestKuryr(base.TestKuryrBase):
|
|||
@ddt.data(
|
||||
(False), (True))
|
||||
def test_network_driver_create_endpoint_with_no_mac_address(self,
|
||||
vif_plug_is_fatal, mock_vif, mock_list_subnets, mock_list_ports,
|
||||
vif_plug_is_fatal, mock_app, mock_list_subnets, mock_list_ports,
|
||||
mock_update_port, mock_show_port, mock_list_networks,
|
||||
mock_create_host_iface):
|
||||
mock_vif.vif_plug_is_fatal = vif_plug_is_fatal
|
||||
mock_app.vif_plug_is_fatal = vif_plug_is_fatal
|
||||
mock_app.tag = True
|
||||
fake_docker_network_id = lib_utils.get_hash()
|
||||
fake_docker_endpoint_id = lib_utils.get_hash()
|
||||
fake_neutron_net_id = uuidutils.generate_uuid()
|
||||
|
@ -1936,7 +1946,8 @@ class TestKuryr(base.TestKuryrBase):
|
|||
fake_port_response = self._get_fake_port(
|
||||
fake_docker_endpoint_id, fake_neutron_net_id,
|
||||
fake_port_id, lib_const.PORT_STATUS_ACTIVE,
|
||||
subnet_v4_id, subnet_v6_id, neutron_mac_address=fake_mac_address)
|
||||
subnet_v4_id, subnet_v6_id, neutron_mac_address=fake_mac_address,
|
||||
tags=utils.create_port_tags(fake_docker_endpoint_id))
|
||||
fake_ports_response = {
|
||||
"ports": [
|
||||
fake_port_response['port']
|
||||
|
@ -1958,7 +1969,8 @@ class TestKuryr(base.TestKuryrBase):
|
|||
fake_neutron_ports_response_2 = self._get_fake_port(
|
||||
fake_docker_endpoint_id, fake_neutron_net_id,
|
||||
fake_port_id, lib_const.PORT_STATUS_ACTIVE,
|
||||
subnet_v4_id, subnet_v6_id)
|
||||
subnet_v4_id, subnet_v6_id,
|
||||
tags=utils.create_port_tags(fake_docker_endpoint_id))
|
||||
mock_show_port.return_value = fake_neutron_ports_response_2
|
||||
|
||||
data = {
|
||||
|
@ -1981,7 +1993,8 @@ class TestKuryr(base.TestKuryrBase):
|
|||
network_id=fake_neutron_net_id, cidr='fe80::/64')
|
||||
mock_list_ports.assert_called_with(fixed_ips=fake_fixed_ips)
|
||||
mock_update_port.assert_called_with(fake_port_response['port'],
|
||||
fake_docker_endpoint_id, '')
|
||||
fake_docker_endpoint_id, '',
|
||||
tags=True)
|
||||
mock_list_networks.assert_any_call(tags=t)
|
||||
mock_create_host_iface.assert_called_with(fake_docker_endpoint_id,
|
||||
fake_updated_port,
|
||||
|
@ -2012,8 +2025,8 @@ class TestKuryr(base.TestKuryrBase):
|
|||
decoded_json = jsonutils.loads(response.data)
|
||||
self.assertEqual(200, response.status_code)
|
||||
|
||||
port_name = utils.get_neutron_port_name(docker_endpoint_id)
|
||||
mock_list_ports.assert_called_once_with(name=port_name)
|
||||
port_tags = utils.make_port_tags(docker_endpoint_id)
|
||||
mock_list_ports.assert_called_once_with(tags=port_tags)
|
||||
|
||||
self.assertEqual({}, decoded_json['Value'])
|
||||
|
||||
|
@ -2045,18 +2058,19 @@ class TestKuryr(base.TestKuryrBase):
|
|||
decoded_json = jsonutils.loads(response.data)
|
||||
self.assertEqual(200, response.status_code)
|
||||
|
||||
port_name = utils.get_neutron_port_name(docker_endpoint_id)
|
||||
mock_list_ports.assert_called_once_with(name=port_name)
|
||||
port_tags = utils.make_port_tags(docker_endpoint_id)
|
||||
mock_list_ports.assert_called_once_with(tags=port_tags)
|
||||
|
||||
self.assertEqual(fake_port_response['ports'][0]['status'],
|
||||
decoded_json['Value']['status'])
|
||||
|
||||
@mock.patch('kuryr_libnetwork.controllers.app.neutron.remove_tag')
|
||||
@mock.patch('kuryr_libnetwork.controllers.DEFAULT_DRIVER'
|
||||
'.delete_host_iface')
|
||||
@mock.patch('kuryr_libnetwork.controllers.app.neutron.list_ports')
|
||||
@mock.patch('kuryr_libnetwork.controllers.app.neutron.list_networks')
|
||||
def test_network_driver_delete_endpoint(self, mock_list_networks,
|
||||
mock_list_ports, mock_delete_host_iface):
|
||||
mock_list_ports, mock_delete_host_iface, mock_remove_tag):
|
||||
fake_docker_net_id = lib_utils.get_hash()
|
||||
fake_docker_endpoint_id = lib_utils.get_hash()
|
||||
|
||||
|
@ -2069,12 +2083,12 @@ class TestKuryr(base.TestKuryrBase):
|
|||
fake_neutron_ports_response = self._get_fake_ports(
|
||||
fake_docker_endpoint_id, fake_neutron_net_id,
|
||||
fake_neutron_port_id, lib_const.PORT_STATUS_ACTIVE,
|
||||
fake_neutron_v4_subnet_id, fake_neutron_v6_subnet_id)
|
||||
fake_neutron_v4_subnet_id, fake_neutron_v6_subnet_id,
|
||||
tags=utils.make_port_tags(fake_docker_endpoint_id))
|
||||
fake_neutron_port = fake_neutron_ports_response['ports'][0]
|
||||
|
||||
t = utils.make_net_tags(fake_docker_net_id)
|
||||
neutron_port_name = utils.get_neutron_port_name(
|
||||
fake_docker_endpoint_id)
|
||||
port_tags = utils.make_port_tags(fake_docker_endpoint_id)
|
||||
mock_list_networks.return_value = self._get_fake_list_network(
|
||||
fake_neutron_net_id)
|
||||
mock_list_ports.return_value = fake_neutron_ports_response
|
||||
|
@ -2090,7 +2104,7 @@ class TestKuryr(base.TestKuryrBase):
|
|||
|
||||
self.assertEqual(200, response.status_code)
|
||||
mock_list_networks.assert_called_with(tags=t)
|
||||
mock_list_ports.assert_called_with(name=neutron_port_name)
|
||||
mock_list_ports.assert_called_with(tags=port_tags)
|
||||
mock_delete_host_iface.assert_called_with(fake_docker_endpoint_id,
|
||||
fake_neutron_port)
|
||||
decoded_json = jsonutils.loads(response.data)
|
||||
|
@ -2123,8 +2137,7 @@ class TestKuryr(base.TestKuryrBase):
|
|||
fake_neutron_net_id)
|
||||
mock_list_networks.side_effect = mock_network
|
||||
fake_neutron_port_id = uuidutils.generate_uuid()
|
||||
neutron_port_name = utils.get_neutron_port_name(
|
||||
fake_docker_endpoint_id)
|
||||
port_tags = utils.make_port_tags(fake_docker_endpoint_id)
|
||||
fake_neutron_v4_subnet_id = uuidutils.generate_uuid()
|
||||
fake_neutron_v6_subnet_id = uuidutils.generate_uuid()
|
||||
fake_neutron_ports_response = self._get_fake_ports(
|
||||
|
@ -2175,7 +2188,7 @@ class TestKuryr(base.TestKuryrBase):
|
|||
mock_list_networks.assert_any_call(tags=t)
|
||||
mock_get_container_iface_name.assert_called_with(
|
||||
fake_neutron_ports_response['ports'][0])
|
||||
mock_list_ports.assert_called_with(name=neutron_port_name)
|
||||
mock_list_ports.assert_called_with(tags=port_tags)
|
||||
mock_list_subnets.assert_called_with(network_id=fake_neutron_net_id)
|
||||
|
||||
self.assertEqual(expected_response, decoded_json)
|
||||
|
@ -2211,8 +2224,7 @@ class TestKuryr(base.TestKuryrBase):
|
|||
mock_list_networks.side_effect = mock_network
|
||||
fake_neutron_port_id = uuidutils.generate_uuid()
|
||||
fake_neutron_subnetpool_id = uuidutils.generate_uuid()
|
||||
neutron_port_name = utils.get_neutron_port_name(
|
||||
fake_docker_endpoint_id)
|
||||
port_tags = utils.make_port_tags(fake_docker_endpoint_id)
|
||||
fake_neutron_v4_subnet_id = uuidutils.generate_uuid()
|
||||
fake_neutron_v4_subnet_id_2 = uuidutils.generate_uuid()
|
||||
fake_neutron_v6_subnet_id = uuidutils.generate_uuid()
|
||||
|
@ -2293,7 +2305,7 @@ class TestKuryr(base.TestKuryrBase):
|
|||
mock_list_networks.assert_any_call(tags=t)
|
||||
mock_get_container_iface_name.assert_called_with(
|
||||
fake_neutron_ports_response['ports'][0])
|
||||
mock_list_ports.assert_called_with(name=neutron_port_name)
|
||||
mock_list_ports.assert_called_with(tags=port_tags)
|
||||
mock_list_subnets.assert_called_with(network_id=fake_neutron_net_id)
|
||||
|
||||
self.assertEqual(expected_response, decoded_json)
|
||||
|
@ -2405,9 +2417,12 @@ class TestKuryr(base.TestKuryrBase):
|
|||
|
||||
mock_get_container_iface_name.assert_called_with(
|
||||
fake_neutron_ports_response['ports'][0])
|
||||
neutron_port_name = utils.get_neutron_port_name(
|
||||
fake_docker_endpoint_id)
|
||||
mock_list_ports.assert_called_with(name=neutron_port_name)
|
||||
if mock_app.tag:
|
||||
port_tags = utils.make_port_tags(fake_docker_endpoint_id)
|
||||
mock_list_ports.assert_called_with(tags=port_tags)
|
||||
else:
|
||||
port_name = utils.get_neutron_port_name(fake_docker_endpoint_id)
|
||||
mock_list_ports.assert_called_once_with(name=port_name)
|
||||
mock_list_subnets.assert_called_with(network_id=fake_neutron_net_id)
|
||||
self.assertEqual(expected_response, decoded_json)
|
||||
|
||||
|
|
|
@ -180,7 +180,8 @@ class TestKuryrEndpointCreateFailures(base.TestKuryrFailures):
|
|||
fake_port_response = self._get_fake_port(
|
||||
fake_docker_endpoint_id, fake_neutron_network_id,
|
||||
fake_neutron_port_id, lib_const.PORT_STATUS_ACTIVE,
|
||||
fake_neutron_v4_subnet_id, fake_neutron_v6_subnet_id)
|
||||
fake_neutron_v4_subnet_id, fake_neutron_v6_subnet_id,
|
||||
tags=utils.create_port_tags(fake_docker_endpoint_id))
|
||||
fake_ports_response = {
|
||||
"ports": [
|
||||
fake_port_response['port']
|
||||
|
@ -215,7 +216,8 @@ class TestKuryrEndpointCreateFailures(base.TestKuryrFailures):
|
|||
mock_list_ports.assert_called_with(fixed_ips=fake_fixed_ips)
|
||||
mock_update_port.assert_called_with(fake_port_response['port'],
|
||||
fake_docker_endpoint_id,
|
||||
"fa:16:3e:20:57:c3")
|
||||
"fa:16:3e:20:57:c3",
|
||||
tags=True)
|
||||
mock_create_host_iface.assert_called_with(
|
||||
fake_docker_endpoint_id, fake_updated_port, fake_neutron_subnets,
|
||||
fake_neutron_network['networks'][0])
|
||||
|
@ -270,8 +272,7 @@ class TestKuryrEndpointDeleteFailures(base.TestKuryrFailures):
|
|||
t = utils.make_net_tags(fake_docker_network_id)
|
||||
mock_list_networks.return_value = self._get_fake_list_network(
|
||||
fake_neutron_network_id)
|
||||
neutron_port_name = utils.get_neutron_port_name(
|
||||
fake_docker_endpoint_id)
|
||||
port_tags = utils.make_port_tags(fake_docker_endpoint_id)
|
||||
fake_neutron_ports_response = self._get_fake_ports(
|
||||
fake_docker_endpoint_id, fake_neutron_network_id,
|
||||
fake_neutron_port_id, lib_const.PORT_STATUS_ACTIVE,
|
||||
|
@ -291,7 +292,7 @@ class TestKuryrEndpointDeleteFailures(base.TestKuryrFailures):
|
|||
self.assertEqual(
|
||||
w_exceptions.InternalServerError.code, response.status_code)
|
||||
mock_list_networks.assert_called_with(tags=t)
|
||||
mock_list_ports.assert_called_with(name=neutron_port_name)
|
||||
mock_list_ports.assert_called_with(tags=port_tags)
|
||||
mock_delete_host_iface.assert_called_with(fake_docker_endpoint_id,
|
||||
fake_neutron_port)
|
||||
decoded_json = jsonutils.loads(response.data)
|
||||
|
|
|
@ -1540,7 +1540,7 @@ class TestKuryrIpam(base.TestKuryrBase):
|
|||
mock_list_subnets.assert_called_with(
|
||||
subnetpool_id=fake_kuryr_subnetpool_id)
|
||||
mock_list_ports.assert_called()
|
||||
expect_updated_port = {'name': '', 'device_owner': '',
|
||||
expect_updated_port = {'device_owner': '',
|
||||
'device_id': '', 'binding:host_id': ''}
|
||||
mock_update_port.assert_called_with(fake_port['port']['id'],
|
||||
{'port': expect_updated_port})
|
||||
|
@ -1706,7 +1706,7 @@ class TestKuryrIpam(base.TestKuryrBase):
|
|||
mock_list_subnets.assert_called_with(
|
||||
subnetpool_id=fake_kuryr_subnetpool_id)
|
||||
mock_list_ports.assert_called()
|
||||
expect_updated_port = {'name': '', 'device_owner': '',
|
||||
expect_updated_port = {'device_owner': '',
|
||||
'device_id': '', 'binding:host_id': ''}
|
||||
mock_update_port.assert_called_once_with(fake_port['port']['id'],
|
||||
{'port': expect_updated_port})
|
||||
|
|
|
@ -130,6 +130,20 @@ def make_subnet_name(pool_cidr):
|
|||
return const.SUBNET_NAME_PREFIX + pool_cidr
|
||||
|
||||
|
||||
def create_port_tags(tag):
|
||||
tags = []
|
||||
tags.append(const.NEUTRON_ID_LH_OPTION + ':' + tag[:32])
|
||||
if len(tag) > 32:
|
||||
tags.append(const.NEUTRON_ID_UH_OPTION + ':' + tag[32:64])
|
||||
|
||||
return tags
|
||||
|
||||
|
||||
def make_port_tags(tag):
|
||||
tags = create_port_tags(tag)
|
||||
return ','.join(map(str, tags))
|
||||
|
||||
|
||||
def wait_for_port_active(neutron_client, neutron_port_id, vif_plug_timeout):
|
||||
port_active = False
|
||||
tries = 0
|
||||
|
|
Loading…
Reference in New Issue