Merge "Correct inventory script key usage"
This commit is contained in:
commit
c3ce148cb0
@ -184,12 +184,14 @@ def _process_baremetal_data(data_source, groups, hostvars):
|
|||||||
for name in file_data:
|
for name in file_data:
|
||||||
host = file_data[name]
|
host = file_data[name]
|
||||||
# Perform basic validation
|
# Perform basic validation
|
||||||
if not host['ipv4_address']:
|
if ('ipv4_address' not in host or
|
||||||
|
not host['ipv4_address']):
|
||||||
host['addressing_mode'] = "dhcp"
|
host['addressing_mode'] = "dhcp"
|
||||||
else:
|
else:
|
||||||
host['ansible_ssh_host'] = host['ipv4_address']
|
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']
|
host['provisioning_ipv4_address'] = host['ipv4_address']
|
||||||
# Add each host to the values to be returned.
|
# Add each host to the values to be returned.
|
||||||
groups['baremetal']['hosts'].append(host['name'])
|
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['uuid'] = _val_or_none(row, 9)
|
||||||
host['name'] = _val_or_none(row, 10)
|
host['name'] = _val_or_none(row, 10)
|
||||||
host['ipv4_address'] = _val_or_none(row, 11)
|
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['addressing_mode'] = "dhcp"
|
||||||
host['provisioning_ipv4_address'] = None
|
host['provisioning_ipv4_address'] = None
|
||||||
else:
|
else:
|
||||||
host['ansible_ssh_host'] = host['ipv4_address']
|
host['ansible_ssh_host'] = host['ipv4_address']
|
||||||
|
# Note(TheJulia): We can't assign ipv4_address if we are
|
||||||
if len(row) > 17:
|
# using DHCP.
|
||||||
|
if (len(row) > 17 and 'addressing_mode' not in host):
|
||||||
host['provisioning_ipv4_address'] = row[18]
|
host['provisioning_ipv4_address'] = row[18]
|
||||||
else:
|
else:
|
||||||
host['provisioning_ipv4_address'] = host['ipv4_address']
|
host['provisioning_ipv4_address'] = host['ipv4_address']
|
||||||
|
@ -210,3 +210,16 @@ unused,,00000000-0000-0000-0000-000000000002,hostname1,
|
|||||||
(groups, hostvars) = utils.bifrost_data_conversion(
|
(groups, hostvars) = utils.bifrost_data_conversion(
|
||||||
yaml.dump(json.loads(str(expected_hostvars))))
|
yaml.dump(json.loads(str(expected_hostvars))))
|
||||||
self.assertDictEqual(json.loads(str(expected_hostvars)), 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