mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 05:42:50 +00:00
Bug fixes and cleanup for ansible-test. (#45991)
* Remove unused imports. * Clean up ConfigParser usage in ansible-test. * Fix bare except statements in ansible-test. * Miscellaneous cleanup from PyCharm inspections. * Enable pylint no-self-use for ansible-test. * Remove obsolete pylint ignores for Python 3.7. * Fix shellcheck issuers under newer shellcheck. * Use newer path for ansible-test. * Fix issues in code-smell tests.
This commit is contained in:
@@ -25,7 +25,6 @@ NOTE: Running ansible-test with the --tox option or inside a virtual environment
|
||||
|
||||
from __future__ import absolute_import, print_function
|
||||
|
||||
import errno
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
@@ -203,10 +202,10 @@ def find_executable(executable):
|
||||
:rtype: str
|
||||
"""
|
||||
self = os.path.abspath(__file__)
|
||||
path = os.environ.get('PATH', os.defpath)
|
||||
path = os.environ.get('PATH', os.path.defpath)
|
||||
seen_dirs = set()
|
||||
|
||||
for path_dir in path.split(os.pathsep):
|
||||
for path_dir in path.split(os.path.pathsep):
|
||||
if path_dir in seen_dirs:
|
||||
continue
|
||||
|
||||
|
||||
@@ -25,8 +25,8 @@ def ansible_environment(args, color=True):
|
||||
|
||||
ansible_path = os.path.join(os.getcwd(), 'bin')
|
||||
|
||||
if not path.startswith(ansible_path + os.pathsep):
|
||||
path = ansible_path + os.pathsep + path
|
||||
if not path.startswith(ansible_path + os.path.pathsep):
|
||||
path = ansible_path + os.path.pathsep + path
|
||||
|
||||
if isinstance(args, IntegrationConfig):
|
||||
ansible_config = 'test/integration/%s.cfg' % args.command
|
||||
|
||||
@@ -28,13 +28,6 @@ from lib.docker_util import (
|
||||
get_docker_container_id,
|
||||
)
|
||||
|
||||
try:
|
||||
# noinspection PyPep8Naming
|
||||
import ConfigParser as configparser
|
||||
except ImportError:
|
||||
# noinspection PyUnresolvedReferences
|
||||
import configparser
|
||||
|
||||
|
||||
class ACMEProvider(CloudProvider):
|
||||
"""ACME plugin. Sets up cloud resources for tests."""
|
||||
|
||||
@@ -17,6 +17,7 @@ from lib.util import (
|
||||
display,
|
||||
SubprocessError,
|
||||
is_shippable,
|
||||
ConfigParser,
|
||||
)
|
||||
|
||||
from lib.http import (
|
||||
@@ -34,13 +35,6 @@ from lib.docker_util import (
|
||||
get_docker_container_id,
|
||||
)
|
||||
|
||||
try:
|
||||
# noinspection PyPep8Naming
|
||||
import ConfigParser as configparser
|
||||
except ImportError:
|
||||
# noinspection PyUnresolvedReferences
|
||||
import configparser
|
||||
|
||||
|
||||
class CsCloudProvider(CloudProvider):
|
||||
"""CloudStack cloud provider plugin. Sets up cloud resources before delegation."""
|
||||
@@ -119,7 +113,7 @@ class CsCloudProvider(CloudProvider):
|
||||
|
||||
def _setup_static(self):
|
||||
"""Configure CloudStack tests for use with static configuration."""
|
||||
parser = configparser.RawConfigParser()
|
||||
parser = ConfigParser()
|
||||
parser.read(self.config_static_path)
|
||||
|
||||
self.endpoint = parser.get('cloudstack', 'endpoint')
|
||||
@@ -211,7 +205,7 @@ class CsCloudProvider(CloudProvider):
|
||||
containers = bridge['Containers']
|
||||
container = [containers[container] for container in containers if containers[container]['Name'] == self.DOCKER_SIMULATOR_NAME][0]
|
||||
return re.sub(r'/[0-9]+$', '', container['IPv4Address'])
|
||||
except:
|
||||
except Exception:
|
||||
display.error('Failed to process the following docker network inspect output:\n%s' %
|
||||
json.dumps(networks, indent=4, sort_keys=True))
|
||||
raise
|
||||
|
||||
@@ -6,9 +6,7 @@ from __future__ import absolute_import, print_function
|
||||
import os
|
||||
|
||||
from lib.util import (
|
||||
ApplicationError,
|
||||
display,
|
||||
is_shippable,
|
||||
)
|
||||
|
||||
from lib.cloud import (
|
||||
@@ -16,9 +14,6 @@ from lib.cloud import (
|
||||
CloudEnvironment,
|
||||
)
|
||||
|
||||
from lib.core_ci import (
|
||||
AnsibleCoreCI, )
|
||||
|
||||
|
||||
class GcpCloudProvider(CloudProvider):
|
||||
"""GCP cloud provider plugin. Sets up cloud resources before delegation."""
|
||||
|
||||
@@ -1,17 +1,12 @@
|
||||
"""OpenNebula plugin for integration tests."""
|
||||
|
||||
import os
|
||||
|
||||
from lib.cloud import (
|
||||
CloudProvider,
|
||||
CloudEnvironment
|
||||
)
|
||||
|
||||
from lib.util import (
|
||||
find_executable,
|
||||
ApplicationError,
|
||||
display,
|
||||
is_shippable,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -4,20 +4,13 @@ from __future__ import absolute_import, print_function
|
||||
import os
|
||||
import time
|
||||
|
||||
try:
|
||||
# noinspection PyPep8Naming
|
||||
import ConfigParser as configparser
|
||||
except ImportError:
|
||||
# noinspection PyUnresolvedReferences
|
||||
import configparser
|
||||
|
||||
from lib.util import (
|
||||
display,
|
||||
ApplicationError,
|
||||
is_shippable,
|
||||
run_command,
|
||||
generate_password,
|
||||
SubprocessError,
|
||||
ConfigParser,
|
||||
)
|
||||
|
||||
from lib.cloud import (
|
||||
@@ -27,15 +20,6 @@ from lib.cloud import (
|
||||
|
||||
from lib.core_ci import (
|
||||
AnsibleCoreCI,
|
||||
InstanceConnection,
|
||||
)
|
||||
|
||||
from lib.manage_ci import (
|
||||
ManagePosixCI,
|
||||
)
|
||||
|
||||
from lib.http import (
|
||||
HttpClient,
|
||||
)
|
||||
|
||||
|
||||
@@ -219,7 +203,7 @@ class TowerConfig(object):
|
||||
:type path: str
|
||||
:rtype: TowerConfig
|
||||
"""
|
||||
parser = configparser.RawConfigParser()
|
||||
parser = ConfigParser()
|
||||
parser.read(path)
|
||||
|
||||
keys = (
|
||||
|
||||
@@ -21,13 +21,6 @@ from lib.docker_util import (
|
||||
get_docker_container_id,
|
||||
)
|
||||
|
||||
try:
|
||||
# noinspection PyPep8Naming
|
||||
import ConfigParser as configparser
|
||||
except ImportError:
|
||||
# noinspection PyUnresolvedReferences
|
||||
import configparser
|
||||
|
||||
|
||||
class VcenterProvider(CloudProvider):
|
||||
"""VMware vcenter/esx plugin. Sets up cloud resources for tests."""
|
||||
|
||||
@@ -172,8 +172,8 @@ def docker_inspect(args, container_id):
|
||||
except SubprocessError as ex:
|
||||
try:
|
||||
return json.loads(ex.stdout)
|
||||
except:
|
||||
raise ex # pylint: disable=locally-disabled, raising-bad-type
|
||||
except Exception:
|
||||
raise ex
|
||||
|
||||
|
||||
def docker_network_disconnect(args, container_id, network):
|
||||
@@ -200,8 +200,8 @@ def docker_network_inspect(args, network):
|
||||
except SubprocessError as ex:
|
||||
try:
|
||||
return json.loads(ex.stdout)
|
||||
except:
|
||||
raise ex # pylint: disable=locally-disabled, raising-bad-type
|
||||
except Exception:
|
||||
raise ex
|
||||
|
||||
|
||||
def docker_exec(args, container_id, cmd, options=None, capture=False, stdin=None, stdout=None):
|
||||
|
||||
@@ -541,6 +541,7 @@ def command_windows_integration(args):
|
||||
instance.result.stop()
|
||||
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
def windows_init(args, internal_targets): # pylint: disable=locally-disabled, unused-argument
|
||||
"""
|
||||
:type args: WindowsIntegrationConfig
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
from __future__ import absolute_import, print_function
|
||||
|
||||
import os
|
||||
import re
|
||||
|
||||
from lib.sanity import (
|
||||
SanityMultipleVersion,
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
from __future__ import absolute_import, print_function
|
||||
|
||||
import os
|
||||
import re
|
||||
|
||||
from lib.sanity import (
|
||||
SanityMultipleVersion,
|
||||
|
||||
@@ -6,11 +6,6 @@ import json
|
||||
import os
|
||||
import datetime
|
||||
|
||||
try:
|
||||
import ConfigParser as configparser
|
||||
except ImportError:
|
||||
import configparser
|
||||
|
||||
from lib.sanity import (
|
||||
SanitySingleVersion,
|
||||
SanityMessage,
|
||||
@@ -23,8 +18,8 @@ from lib.util import (
|
||||
SubprocessError,
|
||||
run_command,
|
||||
display,
|
||||
find_executable,
|
||||
read_lines_without_comments,
|
||||
ConfigParser,
|
||||
)
|
||||
|
||||
from lib.executor import (
|
||||
@@ -245,7 +240,7 @@ class PylintTest(SanitySingleVersion):
|
||||
if not os.path.exists(rcfile):
|
||||
rcfile = 'test/sanity/pylint/config/default'
|
||||
|
||||
parser = configparser.SafeConfigParser()
|
||||
parser = ConfigParser()
|
||||
parser.read(rcfile)
|
||||
|
||||
if parser.has_section('ansible-test'):
|
||||
@@ -268,7 +263,7 @@ class PylintTest(SanitySingleVersion):
|
||||
] + paths
|
||||
|
||||
env = ansible_environment(args)
|
||||
env['PYTHONPATH'] += '%s%s' % (os.pathsep, self.plugin_dir)
|
||||
env['PYTHONPATH'] += '%s%s' % (os.path.pathsep, self.plugin_dir)
|
||||
|
||||
if paths:
|
||||
try:
|
||||
|
||||
@@ -16,7 +16,6 @@ from lib.util import (
|
||||
run_command,
|
||||
parse_to_list_of_dict,
|
||||
display,
|
||||
find_executable,
|
||||
read_lines_without_comments,
|
||||
)
|
||||
|
||||
|
||||
@@ -62,7 +62,8 @@ class YamllintTest(SanitySingleVersion):
|
||||
|
||||
return SanitySuccess(self.name)
|
||||
|
||||
def test_paths(self, args, paths):
|
||||
@staticmethod
|
||||
def test_paths(args, paths):
|
||||
"""
|
||||
:type args: SanityConfig
|
||||
:type paths: list[str]
|
||||
|
||||
@@ -30,7 +30,7 @@ class WrappedThread(threading.Thread):
|
||||
Run action and capture results or exception.
|
||||
Do not override. Do not call directly. Executed by the start() method.
|
||||
"""
|
||||
# noinspection PyBroadException
|
||||
# noinspection PyBroadException, PyPep8
|
||||
try:
|
||||
self._result.put((self.action(), None))
|
||||
except: # pylint: disable=locally-disabled, bare-except
|
||||
|
||||
@@ -5,7 +5,6 @@ from __future__ import absolute_import, print_function
|
||||
import atexit
|
||||
import contextlib
|
||||
import errno
|
||||
import filecmp
|
||||
import fcntl
|
||||
import inspect
|
||||
import json
|
||||
@@ -32,6 +31,13 @@ except ImportError:
|
||||
from abc import ABCMeta
|
||||
ABC = ABCMeta('ABC', (), {})
|
||||
|
||||
try:
|
||||
# noinspection PyCompatibility
|
||||
from ConfigParser import SafeConfigParser as ConfigParser
|
||||
except ImportError:
|
||||
# noinspection PyCompatibility
|
||||
from configparser import ConfigParser
|
||||
|
||||
DOCKER_COMPLETION = {}
|
||||
|
||||
coverage_path = '' # pylint: disable=locally-disabled, invalid-name
|
||||
@@ -117,10 +123,10 @@ def find_executable(executable, cwd=None, path=None, required=True):
|
||||
match = executable
|
||||
else:
|
||||
if path is None:
|
||||
path = os.environ.get('PATH', os.defpath)
|
||||
path = os.environ.get('PATH', os.path.defpath)
|
||||
|
||||
if path:
|
||||
path_dirs = path.split(os.pathsep)
|
||||
path_dirs = path.split(os.path.pathsep)
|
||||
seen_dirs = set()
|
||||
|
||||
for path_dir in path_dirs:
|
||||
@@ -197,7 +203,7 @@ def intercept_command(args, cmd, target_name, capture=False, env=None, data=None
|
||||
coverage_file = os.path.abspath(os.path.join(inject_path, '..', 'output', '%s=%s=%s=%s=coverage' % (
|
||||
args.command, target_name, args.coverage_label or 'local-%s' % version, 'python-%s' % version)))
|
||||
|
||||
env['PATH'] = inject_path + os.pathsep + env['PATH']
|
||||
env['PATH'] = inject_path + os.path.pathsep + env['PATH']
|
||||
env['ANSIBLE_TEST_PYTHON_VERSION'] = version
|
||||
env['ANSIBLE_TEST_PYTHON_INTERPRETER'] = interpreter
|
||||
|
||||
@@ -388,7 +394,7 @@ def common_environment():
|
||||
"""Common environment used for executing all programs."""
|
||||
env = dict(
|
||||
LC_ALL='en_US.UTF-8',
|
||||
PATH=os.environ.get('PATH', os.defpath),
|
||||
PATH=os.environ.get('PATH', os.path.defpath),
|
||||
)
|
||||
|
||||
required = (
|
||||
|
||||
@@ -17,6 +17,7 @@ if [ ! -f /usr/bin/virtualenv ] && [ -f /usr/bin/virtualenv-3 ]; then
|
||||
fi
|
||||
|
||||
# Improve prompts on remote host for interactive use.
|
||||
# shellcheck disable=SC1117
|
||||
cat << EOF > ~/.bashrc
|
||||
alias ls='ls --color=auto'
|
||||
export PS1='\[\e]0;\u@\h: \w\a\]\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
|
||||
|
||||
@@ -76,6 +76,7 @@ if [ ! -f "${HOME}/.ssh/id_rsa.pub" ]; then
|
||||
fi
|
||||
|
||||
# Improve prompts on remote host for interactive use.
|
||||
# shellcheck disable=SC1117
|
||||
cat << EOF > ~/.bashrc
|
||||
alias ls='ls -G'
|
||||
export PS1='\[\e]0;\u@\h: \w\a\]\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
|
||||
|
||||
Reference in New Issue
Block a user