diff options
author | Alberto Contreras <alberto.contreras@canonical.com> | 2023-03-14 10:36:36 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-14 10:36:36 +0100 |
commit | 8a0feb1ec04b211f9444e0eeaf473b670db475bd (patch) | |
tree | fd7d1a596b5dcd8a9a5b9077004459735218a263 /cloudinit/config | |
parent | 2e697bb0e7f251385e9c227629b78d59e4cfea8b (diff) | |
download | cloud-init-git-8a0feb1ec04b211f9444e0eeaf473b670db475bd.tar.gz |
chore: fix style tip (#2071)
- remove too broad exceptions
- ignore dynamic base types in templater
Diffstat (limited to 'cloudinit/config')
-rw-r--r-- | cloudinit/config/cc_disk_setup.py | 38 | ||||
-rw-r--r-- | cloudinit/config/cc_lxd.py | 4 | ||||
-rw-r--r-- | cloudinit/config/cc_reset_rmc.py | 2 |
3 files changed, 23 insertions, 21 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 diff --git a/cloudinit/config/cc_lxd.py b/cloudinit/config/cc_lxd.py index e692fbd5..06c9f6a6 100644 --- a/cloudinit/config/cc_lxd.py +++ b/cloudinit/config/cc_lxd.py @@ -382,7 +382,7 @@ def bridge_to_debconf(bridge_cfg): debconf["lxd/bridge-domain"] = bridge_cfg.get("domain") else: - raise Exception('invalid bridge mode "%s"' % bridge_cfg.get("mode")) + raise RuntimeError('invalid bridge mode "%s"' % bridge_cfg.get("mode")) return debconf @@ -399,7 +399,7 @@ def bridge_to_cmd(bridge_cfg): return None, cmd_attach if bridge_cfg.get("mode") != "new": - raise Exception('invalid bridge mode "%s"' % bridge_cfg.get("mode")) + raise RuntimeError('invalid bridge mode "%s"' % bridge_cfg.get("mode")) cmd_create = ["network", "create", bridge_name] diff --git a/cloudinit/config/cc_reset_rmc.py b/cloudinit/config/cc_reset_rmc.py index a780e4ff..d687c482 100644 --- a/cloudinit/config/cc_reset_rmc.py +++ b/cloudinit/config/cc_reset_rmc.py @@ -149,4 +149,4 @@ def reset_rmc(): if node_id_after == node_id_before: msg = "New node ID did not get generated." LOG.error(msg) - raise Exception(msg) + raise RuntimeError(msg) |