diff options
| author | Bob Fournier <bfournie@redhat.com> | 2021-03-07 15:18:40 -0500 |
|---|---|---|
| committer | Bob Fournier <bfournie@redhat.com> | 2021-03-09 07:05:27 -0500 |
| commit | 4afe4f6069bae2215617b676ae9d4860ac84609c (patch) | |
| tree | 537620039b71fd4f598bc590abaf41add7f405c0 /ironic_python_agent/hardware.py | |
| parent | 7931ccedfb8c3f204896a26152e259a67196e79e (diff) | |
| download | ironic-python-agent-4afe4f6069bae2215617b676ae9d4860ac84609c.tar.gz | |
Check the base device if the read-only file cannot be read
For some drives, the partition e.g. `/dev/sda1` will not have the
'ro' file which can result in a metadata erasure failure but the base
device (`/dev/sda`) will have this file. Add an additional check
for the base device.
Change-Id: Ia01bdbf82cee6ce15fabdc42f9c23036df55b4c5
Story: 2008696
Task: 42004
Diffstat (limited to 'ironic_python_agent/hardware.py')
| -rw-r--r-- | ironic_python_agent/hardware.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/ironic_python_agent/hardware.py b/ironic_python_agent/hardware.py index b9958e19..f245feb9 100644 --- a/ironic_python_agent/hardware.py +++ b/ironic_python_agent/hardware.py @@ -24,6 +24,7 @@ import re import shlex import shutil import stat +import string import time from ironic_lib import disk_utils @@ -1447,23 +1448,32 @@ class GenericHardwareManager(HardwareManager): return 'linux_raid_member' in out - def _is_read_only_device(self, block_device): + def _is_read_only_device(self, block_device, partition=False): """Check if a block device is read-only. Checks the device read-only flag in order to identify virtual and firmware driven devices that block write device access. :param block_device: a BlockDevice object + :param partition: if True, this device is a partition :returns: True if the device is read-only. """ try: - dev_name = str(block_device.name)[5:] + dev_name = os.path.basename(block_device.name) + if partition: + # Check the base device + dev_name = dev_name.rstrip(string.digits) with open('/sys/block/%s/ro' % dev_name, 'r') as f: flag = f.read().strip() if flag == '1': return True except IOError as e: + # Check underlying device as the file may exist there + if (not partition and dev_name[-1].isdigit() + and 'nvme' not in dev_name): + return self._is_read_only_device(block_device, partition=True) + LOG.warning("Could not determine if %(name)s is a" "read-only device. Error: %(err)s", {'name': block_device.name, 'err': e}) |
