Skip to content

Commit

Permalink
Do not assume fixed_ips is a specified property
Browse files Browse the repository at this point in the history
Check if property is set before attempting use to avoid KeyError

Fixes bug #1232252

Change-Id: I731c13eb73b1ed624a99f84e4b6977f82a731cfc
  • Loading branch information
jpeeler authored and steveb committed Sep 29, 2013
1 parent dcbd7b6 commit 3f1a309
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion heat/engine/resources/neutron/port.py
Expand Up @@ -73,7 +73,7 @@ def handle_create(self):
self.properties,
self.physical_resource_name())

for fixed_ip in props['fixed_ips']:
for fixed_ip in props.get('fixed_ips', []):
for key, value in fixed_ip.items():
if value is None:
fixed_ip.pop(key)
Expand Down
28 changes: 28 additions & 0 deletions heat/tests/test_neutron.py
Expand Up @@ -1123,3 +1123,31 @@ def test_missing_ip_address(self):
port = stack['port']
scheduler.TaskRunner(port.create)()
self.m.VerifyAll()

def test_missing_fixed_ips(self):
clients.OpenStackClients.keystone().AndReturn(
fakes.FakeKeystoneClient())
neutronclient.Client.create_port({'port': {
'network_id': u'net1234',
'name': utils.PhysName('test_stack', 'port'),
'admin_state_up': True}}
).AndReturn({'port': {
"status": "BUILD",
"id": "fc68ea2c-b60b-4b4f-bd82-94ec81110766"
}})
neutronclient.Client.show_port(
'fc68ea2c-b60b-4b4f-bd82-94ec81110766'
).AndReturn({'port': {
"status": "ACTIVE",
"id": "fc68ea2c-b60b-4b4f-bd82-94ec81110766"
}})

self.m.ReplayAll()

t = template_format.parse(neutron_port_template)
t['Resources']['port']['Properties'].pop('fixed_ips')
stack = utils.parse_stack(t)

port = stack['port']
scheduler.TaskRunner(port.create)()
self.m.VerifyAll()

0 comments on commit 3f1a309

Please sign in to comment.