Skip to content

Commit 983e148

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Accept drives with vFAT label 'cidata' as a configdrive."
2 parents 102cd5a + 9b17eaf commit 983e148

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

cloudbaseinit/metadata/services/osconfigdrive/windows.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def _get_config_drive_from_raw_hdd(self, drive_label, metadata_file):
165165

166166
def _get_config_drive_from_vfat(self, drive_label, metadata_file):
167167
for drive_path in self._osutils.get_physical_disks():
168-
if vfat.is_vfat_drive(self._osutils, drive_path):
168+
if vfat.is_vfat_drive(self._osutils, drive_path, drive_label):
169169
LOG.info('Config Drive found on disk %r', drive_path)
170170
vfat.copy_from_vfat_drive(self._osutils, drive_path,
171171
self.target_path)

cloudbaseinit/tests/metadata/services/osconfigdrive/test_windows.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ def test_get_config_drive_from_vfat(self, mock_is_vfat_drive,
329329
self.osutils.get_physical_disks.assert_called_once_with()
330330

331331
expected_is_vfat_calls = [
332-
mock.call(self.osutils, mock.sentinel.drive1),
333-
mock.call(self.osutils, mock.sentinel.drive2),
332+
mock.call(self.osutils, mock.sentinel.drive1, self._fake_label),
333+
mock.call(self.osutils, mock.sentinel.drive2, self._fake_label),
334334
]
335335
self.assertEqual(expected_is_vfat_calls, mock_is_vfat_drive.mock_calls)
336336
mock_copy_from_vfat_drive.assert_called_once_with(

cloudbaseinit/tests/utils/windows/test_vfat.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class TestVfat(unittest.TestCase):
3131

3232
def _test_is_vfat_drive(self, execute_process_value,
3333
expected_logging,
34-
expected_response):
34+
expected_response,
35+
drive_label='config-2'):
3536

3637
mock_osutils = mock.Mock()
3738
mock_osutils.execute_process.return_value = execute_process_value
@@ -41,7 +42,8 @@ def _test_is_vfat_drive(self, execute_process_value,
4142
with testutils.ConfPatcher('mtools_path', 'mtools_path'):
4243

4344
response = vfat.is_vfat_drive(mock_osutils,
44-
mock.sentinel.drive)
45+
mock.sentinel.drive,
46+
drive_label)
4547

4648
mdir = os.path.join(CONF.mtools_path, "mlabel.exe")
4749
mock_osutils.execute_process.assert_called_once_with(
@@ -105,6 +107,20 @@ def test_is_vfat_drive_works_uppercase(self):
105107
expected_logging=expected_logging,
106108
expected_response=expected_response)
107109

110+
def test_is_vfat_drive_works_alternate_drive_label(self):
111+
mock_out = b"Volume label is CIDATA \r\n"
112+
expected_logging = [
113+
"Obtained label information for drive %r: %r"
114+
% (mock.sentinel.drive, mock_out)
115+
]
116+
execute_process_value = (mock_out, None, 0)
117+
expected_response = True
118+
119+
self._test_is_vfat_drive(execute_process_value=execute_process_value,
120+
expected_logging=expected_logging,
121+
expected_response=expected_response,
122+
drive_label='cidata')
123+
108124
def test_is_vfat_drive_with_wrong_label(self):
109125
mock_out = b"Not volu label \r\n"
110126
expected_logging = [
@@ -143,7 +159,8 @@ def test_copy(self, mock_os_chdir):
143159
def test_is_vfat_drive_mtools_not_given(self):
144160
with self.assertRaises(exception.CloudbaseInitException) as cm:
145161
vfat.is_vfat_drive(mock.sentinel.osutils,
146-
mock.sentinel.target_path)
162+
mock.sentinel.target_path,
163+
mock.sentinel.drive_label)
147164
expected_message = ('"mtools_path" needs to be provided in order '
148165
'to access VFAT drives')
149166
self.assertEqual(expected_message, str(cm.exception.args[0]))

cloudbaseinit/utils/windows/vfat.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323

2424
CONF = cloudbaseinit_conf.CONF
25-
CONFIG_DRIVE_LABELS = ['config-2', 'CONFIG-2']
2625
LOG = oslo_logging.getLogger(__name__)
2726
VOLUME_LABEL_REGEX = re.compile("Volume label is (.*?)$")
2827

@@ -34,7 +33,7 @@ def _check_mtools_path():
3433
'to access VFAT drives')
3534

3635

37-
def is_vfat_drive(osutils, drive_path):
36+
def is_vfat_drive(osutils, drive_path, drive_label):
3837
"""Check if the given drive contains a VFAT filesystem."""
3938
_check_mtools_path()
4039
mlabel = os.path.join(CONF.mtools_path, "mlabel.exe")
@@ -50,7 +49,8 @@ def is_vfat_drive(osutils, drive_path):
5049
LOG.debug("Obtained label information for drive %r: %r", drive_path, out)
5150
out = out.decode().strip()
5251
match = VOLUME_LABEL_REGEX.search(out)
53-
return match.group(1) in CONFIG_DRIVE_LABELS if match else False
52+
drive_labels = [drive_label.lower(), drive_label.upper()]
53+
return match.group(1) in drive_labels if match else False
5454

5555

5656
def copy_from_vfat_drive(osutils, drive_path, target_path):

0 commit comments

Comments
 (0)