Merge "Ignore NotFound error in prepare_for_replace" into stable/ocata

This commit is contained in:
Zuul 2018-08-08 17:34:07 +00:00 committed by Gerrit Code Review
commit 21a4740a88
2 changed files with 26 additions and 5 deletions

View File

@ -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

View File

@ -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)