tests: make salvage NCP report root-aware
This commit is contained in:
@@ -10,11 +10,13 @@ USER_NAME="SUPERVISOR"
|
||||
PASSWORD=""
|
||||
NETWARE_PATH="SYS:PUBLIC/SLVGCHK.TXT"
|
||||
UNIX_PATH="/var/mars_nwe/SYS/public/SLVGCHK.TXT"
|
||||
VOLUME_ROOT=""
|
||||
RECYCLE_REPOSITORY=".recycle"
|
||||
SALVAGE_REPOSITORY=".salvage"
|
||||
DELETED_BY=""
|
||||
OUT_FILE=""
|
||||
KEEP_GOING=1
|
||||
CLEAN_ARTIFACTS=1
|
||||
|
||||
usage() {
|
||||
cat <<USAGE
|
||||
@@ -23,10 +25,12 @@ Usage: $0 -S SERVER -U USER -P PASSWORD [options]
|
||||
Options:
|
||||
--path NETWARE_PATH NetWare file path to create/delete (default: $NETWARE_PATH)
|
||||
--unix-path UNIX_PATH Unix path corresponding to --path (default: $UNIX_PATH)
|
||||
--volume-root DIR Unix volume root; avoids deriving it from --unix-path
|
||||
--deleted-by NAME Expected directory below .recycle/.salvage (default: USER)
|
||||
--recycle-name NAME Recycle repository name (default: $RECYCLE_REPOSITORY)
|
||||
--salvage-name NAME Salvage metadata repository name (default: $SALVAGE_REPOSITORY)
|
||||
--out FILE Write the complete report to FILE as well as stdout
|
||||
--no-clean-artifacts Do not remove stale .recycle/.salvage test artifacts before NCP delete
|
||||
--stop-on-failure Stop after the first failing check
|
||||
-h, --help Show this help
|
||||
|
||||
@@ -49,6 +53,8 @@ while [ $# -gt 0 ]; do
|
||||
NETWARE_PATH=$2; shift 2 ;;
|
||||
--unix-path)
|
||||
UNIX_PATH=$2; shift 2 ;;
|
||||
--volume-root)
|
||||
VOLUME_ROOT=$2; shift 2 ;;
|
||||
--deleted-by)
|
||||
DELETED_BY=$2; shift 2 ;;
|
||||
--recycle-name)
|
||||
@@ -57,6 +63,8 @@ while [ $# -gt 0 ]; do
|
||||
SALVAGE_REPOSITORY=$2; shift 2 ;;
|
||||
--out)
|
||||
OUT_FILE=$2; shift 2 ;;
|
||||
--no-clean-artifacts)
|
||||
CLEAN_ARTIFACTS=0; shift ;;
|
||||
--stop-on-failure)
|
||||
KEEP_GOING=0; shift ;;
|
||||
-h|--help)
|
||||
@@ -84,6 +92,12 @@ case "$UNIX_PATH" in
|
||||
/*) ;;
|
||||
*) echo "--unix-path must be absolute" >&2; exit 2 ;;
|
||||
esac
|
||||
if [ -n "$VOLUME_ROOT" ]; then
|
||||
case "$VOLUME_ROOT" in
|
||||
/*) ;;
|
||||
*) echo "--volume-root must be absolute" >&2; exit 2 ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
REPORT_TMP=$(mktemp "${TMPDIR:-/tmp}/mars-salvage-ncp.XXXXXX")
|
||||
FAILURES=0
|
||||
@@ -176,6 +190,81 @@ relative_to_volume_root() {
|
||||
esac
|
||||
}
|
||||
|
||||
relative_from_netware_path() {
|
||||
local path=$1
|
||||
|
||||
path=${path#*:}
|
||||
path=${path#/}
|
||||
path=${path#\\}
|
||||
path=${path//\\//}
|
||||
printf '%s\n' "$path"
|
||||
}
|
||||
|
||||
resolve_case_path() {
|
||||
local root=$1
|
||||
local rel=$2
|
||||
local current=$root
|
||||
local old_ifs=$IFS
|
||||
local part entry found
|
||||
|
||||
rel=${rel#/}
|
||||
IFS=/
|
||||
for part in $rel; do
|
||||
[ -z "$part" ] && continue
|
||||
found=""
|
||||
if [ -d "$current" ]; then
|
||||
for entry in "$current"/* "$current"/.[!.]* "$current"/..?*; do
|
||||
[ -e "$entry" ] || continue
|
||||
if [ "$(basename -- "$entry" | tr '[:upper:]' '[:lower:]')" = \
|
||||
"$(printf '%s' "$part" | tr '[:upper:]' '[:lower:]')" ]; then
|
||||
found=$entry
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
if [ -n "$found" ]; then
|
||||
current=$found
|
||||
else
|
||||
current=$current/$part
|
||||
fi
|
||||
done
|
||||
IFS=$old_ifs
|
||||
printf '%s\n' "$current"
|
||||
}
|
||||
|
||||
|
||||
prepare_expected_paths() {
|
||||
if [ -z "$VOLUME_ROOT" ]; then
|
||||
VOLUME_ROOT=$(compute_unix_volume_root) || return 1
|
||||
fi
|
||||
if [ -z "$RELATIVE_PATH" ]; then
|
||||
RELATIVE_PATH=$(relative_to_volume_root "$UNIX_PATH" "$VOLUME_ROOT") || \
|
||||
RELATIVE_PATH=$(relative_from_netware_path "$NETWARE_PATH") || return 1
|
||||
fi
|
||||
RECYCLE_PATH=$(resolve_case_path "$VOLUME_ROOT" "$RECYCLE_REPOSITORY/$DELETED_BY/$RELATIVE_PATH")
|
||||
METADATA_PATH=$(resolve_case_path "$VOLUME_ROOT" "$SALVAGE_REPOSITORY/$DELETED_BY/$RELATIVE_PATH.json")
|
||||
return 0
|
||||
}
|
||||
|
||||
clean_stale_artifacts() {
|
||||
if [ "$CLEAN_ARTIFACTS" -eq 0 ]; then
|
||||
return 0
|
||||
fi
|
||||
section "pre-clean stale salvage artifacts"
|
||||
if [ -n "$METADATA_PATH" ] && [ -e "$METADATA_PATH" ]; then
|
||||
emit "rm '$METADATA_PATH'"
|
||||
rm -f -- "$METADATA_PATH" || fail_check "could not remove stale metadata: $METADATA_PATH"
|
||||
else
|
||||
emit "metadata clean"
|
||||
fi
|
||||
if [ -n "$RECYCLE_PATH" ] && [ -e "$RECYCLE_PATH" ]; then
|
||||
emit "rm '$RECYCLE_PATH'"
|
||||
rm -f -- "$RECYCLE_PATH" || fail_check "could not remove stale recycle payload: $RECYCLE_PATH"
|
||||
else
|
||||
emit "recycle payload clean"
|
||||
fi
|
||||
}
|
||||
|
||||
check_file() {
|
||||
local label=$1
|
||||
local path=$2
|
||||
@@ -215,35 +304,33 @@ emit "server=$SERVER"
|
||||
emit "user=$USER_NAME"
|
||||
emit "path=$NETWARE_PATH"
|
||||
emit "unix_path=$UNIX_PATH"
|
||||
if [ -n "$VOLUME_ROOT" ]; then
|
||||
emit "volume_root_arg=$VOLUME_ROOT"
|
||||
fi
|
||||
emit "deleted_by=$DELETED_BY"
|
||||
emit "recycle_repository=$RECYCLE_REPOSITORY"
|
||||
emit "salvage_repository=$SALVAGE_REPOSITORY"
|
||||
emit "clean_artifacts=$CLEAN_ARTIFACTS"
|
||||
|
||||
RELATIVE_PATH=""
|
||||
RECYCLE_PATH=""
|
||||
METADATA_PATH=""
|
||||
if prepare_expected_paths; then
|
||||
emit "volume_root=$VOLUME_ROOT"
|
||||
emit "relative_path=$RELATIVE_PATH"
|
||||
emit "recycle_path=$RECYCLE_PATH"
|
||||
emit "metadata_path=$METADATA_PATH"
|
||||
clean_stale_artifacts
|
||||
else
|
||||
fail_check "could not prepare expected paths before NCP delete"
|
||||
fi
|
||||
|
||||
run_cmd \
|
||||
"NCP create/delete" \
|
||||
"./ncp_delete_smoke -S '$SERVER' -U '$USER_NAME' -P ****** '$NETWARE_PATH'" \
|
||||
"$SCRIPT_DIR/ncp_delete_smoke" -S "$SERVER" -U "$USER_NAME" -P "$PASSWORD" "$NETWARE_PATH"
|
||||
|
||||
VOLUME_ROOT=$(compute_unix_volume_root) || {
|
||||
fail_check "could not compute Unix volume root from $NETWARE_PATH and $UNIX_PATH"
|
||||
VOLUME_ROOT=""
|
||||
}
|
||||
RELATIVE_PATH=""
|
||||
if [ -n "$VOLUME_ROOT" ]; then
|
||||
RELATIVE_PATH=$(relative_to_volume_root "$UNIX_PATH" "$VOLUME_ROOT") || {
|
||||
fail_check "could not derive relative path: unix_path=$UNIX_PATH volume_root=$VOLUME_ROOT"
|
||||
RELATIVE_PATH=""
|
||||
}
|
||||
fi
|
||||
|
||||
if [ -n "$RELATIVE_PATH" ]; then
|
||||
RECYCLE_PATH="$VOLUME_ROOT/$RECYCLE_REPOSITORY/$DELETED_BY/$RELATIVE_PATH"
|
||||
METADATA_PATH="$VOLUME_ROOT/$SALVAGE_REPOSITORY/$DELETED_BY/$RELATIVE_PATH.json"
|
||||
|
||||
emit "volume_root=$VOLUME_ROOT"
|
||||
emit "relative_path=$RELATIVE_PATH"
|
||||
emit "recycle_path=$RECYCLE_PATH"
|
||||
emit "metadata_path=$METADATA_PATH"
|
||||
|
||||
check_file "recycle payload" "$RECYCLE_PATH"
|
||||
check_file "salvage metadata sidecar" "$METADATA_PATH"
|
||||
|
||||
Reference in New Issue
Block a user