1 ##############################################################################
2 # Copyright (c) 2016 Max Breitenfeldt and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
15 from django.core.cache import cache
17 logger = logging.getLogger(__name__)
19 # TODO: implement caching decorator, cache get_* functions
21 if cache.get(url) is None:
23 response = requests.get(url)
24 json = response.json()
25 cache.set(url, json, 180) # cache result for 180 seconds
27 except requests.exceptions.RequestException as e:
29 except ValueError as e:
36 url = "https://build.opnfv.org/ci/computer/api/json?tree=computer[displayName,offline,idle]"
39 return json['computer'] # return list of dictionaries
43 def get_slave(slavename):
44 slaves = get_all_slaves()
46 if slave['displayName'] == slavename:
52 url = "https://build.opnfv.org/ci/label/ci-pod/api/json?tree=nodes[nodeName,offline,idle]"
60 url = "https://build.opnfv.org/ci/api/json?tree=jobs[displayName,url,lastBuild[fullDisplayName,building,builtOn,timestamp,result]]"
63 return json['jobs'] # return list of dictionaries
67 def get_jenkins_job(slavename):
72 if job['lastBuild'] is not None:
73 if job['lastBuild']['builtOn'] == slavename:
74 if job['lastBuild']['building'] is True:
75 return job # return active build
76 if job['lastBuild']['timestamp'] > max_time:
78 max_time = job['lastBuild']['timestamp']
82 def is_ci_slave(slavename):
83 ci_slaves = get_ci_slaves()
84 for ci_slave in ci_slaves:
85 if ci_slave['nodeName'] == slavename:
90 def is_dev_pod(slavename):
91 if is_ci_slave(slavename):
93 if slavename.find('pod') != -1:
99 result = parse_job_string(job['lastBuild']['fullDisplayName'])
100 result['building'] = job['lastBuild']['building']
101 result['result'] = ''
102 if not job['lastBuild']['building']:
103 result['result'] = job['lastBuild']['result']
104 result['url'] = job['url']
108 def parse_job_string(full_displayname):
111 job['installer'] = ''
113 tokens = re.split(r'[ -]', full_displayname)
114 for i in range(len(tokens)):
115 if tokens[i] == 'os':
116 job['scenario'] = '-'.join(tokens[i: i + 4])
117 elif tokens[i] in ['fuel', 'joid', 'apex', 'compass']:
118 job['installer'] = tokens[i]
119 elif tokens[i] in ['master', 'arno', 'brahmaputra', 'colorado']:
120 job['branch'] = tokens[i]
121 tokens = full_displayname.split(' ')
122 job['name'] = tokens[0]
125 def get_slave_url(slave):
126 return 'https://build.opnfv.org/ci/computer/' + slave['displayName']
129 def get_slave_status(slave):
130 if not slave['offline'] and slave['idle']:
131 return 'online / idle'
132 if not slave['offline']: