Skip to content

Commit

Permalink
bugfix in ada extended attributes; added integration tests for extend…
Browse files Browse the repository at this point in the history
…ed attributes
  • Loading branch information
hailihu committed Jan 27, 2025
1 parent f74c8a1 commit 817912d
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ brew install rclone
```
There are also optional dependencies to run tests and create macaroons:
```
brew install shunit2
brew install shunit2 (or get from `https://github.com/kward/shunit2`)
pip install pymacaroons
wget https://raw.githubusercontent.com/sara-nl/GridScripts/master/view-macaroon -P ada
wget https://raw.githubusercontent.com/sara-nl/GridScripts/master/get-macaroon -P ada
Expand Down
2 changes: 1 addition & 1 deletion ada/ada
Original file line number Diff line number Diff line change
Expand Up @@ -2099,7 +2099,7 @@ api_call () {
encoded_path=$(urlencode "$path")
case $command in
setxattr )
attributes=$(cat $attr_file)
attributes=$(cat $xattr_file)
xattr_json=$(to_json "$attributes")
echo "$xattr_json"
(
Expand Down
71 changes: 57 additions & 14 deletions tests/integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
# file: tests/integration_test.sh


# Check if version is as expected
test_ada_version() {
result=`ada/ada --version`
assertEquals "Check ada version:" "v2.2" ${result}
}


# Create directory on dCache
test_ada_mkdir() {
ada/ada --tokenfile ${token_file} --mkdir "/${disk_path}/${dirname}/${testdir}/${subdir}" --recursive --api ${api} >${stdoutF} 2>${stderrF}
result=$?
Expand All @@ -18,7 +19,7 @@ test_ada_mkdir() {
assertTrue "could not get locality" $?
}


# Move a file (created in oneTimeSetUp) to folder created in above test
test_ada_mv1() {
ada/ada --tokenfile ${token_file} --mv "/${disk_path}/${dirname}/${testfile}" "/${disk_path}/${dirname}/${testdir}/${testfile}" --api ${api} >${stdoutF} 2>${stderrF}
result=$?
Expand All @@ -27,7 +28,7 @@ test_ada_mv1() {
assertTrue "ada could not move the file" $?
}


# List file
test_ada_list_file() {
ada/ada --tokenfile ${token_file} --list "/${disk_path}/${dirname}/${testdir}/${testfile}" --api ${api} >${stdoutF} 2>${stderrF}
result=$?
Expand All @@ -36,7 +37,7 @@ test_ada_list_file() {
assertEquals "ada could not list the correct file" "/${disk_path}/${dirname}/${testdir}/${testfile}" "$result"
}


# Set label on a file
test_ada_setlabel() {
ada/ada --tokenfile ${token_file} --setlabel "/${disk_path}/${dirname}/${testdir}/${testfile}" "testlabel" --api ${api} >${stdoutF} 2>${stderrF}
result=$?
Expand All @@ -45,7 +46,7 @@ test_ada_setlabel() {
assertEquals "success" "$result"
}


# Find files in directory with specified label
test_ada_findlabel() {
ada/ada --tokenfile ${token_file} --findlabel "/${disk_path}/${dirname}/${testdir}" "testlabel" --api ${api} >${stdoutF} 2>${stderrF}
result=$?
Expand All @@ -54,7 +55,7 @@ test_ada_findlabel() {
assertTrue "ada could not find file with findlabel" $?
}


# List label of file
test_ada_lslabel() {
ada/ada --tokenfile ${token_file} --lslabel "/${disk_path}/${dirname}/${testdir}/${testfile}" --api ${api} >${stdoutF} 2>${stderrF}
result=$?
Expand All @@ -64,6 +65,7 @@ test_ada_lslabel() {
}


# Remove label of file
test_ada_rmlabel() {
ada/ada --tokenfile ${token_file} --rmlabel "/${disk_path}/${dirname}/${testdir}/${testfile}" "testlabel" --api ${api} >${stdoutF} 2>${stderrF}
result=$?
Expand All @@ -72,7 +74,47 @@ test_ada_rmlabel() {
assertEquals "success" "$result"
}

# Set extended attribute of file
test_ada_setxattr() {
echo "test=attribute" > ${outputDir}/attr_file
ada/ada --tokenfile ${token_file} --setxattr "/${disk_path}/${dirname}/${testdir}/${testfile}" ${outputDir}/attr_file --api ${api} >${stdoutF} 2>${stderrF}
result=$?
assertEquals "ada returned error code ${result}" 0 ${result} || return
grep "success" "${stdoutF}" >/dev/null
assertTrue "ada could not set extended attribute" $?
}

# List extended attribute of file
test_ada_lsxattr() {
ada/ada --tokenfile ${token_file} --lsxattr "/${disk_path}/${dirname}/${testdir}/${testfile}" --api ${api} >${stdoutF} 2>${stderrF}
result=$?
assertEquals "ada returned error code ${result}" 0 ${result} || return
grep '"test": "attribute"' "${stdoutF}" >/dev/null
assertTrue "ada could not list extended attribute" $?
}

# Find file with attribute with key-value pair
test_ada_findxattr() {
ada/ada --tokenfile ${token_file} --findxattr "/${disk_path}/${dirname}/${testdir}" "test" "attribute" --api ${api} >${stdoutF} 2>${stderrF}
result=$?
assertEquals "ada returned error code ${result}" 0 ${result} || return
grep "${testfile}" "${stdoutF}" >/dev/null
assertTrue "ada could not find file with extended attribute" $?
}

# Remove all attributes of file
test_ada_rmxattr() {
ada/ada --tokenfile ${token_file} --rmxattr "/${disk_path}/${dirname}/${testdir}/${testfile}" --all --api ${api} >${stdoutF} 2>${stderrF}
result=$?
assertEquals "ada returned error code ${result}" 0 ${result} || return
grep "success" "${stdoutF}" >/dev/null
assertTrue "ada could not list extended attribute" $?
ada/ada --tokenfile ${token_file} --lsxattr "/${disk_path}/${dirname}/${testdir}/${testfile}" --api ${api} >${stdoutF} 2>${stderrF}
result=`cat "${stdoutF}"`
assertEquals "{}" "$result"
}

# Get checksum of file
test_ada_checksum_file() {
ada/ada --tokenfile ${token_file} --checksum "/${disk_path}/${dirname}/${testdir}/${testfile}" --api ${api} >${stdoutF} 2>${stderrF}
result=$?
Expand All @@ -81,7 +123,7 @@ test_ada_checksum_file() {
assertTrue "ada could not get checksum of file" $?
}


# Get checksum of files in a directory
test_ada_checksum_dir() {
ada/ada --tokenfile ${token_file} --checksum "/${disk_path}/${dirname}/${testdir}" --api ${api} >${stdoutF} 2>${stderrF}
result=$?
Expand All @@ -90,7 +132,7 @@ test_ada_checksum_dir() {
assertTrue "ada could not get checksum of file" $?
}


# List files in directory
test_ada_list_dir() {
ada/ada --tokenfile ${token_file} --list "/${disk_path}/${dirname}/${testdir}" --api ${api} >${stdoutF} 2>${stderrF}
result=$?
Expand All @@ -99,7 +141,7 @@ test_ada_list_dir() {
assertTrue "ada could not list the correct directory" $?
}


# List files in directory with details
test_ada_longlist() {
ada/ada --tokenfile ${token_file} --longlist "/${disk_path}/${dirname}/${testdir}/${testfile}" --api ${api} >${stdoutF} 2>${stderrF}
result=$?
Expand All @@ -109,6 +151,7 @@ test_ada_longlist() {
}


# Show all details of file or directory
test_ada_stat() {
ada/ada --tokenfile ${token_file} --stat "/${disk_path}/${dirname}/${testdir}/${testfile}" --api ${api} >${stdoutF} 2>${stderrF}
result=$?
Expand Down Expand Up @@ -136,7 +179,7 @@ test_ada_delete() {
assertTrue "ada could not delete the directory" $?
}


# Stage a file
test_ada_stage_file() {
ada/ada --tokenfile ${token_file} --stage "/${tape_path}/${dirname}/${testfile}" --api ${api} >${stdoutF} 2>${stderrF}
result=$?
Expand All @@ -148,7 +191,7 @@ test_ada_stage_file() {
assertEquals "State of target:" "COMPLETED" $state
}


# Unstage a file
test_ada_unstage_file() {
ada/ada --tokenfile ${token_file} --unstage "/${tape_path}/${dirname}/${testfile}" --api ${api} >${stdoutF} 2>${stderrF}
result=$?
Expand All @@ -160,6 +203,7 @@ test_ada_unstage_file() {
assertEquals "State of target:" "COMPLETED" $state
}

# Stages files in file_list
test_ada_stage_filelist() {
echo "/${tape_path}/${dirname}/${testfile}" > ${outputDir}/file_list
ada/ada --tokenfile ${token_file} --stage --from-file ${outputDir}/file_list --api ${api} >${stdoutF} 2>${stderrF}
Expand All @@ -172,7 +216,7 @@ test_ada_stage_filelist() {
assertEquals "State of target:" "COMPLETED" $state
}


# Unstage files in file_list
test_ada_unstage_filelist() {
ada/ada --tokenfile ${token_file} --unstage --from-file ${outputDir}/file_list --api ${api} >${stdoutF} 2>${stderrF}
result=$?
Expand All @@ -184,15 +228,14 @@ test_ada_unstage_filelist() {
assertEquals "State of target:" "COMPLETED" $state
}


# Test if ada exits with error when staging non-existing file
test_ada_stage_file_error() {
ada/ada --tokenfile ${token_file} --stage "/${tape_path}/${dirname}/testerror" --api ${api} >${stdoutF} 2>${stderrF}
result=$?
assertEquals "ada returned error code ${result}" 1 ${result}
}


# Set up for tests
oneTimeSetUp() {
outputDir="${SHUNIT_TMPDIR}/output"
# outputDir="output"
Expand Down

0 comments on commit 817912d

Please sign in to comment.