Report: Delete xml file when parsed
[csit.git] / resources / tools / presentation / input_data_parser.py
index 87d822f..0ad07a9 100644 (file)
 import re
 import pandas as pd
 import logging
+import xml.etree.ElementTree as ET
 
 from robot.api import ExecutionResult, ResultVisitor
 from robot import errors
 from collections import OrderedDict
 from string import replace
+from os import remove
 
 
 class ExecutionChecker(ResultVisitor):
@@ -170,7 +172,7 @@ class ExecutionChecker(ResultVisitor):
     REGEX_TOLERANCE = re.compile(r'^[\D\d]*LOSS_ACCEPTANCE:\s(\d*\.\d*)\s'
                                  r'[\D\d]*')
 
-    REGEX_VERSION = re.compile(r"(stdout: 'vat# vat# Version:)(\s*)(.*)")
+    REGEX_VERSION = re.compile(r"(return STDOUT Version:\s*)(.*)")
 
     REGEX_TCP = re.compile(r'Total\s(rps|cps|throughput):\s([0-9]*).*$')
 
@@ -243,13 +245,13 @@ class ExecutionChecker(ResultVisitor):
         :returns: Nothing.
         """
 
-        if msg.message.count("stdout: 'vat# vat# Version:"):
+        if msg.message.count("return STDOUT Version:"):
             self._version = str(re.search(self.REGEX_VERSION, msg.message).
-                                group(3))
+                                group(2))
             self._data["metadata"]["version"] = self._version
             self._msg_type = None
 
-            logging.debug("    VPP version: {0}".format(self._version))
+            logging.info("    VPP version: {0}".format(self._version))
 
     def _get_vat_history(self, msg):
         """Called when extraction of VAT command history is required.
@@ -584,7 +586,7 @@ class ExecutionChecker(ResultVisitor):
         :type setup_kw: Keyword
         :returns: Nothing.
         """
-        if setup_kw.name.count("Vpp Show Version Verbose") \
+        if setup_kw.name.count("Show Vpp Version On All Duts") \
                 and not self._version:
             self._msg_type = "setup-version"
             setup_kw.messages.visit(self)
@@ -758,6 +760,10 @@ class InputData(object):
         :rtype: dict
         """
 
+        tree = ET.parse(build["file-name"])
+        root = tree.getroot()
+        generated = root.attrib["generated"]
+
         with open(build["file-name"], 'r') as data_file:
             try:
                 result = ExecutionResult(data_file)
@@ -765,7 +771,7 @@ class InputData(object):
                 logging.error("Error occurred while parsing output.xml: {0}".
                               format(err))
                 return None
-        checker = ExecutionChecker(job=job, build=build)
+        checker = ExecutionChecker(job=job, build=build, generated=generated)
         result.visit(checker)
 
         return checker.data
@@ -789,7 +795,17 @@ class InputData(object):
                              format(build["build"]))
                 logging.info("    Processing the file '{0}'".
                              format(build["file-name"]))
+
                 data = InputData._parse_tests(job, build)
+
+                logging.info("    Removing the file '{0}'".
+                             format(build["file-name"]))
+                try:
+                    remove(build["file-name"])
+                    build["status"] = "processed"
+                except OSError as err:
+                    logging.error("   Cannot remove the file '{0}': {1}".
+                                  format(build["file-name"], err))
                 if data is None:
                     logging.error("Input data file from the job '{job}', build "
                                   "'{build}' is damaged. Skipped.".