diff --git a/heat/engine/resources/openstack/neutron/port.py b/heat/engine/resources/openstack/neutron/port.py index 6ad72425b9..79f84841a7 100644 --- a/heat/engine/resources/openstack/neutron/port.py +++ b/heat/engine/resources/openstack/neutron/port.py @@ -579,11 +579,13 @@ class Port(neutron.NeutronResource): if self.resource_id is None: return # store port fixed_ips for restoring after failed update - fixed_ips = self._show_resource().get('fixed_ips', []) - self.data_set('port_fip', jsonutils.dumps(fixed_ips)) - # reset fixed_ips for this port by setting fixed_ips to [] - props = {'fixed_ips': []} - self.client().update_port(self.resource_id, {'port': props}) + # Ignore if the port does not exist in neutron (deleted) + with self.client_plugin().ignore_not_found: + fixed_ips = self._show_resource().get('fixed_ips', []) + self.data_set('port_fip', jsonutils.dumps(fixed_ips)) + # reset fixed_ips for this port by setting fixed_ips to [] + props = {'fixed_ips': []} + self.client().update_port(self.resource_id, {'port': props}) def restore_prev_rsrc(self, convergence=False): # In case of convergence, during rollback, the previous rsrc is diff --git a/heat/tests/openstack/neutron/test_neutron_port.py b/heat/tests/openstack/neutron/test_neutron_port.py index 20a1320aea..f42aa8747c 100644 --- a/heat/tests/openstack/neutron/test_neutron_port.py +++ b/heat/tests/openstack/neutron/test_neutron_port.py @@ -681,6 +681,25 @@ class NeutronPortTest(common.HeatTestCase): self.assertFalse(port.data_set.called) self.assertFalse(n_client.update_port.called) + def test_prepare_for_replace_port_not_found(self): + t = template_format.parse(neutron_port_template) + stack = utils.parse_stack(t) + port = stack['port'] + port.resource_id = 'test_res_id' + port._show_resource = mock.Mock(side_effect=qe.NotFound) + port.data_set = mock.Mock() + n_client = mock.Mock() + port.client = mock.Mock(return_value=n_client) + + # execute prepare_for_replace + port.prepare_for_replace() + + # check, if the port is not found, do nothing in + # prepare_for_replace() + self.assertTrue(port._show_resource.called) + self.assertFalse(port.data_set.called) + self.assertFalse(n_client.update_port.called) + def test_prepare_for_replace_port(self): t = template_format.parse(neutron_port_template) stack = utils.parse_stack(t)