Skip to content

Commit

Permalink
GET multiple archived files in one shot (feature)
Browse files Browse the repository at this point in the history
* add scripted test (CLI, 'archregx' & 'archmode=wdskey')
* part seven, prev. commit: 473a637

Signed-off-by: Alex Aizman <[email protected]>
  • Loading branch information
alex-aizman committed May 15, 2024
1 parent 2ce1aae commit dc03799
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ais/test/scripted_cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,14 @@ func TestRemaisBlobDownloadScript(t *testing.T) {
}
tassert.CheckFatal(t, err)
}

// get-archregx-wdskey.sh
func TestGetArchregxWdskeyScript(t *testing.T) {
cmd := exec.Command("./scripts/get-archregx-wdskey.sh")

out, err := cmd.CombinedOutput()
if len(out) > 0 {
tlog.Logln(string(out))
}
tassert.CheckFatal(t, err)
}
91 changes: 91 additions & 0 deletions ais/test/scripts/get-archregx-wdskey.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/bin/bash

# Prerequisites: ########################################################################################
# - aistore cluster
# - ais (CLI)
#
## Example usage:
## 1. ./ais/test/scripts/get-archregx-wdskey.sh
## 2. ./ais/test/scripts/get-archregx-wdskey.sh --bck ais://abc
## 3. ./ais/test/scripts/get-archregx-wdskey.sh --bck ais://abc --dir /tmp/out
# #######################################################################################################

# command line

while (( "$#" )); do
case "${1}" in
--bck) bck=$2; shift; shift;;
--dir) dir=$2; shift; shift;;
*) echo "fatal: unknown argument '${1}'"; exit 1;;
esac
done

## runtime constants
#### random suffix & destination subdirectory
rand=$RANDOM

#### generate that many WD-formatted shards
num=32

## establish existence
bck_check_rc=1
if [ ! -z "$bck" ]; then
ais show bucket $bck -c 1>/dev/null 2>&1
bck_check_rc=$?
fi
dir_check_rc=1
if [ ! -z "$dir" ]; then
ls $dir 1>/dev/null 2>&1
dir_check_rc=$?
fi

if [[ $bck_check_rc != 0 ]]; then
if [ -z "$bck" ]; then
bck="ais://archregx-$rand"
fi
ais create $bck || exit 1
fi
if [[ $dir_check_rc != 0 ]]; then
if [ -z "$dir" ]; then
dir=$(mktemp -d -t archregx-XXX) || exit $?
else
mkdir $dir || exit $?
fi
else
dir="$dir/archregx-$rand"
mkdir $dir || exit $?
fi

cleanup() {
rc=$?
if [[ $bck_check_rc == 0 ]]; then
ais rmo $bck --prefix $rand 1>/dev/null
else
ais rmb $bck --yes 1>/dev/null
fi
rm -rf $dir 1>/dev/null

[[ $rc == 0 ]] && echo "PASS: $num tests"
exit $rc
}

trap cleanup EXIT INT TERM

## uncomment for verbose output
## set -x

ais archive gen-shards "$bck/$rand/shard-{01..$num}.tar" --fext '.mp3,.json,.cls'

shards=$(ais ls $bck --name-only | grep shard)

for s in $shards; do
files=$(ais archive ls $bck/$s -name-only | grep /)
for f in $files; do
if [ "${f: -4}" == ".cls" ]; then
name=$(basename -s .cls $f)
ais archive get $bck/$s $dir/$name.tar --archregx=$name --archmode=wdskey 1>/dev/null
cnt=$(tar tvf $dir/$name.tar | grep $name | wc -l)
[[ $cnt == 3 ]] || { echo "FAIL: $cnt != 3"; exit 1; }
fi
done
done

0 comments on commit dc03799

Please sign in to comment.