Merge "Fix possible TypeError in VIF.fixed_ips" into stable/pike

This commit is contained in:
Zuul 2018-02-28 17:26:11 +00:00 committed by Gerrit Code Review
commit 0743277a7c
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')