Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code cleanup for test infrastructure. #59046

Merged
merged 12 commits into from
Jul 12, 2019
2 changes: 1 addition & 1 deletion test/runner/lib/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
__metaclass__ = type


class CommonCache(object):
class CommonCache:
"""Common cache."""
def __init__(self, args):
"""
Expand Down
5 changes: 2 additions & 3 deletions test/runner/lib/changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ def __init__(self, branch, reason):

class ChangeDetectionNotSupported(ApplicationError):
"""Exception for cases where change detection is not supported."""
pass


class ShippableChanges(object):
class ShippableChanges:
"""Change information for Shippable build."""
def __init__(self, args, git):
"""
Expand Down Expand Up @@ -120,7 +119,7 @@ def get_last_successful_commit(git, merge_runs):
return last_successful_commit


class LocalChanges(object):
class LocalChanges:
"""Change information for local work."""
def __init__(self, args, git):
"""
Expand Down
2 changes: 1 addition & 1 deletion test/runner/lib/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def categorize_changes(args, paths, verbose_command=None):
return changes


class PathMapper(object):
class PathMapper:
"""Map file paths to test commands and targets."""
def __init__(self, args):
"""
Expand Down
5 changes: 1 addition & 4 deletions test/runner/lib/cloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,24 +388,21 @@ def setup_once(self):

def setup(self):
"""Setup which should be done once per environment instead of once per test target."""
pass

@abc.abstractmethod
def get_environment_config(self):
"""
:rtype: CloudEnvironmentConfig
"""
pass

def on_failure(self, target, tries):
"""
:type target: IntegrationTarget
:type tries: int
"""
pass


class CloudEnvironmentConfig(object):
class CloudEnvironmentConfig:
"""Configuration for the environment."""
def __init__(self, env_vars=None, ansible_vars=None, module_defaults=None, callback_plugins=None):
"""
Expand Down
1 change: 0 additions & 1 deletion test/runner/lib/cloud/opennebula.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class OpenNebulaCloudProvider(CloudProvider):

def filter(self, targets, exclude):
""" no need to filter modules, they can either run from config file or from fixtures"""
pass

def setup(self):
"""Setup the cloud resource before delegation and register a cleanup callback."""
Expand Down
2 changes: 1 addition & 1 deletion test/runner/lib/cloud/tower.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def get_environment_config(self):
)


class TowerConfig(object):
class TowerConfig:
"""Tower settings."""
def __init__(self, values):
self.version = values.get('version')
Expand Down
6 changes: 3 additions & 3 deletions test/runner/lib/core_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
}


class AnsibleCoreCI(object):
class AnsibleCoreCI:
"""Client for Ansible Core CI services."""
def __init__(self, args, platform, version, stage='prod', persist=True, load=True, name=None, provider=None):
"""
Expand Down Expand Up @@ -537,7 +537,7 @@ def __init__(self, status, remote_message, remote_stack_trace):
self.remote_stack_trace = remote_stack_trace


class SshKey(object):
class SshKey:
"""Container for SSH key used to connect to remote instances."""
KEY_NAME = 'id_rsa'
PUB_NAME = 'id_rsa.pub'
Expand Down Expand Up @@ -574,7 +574,7 @@ def __init__(self, args):
self.pub_contents = pub_fd.read().strip()


class InstanceConnection(object):
class InstanceConnection:
"""Container for remote instance status and connection details."""
def __init__(self, running, hostname, port, username, password):
"""
Expand Down
6 changes: 3 additions & 3 deletions test/runner/lib/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def parse_diff(lines):
return DiffParser(lines).files


class FileDiff(object):
class FileDiff:
"""Parsed diff for a single file."""
def __init__(self, old_path, new_path):
"""
Expand All @@ -47,7 +47,7 @@ def is_complete(self):
return self.old.is_complete and self.new.is_complete


