diff options
| author | Riccardo Pittau <elfosardo@gmail.com> | 2022-07-20 11:56:27 +0200 |
|---|---|---|
| committer | Riccardo Pittau <elfosardo@gmail.com> | 2022-07-20 11:56:27 +0200 |
| commit | b5fac66bc3ce2cd03a6561f32fb2aba31e8f9fcb (patch) | |
| tree | 8deee84855d63320127ff44a549afbc2f47e1e4e /ironic_python_agent/hardware.py | |
| parent | beb7484858d56ef34699895412881945c5507c81 (diff) | |
| download | ironic-python-agent-b5fac66bc3ce2cd03a6561f32fb2aba31e8f9fcb.tar.gz | |
Use lsblk json output for safety_check_block_device
Change-Id: Ibfc2e203287d92e66567c33dc48f59392852b88e
Diffstat (limited to 'ironic_python_agent/hardware.py')
| -rw-r--r-- | ironic_python_agent/hardware.py | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/ironic_python_agent/hardware.py b/ironic_python_agent/hardware.py index dfcce6f8..e5f51025 100644 --- a/ironic_python_agent/hardware.py +++ b/ironic_python_agent/hardware.py @@ -3016,26 +3016,24 @@ def safety_check_block_device(node, device): di_info = node.get('driver_internal_info', {}) if not di_info.get('wipe_special_filesystems', True): return - report, _e = il_utils.execute('lsblk', '-Pbia', - '-oFSTYPE,UUID,PTUUID,PARTTYPE,PARTUUID', - device) + lsblk_ids = ['UUID', 'PTUUID', 'PARTTYPE', 'PARTUUID'] + report = il_utils.execute('lsblk', '-bia', '--json', + '-o{}'.format(','.join(lsblk_ids)), + device, check_exit_code=[0])[0] - lines = report.splitlines() + try: + report_json = json.loads(report) + except json.decoder.JSONDecodeError as ex: + LOG.error("Unable to decode lsblk output, invalid JSON: %s", ex) + device_json = report_json['blockdevices'][0] identified_fs_types = [] identified_ids = [] - for line in lines: - device = {} - # Split into KEY=VAL pairs - vals = shlex.split(line) - if not vals: - continue - for key, val in (v.split('=', 1) for v in vals): - if key == 'FSTYPE': - identified_fs_types.append(val) - if key in ['UUID', 'PTUUID', 'PARTTYPE', 'PARTUUID']: - identified_ids.append(val) - # Ignore block types not specified + + fstype = device_json.get('fstype') + identified_fs_types.append(fstype) + for key in lsblk_ids: + identified_ids.append(device_json.get(key.lower())) _check_for_special_partitions_filesystems( device, @@ -3053,7 +3051,6 @@ def _check_for_special_partitions_filesystems(device, ids, fs_types): be discovered which suggests a shared disk clustered filesystem has been discovered. """ - guarded_ids = { # Apparently GPFS can used shared volumes.... '37AFFC90-EF7D-4E96-91C3-2D7AE055B174': 'IBM GPFS Partition', |
