aboutsummaryrefslogtreecommitdiffstats
path: root/resources/libraries/bash/function/common.sh
diff options
context:
space:
mode:
authorVratko Polak <vrpolak@cisco.com>2020-11-26 10:25:06 +0100
committerTibor Frank <tifrank@cisco.com>2020-12-03 05:03:39 +0000
commit7ea5bcd7dc334246307a50459fad80561580fa7e (patch)
treebc14d8f61093fe955311075f49a1224254c13b09 /resources/libraries/bash/function/common.sh
parent2f4a2fd01579816b7cccb1d640642fba03d96a30 (diff)
Avoid ci-management archiving files twice
This is a follow-up to https://gerrit.fd.io/r/c/csit/+/20394 https://gerrit.fd.io/r/20119 has changed the way archival works, everything should now go to logs.fd.io (instead of appearing on run page in jenkins.fd.io). The glob pattern for archiving is quite eager, doing recursive search. That is good, as it can find also misplaced useful outputs. But it also means our usage of copy_archives function creates two copies of archived directtories, usually archives/ and archives/archive/. This change renames copy_archives to move_archives, with few workarounds to support multiple calls. I also renamed ARCHIVE_DIR value from $CSIT_DIR/archive to $CSIT_DIR/archives to make "move" operation look natural. Finally, download_builds function is being removed, as after recent improvements to VPP compilation speed nobody seems to be using it. Change-Id: I19a429e1dfdfaab7fcf32a9609963b1aebd33c6c Signed-off-by: Vratko Polak <vrpolak@cisco.com> (cherry picked from commit 523c6e6e24101206ff1318ca17c310dff8b3c9d2)
Diffstat (limited to 'resources/libraries/bash/function/common.sh')
-rw-r--r--resources/libraries/bash/function/common.sh71
1 files changed, 44 insertions, 27 deletions
diff --git a/resources/libraries/bash/function/common.sh b/resources/libraries/bash/function/common.sh
index af59bc4ed3..c0aa5f9f7d 100644
--- a/resources/libraries/bash/function/common.sh
+++ b/resources/libraries/bash/function/common.sh
@@ -198,7 +198,8 @@ function common_dirs () {
# - RESOURCES_DIR - Path to existing CSIT subdirectory "resources".
# - TOOLS_DIR - Path to existing resources subdirectory "tools".
# - PYTHON_SCRIPTS_DIR - Path to existing tools subdirectory "scripts".
- # - ARCHIVE_DIR - Path to created CSIT subdirectory "archive".
+ # - ARCHIVE_DIR - Path to created CSIT subdirectory "archives".
+ # The name is chosen to match what ci-management expects.
# - DOWNLOAD_DIR - Path to created CSIT subdirectory "download_dir".
# - GENERATED_DIR - Path to created CSIT subdirectory "generated".
# Directories created if not present:
@@ -240,7 +241,7 @@ function common_dirs () {
die "Readlink failed."
}
- ARCHIVE_DIR=$(readlink -f "${CSIT_DIR}/archive") || {
+ ARCHIVE_DIR=$(readlink -f "${CSIT_DIR}/archives") || {
die "Readlink failed."
}
mkdir -p "${ARCHIVE_DIR}" || die "Mkdir failed."
@@ -295,31 +296,6 @@ function compose_pybot_arguments () {
}
-function copy_archives () {
-
- # Create additional archive if workspace variable is set.
- # This way if script is running in jenkins all will be
- # automatically archived to logs.fd.io.
- #
- # Variables read:
- # - WORKSPACE - Jenkins workspace, copy 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 copied.
- # Directories updated:
- # - ${WORKSPACE}/archives/ - Created if does not exist.
- # Content of ${ARCHIVE_DIR}/ is copied here.
- # Functions called:
- # - die - Print to stderr and exit.
-
- set -exuo pipefail
-
- if [[ -n "${WORKSPACE-}" ]]; then
- mkdir -p "${WORKSPACE}/archives/" || die "Archives dir create failed."
- cp -rf "${ARCHIVE_DIR}"/* "${WORKSPACE}/archives" || die "Copy failed."
- fi
-}
-
-
function deactivate_docker_topology () {
# Deactivate virtual vpp-device topology by removing containers.
@@ -568,6 +544,47 @@ function installed () {
}
+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 reserve_and_cleanup_testbed () {
# Reserve physical testbed, perform cleanup, register trap to unreserve.