Fix network_gateway residue when resource deletion

Should set resource_id after network_gateway creation
instead of after network_gateway connection for
OS::Neutron::NetworkGateway, to avoid the network_gateway
residue when the resource deletion.

Change-Id: I89e1aed10685c0448a15decb95b89dbd946d39c2
Closes-bug: #1368008
This commit is contained in:
huangtianhua 2014-09-11 12:16:00 +08:00
parent 2d669b4f8b
commit 90f89b6d71
2 changed files with 63 additions and 2 deletions

View File

@ -172,6 +172,8 @@ class NetworkGateway(neutron.NeutronResource):
ret = self.neutron().create_network_gateway( ret = self.neutron().create_network_gateway(
{'network_gateway': props})['network_gateway'] {'network_gateway': props})['network_gateway']
self.resource_id_set(ret['id'])
for connection in connections: for connection in connections:
self.client_plugin().resolve_network( self.client_plugin().resolve_network(
connection, self.NETWORK, 'network_id') connection, self.NETWORK, 'network_id')
@ -181,8 +183,6 @@ class NetworkGateway(neutron.NeutronResource):
ret['id'], connection ret['id'], connection
) )
self.resource_id_set(ret['id'])
def handle_delete(self): def handle_delete(self):
if not self.resource_id: if not self.resource_id:
return return

View File

@ -107,6 +107,49 @@ class NeutronNetworkGatewayTest(HeatTestCase):
self.m.StubOutWithMock(neutronV20, 'find_resourceid_by_name_or_id') self.m.StubOutWithMock(neutronV20, 'find_resourceid_by_name_or_id')
self.stub_keystoneclient() self.stub_keystoneclient()
def mock_create_fail_network_not_found_delete_success(self):
neutronclient.Client.create_network_gateway({
'network_gateway': {
'name': u'NetworkGateway',
'devices': [{'id': u'e52148ca-7db9-4ec3-abe6-2c7c0ff316eb',
'interface_name': u'breth1'}]
}
}
).AndReturn({
'network_gateway': {
'id': 'ed4c03b9-8251-4c09-acc4-e59ee9e6aa37',
'name': 'NetworkGateway',
'default': False,
'tenant_id': '96ba52dc-c5c5-44c6-9a9d-d3ba1a03f77f',
'devices': [{
'id': 'e52148ca-7db9-4ec3-abe6-2c7c0ff316eb',
'interface_name': 'breth1'}]
}
}
)
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
'network',
'6af055d3-26f6-48dd-a597-7611d7e58d35'
).MultipleTimes().AndRaise(qe.NeutronClientException(status_code=404))
# mock successful to delete the network_gateway
neutronclient.Client.delete_network_gateway(
u'ed4c03b9-8251-4c09-acc4-e59ee9e6aa37'
).AndReturn(None)
neutronclient.Client.show_network_gateway(
u'ed4c03b9-8251-4c09-acc4-e59ee9e6aa37'
).AndRaise(qe.NeutronClientException(status_code=404))
t = template_format.parse(gw_template)
stack = utils.parse_stack(t)
resource_defns = stack.t.resource_definitions(stack)
rsrc = network_gateway.NetworkGateway(
'test_network_gateway',
resource_defns['NetworkGateway'], stack)
return rsrc
def prepare_create_network_gateway(self, resolve_neutron=True): def prepare_create_network_gateway(self, resolve_neutron=True):
neutronclient.Client.create_network_gateway({ neutronclient.Client.create_network_gateway({
'network_gateway': { 'network_gateway': {
@ -228,6 +271,24 @@ class NeutronNetworkGatewayTest(HeatTestCase):
def test_network_gateway_create(self): def test_network_gateway_create(self):
self._test_network_gateway_create() self._test_network_gateway_create()
def test_network_gateway_create_fail_delete_success(self):
# if network_gateway created successful, but didn't to connect with
# network, then can delete the network_gateway successful
# without residue network_gateway
rsrc = self.mock_create_fail_network_not_found_delete_success()
self.m.ReplayAll()
rsrc.validate()
self.assertRaises(exception.ResourceFailure,
scheduler.TaskRunner(rsrc.create))
self.assertEqual((rsrc.CREATE, rsrc.FAILED), rsrc.state)
ref_id = rsrc.FnGetRefId()
self.assertEqual(u'ed4c03b9-8251-4c09-acc4-e59ee9e6aa37', ref_id)
self.assertIsNone(scheduler.TaskRunner(rsrc.delete)())
self.assertEqual((rsrc.DELETE, rsrc.COMPLETE), rsrc.state)
self.m.VerifyAll()
def test_network_gateway_update(self): def test_network_gateway_update(self):
rsrc = self.prepare_create_network_gateway() rsrc = self.prepare_create_network_gateway()
neutronV20.find_resourceid_by_name_or_id( neutronV20.find_resourceid_by_name_or_id(