Ignore NotFound Exception in Delete ServiceChainInstance

When cleaning up services in a service chain instance, NotFound
exception is safely ignored rather than propagating the exception

Change-Id: If974bdc31efd44feb77fa5eac09dba31f221ce16
Closes-Bug: 1420058
This commit is contained in:
Magesh GV 2015-02-19 09:46:02 +05:30
parent 8922c5ffb9
commit 2cb2c9fc13
2 changed files with 41 additions and 1 deletions

View File

@ -14,6 +14,7 @@ import ast
import time
from heatclient import client as heat_client
from heatclient import exc as heatException
from neutron.common import log
from neutron.db import model_base
from neutron import manager
@ -394,7 +395,11 @@ class HeatClient:
return self.stacks.create(**fields)
def delete(self, stack_id):
return self.stacks.delete(stack_id)
try:
self.stacks.delete(stack_id)
except heatException.HTTPNotFound:
LOG.warn(_("Stack %(stack)s created by service chain driver is "
"not found at cleanup"), {'stack': stack_id})
def get(self, stack_id):
return self.stacks.get(stack_id)

View File

@ -12,6 +12,7 @@
# limitations under the License.
import contextlib
import heatclient
import mock
from neutron.openstack.common import jsonutils
from neutron.openstack.common import uuidutils
@ -33,6 +34,22 @@ class MockStackObject(object):
self.stack_status = status
class MockHeatClientFunctions(object):
def delete(self, stack_id):
raise heatclient.exc.HTTPNotFound()
def create(self, **fields):
return {'stack': {'id': uuidutils.generate_uuid()}}
def get(self, stack_id):
return MockStackObject('DELETE_COMPLETE')
class MockHeatClient(object):
def __init__(self, api_version, endpoint, **kwargs):
self.stacks = MockHeatClientFunctions()
class SimpleChainDriverTestCase(
test_servicechain_plugin.ServiceChainPluginTestCase):
@ -233,3 +250,21 @@ class TestServiceChainInstance(SimpleChainDriverTestCase):
self.assertEqual(res.status_int, webob.exc.HTTPNoContent.code)
stack_delete.assert_called_once_with(mock.ANY)
self.assertEqual(stack_get.call_count, 1)
def test_stack_not_found_ignored(self):
name = "scs1"
scn = self.create_servicechain_node()
scn_id = scn['servicechain_node']['id']
scs = self.create_servicechain_spec(name=name, nodes=[scn_id])
sc_spec_id = scs['servicechain_spec']['id']
mock.patch(heatclient.__name__ + ".client.Client",
new=MockHeatClient).start()
sc_instance = self.create_servicechain_instance(
name="sc_instance_1",
servicechain_specs=[sc_spec_id])
req = self.new_delete_request(
'servicechain_instances',
sc_instance['servicechain_instance']['id'])
res = req.get_response(self.ext_api)
self.assertEqual(webob.exc.HTTPNoContent.code, res.status_int)