1 from datetime import datetime
5 import xml.etree.ElementTree as ET
13 datetime.fromtimestamp(ts).strftime('%Y-%m-%dT%H:%M:%S.%fZ')
14 BODY['@timestamp'] = formatted_ts
16 # Plots are obtained from csv files ( in archives directory in $WORKSPACE).
18 csv_files = glob.glob('archives/*.csv')
19 BODY['project'] = 'opendaylight'
20 BODY['subject'] = 'test'
22 # If there are no csv files, then it is a functional test.
23 # Parse csv files and fill perfomance parameter values
25 if len(csv_files) == 0:
26 BODY['test-type'] = 'functional'
28 BODY['test-type'] = 'performance'
31 key = (f.split('/')[-1])[:-4]
32 BODY['plots'][key] = {}
34 lines = file.readlines()
35 props = lines[0].strip().split(',')
36 vals = lines[1].strip().split(',')
37 for i in range(len(props)):
38 BODY['plots'][key][props[i]] = float(vals[i])
40 # Fill the required parameters whose values are obtained from environment.
42 BODY['jenkins-silo'] = os.environ['SILO']
43 BODY['test-name'] = os.environ['JOB_NAME']
44 BODY['test-run'] = int(os.environ['BUILD_NUMBER'])
46 # Parsing robot log for stats on start-time, pass/fail tests and duration.
48 robot_log = os.environ['WORKSPACE'] + '/output.xml'
49 tree = ET.parse(robot_log)
50 BODY['id'] = '{}-{}'.format(os.environ['JOB_NAME'],
51 os.environ['BUILD_NUMBER'])
52 BODY['start-time'] = tree.getroot().attrib['generated']
53 BODY['pass-tests'] = int(tree.getroot().find('statistics')
55 BODY['fail-tests'] = int(tree.getroot().find('statistics')
57 endtime = tree.getroot().find('suite').find('status').get('endtime')
58 starttime = tree.getroot().find('suite').find('status').get('starttime')
59 elap_time = datetime.strptime(endtime, '%Y%m%d %H:%M:%S.%f') \
60 - datetime.strptime(starttime, '%Y%m%d %H:%M:%S.%f')
61 BODY['duration'] = str(elap_time)