-
Notifications
You must be signed in to change notification settings - Fork 3
/
openqa-db_query_last_use_of_module
executable file
·70 lines (55 loc) · 2.64 KB
/
openqa-db_query_last_use_of_module
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
#!/usr/bin/env python
"""
Helper script to find where a test module I want to change has been run last
As a test developer I would like to know where the test module I want to
change is triggered so that I could identify good candidates for validation
acceptance criteria.
"""
# Python 2 and 3: easiest option
# see http://python-future.org/compatible_idioms.html
from __future__ import absolute_import
from future.standard_library import install_aliases # isort:skip to keep 'install_aliases()'
install_aliases()
import argparse
import logging
import subprocess
import sys
logging.basicConfig()
log = logging.getLogger(sys.argv[0] if __name__ == "__main__" else __name__)
class CustomFormatter(argparse.ArgumentDefaultsHelpFormatter, argparse.RawDescriptionHelpFormatter):
"""Preserve multi-line __doc__ and provide default arguments in help strings."""
pass
def parse_args():
parser = argparse.ArgumentParser(description=__doc__, formatter_class=CustomFormatter)
parser.add_argument('-v', '--verbose',
help="Increase verbosity level, specify multiple times to increase verbosity", action='count', default=1)
parser.add_argument('--openqa-host', default="openqa.opensuse.org",
help="The openQA host to act on")
parser.add_argument('--module',
help="The failing module to look for")
parser.add_argument('--dry-run', action='store_true',
help="Do not do any action on the host")
parser.add_argument('--limit', type=int, default=30,
help="How many results to return")
parser.add_argument('--age', default='90 days',
help="How far to look back in history")
args = parser.parse_args()
verbose_to_log = {
0: logging.CRITICAL,
1: logging.ERROR,
2: logging.WARN,
3: logging.INFO,
4: logging.DEBUG
}
logging_level = logging.DEBUG if args.verbose > 4 else verbose_to_log[args.verbose]
log.setLevel(logging_level)
return args
def call(cmds, dry_run=False):
log.debug("call: %s" % cmds)
return subprocess.call((['echo', 'Simulating: '] if dry_run else []) + cmds)
def main():
args = parse_args()
sql_query = 'select distinct distri,version,flavor,test,arch,machine from jobs where id in (select job_id from job_modules where (name=\'{module}\')and t_updated > now() - interval \'{age}\') limit {limit};'.format(module=args.module, limit=args.limit, age=args.age)
call(['ssh', args.openqa_host] + ['sudo -u geekotest psql -t --command="{sql_query}" openqa'.format(sql_query=sql_query)], args.dry_run)
if __name__ == "__main__":
main()