diff options
author | Zuul <zuul@review.opendev.org> | 2022-08-03 23:47:17 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2022-08-03 23:47:17 +0000 |
commit | eb2215090aa0f8971e05f961a1c8aad3902638dc (patch) | |
tree | a4e8298fb8ebe71b89a135af59237a07118984a4 | |
parent | e196fdfb62a5c5a8d56727f703e8a35abe3956ea (diff) | |
parent | b5fac66bc3ce2cd03a6561f32fb2aba31e8f9fcb (diff) | |
download | ironic-python-agent-eb2215090aa0f8971e05f961a1c8aad3902638dc.tar.gz |
Merge "Use lsblk json output for safety_check_block_device"
-rw-r--r-- | ironic_python_agent/hardware.py | 31 | ||||
-rw-r--r-- | ironic_python_agent/tests/unit/test_hardware.py | 32 |
2 files changed, 31 insertions, 32 deletions
diff --git a/ironic_python_agent/hardware.py b/ironic_python_agent/hardware.py index b3f035dc..53344eb6 100644 --- a/ironic_python_agent/hardware.py +++ b/ironic_python_agent/hardware.py @@ -3011,26 +3011,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, @@ -3048,7 +3046,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', diff --git a/ironic_python_agent/tests/unit/test_hardware.py b/ironic_python_agent/tests/unit/test_hardware.py index 21349050..d3393cb4 100644 --- a/ironic_python_agent/tests/unit/test_hardware.py +++ b/ironic_python_agent/tests/unit/test_hardware.py @@ -5154,29 +5154,31 @@ class TestProtectedDiskSafetyChecks(base.IronicAgentTest): mock_execute.assert_not_called() def test_special_filesystem_guard_enabled_no_results(self, mock_execute): - mock_execute.return_value = ('', '') + mock_execute.return_value = ('{"blockdevices": [{"foo": "bar"}]}', '') hardware.safety_check_block_device({}, '/dev/foo') def test_special_filesystem_guard_raises(self, mock_execute): - GFS2 = 'FSTYPE="gfs2"\n' - GPFS1 = 'UUID="37AFFC90-EF7D-4E96-91C3-2D7AE055B174"\n' - GPFS2 = 'PTUUID="37AFFC90-EF7D-4E96-91C3-2D7AE055B174"\n' - GPFS3 = 'PARTTYPE="37AFFC90-EF7D-4E96-91C3-2D7AE055B174"\n' - GPFS4 = 'PARTUUID="37AFFC90-EF7D-4E96-91C3-2D7AE055B174"\n' - VMFS1 = 'UUID="AA31E02A-400F-11DB-9590-000C2911D1B8"\n' - VMFS2 = 'UUID="AA31E02A-400F-11DB-9590-000C2911D1B8"\n' - VMFS3 = 'UUID="AA31E02A-400F-11DB-9590-000C2911D1B8"\n' - VMFS4 = 'UUID="AA31E02A-400F-11DB-9590-000C2911D1B8"\n' - VMFS5 = 'UUID="0xfb"\n' - VMFS6 = 'PTUUID="0xfb"\n' - VMFS7 = 'PARTTYPE="0xfb"\n' - VMFS8 = 'PARTUUID="0xfb"\n' + GFS2 = '"fstype": "gfs2"' + GPFS1 = '"uuid": "37AFFC90-EF7D-4E96-91C3-2D7AE055B174"' + GPFS2 = '"ptuuid": "37AFFC90-EF7D-4E96-91C3-2D7AE055B174"' + GPFS3 = '"parttype": "37AFFC90-EF7D-4E96-91C3-2D7AE055B174"' + GPFS4 = '"partuuid": "37AFFC90-EF7D-4E96-91C3-2D7AE055B174"' + VMFS1 = '"uuid": "AA31E02A-400F-11DB-9590-000C2911D1B8"' + VMFS2 = '"uuid": "AA31E02A-400F-11DB-9590-000C2911D1B8"' + VMFS3 = '"uuid": "AA31E02A-400F-11DB-9590-000C2911D1B8"' + VMFS4 = '"uuid": "AA31E02A-400F-11DB-9590-000C2911D1B8"' + VMFS5 = '"uuid": "0xfb"' + VMFS6 = '"ptuuid": "0xfb"' + VMFS7 = '"parttype": "0xfb"' + VMFS8 = '"partuuid": "0xfb"' expected_failures = [GFS2, GPFS1, GPFS2, GPFS3, GPFS4, VMFS1, VMFS2, VMFS3, VMFS4, VMFS5, VMFS6, VMFS7, VMFS8] for failure in expected_failures: mock_execute.reset_mock() - mock_execute.return_value = (failure, '') + dev_failure = ('{{"blockdevices": [{{{failure}}}]}}' + .format(failure=failure)) + mock_execute.return_value = (dev_failure, '') self.assertRaises(errors.ProtectedDeviceError, hardware.safety_check_block_device, {}, '/dev/foo') |