Skip to content

Commit

Permalink
fix(cleanup): cleanup sct-runner when logs collected
Browse files Browse the repository at this point in the history
When test fail, often sct-runners are kept for long - especially in perf
tests. This is because of broken/unclear logic behind setting sct-runner
keep flags.

Fixed that logic to:
- when test timeouted and logs collected, keep sct-runner for another 6 h
- if logs were collected, regardless of test status, terminate
  sct-runner immediately
- otherwise keep for additional 48h
  • Loading branch information
soyacz authored and fruch committed Oct 28, 2024
1 parent 7cbe4d5 commit 3e98ac0
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions sdcm/sct_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -1261,16 +1261,8 @@ def _manage_runner_keep_tag_value(utc_now: datetime,
dry_run: bool = False) -> SctRunnerInfo:
LOGGER.info("Managing runner's tags. Timeout flag: %s, logs_collected: %s, dry_run: %s",
timeout_flag, sct_runner_info.logs_collected, dry_run)

if test_status == "SUCCESS" and sct_runner_info.logs_collected:
if not dry_run:
sct_runner_info.sct_runner_class.set_tags(sct_runner_info, {"keep": "0", "keep-action": "terminate"})
sct_runner_info.keep = 0
sct_runner_info.keep_action = "terminate"
return sct_runner_info

if not timeout_flag and sct_runner_info.logs_collected:
current_run_time_hrs = int((utc_now - sct_runner_info.launch_time).total_seconds() // 3600)
current_run_time_hrs = int((utc_now - sct_runner_info.launch_time).total_seconds() // 3600)
if timeout_flag and sct_runner_info.logs_collected:
new_keep_value = int(sct_runner_info.keep) - current_run_time_hrs + 6

if new_keep_value > 0:
Expand All @@ -1279,7 +1271,18 @@ def _manage_runner_keep_tag_value(utc_now: datetime,
sct_runner_info.keep = new_keep_value
return sct_runner_info

LOGGER.info("No changes to make to runner tags.")
if sct_runner_info.logs_collected:
if not dry_run:
sct_runner_info.sct_runner_class.set_tags(sct_runner_info, {"keep": "0", "keep-action": "terminate"})
sct_runner_info.keep = 0
sct_runner_info.keep_action = "terminate"
return sct_runner_info
else:
new_keep_value = current_run_time_hrs + 48
if not dry_run:
sct_runner_info.sct_runner_class.set_tags(sct_runner_info, {"keep": str(new_keep_value)})
sct_runner_info.keep = new_keep_value
return sct_runner_info


def clean_sct_runners(test_status: str,
Expand Down

0 comments on commit 3e98ac0

Please sign in to comment.