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

[stable-2.5] Backport test infra bug fixes. #48700

Merged
merged 7 commits into from
Nov 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/integration/targets/apt/tasks/upgrade.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
#### Tests for upgrade/download functions in modules/packaging/os/apt.py ####
- name: download and install old version of hello
apt: "deb=https://launchpad.net/ubuntu/+archive/primary/+files/hello_{{ hello_old_version }}_amd64.deb"
apt: "deb=https://s3.amazonaws.com/ansible-ci-files/test/integration/targets/apt/hello_{{ hello_old_version }}_amd64.deb"

- name: check hello version
shell: dpkg -s hello | grep Version | awk '{print $2}'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

- name: attempt to upgrade hello
apt:
upgrade: dist
name: hello
state: latest
ignore_errors: yes

- name: check hello version
shell: dpkg -s hello | grep Version | awk '{print $2}'
Expand All @@ -37,7 +39,8 @@

- name: upgrade hello
apt:
upgrade: dist
name: hello
state: latest

- name: check hello version
shell: dpkg -s hello | grep Version | awk '{print $2}'
Expand Down
15 changes: 4 additions & 11 deletions test/runner/lib/changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,10 @@ def get_last_successful_commit(git, merge_runs):
display.warning('Unable to find project. Cannot determine changes. All tests will be executed.')
return None

merge_runs = sorted(merge_runs, key=lambda r: r['createdAt'])
known_commits = set()
last_successful_commit = None

for merge_run in merge_runs:
commit_sha = merge_run['commitSha']
if commit_sha not in known_commits:
known_commits.add(commit_sha)
if merge_run['statusCode'] == 30:
if git.is_valid_ref(commit_sha):
last_successful_commit = commit_sha
successful_commits = set(run['commitSha'] for run in merge_runs if run['statusCode'] == 30)
commit_history = git.get_rev_list(max_count=100)
ordered_successful_commits = [commit for commit in commit_history if commit in successful_commits]
last_successful_commit = ordered_successful_commits[0] if ordered_successful_commits else None

if last_successful_commit is None:
display.warning('No successful commit found. All tests will be executed.')
Expand Down
4 changes: 2 additions & 2 deletions test/runner/lib/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def command_network_integration(args):
instances = [] # type: list [lib.thread.WrappedThread]

if args.platform:
get_coverage_path(args) # initialize before starting threads
get_coverage_path(args, args.python_executable) # initialize before starting threads

configs = dict((config['platform_version'], config) for config in args.metadata.instance_config)

Expand Down Expand Up @@ -514,7 +514,7 @@ def command_windows_integration(args):
httptester_id = None

if args.windows:
get_coverage_path(args) # initialize before starting threads
get_coverage_path(args, args.python_executable) # initialize before starting threads

configs = dict((config['platform_version'], config) for config in args.metadata.instance_config)

Expand Down
18 changes: 18 additions & 0 deletions test/runner/lib/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,24 @@ def get_branch(self):
cmd = ['symbolic-ref', '--short', 'HEAD']
return self.run_git(cmd).strip()

def get_rev_list(self, commits=None, max_count=None):
"""
:type commits: list[str] | None
:type max_count: int | None
:rtype: list[str]
"""
cmd = ['rev-list']

if commits:
cmd += commits
else:
cmd += ['HEAD']

if max_count:
cmd += ['--max-count', '%s' % max_count]

return self.run_git_split(cmd)

def get_branch_fork_point(self, branch):
"""
:type branch: str
Expand Down
32 changes: 23 additions & 9 deletions test/runner/lib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
from configparser import ConfigParser

DOCKER_COMPLETION = {}

coverage_path = '' # pylint: disable=locally-disabled, invalid-name
COVERAGE_PATHS = {} # type: dict[str, str]


def get_docker_completion():
Expand Down Expand Up @@ -196,10 +195,10 @@ def intercept_command(args, cmd, target_name, capture=False, env=None, data=None
env = common_environment()

cmd = list(cmd)
inject_path = get_coverage_path(args)
config_path = os.path.join(inject_path, 'injector.json')
version = python_version or args.python_version
interpreter = find_python(version, path)
inject_path = get_coverage_path(args, interpreter)
config_path = os.path.join(inject_path, 'injector.json')
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)))

Expand All @@ -219,12 +218,13 @@ def intercept_command(args, cmd, target_name, capture=False, env=None, data=None
return run_command(args, cmd, capture=capture, env=env, data=data, cwd=cwd)


def get_coverage_path(args):
def get_coverage_path(args, interpreter):
"""
:type args: TestConfig
:type interpreter: str
:rtype: str
"""
global coverage_path # pylint: disable=locally-disabled, global-statement, invalid-name
coverage_path = COVERAGE_PATHS.get(interpreter)

if coverage_path:
return os.path.join(coverage_path, 'coverage')
Expand All @@ -251,13 +251,27 @@ def get_coverage_path(args):
os.mkdir(os.path.join(coverage_path, directory))
os.chmod(os.path.join(coverage_path, directory), stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)

atexit.register(cleanup_coverage_dir)
os.symlink(interpreter, os.path.join(coverage_path, 'coverage', 'python'))

if not COVERAGE_PATHS:
atexit.register(cleanup_coverage_dirs)

COVERAGE_PATHS[interpreter] = coverage_path

return os.path.join(coverage_path, 'coverage')


def cleanup_coverage_dir():
"""Copy over coverage data from temporary directory and purge temporary directory."""
def cleanup_coverage_dirs():
"""Clean up all coverage directories."""
for path in COVERAGE_PATHS.values():
display.info('Cleaning up coverage directory: %s' % path, verbosity=2)
cleanup_coverage_dir(path)


def cleanup_coverage_dir(coverage_path):
"""Copy over coverage data from temporary directory and purge temporary directory.
:type coverage_path: str
"""
output_dir = os.path.join(coverage_path, 'output')

for filename in os.listdir(output_dir):
Expand Down
6 changes: 3 additions & 3 deletions test/utils/shippable/tools/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def main():
# new build

data = dict(
globalEnv=['%s=%s' % (kp[0], kp[1]) for kp in args.env or []]
globalEnv=dict((kp[0], kp[1]) for kp in args.env or [])
)

if args.branch:
Expand All @@ -108,10 +108,10 @@ def main():
data['runId'] = args.run

url = 'https://api.shippable.com/projects/%s/newBuild' % project_id
response = requests.post(url, data, headers=headers)
response = requests.post(url, json=data, headers=headers)

if response.status_code != 200:
raise Exception(response.content)
raise Exception("HTTP %s: %s\n%s" % (response.status_code, response.reason, response.content))

print(json.dumps(response.json(), indent=4, sort_keys=True))

Expand Down