diff options
author | Mohammed Naser <mnaser@vexxhost.com> | 2021-02-26 21:42:18 -0500 |
---|---|---|
committer | Mohammed Naser <mnaser@vexxhost.com> | 2021-02-27 17:24:16 -0500 |
commit | ab267aabdd84e4cdf6496ec3a11fcb3580d542bd (patch) | |
tree | b939eae8d235dd5cb8bb88b5fde9b41389731465 | |
parent | 6ea3aff8d6170531510d4ab121b22272240e2a26 (diff) | |
download | ironic-python-agent-ab267aabdd84e4cdf6496ec3a11fcb3580d542bd.tar.gz |
Allow clean_configuration to run against full-device arrays
At the moment, it is not possible for Ironic to clean up a
RAID array that is built from an entire device. This patch
allows it to do so by overriding the behaviour of attempting
to find the device name if the device names does not end with
a number and is a real block device.
Story: #2008663
Task: #41948
Change-Id: I66b0990acaec45b1635795563987b99f9fa04ac7
4 files changed, 55 insertions, 0 deletions
diff --git a/ironic_python_agent/hardware.py b/ironic_python_agent/hardware.py index 99d2d332..fc4f1664 100644 --- a/ironic_python_agent/hardware.py +++ b/ironic_python_agent/hardware.py @@ -23,6 +23,7 @@ import os import re import shlex import shutil +import stat import time from ironic_lib import disk_utils @@ -262,6 +263,13 @@ def get_holder_disks(raid_device): holder_parts += device for part in holder_parts: + # NOTE(mnaser): If the last character is not a digit and it is a valid + # device, this means that instead of a partition, it's a + # entire device which is part of this RAID array. + if (not part[-1].isdigit() and os.path.exists(part) + and stat.S_ISBLK(os.stat(part).st_mode)): + holder_disks.append(part) + continue device = utils.extract_device(part) if not device: diff --git a/ironic_python_agent/tests/unit/samples/hardware_samples.py b/ironic_python_agent/tests/unit/samples/hardware_samples.py index 9523323d..f398f60f 100644 --- a/ironic_python_agent/tests/unit/samples/hardware_samples.py +++ b/ironic_python_agent/tests/unit/samples/hardware_samples.py @@ -715,6 +715,34 @@ Consistency Policy : resync 1 253 80 1 active sync /dev/vdf1 """) +MDADM_DETAIL_OUTPUT_WHOLE_DEVICE = ("""/dev/md0: + Version : 1.0 + Creation Time : Fri Feb 15 12:37:44 2019 + Raid Level : raid1 + Array Size : 1048512 (1023.94 MiB 1073.68 MB) + Used Dev Size : 1048512 (1023.94 MiB 1073.68 MB) + Raid Devices : 2 + Total Devices : 2 + Persistence : Superblock is persistent + + Update Time : Fri Feb 15 12:38:02 2019 + State : clean + Active Devices : 2 + Working Devices : 2 + Failed Devices : 0 + Spare Devices : 0 + +Consistency Policy : resync + + Name : abc.xyz.com:0 (local to host abc.xyz.com) + UUID : 83143055:2781ddf5:2c8f44c7:9b45d92e + Events : 17 + + Number Major Minor RaidDevice State + 0 253 64 0 active sync /dev/vde + 1 253 80 1 active sync /dev/vdf +""") + MDADM_DETAIL_OUTPUT_NVME = ("""/dev/md0: Version : 1.2 Creation Time : Wed Aug 7 13:47:27 2019 diff --git a/ironic_python_agent/tests/unit/test_hardware.py b/ironic_python_agent/tests/unit/test_hardware.py index dd3d6b4a..c4fae2ad 100644 --- a/ironic_python_agent/tests/unit/test_hardware.py +++ b/ironic_python_agent/tests/unit/test_hardware.py @@ -15,6 +15,7 @@ import binascii import os import shutil +import stat import time from unittest import mock @@ -3526,6 +3527,19 @@ class TestGenericHardwareManager(base.IronicAgentTest): self.assertEqual(['/dev/vde', '/dev/vdf'], holder_disks) @mock.patch.object(utils, 'execute', autospec=True) + @mock.patch.object(os.path, 'exists', autospec=True) + @mock.patch.object(os, 'stat', autospec=True) + def test_get_holder_disks_with_whole_device(self, mocked_stat, + mocked_exists, + mocked_execute): + mocked_execute.side_effect = [(hws.MDADM_DETAIL_OUTPUT_WHOLE_DEVICE, + '')] + mocked_exists.return_value = True + mocked_stat.return_value.st_mode = stat.S_IFBLK + holder_disks = hardware.get_holder_disks('/dev/md0') + self.assertEqual(['/dev/vde', '/dev/vdf'], holder_disks) + + @mock.patch.object(utils, 'execute', autospec=True) def test_get_holder_disks_with_nvme(self, mocked_execute): mocked_execute.side_effect = [(hws.MDADM_DETAIL_OUTPUT_NVME, '')] holder_disks = hardware.get_holder_disks('/dev/md0') diff --git a/releasenotes/notes/fix-clean-config-for-full-device-28ee09b58d97d122.yaml b/releasenotes/notes/fix-clean-config-for-full-device-28ee09b58d97d122.yaml new file mode 100644 index 00000000..1012a6f4 --- /dev/null +++ b/releasenotes/notes/fix-clean-config-for-full-device-28ee09b58d97d122.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - IPA will now successfully clean configuration when it encounters a software + RAID array that was previously created using entire devices instead of + partitions.
\ No newline at end of file |