+function installed () {
+
+ # Check if the given utility is installed. Fail if not installed.
+ #
+ # Duplicate of common.sh function, as this file is also used standalone.
+ #
+ # Arguments:
+ # - ${1} - Utility to check.
+ # Returns:
+ # - 0 - If command is installed.
+ # - 1 - If command is not installed.
+
+ set -exuo pipefail
+
+ command -v "${1}"
+}
+
+
+function move_archives () {
+
+ # Move archive directory to top of workspace, if not already there.
+ #
+ # ARCHIVE_DIR is positioned relative to CSIT_DIR,
+ # but in some jobs CSIT_DIR is not same as WORKSPACE
+ # (e.g. under VPP_DIR). To simplify ci-management settings,
+ # we want to move the data to the top. We do not want simple copy,
+ # as ci-management is eager with recursive search.
+ #
+ # As some scripts may call this function multiple times,
+ # the actual implementation use copying and deletion,
+ # so the workspace gets "union" of contents (except overwrites on conflict).
+ # The consequence is empty ARCHIVE_DIR remaining after this call.
+ #
+ # As the source directory is emptied,
+ # the check for dirs being different is essential.
+ #
+ # Variables read:
+ # - WORKSPACE - Jenkins workspace, move only if the value is not empty.
+ # Can be unset, then it speeds up manual testing.
+ # - ARCHIVE_DIR - Path to directory with content to be moved.
+ # Directories updated:
+ # - ${WORKSPACE}/archives/ - Created if does not exist.
+ # Content of ${ARCHIVE_DIR}/ is moved.
+ # Functions called:
+ # - die - Print to stderr and exit.
+
+ set -exuo pipefail
+
+ if [[ -n "${WORKSPACE-}" ]]; then
+ target=$(readlink -f "${WORKSPACE}/archives")
+ if [[ "${target}" != "${ARCHIVE_DIR}" ]]; then
+ mkdir -p "${target}" || die "Archives dir create failed."
+ cp -rf "${ARCHIVE_DIR}"/* "${target}" || die "Copy failed."
+ rm -rf "${ARCHIVE_DIR}"/* || die "Delete failed."
+ fi
+ fi
+}
+
+
+function prepare_topology () {
+
+ # Prepare virtual testbed topology if needed based on flavor.
+
+ # Variables read:
+ # - TEST_CODE - String affecting test selection, usually jenkins job name.
+ # - NODENESS - Node multiplicity of testbed, either "2n" or "3n".
+ # - FLAVOR - Node flavor string, e.g. "clx" or "skx".
+ # Functions called:
+ # - die - Print to stderr and exit.
+ # - terraform_init - Terraform init topology.
+ # - terraform_apply - Terraform apply topology.