From 4f6185139c86c3bfe5536b0644f8c5b57510542b Mon Sep 17 00:00:00 2001 From: Caio Carrara Date: Wed, 29 Aug 2018 14:10:01 -0300 Subject: [PATCH] Enables pylint W1201 This pylint check makes sure the log message is not built in log statement itself, but uses the proper argument from logger to do it lazy. Signed-off-by: Caio Carrara --- avocado/core/job.py | 10 +++++----- avocado/core/output.py | 3 +-- avocado/core/runner.py | 5 +++-- avocado/core/sysinfo.py | 2 +- avocado/plugins/config.py | 14 +++++++------- avocado/utils/asset.py | 4 ++-- avocado/utils/data_factory.py | 4 ++-- avocado/utils/download.py | 2 +- avocado/utils/genio.py | 2 +- avocado/utils/lv_utils.py | 12 ++++++------ avocado/utils/memory.py | 4 ++-- avocado/utils/software_manager.py | 2 +- .../html/avocado_result_html/__init__.py | 2 +- .../resultsdb/avocado_resultsdb/__init__.py | 4 ++-- selftests/checkall | 2 +- 15 files changed, 36 insertions(+), 36 deletions(-) diff --git a/avocado/core/job.py b/avocado/core/job.py index 58bef90e..1ff79a9c 100644 --- a/avocado/core/job.py +++ b/avocado/core/job.py @@ -402,10 +402,10 @@ class Job(object): def _log_avocado_datadir(self): LOG_JOB.info('Avocado Data Directories:') LOG_JOB.info('') - LOG_JOB.info('base ' + data_dir.get_base_dir()) - LOG_JOB.info('tests ' + data_dir.get_test_dir()) - LOG_JOB.info('data ' + data_dir.get_data_dir()) - LOG_JOB.info('logs ' + self.logdir) + LOG_JOB.info('base %s', data_dir.get_base_dir()) + LOG_JOB.info('tests %s', data_dir.get_test_dir()) + LOG_JOB.info('data %s', data_dir.get_data_dir()) + LOG_JOB.info('logs %s', self.logdir) LOG_JOB.info('') @staticmethod @@ -540,7 +540,7 @@ class Job(object): self.exitcode |= exit_codes.AVOCADO_JOB_FAIL return self.exitcode except exceptions.OptionValidationError as details: - self.log.error('\n' + str(details)) + self.log.error('\n%s', str(details)) self.exitcode |= exit_codes.AVOCADO_JOB_FAIL return self.exitcode diff --git a/avocado/core/output.py b/avocado/core/output.py index 2495aa50..064c5211 100644 --- a/avocado/core/output.py +++ b/avocado/core/output.py @@ -326,8 +326,7 @@ class StdOutput(object): except RuntimeError as details: # Paginator not available logging.getLogger('avocado.app.debug').error("Failed to enable " - "paginator: %s" - % details) + "paginator: %s", details) return self.stdout = self.stderr = paginator diff --git a/avocado/core/runner.py b/avocado/core/runner.py index 8b39fc6c..ab2732ca 100644 --- a/avocado/core/runner.py +++ b/avocado/core/runner.py @@ -378,13 +378,14 @@ class TestRunner(object): return with sigtstp: msg = "ctrl+z pressed, %%s test (%s)" % proc.pid + app_log_msg = '\n%s' % msg if self.sigstopped: - APP_LOG.info("\n" + msg, "resumming") + APP_LOG.info(app_log_msg, "resumming") TEST_LOG.info(msg, "resumming") process.kill_process_tree(proc.pid, signal.SIGCONT, False) self.sigstopped = False else: - APP_LOG.info("\n" + msg, "stopping") + APP_LOG.info(app_log_msg, "stopping") TEST_LOG.info(msg, "stopping") process.kill_process_tree(proc.pid, signal.SIGSTOP, False) self.sigstopped = True diff --git a/avocado/core/sysinfo.py b/avocado/core/sysinfo.py index a7395e8f..c319d8af 100644 --- a/avocado/core/sysinfo.py +++ b/avocado/core/sysinfo.py @@ -213,7 +213,7 @@ class Daemon(Command): stderr=subprocess.STDOUT, shell=False, env=env) except OSError: - log.debug("Not logging %s (command could not be run)" % self.cmd) + log.debug("Not logging %s (command could not be run)", self.cmd) def stop(self): """ diff --git a/avocado/plugins/config.py b/avocado/plugins/config.py index 78f2911e..32e693f3 100644 --- a/avocado/plugins/config.py +++ b/avocado/plugins/config.py @@ -39,11 +39,11 @@ class Config(CLICmd): def run(self, args): LOG_UI.info('Config files read (in order):') for cfg_path in settings.config_paths: - LOG_UI.debug(' %s' % cfg_path) + LOG_UI.debug(' %s', cfg_path) if settings.config_paths_failed: LOG_UI.error('\nConfig files that failed to read:') for cfg_path in settings.config_paths_failed: - LOG_UI.error(' %s' % cfg_path) + LOG_UI.error(' %s', cfg_path) LOG_UI.debug("") if not args.datadir: blength = 0 @@ -66,8 +66,8 @@ class Config(CLICmd): LOG_UI.debug("file to customize values") LOG_UI.debug('') LOG_UI.info('Avocado Data Directories:') - LOG_UI.debug(' base ' + data_dir.get_base_dir()) - LOG_UI.debug(' tests ' + data_dir.get_test_dir()) - LOG_UI.debug(' data ' + data_dir.get_data_dir()) - LOG_UI.debug(' logs ' + data_dir.get_logs_dir()) - LOG_UI.debug(' cache ' + ", ".join(data_dir.get_cache_dirs())) + LOG_UI.debug(' base %s', data_dir.get_base_dir()) + LOG_UI.debug(' tests %s', data_dir.get_test_dir()) + LOG_UI.debug(' data %s', data_dir.get_data_dir()) + LOG_UI.debug(' logs %s', data_dir.get_logs_dir()) + LOG_UI.debug(' cache %s', ", ".join(data_dir.get_cache_dirs())) diff --git a/avocado/utils/asset.py b/avocado/utils/asset.py index 8c35849c..85b42228 100644 --- a/avocado/utils/asset.py +++ b/avocado/utils/asset.py @@ -159,7 +159,7 @@ class Asset(object): return asset_file except: exc_type, exc_value = sys.exc_info()[:2] - log.error('%s: %s' % (exc_type.__name__, exc_value)) + log.error('%s: %s', exc_type.__name__, exc_value) # If we get to this point, we have to download it from a location. # A writable cache directory is then needed. The first available @@ -190,7 +190,7 @@ class Asset(object): return asset_file except: exc_type, exc_value = sys.exc_info()[:2] - log.error('%s: %s' % (exc_type.__name__, exc_value)) + log.error('%s: %s', exc_type.__name__, exc_value) raise EnvironmentError("Failed to fetch %s." % basename) diff --git a/avocado/utils/data_factory.py b/avocado/utils/data_factory.py index 093cd0c3..93106860 100644 --- a/avocado/utils/data_factory.py +++ b/avocado/utils/data_factory.py @@ -82,8 +82,8 @@ def make_dir_and_populate(basedir='/tmp'): os.write(fd, generate_random_string(str_length)) os.close(fd) except OSError as details: - log.error("Failed to generate dir in '%s' and populate: %s" % - (basedir, details)) + log_msg = "Failed to generate dir in '%s' and populate: %s" + log.error(log_msg, basedir, details) return None return path diff --git a/avocado/utils/download.py b/avocado/utils/download.py index 907c7fdc..a2c3cdf5 100644 --- a/avocado/utils/download.py +++ b/avocado/utils/download.py @@ -171,7 +171,7 @@ def get_file(src, dst, permissions=None, hash_expected=None, while not hash_file == hash_expected: hash_file = _verify_hash(_get_file(src, dst, permissions)) if hash_file != hash_expected: - log.error("It seems that dst %s is corrupted" % dst) + log.error("It seems that dst %s is corrupted", dst) download_failures += 1 if download_failures > download_retries: raise EnvironmentError("Failed to retrieve %s. " diff --git a/avocado/utils/genio.py b/avocado/utils/genio.py index 3b7cc5f7..f00a047b 100644 --- a/avocado/utils/genio.py +++ b/avocado/utils/genio.py @@ -99,7 +99,7 @@ def ask(question, auto=False): :rtype: str """ if auto: - log.info("%s (y/n) y" % question) + log.info("%s (y/n) y", question) return "y" return input("%s (y/n) " % question) diff --git a/avocado/utils/lv_utils.py b/avocado/utils/lv_utils.py index ff2806db..1af69477 100644 --- a/avocado/utils/lv_utils.py +++ b/avocado/utils/lv_utils.py @@ -448,8 +448,8 @@ def lv_take_snapshot(vg_name, lv_name, re.search(re.escape(lv_snapshot_name + " [active]"), process.run("lvdisplay", sudo=True).stdout)): # the above conditions detect if merge of snapshot was postponed - LOGGER.debug(("Logical volume %s is still active! " + - "Attempting to deactivate..."), lv_name) + log_msg = "Logical volume %s is still active! Attempting to deactivate..." + LOGGER.debug(log_msg, lv_name) lv_reactivate(vg_name, lv_name) process.run(cmd, sudo=True) else: @@ -491,8 +491,8 @@ def lv_revert(vg_name, lv_name, lv_snapshot_name): if ('Snapshot could not be found' in ex.result.stderr and re.search(active_lv_pattern, lvdisplay_output) or "The Logical volume %s is still active" % lv_name in ex.result.stderr): - LOGGER.debug(("Logical volume %s is still active! " + - "Attempting to deactivate..."), lv_name) + log_msg = "Logical volume %s is still active! Attempting to deactivate..." + LOGGER.debug(log_msg, lv_name) lv_reactivate(vg_name, lv_name) LOGGER.error("Continuing after reactivation") elif 'Snapshot could not be found' in ex.result.stderr: @@ -533,8 +533,8 @@ def lv_reactivate(vg_name, lv_name, timeout=10): process.run("lvchange -ay /dev/%s/%s" % (vg_name, lv_name), sudo=True) time.sleep(timeout) except process.CmdError: - LOGGER.error(("Failed to reactivate %s - please, " + - "nuke the process that uses it first."), lv_name) + log_msg = "Failed to reactivate %s - please, nuke the process that uses it first." + LOGGER.error(log_msg, lv_name) raise LVException("The Logical volume %s is still active" % lv_name) diff --git a/avocado/utils/memory.py b/avocado/utils/memory.py index 9524c803..27e8e756 100644 --- a/avocado/utils/memory.py +++ b/avocado/utils/memory.py @@ -394,7 +394,7 @@ def get_buddy_info(chunk_sizes, nodes="all", zones="all"): re_buddyinfo += "(%s)" % "|".join(nodes.split()) if not re.findall(re_buddyinfo, buddy_info_content): - logging.warn("Can not find Nodes %s" % nodes) + logging.warn("Can not find Nodes %s", nodes) return None re_buddyinfo += r".*?zone\s+" if zones == "all": @@ -402,7 +402,7 @@ def get_buddy_info(chunk_sizes, nodes="all", zones="all"): else: re_buddyinfo += "(%s)" % "|".join(zones.split()) if not re.findall(re_buddyinfo, buddy_info_content): - logging.warn("Can not find zones %s" % zones) + logging.warn("Can not find zones %s", zones) return None re_buddyinfo += r"\s+([\s\d]+)" diff --git a/avocado/utils/software_manager.py b/avocado/utils/software_manager.py index 44b533f2..3828a0c8 100644 --- a/avocado/utils/software_manager.py +++ b/avocado/utils/software_manager.py @@ -662,7 +662,7 @@ class ZypperBackend(RpmBackend): except IndexError: ver = out self.pm_version = ver - log.debug('Zypper version: %s' % self.pm_version) + log.debug('Zypper version: %s', self.pm_version) def install(self, name): """ diff --git a/optional_plugins/html/avocado_result_html/__init__.py b/optional_plugins/html/avocado_result_html/__init__.py index e8093115..fbffdb3a 100644 --- a/optional_plugins/html/avocado_result_html/__init__.py +++ b/optional_plugins/html/avocado_result_html/__init__.py @@ -253,7 +253,7 @@ class HTMLResult(Result): report_contents = v.render('utf8') except UnicodeDecodeError as details: # FIXME: Remove me when UnicodeDecodeError problem is fixed - LOG_UI.critical("\n" + ("-" * 80)) + LOG_UI.critical("\n%s", ("-" * 80)) LOG_UI.critical("HTML failed to render the template: %s\n\n", template) LOG_UI.critical("-" * 80) diff --git a/optional_plugins/resultsdb/avocado_resultsdb/__init__.py b/optional_plugins/resultsdb/avocado_resultsdb/__init__.py index 3cc73602..b2982bd4 100644 --- a/optional_plugins/resultsdb/avocado_resultsdb/__init__.py +++ b/optional_plugins/resultsdb/avocado_resultsdb/__init__.py @@ -162,8 +162,8 @@ class ResultsdbResult(Result): def render(self, result, job): if (getattr(job.args, 'resultsdb_logs', None) is not None and getattr(job.args, 'stdout_claimed_by', None) is None): - LOG_UI.info("JOB URL : %s/%s" % (job.args.resultsdb_logs, - os.path.basename(job.logdir))) + log_msg = "JOB URL : %s/%s" + LOG_UI.info(log_msg, job.args.resultsdb_logs, os.path.basename(job.logdir)) class ResultsdbCLI(CLI): diff --git a/selftests/checkall b/selftests/checkall index bff99aaf..7e664c3c 100755 --- a/selftests/checkall +++ b/selftests/checkall @@ -169,7 +169,7 @@ results_dir_content() { [ "$SKIP_RESULTSDIR_CHECK" ] || RESULTS_DIR_CONTENT="$(ls $RESULTS_DIR 2> /dev/null)" LINT_CMD="inspekt lint --exclude=.git" -PYLINT_ENABLE="--enable R0401,W0101,W0102,W0104,W0105,W0106,W0107,W0108,W0109,W0111,W0120,W0122,W0123,W0124,W0125,W0150,W0199,W0211,W0222,W0232,W0233,W0301,W0312,W0401,W0404,W0406,W0410,W0601,W0602,W0603,W0604,W0611,W0612,W0614,W0622,W0623,W0640,W0711,W1202,W1300,W1301,W1302,W1303,W1304,W1305,W1306,W1307,W1401,W1402,W1501,W1503,W1645" +PYLINT_ENABLE="--enable R0401,W0101,W0102,W0104,W0105,W0106,W0107,W0108,W0109,W0111,W0120,W0122,W0123,W0124,W0125,W0150,W0199,W0211,W0222,W0232,W0233,W0301,W0312,W0401,W0404,W0406,W0410,W0601,W0602,W0603,W0604,W0611,W0612,W0614,W0622,W0623,W0640,W0711,W1201,W1202,W1300,W1301,W1302,W1303,W1304,W1305,W1306,W1307,W1401,W1402,W1501,W1503,W1645" if [ "$AVOCADO_PARALLEL_LINT" ]; then LINT_CMD="$LINT_CMD --parallel=$AVOCADO_PARALLEL_LINT" fi -- GitLab