3
by Taihsiang Ho
init local and satellite directories |
1 |
#!/usr/bin/python
|
2 |
#
|
|
3 |
#
|
|
4 |
# PLEASE THINK TWICE BEFORE USING --batch_limit 0
|
|
5 |
# OTHERWISE THE LOADING IS HEAVY
|
|
6 |
#
|
|
7 |
#
|
|
8 |
# $ ./diffsbm.py -u foo -k foo 93246 93262 --batch_limit 0
|
|
9 |
# <TEST ITEM> <93246 TEST STATUS> <93262 TEST STATUS>
|
|
10 |
# mediacard/mmc-insert-after-suspend pass fail
|
|
11 |
# networking/internet fail pass
|
|
12 |
# suspend/network_after_suspend uninitiated pass
|
|
13 |
# mediacard/sd-storage pass uninitiated
|
|
14 |
# mediacard/sd-remove-after-suspend fail uninitiated
|
|
15 |
# mediacard/mmc-storage-after-suspend pass uninitiated
|
|
16 |
# networking/ntp fail pass
|
|
17 |
# mediacard/sd-remove fail uninitiated
|
|
18 |
# keys/wireless fail untested
|
|
19 |
# mediacard/mmc-remove-after-suspend fail uninitiated
|
|
20 |
# mediacard/sd-storage-after-suspend pass uninitiated
|
|
21 |
# mediacard/sd-insert-after-suspend pass fail
|
|
22 |
# optical/cdrom-write_sr0 pass untested
|
|
23 |
# ......
|
|
24 |
#
|
|
25 |
# TODO:
|
|
26 |
# 1. handling the Key Error when keys is different in two submissions
|
|
27 |
# Key Error for key: networking/info_eth0
|
|
28 |
# 2. dump to a json file then we only need to access the site at first
|
|
29 |
# 3. LP: #1208757
|
|
30 |
||
31 |
||
32 |
||
33 |
||
34 |
||
35 |
||
36 |
#import ipdb
|
|
37 |
||
38 |
import argparse |
|
39 |
import requests |
|
40 |
import logging |
|
41 |
||
42 |
# This will be replaced by the method:
|
|
43 |
# getTestStatusByUrl
|
|
44 |
# to walk through the status by url and then
|
|
45 |
# the loading of the site could be smaller
|
|
46 |
#
|
|
47 |
# LP: #1208757
|
|
48 |
#
|
|
49 |
# input:args (args for future different protocal
|
|
50 |
# return: test report in json
|
|
51 |
def getTestRpt(args, rpt_no): |
|
52 |
||
53 |
api_uri = args.instance_uri + 'api/v1/testresults/?report__id=' + rpt_no |
|
54 |
api_params = {'username': args.username, 'api_key': args.apikey, 'limit': args.batch_limit} |
|
55 |
result = requests.get(api_uri, params=api_params) |
|
56 |
||
57 |
return result.json() |
|
58 |
||
59 |
# input: test report in json
|
|
60 |
# return: dictionary = {"testing-items" : "status"}
|
|
61 |
def getTestStatus(rpt_json): |
|
62 |
||
63 |
rtn = {} |
|
64 |
for rpt_entry in rpt_json['objects']: |
|
65 |
rtn[rpt_entry['test']['name']] = rpt_entry['status'] |
|
66 |
||
67 |
return rtn |
|
68 |
||
69 |
# rprtprev, rptnext are dictionaries = {"testing-items" : "status"}
|
|
70 |
def diffTestStatus(rptprev, rptnext, mode): |
|
71 |
||
72 |
for entry in rptprev: |
|
73 |
try: |
|
74 |
if rptprev[entry] != rptnext[entry]: |
|
75 |
print "%s %s %s" % (entry, rptprev[entry], rptnext[entry]) |
|
76 |
except KeyError: |
|
77 |
print "Key Error for key: %s" % entry |
|
78 |
||
79 |
||
80 |
def main(): |
|
81 |
# parsing the arguments and initializing the parameters
|
|
82 |
parser = argparse.ArgumentParser() |
|
83 |
parser.add_argument('--batch_limit', type=int, default=1, |
|
84 |
help='Number of element in a batch result. 0 for as many as possible') |
|
85 |
parser.add_argument('--instance_uri', |
|
86 |
default="https://certification.canonical.com/", |
|
87 |
help='Certification site URI. ') |
|
88 |
parser.add_argument('-u', '--username', help='User name', required=True) |
|
89 |
parser.add_argument('-k', '--apikey', help='API key', required=True) |
|
90 |
parser.add_argument('-m', '--mode', |
|
91 |
default='all', |
|
92 |
help='pass, fail or skipped. Default is all') |
|
93 |
parser.add_argument('rptprev', |
|
94 |
help='a benchmark test report. Input the report number.') |
|
95 |
parser.add_argument('rptnext', |
|
96 |
help='a test report compared to the benchmark test report. Input the report number.') |
|
97 |
parser.add_argument("-d", "--debug", help="Set debug mode", |
|
98 |
# action='store_const', const=logging.DEBUG,
|
|
99 |
default=logging.WARNING) |
|
100 |
||
101 |
args = parser.parse_args() |
|
102 |
||
103 |
logging.basicConfig(level=args.debug) |
|
104 |
||
105 |
rptprev_json = getTestRpt(args, args.rptprev) |
|
106 |
rptnext_json = getTestRpt(args, args.rptnext) |
|
107 |
||
108 |
rptprev_status = getTestStatus(rptprev_json) |
|
109 |
rptnext_status = getTestStatus(rptnext_json) |
|
110 |
||
111 |
diffTestStatus(rptprev_status, rptnext_status, args.mode) |
|
112 |
||
113 |
||
114 |
if __name__ == "__main__": |
|
115 |
main() |