Merge "Accept drives with vFAT label 'cidata' as a configdrive."

This commit is contained in:
Zuul 2023-10-16 14:04:28 +00:00 committed by Gerrit Code Review
commit 983e1482e6
4 changed files with 26 additions and 9 deletions

View File

@ -165,7 +165,7 @@ class WindowsConfigDriveManager(base.BaseConfigDriveManager):
def _get_config_drive_from_vfat(self, drive_label, metadata_file):
for drive_path in self._osutils.get_physical_disks():
if vfat.is_vfat_drive(self._osutils, drive_path):
if vfat.is_vfat_drive(self._osutils, drive_path, drive_label):
LOG.info('Config Drive found on disk %r', drive_path)
vfat.copy_from_vfat_drive(self._osutils, drive_path,
self.target_path)

View File

@ -329,8 +329,8 @@ class TestWindowsConfigDriveManager(unittest.TestCase):
self.osutils.get_physical_disks.assert_called_once_with()
expected_is_vfat_calls = [
mock.call(self.osutils, mock.sentinel.drive1),
mock.call(self.osutils, mock.sentinel.drive2),
mock.call(self.osutils, mock.sentinel.drive1, self._fake_label),
mock.call(self.osutils, mock.sentinel.drive2, self._fake_label),
]
self.assertEqual(expected_is_vfat_calls, mock_is_vfat_drive.mock_calls)
mock_copy_from_vfat_drive.assert_called_once_with(

View File

@ -31,7 +31,8 @@ class TestVfat(unittest.TestCase):
def _test_is_vfat_drive(self, execute_process_value,
expected_logging,
expected_response):
expected_response,
drive_label='config-2'):
mock_osutils = mock.Mock()
mock_osutils.execute_process.return_value = execute_process_value
@ -41,7 +42,8 @@ class TestVfat(unittest.TestCase):
with testutils.ConfPatcher('mtools_path', 'mtools_path'):
response = vfat.is_vfat_drive(mock_osutils,
mock.sentinel.drive)
mock.sentinel.drive,
drive_label)
mdir = os.path.join(CONF.mtools_path, "mlabel.exe")
mock_osutils.execute_process.assert_called_once_with(
@ -105,6 +107,20 @@ class TestVfat(unittest.TestCase):
expected_logging=expected_logging,
expected_response=expected_response)
def test_is_vfat_drive_works_alternate_drive_label(self):
mock_out = b"Volume label is CIDATA \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,
drive_label='cidata')
def test_is_vfat_drive_with_wrong_label(self):
mock_out = b"Not volu label \r\n"
expected_logging = [
@ -143,7 +159,8 @@ class TestVfat(unittest.TestCase):
def test_is_vfat_drive_mtools_not_given(self):
with self.assertRaises(exception.CloudbaseInitException) as cm:
vfat.is_vfat_drive(mock.sentinel.osutils,
mock.sentinel.target_path)
mock.sentinel.target_path,
mock.sentinel.drive_label)
expected_message = ('"mtools_path" needs to be provided in order '
'to access VFAT drives')
self.assertEqual(expected_message, str(cm.exception.args[0]))

View File

@ -22,7 +22,6 @@ from cloudbaseinit import exception
CONF = cloudbaseinit_conf.CONF
CONFIG_DRIVE_LABELS = ['config-2', 'CONFIG-2']
LOG = oslo_logging.getLogger(__name__)
VOLUME_LABEL_REGEX = re.compile("Volume label is (.*?)$")
@ -34,7 +33,7 @@ def _check_mtools_path():
'to access VFAT drives')
def is_vfat_drive(osutils, drive_path):
def is_vfat_drive(osutils, drive_path, drive_label):
"""Check if the given drive contains a VFAT filesystem."""
_check_mtools_path()
mlabel = os.path.join(CONF.mtools_path, "mlabel.exe")
@ -50,7 +49,8 @@ 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) in CONFIG_DRIVE_LABELS if match else False
drive_labels = [drive_label.lower(), drive_label.upper()]
return match.group(1) in drive_labels if match else False
def copy_from_vfat_drive(osutils, drive_path, target_path):