Skip to content

Commit

Permalink
Add timeout to CLI
Browse files Browse the repository at this point in the history
Signed-off-by: lachmanfrantisek <[email protected]>
  • Loading branch information
lachmanfrantisek committed Nov 7, 2018
1 parent 7c92d7d commit 7364391
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
5 changes: 4 additions & 1 deletion colin/cli/colin.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,12 @@ def cli():
@click.option('--target-type', type=click.STRING, default="image",
help="Type of selected target (one of image, dockerfile, "
"ostree). For ostree, please specify image name and path like this: image@path")
@click.option('--timeout', type=click.INT,
help="Timeout for each check in seconds. (default=600)")
@click.option('--insecure', is_flag=True, default=False,
help="Pull from an insecure registry (HTTP or invalid TLS).")
def check(target, ruleset, ruleset_file, debug, json, stat, skip, tag, verbose,
checks_paths, target_type, pull, insecure):
checks_paths, target_type, timeout, pull, insecure):
"""
Check the image/dockerfile (default).
"""
Expand All @@ -106,6 +108,7 @@ def check(target, ruleset, ruleset_file, debug, json, stat, skip, tag, verbose,
pull=pull,
checks_paths=checks_paths,
target_type=target_type,
timeout=timeout,
insecure=insecure,
skips=skip
)
Expand Down
10 changes: 6 additions & 4 deletions colin/core/check_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,21 @@
logger = logging.getLogger(__name__)


def go_through_checks(target, checks):
def go_through_checks(target, checks, timeout=None):
logger.debug("Going through checks.")
results = _result_generator(target=target,
checks=checks)
checks=checks,
timeout=timeout)
return CheckResults(results=results)


def _result_generator(target, checks):
def _result_generator(target, checks, timeout=None):
try:
for check in checks:
logger.debug("Checking {}".format(check.name))
try:
timeout = check.timeout or CHECK_TIMEOUT
timeout = timeout or check.timeout or CHECK_TIMEOUT
logger.debug("Check timeout: {}".format(timeout))
yield exit_after(timeout)(check.check)(target)
except TimeoutError as ex:
logger.warning(
Expand Down
4 changes: 3 additions & 1 deletion colin/core/colin.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ def run(
pull=None,
insecure=False,
skips=None,
timeout=None,
):
"""
Runs the sanity checks for the target.
:param timeout: timeout per-check (in seconds)
:param skips: name of checks to skip
:param target: str (image name, ostree or dockertar)
or Image (instance from conu)
Expand Down Expand Up @@ -72,7 +74,7 @@ def run(
checks_paths=checks_paths,
skips=skips,
)
result = go_through_checks(target=target, checks=checks_to_run)
result = go_through_checks(target=target, checks=checks_to_run, timeout=timeout)
return result


Expand Down

0 comments on commit 7364391

Please sign in to comment.