diff options
author | Tibor Frank <tifrank@cisco.com> | 2019-01-02 09:49:01 +0100 |
---|---|---|
committer | Tibor Frank <tifrank@cisco.com> | 2019-01-02 14:45:07 +0000 |
commit | 42fe666a56bb77efec0dd08268ee57e6482962d3 (patch) | |
tree | fbb35431ef8da40ff47f2e66ff85ea4afd62813a /resources/tools/presentation_new/input_data_parser.py | |
parent | ff8ba5fd5fd066332b4b109caad09e5dbb86b853 (diff) |
Trending: Align the content of old and new dirs
Change-Id: I39d1f71adac0bad3dbe18a987909904ea5c1e6cb
Signed-off-by: Tibor Frank <tifrank@cisco.com>
Diffstat (limited to 'resources/tools/presentation_new/input_data_parser.py')
-rw-r--r-- | resources/tools/presentation_new/input_data_parser.py | 51 |
1 files changed, 48 insertions, 3 deletions
diff --git a/resources/tools/presentation_new/input_data_parser.py b/resources/tools/presentation_new/input_data_parser.py index 0712156f77..f7a2094e58 100644 --- a/resources/tools/presentation_new/input_data_parser.py +++ b/resources/tools/presentation_new/input_data_parser.py @@ -1,4 +1,4 @@ -# Copyright (c) 2018 Cisco and/or its affiliates. +# Copyright (c) 2019 Cisco and/or its affiliates. # 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: @@ -30,12 +30,19 @@ from robot import errors from collections import OrderedDict from string import replace from os import remove +from os.path import join +from datetime import datetime as dt +from datetime import timedelta from jumpavg.AvgStdevMetadataFactory import AvgStdevMetadataFactory from input_data_files import download_and_unzip_data_file from utils import Worker +# Separator used in file names +SEPARATOR = "__" + + class ExecutionChecker(ResultVisitor): """Class to traverse through the test suite structure. @@ -696,7 +703,7 @@ class ExecutionChecker(ResultVisitor): else: test_result["status"] = "FAIL" self._data["tests"][self._test_ID] = test_result - logging.error("The test '{0}' has no or more than one " + logging.debug("The test '{0}' has no or more than one " "multi-threading tags.".format(self._test_ID)) logging.debug("Tags: {0}".format(test_result["tags"])) return @@ -1139,7 +1146,45 @@ class InputData(object): remove(build["file-name"]) except OSError as err: logs.append(("ERROR", "Cannot remove the file '{0}': {1}". - format(build["file-name"], err))) + format(build["file-name"], repr(err)))) + + # If the time-period is defined in the specification file, remove all + # files which are outside the time period. + timeperiod = self._cfg.input.get("time-period", None) + if timeperiod and data: + now = dt.utcnow() + timeperiod = timedelta(int(timeperiod)) + metadata = data.get("metadata", None) + if metadata: + generated = metadata.get("generated", None) + if generated: + generated = dt.strptime(generated, "%Y%m%d %H:%M") + if (now - generated) > timeperiod: + # Remove the data and the file: + state = "removed" + data = None + logs.append( + ("INFO", + " The build {job}/{build} is outdated, will be " + "removed".format(job=job, build=build["build"]))) + file_name = self._cfg.input["file-name"] + full_name = join( + self._cfg.environment["paths"]["DIR[WORKING,DATA]"], + "{job}{sep}{build}{sep}{name}". + format(job=job, + sep=SEPARATOR, + build=build["build"], + name=file_name)) + try: + remove(full_name) + logs.append(("INFO", + " The file {name} has been removed". + format(name=full_name))) + except OSError as err: + logs.append(("ERROR", + "Cannot remove the file '{0}': {1}". + format(full_name, repr(err)))) + logs.append(("INFO", " Done.")) result = { |