From b9a109c65f23b217aac9e698fdfd47f4fc174331 Mon Sep 17 00:00:00 2001 From: cheng Date: Wed, 22 Aug 2018 18:05:58 +0800 Subject: [PATCH] Check GPT table with sgdisk insread of partprobe On centos7.2, it doesn't happen every time, but sometimes, partprobe fails with error `Device or resource busy` in _fix_gpt_structs. In fact, this is not a problem, I tried ignoring this error and ran remain code. Things went well. The target of running `partprobe` is to check GPT table, we can run `sgdisk -v` instead. This patch is to replace `partprobe` command in _fix_gpt_structs to avoid `Device or resource busy` error. Change-Id: I43182f17b1c6229132814313f7582ab30245f6bb --- ironic_lib/disk_utils.py | 8 +++----- ironic_lib/tests/test_disk_utils.py | 25 +++++++++++-------------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/ironic_lib/disk_utils.py b/ironic_lib/disk_utils.py index 9dfbb88b..76682c21 100644 --- a/ironic_lib/disk_utils.py +++ b/ironic_lib/disk_utils.py @@ -742,12 +742,10 @@ def _fix_gpt_structs(device, node_uuid): commands fail. """ try: - output, err = utils.execute('partprobe', device, - use_standard_locale=True, - run_as_root=True) + output, _err = utils.execute('sgdisk', '-v', device, run_as_root=True) - search_str = "fix the GPT to use all of the space" - if search_str in err: + search_str = "it doesn't reside\nat the end of the disk" + if search_str in output: utils.execute('sgdisk', '-e', device, run_as_root=True) except (processutils.UnknownArgumentError, processutils.ProcessExecutionError, OSError) as e: diff --git a/ironic_lib/tests/test_disk_utils.py b/ironic_lib/tests/test_disk_utils.py index fa426f6d..468bb459 100644 --- a/ironic_lib/tests/test_disk_utils.py +++ b/ironic_lib/tests/test_disk_utils.py @@ -1022,18 +1022,17 @@ class WholeDiskPartitionTestCases(base.IronicLibTestCase): self.assertEqual(1, mock_log.call_count) def test_fix_gpt_structs_fix_required(self, mock_execute): - partprobe_err = """ -Error: The backup GPT table is not at the end of the disk, as it should be. -This might mean that another operating system believes the disk is smaller. -Fix, by moving the backup to the end (and removing the old backup)? -Warning: Not all of the space available to /dev/sdb appears to be used, -you can fix the GPT to use all of the space (an extra 581456476 blocks) -or continue with the current setting? + sgdisk_v_output = """ +Problem: The secondary header's self-pointer indicates that it doesn't reside +at the end of the disk. If you've added a disk to a RAID array, use the 'e' +option on the experts' menu to adjust the secondary header's and partition +table's locations. + +Identified 1 problems! """ - mock_execute.return_value = ('', partprobe_err) + mock_execute.return_value = (sgdisk_v_output, '') execute_calls = [ - mock.call('partprobe', '/dev/fake', use_standard_locale=True, - run_as_root=True), + mock.call('sgdisk', '-v', '/dev/fake', run_as_root=True), mock.call('sgdisk', '-e', '/dev/fake', run_as_root=True) ] disk_utils._fix_gpt_structs('/dev/fake', self.node_uuid) @@ -1043,8 +1042,7 @@ or continue with the current setting? mock_execute.return_value = ('', '') disk_utils._fix_gpt_structs('/dev/fake', self.node_uuid) - mock_execute.assert_called_once_with('partprobe', '/dev/fake', - use_standard_locale=True, + mock_execute.assert_called_once_with('sgdisk', '-v', '/dev/fake', run_as_root=True) @mock.patch.object(disk_utils.LOG, 'error', autospec=True) @@ -1054,8 +1052,7 @@ or continue with the current setting? 'Failed to fix GPT data structures on disk', disk_utils._fix_gpt_structs, self.dev, self.node_uuid) - mock_execute.assert_called_once_with('partprobe', '/dev/fake', - use_standard_locale=True, + mock_execute.assert_called_once_with('sgdisk', '-v', '/dev/fake', run_as_root=True) self.assertEqual(1, mock_log.call_count)