1#!/usr/bin/env bash 2 3# This file contains the second part of Stage 2 for the rolling upgrade test. 4# Description of file functionality: 5# * Upload an inline, remote, and multisegment file to the network using the main uplink and the new satellite api. 6# * Upload an inline, remote, and multisegment file to the network using the main uplink and the old satellite api. 7# * Download the six inline, remote, and multisegment files from the previous two steps using the main uplink and new satellite api. 8# * Download the six inline, remote, and multisegment files from the previous two steps using the main uplink and old satellite api. 9 10set -ueo pipefail 11 12# This script assumes that storj-sim and uplink has already been set up 13main_cfg_dir=$1 14 15bucket="bucket-123" 16test_files_dir="${main_cfg_dir}/testfiles" 17stage2_dst_dir="${main_cfg_dir}/stage2" 18 19create_test_files(){ 20 mkdir -p "$test_files_dir" 21 random_bytes_file () { 22 size=$1 23 output=$2 24 head -c $size </dev/urandom > $output 25 } 26 random_bytes_file "2048" "$test_files_dir/small-upload-testfile" # create 2kb file of random bytes (inline) 27 random_bytes_file "5120" "$test_files_dir/big-upload-testfile" # create 5kb file of random bytes (remote) 28 random_bytes_file "131072" "$test_files_dir/multisegment-upload-testfile" # create 128kb file of random bytes (remote) 29 30 echo "created test files" 31} 32 33create_test_files 34 35# Test that new files can be uploaded and downloaded successfully with both apis 36bucket_name=${bucket}-final-upload 37old_api_bucket_name=${bucket}-final-upload-old 38# download directory for new-api-uploaded + new-api-downloaded files 39download_dst_dir=${stage2_dst_dir}/final-upload 40# download directory for old-api-uploaded + new-api-downloaded files 41download_dst_dir2=${stage2_dst_dir}/final-upload2 42# download directory for new-api-uploaded + old-api-downloaded files 43old_api_download_dst_dir=${download_dst_dir}/old-api 44# download directory for old-api-uploaded + old-api-downloaded files 45old_api_download_dst_dir2=${download_dst_dir2}/old-api 46mkdir -p "$download_dst_dir" 47mkdir -p "$download_dst_dir2" 48mkdir -p "$old_api_download_dst_dir" 49mkdir -p "$old_api_download_dst_dir2" 50 51uplink mb "sj://$bucket_name/" --config-dir="${main_cfg_dir}/uplink" 52uplink mb "sj://$old_api_bucket_name/" --config-dir="${main_cfg_dir}/uplink-old-api" 53 54# new api uploads 55uplink cp --config-dir="${main_cfg_dir}/uplink" --progress=false "${test_files_dir}/small-upload-testfile" "sj://$bucket_name/" 56uplink cp --config-dir="${main_cfg_dir}/uplink" --progress=false "${test_files_dir}/big-upload-testfile" "sj://$bucket_name/" 57uplink cp --config-dir="${main_cfg_dir}/uplink" --progress=false "${test_files_dir}/multisegment-upload-testfile" "sj://$bucket_name/" 58 59# TODO we should be able to uncomment those cases when we will have at least one point release of multipart satellite after merging to main 60# old api uploads 61# uplink cp --config-dir="${main_cfg_dir}/uplink-old-api" --progress=false "${test_files_dir}/small-upload-testfile" "sj://$old_api_bucket_name/" 62# uplink cp --config-dir="${main_cfg_dir}/uplink-old-api" --progress=false "${test_files_dir}/big-upload-testfile" "sj://$old_api_bucket_name/" 63# uplink cp --config-dir="${main_cfg_dir}/uplink-old-api" --progress=false "${test_files_dir}/multisegment-upload-testfile" "sj://$old_api_bucket_name/" 64 65# new api downloads of new api uploaded files 66uplink cp --config-dir="${main_cfg_dir}/uplink" --progress=false "sj://$bucket_name/small-upload-testfile" "${download_dst_dir}" 67uplink cp --config-dir="${main_cfg_dir}/uplink" --progress=false "sj://$bucket_name/big-upload-testfile" "${download_dst_dir}" 68uplink cp --config-dir="${main_cfg_dir}/uplink" --progress=false "sj://$bucket_name/multisegment-upload-testfile" "${download_dst_dir}" 69 70# TODO we should be able to uncomment those cases when we will have at least one point release of multipart satellite after merging to main 71# new api downloads of old api uploaded files 72# uplink cp --config-dir="${main_cfg_dir}/uplink" --progress=false "sj://$old_api_bucket_name/small-upload-testfile" "${download_dst_dir2}" 73# uplink cp --config-dir="${main_cfg_dir}/uplink" --progress=false "sj://$old_api_bucket_name/big-upload-testfile" "${download_dst_dir2}" 74# uplink cp --config-dir="${main_cfg_dir}/uplink" --progress=false "sj://$old_api_bucket_name/multisegment-upload-testfile" "${download_dst_dir2}" 75 76echo "checking files uploaded with new api and downloaded with new api" 77if cmp "${test_files_dir}/small-upload-testfile" "${download_dst_dir}/small-upload-testfile" 78then 79 echo "download test on current branch: small upload testfile matches uploaded file" 80else 81 echo "download test on current branch: small upload testfile does not match uploaded file" 82 exit 1 83fi 84if cmp "${test_files_dir}/big-upload-testfile" "${download_dst_dir}/big-upload-testfile" 85then 86 echo "download test on current branch: big upload testfile matches uploaded file" 87else 88 echo "download test on current branch: big upload testfile does not match uploaded file" 89 exit 1 90fi 91if cmp "${test_files_dir}/multisegment-upload-testfile" "${download_dst_dir}/multisegment-upload-testfile" 92then 93 echo "download test on current branch: multisegment upload testfile matches uploaded file" 94else 95 echo "download test on current branch: multisegment upload testfile does not match uploaded file" 96 exit 1 97fi 98 99# TODO we should be able to uncomment those cases when we will have at least one point release of multipart satellite after merging to main 100# echo "checking files uploaded with old api and downloaded with new api" 101# if cmp "${test_files_dir}/small-upload-testfile" "${download_dst_dir2}/small-upload-testfile" 102# then 103# echo "download test on current branch: small upload testfile matches uploaded file" 104# else 105# echo "download test on current branch: small upload testfile does not match uploaded file" 106# exit 1 107# fi 108# if cmp "${test_files_dir}/big-upload-testfile" "${download_dst_dir2}/big-upload-testfile" 109# then 110# echo "download test on current branch: big upload testfile matches uploaded file" 111# else 112# echo "download test on current branch: big upload testfile does not match uploaded file" 113# exit 1 114# fi 115# if cmp "${test_files_dir}/multisegment-upload-testfile" "${download_dst_dir2}/multisegment-upload-testfile" 116# then 117# echo "download test on current branch: multisegment upload testfile matches uploaded file" 118# else 119# echo "download test on current branch: multisegment upload testfile does not match uploaded file" 120# exit 1 121# fi 122 123# TODO we should be able to uncomment those cases when we will have at least one point release of multipart satellite after merging to main 124# old api downloads of new api uploaded files 125# uplink cp --config-dir="${main_cfg_dir}/uplink-old-api" --progress=false "sj://$bucket_name/small-upload-testfile" "${old_api_download_dst_dir}" 126# uplink cp --config-dir="${main_cfg_dir}/uplink-old-api" --progress=false "sj://$bucket_name/big-upload-testfile" "${old_api_download_dst_dir}" 127# uplink cp --config-dir="${main_cfg_dir}/uplink-old-api" --progress=false "sj://$bucket_name/multisegment-upload-testfile" "${old_api_download_dst_dir}" 128# old api downloads of old api uploaded files 129# uplink cp --config-dir="${main_cfg_dir}/uplink-old-api" --progress=false "sj://$old_api_bucket_name/small-upload-testfile" "${old_api_download_dst_dir2}" 130# uplink cp --config-dir="${main_cfg_dir}/uplink-old-api" --progress=false "sj://$old_api_bucket_name/big-upload-testfile" "${old_api_download_dst_dir2}" 131# uplink cp --config-dir="${main_cfg_dir}/uplink-old-api" --progress=false "sj://$old_api_bucket_name/multisegment-upload-testfile" "${old_api_download_dst_dir2}" 132 133# echo "checking files uploaded with new api and downloaded with old api" 134# if cmp "${test_files_dir}/small-upload-testfile" "${old_api_download_dst_dir}/small-upload-testfile" 135# then 136# echo "download test on current branch: small upload testfile matches uploaded file" 137# else 138# echo "download test on current branch: small upload testfile does not match uploaded file" 139# exit 1 140# fi 141# if cmp "${test_files_dir}/big-upload-testfile" "${old_api_download_dst_dir}/big-upload-testfile" 142# then 143# echo "download test on current branch: big upload testfile matches uploaded file" 144# else 145# echo "download test on current branch: big upload testfile does not match uploaded file" 146# exit 1 147# fi 148# if cmp "${test_files_dir}/multisegment-upload-testfile" "${old_api_download_dst_dir}/multisegment-upload-testfile" 149# then 150# echo "download test on current branch: multisegment upload testfile matches uploaded file" 151# else 152# echo "download test on current branch: multisegment upload testfile does not match uploaded file" 153# exit 1 154# fi 155 156# echo "checking files uploaded with old api and downloaded with old api" 157# if cmp "${test_files_dir}/small-upload-testfile" "${old_api_download_dst_dir2}/small-upload-testfile" 158# then 159# echo "download test on current branch: small upload testfile matches uploaded file" 160# else 161# echo "download test on current branch: small upload testfile does not match uploaded file" 162# exit 1 163# fi 164# if cmp "${test_files_dir}/big-upload-testfile" "${old_api_download_dst_dir2}/big-upload-testfile" 165# then 166# echo "download test on current branch: big upload testfile matches uploaded file" 167# else 168# echo "download test on current branch: big upload testfile does not match uploaded file" 169# exit 1 170# fi 171# if cmp "${test_files_dir}/multisegment-upload-testfile" "${old_api_download_dst_dir2}/multisegment-upload-testfile" 172# then 173# echo "download test on current branch: multisegment upload testfile matches uploaded file" 174# else 175# echo "download test on current branch: multisegment upload testfile does not match uploaded file" 176# exit 1 177# fi 178 179rm -rf ${download_dst_dir} 180rm -rf ${download_dst_dir2} 181 182uplink rm --config-dir="${main_cfg_dir}/uplink" "sj://$bucket_name/small-upload-testfile" 183uplink rm --config-dir="${main_cfg_dir}/uplink" "sj://$bucket_name/big-upload-testfile" 184uplink rm --config-dir="${main_cfg_dir}/uplink" "sj://$bucket_name/multisegment-upload-testfile" 185uplink rb --config-dir="${main_cfg_dir}/uplink" "sj://$bucket_name" 186 187# TODO we should be able to uncomment those cases when we will have at least one point release of multipart satellite after merging to main 188# uplink rm --config-dir="${main_cfg_dir}/uplink-old-api" "sj://$old_api_bucket_name/small-upload-testfile" 189# uplink rm --config-dir="${main_cfg_dir}/uplink-old-api" "sj://$old_api_bucket_name/big-upload-testfile" 190# uplink rm --config-dir="${main_cfg_dir}/uplink-old-api" "sj://$old_api_bucket_name/multisegment-upload-testfile" 191# uplink rb --config-dir="${main_cfg_dir}/uplink-old-api" "sj://$old_api_bucket_name" 192