summaryrefslogtreecommitdiff
path: root/cloudinit/config
diff options
context:
space:
mode:
authorParide Legovini <paride.legovini@canonical.com>2020-08-25 17:21:18 +0200
committerGitHub <noreply@github.com>2020-08-25 09:21:18 -0600
commit07104504ab5b30efd2d1f7a8c36effe18b8e5fe0 (patch)
treec441dddd012f81dad39cfe97821d83bc7ee1a82b /cloudinit/config
parent4068137e3ef048d3e2da56a8190f682eb19d501e (diff)
downloadvyos-cloud-init-07104504ab5b30efd2d1f7a8c36effe18b8e5fe0.tar.gz
vyos-cloud-init-07104504ab5b30efd2d1f7a8c36effe18b8e5fe0.zip
tox: bump the pylint version to 2.6.0 in the default run (#544)
Changes: tox: bump the pylint version to 2.6.0 in the default run Fix pylint 2.6.0 W0707 warnings (raise-missing-from)
Diffstat (limited to 'cloudinit/config')
-rw-r--r--cloudinit/config/cc_disk_setup.py36
-rw-r--r--cloudinit/config/cc_growpart.py8
-rw-r--r--cloudinit/config/cc_power_state_change.py12
-rw-r--r--cloudinit/config/cc_rsyslog.py6
-rw-r--r--cloudinit/config/cc_set_hostname.py2
-rw-r--r--cloudinit/config/cc_ubuntu_advantage.py2
-rw-r--r--cloudinit/config/schema.py2
7 files changed, 41 insertions, 27 deletions
diff --git a/cloudinit/config/cc_disk_setup.py b/cloudinit/config/cc_disk_setup.py
index d957cfe3..a7bdc703 100644
--- a/cloudinit/config/cc_disk_setup.py
+++ b/cloudinit/config/cc_disk_setup.py
@@ -251,7 +251,9 @@ def enumerate_disk(device, nodeps=False):
try:
info, _err = subp.subp(lsblk_cmd)
except Exception as e:
- raise Exception("Failed during disk check for %s\n%s" % (device, e))
+ raise Exception(
+ "Failed during disk check for %s\n%s" % (device, e)
+ ) from e
parts = [x for x in (info.strip()).splitlines() if len(x.split()) > 0]
@@ -313,7 +315,9 @@ def check_fs(device):
try:
out, _err = subp.subp(blkid_cmd, rcs=[0, 2])
except Exception as e:
- raise Exception("Failed during disk check for %s\n%s" % (device, e))
+ raise Exception(
+ "Failed during disk check for %s\n%s" % (device, e)
+ ) from e
if out:
if len(out.splitlines()) == 1:
@@ -428,8 +432,8 @@ def get_dyn_func(*args):
else:
return globals()[func_name]
- except KeyError:
- raise Exception("No such function %s to call!" % func_name)
+ except KeyError as e:
+ raise Exception("No such function %s to call!" % func_name) from e
def get_hdd_size(device):
@@ -437,7 +441,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))
+ raise Exception("Failed to get %s size\n%s" % (device, e)) from e
return int(size_in_bytes) / int(sector_size)
@@ -455,8 +459,9 @@ def check_partition_mbr_layout(device, layout):
try:
out, _err = subp.subp(prt_cmd, data="%s\n" % layout)
except Exception as e:
- raise Exception("Error running partition command on %s\n%s" % (
- device, e))
+ raise Exception(
+ "Error running partition command on %s\n%s" % (device, e)
+ ) from e
found_layout = []
for line in out.splitlines():
@@ -485,8 +490,9 @@ 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("Error running partition command on %s\n%s" % (
- device, e))
+ raise Exception(
+ "Error running partition command on %s\n%s" % (device, e)
+ ) from e
out_lines = iter(out.splitlines())
# Skip header. Output looks like:
@@ -657,8 +663,10 @@ def purge_disk(device):
try:
LOG.info("Purging filesystem on /dev/%s", d['name'])
subp.subp(wipefs_cmd)
- except Exception:
- raise Exception("Failed FS purge of /dev/%s" % d['name'])
+ except Exception as e:
+ raise Exception(
+ "Failed FS purge of /dev/%s" % d['name']
+ ) from e
purge_disk_ptable(device)
@@ -700,7 +708,9 @@ def exec_mkpart_mbr(device, layout):
try:
subp.subp(prt_cmd, data="%s\n" % layout)
except Exception as e:
- raise Exception("Failed to partition device %s\n%s" % (device, e))
+ raise Exception(
+ "Failed to partition device %s\n%s" % (device, e)
+ ) from e
read_parttbl(device)
@@ -997,6 +1007,6 @@ 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))
+ raise Exception("Failed to exec of '%s':\n%s" % (fs_cmd, e)) from e
# vi: ts=4 expandtab
diff --git a/cloudinit/config/cc_growpart.py b/cloudinit/config/cc_growpart.py
index c5d93f81..237c3d02 100644
--- a/cloudinit/config/cc_growpart.py
+++ b/cloudinit/config/cc_growpart.py
@@ -148,14 +148,14 @@ class ResizeGrowPart(object):
if e.exit_code != 1:
util.logexc(LOG, "Failed growpart --dry-run for (%s, %s)",
diskdev, partnum)
- raise ResizeFailedException(e)
+ raise ResizeFailedException(e) from e
return (before, before)
try:
subp.subp(["growpart", diskdev, partnum])
except subp.ProcessExecutionError as e:
util.logexc(LOG, "Failed: growpart %s %s", diskdev, partnum)
- raise ResizeFailedException(e)
+ raise ResizeFailedException(e) from e
return (before, get_size(partdev))
@@ -187,14 +187,14 @@ class ResizeGpart(object):
except subp.ProcessExecutionError as e:
if e.exit_code != 0:
util.logexc(LOG, "Failed: gpart recover %s", diskdev)
- raise ResizeFailedException(e)
+ raise ResizeFailedException(e) from e
before = get_size(partdev)
try:
subp.subp(["gpart", "resize", "-i", partnum, diskdev])
except subp.ProcessExecutionError as e:
util.logexc(LOG, "Failed: gpart resize -i %s %s", partnum, diskdev)
- raise ResizeFailedException(e)
+ raise ResizeFailedException(e) from e
# Since growing the FS requires a reboot, make sure we reboot
# first when this module has finished.
diff --git a/cloudinit/config/cc_power_state_change.py b/cloudinit/config/cc_power_state_change.py
index ab953a0d..6fcb8a7d 100644
--- a/cloudinit/config/cc_power_state_change.py
+++ b/cloudinit/config/cc_power_state_change.py
@@ -196,10 +196,11 @@ def load_power_state(cfg, distro_name):
try:
delay = convert_delay(delay, fmt=fmt, scale=scale)
- except ValueError:
+ except ValueError as e:
raise TypeError(
"power_state[delay] must be 'now' or '+m' (minutes)."
- " found '%s'." % delay)
+ " found '%s'." % delay
+ ) from e
args = command + [delay]
if message:
@@ -207,9 +208,10 @@ def load_power_state(cfg, distro_name):
try:
timeout = float(pstate.get('timeout', 30.0))
- except ValueError:
- raise ValueError("failed to convert timeout '%s' to float." %
- pstate['timeout'])
+ except ValueError as e:
+ raise ValueError(
+ "failed to convert timeout '%s' to float." % pstate['timeout']
+ ) from e
condition = pstate.get("condition", True)
if not isinstance(condition, (str, list, bool)):
diff --git a/cloudinit/config/cc_rsyslog.py b/cloudinit/config/cc_rsyslog.py
index 1354885a..2a2bc931 100644
--- a/cloudinit/config/cc_rsyslog.py
+++ b/cloudinit/config/cc_rsyslog.py
@@ -347,8 +347,10 @@ class SyslogRemotesLine(object):
if self.port:
try:
int(self.port)
- except ValueError:
- raise ValueError("port '%s' is not an integer" % self.port)
+ except ValueError as e:
+ raise ValueError(
+ "port '%s' is not an integer" % self.port
+ ) from e
if not self.addr:
raise ValueError("address is required")
diff --git a/cloudinit/config/cc_set_hostname.py b/cloudinit/config/cc_set_hostname.py
index c13020d8..1d23d80d 100644
--- a/cloudinit/config/cc_set_hostname.py
+++ b/cloudinit/config/cc_set_hostname.py
@@ -85,7 +85,7 @@ def handle(name, cfg, cloud, log, _args):
except Exception as e:
msg = "Failed to set the hostname to %s (%s)" % (fqdn, hostname)
util.logexc(log, msg)
- raise SetHostnameError("%s: %s" % (msg, e))
+ raise SetHostnameError("%s: %s" % (msg, e)) from e
write_json(prev_fn, {'hostname': hostname, 'fqdn': fqdn})
# vi: ts=4 expandtab
diff --git a/cloudinit/config/cc_ubuntu_advantage.py b/cloudinit/config/cc_ubuntu_advantage.py
index 35ded5db..d61dc655 100644
--- a/cloudinit/config/cc_ubuntu_advantage.py
+++ b/cloudinit/config/cc_ubuntu_advantage.py
@@ -115,7 +115,7 @@ def configure_ua(token=None, enable=None):
msg = 'Failure attaching Ubuntu Advantage:\n{error}'.format(
error=str(e))
util.logexc(LOG, msg)
- raise RuntimeError(msg)
+ raise RuntimeError(msg) from e
enable_errors = []
for service in enable:
try:
diff --git a/cloudinit/config/schema.py b/cloudinit/config/schema.py
index 2d8c7577..8a966aee 100644
--- a/cloudinit/config/schema.py
+++ b/cloudinit/config/schema.py
@@ -210,7 +210,7 @@ def validate_cloudconfig_file(config_path, schema, annotate=False):
error = SchemaValidationError(errors)
if annotate:
print(annotated_cloudconfig_file({}, content, error.schema_errors))
- raise error
+ raise error from e
try:
validate_cloudconfig_schema(
cloudconfig, schema, strict=True)