diff --git a/doc/source/admin/how_it_works.rst b/doc/source/admin/how_it_works.rst index 7154d219f..aeb25ad28 100644 --- a/doc/source/admin/how_it_works.rst +++ b/doc/source/admin/how_it_works.rst @@ -117,6 +117,13 @@ fields: the current boot - BIOS or UEFI) and ``pxe_interface`` (interface used for PXE booting, if any). +``hostname`` + hostname for the system + + .. note:: + This is most likely to be set by the DHCP server. Could be localhost + if the DHCP server does not set it. + References ========== .. [0] Enabling Drivers - https://docs.openstack.org/ironic/latest/admin/drivers/ipa.html diff --git a/ironic_python_agent/hardware.py b/ironic_python_agent/hardware.py index ec4b8b55f..63fbb34cc 100644 --- a/ironic_python_agent/hardware.py +++ b/ironic_python_agent/hardware.py @@ -600,6 +600,7 @@ class HardwareManager(object): hardware_info['bmc_v6address'] = self.get_bmc_v6address() hardware_info['system_vendor'] = self.get_system_vendor_info() hardware_info['boot'] = self.get_boot_info() + hardware_info['hostname'] = netutils.get_hostname() return hardware_info def get_clean_steps(self, node, ports): diff --git a/ironic_python_agent/netutils.py b/ironic_python_agent/netutils.py index 656e61ace..785e81d3e 100644 --- a/ironic_python_agent/netutils.py +++ b/ironic_python_agent/netutils.py @@ -230,6 +230,13 @@ def get_mac_addr(interface_id): return None +# Other options... +# 1. import os; os.uname()[1] +# 2. import platform; platform.node() +def get_hostname(): + return socket.gethostname() + + def interface_has_carrier(interface_name): path = '/sys/class/net/{}/carrier'.format(interface_name) try: diff --git a/ironic_python_agent/tests/unit/test_hardware.py b/ironic_python_agent/tests/unit/test_hardware.py index 561d0bac8..907bd3caf 100644 --- a/ironic_python_agent/tests/unit/test_hardware.py +++ b/ironic_python_agent/tests/unit/test_hardware.py @@ -1382,7 +1382,8 @@ class TestGenericHardwareManager(base.IronicAgentTest): self.assertEqual(3952 * 1024 * 1024, mem.total) self.assertIsNone(mem.physical_mb) - def test_list_hardware_info(self): + @mock.patch('ironic_python_agent.netutils.get_hostname', autospec=True) + def test_list_hardware_info(self, mocked_get_hostname): self.hardware.list_network_interfaces = mock.Mock() self.hardware.list_network_interfaces.return_value = [ hardware.NetworkInterface('eth0', '00:0c:29:8c:11:b1'), @@ -1413,6 +1414,8 @@ class TestGenericHardwareManager(base.IronicAgentTest): self.hardware.get_bmc_v6address = mock.Mock() self.hardware.get_system_vendor_info = mock.Mock() + mocked_get_hostname.return_value = 'mock_hostname' + hardware_info = self.hardware.list_hardware_info() self.assertEqual(self.hardware.get_memory(), hardware_info['memory']) self.assertEqual(self.hardware.get_cpus(), hardware_info['cpu']) @@ -1422,6 +1425,7 @@ class TestGenericHardwareManager(base.IronicAgentTest): hardware_info['interfaces']) self.assertEqual(self.hardware.get_boot_info(), hardware_info['boot']) + self.assertEqual('mock_hostname', hardware_info['hostname']) @mock.patch.object(hardware, 'list_all_block_devices', autospec=True) def test_list_block_devices(self, list_mock): diff --git a/releasenotes/notes/add-hostname-8bbf24712b6a4919.yaml b/releasenotes/notes/add-hostname-8bbf24712b6a4919.yaml new file mode 100644 index 000000000..292a6d494 --- /dev/null +++ b/releasenotes/notes/add-hostname-8bbf24712b6a4919.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Add the hostname to the introspection data. This will likely be the + hostname as set by the DHCP server.