52
by Taihsiang Ho
pickup-fglrx-needed-system.py prototype |
1 |
#!/usr/bin/python
|
2 |
#
|
|
3 |
# pickup-fglrx-needed-system.py
|
|
4 |
#
|
|
5 |
# PLEASE THINK TWICE BEFORE USING --batch_limit 0
|
|
6 |
# OTHERWISE THE LOADING IS HEAVY
|
|
7 |
#
|
|
77.1.1
by Taihsiang Ho
more comments, warning messages and usage |
8 |
# A script to pick up the systems needing fglrx to pass
|
52
by Taihsiang Ho
pickup-fglrx-needed-system.py prototype |
9 |
# certification based on the data on C3.
|
77.1.1
by Taihsiang Ho
more comments, warning messages and usage |
10 |
# This is not completed and not it could only find out
|
11 |
# the not with title "roprietary" and body containing "video".
|
|
12 |
# Please see the function is_proprietary_needed
|
|
13 |
#
|
|
14 |
# TODO: implement function is_amd_ait_gfx
|
|
15 |
#
|
|
16 |
# Usage:
|
|
17 |
# ./pickup-fglrx-needed-system.py -u USER -k API_KEY CID --batch_limit 0
|
|
18 |
#
|
|
19 |
# You may edit releases_precise to specify the releases
|
|
20 |
# you want to scan.
|
|
21 |
#
|
|
22 |
# --batch_limit 0 to help you get multiple certificates for one CID.
|
|
23 |
# please make sure you won't make the server have heavy loading before
|
|
24 |
# using it.
|
|
25 |
#
|
|
52
by Taihsiang Ho
pickup-fglrx-needed-system.py prototype |
26 |
|
27 |
import argparse |
|
28 |
import requests |
|
29 |
import logging |
|
30 |
||
77.1.1
by Taihsiang Ho
more comments, warning messages and usage |
31 |
# I want to scan 12.04 LTS to 12.04.4 LTS
|
32 |
# Please note I exclude 12.04.5 LTS
|
|
33 |
releases_precise = ["12.04.4 LTS", |
|
52
by Taihsiang Ho
pickup-fglrx-needed-system.py prototype |
34 |
"12.04.3 LTS", |
35 |
"12.04.2 LTS", |
|
36 |
"12.04.1 LTS", |
|
37 |
"12.04 LTS"] |
|
38 |
||
39 |
def get_machine_id_from_hardware_json(json_hardware): |
|
54
by Taihsiang Ho
test pickup-fglrx-needed-system.py via 201201-10383 and pass |
40 |
"""
|
41 |
@json_hardware, a json-to-python data structure.
|
|
42 |
@return: int, id_machine, which could be used to request certificates.
|
|
43 |
"""
|
|
44 |
return json_hardware['id'] |
|
52
by Taihsiang Ho
pickup-fglrx-needed-system.py prototype |
45 |
|
54
by Taihsiang Ho
test pickup-fglrx-needed-system.py via 201201-10383 and pass |
46 |
def get_machine_id_by_cid(args, cid): |
52
by Taihsiang Ho
pickup-fglrx-needed-system.py prototype |
47 |
"""
|
48 |
cid: 201201-10383
|
|
54
by Taihsiang Ho
test pickup-fglrx-needed-system.py via 201201-10383 and pass |
49 |
id_machine, int, which could be used to request certificates.
|
52
by Taihsiang Ho
pickup-fglrx-needed-system.py prototype |
50 |
"""
|
54
by Taihsiang Ho
test pickup-fglrx-needed-system.py via 201201-10383 and pass |
51 |
api_uri = args.instance_uri + 'api/v1/hardware/' + cid |
52
by Taihsiang Ho
pickup-fglrx-needed-system.py prototype |
52 |
api_params = {'username': args.username, |
53 |
'api_key': args.apikey, |
|
54 |
'limit': args.batch_limit} |
|
54
by Taihsiang Ho
test pickup-fglrx-needed-system.py via 201201-10383 and pass |
55 |
request_hardware = requests.get(api_uri, params=api_params) |
56 |
id_machine = get_machine_id_from_hardware_json(request_hardware.json()) |
|
52
by Taihsiang Ho
pickup-fglrx-needed-system.py prototype |
57 |
return id_machine |
58 |
||
59 |
||
60 |
def get_certificates_by_machine_id(args, id_machine): |
|
61 |
"""
|
|
62 |
id_machine: machine id, which could be used to request certificates.
|
|
63 |
@json_certificates: the requested json certificate info from C3.
|
|
64 |
"""
|
|
54
by Taihsiang Ho
test pickup-fglrx-needed-system.py via 201201-10383 and pass |
65 |
api_uri = args.instance_uri + 'api/v1/certificates/?machine='\ |
66 |
+ str(id_machine) |
|
52
by Taihsiang Ho
pickup-fglrx-needed-system.py prototype |
67 |
api_params = {'username': args.username, |
68 |
'api_key': args.apikey, |
|
69 |
'limit': args.batch_limit} |
|
54
by Taihsiang Ho
test pickup-fglrx-needed-system.py via 201201-10383 and pass |
70 |
request_certificates = requests.get(api_uri, params=api_params) |
71 |
return request_certificates.json() |
|
52
by Taihsiang Ho
pickup-fglrx-needed-system.py prototype |
72 |
|
73 |
||
74 |
def get_release_certificates(json_certificates): |
|
75 |
"""
|
|
76 |
@json_certificates: the requested json certificate info from C3.
|
|
77 |
@release_certificates: list,
|
|
78 |
release_certificates, [release_name_1, release_name_2,...],
|
|
79 |
the release names are strings.
|
|
80 |
"""
|
|
54
by Taihsiang Ho
test pickup-fglrx-needed-system.py via 201201-10383 and pass |
81 |
release_certificates = [] |
82 |
for certificate in json_certificates['objects']: |
|
83 |
release_certificates.append(certificate['release']['release']) |
|
52
by Taihsiang Ho
pickup-fglrx-needed-system.py prototype |
84 |
# TODO: validate there is no duplicate certified release.
|
85 |
return release_certificates |
|
86 |
||
87 |
||
88 |
def get_latest_release(release_certificates, release="precise"): |
|
89 |
"""
|
|
90 |
@release_certificates: list,
|
|
91 |
release_certificates, [release_name_1, release_name_2,...],
|
|
92 |
the release names are strings.
|
|
93 |
@release: precise, saucy, trusty ...etc.
|
|
94 |
@point_release_latest: string, the latest release, e.g. 12.04.5
|
|
95 |
"""
|
|
96 |
if release == "precise" : |
|
97 |
for point_release in releases_precise: |
|
98 |
try: |
|
99 |
release_certificates.index(point_release) |
|
100 |
point_release_latest = point_release |
|
54
by Taihsiang Ho
test pickup-fglrx-needed-system.py via 201201-10383 and pass |
101 |
break
|
52
by Taihsiang Ho
pickup-fglrx-needed-system.py prototype |
102 |
except ValueError: |
103 |
pass
|
|
104 |
return point_release_latest |
|
105 |
||
106 |
||
107 |
def get_certificate_from_json(json_certificates, release): |
|
108 |
"""
|
|
109 |
@json_certificates: the requested json certificate info from C3.
|
|
110 |
@release: string, e.g. "12.04.5 LTS"
|
|
54
by Taihsiang Ho
test pickup-fglrx-needed-system.py via 201201-10383 and pass |
111 |
@certificate: dict info for a certificate
|
52
by Taihsiang Ho
pickup-fglrx-needed-system.py prototype |
112 |
"""
|
54
by Taihsiang Ho
test pickup-fglrx-needed-system.py via 201201-10383 and pass |
113 |
for certificate in json_certificates['objects']: |
114 |
if certificate['release']['release'] == release : |
|
115 |
return certificate |
|
116 |
else: |
|
77.1.1
by Taihsiang Ho
more comments, warning messages and usage |
117 |
logging.warning("release name %s was not found." % release) |
52
by Taihsiang Ho
pickup-fglrx-needed-system.py prototype |
118 |
|
119 |
||
120 |
def is_amd_ait_gfx(json_certificate): |
|
121 |
"""
|
|
122 |
@json_certificate: json info for a certificate
|
|
123 |
"""
|
|
124 |
# TODO: implement it when knowing how to use C3 API
|
|
125 |
return True |
|
126 |
||
127 |
||
54
by Taihsiang Ho
test pickup-fglrx-needed-system.py via 201201-10383 and pass |
128 |
def is_proprietary_needed(certificate): |
52
by Taihsiang Ho
pickup-fglrx-needed-system.py prototype |
129 |
"""
|
130 |
check whether there is a note to say that needing
|
|
131 |
the proprietary driver to pass the certification.
|
|
54
by Taihsiang Ho
test pickup-fglrx-needed-system.py via 201201-10383 and pass |
132 |
@certificate: dict info for a certificate
|
52
by Taihsiang Ho
pickup-fglrx-needed-system.py prototype |
133 |
"""
|
54
by Taihsiang Ho
test pickup-fglrx-needed-system.py via 201201-10383 and pass |
134 |
for note in certificate['notes']: |
135 |
# TODO: the search condition could be smarter
|
|
136 |
if (note['title'].find('roprietary') > 0) and (note['body'].find('video') > 0): |
|
137 |
return True |
|
138 |
return False |
|
52
by Taihsiang Ho
pickup-fglrx-needed-system.py prototype |
139 |
|
140 |
def main(): |
|
141 |
# parsing the arguments and initializing the parameters
|
|
142 |
parser = argparse.ArgumentParser() |
|
143 |
parser.add_argument('--batch_limit', type=int, default=1, |
|
54
by Taihsiang Ho
test pickup-fglrx-needed-system.py via 201201-10383 and pass |
144 |
help='Number of element in a batch result. \ |
52
by Taihsiang Ho
pickup-fglrx-needed-system.py prototype |
145 |
0 for as many as possible') |
146 |
parser.add_argument('--instance_uri', |
|
147 |
default="https://certification.canonical.com/", |
|
148 |
help='Certification site URI. ') |
|
149 |
parser.add_argument('-u', '--username', help='User name', required=True) |
|
150 |
parser.add_argument('-k', '--apikey', help='API key', required=True) |
|
151 |
parser.add_argument('-m', '--mode', |
|
152 |
default='all', |
|
153 |
help='pass, fail or skipped. Default is all') |
|
154 |
parser.add_argument('cid', |
|
155 |
help='the canonical cid, e.g. 201201-10383') |
|
156 |
parser.add_argument("-d", "--debug", help="Set debug mode", |
|
157 |
# action='store_const', const=logging.DEBUG,
|
|
158 |
default=logging.WARNING) |
|
159 |
||
160 |
args = parser.parse_args() |
|
54
by Taihsiang Ho
test pickup-fglrx-needed-system.py via 201201-10383 and pass |
161 |
cid = args.cid |
52
by Taihsiang Ho
pickup-fglrx-needed-system.py prototype |
162 |
|
163 |
logging.basicConfig(level=args.debug) |
|
164 |
||
54
by Taihsiang Ho
test pickup-fglrx-needed-system.py via 201201-10383 and pass |
165 |
machine_id = get_machine_id_by_cid(args, cid) |
52
by Taihsiang Ho
pickup-fglrx-needed-system.py prototype |
166 |
|
167 |
json_certificates = get_certificates_by_machine_id(args, machine_id) |
|
168 |
||
169 |
json_certificate = get_certificate_from_json(json_certificates, |
|
54
by Taihsiang Ho
test pickup-fglrx-needed-system.py via 201201-10383 and pass |
170 |
get_latest_release(get_release_certificates(json_certificates))) |
52
by Taihsiang Ho
pickup-fglrx-needed-system.py prototype |
171 |
|
54
by Taihsiang Ho
test pickup-fglrx-needed-system.py via 201201-10383 and pass |
172 |
if is_amd_ait_gfx(json_certificate) and is_proprietary_needed(json_certificate): |
52
by Taihsiang Ho
pickup-fglrx-needed-system.py prototype |
173 |
#print "%s has AMD/ATI graphic cards and need fglrx" % args.cid
|
54
by Taihsiang Ho
test pickup-fglrx-needed-system.py via 201201-10383 and pass |
174 |
#print "https://certification.canonical.com/hardware/%s" % args.cid
|
175 |
print "%s https://certification.canonical.com/certificates/%s" % (args.cid, json_certificate['name']) |
|
52
by Taihsiang Ho
pickup-fglrx-needed-system.py prototype |
176 |
|
177 |
if __name__ == "__main__": |
|
178 |
main() |