Merge "Do not pass rich objects in CloudNetwork resource"

This commit is contained in:
Jenkins 2015-08-25 13:07:47 +00:00 committed by Gerrit Code Review
commit 75e73bc7dc
2 changed files with 12 additions and 26 deletions

View File

@ -97,6 +97,7 @@ class CloudNetwork(resource.Resource):
def __init__(self, name, json_snippet, stack):
resource.Resource.__init__(self, name, json_snippet, stack)
self._network = None
self._delete_issued = False
def network(self):
if self.resource_id and not self._network:
@ -118,40 +119,24 @@ class CloudNetwork(resource.Resource):
def handle_check(self):
self.cloud_networks().get(self.resource_id)
def handle_delete(self):
'''Delete cloud network.
Cloud Network doesn't have a status attribute, and there is a non-zero
window between the deletion of a server and the acknowledgement from
the cloud network that it's no longer in use, so it needs some way to
keep track of when the delete call was successfully issued.
'''
network_info = {
'delete_issued': False,
'network': self.network(),
}
return network_info
def check_delete_complete(self, network_info):
network = network_info['network']
def check_delete_complete(self, cookie):
try:
network = self.cloud_networks().get(self.resource_id)
except NotFound:
return True
if not network:
return True
if not network_info['delete_issued']:
if not self._delete_issued:
try:
network.delete()
except NetworkInUse:
LOG.warn(_LW("Network '%s' still in use."), network.id)
else:
network_info['delete_issued'] = True
self._delete_issued = True
return False
try:
network.get()
except NotFound:
return True
return False
def validate(self):

View File

@ -153,7 +153,9 @@ class CloudNetworkTest(common.HeatTestCase):
fake_network = res.network()
fake_network.delete = mock.Mock()
fake_network.delete.side_effect = [cloudnetworks.NetworkInUse(), True]
fake_network.get = mock.Mock(side_effect=cloudnetworks.NotFound())
mock_client.return_value = fake_network
fake_network.get = mock.Mock()
fake_network.get.side_effect = [cloudnetworks.NotFound()]
scheduler.TaskRunner(res.delete)()
self.assertEqual((res.DELETE, res.COMPLETE), res.state)
@ -161,8 +163,7 @@ class CloudNetworkTest(common.HeatTestCase):
def test_delete_not_complete(self, mock_client):
self._setup_stack(mock_client)
res = self.stack['cnw']
fake_network = res.network()
fake_network.get = mock.Mock()
mock_client.get = mock.Mock()
task = res.handle_delete()
self.assertFalse(res.check_delete_complete(task))