class DiffSide(object):
class DiffSide:
"""Parsed diff for a single 'side' of a single file."""
def __init__(self, path, new):
"""
Expand Down Expand Up @@ -134,7 +134,7 @@ def format_lines(self, context=True):
return ['%s:%4d %s' % (self.path, line[0], line[1]) for line in lines]


class DiffParser(object):
class DiffParser:
"""Parse diff lines."""
def __init__(self, lines):
"""
Expand Down
2 changes: 1 addition & 1 deletion test/runner/lib/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1795,7 +1795,7 @@ def get_python_interpreter(args, configs, name):
return python_interpreter


class EnvironmentDescription(object):
class EnvironmentDescription:
"""Description of current running environment."""
def __init__(self, args):
"""Initialize snapshot of environment configuration.
Expand Down
2 changes: 1 addition & 1 deletion test/runner/lib/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
)


class Git(object):
class Git:
"""Wrapper around git command-line tools."""
def __init__(self, root=None): # type: (t.Optional[str]) -> None
self.git = 'git'
Expand Down
4 changes: 2 additions & 2 deletions test/runner/lib/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
)


class HttpClient(object):
class HttpClient:
"""Make HTTP requests via curl."""
def __init__(self, args, always=False, insecure=False, proxy=None):
"""
Expand Down Expand Up @@ -146,7 +146,7 @@ def request(self, method, url, data=None, headers=None):
return HttpResponse(method, url, status_code, body)


class HttpResponse(object):
class HttpResponse:
"""HTTP response from curl."""
def __init__(self, method, url, status_code, response):
"""
Expand Down
2 changes: 1 addition & 1 deletion test/runner/lib/integration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def integration_test_config_file(args, env_config, integration_dir):
yield path


class IntegrationEnvironment(object):
class IntegrationEnvironment:
"""Details about the integration environment."""
def __init__(self, integration_dir, inventory_path, ansible_config, vars_file):
self.integration_dir = integration_dir
Expand Down
7 changes: 3 additions & 4 deletions test/runner/lib/manage_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
)


class ManageWindowsCI(object):
class ManageWindowsCI:
"""Manage access to a Windows instance provided by Ansible Core CI."""
def __init__(self, core_ci):
"""
Expand All @@ -56,7 +56,6 @@ def setup(self, python_version):
"""Used in delegate_remote to setup the host, no action is required for Windows.
:type python_version: str
"""
pass

def wait(self):
"""Wait for instance to respond to ansible ping."""
Expand Down Expand Up @@ -136,7 +135,7 @@ def scp(self, src, dst):
raise ApplicationError('Failed transfer: %s -> %s' % (src, dst))


class ManageNetworkCI(object):
class ManageNetworkCI:
"""Manage access to a network instance provided by Ansible Core CI."""
def __init__(self, core_ci):
"""
Expand Down Expand Up @@ -177,7 +176,7 @@ def wait(self):
(self.core_ci.platform, self.core_ci.version, self.core_ci.instance_id))


class ManagePosixCI(object):
class ManagePosixCI:
"""Manage access to a POSIX instance provided by Ansible Core CI."""
def __init__(self, core_ci):
"""
Expand Down
4 changes: 2 additions & 2 deletions test/runner/lib/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
)


class Metadata(object):
class Metadata:
"""Metadata object for passing data to delegated tests."""
def __init__(self):
"""Initialize metadata."""
Expand Down Expand Up @@ -102,7 +102,7 @@ def from_dict(data):
return metadata


class ChangeDescription(object):
class ChangeDescription:
"""Description of changes."""
def __init__(self):
self.command = '' # type: str
Expand Down
1 change: 0 additions & 1 deletion test/runner/lib/pytar.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def ignore(self, item):
:type item: tarfile.TarInfo
:rtype: tarfile.TarInfo | None
"""
pass


class DefaultTarFilter(TarFilter):
Expand Down
5 changes: 1 addition & 4 deletions test/runner/lib/sanity/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,9 @@ def __init__(self, test, python_version=None, messages=None, summary=None):

class SanityMessage(TestMessage):
"""Single sanity test message for one file."""
pass


class SanityTargets(object):
class SanityTargets:
"""Sanity test target information."""
def __init__(self, include, exclude, require):
"""
Expand Down Expand Up @@ -363,7 +362,6 @@ def test(self, args, targets):
:type targets: SanityTargets
:rtype: TestResult
"""
pass


class SanityMultipleVersion(SanityFunc):
Expand All @@ -376,7 +374,6 @@ def test(self, args, targets, python_version):
:type python_version: str
:rtype: TestResult
"""
pass


