From e2f04a481abd6bd41bf10d7f362a2d68ee9d0e40 Mon Sep 17 00:00:00 2001 From: Hongbin Lu Date: Fri, 7 Sep 2018 04:06:07 +0000 Subject: [PATCH] Fix a docker internal error on server restart Zun creates docker network by passing the subnetpool and subnet to kuryr-libnetwork. However, kuryr-libnetwork has an issue on unseting neutron ports if a subnetpool is passed. This commit avoid passing subnetpool when creating the docker network. Note: we passed subnetpool to kuryr in before because kuryr doesn't take subnet as an input at that time so we pass subnetpool for kuryr to search for the subnet. Right now, kuryr support directly taking subnet as input so subnetpool is not needed anymore. Change-Id: I5a6ef58cd109749a4aac7e6295e0f6d737918ac0 Closes-Bug: #1791041 --- zun/compute/manager.py | 2 +- zun/network/kuryr_network.py | 48 +------------------ .../unit/compute/test_compute_manager.py | 9 ++-- zun/tests/unit/network/test_kuryr_network.py | 12 ++--- 4 files changed, 10 insertions(+), 61 deletions(-) diff --git a/zun/compute/manager.py b/zun/compute/manager.py index 635fb613f..dfed674d6 100644 --- a/zun/compute/manager.py +++ b/zun/compute/manager.py @@ -66,7 +66,7 @@ class Manager(periodic_task.PeriodicTasks): {'container_uuid': container.uuid, 'old_status': container.status, 'current_status': current_status}) - self.container_reboot(context, container, 10) + self.container_start(context, container) def init_containers(self, context): containers = objects.Container.list_by_host(context, self.host) diff --git a/zun/network/kuryr_network.py b/zun/network/kuryr_network.py index 30a9c5129..3ef21fdd0 100644 --- a/zun/network/kuryr_network.py +++ b/zun/network/kuryr_network.py @@ -59,7 +59,7 @@ class KuryrNetwork(network.Network): will have both ipv4 and ipv6 addresses. What this method does is finding the subnets under the specified - neutron net, retrieving the cidr, gateway, subnetpool of each + neutron net, retrieving the cidr, gateway of each subnet, and compile the list of parameters for docker.create_network. """ # find a v4 and/or v6 subnet of the network @@ -90,8 +90,6 @@ class KuryrNetwork(network.Network): } if v4_subnet: - ipam_options["Options"]['neutron.pool.uuid'] = \ - self._get_subnetpool(v4_subnet) ipam_options['Options']['neutron.subnet.uuid'] = \ v4_subnet.get('id') ipam_options["Config"].append({ @@ -99,11 +97,8 @@ class KuryrNetwork(network.Network): "Gateway": v4_subnet['gateway_ip'] }) - options['neutron.pool.uuid'] = v4_subnet.get('subnetpool_id') options['neutron.subnet.uuid'] = v4_subnet.get('id') if v6_subnet: - ipam_options["Options"]['neutron.pool.v6.uuid'] = \ - self._get_subnetpool(v6_subnet) ipam_options['Options']['neutron.subnet.v6.uuid'] = \ v6_subnet.get('id') ipam_options["Config"].append({ @@ -111,7 +106,6 @@ class KuryrNetwork(network.Network): "Gateway": v6_subnet['gateway_ip'] }) - options['neutron.pool.v6.uuid'] = v6_subnet.get('subnetpool_id') options['neutron.subnet.v6.uuid'] = v6_subnet.get('id') network_dict = {} @@ -143,46 +137,6 @@ class KuryrNetwork(network.Network): network.save() return network - def _check_valid_subnetpool(self, neutron_api, - subnetpool_id, subnet_cidr): - """Check subnet's cidr matches with subnetpool prefixes or not""" - subnetpools = \ - neutron_api.list_subnetpools(id=subnetpool_id) - subnetpools = subnetpools.get('subnetpools', []) - if not len(subnetpools): - return False - if subnet_cidr in subnetpools[0]['prefixes']: - return True - return False - - def _get_subnetpool(self, subnet): - # NOTE(kiennt): Elevate admin privilege to list all subnetpools - # across projects. - admin_context = zun_context.get_admin_context() - neutron_api = neutron.NeutronAPI(admin_context) - subnetpool_id = subnet.get('subnetpool_id') - if not subnetpool_id: - return None - if self._check_valid_subnetpool(neutron_api, subnetpool_id, - subnet['cidr']): - return subnetpool_id - # NOTE(kiennt): Subnetpool which was created by Kuryr-libnetwork - # will be tagged with subnet_id. - kwargs = { - 'tags': [subnet['id']], - } - - subnetpools = \ - neutron_api.list_subnetpools(**kwargs).get('subnetpools', []) - if not subnetpools: - return None - elif len(subnetpools) > 1: - raise exception.ZunException(_( - 'Multiple Neutron subnetpools exist with prefixes %s') % - subnet['cidr']) - else: - return subnetpools[0]['id'] - def _get_subnet(self, subnets, ip_version): subnets = [s for s in subnets if s['ip_version'] == ip_version] if len(subnets) == 0: diff --git a/zun/tests/unit/compute/test_compute_manager.py b/zun/tests/unit/compute/test_compute_manager.py index 81e94d64e..2d358b44d 100644 --- a/zun/tests/unit/compute/test_compute_manager.py +++ b/zun/tests/unit/compute/test_compute_manager.py @@ -125,18 +125,17 @@ class TestManager(base.TestCase): mock_container_start.assert_called_once_with(self.context, container) - @mock.patch.object(manager.Manager, 'container_reboot') + @mock.patch.object(manager.Manager, 'container_start') @mock.patch.object(Container, 'save') def test_container_reboot_after_host_reboot(self, mock_save, - mock_container_reboot): + mock_container_start): container_1 = Container(self.context, **utils.get_test_container()) container_1.status = consts.RUNNING self.compute_manager.restore_running_container(self.context, container_1, consts.STOPPED) - mock_container_reboot.assert_called_once_with(self.context, - container_1, - 10) + mock_container_start.assert_called_once_with(self.context, + container_1) @mock.patch.object(manager.Manager, 'container_stop') @mock.patch.object(Container, 'save') diff --git a/zun/tests/unit/network/test_kuryr_network.py b/zun/tests/unit/network/test_kuryr_network.py index 7136b8631..78b56652e 100644 --- a/zun/tests/unit/network/test_kuryr_network.py +++ b/zun/tests/unit/network/test_kuryr_network.py @@ -164,12 +164,10 @@ class KuryrNetworkTestCase(base.TestCase): ipam={'Config': [{'Subnet': '10.5.0.0/16', 'Gateway': '10.5.0.1'}], 'Driver': 'kuryr', 'Options': {'neutron.net.shared': 'False', - 'neutron.subnet.uuid': 'fake-subnet-id', - 'neutron.pool.uuid': None}}, + 'neutron.subnet.uuid': 'fake-subnet-id'}}, options={'neutron.net.uuid': 'fake-net-id', 'neutron.net.shared': 'False', - 'neutron.subnet.uuid': 'fake-subnet-id', - 'neutron.pool.uuid': None}) + 'neutron.subnet.uuid': 'fake-subnet-id'}) @mock.patch.object(Network, 'create') @mock.patch.object(Network, 'save') @@ -191,12 +189,10 @@ class KuryrNetworkTestCase(base.TestCase): ipam={'Config': [{'Subnet': '10.5.0.0/16', 'Gateway': '10.5.0.1'}], 'Driver': 'kuryr', 'Options': {'neutron.net.shared': 'False', - 'neutron.subnet.uuid': 'fake-subnet-id', - 'neutron.pool.uuid': 'fake-subnetpool-id'}}, + 'neutron.subnet.uuid': 'fake-subnet-id'}}, options={'neutron.net.uuid': 'fake-net-id', 'neutron.net.shared': 'False', - 'neutron.subnet.uuid': 'fake-subnet-id', - 'neutron.pool.uuid': 'fake-subnetpool-id'}) + 'neutron.subnet.uuid': 'fake-subnet-id'}) def test_remove_network(self): network_name = 'c02afe4e-8350-4263-8078'