提交 674967ec 编写于 作者: A Amador Pahim

avocado.core.jobdata remove sys.exit() from core module

Raise an exception instead of sys.exit() inside the module and let
callers deal with the exception.
Signed-off-by: NAmador Pahim <apahim@redhat.com>
上级 d8ee4dbf
......@@ -20,9 +20,7 @@ import ast
import glob
import os
import pickle
import sys
from . import exit_codes
from .settings import settings
from ..utils.path import init_dir
......@@ -168,10 +166,7 @@ def get_resultsdir(logdir, jobid):
match_file = id_file
matches += 1
if matches > 1:
from logging import getLogger
getLogger("avocado.app").error("hash '%s' is not unique "
"enough", jobid)
sys.exit(exit_codes.AVOCADO_JOB_FAIL)
raise ValueError("hash '%s' is not unique enough" % jobid)
if matches == 1:
return os.path.dirname(match_file)
......
......@@ -339,7 +339,11 @@ class Diff(CLICmd):
logs_dir = settings.get_value('datadir.paths', 'logs_dir',
default=None)
logdir = os.path.expanduser(logs_dir)
resultsdir = jobdata.get_resultsdir(logdir, job_id)
try:
resultsdir = jobdata.get_resultsdir(logdir, job_id)
except ValueError as exception:
LOG.error(exception.message)
sys.exit(exit_codes.AVOCADO_JOB_FAIL)
if resultsdir is None:
LOG.error("Can't find job results directory for '%s' in '%s'",
......
......@@ -143,7 +143,11 @@ class Replay(CLI):
logs_dir = settings.get_value('datadir.paths', 'logs_dir',
default=None)
logdir = os.path.expanduser(logs_dir)
resultsdir = jobdata.get_resultsdir(logdir, args.replay_jobid)
try:
resultsdir = jobdata.get_resultsdir(logdir, args.replay_jobid)
except ValueError as exception:
log.error(exception.message)
sys.exit(exit_codes.AVOCADO_JOB_FAIL)
if resultsdir is None:
log.error("Can't find job results directory in '%s'", logdir)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册