diff options
author | rabi <ramishra@redhat.com> | 2018-07-21 11:52:17 +0530 |
---|---|---|
committer | Rabi Mishra <ramishra@redhat.com> | 2018-07-31 07:42:46 +0000 |
commit | 41fd13174549ab62be55906a1b2c0b5aff05335b (patch) | |
tree | d3a8767d53f4fbd0794cb47e09e3d5244b2b029b | |
parent | 4a9fd8fa9aed62efaa7a3f327a99c177df606321 (diff) | |
download | heat-41fd13174549ab62be55906a1b2c0b5aff05335b.tar.gz |
Ignore NotFound error in prepare_for_replace
If the port is already deleted in neutron, we don't need to do
anything.
Change-Id: I9275610931a174919076330ec443f54f68cc1371
Story: #2003015
Task: 23035
(cherry picked from commit 3d542935fbe7def5e785c26a1b6a8b468cfeaa48)
-rw-r--r-- | heat/engine/resources/openstack/neutron/port.py | 12 | ||||
-rw-r--r-- | heat/tests/openstack/neutron/test_neutron_port.py | 19 |
2 files changed, 26 insertions, 5 deletions
diff --git a/heat/engine/resources/openstack/neutron/port.py b/heat/engine/resources/openstack/neutron/port.py index 4ca10292c..6e12a1a8f 100644 --- a/heat/engine/resources/openstack/neutron/port.py +++ b/heat/engine/resources/openstack/neutron/port.py @@ -529,11 +529,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 d0b3a1fea..1410ecfba 100644 --- a/heat/tests/openstack/neutron/test_neutron_port.py +++ b/heat/tests/openstack/neutron/test_neutron_port.py @@ -605,6 +605,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) |