mirror of
https://github.com/clearlinux/swupd-client.git
synced 2026-09-03 20:21:29 +00:00
Define size of test environment
Sometimes is useful to be able to limit the size of a test environment to validate some scenarios that are bound to disk size. This commit adds a -s (size) option that can be used when creating test environments so the user can control how much space is available in that environment. If not used, the test environment works the same as before. Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
This commit is contained in:
committed by
Otavio Pontes
parent
116a4c612e
commit
39e2d40127
@@ -8,8 +8,8 @@ test_setup() {
|
||||
create_bundle -n test-bundle -f /usr/bin/test-file "$TEST_NAME"
|
||||
# set up state directory with bad hash file and pack hint
|
||||
file_hash=$(get_hash_from_manifest "$TEST_NAME"/web-dir/10/Manifest.test-bundle /usr/bin/test-file)
|
||||
sudo sh -c "echo \"test file MODIFIED\" > $TEST_NAME/state/staged/$file_hash"
|
||||
sudo touch "$TEST_NAME"/state/pack-test-bundle-from-0-to-10.tar
|
||||
sudo sh -c "echo \"test file MODIFIED\" > $STATEDIR/staged/$file_hash"
|
||||
sudo touch "$STATEDIR"/pack-test-bundle-from-0-to-10.tar
|
||||
|
||||
}
|
||||
|
||||
@@ -18,13 +18,13 @@ test_setup() {
|
||||
# since one of the files needed to install the bundle is already in the state/staged
|
||||
# directory, in theory this one should be used instead of downloading it again...
|
||||
# however since the hash of this file is wrong it should be deleted and re-downloaded
|
||||
hash_before=$(sudo "$SWUPD" hashdump "$TEST_NAME"/state/staged/"$file_hash")
|
||||
hash_before=$(sudo "$SWUPD" hashdump "$STATEDIR"/staged/"$file_hash")
|
||||
|
||||
run sudo sh -c "$SWUPD bundle-add $SWUPD_OPTS test-bundle"
|
||||
|
||||
assert_status_is 0
|
||||
hash_after=$(sudo "$SWUPD" hashdump "$TEST_NAME"/state/staged/"$file_hash")
|
||||
assert_file_exists "$TEST_NAME"/target-dir/usr/bin/test-file
|
||||
hash_after=$(sudo "$SWUPD" hashdump "$STATEDIR"/staged/"$file_hash")
|
||||
assert_file_exists "$TARGETDIR"/usr/bin/test-file
|
||||
assert_not_equal "$hash_before" "$hash_after"
|
||||
expected_output=$(cat <<-EOM
|
||||
Starting download of remaining update content. This may take a while...
|
||||
|
||||
@@ -25,14 +25,13 @@ test_setup() {
|
||||
# downloaded fullfile had a bad hash - immediately fatal with a 1 return code
|
||||
assert_status_is 1
|
||||
# the bad hash file should not exist on the system
|
||||
assert_file_not_exists "$TEST_NAME"/target-dir/usr/bin/file1
|
||||
assert_file_not_exists "$TARGETDIR"/usr/bin/file1
|
||||
expected_output=$(cat <<-EOM
|
||||
Starting download of remaining update content. This may take a while...
|
||||
Finishing download of update content...
|
||||
Error: File content hash mismatch for $TEST_DIRNAME/state/staged/e6d85023c5e619eb43d5cfbfdbdec784afef5a82ffa54e8c93bda3e0883360a3 (bad server data?)
|
||||
Error: File content hash mismatch for $TEST_DIRNAME/testfs/state/staged/e6d85023c5e619eb43d5cfbfdbdec784afef5a82ffa54e8c93bda3e0883360a3 (bad server data?)
|
||||
EOM
|
||||
)
|
||||
assert_is_output "$expected_output"
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ test_setup() {
|
||||
run sudo sh -c "$SWUPD bundle-add $SWUPD_OPTS test-bundle"
|
||||
|
||||
assert_status_is 0
|
||||
assert_file_exists "$TEST_NAME/target-dir/usr/lib/kernel/test-file"
|
||||
assert_file_exists "$TARGETDIR/usr/lib/kernel/test-file"
|
||||
expected_output=$(cat <<-EOM
|
||||
Starting download of remaining update content. This may take a while...
|
||||
Finishing download of update content...
|
||||
|
||||
@@ -15,7 +15,7 @@ test_setup() {
|
||||
run sudo sh -c "$SWUPD bundle-add -b $SWUPD_OPTS test-bundle"
|
||||
|
||||
assert_status_is 0
|
||||
assert_file_exists "$TEST_NAME/target-dir/usr/lib/kernel/test-file"
|
||||
assert_file_exists "$TARGETDIR/usr/lib/kernel/test-file"
|
||||
expected_output=$(cat <<-EOM
|
||||
Starting download of remaining update content. This may take a while...
|
||||
Finishing download of update content...
|
||||
|
||||
@@ -73,7 +73,7 @@ global_teardown() {
|
||||
run sudo sh -c "$SWUPD bundle-add $SWUPD_OPTS test-bundle"
|
||||
|
||||
assert_status_is 0
|
||||
assert_file_exists "$TEST_NAME"/target-dir/usr/bin/test-file
|
||||
assert_file_exists "$TARGETDIR"/usr/bin/test-file
|
||||
}
|
||||
|
||||
@test "ADD024: Try adding bundle over HTTPS with no client certificate" {
|
||||
|
||||
@@ -8,7 +8,7 @@ test_setup() {
|
||||
create_bundle -n test-bundle1 -f /foo/test-file1 "$TEST_NAME"
|
||||
create_bundle -n test-bundle2 -f /bar/test-file2 "$TEST_NAME"
|
||||
# add test-bundle2 as a dependency of test-bundle1
|
||||
add_dependency_to_manifest "$TEST_NAME"/web-dir/10/Manifest.test-bundle1 test-bundle2
|
||||
add_dependency_to_manifest "$WEBDIR"/10/Manifest.test-bundle1 test-bundle2
|
||||
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@ test_setup() {
|
||||
run sudo sh -c "$SWUPD bundle-add $SWUPD_OPTS test-bundle1"
|
||||
|
||||
assert_status_is 0
|
||||
assert_file_exists "$TEST_NAME"/target-dir/foo/test-file1
|
||||
assert_file_exists "$TEST_NAME"/target-dir/bar/test-file2
|
||||
assert_file_exists "$TARGETDIR"/foo/test-file1
|
||||
assert_file_exists "$TARGETDIR"/bar/test-file2
|
||||
expected_output=$(cat <<-EOM
|
||||
Starting download of remaining update content. This may take a while...
|
||||
Finishing download of update content...
|
||||
|
||||
@@ -16,10 +16,10 @@ test_setup() {
|
||||
run sudo sh -c "$SWUPD bundle-add $SWUPD_OPTS test-bundle1 test-bundle2"
|
||||
|
||||
assert_status_is 0
|
||||
assert_dir_exists "$TEST_NAME/target-dir/usr/bin"
|
||||
assert_dir_exists "$TEST_NAME/target-dir/media/lib"
|
||||
assert_file_exists "$TEST_NAME/target-dir/usr/bin/10"
|
||||
assert_file_exists "$TEST_NAME/target-dir/media/lib/file2"
|
||||
assert_dir_exists "$TARGETDIR/usr/bin"
|
||||
assert_dir_exists "$TARGETDIR/media/lib"
|
||||
assert_file_exists "$TARGETDIR/usr/bin/10"
|
||||
assert_file_exists "$TARGETDIR/media/lib/file2"
|
||||
expected_output=$(cat <<-EOM
|
||||
Downloading packs...
|
||||
Extracting test-bundle1 pack for version 10
|
||||
|
||||
@@ -14,7 +14,7 @@ test_setup() {
|
||||
|
||||
run sudo sh -c "$SWUPD bundle-add --no-scripts $SWUPD_OPTS test-bundle"
|
||||
assert_status_is 0
|
||||
assert_file_exists "$TEST_NAME/target-dir/usr/lib/kernel/test-file"
|
||||
assert_file_exists "$TARGETDIR/usr/lib/kernel/test-file"
|
||||
expected_output=$(cat <<-EOM
|
||||
Starting download of remaining update content. This may take a while...
|
||||
Finishing download of update content...
|
||||
|
||||
@@ -10,12 +10,12 @@ test_setup() {
|
||||
# bundles created with the testlib add all needed directories to the
|
||||
# manifest by default, so we need to remove the directory from test-bundle1
|
||||
# so its missing the path to the file.
|
||||
remove_from_manifest "$TEST_NAME"/web-dir/10/Manifest.test-bundle1 /foo
|
||||
remove_from_manifest "$TEST_NAME"/web-dir/10/Manifest.test-bundle1 /foo/bar
|
||||
remove_from_manifest "$WEBDIR"/10/Manifest.test-bundle1 /foo
|
||||
remove_from_manifest "$WEBDIR"/10/Manifest.test-bundle1 /foo/bar
|
||||
# since test-bundle2 is already installed, both directories defined
|
||||
# there already exist, so we need to delete one of the /foo/bar so it
|
||||
# can be fixed using verify_fix_path
|
||||
sudo rm -rf "$TEST_NAME"/target-dir/foo/bar
|
||||
sudo rm -rf "$TARGETDIR"/foo/bar
|
||||
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ test_setup() {
|
||||
Starting download of remaining update content. This may take a while...
|
||||
Finishing download of update content...
|
||||
Installing bundle(s) files...
|
||||
Update target directory does not exist: $TEST_DIRNAME/target-dir/foo/bar. Auto-fix disabled
|
||||
Update target directory does not exist: $TEST_DIRNAME/testfs/target-dir/foo/bar. Auto-fix disabled
|
||||
Path /foo/bar is missing on the file system ... fixing
|
||||
Path /foo/bar/test-file1 is missing on the file system ... fixing
|
||||
Calling post-update helper scripts.
|
||||
|
||||
@@ -22,9 +22,9 @@ test_setup() {
|
||||
assert_file_exists "$TARGETDIR"/usr/share/clear/bundles/test-bundle1
|
||||
assert_file_exists "$TARGETDIR"/usr/share/clear/bundles/test-bundle2
|
||||
assert_file_exists "$TARGETDIR"/usr/share/clear/bundles/test-bundle3
|
||||
assert_file_exists "$TEST_NAME"/target-dir/test-file1
|
||||
assert_file_exists "$TEST_NAME"/target-dir/test-file2
|
||||
assert_file_exists "$TEST_NAME"/target-dir/test-file3
|
||||
assert_file_exists "$TARGETDIR"/test-file1
|
||||
assert_file_exists "$TARGETDIR"/test-file2
|
||||
assert_file_exists "$TARGETDIR"/test-file3
|
||||
expected_output=$(cat <<-EOM
|
||||
Error: bundle requested to be removed is required by the following bundles:
|
||||
format:
|
||||
|
||||
@@ -6,7 +6,7 @@ test_setup() {
|
||||
|
||||
create_test_environment "$TEST_NAME"
|
||||
# remove os-release file from target-dir so no current version can be determined
|
||||
sudo rm "$TEST_NAME"/target-dir/usr/lib/os-release
|
||||
sudo rm "$TARGETDIR"/usr/lib/os-release
|
||||
|
||||
}
|
||||
|
||||
|
||||
+157
-49
@@ -230,6 +230,15 @@ validate_param() {
|
||||
|
||||
}
|
||||
|
||||
validate_number() {
|
||||
|
||||
local param=$1
|
||||
if ! [[ $param =~ ^[0-9]+([.][0-9]+)?$ ]] ; then
|
||||
terminate "Bad parameter provided, expecting a number"
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
# Writes to a file that is owned by root
|
||||
# Parameters:
|
||||
# - "-a": if set, the text will be appeneded to the file,
|
||||
@@ -264,6 +273,7 @@ set_env_variables() { # swupd_function
|
||||
|
||||
local env_name=$1
|
||||
local path
|
||||
local testfs_path
|
||||
# If no parameters are received show usage
|
||||
if [ $# -eq 0 ]; then
|
||||
cat <<-EOM
|
||||
@@ -274,19 +284,25 @@ set_env_variables() { # swupd_function
|
||||
fi
|
||||
validate_path "$env_name"
|
||||
path=$(dirname "$(realpath "$env_name")")
|
||||
testfs_path="$path"/"$env_name"/testfs
|
||||
|
||||
export TEST_DIRNAME="$path"/"$env_name"
|
||||
export WEBDIR="$env_name"/web-dir
|
||||
export TARGETDIR="$env_name"/testfs/target-dir
|
||||
export STATEDIR="$env_name"/testfs/state
|
||||
|
||||
# different options for swupd
|
||||
export SWUPD_OPTS="-S $path/$env_name/state -p $path/$env_name/target-dir -F staging -C $FUNC_DIR/Swupd_Root.pem -I"
|
||||
export SWUPD_OPTS="-S $testfs_path/state -p $testfs_path/target-dir -F staging -C $FUNC_DIR/Swupd_Root.pem -I"
|
||||
export SWUPD_OPTS_KEEPCACHE="$SWUPD_OPTS --keepcache"
|
||||
export SWUPD_OPTS_NO_CERT="-S $path/$env_name/state -p $path/$env_name/target-dir -F staging"
|
||||
export SWUPD_OPTS_MIRROR="-p $path/$env_name/target-dir"
|
||||
export SWUPD_OPTS_NO_FMT="-S $path/$env_name/state -p $path/$env_name/target-dir -C $FUNC_DIR/Swupd_Root.pem -I"
|
||||
export SWUPD_OPTS_NO_CERT="-S $testfs_path/state -p $testfs_path/target-dir -F staging"
|
||||
export SWUPD_OPTS_MIRROR="-p $testfs_path/target-dir"
|
||||
export SWUPD_OPTS_NO_FMT="-S $testfs_path/state -p $testfs_path/target-dir -C $FUNC_DIR/Swupd_Root.pem -I"
|
||||
|
||||
export CLIENT_CERT_DIR="$TEST_NAME/target-dir/etc/swupd"
|
||||
export CLIENT_CERT_DIR="$testfs_path/target-dir/etc/swupd"
|
||||
export CLIENT_CERT="$CLIENT_CERT_DIR/client.pem"
|
||||
export CACERT_DIR="$SWUPD_DIR/swupd_test_certificates" # trusted key store path
|
||||
export PORT_FILE="$TEST_NAME/port_file.txt" # stores web server port
|
||||
export SERVER_PID_FILE="$TEST_NAME/pid_file.txt" # stores web server pid
|
||||
export PORT_FILE="$path/$env_name/port_file.txt" # stores web server port
|
||||
export SERVER_PID_FILE="$path/$env_name/pid_file.txt" # stores web server pid
|
||||
|
||||
# Add environment variables for PORT and SERVER_PID when web server used
|
||||
if [ -f "$PORT_FILE" ]; then
|
||||
@@ -298,11 +314,6 @@ set_env_variables() { # swupd_function
|
||||
export SERVER_PID=$(cat "$SERVER_PID_FILE")
|
||||
fi
|
||||
|
||||
export TEST_DIRNAME="$path"/"$env_name"
|
||||
export WEBDIR="$env_name"/web-dir
|
||||
export TARGETDIR="$env_name"/target-dir
|
||||
export STATEDIR="$env_name"/state
|
||||
|
||||
}
|
||||
|
||||
# Creates a directory with a hashed name in the specified path, if a directory
|
||||
@@ -362,7 +373,7 @@ create_file() { # swupd_function
|
||||
validate_path "$path"
|
||||
|
||||
if [ -n "$size" ]; then
|
||||
head -c "$size" /dev/urandom | sudo tee "$path/testfile" > /dev/null
|
||||
< /dev/urandom tr -dc 'a-zA-Z0-9-_!@#$%^&*()_+{}|:<>?=' | head -c "$size" | sudo tee "$path/testfile" > /dev/null
|
||||
else
|
||||
generate_random_content | sudo tee "$path/testfile" > /dev/null
|
||||
fi
|
||||
@@ -1141,7 +1152,7 @@ set_current_version() { # swupd_function
|
||||
fi
|
||||
validate_path "$env_name"
|
||||
|
||||
sudo sed -i "s/VERSION_ID=.*/VERSION_ID=$new_version/" "$env_name"/target-dir/usr/lib/os-release
|
||||
sudo sed -i "s/VERSION_ID=.*/VERSION_ID=$new_version/" "$env_name"/testfs/target-dir/usr/lib/os-release
|
||||
|
||||
}
|
||||
|
||||
@@ -1309,19 +1320,10 @@ create_version() { # swupd_function
|
||||
# - FORMAT: the format number to use initially in the environment
|
||||
create_test_environment() { # swupd_function
|
||||
|
||||
local empty=false
|
||||
local release_files=false
|
||||
[ "$1" = "-e" ] && { empty=true ; shift ; }
|
||||
[ "$1" = "-r" ] && { release_files=true ; shift ; }
|
||||
local env_name=$1
|
||||
local version=${2:-10}
|
||||
local format=${3:-staging}
|
||||
local path
|
||||
# If no parameters are received show usage
|
||||
if [ $# -eq 0 ]; then
|
||||
cte_usage() {
|
||||
cat <<-EOM
|
||||
Usage:
|
||||
create_test_environment [-e|-r] <environment_name> [initial_version] [format]
|
||||
create_test_environment [-e|-r] [-s <size in MB>] <environment_name> [initial_version] [format]
|
||||
|
||||
Options:
|
||||
-e If set, the test environment is created empty, otherwise it will have
|
||||
@@ -1329,12 +1331,47 @@ create_test_environment() { # swupd_function
|
||||
-r If set, the test environment is created with a more complete version of
|
||||
the os-core bundle, a version that includes the os-release and format
|
||||
files, so it is more useful for some tests, like update tests.
|
||||
-s If used, specifies the maximum size the test environment has in MB, this
|
||||
can be useful when testing scenarios bound to the disk size.
|
||||
|
||||
Note: options -e and -r are mutually exclusive, so you can only use one at a time.
|
||||
EOM
|
||||
EOM
|
||||
}
|
||||
|
||||
local OPTIND
|
||||
local opt
|
||||
local empty=false
|
||||
local release_files=false
|
||||
local size=0
|
||||
local path
|
||||
local tagetdir
|
||||
local statedir
|
||||
local fs
|
||||
|
||||
# If no parameters are received show usage
|
||||
if [ $# -eq 0 ]; then
|
||||
create_test_environment -h
|
||||
return
|
||||
fi
|
||||
|
||||
while getopts :ers: opt; do
|
||||
case "$opt" in
|
||||
e) empty=true
|
||||
release_files=false ;;
|
||||
r) release_files=true
|
||||
empty=false ;;
|
||||
s) size="$OPTARG" ;;
|
||||
*) cte_usage
|
||||
return ;;
|
||||
esac
|
||||
done
|
||||
shift $((OPTIND-1))
|
||||
|
||||
local env_name=$1
|
||||
local version=${2:-10}
|
||||
local format=${3:-staging}
|
||||
validate_param "$env_name"
|
||||
validate_number "$size"
|
||||
|
||||
# clean test environment when test interrupted
|
||||
trap "destroy_test_environment $TEST_NAME" INT
|
||||
@@ -1348,20 +1385,32 @@ create_test_environment() { # swupd_function
|
||||
create_version -p "$env_name" "$version" "0" "$format"
|
||||
fi
|
||||
|
||||
# if a size was selected, create the FS,
|
||||
# if not just use a normal directory
|
||||
if [ "$size" -gt 0 ]; then
|
||||
print "Creating a test file system..."
|
||||
print "Created: $(create_test_fs "$env_name" "$size") ($size MB)"
|
||||
sudo touch "$env_name"/.testfs
|
||||
else
|
||||
sudo mkdir -p "$env_name"/testfs
|
||||
fi
|
||||
targetdir="$env_name"/testfs/target-dir
|
||||
statedir="$env_name"/testfs/state
|
||||
|
||||
# target-dir files & dirs
|
||||
path=$(dirname "$(realpath "$env_name")")
|
||||
sudo mkdir -p "$env_name"/target-dir/usr/lib
|
||||
sudo cp "$env_name"/web-dir/"$version"/os-release "$env_name"/target-dir/usr/lib/os-release
|
||||
sudo mkdir -p "$env_name"/target-dir/usr/share/clear/bundles
|
||||
sudo mkdir -p "$env_name"/target-dir/usr/share/defaults/swupd
|
||||
sudo cp "$env_name"/web-dir/"$version"/format "$env_name"/target-dir/usr/share/defaults/swupd/format
|
||||
write_to_protected_file "$env_name"/target-dir/usr/share/defaults/swupd/versionurl "file://$path/$env_name/web-dir"
|
||||
write_to_protected_file "$env_name"/target-dir/usr/share/defaults/swupd/contenturl "file://$path/$env_name/web-dir"
|
||||
sudo mkdir -p "$env_name"/target-dir/etc/swupd
|
||||
sudo mkdir -p "$targetdir"/usr/lib
|
||||
sudo cp "$env_name"/web-dir/"$version"/os-release "$targetdir"/usr/lib/os-release
|
||||
sudo mkdir -p "$targetdir"/usr/share/clear/bundles
|
||||
sudo mkdir -p "$targetdir"/usr/share/defaults/swupd
|
||||
sudo cp "$env_name"/web-dir/"$version"/format "$targetdir"/usr/share/defaults/swupd/format
|
||||
write_to_protected_file "$targetdir"/usr/share/defaults/swupd/versionurl "file://$path/$env_name/web-dir"
|
||||
write_to_protected_file "$targetdir"/usr/share/defaults/swupd/contenturl "file://$path/$env_name/web-dir"
|
||||
sudo mkdir -p "$targetdir"/etc/swupd
|
||||
|
||||
# state files & dirs
|
||||
sudo mkdir -p "$env_name"/state/{staged,download,delta,telemetry}
|
||||
sudo chmod -R 0700 "$env_name"/state
|
||||
sudo mkdir -p "$statedir"/{staged,download,delta,telemetry}
|
||||
sudo chmod -R 0700 "$statedir"
|
||||
|
||||
# export environment variables that are dependent of the test env
|
||||
set_env_variables "$env_name"
|
||||
@@ -1420,16 +1469,75 @@ destroy_test_environment() { # swupd_function
|
||||
|
||||
# since the action to be performed is very destructive, at least
|
||||
# make sure the directory does look like a test environment
|
||||
for var in "state" "target-dir" "web-dir"; do
|
||||
if [ ! -d "$env_name/$var" ]; then
|
||||
for var in "testfs" "web-dir"; do
|
||||
if [ ! -d "$env_name"/"$var" ]; then
|
||||
echo "The name provided doesn't seem to be a valid test environment"
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
|
||||
# if a test fs was created, destroy it
|
||||
if [ -e "$env_name"/.testfs ]; then
|
||||
destroy_test_fs "$env_name"
|
||||
fi
|
||||
|
||||
sudo rm -rf "$env_name"
|
||||
|
||||
}
|
||||
|
||||
# Creates a test fiile system of a given size
|
||||
create_test_fs() { # swupd_function
|
||||
|
||||
local env_name=$1
|
||||
local size=$2
|
||||
local fsfile
|
||||
# If no parameters are received show usage
|
||||
if [ $# -eq 0 ]; then
|
||||
cat <<-EOM
|
||||
Usage:
|
||||
create_test_fs <environment_name> <size_in_MB>
|
||||
EOM
|
||||
return
|
||||
fi
|
||||
validate_path "$env_name"
|
||||
validate_param "$size"
|
||||
fsfile=/tmp/"$env_name"
|
||||
|
||||
# create a file of the appropriate size
|
||||
dd if=/dev/zero of="$fsfile" bs=1M count="$size" >& /dev/null
|
||||
# create loop device and format it
|
||||
sudo losetup -f "$fsfile"
|
||||
mkfs.ext4 "$fsfile" >& /dev/null
|
||||
# mount the fs
|
||||
sudo mkdir "$env_name"/testfs
|
||||
sudo mount "$fsfile" "$env_name"/testfs -o sync
|
||||
|
||||
# return the fs
|
||||
echo "$env_name"/testfs
|
||||
|
||||
}
|
||||
|
||||
destroy_test_fs() { # swupd_function
|
||||
|
||||
local env_name=$1
|
||||
local fsfile
|
||||
# If no parameters are received show usage
|
||||
if [ $# -eq 0 ]; then
|
||||
cat <<-EOM
|
||||
Usage:
|
||||
destroy_test_fs <environment_name>
|
||||
EOM
|
||||
return
|
||||
fi
|
||||
validate_path "$env_name"
|
||||
fsfile=/tmp/"$env_name"
|
||||
|
||||
sudo umount "$env_name"/testfs
|
||||
sudo losetup -d "$(losetup -j "$fsfile" -nO NAME)"
|
||||
rm "$fsfile"
|
||||
|
||||
}
|
||||
|
||||
# creates a mirror of whatever is in web-dir
|
||||
# Parameters:
|
||||
# - ENVIRONMENT_NAME: the name of the test environment where the mirror will be created
|
||||
@@ -1455,8 +1563,8 @@ create_mirror() { # swupd_function
|
||||
export MIRROR="$env_name"/mirror/web-dir
|
||||
|
||||
# set the mirror in the target-dir
|
||||
write_to_protected_file "$env_name"/target-dir/etc/swupd/mirror_versionurl "file://$path/$MIRROR"
|
||||
write_to_protected_file "$env_name"/target-dir/etc/swupd/mirror_contenturl "file://$path/$MIRROR"
|
||||
write_to_protected_file "$env_name"/testfs/target-dir/etc/swupd/mirror_versionurl "file://$path/$MIRROR"
|
||||
write_to_protected_file "$env_name"/testfs/target-dir/etc/swupd/mirror_contenturl "file://$path/$MIRROR"
|
||||
|
||||
}
|
||||
|
||||
@@ -1484,7 +1592,7 @@ set_version_url() { # swupd_function
|
||||
validate_path "$env_name"
|
||||
validate_param "$version_url"
|
||||
|
||||
write_to_protected_file "$env_name"/target-dir/usr/share/defaults/swupd/versionurl "$version_url"
|
||||
write_to_protected_file "$env_name"/testfs/target-dir/usr/share/defaults/swupd/versionurl "$version_url"
|
||||
|
||||
}
|
||||
|
||||
@@ -1512,7 +1620,7 @@ set_content_url() { # swupd_function
|
||||
validate_path "$env_name"
|
||||
validate_param "$content_url"
|
||||
|
||||
write_to_protected_file "$env_name"/target-dir/usr/share/defaults/swupd/contenturl "$content_url"
|
||||
write_to_protected_file "$env_name"/testfs/target-dir/usr/share/defaults/swupd/contenturl "$content_url"
|
||||
|
||||
}
|
||||
|
||||
@@ -1827,7 +1935,7 @@ create_bundle() { # swupd_function
|
||||
validate_path "$env_name"
|
||||
version_path="$env_name"/web-dir/"$version"
|
||||
files_path="$version_path"/files
|
||||
target_path="$env_name"/target-dir
|
||||
target_path="$env_name"/testfs/target-dir
|
||||
|
||||
# 1) create the initial manifest
|
||||
manifest=$(create_manifest "$version_path" "$bundle_name")
|
||||
@@ -2055,7 +2163,7 @@ remove_bundle() { # swupd_function
|
||||
return
|
||||
fi
|
||||
|
||||
target_path=$(dirname "$bundle_manifest" | cut -d "/" -f1)/target-dir
|
||||
target_path=$(dirname "$bundle_manifest" | cut -d "/" -f1)/testfs/target-dir
|
||||
version_path=$(dirname "$bundle_manifest")
|
||||
manifest_file=$(basename "$bundle_manifest")
|
||||
bundle_name=${manifest_file#Manifest.}
|
||||
@@ -2111,7 +2219,7 @@ install_bundle() { # swupd_function
|
||||
return
|
||||
fi
|
||||
validate_item "$bundle_manifest"
|
||||
target_path=$(dirname "$bundle_manifest" | cut -d "/" -f1)/target-dir
|
||||
target_path=$(dirname "$bundle_manifest" | cut -d "/" -f1)/testfs/target-dir
|
||||
files_path=$(dirname "$bundle_manifest")/files
|
||||
manifest_file=$(basename "$bundle_manifest")
|
||||
bundle_name=${manifest_file#Manifest.}
|
||||
@@ -2529,9 +2637,9 @@ clean_state_dir() { # swupd_function
|
||||
fi
|
||||
validate_path "$env_name"
|
||||
|
||||
sudo rm -rf "$env_name"/state
|
||||
sudo mkdir -p "$env_name"/state/{staged,download,delta,telemetry}
|
||||
sudo chmod -R 0700 "$env_name"/state
|
||||
sudo rm -rf "$env_name"/testfs/state
|
||||
sudo mkdir -p "$env_name"/testfs/state/{staged,download,delta,telemetry}
|
||||
sudo chmod -R 0700 "$env_name"/testfs/state
|
||||
|
||||
}
|
||||
|
||||
@@ -2765,7 +2873,7 @@ teardown() {
|
||||
|
||||
if [ "$DEBUG_TEST" = true ] && [ "$global_env" = true ] && [ -d "$TEST_NAME" ]; then
|
||||
print "Saving a copy of the state dir in $TEST_NAME/state_$BATS_TEST_NUMBER"
|
||||
sudo cp -r "$TEST_NAME"/state "$TEST_NAME"/state_"$BATS_TEST_NUMBER"
|
||||
sudo cp -r "$TEST_NAME"/testfs/state "$TEST_NAME"/state_"$BATS_TEST_NUMBER"
|
||||
fi
|
||||
test_teardown
|
||||
# if the last test just ran, run the global teardown
|
||||
|
||||
@@ -25,8 +25,8 @@ test_setup() {
|
||||
EOM
|
||||
)
|
||||
assert_regex_is_output "$expected_output"
|
||||
assert_file_not_exists "$TEST_NAME"/target-dir/foo/test-file1
|
||||
assert_file_exists "$TEST_NAME"/target-dir/bar/test-file2
|
||||
assert_file_not_exists "$TARGETDIR"/foo/test-file1
|
||||
assert_file_exists "$TARGETDIR"/bar/test-file2
|
||||
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ test_setup() {
|
||||
EOM
|
||||
)
|
||||
assert_regex_is_output "$expected_output"
|
||||
assert_file_exists "$TEST_NAME"/target-dir/foo/test-file1
|
||||
assert_file_exists "$TEST_NAME"/target-dir/bar/test-file2
|
||||
assert_file_exists "$TARGETDIR"/foo/test-file1
|
||||
assert_file_exists "$TARGETDIR"/bar/test-file2
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user