From 99b3182e347fa886debab410284a157d6a3223ca Mon Sep 17 00:00:00 2001 From: Yolanda Robla Date: Fri, 24 Aug 2018 10:04:15 +0200 Subject: [PATCH] Make search for config drive partition case insensitive Currently the search for config drive is just done for config-2 in lowercase. If we pass the label with vfat, the label will be in uppercase by convention. So the comparison will fail, and this needs to be case insensitive to work. Fixed argument from original backport due to changes that were introduced later in ironic-lib. Change-Id: I1dd196841fc3599333d68459eac606bd3b104b7b Story: #2003547 Task: #24834 (cherry picked from commit 65b3df1aa8c08d1242274d2fa27bd4ea320bae61) --- ironic_lib/disk_utils.py | 2 +- ironic_lib/tests/test_disk_utils.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ironic_lib/disk_utils.py b/ironic_lib/disk_utils.py index dfdf9f1a..d1a5b331 100644 --- a/ironic_lib/disk_utils.py +++ b/ironic_lib/disk_utils.py @@ -631,7 +631,7 @@ def _get_labelled_partition(device_path, label, node_uuid): for v in shlex.split(device))} if not dev: continue - if dev['LABEL'] == label: + if dev['LABEL'].upper() == label.upper(): if found_part: found_2 = '/dev/%(part)s' % {'part': dev['NAME'].strip()} found = [found_part, found_2] diff --git a/ironic_lib/tests/test_disk_utils.py b/ironic_lib/tests/test_disk_utils.py index d9654e4f..519b14ba 100644 --- a/ironic_lib/tests/test_disk_utils.py +++ b/ironic_lib/tests/test_disk_utils.py @@ -796,6 +796,22 @@ class WholeDiskPartitionTestCases(test_base.BaseTestCase): ] mock_execute.assert_has_calls(execute_calls) + def test_get_partition_present_uppercase(self, mock_execute): + lsblk_output = 'NAME="fake12" LABEL="CONFIG-2"\n' + part_result = '/dev/fake12' + mock_execute.side_effect = [(None, ''), (lsblk_output, '')] + result = disk_utils._get_labelled_partition(self.dev, + self.config_part_label, + self.node_uuid) + self.assertEqual(part_result, result) + execute_calls = [ + mock.call('partprobe', self.dev, run_as_root=True), + mock.call('lsblk', '-Po', 'name,label', self.dev, + check_exit_code=[0, 1], + use_standard_locale=True, run_as_root=True) + ] + mock_execute.assert_has_calls(execute_calls) + def test_get_partition_absent(self, mock_execute): mock_execute.side_effect = [(None, ''), (None, '')]