summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulia Kreger <juliaashleykreger@gmail.com>2022-08-24 10:15:27 -0700
committerJay Faulkner <jay@jvf.cc>2022-09-16 14:32:06 -0700
commit8d033aa4e551cc3974448aca77147a339c749ecc (patch)
tree60ea35249bacf1139b8bba8c239c7fc11d3bdda7
parent8c576f14eb688323bf241800d2eae28278991c02 (diff)
downloadironic-python-agent-8d033aa4e551cc3974448aca77147a339c749ecc.tar.gz
Fix software raid output poisoning
In the event a device name is set to contain a raid device path, it is possible for the Name and Events field values of mdadm's detailed output to contain text which inadvertently gets captured and mapped as component data for the "holder" devices of the RAID set. This would cause invalid values to get passed to UEFI methods which would cause a deployment to fail under these circumstances. We now ignore the Name and Events fields in mdadm output. Change-Id: If721dfe1caa5915326482969e55fbf4697538231 (cherry picked from commit f3e3de8097f05cc830768da7d3f3e9eae04b40a1) (cherry picked from commit 6660e01e1f8a6e7a40b798eea5215b1eddcbe0c3) (cherry picked from commit 5751f60353f3a4bf325a8c9335d743eec45fbcd1)
-rw-r--r--ironic_python_agent/hardware.py3
-rw-r--r--ironic_python_agent/tests/unit/samples/hardware_samples.py27
-rw-r--r--ironic_python_agent/tests/unit/test_hardware.py6
-rw-r--r--releasenotes/notes/fix-softraid-name-poisoning-4e934dd4e60830b1.yaml7
4 files changed, 42 insertions, 1 deletions
diff --git a/ironic_python_agent/hardware.py b/ironic_python_agent/hardware.py
index c35de741..c87a7202 100644
--- a/ironic_python_agent/hardware.py
+++ b/ironic_python_agent/hardware.py
@@ -382,9 +382,10 @@ def get_holder_disks(raid_device):
holder_parts = []
for line in lines[1:]:
+ if 'Events' in line or 'Name' in line:
+ continue
device = re.findall(r'/dev/\w+', line)
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
diff --git a/ironic_python_agent/tests/unit/samples/hardware_samples.py b/ironic_python_agent/tests/unit/samples/hardware_samples.py
index e402af45..056f41ef 100644
--- a/ironic_python_agent/tests/unit/samples/hardware_samples.py
+++ b/ironic_python_agent/tests/unit/samples/hardware_samples.py
@@ -1027,6 +1027,33 @@ MDADM_DETAIL_OUTPUT_BROKEN_RAID0 = ("""/dev/md126:
- 8 2 - /dev/sda2
""")
+# NOTE(TheJulia): The name and events field, in some cases can
+# match the regex causing parsing of the text to fail.
+MDADM_DETAIL_POISONED = ("""/dev/md0:
+ Version : 1.2
+ Creation Time : Wed Aug 17 16:09:19 2022
+ Raid Level : raid1
+ Array Size : 4673536 (4.46 GiB 4.79 GB)
+ Used Dev Size : 4673536 (4.46 GiB 4.79 GB)
+ Raid Devices : 2
+ Total Devices : 2
+ Persistence : Superblock is persistent
+
+ Update Time : Wed Aug 17 16:10:03 2022
+ State : clean
+ Active Devices : 2
+Working Devices : 2
+ Failed Devices : 0
+ Spare Devices : 0
+
+ Name : box:/dev/md0 (local to host box)
+ UUID : e50fb152:aa80db1d:3c901b03:dd280e35
+ Events : 21/dev/md/dev/md
+
+ Number Major Minor RaidDevice State
+ 0 251 1 0 active sync /dev/vda1
+ 1 251 17 1 active sync /dev/vdb1
+""")
MDADM_EXAMINE_OUTPUT_MEMBER = ("""/dev/sda1:
Magic : a92b4efc
diff --git a/ironic_python_agent/tests/unit/test_hardware.py b/ironic_python_agent/tests/unit/test_hardware.py
index 9217e93c..7e807a81 100644
--- a/ironic_python_agent/tests/unit/test_hardware.py
+++ b/ironic_python_agent/tests/unit/test_hardware.py
@@ -3998,6 +3998,12 @@ class TestGenericHardwareManager(base.IronicAgentTest):
holder_disks = hardware.get_holder_disks('/dev/md126')
self.assertEqual(['/dev/sda'], holder_disks)
+ @mock.patch.object(utils, 'execute', autospec=True)
+ def test_get_holder_disks_poisoned_output(self, mocked_execute):
+ mocked_execute.side_effect = [(hws.MDADM_DETAIL_POISONED, '')]
+ holder_disks = hardware.get_holder_disks('/dev/md0')
+ self.assertEqual(['/dev/vda', '/dev/vdb'], holder_disks)
+
@mock.patch.object(hardware, 'get_holder_disks', autospec=True)
@mock.patch.object(hardware, 'get_component_devices', autospec=True)
@mock.patch.object(hardware, 'list_all_block_devices', autospec=True)
diff --git a/releasenotes/notes/fix-softraid-name-poisoning-4e934dd4e60830b1.yaml b/releasenotes/notes/fix-softraid-name-poisoning-4e934dd4e60830b1.yaml
new file mode 100644
index 00000000..9b80e30c
--- /dev/null
+++ b/releasenotes/notes/fix-softraid-name-poisoning-4e934dd4e60830b1.yaml
@@ -0,0 +1,7 @@
+---
+fixes:
+ - |
+ Fixes handling of Software RAID device discovery so RAID device ``Names``
+ and ``Events`` field values do not inadvertently cause the command to
+ return unexpected output. Previously this could cause a deployment to
+ when handling UEFI partitions.