From 8837a2dfe2bf2859e481fa18ca22cda36a44f1ca Mon Sep 17 00:00:00 2001 From: auto-revert-processor Date: Thu, 13 Jul 2023 19:30:15 +0000 Subject: [PATCH] Revert "SERVER-76796 Enable more lint warnings and fix them" This reverts commit 7e0887b55daf8cff8fd9552da38ce95d3faa73a9. --- .pylintrc | 13 +++++++++++++ buildscripts/blackduck_hub.py | 2 +- buildscripts/ciconfig/evergreen.py | 2 +- buildscripts/gdb/optimizer_printers.py | 4 ++-- buildscripts/idl/gen_all_feature_flag_list.py | 2 +- buildscripts/idl/idl/binder.py | 2 +- buildscripts/idl/idl/errors.py | 2 +- .../flask/flask_backend.py | 2 +- buildscripts/linter/mongolint.py | 4 +++- buildscripts/powercycle_operations.py | 2 +- buildscripts/resmoke.py | 2 +- .../resmokelib/hang_analyzer/dumper.py | 2 +- .../resmokelib/hang_analyzer/hang_analyzer.py | 2 +- .../resmokelib/hang_analyzer/process_list.py | 2 +- .../resmokelib/powercycle/lib/__init__.py | 2 +- .../powercycle/lib/remote_operations.py | 2 +- .../resmokelib/powercycle/lib/services.py | 2 +- .../resmokelib/powercycle/powercycle.py | 8 ++++---- .../setup_multiversion/setup_multiversion.py | 2 +- buildscripts/resmokelib/suitesconfig.py | 4 ++-- .../resmokelib/testing/fixtures/_builder.py | 4 ++-- .../resmokelib/testing/fixtures/external.py | 2 +- .../resmokelib/testing/fixtures/interface.py | 2 +- .../resmokelib/testing/fixtures/replicaset.py | 18 ++++++++---------- .../resmokelib/testing/fixtures/shard_merge.py | 2 +- .../resmokelib/testing/fixtures/shard_split.py | 2 +- .../testing/fixtures/shardedcluster.py | 4 ++-- .../resmokelib/testing/fixtures/standalone.py | 2 +- .../fixtures/talk_directly_to_shardsvrs.py | 2 +- .../testing/fixtures/tenant_migration.py | 2 +- .../resmokelib/testing/fixtures/yesfixture.py | 2 +- .../testing/hooks/continuous_initial_sync.py | 15 ++++++++------- .../resmokelib/testing/hooks/initialsync.py | 8 ++++---- .../testing/hooks/periodic_kill_secondaries.py | 6 +++--- .../resmokelib/testing/symbolizer_service.py | 2 +- buildscripts/resmokelib/utils/archival.py | 4 ++-- buildscripts/resmokelib/utils/scheduler.py | 2 -- .../tests/resmokelib/core/test_pipe.py | 16 ++++++++-------- buildscripts/tests/resmokelib/test_selector.py | 8 +++++--- buildscripts/tests/resmokelib/test_undodb.py | 2 +- .../tests/test_exception_exctractor.py | 4 ++-- 41 files changed, 93 insertions(+), 79 deletions(-) diff --git a/.pylintrc b/.pylintrc index 4d5a1f78df5..24d5fd2180e 100644 --- a/.pylintrc +++ b/.pylintrc @@ -13,12 +13,15 @@ variable-rgx=[a-z_][a-z0-9_]{1,50}$ [MESSAGES CONTROL] # C0103 - invalid-name - Fix variable names to match convention +# C0200 - consider-using-enumerate - Prefer enumerate() when you need index and value from an iterable +# C0201 - consider-iterating-dictionary # C0206 - consider-using-dict-items - Need to explicitly specify .keys() or .items() in a dictionary iteration # C0207 - use-maxsplit-arg - Use maxsplit arg in split() calls # C0209 - consider-using-f-string - Need to convert most format strings (using both % and .format) to f""-style strings # C0301 - line-too-long - some of the type annotations are longer then 100 columns # C0325 - superfluous-parens - Superfluous parens, easy to fix # C0330 - bad-continuation - ignore conflicts produced by yapf formatting +# C1803 - use-implicit-booleaness-not-comparison # C2801 - unnecessary-dunder-call - Prefer a builtin call instead of a dunder method # C3001 - unnecessary-lambda-assignment - Prefer def over lambda @@ -33,10 +36,12 @@ variable-rgx=[a-z_][a-z0-9_]{1,50}$ # R0204 - redefined-variable-type # R0205 - useless-object-inheritance - See PM-1380 +# R0402 - consider-using-from-import - Use better convention for module import # R0801 - duplicate-code - See PM-1380 # R0903 - too-few-public-methods - pylint does not always know best # R1705 - no-else-return - sometimes an unnecessary else helps readability # R1710 - inconsistent-return-statements +# R1714 - consider-using-in - Use 'x in [...]' instead # R1720 - no-else-raise - See PM-1380 # R1728 - consider-using-generator - Use a generator instead of creating an in-memory list # R1730 - consider-using-min-builtin - Lots of situations where min() can be used to eliminate an if block @@ -59,6 +64,7 @@ variable-rgx=[a-z_][a-z0-9_]{1,50}$ # W0621 - redefined-outer-name - Overriding variable name # W0640 - cell-var-from-loop # W0719 - broad-exception-raised - Should use a more precise exception than `Exception` +# W1406 - redundant-u-string-prefix # W1505 - deprecated-method - See PM-1380 # W1514 - unspecified-encoding - Need to add 'encoding="utf-8"' to most open() operations # W3101 - missing-timeout - Add an explicit timeout to some sync functions @@ -70,8 +76,12 @@ disable= broad-exception-raised, cell-var-from-loop, consider-using-dict-items, + consider-using-enumerate, consider-using-f-string, + consider-using-from-import, consider-using-generator, + consider-using-in, + consider-iterating-dictionary, consider-using-max-builtin, consider-using-min-builtin, consider-using-with, @@ -103,6 +113,7 @@ disable= no-name-in-module, protected-access, raise-missing-from, + redundant-u-string-prefix, redefined-outer-name, subprocess-run-check, super-init-not-called, @@ -129,8 +140,10 @@ disable= unused-argument, use-dict-literal, use-list-literal, + use-implicit-booleaness-not-comparison, used-before-assignment, useless-object-inheritance, + useless-suppression, wrong-import-order enable=useless-suppression diff --git a/buildscripts/blackduck_hub.py b/buildscripts/blackduck_hub.py index 299ef719d7e..16b6458e6fd 100644 --- a/buildscripts/blackduck_hub.py +++ b/buildscripts/blackduck_hub.py @@ -1184,7 +1184,7 @@ class Analyzer: # We filter ourself our of the list of components. self.black_duck_components = [ comp for comp in self.black_duck_components - if not (comp.name in ["MongoDB", "WiredTiger"]) + if not (comp.name == "MongoDB" or comp.name == "WiredTiger") ] # Remove duplicate Black Duck components. We only care about the component with highest version number diff --git a/buildscripts/ciconfig/evergreen.py b/buildscripts/ciconfig/evergreen.py index 871e2689ac9..a3a028caabf 100644 --- a/buildscripts/ciconfig/evergreen.py +++ b/buildscripts/ciconfig/evergreen.py @@ -15,7 +15,7 @@ from typing import Set, List, Optional import yaml -from buildscripts.util import runcommand +import buildscripts.util.runcommand as runcommand ENTERPRISE_MODULE_NAME = "enterprise" ASAN_SIGNATURE = "detect_leaks=1" diff --git a/buildscripts/gdb/optimizer_printers.py b/buildscripts/gdb/optimizer_printers.py index f4e0a0f03e9..926e190df1b 100644 --- a/buildscripts/gdb/optimizer_printers.py +++ b/buildscripts/gdb/optimizer_printers.py @@ -892,10 +892,10 @@ class PolyValuePrinter(object): # from the _tag member variable. poly_type = self.val.type.template_argument(self.tag) dynamic_type = "mongo::optimizer::algebra::ControlBlockVTable<" + poly_type.name - for i, val in enumerate(self.type_set): + for i in range(len(self.type_set)): if i < len(self.type_set): dynamic_type += ", " - dynamic_type += self.type_namespace + val + dynamic_type += self.type_namespace + self.type_set[i] dynamic_type += ">::ConcreteType" return dynamic_type diff --git a/buildscripts/idl/gen_all_feature_flag_list.py b/buildscripts/idl/gen_all_feature_flag_list.py index 2506a0ab3c1..1dcc46d11bc 100644 --- a/buildscripts/idl/gen_all_feature_flag_list.py +++ b/buildscripts/idl/gen_all_feature_flag_list.py @@ -41,7 +41,7 @@ import yaml sys.path.append(os.path.normpath(os.path.join(os.path.abspath(__file__), '../../..'))) # pylint: disable=wrong-import-position -from buildscripts.idl import lib +import buildscripts.idl.lib as lib from buildscripts.idl.idl import parser diff --git a/buildscripts/idl/idl/binder.py b/buildscripts/idl/idl/binder.py index 7a2b51529b5..0d75ee91a47 100644 --- a/buildscripts/idl/idl/binder.py +++ b/buildscripts/idl/idl/binder.py @@ -925,7 +925,7 @@ def _bind_expression(expr, allow_literal_string=True): node.export = True # bool - if expr.literal in ["true", "false"]: + if (expr.literal == "true") or (expr.literal == "false"): node.expr = expr.literal return node diff --git a/buildscripts/idl/idl/errors.py b/buildscripts/idl/idl/errors.py index ebb6beba0c7..2cda901647f 100644 --- a/buildscripts/idl/idl/errors.py +++ b/buildscripts/idl/idl/errors.py @@ -358,7 +358,7 @@ class ParserContext(object): if not self._is_node_type(node, node_name, "scalar"): return False - if not node.value in ["true", "false"]: + if not (node.value == "true" or node.value == "false"): self._add_node_error( node, ERROR_ID_IS_NODE_VALID_BOOL, "Illegal bool value for '%s', expected either 'true' or 'false'." % node_name) diff --git a/buildscripts/libdeps/graph_visualizer_web_stack/flask/flask_backend.py b/buildscripts/libdeps/graph_visualizer_web_stack/flask/flask_backend.py index a79f16d05e0..1c106160552 100644 --- a/buildscripts/libdeps/graph_visualizer_web_stack/flask/flask_backend.py +++ b/buildscripts/libdeps/graph_visualizer_web_stack/flask/flask_backend.py @@ -218,7 +218,7 @@ class BackendServer: if "transitive_edges" in req_body.keys() and req_body["transitive_edges"] is True: for node in selected_nodes: for libdep in dependency_graph[str(node)]: - if str(libdep) in nodes: + if str(libdep) in nodes.keys(): add_link_to_graph_data(node, libdep, dependents_graph[libdep][str(node)]) diff --git a/buildscripts/linter/mongolint.py b/buildscripts/linter/mongolint.py index 101fb8431fa..c2edc606eae 100644 --- a/buildscripts/linter/mongolint.py +++ b/buildscripts/linter/mongolint.py @@ -111,7 +111,9 @@ class Linter: def _check_and_strip_comments(self): in_multi_line_comment = False - for linenum, clean_line in enumerate(self.raw_lines): + for linenum in range(len(self.raw_lines)): + clean_line = self.raw_lines[linenum] + # Users can write NOLINT different ways # // NOLINT # // Some explanation NOLINT diff --git a/buildscripts/powercycle_operations.py b/buildscripts/powercycle_operations.py index c602f992a09..7f12835dd19 100644 --- a/buildscripts/powercycle_operations.py +++ b/buildscripts/powercycle_operations.py @@ -9,6 +9,6 @@ if __name__ == "__main__" and __package__ is None: sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) # pylint: disable=wrong-import-position -from buildscripts.powercycle_setup import cli +import buildscripts.powercycle_setup.cli as cli cli.main(sys.argv) diff --git a/buildscripts/resmoke.py b/buildscripts/resmoke.py index 49f3af8c34d..4f45b893ea7 100755 --- a/buildscripts/resmoke.py +++ b/buildscripts/resmoke.py @@ -9,7 +9,7 @@ if __name__ == "__main__" and __package__ is None: sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) # pylint: disable=wrong-import-position -from buildscripts.resmokelib import cli +import buildscripts.resmokelib.cli as cli def entrypoint(): diff --git a/buildscripts/resmokelib/hang_analyzer/dumper.py b/buildscripts/resmokelib/hang_analyzer/dumper.py index fdbe7211757..7a3d5071168 100644 --- a/buildscripts/resmokelib/hang_analyzer/dumper.py +++ b/buildscripts/resmokelib/hang_analyzer/dumper.py @@ -30,7 +30,7 @@ def get_dumpers(root_logger: logging.Logger, dbg_output: str): if sys.platform.startswith("linux"): dbg = GDBDumper(root_logger, dbg_output) jstack = JstackDumper() - elif sys.platform in ["win32", "cygwin"]: + elif sys.platform == "win32" or sys.platform == "cygwin": dbg = WindowsDumper(root_logger, dbg_output) jstack = JstackWindowsDumper() elif sys.platform == "darwin": diff --git a/buildscripts/resmokelib/hang_analyzer/hang_analyzer.py b/buildscripts/resmokelib/hang_analyzer/hang_analyzer.py index ef6eef10450..28dc4248467 100755 --- a/buildscripts/resmokelib/hang_analyzer/hang_analyzer.py +++ b/buildscripts/resmokelib/hang_analyzer/hang_analyzer.py @@ -210,7 +210,7 @@ class HangAnalyzer(Subcommand): self.root_logger.info("OS: %s", platform.platform()) try: - if sys.platform in ["win32", "cygwin"]: + if sys.platform == "win32" or sys.platform == "cygwin": self.root_logger.info("Windows Distribution: %s", platform.win32_ver()) else: self.root_logger.info("Linux Distribution: %s", distro.linux_distribution()) diff --git a/buildscripts/resmokelib/hang_analyzer/process_list.py b/buildscripts/resmokelib/hang_analyzer/process_list.py index c6d43fb9fba..4704e7ba5cc 100644 --- a/buildscripts/resmokelib/hang_analyzer/process_list.py +++ b/buildscripts/resmokelib/hang_analyzer/process_list.py @@ -82,7 +82,7 @@ def _get_lister(): """Return _ProcessList object for OS.""" if sys.platform.startswith("linux"): ps = _LinuxProcessList() - elif sys.platform in ["win32", "cygwin"]: + elif sys.platform == "win32" or sys.platform == "cygwin": ps = _WindowsProcessList() elif sys.platform == "darwin": ps = _DarwinProcessList() diff --git a/buildscripts/resmokelib/powercycle/lib/__init__.py b/buildscripts/resmokelib/powercycle/lib/__init__.py index 6a57cf48f61..bdb177189b3 100644 --- a/buildscripts/resmokelib/powercycle/lib/__init__.py +++ b/buildscripts/resmokelib/powercycle/lib/__init__.py @@ -39,7 +39,7 @@ class PowercycleCommand(Subcommand): @staticmethod def is_windows() -> bool: """:return: True if running on Windows.""" - return sys.platform in ["win32", "cygwin"] + return sys.platform == "win32" or sys.platform == "cygwin" @staticmethod def _call(cmd): diff --git a/buildscripts/resmokelib/powercycle/lib/remote_operations.py b/buildscripts/resmokelib/powercycle/lib/remote_operations.py index 97e4bcd98df..6d4405e6bd3 100644 --- a/buildscripts/resmokelib/powercycle/lib/remote_operations.py +++ b/buildscripts/resmokelib/powercycle/lib/remote_operations.py @@ -14,7 +14,7 @@ import textwrap if __name__ == "__main__" and __package__ is None: sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) -_IS_WINDOWS = sys.platform in ["win32", "cygwin"] +_IS_WINDOWS = sys.platform == "win32" or sys.platform == "cygwin" _SSH_CONNECTION_ERRORS = [ "Connection refused", diff --git a/buildscripts/resmokelib/powercycle/lib/services.py b/buildscripts/resmokelib/powercycle/lib/services.py index be1a71964a4..2cd1cc4c959 100644 --- a/buildscripts/resmokelib/powercycle/lib/services.py +++ b/buildscripts/resmokelib/powercycle/lib/services.py @@ -7,7 +7,7 @@ import time from buildscripts.resmokelib.powercycle.lib.process_control import ProcessControl from buildscripts.resmokelib.powercycle.lib import execute_cmd -_IS_WINDOWS = sys.platform in ["win32", "cygwin"] +_IS_WINDOWS = sys.platform == "win32" or sys.platform == "cygwin" def _try_import(module, name=None): diff --git a/buildscripts/resmokelib/powercycle/powercycle.py b/buildscripts/resmokelib/powercycle/powercycle.py index 672cf3c77f5..20c4b3feb24 100755 --- a/buildscripts/resmokelib/powercycle/powercycle.py +++ b/buildscripts/resmokelib/powercycle/powercycle.py @@ -38,7 +38,7 @@ from buildscripts.resmokelib.powercycle import powercycle_config, powercycle_con from buildscripts.resmokelib.powercycle.lib.services import WindowsService, PosixService from buildscripts.resmokelib.utils.filesystem import build_hygienic_bin_path -_IS_WINDOWS = sys.platform in ["win32", "cygwin"] +_IS_WINDOWS = sys.platform == "win32" or sys.platform == "cygwin" _IS_LINUX = sys.platform.startswith("linux") _IS_DARWIN = sys.platform == "darwin" @@ -192,7 +192,7 @@ def dump_stacks_and_exit(signum, frame): # pylint: disable=unused-argument LOGGER.info("Dumping stacks!") sb = [] - frames = sys._current_frames() + frames = sys._current_frames() # pylint: disable=protected-access sb.append("Total threads: {}\n".format(len(frames))) sb.append("") @@ -205,7 +205,7 @@ def dump_stacks_and_exit(signum, frame): # pylint: disable=unused-argument if _IS_WINDOWS: exit_handler() - os._exit(1) + os._exit(1) # pylint: disable=protected-access else: sys.exit(1) @@ -1060,7 +1060,7 @@ def crash_server_or_kill_mongod(task_config, crash_canary, local_ops, script_nam LOGGER.info("%s in %d seconds", message_prefix, crash_wait_time) time.sleep(crash_wait_time) - if task_config.crash_method in ["internal", "kill"]: + if task_config.crash_method == "internal" or task_config.crash_method == "kill": crash_cmd = "crash_server" if task_config.crash_method == "internal" else "kill_mongod" crash_func = local_ops.shell remote_python = get_remote_python() diff --git a/buildscripts/resmokelib/setup_multiversion/setup_multiversion.py b/buildscripts/resmokelib/setup_multiversion/setup_multiversion.py index 5137dd51b4f..b26277099ed 100644 --- a/buildscripts/resmokelib/setup_multiversion/setup_multiversion.py +++ b/buildscripts/resmokelib/setup_multiversion/setup_multiversion.py @@ -178,7 +178,7 @@ class SetupMultiversion(Subcommand): " this error, please reach out in #server-testing slack channel.") exit(1) try: - from buildscripts.resmokelib import multiversionconstants + import buildscripts.resmokelib.multiversionconstants as multiversionconstants except ImportError: self.logger.error("Could not import `buildscripts.resmokelib.multiversionconstants`.") self.logger.error( diff --git a/buildscripts/resmokelib/suitesconfig.py b/buildscripts/resmokelib/suitesconfig.py index 89d467c2ab0..a6ea326288b 100644 --- a/buildscripts/resmokelib/suitesconfig.py +++ b/buildscripts/resmokelib/suitesconfig.py @@ -9,7 +9,7 @@ from typing import Dict, List import yaml import buildscripts.resmokelib.utils.filesystem as fs -from buildscripts.resmokelib.logging import loggers +import buildscripts.resmokelib.logging.loggers as loggers from buildscripts.resmokelib import config as _config, errors, utils from buildscripts.resmokelib.testing import suite as _suite from buildscripts.resmokelib.utils import load_yaml_file @@ -358,7 +358,7 @@ class MatrixSuiteConfig(SuiteConfigInterface): """Get the mapping object for a given suite name and directory to search for suite mappings.""" all_matrix_suites = cls.get_all_mappings(suites_dir) - if suite_name in all_matrix_suites: + if suite_name in all_matrix_suites.keys(): return all_matrix_suites[suite_name] return None diff --git a/buildscripts/resmokelib/testing/fixtures/_builder.py b/buildscripts/resmokelib/testing/fixtures/_builder.py index 8be6446d208..7fa3fe75434 100644 --- a/buildscripts/resmokelib/testing/fixtures/_builder.py +++ b/buildscripts/resmokelib/testing/fixtures/_builder.py @@ -4,8 +4,8 @@ import threading from abc import ABC, abstractmethod from typing import Any, Dict, List, Optional, Tuple, Type -from buildscripts.resmokelib import config -from buildscripts.resmokelib.utils import registry +import buildscripts.resmokelib.config as config +import buildscripts.resmokelib.utils.registry as registry from buildscripts.resmokelib import errors from buildscripts.resmokelib.testing.fixtures.fixturelib import FixtureLib from buildscripts.resmokelib.testing.fixtures.interface import _FIXTURES diff --git a/buildscripts/resmokelib/testing/fixtures/external.py b/buildscripts/resmokelib/testing/fixtures/external.py index e15776b667e..9388ff61826 100644 --- a/buildscripts/resmokelib/testing/fixtures/external.py +++ b/buildscripts/resmokelib/testing/fixtures/external.py @@ -1,6 +1,6 @@ """External fixture for executing JSTests against.""" -from buildscripts.resmokelib.testing.fixtures import interface +import buildscripts.resmokelib.testing.fixtures.interface as interface class ExternalFixture(interface.Fixture): diff --git a/buildscripts/resmokelib/testing/fixtures/interface.py b/buildscripts/resmokelib/testing/fixtures/interface.py index 93022c4c278..1f9bf738fca 100644 --- a/buildscripts/resmokelib/testing/fixtures/interface.py +++ b/buildscripts/resmokelib/testing/fixtures/interface.py @@ -9,7 +9,7 @@ from typing import List import pymongo import pymongo.errors -from buildscripts.resmokelib.utils import registry +import buildscripts.resmokelib.utils.registry as registry _VERSIONS = {} # type: ignore diff --git a/buildscripts/resmokelib/testing/fixtures/replicaset.py b/buildscripts/resmokelib/testing/fixtures/replicaset.py index e87f860ebf7..9ea3d2fa0a6 100644 --- a/buildscripts/resmokelib/testing/fixtures/replicaset.py +++ b/buildscripts/resmokelib/testing/fixtures/replicaset.py @@ -9,7 +9,7 @@ import pymongo import pymongo.errors import pymongo.write_concern -from buildscripts.resmokelib.testing.fixtures import interface +import buildscripts.resmokelib.testing.fixtures.interface as interface def compare_timestamp(timestamp1, timestamp2): @@ -240,14 +240,12 @@ class ReplicaSetFixture(interface.ReplFixture): # (potentially) higher config version. We should not receive these codes # indefinitely. # pylint: disable=too-many-boolean-expressions - if err.code not in [ - ReplicaSetFixture._NEW_REPLICA_SET_CONFIGURATION_INCOMPATIBLE, - ReplicaSetFixture._CURRENT_CONFIG_NOT_COMMITTED_YET, - ReplicaSetFixture._CONFIGURATION_IN_PROGRESS, - ReplicaSetFixture._NODE_NOT_FOUND, - ReplicaSetFixture._INTERRUPTED_DUE_TO_REPL_STATE_CHANGE, - ReplicaSetFixture._INTERRUPTED_DUE_TO_STORAGE_CHANGE - ]: + if (err.code != ReplicaSetFixture._NEW_REPLICA_SET_CONFIGURATION_INCOMPATIBLE + and err.code != ReplicaSetFixture._CURRENT_CONFIG_NOT_COMMITTED_YET + and err.code != ReplicaSetFixture._CONFIGURATION_IN_PROGRESS + and err.code != ReplicaSetFixture._NODE_NOT_FOUND + and err.code != ReplicaSetFixture._INTERRUPTED_DUE_TO_REPL_STATE_CHANGE + and err.code != ReplicaSetFixture._INTERRUPTED_DUE_TO_STORAGE_CHANGE): msg = ("Operation failure while setting up the " "replica set fixture: {}").format(err) self.logger.error(msg) @@ -486,7 +484,7 @@ class ReplicaSetFixture(interface.ReplFixture): return running - def get_primary(self, timeout_secs=30): + def get_primary(self, timeout_secs=30): # pylint: disable=arguments-differ """Return the primary from a replica set.""" if not self.all_nodes_electable: # The primary is always the first element of the 'nodes' list because all other members diff --git a/buildscripts/resmokelib/testing/fixtures/shard_merge.py b/buildscripts/resmokelib/testing/fixtures/shard_merge.py index 7e58667b192..6c88b3066b5 100644 --- a/buildscripts/resmokelib/testing/fixtures/shard_merge.py +++ b/buildscripts/resmokelib/testing/fixtures/shard_merge.py @@ -1,7 +1,7 @@ """Fixture with multiple replica sets for executing JSTests against.""" import os.path -from buildscripts.resmokelib.testing.fixtures import interface +import buildscripts.resmokelib.testing.fixtures.interface as interface class ShardMergeFixture(interface.MultiClusterFixture): # pylint: disable=too-many-instance-attributes diff --git a/buildscripts/resmokelib/testing/fixtures/shard_split.py b/buildscripts/resmokelib/testing/fixtures/shard_split.py index 66ff6411049..e707254b011 100644 --- a/buildscripts/resmokelib/testing/fixtures/shard_split.py +++ b/buildscripts/resmokelib/testing/fixtures/shard_split.py @@ -8,7 +8,7 @@ import shutil import pymongo from bson.objectid import ObjectId -from buildscripts.resmokelib.testing.fixtures import interface +import buildscripts.resmokelib.testing.fixtures.interface as interface from buildscripts.resmokelib.testing.fixtures.fixturelib import with_naive_retry diff --git a/buildscripts/resmokelib/testing/fixtures/shardedcluster.py b/buildscripts/resmokelib/testing/fixtures/shardedcluster.py index 5ecee4a03cf..a561c44f471 100644 --- a/buildscripts/resmokelib/testing/fixtures/shardedcluster.py +++ b/buildscripts/resmokelib/testing/fixtures/shardedcluster.py @@ -7,8 +7,8 @@ import yaml import pymongo import pymongo.errors -from buildscripts.resmokelib.testing.fixtures import interface -from buildscripts.resmokelib.testing.fixtures import external +import buildscripts.resmokelib.testing.fixtures.interface as interface +import buildscripts.resmokelib.testing.fixtures.external as external class ShardedClusterFixture(interface.Fixture): diff --git a/buildscripts/resmokelib/testing/fixtures/standalone.py b/buildscripts/resmokelib/testing/fixtures/standalone.py index 6b4170d4bf9..055f06077c5 100644 --- a/buildscripts/resmokelib/testing/fixtures/standalone.py +++ b/buildscripts/resmokelib/testing/fixtures/standalone.py @@ -11,7 +11,7 @@ import yaml import pymongo import pymongo.errors -from buildscripts.resmokelib.testing.fixtures import interface +import buildscripts.resmokelib.testing.fixtures.interface as interface class MongoDFixture(interface.Fixture): diff --git a/buildscripts/resmokelib/testing/fixtures/talk_directly_to_shardsvrs.py b/buildscripts/resmokelib/testing/fixtures/talk_directly_to_shardsvrs.py index fbaf6fcdb1e..387b20f4214 100644 --- a/buildscripts/resmokelib/testing/fixtures/talk_directly_to_shardsvrs.py +++ b/buildscripts/resmokelib/testing/fixtures/talk_directly_to_shardsvrs.py @@ -5,7 +5,7 @@ import os.path import pymongo import pymongo.write_concern -from buildscripts.resmokelib.testing.fixtures import interface +import buildscripts.resmokelib.testing.fixtures.interface as interface from buildscripts.resmokelib.testing.fixtures.fixturelib import FixtureLib diff --git a/buildscripts/resmokelib/testing/fixtures/tenant_migration.py b/buildscripts/resmokelib/testing/fixtures/tenant_migration.py index cc6960c9426..5e4ede264f9 100644 --- a/buildscripts/resmokelib/testing/fixtures/tenant_migration.py +++ b/buildscripts/resmokelib/testing/fixtures/tenant_migration.py @@ -2,7 +2,7 @@ import os.path -from buildscripts.resmokelib.testing.fixtures import interface +import buildscripts.resmokelib.testing.fixtures.interface as interface from buildscripts.resmokelib.testing.fixtures.fixturelib import with_naive_retry diff --git a/buildscripts/resmokelib/testing/fixtures/yesfixture.py b/buildscripts/resmokelib/testing/fixtures/yesfixture.py index b41dc5bbf16..ca594fc52dc 100644 --- a/buildscripts/resmokelib/testing/fixtures/yesfixture.py +++ b/buildscripts/resmokelib/testing/fixtures/yesfixture.py @@ -2,7 +2,7 @@ import signal -from buildscripts.resmokelib.testing.fixtures import interface +import buildscripts.resmokelib.testing.fixtures.interface as interface from buildscripts.resmokelib.testing.fixtures.fixturelib import FixtureLib diff --git a/buildscripts/resmokelib/testing/hooks/continuous_initial_sync.py b/buildscripts/resmokelib/testing/hooks/continuous_initial_sync.py index 6b818b1b28f..a8b679904c2 100644 --- a/buildscripts/resmokelib/testing/hooks/continuous_initial_sync.py +++ b/buildscripts/resmokelib/testing/hooks/continuous_initial_sync.py @@ -323,11 +323,12 @@ class _InitialSyncThread(threading.Thread): # (potentially) higher config version. We should not receive these codes # indefinitely. # pylint: disable=too-many-boolean-expressions - if err.code not in (self._NEW_REPLICA_SET_CONFIGURATION_INCOMPATIBLE, - self._CURRENT_CONFIG_NOT_COMMITTED_YET, - self._CONFIGURATION_IN_PROGRESS, self._NODE_NOT_FOUND, - self._INTERRUPTED_DUE_TO_REPL_STATE_CHANGE, - self._INTERRUPTED_DUE_TO_STORAGE_CHANGE): + if (err.code != self._NEW_REPLICA_SET_CONFIGURATION_INCOMPATIBLE + and err.code != self._CURRENT_CONFIG_NOT_COMMITTED_YET + and err.code != self._CONFIGURATION_IN_PROGRESS + and err.code != self._NODE_NOT_FOUND + and err.code != self._INTERRUPTED_DUE_TO_REPL_STATE_CHANGE + and err.code != self._INTERRUPTED_DUE_TO_STORAGE_CHANGE): msg = ( "Operation failure while adding tag for node on port {} in fixture {}: {}" ).format(sync_node.port, fixture.replset_name, err) @@ -431,8 +432,8 @@ class _InitialSyncThread(threading.Thread): conn.admin.command(cmd) break except pymongo.errors.OperationFailure as err: - if err.code not in (self.INTERRUPTED_DUE_TO_REPL_STATE_CHANGE, - self.INTERRUPTED_DUE_TO_STORAGE_CHANGE): + if (err.code != self.INTERRUPTED_DUE_TO_REPL_STATE_CHANGE + and err.code != self.INTERRUPTED_DUE_TO_STORAGE_CHANGE): raise msg = ( "Interrupted while waiting for node on port {} in set {} to reach primary state, retrying: {}" diff --git a/buildscripts/resmokelib/testing/hooks/initialsync.py b/buildscripts/resmokelib/testing/hooks/initialsync.py index 666b324ec08..29d43c9c9ff 100644 --- a/buildscripts/resmokelib/testing/hooks/initialsync.py +++ b/buildscripts/resmokelib/testing/hooks/initialsync.py @@ -89,8 +89,8 @@ class BackgroundInitialSyncTestCase(jsfile.DynamicJSTestCase): sync_node_conn.admin.command(cmd) break except pymongo.errors.OperationFailure as err: - if err.code not in (self.INTERRUPTED_DUE_TO_REPL_STATE_CHANGE, - self.INTERRUPTED_DUE_TO_STORAGE_CHANGE): + if (err.code != self.INTERRUPTED_DUE_TO_REPL_STATE_CHANGE + and err.code != self.INTERRUPTED_DUE_TO_STORAGE_CHANGE): raise msg = ( "Interrupted while waiting for node to reach secondary state, retrying: {}" @@ -224,8 +224,8 @@ class IntermediateInitialSyncTestCase(jsfile.DynamicJSTestCase): sync_node_conn.admin.command(cmd) break except pymongo.errors.OperationFailure as err: - if err.code not in (self.INTERRUPTED_DUE_TO_REPL_STATE_CHANGE, - self.INTERRUPTED_DUE_TO_STORAGE_CHANGE): + if (err.code != self.INTERRUPTED_DUE_TO_REPL_STATE_CHANGE + and err.code != self.INTERRUPTED_DUE_TO_STORAGE_CHANGE): raise msg = ("Interrupted while waiting for node to reach secondary state, retrying: {}" ).format(err) diff --git a/buildscripts/resmokelib/testing/hooks/periodic_kill_secondaries.py b/buildscripts/resmokelib/testing/hooks/periodic_kill_secondaries.py index 7d7ca278439..4cce5617645 100644 --- a/buildscripts/resmokelib/testing/hooks/periodic_kill_secondaries.py +++ b/buildscripts/resmokelib/testing/hooks/periodic_kill_secondaries.py @@ -159,7 +159,7 @@ class PeriodicKillSecondariesTestCase(interface.DynamicTestCase): for secondary in self.fixture.get_secondaries(): # Disable the "rsSyncApplyStop" failpoint on the secondary to have it resume applying # oplog entries. - self._hook._disable_rssyncapplystop(secondary) + self._hook._disable_rssyncapplystop(secondary) # pylint: disable=protected-access # Wait a little bit for the secondary to start apply oplog entries so that we are more # likely to kill the mongod process while it is partway into applying a batch. @@ -350,8 +350,8 @@ class PeriodicKillSecondariesTestCase(interface.DynamicTestCase): ])) break except pymongo.errors.OperationFailure as err: - if err.code not in (self.INTERRUPTED_DUE_TO_REPL_STATE_CHANGE, - self.INTERRUPTED_DUE_TO_STORAGE_CHANGE): + if (err.code != self.INTERRUPTED_DUE_TO_REPL_STATE_CHANGE + and err.code != self.INTERRUPTED_DUE_TO_STORAGE_CHANGE): self.logger.exception( "mongod on port %d failed to reach state SECONDARY after %d seconds", secondary.port, fixture.ReplFixture.AWAIT_REPL_TIMEOUT_FOREVER_MINS * 60) diff --git a/buildscripts/resmokelib/testing/symbolizer_service.py b/buildscripts/resmokelib/testing/symbolizer_service.py index 1abe74c0dab..b4468ef3175 100644 --- a/buildscripts/resmokelib/testing/symbolizer_service.py +++ b/buildscripts/resmokelib/testing/symbolizer_service.py @@ -56,7 +56,7 @@ class ResmokeSymbolizerConfig(NamedTuple): :return: True if on Windows """ - return sys.platform in ("win32", "cygwin") + return sys.platform == "win32" or sys.platform == "cygwin" @staticmethod def is_macos() -> bool: diff --git a/buildscripts/resmokelib/utils/archival.py b/buildscripts/resmokelib/utils/archival.py index a6ecc9d6d14..8fa20906107 100644 --- a/buildscripts/resmokelib/utils/archival.py +++ b/buildscripts/resmokelib/utils/archival.py @@ -14,7 +14,7 @@ import math from buildscripts.resmokelib import config -_IS_WINDOWS = sys.platform in ("win32", "cygwin") +_IS_WINDOWS = sys.platform == "win32" or sys.platform == "cygwin" if _IS_WINDOWS: import ctypes @@ -277,7 +277,7 @@ class Archival(object): return 1, str(err), 0 # Round up the size of the archive. - size_mb = int(math.ceil(float(file_list_size(temp_file)) / (1024 * 1024))) + size_mb = int(math.ceil(float(file_list_size(temp_file)) / (1024 * 1024))) # pylint: disable=c-extension-no-member self._upload_queue.put( UploadArgs(self.archival_json_file, display_name, temp_file, "application/x-gzip", s3_bucket, s3_path, True)) diff --git a/buildscripts/resmokelib/utils/scheduler.py b/buildscripts/resmokelib/utils/scheduler.py index 38fda12da61..12ebd47c35d 100644 --- a/buildscripts/resmokelib/utils/scheduler.py +++ b/buildscripts/resmokelib/utils/scheduler.py @@ -21,8 +21,6 @@ class Scheduler(sched.scheduler): # only has a resolution of ~15ms. We therefore use the `is` operator to remove the correct # event from the list. with self._lock: - # Disable warning, since we're deleting elements from a queue while traversing it - # pylint: disable=C0200 for i in range(len(self._queue)): if self._queue[i] is event: del self._queue[i] diff --git a/buildscripts/tests/resmokelib/core/test_pipe.py b/buildscripts/tests/resmokelib/core/test_pipe.py index 954f3a9979e..92d0a0aed69 100644 --- a/buildscripts/tests/resmokelib/core/test_pipe.py +++ b/buildscripts/tests/resmokelib/core/test_pipe.py @@ -30,19 +30,19 @@ class TestLoggerPipe(unittest.TestCase): def test_strips_trailing_whitespace(self): calls = self._get_log_calls(b" a ") - self.assertEqual(calls, [mock.call(self.LOG_LEVEL, " a")]) + self.assertEqual(calls, [mock.call(self.LOG_LEVEL, u" a")]) def test_strips_trailing_newlines(self): calls = self._get_log_calls(b"a\r\n") - self.assertEqual(calls, [mock.call(self.LOG_LEVEL, "a")]) + self.assertEqual(calls, [mock.call(self.LOG_LEVEL, u"a")]) def test_handles_invalid_utf8(self): calls = self._get_log_calls(b"a\x80b") - self.assertEqual(calls, [mock.call(self.LOG_LEVEL, "a\ufffdb")]) + self.assertEqual(calls, [mock.call(self.LOG_LEVEL, u"a\ufffdb")]) def test_escapes_null_bytes(self): calls = self._get_log_calls(b"a\0b") - self.assertEqual(calls, [mock.call(self.LOG_LEVEL, "a\\0b")]) + self.assertEqual(calls, [mock.call(self.LOG_LEVEL, u"a\\0b")]) class TestFormatLineForLogging(unittest.TestCase): @@ -51,28 +51,28 @@ class TestFormatLineForLogging(unittest.TestCase): line_output = _pipe.LoggerPipe._format_line_for_logging(line) - self.assertEqual([" a"], line_output) + self.assertEqual([u" a"], line_output) def test_strips_trailing_newlines(self): line = b"a\r\n" line_output = _pipe.LoggerPipe._format_line_for_logging(line) - self.assertEqual(["a"], line_output) + self.assertEqual([u"a"], line_output) def test_handles_invalid_utf8(self): line = b"a\x80b" line_output = _pipe.LoggerPipe._format_line_for_logging(line) - self.assertEqual(["a\ufffdb"], line_output) + self.assertEqual([u"a\ufffdb"], line_output) def test_escapes_null_bytes(self): line = b"a\0b" line_output = _pipe.LoggerPipe._format_line_for_logging(line) - self.assertEqual(["a\\0b"], line_output) + self.assertEqual([u"a\\0b"], line_output) def test_long_lines_are_split(self): line = b"a" * 4_000_000 diff --git a/buildscripts/tests/resmokelib/test_selector.py b/buildscripts/tests/resmokelib/test_selector.py index e3f0844c3ac..e94c6c097bc 100644 --- a/buildscripts/tests/resmokelib/test_selector.py +++ b/buildscripts/tests/resmokelib/test_selector.py @@ -7,9 +7,11 @@ import unittest import collections import buildscripts.resmokelib.config -from buildscripts.resmokelib import parser -from buildscripts.resmokelib import selector -from buildscripts.resmokelib.utils import globstar +import buildscripts.resmokelib.parser as parser +import buildscripts.resmokelib.selector as selector +import buildscripts.resmokelib.utils.globstar as globstar + +# pylint: disable=protected-access FIXTURE_PREFIX = "buildscripts/tests/selftest_fixtures" diff --git a/buildscripts/tests/resmokelib/test_undodb.py b/buildscripts/tests/resmokelib/test_undodb.py index 9b7dd6c0aaf..e523a3b2770 100644 --- a/buildscripts/tests/resmokelib/test_undodb.py +++ b/buildscripts/tests/resmokelib/test_undodb.py @@ -3,7 +3,7 @@ import os import unittest from mock import MagicMock, Mock, patch, call import evergreen -from buildscripts.resmokelib.undodb import fetch +import buildscripts.resmokelib.undodb.fetch as fetch class TestFetch(unittest.TestCase): diff --git a/buildscripts/tests/test_exception_exctractor.py b/buildscripts/tests/test_exception_exctractor.py index 8f4ae6ed62a..b8bdac0dcdd 100644 --- a/buildscripts/tests/test_exception_exctractor.py +++ b/buildscripts/tests/test_exception_exctractor.py @@ -43,7 +43,7 @@ class TestExceptionExtractor(unittest.TestCase): assert exception_extractor.active is True assert exception_extractor.exception_detected is False assert list(exception_extractor.current_exception) == expected_current_exception - assert exception_extractor.get_exception() + assert exception_extractor.get_exception() == [] def test_no_extraction(self): logs = [ @@ -58,7 +58,7 @@ class TestExceptionExtractor(unittest.TestCase): assert exception_extractor.active is False assert exception_extractor.exception_detected is False assert list(exception_extractor.current_exception) == expected_current_exception - assert exception_extractor.get_exception() + assert exception_extractor.get_exception() == [] def test_successful_extraction_truncate_first(self): logs = ["START"] + ["not captured"