SANITY_TESTS = (
Expand Down
2 changes: 2 additions & 0 deletions test/runner/lib/sanity/pylint.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ def context_filter(path_to_filter):
return context_filter

add_context(remaining_paths, 'ansible-test', filter_path('test/runner/'))
add_context(remaining_paths, 'validate-modules', filter_path('test/sanity/validate-modules/'))
add_context(remaining_paths, 'sanity', filter_path('test/sanity/'))
add_context(remaining_paths, 'units', filter_path('test/units/'))
add_context(remaining_paths, 'test', filter_path('test/'))
add_context(remaining_paths, 'hacking', filter_path('hacking/'))
Expand Down
2 changes: 1 addition & 1 deletion test/runner/lib/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def analyze_integration_target_dependencies(integration_targets):
return dependencies


class CompletionTarget(object):
class CompletionTarget:
"""Command-line argument completion target base class."""
__metaclass__ = abc.ABCMeta

Expand Down
8 changes: 2 additions & 6 deletions test/runner/lib/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def calculate_confidence(path, line, metadata):
return 50


class TestResult(object):
class TestResult:
"""Base class for test results."""
def __init__(self, command, test, python_version=None):
"""
Expand Down Expand Up @@ -96,23 +96,19 @@ def write(self, args):

def write_console(self):
"""Write results to console."""
pass

def write_lint(self):
"""Write lint results to stdout."""
pass

def write_bot(self, args):
"""
:type args: TestConfig
"""
pass

def write_junit(self, args):
"""
:type args: TestConfig
"""
pass

def create_path(self, directory, extension):
"""
Expand Down Expand Up @@ -419,7 +415,7 @@ def format_block(self):
return message


class TestMessage(object):
class TestMessage:
"""Single test message for one file."""
def __init__(self, message, path, line=0, column=0, level='error', code=None, confidence=None):
"""
Expand Down
4 changes: 1 addition & 3 deletions test/runner/lib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ def generate_password():
return password


class Display(object):
class Display:
"""Manages color console output."""
clear = '\033[0m'
red = '\033[31m'
Expand Down Expand Up @@ -626,12 +626,10 @@ def print_message(self, message, color=None, fd=sys.stdout, truncate=False): #

class ApplicationError(Exception):
"""General application error."""
pass


class ApplicationWarning(Exception):
"""General application warning which interrupts normal program flow."""
pass


class SubprocessError(ApplicationError):
Expand Down
2 changes: 1 addition & 1 deletion test/runner/lib/util_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
)


class CommonConfig(object):
class CommonConfig:
"""Configuration common to all commands."""
def __init__(self, args, command):
"""
Expand Down
6 changes: 3 additions & 3 deletions test/sanity/code-smell/botmeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

from ansible.module_utils.six import string_types

list_string_types = list(string_types)


def main():
"""Validate BOTMETA"""
Expand All @@ -27,10 +25,12 @@ def main():
except yaml.error.MarkedYAMLError as ex:
print('%s:%d:%d: YAML load failed: %s' % (path, ex.context_mark.line + 1, ex.context_mark.column + 1, re.sub(r'\s+', ' ', str(ex))))
sys.exit()
except Exception as ex:
except Exception as ex: # pylint: disable=broad-except
print('%s:%d:%d: YAML load failed: %s' % (path, 0, 0, re.sub(r'\s+', ' ', str(ex))))
sys.exit()

list_string_types = list(string_types)

files_schema = Any(
Schema(*string_types),
Schema({
Expand Down