[VOL-3007] Moving the scale pipeline in robot
Change-Id: I729685325f6b05e9f9f17f14e96d597c885ebe68
diff --git a/tests/scale/collect-result.py b/tests/scale/collect-result.py
new file mode 100644
index 0000000..f65ae31
--- /dev/null
+++ b/tests/scale/collect-result.py
@@ -0,0 +1,76 @@
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import argparse
+import os
+import xml.etree.ElementTree as ET
+from datetime import datetime
+
+dash = "-" * 75
+double_dash = "=" * 75
+
+
+def cut_string(str):
+ return (str[:48] + "..") if len(str) > 50 else str
+
+def format_key(str):
+ return str.replace("plot-", "").replace("-", " ")
+
+def read_file(file, plot_folder):
+ # create element tree object
+ tree = ET.parse(file)
+
+ # get root element
+ root = tree.getroot()
+
+ results = {}
+
+ print(double_dash)
+ print("{:<50}{:>10}{:>15}".format("Test Name", "Status", "Duration (s)"))
+ print(double_dash)
+ for test in root.findall("./suite/test"):
+ status = test.find(".status")
+ name = test.attrib["name"]
+ start = status.attrib["starttime"]
+ end = status.attrib["endtime"]
+ s = datetime.strptime(start[:-4], "%Y%m%d %H:%M:%S")
+ e = datetime.strptime(end[:-4], "%Y%m%d %H:%M:%S")
+ diff = e - s
+ print("{:<50}{:>10}{:>15}".format(cut_string(name), status.attrib["status"], diff.seconds))
+ print(dash)
+
+ # check if the test has a tag that starts with "plot-",
+ # if so store the result to create plot files for Jenkins
+ for tag in test.findall("./tags/tag"):
+ if "plot-" in tag.text:
+ results[tag.text] = diff.seconds
+
+ if not os.path.isdir(plot_folder):
+ os.mkdir(plot_folder)
+
+ for k, v in results.items():
+ f = open("%s/%s.txt" % (plot_folder, k), "a")
+ f.write("%s\n" % format_key(k))
+ f.write(str(v))
+ f.close()
+
+
+if __name__ == "__main__":
+ parser = argparse.ArgumentParser(prog="collect-result")
+ parser.add_argument("-r", "--robot-output", help="he robot output.xml file to process", default="output.xml"),
+ parser.add_argument("-p", "--plot-folder", help="here to output the files needed for the Jenkins plots", default="plots")
+
+ args = parser.parse_args()
+
+ read_file(args.robot_output, args.plot_folder)