summaryrefslogtreecommitdiff
path: root/cloudinit/config/cc_disk_setup.py
diff options
context:
space:
mode:
Diffstat (limited to 'cloudinit/config/cc_disk_setup.py')
-rw-r--r--cloudinit/config/cc_disk_setup.py38
1 files changed, 20 insertions, 18 deletions
diff --git a/cloudinit/config/cc_disk_setup.py b/cloudinit/config/cc_disk_setup.py
index 4aae5530..ecaca079 100644
--- a/cloudinit/config/cc_disk_setup.py
+++ b/cloudinit/config/cc_disk_setup.py
@@ -274,7 +274,7 @@ def enumerate_disk(device, nodeps=False):
try:
info, _err = subp.subp(lsblk_cmd)
except Exception as e:
- raise Exception(
+ raise RuntimeError(
"Failed during disk check for %s\n%s" % (device, e)
) from e
@@ -338,7 +338,7 @@ def check_fs(device):
try:
out, _err = subp.subp(blkid_cmd, rcs=[0, 2])
except Exception as e:
- raise Exception(
+ raise RuntimeError(
"Failed during disk check for %s\n%s" % (device, e)
) from e
@@ -444,7 +444,7 @@ def get_hdd_size(device):
size_in_bytes, _ = subp.subp([BLKDEV_CMD, "--getsize64", device])
sector_size, _ = subp.subp([BLKDEV_CMD, "--getss", device])
except Exception as e:
- raise Exception("Failed to get %s size\n%s" % (device, e)) from e
+ raise RuntimeError("Failed to get %s size\n%s" % (device, e)) from e
return int(size_in_bytes) / int(sector_size)
@@ -462,7 +462,7 @@ def check_partition_mbr_layout(device, layout):
try:
out, _err = subp.subp(prt_cmd, data="%s\n" % layout)
except Exception as e:
- raise Exception(
+ raise RuntimeError(
"Error running partition command on %s\n%s" % (device, e)
) from e
@@ -493,7 +493,7 @@ def check_partition_gpt_layout(device, layout):
try:
out, _err = subp.subp(prt_cmd, update_env=LANG_C_ENV)
except Exception as e:
- raise Exception(
+ raise RuntimeError(
"Error running partition command on %s\n%s" % (device, e)
) from e
@@ -542,7 +542,7 @@ def check_partition_layout(table_type, device, layout):
elif "mbr" == table_type:
found_layout = check_partition_mbr_layout(device, layout)
else:
- raise Exception("Unable to determine table type")
+ raise RuntimeError("Unable to determine table type")
LOG.debug(
"called check_partition_%s_layout(%s, %s), returned: %s",
@@ -595,11 +595,11 @@ def get_partition_mbr_layout(size, layout):
if (len(layout) == 0 and isinstance(layout, list)) or not isinstance(
layout, list
):
- raise Exception("Partition layout is invalid")
+ raise RuntimeError("Partition layout is invalid")
last_part_num = len(layout)
if last_part_num > 4:
- raise Exception("Only simply partitioning is allowed.")
+ raise RuntimeError("Only simply partitioning is allowed.")
part_definition = []
part_num = 0
@@ -610,7 +610,9 @@ def get_partition_mbr_layout(size, layout):
if isinstance(part, list):
if len(part) != 2:
- raise Exception("Partition was incorrectly defined: %s" % part)
+ raise RuntimeError(
+ "Partition was incorrectly defined: %s" % part
+ )
percent, part_type = part
part_size = int(float(size) * (float(percent) / 100))
@@ -622,7 +624,7 @@ def get_partition_mbr_layout(size, layout):
sfdisk_definition = "\n".join(part_definition)
if len(part_definition) > 4:
- raise Exception(
+ raise RuntimeError(
"Calculated partition definition is too big\n%s"
% sfdisk_definition
)
@@ -638,7 +640,7 @@ def get_partition_gpt_layout(size, layout):
for partition in layout:
if isinstance(partition, list):
if len(partition) != 2:
- raise Exception(
+ raise RuntimeError(
"Partition was incorrectly defined: %s" % partition
)
percent, partition_type = partition
@@ -682,7 +684,7 @@ def purge_disk(device):
LOG.info("Purging filesystem on /dev/%s", d["name"])
subp.subp(wipefs_cmd)
except Exception as e:
- raise Exception(
+ raise RuntimeError(
"Failed FS purge of /dev/%s" % d["name"]
) from e
@@ -702,7 +704,7 @@ def get_partition_layout(table_type, size, layout):
return get_partition_mbr_layout(size, layout)
elif "gpt" == table_type:
return get_partition_gpt_layout(size, layout)
- raise Exception("Unable to determine table type")
+ raise RuntimeError("Unable to determine table type")
def read_parttbl(device):
@@ -733,7 +735,7 @@ def exec_mkpart_mbr(device, layout):
try:
subp.subp(prt_cmd, data="%s\n" % layout)
except Exception as e:
- raise Exception(
+ raise RuntimeError(
"Failed to partition device %s\n%s" % (device, e)
) from e
@@ -816,7 +818,7 @@ def mkpart(device, definition):
# This prevents you from overwriting the device
LOG.debug("Checking if device %s is a valid device", device)
if not is_device_valid(device):
- raise Exception(
+ raise RuntimeError(
"Device {device} is not a disk device!".format(device=device)
)
@@ -849,7 +851,7 @@ def mkpart(device, definition):
elif "gpt" == table_type:
exec_mkpart_gpt(device, part_definition)
else:
- raise Exception("Unable to determine table type")
+ raise RuntimeError("Unable to determine table type")
LOG.debug("Partition table created for %s", device)
@@ -997,7 +999,7 @@ def mkfs(fs_cfg):
# Check that we can create the FS
if not (fs_type or fs_cmd):
- raise Exception(
+ raise RuntimeError(
"No way to create filesystem '{label}'. fs_type or fs_cmd "
"must be set.".format(label=label)
)
@@ -1059,7 +1061,7 @@ def mkfs(fs_cfg):
try:
subp.subp(fs_cmd, shell=shell)
except Exception as e:
- raise Exception("Failed to exec of '%s':\n%s" % (fs_cmd, e)) from e
+ raise RuntimeError("Failed to exec of '%s':\n%s" % (fs_cmd, e)) from e
# vi: ts=4 expandtab