forked from cockpit-project/bots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests-invoke
executable file
·83 lines (69 loc) · 2.78 KB
/
tests-invoke
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python3
# This file is part of Cockpit.
#
# Copyright (C) 2016 Red Hat, Inc.
#
# Cockpit is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Cockpit is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Cockpit; If not, see <http://www.gnu.org/licenses/>.
import argparse
import os
import subprocess
import sys
import time
from task import github
from machine.machine_core.directories import BASE_DIR
sys.dont_write_bytecode = True
def main():
parser = argparse.ArgumentParser(description='Run integration tests')
parser.add_argument('--repo', help="The repository in which the tested PR is opened", default=None)
parser.add_argument('--pull-number', help="The number of the pull request to test",
required=True)
parser.add_argument('--revision', help="Revision of the PR head", required=True)
opts = parser.parse_args()
def detect_collisions(opts):
api = github.GitHub(repo=opts.repo)
pull = api.get("pulls/{0}".format(opts.pull_number))
if pull:
if pull["head"]["sha"] != opts.revision:
return "Newer revision available on GitHub for this pull request"
if pull["state"] != "open":
return "Pull request isn't open"
return None
try:
entry_point = os.path.join(BASE_DIR, ".cockpit-ci", "run")
alt_entry_point = os.path.join(BASE_DIR, "test", "run")
if not os.path.exists(entry_point) and os.path.exists(alt_entry_point):
entry_point = alt_entry_point
cmd = ["timeout", "120m", entry_point]
p = subprocess.Popen(cmd)
while p.poll() is None:
# Cancel test if PR gets updated while running
ret = detect_collisions(opts)
if ret:
sys.stderr.write('Collision detected, cancelling this test run: {0}\n'.format(ret))
ret = None
p.terminate()
p.wait(timeout=60)
else:
time.sleep(60)
return_code = p.returncode
sys.stderr.write("Test run finished, return code: {0}\n".format(return_code))
return return_code
except RuntimeError as ex:
ret = str(ex)
if ret:
sys.stderr.write("tests-invoke: {0}\n".format(ret))
return 1
return 0
if __name__ == '__main__':
sys.exit(main())