diff --git a/bifrost/inventory.py b/bifrost/inventory.py index 0e57b5e42..d96cf0371 100755 --- a/bifrost/inventory.py +++ b/bifrost/inventory.py @@ -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'] diff --git a/bifrost/tests/functional/test_inventory_functional.py b/bifrost/tests/functional/test_inventory_functional.py index 8d53154f7..fa4fd268c 100644 --- a/bifrost/tests/functional/test_inventory_functional.py +++ b/bifrost/tests/functional/test_inventory_functional.py @@ -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)