From 24365043e31a7cb0899d2222bbba654ef718da5b Mon Sep 17 00:00:00 2001 From: James Penick Date: Thu, 21 Dec 2017 01:16:41 +0000 Subject: [PATCH] Recognize uppercase vfat disk labels New mkfs.vfat and fatlabel tools included in the dosfsutils package no longer support creating vfat disks with lowercase labels. They silently default to an all uppercase label eg CONFIG-2 instead of config-2. This change makes cloud-init handle either upper or lower case. Change-Id: Iec927db04b9621b20c9bee2c8d81325d7af80f9b Closes-Bug: #1598783 --- cloudbaseinit/tests/utils/windows/test_vfat.py | 13 +++++++++++++ cloudbaseinit/utils/windows/vfat.py | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/cloudbaseinit/tests/utils/windows/test_vfat.py b/cloudbaseinit/tests/utils/windows/test_vfat.py index ebfd8786..35468b61 100644 --- a/cloudbaseinit/tests/utils/windows/test_vfat.py +++ b/cloudbaseinit/tests/utils/windows/test_vfat.py @@ -92,6 +92,19 @@ class TestVfat(unittest.TestCase): expected_logging=expected_logging, expected_response=expected_response) + def test_is_vfat_drive_works_uppercase(self): + mock_out = b"Volume label is CONFIG-2 \r\n" + expected_logging = [ + "Obtained label information for drive %r: %r" + % (mock.sentinel.drive, mock_out) + ] + execute_process_value = (mock_out, None, 0) + expected_response = True + + self._test_is_vfat_drive(execute_process_value=execute_process_value, + expected_logging=expected_logging, + expected_response=expected_response) + @testutils.ConfPatcher('mtools_path', 'mtools_path') @mock.patch('os.chdir') def test_copy(self, mock_os_chdir): diff --git a/cloudbaseinit/utils/windows/vfat.py b/cloudbaseinit/utils/windows/vfat.py index b03969d1..60b91df6 100644 --- a/cloudbaseinit/utils/windows/vfat.py +++ b/cloudbaseinit/utils/windows/vfat.py @@ -22,7 +22,7 @@ from cloudbaseinit import exception CONF = cloudbaseinit_conf.CONF -CONFIG_DRIVE_LABEL = 'config-2' +CONFIG_DRIVE_LABELS = ['config-2', 'CONFIG-2'] LOG = oslo_logging.getLogger(__name__) VOLUME_LABEL_REGEX = re.compile("Volume label is (.*?)$") @@ -50,7 +50,7 @@ def is_vfat_drive(osutils, drive_path): LOG.debug("Obtained label information for drive %r: %r", drive_path, out) out = out.decode().strip() match = VOLUME_LABEL_REGEX.search(out) - return match.group(1) == CONFIG_DRIVE_LABEL + return match.group(1) in CONFIG_DRIVE_LABELS def copy_from_vfat_drive(osutils, drive_path, target_path):