Created
January 24, 2020 07:32
-
-
Save toabctl/714520dcf17e670a0003c440a724f7e5 to your computer and use it in GitHub Desktop.
Get number of Ceph teuthology test cases over time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/usr/bin/python3 | |
""" | |
Get statistics out of teuthology | |
This needs a ceph repo git checkout. | |
Author: Thomas Bechtold <tbechtold@suse.com> | |
License: Apache-2.0 | |
""" | |
import argparse | |
import subprocess | |
import os | |
import contextlib | |
import json | |
import csv | |
@contextlib.contextmanager | |
def remember_cwd(): | |
curdir = os.getcwd() | |
try: | |
yield | |
finally: | |
os.chdir(curdir) | |
def _git_ref_before_date(year, month): | |
cmd = [ | |
'/usr/bin/git', | |
'rev-list', '-n', '1', | |
'--first-parent', | |
'--before="{}-{:02d}-01 00:00"'.format(year, month), | |
'master' | |
] | |
return subprocess.check_output(cmd, encoding='utf-8').strip() | |
def _git_checkout(rev): | |
cmd = [ | |
'/usr/bin/git', | |
'checkout', '--force', | |
'{}'.format(rev) | |
] | |
return subprocess.check_output(cmd, encoding='utf-8').strip() | |
def _teuthology_get_tests_from_suite(suite_dir): | |
cmd = [ | |
'teuthology-describe-tests', | |
suite_dir, | |
'-c', | |
'--format', 'json', | |
] | |
print('Calling now: ' + ' '.join(cmd)) | |
data = json.loads(subprocess.check_output(cmd, encoding='utf-8')) | |
return data['data'] | |
def parse_args(): | |
"""parse command line arguments""" | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--ceph-repo', default='/home/tom/devel/ceph/ceph/', | |
help='Path to a ceph git repo (default: %(default)s)') | |
parser.add_argument( | |
'--suites', default=['big', 'buildpackages', 'cephmetrics', 'experimental', | |
'fs', 'hadoop', 'kcephfs', 'krbd', 'marginal', 'mixed-clients', | |
'multimds', 'perf-basic', 'powercycle', 'rados', 'rbd', 'rgw', | |
'samba', 'smoke', 'stress', 'teuthology', 'tgt', 'upgrade'], | |
nargs='*', | |
help='Path to a ceph git repo (default: %(default)s)') | |
parser.add_argument('--years', default=[2018, 2019], nargs='*', | |
help='Years to get data for (default: %(default)s)') | |
return parser.parse_args() | |
def main(): | |
args = parse_args() | |
print(args) | |
if not os.path.isdir(args.ceph_repo): | |
raise Exception('ceph repo dir "{}" does not exist'.format(args.ceph_repo)) | |
with remember_cwd(): | |
os.chdir(args.ceph_repo) | |
data = {} | |
for year in args.years: | |
for month in range(0, 6): | |
month = month * 2 + 1 | |
ym = '{}-{}'.format(year, month) | |
data[ym] = {} | |
ref = _git_ref_before_date(year, month) | |
_git_checkout(ref) | |
print('git checkout of ref {} done ({})'.format(ref, ym)) | |
for suite in args.suites: | |
suite_dir = os.path.join(args.ceph_repo, 'qa', 'suites', suite) | |
if not os.path.exists(suite_dir): | |
print('suite "{}" not found ({})'.format(suite, ym)) | |
data[ym][suite] = 0 | |
else: | |
print('get suite data for {} ({})'.format(suite, ym)) | |
suite_data = _teuthology_get_tests_from_suite(suite_dir) | |
data[ym][suite] = len(suite_data) | |
print(data) | |
# print the whole data | |
with open('data.csv', 'w', newline='') as csvfile: | |
fieldnames = ['date', 'suite_name', 'suite_tests'] | |
writer = csv.DictWriter(csvfile, fieldnames=fieldnames) | |
writer.writeheader() | |
for date, suite_data in data.items(): | |
for suite_name, suite_tests in suite_data.items(): | |
writer.writerow({'date': date, 'suite_name': suite_name, 'suite_tests': suite_tests}) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment