Skip to content

Commit

Permalink
Fix iteration in floatingip's add dependencies method
Browse files Browse the repository at this point in the history
port.Port.FIXED_IPS can be None and we can't iterate by None.

Closes bug: #1608973

Change-Id: I273c6383ab77adfbc5c51b94a2f3b2fa7cdbafc0
(cherry picked from commit 432e240)
  • Loading branch information
Dmitriy Uvarenkov authored and Sergey Kraynev committed Aug 18, 2016
1 parent a6878ee commit 13aaa7e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
6 changes: 3 additions & 3 deletions heat/engine/resources/openstack/neutron/floatingip.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,9 @@ def add_dependencies(self, deps):
def port_on_subnet(resource, subnet):
if not resource.has_interface('OS::Neutron::Port'):
return False
for fixed_ip in resource.properties.get(
port.Port.FIXED_IPS):

fixed_ips = resource.properties.get(
port.Port.FIXED_IPS) or []
for fixed_ip in fixed_ips:
port_subnet = (
fixed_ip.get(port.Port.FIXED_IP_SUBNET)
or fixed_ip.get(port.Port.FIXED_IP_SUBNET_ID))
Expand Down
32 changes: 32 additions & 0 deletions heat/tests/openstack/neutron/test_neutron_floating_ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,3 +674,35 @@ def test_floatip_port(self):
scheduler.TaskRunner(p.delete)()

self.m.VerifyAll()

def test_add_dependencies(self):
t = template_format.parse(neutron_floating_template)
stack = utils.parse_stack(t)
fipa = stack['floating_ip_assoc']
port = stack['port_floating']
r_int = stack['router_interface']
deps = mock.MagicMock()
dep_list = []

def iadd(obj):
dep_list.append(obj[1])
deps.__iadd__.side_effect = iadd
deps.graph.return_value = {fipa: [port]}
fipa.add_dependencies(deps)
self.assertEqual([r_int], dep_list)

def test_add_dependencies_without_fixed_ips_in_port(self):
t = template_format.parse(neutron_floating_template)
del t['resources']['port_floating']['properties']['fixed_ips']
stack = utils.parse_stack(t)
fipa = stack['floating_ip_assoc']
port = stack['port_floating']
deps = mock.MagicMock()
dep_list = []

def iadd(obj):
dep_list.append(obj[1])
deps.__iadd__.side_effect = iadd
deps.graph.return_value = {fipa: [port]}
fipa.add_dependencies(deps)
self.assertEqual([], dep_list)

0 comments on commit 13aaa7e

Please sign in to comment.