Check resource_id before calling network delete
On Rackspace::Cloud::Network delete, current code does not check if resource_id (network_id) is valid or not. So adding a check before calling network delete. Change-Id: I1a631703cb6cf6266dd97f15b9e477f5702e291d Co-Authored-By: Pratik Mallya <pratik.mallya@gmail.com> Closes-Bug: #1521715
This commit is contained in:
parent
1a8790d970
commit
1c1e32340b
@ -124,6 +124,9 @@ class CloudNetwork(resource.Resource):
|
||||
self.cloud_networks().get(self.resource_id)
|
||||
|
||||
def check_delete_complete(self, cookie):
|
||||
if not self.resource_id:
|
||||
return True
|
||||
|
||||
try:
|
||||
network = self.cloud_networks().get(self.resource_id)
|
||||
except NotFound:
|
||||
|
@ -74,6 +74,15 @@ class FakeClient(object):
|
||||
pass
|
||||
|
||||
|
||||
class FakeClientRaiseException(FakeClient):
|
||||
|
||||
def create(self, label=None, cidr=None):
|
||||
raise Exception
|
||||
|
||||
def get(self, nwid):
|
||||
raise Exception
|
||||
|
||||
|
||||
@mock.patch.object(cloudnetworks.CloudNetwork, "cloud_networks")
|
||||
class CloudNetworkTest(common.HeatTestCase):
|
||||
|
||||
@ -147,6 +156,18 @@ class CloudNetworkTest(common.HeatTestCase):
|
||||
exc = self.assertRaises(NotFound, self.fake_cnw.get, res_id)
|
||||
self.assertIn(res_id, six.text_type(exc))
|
||||
|
||||
def test_delete_no_network_created(self, mock_client):
|
||||
self.fake_cnw = FakeClientRaiseException()
|
||||
mock_client.return_value = self.fake_cnw
|
||||
self._parse_stack()
|
||||
self.stack.create()
|
||||
self.assertEqual((self.stack.CREATE, self.stack.FAILED),
|
||||
self.stack.state)
|
||||
res = self.stack['cnw']
|
||||
self.assertEqual((res.CREATE, res.FAILED), res.state)
|
||||
scheduler.TaskRunner(res.delete)()
|
||||
self.assertEqual((res.DELETE, res.COMPLETE), res.state)
|
||||
|
||||
def test_delete_in_use(self, mock_client):
|
||||
self._setup_stack(mock_client)
|
||||
res = self.stack['cnw']
|
||||
|
Loading…
x
Reference in New Issue
Block a user