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
This commit is contained in:
parent
dc3b7f15e6
commit
553f2edde5
@ -412,8 +412,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()
|
||||
|
@ -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')
|
||||
|
Loading…
x
Reference in New Issue
Block a user