From 96a094646b4463b5204509dfc13b3ccaf9c59075 Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Fri, 3 Jan 2020 17:29:05 +0100 Subject: [PATCH] Allow reading root_device from instance_info For the future deployment API we need to be able to set root_device per deployment in addition to per node. This change adds it. Change-Id: I1dd046c2e5fca211a84290bac8daa7550b21614f Story: #2006910 Task: #37955 --- ironic_python_agent/hardware.py | 4 +- .../tests/unit/test_hardware.py | 40 ++++++++++++++++++- ...nce-info-root-device-02fed0966bb00fb3.yaml | 5 +++ 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 releasenotes/notes/instance-info-root-device-02fed0966bb00fb3.yaml diff --git a/ironic_python_agent/hardware.py b/ironic_python_agent/hardware.py index fe717f186..68a233b6f 100644 --- a/ironic_python_agent/hardware.py +++ b/ironic_python_agent/hardware.py @@ -952,7 +952,9 @@ class GenericHardwareManager(HardwareManager): cached_node = get_cached_node() root_device_hints = None if cached_node is not None: - root_device_hints = cached_node['properties'].get('root_device') + root_device_hints = ( + cached_node['instance_info'].get('root_device') + or cached_node['properties'].get('root_device')) LOG.debug('Looking for a device matching root hints %s', root_device_hints) diff --git a/ironic_python_agent/tests/unit/test_hardware.py b/ironic_python_agent/tests/unit/test_hardware.py index e1ae2cc58..407f2fae3 100644 --- a/ironic_python_agent/tests/unit/test_hardware.py +++ b/ironic_python_agent/tests/unit/test_hardware.py @@ -1304,7 +1304,8 @@ class TestGenericHardwareManager(base.IronicAgentTest): def _get_os_install_device_root_device_hints(self, hints, expected_device, mock_cached_node, mock_dev): mock_cached_node.return_value = {'properties': {'root_device': hints}, - 'uuid': 'node1'} + 'uuid': 'node1', + 'instance_info': {}} model = 'fastable sd131 7' mock_dev.return_value = [ hardware.BlockDevice(name='/dev/sda', @@ -1381,6 +1382,7 @@ class TestGenericHardwareManager(base.IronicAgentTest): self, mock_cached_node, mock_dev): model = 'fastable sd131 7' mock_cached_node.return_value = { + 'instance_info': {}, 'properties': { 'root_device': { 'model': model, @@ -1410,6 +1412,42 @@ class TestGenericHardwareManager(base.IronicAgentTest): mock_cached_node.assert_called_once_with() mock_dev.assert_called_once_with() + @mock.patch.object(hardware, 'list_all_block_devices', autospec=True) + @mock.patch.object(hardware, 'get_cached_node', autospec=True) + def test_get_os_install_device_root_device_hints_iinfo(self, + mock_cached_node, + mock_dev): + model = 'fastable sd131 7' + mock_cached_node.return_value = { + 'instance_info': {'root_device': {'model': model}}, + 'uuid': 'node1' + } + mock_dev.return_value = [ + hardware.BlockDevice(name='/dev/sda', + model='TinyUSB Drive', + size=3116853504, + rotational=False, + vendor='Super Vendor', + wwn='wwn0', + wwn_with_extension='wwn0ven0', + wwn_vendor_extension='ven0', + serial='serial0'), + hardware.BlockDevice(name='/dev/sdb', + model=model, + size=10737418240, + rotational=True, + vendor='fake-vendor', + wwn='fake-wwn', + wwn_with_extension='fake-wwnven0', + wwn_vendor_extension='ven0', + serial='fake-serial', + by_path='/dev/disk/by-path/1:0:0:0'), + ] + + self.assertEqual('/dev/sdb', self.hardware.get_os_install_device()) + mock_cached_node.assert_called_once_with() + mock_dev.assert_called_once_with() + def test__get_device_info(self): fileobj = mock.mock_open(read_data='fake-vendor') with mock.patch( diff --git a/releasenotes/notes/instance-info-root-device-02fed0966bb00fb3.yaml b/releasenotes/notes/instance-info-root-device-02fed0966bb00fb3.yaml new file mode 100644 index 000000000..32fe0afcc --- /dev/null +++ b/releasenotes/notes/instance-info-root-device-02fed0966bb00fb3.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Allows reading the ``root_device`` from ``instance_info``, overriding + the value in ``properties``.