diff options
| author | Brad P. Crochet <brad@redhat.com> | 2019-06-07 12:11:08 -0400 |
|---|---|---|
| committer | Dmitry Tantsur <dtantsur@protonmail.com> | 2019-06-12 13:00:21 +0000 |
| commit | 7b3469ee0f2fbe21d807db88317187772ad2612d (patch) | |
| tree | 3c2e2e715493ed73353eef1f8ced689dd9990b1c /ironic_python_agent | |
| parent | 2e5fb1b5310534f79f704e0128ab46eccf55b30d (diff) | |
| download | ironic-python-agent-7b3469ee0f2fbe21d807db88317187772ad2612d.tar.gz | |
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
Diffstat (limited to 'ironic_python_agent')
| -rw-r--r-- | ironic_python_agent/hardware.py | 1 | ||||
| -rw-r--r-- | ironic_python_agent/netutils.py | 7 | ||||
| -rw-r--r-- | ironic_python_agent/tests/unit/test_hardware.py | 6 |
3 files changed, 13 insertions, 1 deletions
diff --git a/ironic_python_agent/hardware.py b/ironic_python_agent/hardware.py index ec4b8b55..63fbb34c 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 656e61ac..785e81d3 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 561d0bac..907bd3ca 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): |
