xref: /spdk/test/ocf/management/create-destruct.sh (revision eb53c23236cccb6b698b7ca70ee783da1c574b5f)
1#!/usr/bin/env bash
2#  SPDX-License-Identifier: BSD-3-Clause
3#  Copyright (C) 2019 Intel Corporation
4#  All rights reserved.
5#
6curdir=$(dirname $(readlink -f "${BASH_SOURCE[0]}"))
7rootdir=$(readlink -f $curdir/../../..)
8source $rootdir/test/common/autotest_common.sh
9
10rpc_py=$rootdir/scripts/rpc.py
11
12function bdev_check_claimed() {
13	if [ "$($rpc_py bdev_get_bdevs -b "$@" | jq '.[0].claimed')" = "true" ]; then
14		return 0
15	else
16		return 1
17	fi
18}
19
20$SPDK_BIN_DIR/iscsi_tgt &
21spdk_pid=$!
22
23trap 'killprocess $spdk_pid; exit 1' SIGINT SIGTERM EXIT
24
25waitforlisten $spdk_pid
26
27$rpc_py bdev_malloc_create 101 512 -b Malloc0
28$rpc_py bdev_malloc_create 101 512 -b Malloc1
29
30$rpc_py bdev_ocf_create PartCache wt Malloc0 NonExisting
31
32$rpc_py bdev_ocf_get_bdevs PartCache | jq -e \
33	'.[0] | .started == false and .cache.attached and .core.attached == false'
34
35$rpc_py bdev_ocf_get_bdevs NonExisting | jq -e \
36	'.[0] | .name == "PartCache"'
37
38if ! bdev_check_claimed Malloc0; then
39	echo >&2 "Base device expected to be claimed now"
40	exit 1
41fi
42
43$rpc_py bdev_ocf_delete PartCache
44if bdev_check_claimed Malloc0; then
45	echo >&2 "Base device is not expected to be claimed now"
46	exit 1
47fi
48
49$rpc_py bdev_ocf_create FullCache wt Malloc0 Malloc1
50
51$rpc_py bdev_ocf_get_bdevs FullCache | jq -e \
52	'.[0] | .started and .cache.attached and .core.attached'
53
54if ! (bdev_check_claimed Malloc0 && bdev_check_claimed Malloc1); then
55	echo >&2 "Base devices expected to be claimed now"
56	exit 1
57fi
58
59$rpc_py bdev_ocf_delete FullCache
60if bdev_check_claimed Malloc0 && bdev_check_claimed Malloc1; then
61	echo >&2 "Base devices are not expected to be claimed now"
62	exit 1
63fi
64
65$rpc_py bdev_ocf_create HotCache wt Malloc0 Malloc1
66
67if ! (bdev_check_claimed Malloc0 && bdev_check_claimed Malloc1); then
68	echo >&2 "Base devices expected to be claimed now"
69	exit 1
70fi
71
72$rpc_py bdev_malloc_delete Malloc0
73
74if bdev_check_claimed Malloc1; then
75	echo >&2 "Base device is not expected to be claimed now"
76	exit 1
77fi
78
79status=$($rpc_py bdev_get_bdevs)
80gone=$(echo $status | jq 'map(select(.name == "HotCache")) == []')
81if [[ $gone == false ]]; then
82	echo >&2 "OCF bdev is expected to unregister"
83	exit 1
84fi
85
86# check if shutdown of running CAS bdev is ok
87$rpc_py bdev_ocf_create PartCache wt NonExisting Malloc1
88
89trap - SIGINT SIGTERM EXIT
90
91killprocess $spdk_pid
92