Raise exception when no IPs found

When generating the inventory, an exception is now raised if no IP
addresses are found for a given role from the specified network.
Previously, an unhandled IndexError was thrown with no indication as to
the actual problem.

This situtation can occur when using pre-provisioned nodes and a
malformed DeployedServerPortMap value such that no IP addresses are
assigned.

Change-Id: I2615bf4d5fcedbcf85d11e4aedbe22061348ded2
This commit is contained in:
James Slagle 2019-10-02 15:36:49 -04:00
parent 33cb21a89b
commit 70c0c674a1
2 changed files with 9 additions and 0 deletions

View File

@ -222,6 +222,9 @@ class TripleoInventory(object):
shortnames = [n.split(".%s." % self.host_network)[0].lower()
for n in names]
ips = role_net_ip_map[role][self.host_network]
if not ips:
raise Exception("No IPs found for %s role on %s network"
% (role, self.host_network))
hosts = {}
for idx, name in enumerate(shortnames):
hosts[name] = {}

View File

@ -158,6 +158,12 @@ class TestInventory(base.TestCase):
self.assertTrue(self.hclient.called_once_with('overcloud',
'KeystoneURL'))
def test_no_ips(self):
for output in self.outputs_data['outputs']:
if output['output_key'] == 'RoleNetIpMap':
output['output_value'] = dict(Controller=dict(ctlplane=[]))
self.assertRaises(Exception, self.inventory.list)
def test_outputs_invalid_key_raises_keyerror(self):
self.assertRaises(KeyError, lambda: self.outputs['Invalid'])