Replacing NetworkGateway when devices updated

Updating OS::Neutron::NetworkGateway failed when devices property changed.

Currently, NetworkGateway's devices property doesn't have update_allowed=True.
So, UpdateReplace have used when updating devices property.
However, Neutron doesn't allow that same Gateway Services ID exist at a time.
Eventually, 409 error occured by Neutron.

For avoiding above error, I implemented replacing NetworkGateway in handle_update.
The processing order is delete -> create. It can avoid the 409 error.

Change-Id: I4021610355d03eb6ca07272cb1e44ff2b31dfff9
Closes-bug: #1291901
This commit is contained in:
Mitsuru Kanabuchi 2014-03-13 19:45:36 +09:00
parent 6e2412a468
commit fde6cd0a8a
2 changed files with 77 additions and 0 deletions

View File

@ -62,6 +62,7 @@ class NetworkGateway(neutron.NeutronResource):
description=_('Device info for this network gateway.'),
required=True,
constraints=[constraints.Length(min=1)],
update_allowed=True,
schema=properties.Schema(
properties.Schema.MAP,
schema={
@ -191,6 +192,14 @@ class NetworkGateway(neutron.NeutronResource):
props = self.prepare_update_properties(json_snippet)
connections = props.pop(self.CONNECTIONS)
if self.DEVICES in prop_diff:
self.handle_delete()
self.properties.data.update(props)
self.handle_create()
return
else:
props.pop(self.DEVICES, None)
if self.NAME in prop_diff:
self.neutron().update_network_gateway(
self.resource_id, {'network_gateway': props})

View File

@ -241,6 +241,52 @@ class NeutronNetworkGatewayTest(HeatTestCase):
}
})
neutronclient.Client.disconnect_network_gateway(
u'ed4c03b9-8251-4c09-acc4-e59ee9e6aa37', {
'network_id': u'6af055d3-26f6-48dd-a597-7611d7e58d35',
'segmentation_id': 10,
'segmentation_type': u'vlan'
}
).AndReturn(None)
neutronclient.Client.delete_network_gateway(
u'ed4c03b9-8251-4c09-acc4-e59ee9e6aa37'
).AndReturn(None)
neutronclient.Client.create_network_gateway({
'network_gateway': {
'name': u'NetworkGateway',
'devices': [{'id': u'e52148ca-7db9-4ec3-abe6-2c7c0ff316eb',
'interface_name': u'breth2'}]
}
}
).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': 'breth2'}]
}
}
)
neutronclient.Client.connect_network_gateway(
u'ed4c03b9-8251-4c09-acc4-e59ee9e6aa37', {
'network_id': u'6af055d3-26f6-48dd-a597-7611d7e58d35',
'segmentation_id': 10,
'segmentation_type': u'vlan'
}
).AndReturn({
'connection_info': {
'network_gateway_id': u'ed4c03b9-8251-4c09-acc4-e59ee9e6aa37',
'network_id': u'6af055d3-26f6-48dd-a597-7611d7e58d35',
'port_id': u'aa800972-f6be-4c65-8453-9ab31834bf80'
}
})
self.m.ReplayAll()
rsrc.validate()
@ -292,6 +338,28 @@ class NeutronNetworkGatewayTest(HeatTestCase):
self.assertIsNone(rsrc.handle_update(snippet_for_update, IgnoreArg(),
prop_diff))
# update devices
snippet_for_update = {
'Type': u'OS::Neutron::NetworkGateway',
'Properties': {
'name': u'NetworkGateway',
'devices': [{
'id': u'e52148ca-7db9-4ec3-abe6-2c7c0ff316eb',
'interface_name': u'breth2'}],
'connections': [{
'network_id': u'6af055d3-26f6-48dd-a597-7611d7e58d35',
'segmentation_type': u'vlan',
'segmentation_id': 10}]
}
}
prop_diff = {
'devices': [{
'id': u'e52148ca-7db9-4ec3-abe6-2c7c0ff316eb',
'interface_name': u'breth2'}]
}
self.assertIsNone(rsrc.handle_update(snippet_for_update, IgnoreArg(),
prop_diff))
self.m.VerifyAll()
def test_network_gatway_create_failed(self):