Skip to content

Commit

Permalink
Merge branch 'main' into photon
Browse files Browse the repository at this point in the history
  • Loading branch information
sshedi committed Aug 3, 2021
2 parents 850cb4d + 758acf9 commit 7bd4fbc
Show file tree
Hide file tree
Showing 6 changed files with 225 additions and 147 deletions.
13 changes: 10 additions & 3 deletions cloudinit/config/cc_disk_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,15 @@ def handle(_name, cfg, cloud, log, _args):
See doc/examples/cloud-config-disk-setup.txt for documentation on the
format.
"""
device_aliases = cfg.get("device_aliases", {})

def alias_to_device(cand):
name = device_aliases.get(cand)
return cloud.device_name_to_device(name or cand) or name

disk_setup = cfg.get("disk_setup")
if isinstance(disk_setup, dict):
update_disk_setup_devices(disk_setup, cloud.device_name_to_device)
update_disk_setup_devices(disk_setup, alias_to_device)
log.debug("Partitioning disks: %s", str(disk_setup))
for disk, definition in disk_setup.items():
if not isinstance(definition, dict):
Expand All @@ -145,7 +151,7 @@ def handle(_name, cfg, cloud, log, _args):
fs_setup = cfg.get("fs_setup")
if isinstance(fs_setup, list):
log.debug("setting up filesystems: %s", str(fs_setup))
update_fs_setup_devices(fs_setup, cloud.device_name_to_device)
update_fs_setup_devices(fs_setup, alias_to_device)
for definition in fs_setup:
if not isinstance(definition, dict):
log.warning("Invalid file system definition: %s" % definition)
Expand Down Expand Up @@ -174,7 +180,8 @@ def update_disk_setup_devices(disk_setup, tformer):
del disk_setup[transformed]

disk_setup[transformed] = disk_setup[origname]
disk_setup[transformed]['_origname'] = origname
if isinstance(disk_setup[transformed], dict):
disk_setup[transformed]['_origname'] = origname
del disk_setup[origname]
LOG.debug("updated disk_setup device entry '%s' to '%s'",
origname, transformed)
Expand Down
17 changes: 13 additions & 4 deletions cloudinit/config/cc_mounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def _is_block_device(device_path, partition_path=None):
return os.path.exists(sys_path)


def sanitize_devname(startname, transformer, log):
def sanitize_devname(startname, transformer, log, aliases=None):
log.debug("Attempting to determine the real name of %s", startname)

# workaround, allow user to specify 'ephemeral'
Expand All @@ -137,9 +137,14 @@ def sanitize_devname(startname, transformer, log):
return startname

device_path, partition_number = util.expand_dotted_devname(devname)
orig = device_path

if aliases:
device_path = aliases.get(device_path, device_path)
if orig != device_path:
log.debug("Mapped device alias %s to %s", orig, device_path)

if is_meta_device_name(device_path):
orig = device_path
device_path = transformer(device_path)
if not device_path:
return None
Expand Down Expand Up @@ -394,6 +399,8 @@ def handle(_name, cfg, cloud, log, _args):
fstab_devs[toks[0]] = line
fstab_lines.append(line)

device_aliases = cfg.get("device_aliases", {})

for i in range(len(cfgmnt)):
# skip something that wasn't a list
if not isinstance(cfgmnt[i], list):
Expand All @@ -402,7 +409,8 @@ def handle(_name, cfg, cloud, log, _args):
continue

start = str(cfgmnt[i][0])
sanitized = sanitize_devname(start, cloud.device_name_to_device, log)
sanitized = sanitize_devname(start, cloud.device_name_to_device, log,
aliases=device_aliases)
if sanitized != start:
log.debug("changed %s => %s" % (start, sanitized))

Expand Down Expand Up @@ -444,7 +452,8 @@ def handle(_name, cfg, cloud, log, _args):
# entry has the same device name
for defmnt in defmnts:
start = defmnt[0]
sanitized = sanitize_devname(start, cloud.device_name_to_device, log)
sanitized = sanitize_devname(start, cloud.device_name_to_device, log,
aliases=device_aliases)
if sanitized != start:
log.debug("changed default device %s => %s" % (start, sanitized))

Expand Down
140 changes: 0 additions & 140 deletions tests/integration_tests/bugs/test_lp1920939.py

This file was deleted.

Loading

0 comments on commit 7bd4fbc

Please sign in to comment.