Correct inventory script key usage
A user reported that they were unable to utilize an inventory that did not have the ipv4_address key present. The user, in the bug report indicated a patch, however the end for bifrost appears to be slightly different since the key could exist but the value could still be None. Added unit test to catch the minimal variable case moving forward. Closes-Bug: #1535117 Change-Id: I0e685342887eaba054a8f80eb529835e48ec6744
This commit is contained in:
parent
1780f41d23
commit
40f016c214
@ -184,12 +184,14 @@ def _process_baremetal_data(data_source, groups, hostvars):
|
||||
for name in file_data:
|
||||
host = file_data[name]
|
||||
# Perform basic validation
|
||||
if not host['ipv4_address']:
|
||||
if ('ipv4_address' not in host or
|
||||
not host['ipv4_address']):
|
||||
host['addressing_mode'] = "dhcp"
|
||||
else:
|
||||
host['ansible_ssh_host'] = host['ipv4_address']
|
||||
|
||||
if 'provisioning_ipv4_address' not in host.keys():
|
||||
if ('provisioning_ipv4_address' not in host and
|
||||
'addressing_mode' not in host):
|
||||
host['provisioning_ipv4_address'] = host['ipv4_address']
|
||||
# Add each host to the values to be returned.
|
||||
groups['baremetal']['hosts'].append(host['name'])
|
||||
@ -229,13 +231,15 @@ def _process_baremetal_csv(data_source, groups, hostvars):
|
||||
host['uuid'] = _val_or_none(row, 9)
|
||||
host['name'] = _val_or_none(row, 10)
|
||||
host['ipv4_address'] = _val_or_none(row, 11)
|
||||
if not host['ipv4_address']:
|
||||
if ('ipv4_address' not in host or
|
||||
not host['ipv4_address']):
|
||||
host['addressing_mode'] = "dhcp"
|
||||
host['provisioning_ipv4_address'] = None
|
||||
else:
|
||||
host['ansible_ssh_host'] = host['ipv4_address']
|
||||
|
||||
if len(row) > 17:
|
||||
# Note(TheJulia): We can't assign ipv4_address if we are
|
||||
# using DHCP.
|
||||
if (len(row) > 17 and 'addressing_mode' not in host):
|
||||
host['provisioning_ipv4_address'] = row[18]
|
||||
else:
|
||||
host['provisioning_ipv4_address'] = host['ipv4_address']
|
||||
|
@ -210,3 +210,16 @@ unused,,00000000-0000-0000-0000-000000000002,hostname1,
|
||||
(groups, hostvars) = utils.bifrost_data_conversion(
|
||||
yaml.dump(json.loads(str(expected_hostvars))))
|
||||
self.assertDictEqual(json.loads(str(expected_hostvars)), hostvars)
|
||||
|
||||
def test_minimal_json(self):
|
||||
input_json = """{"h0000-01":{"uuid":
|
||||
"00000000-0000-0000-0001-bad00000010","name":"h0000-01","driver_info"
|
||||
:{"power":{"ipmi_address":"10.0.0.78","ipmi_username":"ADMIN","
|
||||
ipmi_password":"ADMIN"}},"driver":"agent_ipmitool"}}""".replace('\n', '')
|
||||
expected_json = """{"h0000-01":{"uuid":
|
||||
"00000000-0000-0000-0001-bad00000010","name":"h0000-01","driver_info"
|
||||
:{"power":{"ipmi_address":"10.0.0.78","ipmi_username":"ADMIN","
|
||||
ipmi_password":"ADMIN"}},"driver":"agent_ipmitool","addressing_mode":
|
||||
"dhcp"}}""".replace('\n', '')
|
||||
(groups, hostvars) = utils.bifrost_data_conversion(input_json)
|
||||
self.assertDictEqual(json.loads(str(expected_json)), hostvars)
|
||||
|
Loading…
x
Reference in New Issue
Block a user