summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorParide Legovini <paride.legovini@canonical.com>2021-07-20 16:58:21 +0200
committerGitHub <noreply@github.com>2021-07-20 09:58:21 -0500
commitec6afadbf0f0f77d5b58dccd70df77da89c2c91d (patch)
tree5f1a719faf924b28cdc2d6958a3b6a8eb2c771bf
parenta984ee78b745b157b4b023a1786bfbd3b2002b88 (diff)
downloadvyos-cloud-init-ec6afadbf0f0f77d5b58dccd70df77da89c2c91d.tar.gz
vyos-cloud-init-ec6afadbf0f0f77d5b58dccd70df77da89c2c91d.zip
Update pylint to v2.9.3 and fix the new issues it spots (#946)
In CI run against pylint 2.9.3 and fix occurrences of: - W0237 (arguments-renamed) - W0402 (deprecated-module) The W0402 deprecated-module was about module `imp`: cloudinit/patcher.py:9: [W0402(deprecated-module), ] Uses of a deprecated module 'imp' The imp module is deprecated and replaced by importlib, which according to the documentation has no replacement for acquire_lock() and release_lock(), which are the only reason why `imp` is imported. Nothing about the code using this lock that actually requires it. Let's remove the locking code and the import altogether. Dropping the locking makes patcher.patch() an empty wrapper around _patch_logging(). Rename _patch_logging() to patch_logging() and call it directly instead. Drop patch().
-rw-r--r--cloudinit/cmd/main.py2
-rwxr-xr-xcloudinit/distros/__init__.py2
-rw-r--r--cloudinit/distros/alpine.py8
-rw-r--r--cloudinit/distros/arch.py8
-rw-r--r--cloudinit/distros/debian.py8
-rw-r--r--cloudinit/distros/gentoo.py8
-rw-r--r--cloudinit/distros/opensuse.py10
-rw-r--r--cloudinit/distros/photon.py6
-rw-r--r--cloudinit/distros/rhel.py8
-rw-r--r--cloudinit/patcher.py11
-rw-r--r--tests/unittests/test_distros/test_create_users.py2
-rw-r--r--tox.ini2
12 files changed, 33 insertions, 42 deletions
diff --git a/cloudinit/cmd/main.py b/cloudinit/cmd/main.py
index 21213a4a..1de1de99 100644
--- a/cloudinit/cmd/main.py
+++ b/cloudinit/cmd/main.py
@@ -19,7 +19,7 @@ import time
import traceback
from cloudinit import patcher
-patcher.patch() # noqa
+patcher.patch_logging()
from cloudinit import log as logging
from cloudinit import netinfo
diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py
index 7bdf2197..40c4f2ac 100755
--- a/cloudinit/distros/__init__.py
+++ b/cloudinit/distros/__init__.py
@@ -147,7 +147,7 @@ class Distro(persistence.CloudInitPickleMixin, metaclass=abc.ABCMeta):
return uses_systemd()
@abc.abstractmethod
- def package_command(self, cmd, args=None, pkgs=None):
+ def package_command(self, command, args=None, pkgs=None):
raise NotImplementedError()
@abc.abstractmethod
diff --git a/cloudinit/distros/alpine.py b/cloudinit/distros/alpine.py
index e4bed5a2..73b68baf 100644
--- a/cloudinit/distros/alpine.py
+++ b/cloudinit/distros/alpine.py
@@ -73,18 +73,18 @@ class Distro(distros.Distro):
self.update_package_sources()
self.package_command('add', pkgs=pkglist)
- def _write_hostname(self, your_hostname, out_fn):
+ def _write_hostname(self, hostname, filename):
conf = None
try:
# Try to update the previous one
# so lets see if we can read it first.
- conf = self._read_hostname_conf(out_fn)
+ conf = self._read_hostname_conf(filename)
except IOError:
pass
if not conf:
conf = HostnameConf('')
- conf.set_hostname(your_hostname)
- util.write_file(out_fn, str(conf), 0o644)
+ conf.set_hostname(hostname)
+ util.write_file(filename, str(conf), 0o644)
def _read_system_hostname(self):
sys_hostname = self._read_hostname(self.hostname_conf_fn)
diff --git a/cloudinit/distros/arch.py b/cloudinit/distros/arch.py
index c9acb11f..3c5bbb38 100644
--- a/cloudinit/distros/arch.py
+++ b/cloudinit/distros/arch.py
@@ -101,18 +101,18 @@ class Distro(distros.Distro):
util.logexc(LOG, "Running interface command %s failed", cmd)
return False
- def _write_hostname(self, your_hostname, out_fn):
+ def _write_hostname(self, hostname, filename):
conf = None
try:
# Try to update the previous one
# so lets see if we can read it first.
- conf = self._read_hostname_conf(out_fn)
+ conf = self._read_hostname_conf(filename)
except IOError:
pass
if not conf:
conf = HostnameConf('')
- conf.set_hostname(your_hostname)
- util.write_file(out_fn, str(conf), omode="w", mode=0o644)
+ conf.set_hostname(hostname)
+ util.write_file(filename, str(conf), omode="w", mode=0o644)
def _read_system_hostname(self):
sys_hostname = self._read_hostname(self.hostname_conf_fn)
diff --git a/cloudinit/distros/debian.py b/cloudinit/distros/debian.py
index 089e0c3e..f2b4dfc9 100644
--- a/cloudinit/distros/debian.py
+++ b/cloudinit/distros/debian.py
@@ -115,18 +115,18 @@ class Distro(distros.Distro):
_maybe_remove_legacy_eth0()
return super()._write_network_state(network_state)
- def _write_hostname(self, your_hostname, out_fn):
+ def _write_hostname(self, hostname, filename):
conf = None
try:
# Try to update the previous one
# so lets see if we can read it first.
- conf = self._read_hostname_conf(out_fn)
+ conf = self._read_hostname_conf(filename)
except IOError:
pass
if not conf:
conf = HostnameConf('')
- conf.set_hostname(your_hostname)
- util.write_file(out_fn, str(conf), 0o644)
+ conf.set_hostname(hostname)
+ util.write_file(filename, str(conf), 0o644)
def _read_system_hostname(self):
sys_hostname = self._read_hostname(self.hostname_conf_fn)
diff --git a/cloudinit/distros/gentoo.py b/cloudinit/distros/gentoo.py
index 68c03e7f..1be76dc8 100644
--- a/cloudinit/distros/gentoo.py
+++ b/cloudinit/distros/gentoo.py
@@ -149,12 +149,12 @@ class Distro(distros.Distro):
else:
return distros.Distro._bring_up_interfaces(self, device_names)
- def _write_hostname(self, your_hostname, out_fn):
+ def _write_hostname(self, hostname, filename):
conf = None
try:
# Try to update the previous one
# so lets see if we can read it first.
- conf = self._read_hostname_conf(out_fn)
+ conf = self._read_hostname_conf(filename)
except IOError:
pass
if not conf:
@@ -163,8 +163,8 @@ class Distro(distros.Distro):
# Many distro's format is the hostname by itself, and that is the
# way HostnameConf works but gentoo expects it to be in
# hostname="the-actual-hostname"
- conf.set_hostname('hostname="%s"' % your_hostname)
- util.write_file(out_fn, str(conf), 0o644)
+ conf.set_hostname('hostname="%s"' % hostname)
+ util.write_file(filename, str(conf), 0o644)
def _read_system_hostname(self):
sys_hostname = self._read_hostname(self.hostname_conf_fn)
diff --git a/cloudinit/distros/opensuse.py b/cloudinit/distros/opensuse.py
index b4193ac2..2a7497cc 100644
--- a/cloudinit/distros/opensuse.py
+++ b/cloudinit/distros/opensuse.py
@@ -150,9 +150,9 @@ class Distro(distros.Distro):
host_fn = self.hostname_conf_fn
return (host_fn, self._read_hostname(host_fn))
- def _write_hostname(self, hostname, out_fn):
- if self.uses_systemd() and out_fn.endswith('/previous-hostname'):
- util.write_file(out_fn, hostname)
+ def _write_hostname(self, hostname, filename):
+ if self.uses_systemd() and filename.endswith('/previous-hostname'):
+ util.write_file(filename, hostname)
elif self.uses_systemd():
subp.subp(['hostnamectl', 'set-hostname', str(hostname)])
else:
@@ -160,13 +160,13 @@ class Distro(distros.Distro):
try:
# Try to update the previous one
# so lets see if we can read it first.
- conf = self._read_hostname_conf(out_fn)
+ conf = self._read_hostname_conf(filename)
except IOError:
pass
if not conf:
conf = HostnameConf('')
conf.set_hostname(hostname)
- util.write_file(out_fn, str(conf), 0o644)
+ util.write_file(filename, str(conf), 0o644)
@property
def preferred_ntp_clients(self):
diff --git a/cloudinit/distros/photon.py b/cloudinit/distros/photon.py
index 0ced7b5f..3ef5dd40 100644
--- a/cloudinit/distros/photon.py
+++ b/cloudinit/distros/photon.py
@@ -83,19 +83,19 @@ class Distro(distros.Distro):
ret, _out, _err = self.exec_cmd(cmd)
return ret
- def _write_hostname(self, hostname, out_fn):
+ def _write_hostname(self, hostname, filename):
conf = None
try:
# Try to update the previous one
# Let's see if we can read it first.
- conf = HostnameConf(util.load_file(out_fn))
+ conf = HostnameConf(util.load_file(filename))
conf.parse()
except IOError:
pass
if not conf:
conf = HostnameConf('')
conf.set_hostname(hostname)
- util.write_file(out_fn, str(conf), mode=0o644)
+ util.write_file(filename, str(conf), mode=0o644)
def _read_system_hostname(self):
sys_hostname = self._read_hostname(self.hostname_conf_fn)
diff --git a/cloudinit/distros/rhel.py b/cloudinit/distros/rhel.py
index be5b3d24..c9ee2747 100644
--- a/cloudinit/distros/rhel.py
+++ b/cloudinit/distros/rhel.py
@@ -78,18 +78,18 @@ class Distro(distros.Distro):
}
rhel_util.update_sysconfig_file(out_fn, locale_cfg)
- def _write_hostname(self, hostname, out_fn):
+ def _write_hostname(self, hostname, filename):
# systemd will never update previous-hostname for us, so
# we need to do it ourselves
- if self.uses_systemd() and out_fn.endswith('/previous-hostname'):
- util.write_file(out_fn, hostname)
+ if self.uses_systemd() and filename.endswith('/previous-hostname'):
+ util.write_file(filename, hostname)
elif self.uses_systemd():
subp.subp(['hostnamectl', 'set-hostname', str(hostname)])
else:
host_cfg = {
'HOSTNAME': hostname,
}
- rhel_util.update_sysconfig_file(out_fn, host_cfg)
+ rhel_util.update_sysconfig_file(filename, host_cfg)
def _read_system_hostname(self):
if self.uses_systemd():
diff --git a/cloudinit/patcher.py b/cloudinit/patcher.py
index 2df9441a..186d8ad8 100644
--- a/cloudinit/patcher.py
+++ b/cloudinit/patcher.py
@@ -6,7 +6,6 @@
#
# This file is part of cloud-init. See LICENSE file for license information.
-import imp
import logging
import sys
@@ -20,7 +19,7 @@ class QuietStreamHandler(logging.StreamHandler):
pass
-def _patch_logging():
+def patch_logging():
# Replace 'handleError' with one that will be more
# tolerant of errors in that it can avoid
# re-notifying on exceptions and when errors
@@ -37,12 +36,4 @@ def _patch_logging():
pass
setattr(logging.Handler, 'handleError', handleError)
-
-def patch():
- imp.acquire_lock()
- try:
- _patch_logging()
- finally:
- imp.release_lock()
-
# vi: ts=4 expandtab
diff --git a/tests/unittests/test_distros/test_create_users.py b/tests/unittests/test_distros/test_create_users.py
index 94ab052d..021866b7 100644
--- a/tests/unittests/test_distros/test_create_users.py
+++ b/tests/unittests/test_distros/test_create_users.py
@@ -23,7 +23,7 @@ class MyBaseDistro(distros.Distro):
def _write_network(self, settings):
raise NotImplementedError()
- def package_command(self, cmd, args=None, pkgs=None):
+ def package_command(self, command, args=None, pkgs=None):
raise NotImplementedError()
def update_package_sources(self):
diff --git a/tox.ini b/tox.ini
index f21e1186..27c16ef3 100644
--- a/tox.ini
+++ b/tox.ini
@@ -23,7 +23,7 @@ setenv =
basepython = python3
deps =
# requirements
- pylint==2.6.0
+ pylint==2.9.3
# test-requirements because unit tests are now present in cloudinit tree
-r{toxinidir}/test-requirements.txt
-r{toxinidir}/integration-requirements.txt