numam-spdk/test/lvol/common.sh

54 lines
1.4 KiB
Bash
Raw Normal View History

test/lvol: start rewriting python tests to bash There are multiple things wrong with current python tests: * they don't stop the execution on error * the output makes it difficult to understand what really happened inside the test * there is no easy way to reproduce a failure if there is one (besides running the same test script again) * they currently suffer from intermittent failures and there's no-one there to fix them * they stand out from the rest of spdk tests, which are written in bash So we rewrite those tests to bash. They will use rpc.py daemon to send RPC commands, so they won't take any more time to run than python tests. The tests are going to be split them into a few different categories: * clones * snapshots * thin provisioning * tasting * renaming * resizing * all the dumb ones - construct, destruct, etc Each file is a standalone test script, with common utility functions located in test/lvol/common.sh. Each file tests a single, specific feature, but under multiple conditions. Each test case is implemented as a separate function, so if you touch only one lvol feature, you can run only one test script, and if e.g. only a later test case notoriously breaks, you can comment out all the previous test case invocations (up to ~10 lines) and focus only on that failing one. The new tests don't correspond 1:1 to the old python ones - they now cover more. Whenever there was a negative test to check if creating lvs on inexistent bdev failed, we'll now also create a dummy bdev beforehand, so that lvs will have more opportunity to do something it should not. Some other test cases were squashed. A few negative tests required a lot of setup just to try doing something illegal and see if spdk crashed. We'll now do those illegal operations in a single test case, giving lvol lib more opportunity to break. Even if illegal operation did not cause any segfault, is the lvolstore/lvol still usable? E.g. if we try to create an lvol on an lvs that doesn't have enough free clusters and it fails as expected, will it be still possible to create a valid lvol afterwards? Besides sending various RPC commands and checking their return code, we'll also parse and compare various fields in JSON RPC output from get_lvol_stores or get_bdevs RPC. We'll use inline jq calls for that. Whenever something's off, it will be clear which RPC returned invalid values and what were the expected values even without having detailed error prints. The tests are designed to be as easy as possible to debug whenever something goes wrong. This patch removes one test case from python tests and adds a corresponding test into the new test/lvol/lvol2.sh file. The script will be renamed to just lvol.sh after the existing lvol.sh (which starts all python tests) is finally removed. As for the bash script itself - each test case is run through a run_test() function which verifies there were no lvolstores, lvols, or bdevs left after the test case has finished. Inside the particular tests we will still check if the lvolstore removal at the end was successful, but that's because we want to make sure it's gone e.g even before we remove the underlying lvs' base bdev. Change-Id: Iaa2bb656233e1c9f0c35093f190ac26c39e78623 Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com> Signed-off-by: Pawel Kaminski <pawelx.kaminski@intel.com> Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/459517 Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com> Reviewed-by: Karol Latecki <karol.latecki@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Community-CI: Broadcom SPDK FC-NVMe CI <spdk-ci.pdl@broadcom.com>
2019-06-10 15:22:11 +02:00
MALLOC_SIZE_MB=128
MALLOC_BS=512
AIO_SIZE_MB=400
AIO_BS=4096
test/lvol: start rewriting python tests to bash There are multiple things wrong with current python tests: * they don't stop the execution on error * the output makes it difficult to understand what really happened inside the test * there is no easy way to reproduce a failure if there is one (besides running the same test script again) * they currently suffer from intermittent failures and there's no-one there to fix them * they stand out from the rest of spdk tests, which are written in bash So we rewrite those tests to bash. They will use rpc.py daemon to send RPC commands, so they won't take any more time to run than python tests. The tests are going to be split them into a few different categories: * clones * snapshots * thin provisioning * tasting * renaming * resizing * all the dumb ones - construct, destruct, etc Each file is a standalone test script, with common utility functions located in test/lvol/common.sh. Each file tests a single, specific feature, but under multiple conditions. Each test case is implemented as a separate function, so if you touch only one lvol feature, you can run only one test script, and if e.g. only a later test case notoriously breaks, you can comment out all the previous test case invocations (up to ~10 lines) and focus only on that failing one. The new tests don't correspond 1:1 to the old python ones - they now cover more. Whenever there was a negative test to check if creating lvs on inexistent bdev failed, we'll now also create a dummy bdev beforehand, so that lvs will have more opportunity to do something it should not. Some other test cases were squashed. A few negative tests required a lot of setup just to try doing something illegal and see if spdk crashed. We'll now do those illegal operations in a single test case, giving lvol lib more opportunity to break. Even if illegal operation did not cause any segfault, is the lvolstore/lvol still usable? E.g. if we try to create an lvol on an lvs that doesn't have enough free clusters and it fails as expected, will it be still possible to create a valid lvol afterwards? Besides sending various RPC commands and checking their return code, we'll also parse and compare various fields in JSON RPC output from get_lvol_stores or get_bdevs RPC. We'll use inline jq calls for that. Whenever something's off, it will be clear which RPC returned invalid values and what were the expected values even without having detailed error prints. The tests are designed to be as easy as possible to debug whenever something goes wrong. This patch removes one test case from python tests and adds a corresponding test into the new test/lvol/lvol2.sh file. The script will be renamed to just lvol.sh after the existing lvol.sh (which starts all python tests) is finally removed. As for the bash script itself - each test case is run through a run_test() function which verifies there were no lvolstores, lvols, or bdevs left after the test case has finished. Inside the particular tests we will still check if the lvolstore removal at the end was successful, but that's because we want to make sure it's gone e.g even before we remove the underlying lvs' base bdev. Change-Id: Iaa2bb656233e1c9f0c35093f190ac26c39e78623 Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com> Signed-off-by: Pawel Kaminski <pawelx.kaminski@intel.com> Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/459517 Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com> Reviewed-by: Karol Latecki <karol.latecki@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Community-CI: Broadcom SPDK FC-NVMe CI <spdk-ci.pdl@broadcom.com>
2019-06-10 15:22:11 +02:00
LVS_DEFAULT_CLUSTER_SIZE_MB=4
LVS_DEFAULT_CLUSTER_SIZE=$((LVS_DEFAULT_CLUSTER_SIZE_MB * 1024 * 1024))
test/lvol: start rewriting python tests to bash There are multiple things wrong with current python tests: * they don't stop the execution on error * the output makes it difficult to understand what really happened inside the test * there is no easy way to reproduce a failure if there is one (besides running the same test script again) * they currently suffer from intermittent failures and there's no-one there to fix them * they stand out from the rest of spdk tests, which are written in bash So we rewrite those tests to bash. They will use rpc.py daemon to send RPC commands, so they won't take any more time to run than python tests. The tests are going to be split them into a few different categories: * clones * snapshots * thin provisioning * tasting * renaming * resizing * all the dumb ones - construct, destruct, etc Each file is a standalone test script, with common utility functions located in test/lvol/common.sh. Each file tests a single, specific feature, but under multiple conditions. Each test case is implemented as a separate function, so if you touch only one lvol feature, you can run only one test script, and if e.g. only a later test case notoriously breaks, you can comment out all the previous test case invocations (up to ~10 lines) and focus only on that failing one. The new tests don't correspond 1:1 to the old python ones - they now cover more. Whenever there was a negative test to check if creating lvs on inexistent bdev failed, we'll now also create a dummy bdev beforehand, so that lvs will have more opportunity to do something it should not. Some other test cases were squashed. A few negative tests required a lot of setup just to try doing something illegal and see if spdk crashed. We'll now do those illegal operations in a single test case, giving lvol lib more opportunity to break. Even if illegal operation did not cause any segfault, is the lvolstore/lvol still usable? E.g. if we try to create an lvol on an lvs that doesn't have enough free clusters and it fails as expected, will it be still possible to create a valid lvol afterwards? Besides sending various RPC commands and checking their return code, we'll also parse and compare various fields in JSON RPC output from get_lvol_stores or get_bdevs RPC. We'll use inline jq calls for that. Whenever something's off, it will be clear which RPC returned invalid values and what were the expected values even without having detailed error prints. The tests are designed to be as easy as possible to debug whenever something goes wrong. This patch removes one test case from python tests and adds a corresponding test into the new test/lvol/lvol2.sh file. The script will be renamed to just lvol.sh after the existing lvol.sh (which starts all python tests) is finally removed. As for the bash script itself - each test case is run through a run_test() function which verifies there were no lvolstores, lvols, or bdevs left after the test case has finished. Inside the particular tests we will still check if the lvolstore removal at the end was successful, but that's because we want to make sure it's gone e.g even before we remove the underlying lvs' base bdev. Change-Id: Iaa2bb656233e1c9f0c35093f190ac26c39e78623 Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com> Signed-off-by: Pawel Kaminski <pawelx.kaminski@intel.com> Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/459517 Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com> Reviewed-by: Karol Latecki <karol.latecki@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Community-CI: Broadcom SPDK FC-NVMe CI <spdk-ci.pdl@broadcom.com>
2019-06-10 15:22:11 +02:00
# reserve some MBs for lvolstore metadata
LVS_DEFAULT_CAPACITY_MB=$((MALLOC_SIZE_MB - LVS_DEFAULT_CLUSTER_SIZE_MB))
LVS_DEFAULT_CAPACITY=$((LVS_DEFAULT_CAPACITY_MB * 1024 * 1024))
test/lvol: start rewriting python tests to bash There are multiple things wrong with current python tests: * they don't stop the execution on error * the output makes it difficult to understand what really happened inside the test * there is no easy way to reproduce a failure if there is one (besides running the same test script again) * they currently suffer from intermittent failures and there's no-one there to fix them * they stand out from the rest of spdk tests, which are written in bash So we rewrite those tests to bash. They will use rpc.py daemon to send RPC commands, so they won't take any more time to run than python tests. The tests are going to be split them into a few different categories: * clones * snapshots * thin provisioning * tasting * renaming * resizing * all the dumb ones - construct, destruct, etc Each file is a standalone test script, with common utility functions located in test/lvol/common.sh. Each file tests a single, specific feature, but under multiple conditions. Each test case is implemented as a separate function, so if you touch only one lvol feature, you can run only one test script, and if e.g. only a later test case notoriously breaks, you can comment out all the previous test case invocations (up to ~10 lines) and focus only on that failing one. The new tests don't correspond 1:1 to the old python ones - they now cover more. Whenever there was a negative test to check if creating lvs on inexistent bdev failed, we'll now also create a dummy bdev beforehand, so that lvs will have more opportunity to do something it should not. Some other test cases were squashed. A few negative tests required a lot of setup just to try doing something illegal and see if spdk crashed. We'll now do those illegal operations in a single test case, giving lvol lib more opportunity to break. Even if illegal operation did not cause any segfault, is the lvolstore/lvol still usable? E.g. if we try to create an lvol on an lvs that doesn't have enough free clusters and it fails as expected, will it be still possible to create a valid lvol afterwards? Besides sending various RPC commands and checking their return code, we'll also parse and compare various fields in JSON RPC output from get_lvol_stores or get_bdevs RPC. We'll use inline jq calls for that. Whenever something's off, it will be clear which RPC returned invalid values and what were the expected values even without having detailed error prints. The tests are designed to be as easy as possible to debug whenever something goes wrong. This patch removes one test case from python tests and adds a corresponding test into the new test/lvol/lvol2.sh file. The script will be renamed to just lvol.sh after the existing lvol.sh (which starts all python tests) is finally removed. As for the bash script itself - each test case is run through a run_test() function which verifies there were no lvolstores, lvols, or bdevs left after the test case has finished. Inside the particular tests we will still check if the lvolstore removal at the end was successful, but that's because we want to make sure it's gone e.g even before we remove the underlying lvs' base bdev. Change-Id: Iaa2bb656233e1c9f0c35093f190ac26c39e78623 Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com> Signed-off-by: Pawel Kaminski <pawelx.kaminski@intel.com> Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/459517 Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com> Reviewed-by: Karol Latecki <karol.latecki@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Community-CI: Broadcom SPDK FC-NVMe CI <spdk-ci.pdl@broadcom.com>
2019-06-10 15:22:11 +02:00
function get_bdev_jq() {
rpc_cmd_simple_data_json bdev "$@"
}
function get_lvs_jq() {
rpc_cmd_simple_data_json lvs "$@"
}
function check_leftover_devices() {
test/lvol: start rewriting python tests to bash There are multiple things wrong with current python tests: * they don't stop the execution on error * the output makes it difficult to understand what really happened inside the test * there is no easy way to reproduce a failure if there is one (besides running the same test script again) * they currently suffer from intermittent failures and there's no-one there to fix them * they stand out from the rest of spdk tests, which are written in bash So we rewrite those tests to bash. They will use rpc.py daemon to send RPC commands, so they won't take any more time to run than python tests. The tests are going to be split them into a few different categories: * clones * snapshots * thin provisioning * tasting * renaming * resizing * all the dumb ones - construct, destruct, etc Each file is a standalone test script, with common utility functions located in test/lvol/common.sh. Each file tests a single, specific feature, but under multiple conditions. Each test case is implemented as a separate function, so if you touch only one lvol feature, you can run only one test script, and if e.g. only a later test case notoriously breaks, you can comment out all the previous test case invocations (up to ~10 lines) and focus only on that failing one. The new tests don't correspond 1:1 to the old python ones - they now cover more. Whenever there was a negative test to check if creating lvs on inexistent bdev failed, we'll now also create a dummy bdev beforehand, so that lvs will have more opportunity to do something it should not. Some other test cases were squashed. A few negative tests required a lot of setup just to try doing something illegal and see if spdk crashed. We'll now do those illegal operations in a single test case, giving lvol lib more opportunity to break. Even if illegal operation did not cause any segfault, is the lvolstore/lvol still usable? E.g. if we try to create an lvol on an lvs that doesn't have enough free clusters and it fails as expected, will it be still possible to create a valid lvol afterwards? Besides sending various RPC commands and checking their return code, we'll also parse and compare various fields in JSON RPC output from get_lvol_stores or get_bdevs RPC. We'll use inline jq calls for that. Whenever something's off, it will be clear which RPC returned invalid values and what were the expected values even without having detailed error prints. The tests are designed to be as easy as possible to debug whenever something goes wrong. This patch removes one test case from python tests and adds a corresponding test into the new test/lvol/lvol2.sh file. The script will be renamed to just lvol.sh after the existing lvol.sh (which starts all python tests) is finally removed. As for the bash script itself - each test case is run through a run_test() function which verifies there were no lvolstores, lvols, or bdevs left after the test case has finished. Inside the particular tests we will still check if the lvolstore removal at the end was successful, but that's because we want to make sure it's gone e.g even before we remove the underlying lvs' base bdev. Change-Id: Iaa2bb656233e1c9f0c35093f190ac26c39e78623 Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com> Signed-off-by: Pawel Kaminski <pawelx.kaminski@intel.com> Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/459517 Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com> Reviewed-by: Karol Latecki <karol.latecki@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Community-CI: Broadcom SPDK FC-NVMe CI <spdk-ci.pdl@broadcom.com>
2019-06-10 15:22:11 +02:00
leftover_bdevs=$(rpc_cmd bdev_get_bdevs)
[ "$(jq length <<< "$leftover_bdevs")" == "0" ]
leftover_lvs=$(rpc_cmd bdev_lvol_get_lvstores)
[ "$(jq length <<< "$leftover_lvs")" == "0" ]
}
function round_down() {
local CLUSTER_SIZE_MB=$LVS_DEFAULT_CLUSTER_SIZE_MB
if [ -n "$2" ]; then
CLUSTER_SIZE_MB=$2
fi
echo $(($1 / CLUSTER_SIZE_MB * CLUSTER_SIZE_MB))
}
function run_fio_test() {
local file=$1
local offset=$2
local size=$3
local rw=$4
local pattern=$5
local extra_params=$6
local pattern_template="" fio_template=""
if [[ -n "$pattern" ]]; then
pattern_template="--do_verify=1 --verify=pattern --verify_pattern=$pattern --verify_state_save=0"
fi
fio_template="fio --name=fio_test --filename=$file --offset=$offset --size=$size --rw=$rw --direct=1 $extra_params $pattern_template"
$fio_template
}
function calc() {
bc -l <<< "define ceil(x) { scale=0; return(x + (x % 1 > 0))/1 } $1"
}