Get the hostname of the introspected host

This will retrieve the hostname of the host being introspected, and
return it as part of the introspection data.

Change-Id: I54084251e1b0f3a40fe5ac760b2a7e45199c9fdb
Story: #2005867
Task: #33674
This commit is contained in:
Brad P. Crochet 2019-06-07 12:11:08 -04:00 committed by Dmitry Tantsur
parent 2e5fb1b531
commit 7b3469ee0f
5 changed files with 25 additions and 1 deletions

View File

@ -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

View File

@ -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):

View File

@ -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:

View File

@ -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):

View File

@ -0,0 +1,5 @@
---
features:
- |
Add the hostname to the introspection data. This will likely be the
hostname as set by the DHCP server.