From 65b3df1aa8c08d1242274d2fa27bd4ea320bae61 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. Change-Id: I1dd196841fc3599333d68459eac606bd3b104b7b Story: #2003547 Task: #24834 --- 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 9dfbb88b..e0684676 100644 --- a/ironic_lib/disk_utils.py +++ b/ironic_lib/disk_utils.py @@ -693,7 +693,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 fa426f6d..508bf33b 100644 --- a/ironic_lib/tests/test_disk_utils.py +++ b/ironic_lib/tests/test_disk_utils.py @@ -909,6 +909,22 @@ class WholeDiskPartitionTestCases(base.IronicLibTestCase): ] 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, attempts=10), + 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, '')]