Files
distcloud/distributedcloud/dccommon/tests/unit/test_utils_script.sh
Kyle MacLeod 886697755b Add timeout for prestage ansible playbooks
Fix an issue observed during the testing of a large-scale
subcloud prestage operation. In one of many rounds of test,
ansible hung in the middle of prestage of a subcloud causing
the whole strategy to hang for many hours. The process had
to be manually killed as strategy abort did not work in
this case.

The issue is addressed by invoking the 'ansible-playbook' call
via '/usr/bin/timeout'. The timeout command will kill the
ansible-playbook tree if the given timeout value is hit.

For now, only the prestaging operations are using the
new timeout. The original 'run_playbook' method is
preserved in order to reduce any risk in this new
method of invoking a subprocess.

When a timeout occurs, the ansible log is updated before
the process is killed. Example:

    2022-04-28-17:28:44 TIMEOUT (1800s) - playbook is terminated

Default timeout:
- We use a global timeout (default: 3600s / 1hr)
- The default can be modified from the [DEFAULTS] section
  in /etc/dcmanager/dcmanager.conf. To change it, add the
  'playbook_timeout' as shown below, then restart the
  dcmanager-manager service.

      playbook_timeout=3600

Future considerations (not part of this commit):
- In python3, this code can be simplified to
  use the new subprocess.run(timeout=val) method
  or Popen with p.wait(timeout=val)
- Beginning with ansible 2.10, we can introduce
  the ANSIBLE_TASK_TIMEOUT value to set a
  task-level timeout. This is not available
  in our current version of ansible (2.7.5)

Test Plan:

PASS:
Add unit tests covering:
  - no timeout given (maintain current functionality)
  - timeout given but not hit
  - timeout given; process is killed
  - timeout given; hung process (ignoring SIGTERM) is killed

Run prestage operations as normal
  - no regression

Modify default timeout to 5s, run prestage operations
  - verify that timeout occurs
  - verify that ansible-playbook is terminated
  - verify that ansible log file shows TIMEOUT log

Modify default timeout to 5s for a single sublcoud, then
run prestage operations
  - verify that only the single subcloud operation is killed

Modify prestage prestage-sw-packages/tasks/main.yml to use
'--bwlimit=128' in the rsync from registry.central. This slows down
the package prestaging, and the playbook timeout is reached.

Add a 'pause' task in the prestage-sw-packages ansible for a
single subcloud. Ensure just the one task times out.

Exercise non-prestaging ansible playbook (to ensure subprocess
Popen change does not impact other playbooks
  - provisioned a new subcloud

Closes-Bug: 1971994
Change-Id: Iaf1bee786afc505594c6671c959cc2650202ee6c
Signed-off-by: Kyle MacLeod <kyle.macleod@windriver.com>
2022-05-09 20:58:47 +00:00

22 lines
391 B
Bash
Executable File

#!/bin/bash
#
# Copyright (c) 2022 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
handle_signal_ignore() {
local signal=$?
echo "Caught signal: $signal (ignoring)"
}
echo "Process id: $BASHPID"
sleep_arg=${1:-30}
do_trap_arg=
if [ -n "$do_trap_arg" ]; then
# trap handle_signal_ignore INT QUIT TERM
trap handle_signal_ignore $do_trap_arg
fi
sleep "$sleep_arg"