Skip to content

Commit

Permalink
Merge pull request #574 from fomars/develop
Browse files Browse the repository at this point in the history
save artifacts if validation fails
  • Loading branch information
fomars committed Apr 25, 2018
2 parents 4a61e3d + 9a1e33a commit a9bd1b4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
1 change: 1 addition & 0 deletions yandextank/core/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def main():
rc = worker.perform_test()
sys.exit(rc)
except Exception as ex:
worker.core._collect_artifacts()
logging.error("Exception: %s", ex)
logging.debug("Exception: %s", traceback.format_exc(ex))
sys.exit(1)
Expand Down
26 changes: 18 additions & 8 deletions yandextank/core/tankcore.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from yandextank.common.exceptions import PluginNotPrepared
from yandextank.common.interfaces import GeneratorPlugin
from yandextank.validator.validator import TankConfig
from yandextank.validator.validator import TankConfig, ValidationError
from yandextank.aggregator import TankAggregator
from ..common.util import update_status, pid_exists
from ..plugins.Telegraf import Plugin as TelegrafPlugin
Expand Down Expand Up @@ -102,9 +102,6 @@ def __init__(self, configs, artifacts_base_dir=None, artifacts_dir_name=None, cf
:param configs: list of dict
"""
self.raw_configs = configs
self.config = TankConfig(self.raw_configs,
with_dynamic_options=True,
core_section=self.SECTION)
self.status = {}
self._plugins = None
self._artifacts_dir = None
Expand All @@ -124,6 +121,13 @@ def __init__(self, configs, artifacts_base_dir=None, artifacts_dir_name=None, cf
self.interrupted = False

self.error_log = None

error_output = 'validation_error.yaml'
self.config = TankConfig(self.raw_configs,
with_dynamic_options=True,
core_section=self.SECTION,
error_output=error_output)
self.add_artifact_file(error_output)
#
# def get_uuid(self):
# return self.uuid
Expand Down Expand Up @@ -160,7 +164,10 @@ def save_config(self, filename):
@property
def artifacts_base_dir(self):
if not self._artifacts_base_dir:
artifacts_base_dir = os.path.expanduser(self.get_option(self.SECTION, "artifacts_base_dir"))
try:
artifacts_base_dir = os.path.expanduser(self.get_option(self.SECTION, "artifacts_base_dir"))
except ValidationError:
artifacts_base_dir = 'logs'
if not os.path.exists(artifacts_base_dir):
os.makedirs(artifacts_base_dir)
os.chmod(self.artifacts_base_dir, 0o755)
Expand Down Expand Up @@ -316,7 +323,7 @@ def plugins_post_process(self, retcode):
logger.error("Failed post-processing plugin %s: %s", plugin, exc_info=True)
if not retcode:
retcode = 1
self.__collect_artifacts()
self._collect_artifacts()
return retcode

def __setup_taskset(self, affinity, pid=None, args=None):
Expand All @@ -338,7 +345,7 @@ def __setup_taskset(self, affinity, pid=None, args=None):
logger.debug('Taskset setup failed w/ retcode :%s', retcode)
raise KeyError(stderr)

def __collect_artifacts(self):
def _collect_artifacts(self, validation_failed=False):
logger.debug("Collecting artifacts")
logger.info("Artifacts dir: %s", self.artifacts_dir)
for filename, keep in self.artifact_files.items():
Expand Down Expand Up @@ -525,7 +532,10 @@ def close(self):
@property
def artifacts_dir(self):
if not self._artifacts_dir:
dir_name = self.get_option(self.SECTION, 'artifacts_dir')
try:
dir_name = self.get_option(self.SECTION, 'artifacts_dir')
except ValidationError:
dir_name = None
if not dir_name:
date_str = datetime.datetime.now().strftime(
"%Y-%m-%d_%H-%M-%S.")
Expand Down

0 comments on commit a9bd1b4

Please sign in to comment.