Fix possible TypeError in VIF.fixed_ips

The VIF['network'] field can be initialized to None and therefore
a later call to VIF.fixed_ips() could raise a TypeError. This problem
was visible during AttachInterfacesTestJSON tempest test case when
nova tried to emit instance.interfacae_attach notification.

This patch checks makes sure that if VIF['network'] is None then
VIF.fixed_ips() return an empty list instead of raising a TypeError.

Change-Id: Ib285d874b19be5bc1dbcd1d2af32e461f67e34cb
Closes-Bug: #1737201
(cherry picked from commit 553f2edde5)
This commit is contained in:
Balazs Gibizer 2017-12-13 17:14:49 +01:00
parent cda224ba00
commit 4eff706211
2 changed files with 10 additions and 2 deletions

View File

@ -409,8 +409,11 @@ class VIF(Model):
return not self.__eq__(other)
def fixed_ips(self):
return [fixed_ip for subnet in self['network']['subnets']
for fixed_ip in subnet['ips']]
if self['network']:
return [fixed_ip for subnet in self['network']['subnets']
for fixed_ip in subnet['ips']]
else:
return []
def floating_ips(self):
return [floating_ip for fixed_ip in self.fixed_ips()

View File

@ -423,6 +423,11 @@ class VIFTests(test.NoDBTestCase):
] * 2
self.assertEqual(fixed_ips, ips)
def test_vif_get_fixed_ips_network_is_none(self):
vif = model.VIF()
fixed_ips = vif.fixed_ips()
self.assertEqual([], fixed_ips)
def test_vif_get_floating_ips(self):
vif = fake_network_cache_model.new_vif()
vif['network']['subnets'][0]['ips'][0].add_floating_ip('192.168.1.1')