Skip to content

Commit 8dbb93f

Browse files
committed
config_drive: ensure the search locations are ordered alphabetically
The internal Python implementation for the configured config drive search locations is not deterministic. Make it deterministic by using alphabetically sorted order. In this case, the search order becomes: - type: iso, vfat - location: cdrom, hdd, partition Change-Id: I622700c9408d3acee6d44eabfd73c662df7e7cfd Signed-off-by: Adrian Vladu <avladu@cloudbasesolutions.com>
1 parent 7e153cd commit 8dbb93f

3 files changed

Lines changed: 34 additions & 27 deletions

File tree

cloudbaseinit/constant.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@
1313
# under the License.
1414

1515
# Config Drive types and possible locations.
16-
CD_TYPES = {
17-
"vfat", # Visible device (with partition table).
16+
CD_TYPES = sorted({
1817
"iso", # "Raw" format containing ISO bytes.
19-
}
20-
CD_LOCATIONS = {
21-
# Look into optical devices. Only an ISO format could be
22-
# used here (vfat ignored).
23-
"cdrom",
24-
# Search through physical disks for raw ISO content or vfat filesystems
25-
# containing configuration drive's content.
26-
"hdd",
18+
"vfat", # Visible device (with partition table).
19+
})
20+
CD_LOCATIONS = sorted({
2721
# Search through partitions for raw ISO content or through volumes
2822
# containing configuration drive's content.
2923
"partition",
30-
}
24+
# Search through physical disks for raw ISO content or vfat filesystems
25+
# containing configuration drive's content.
26+
"hdd",
27+
# Look into optical devices. Only an ISO format could be
28+
# used here (vfat ignored).
29+
"cdrom",
30+
})
3131

3232
POLICY_IGNORE_ALL_FAILURES = "ignoreallfailures"
3333

cloudbaseinit/metadata/services/baseconfigdrive.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,31 +39,38 @@ def __init__(self, drive_label, metadata_file,
3939
self._metadata_file = metadata_file
4040
self._userdata_file = userdata_file
4141
self._metadata_path = None
42-
self._searched_types = set()
43-
self._searched_locations = set()
42+
self._searched_types = list()
43+
self._searched_locations = list()
4444

4545
def _preprocess_options(self):
46-
self._searched_types = set(CONF.config_drive.types)
47-
self._searched_locations = set(CONF.config_drive.locations)
46+
self._searched_types = sorted(set(CONF.config_drive.types))
47+
self._searched_locations = sorted(set(CONF.config_drive.locations))
4848

4949
# Deprecation backward compatibility.
50-
if CONF.config_drive.raw_hdd:
51-
self._searched_types.add("iso")
52-
self._searched_locations.add("hdd")
5350
if CONF.config_drive.cdrom:
54-
self._searched_types.add("iso")
55-
self._searched_locations.add("cdrom")
51+
self._searched_types.append("iso")
52+
self._searched_locations.append("cdrom")
53+
if CONF.config_drive.raw_hdd:
54+
self._searched_types.append("iso")
55+
self._searched_locations.append("hdd")
5656
if CONF.config_drive.vfat:
57-
self._searched_types.add("vfat")
58-
self._searched_locations.add("hdd")
57+
self._searched_types.append("vfat")
58+
self._searched_locations.append("hdd")
5959

6060
# Check for invalid option values.
61-
if self._searched_types | CD_TYPES != CD_TYPES:
61+
SCD_TYPES = set(CD_TYPES)
62+
if set(self._searched_types) | SCD_TYPES != SCD_TYPES:
6263
raise exception.CloudbaseInitException(
6364
"Invalid Config Drive types %s", self._searched_types)
64-
if self._searched_locations | CD_LOCATIONS != CD_LOCATIONS:
65+
SCD_LOCATIONS = set(CD_LOCATIONS)
66+
if set(self._searched_locations) | SCD_LOCATIONS != SCD_LOCATIONS:
6567
raise exception.CloudbaseInitException(
6668
"Invalid Config Drive locations %s", self._searched_locations)
69+
# Note(avladu): sort the order of the searched locations
70+
# This is needed to be sure that the order is respected
71+
# See: https://github.com/cloudbase/cloudbase-init/issues/200
72+
self._searched_types = sorted(set(self._searched_types))
73+
self._searched_locations = sorted(set(self._searched_locations))
6774

6875
def load(self):
6976
super(BaseConfigDriveService, self).load()

cloudbaseinit/tests/metadata/services/test_baseconfigdrive.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,17 @@ def _test_preprocess_options(self, fail=False):
7070
"cdrom": False,
7171
"vfat": True,
7272
# Deprecated options above.
73-
"types": ["vfat", "iso"],
73+
"types": ["iso", "vfat"],
7474
"locations": ["partition"]
7575
}
7676
contexts = [testutils.ConfPatcher(key, value, group="config_drive")
7777
for key, value in options.items()]
7878
with contexts[0], contexts[1], contexts[2], \
7979
contexts[3], contexts[4]:
8080
self._config_drive._preprocess_options()
81-
self.assertEqual({"vfat", "iso"},
81+
self.assertEqual(["iso", "vfat"],
8282
self._config_drive._searched_types)
83-
self.assertEqual({"hdd", "partition"},
83+
self.assertEqual(["hdd", "partition"],
8484
self._config_drive._searched_locations)
8585

8686
def test_preprocess_options_fail(self):

0 commit comments

Comments
 (0)