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