xref: /spdk/test/sma/plugins.sh (revision 18c8b52afa69f39481ebb75711b2f30b11693f9d)
1#!/usr/bin/env bash
2
3testdir=$(readlink -f "$(dirname "$0")")
4rootdir=$(readlink -f "$testdir/../..")
5
6source "$rootdir/test/common/autotest_common.sh"
7source "$testdir/common.sh"
8
9function cleanup() {
10	killprocess $tgtpid
11	killprocess $smapid
12}
13
14function create_device() {
15	"$rootdir/scripts/sma-client.py" <<- EOF
16		{
17			"method": "CreateDevice",
18			"params": {
19				"$1": {}
20			}
21		}
22	EOF
23}
24
25trap 'cleanup; exit 1' SIGINT SIGTERM EXIT
26
27$rootdir/build/bin/spdk_tgt &
28tgtpid=$!
29
30# First check a single plugin with both its devices enabled in the config
31PYTHONPATH=$testdir/plugins $rootdir/scripts/sma.py -c <(
32	cat <<- EOF
33		plugins:
34		  - 'plugin1'
35		devices:
36		  - name: 'plugin1-device1'
37		  - name: 'plugin1-device2'
38	EOF
39) &
40smapid=$!
41# Wait for a while to make sure SMA starts listening
42sma_waitforlisten
43
44[[ $(create_device nvme | jq -r '.handle') == 'nvme:plugin1-device1:nop' ]]
45[[ $(create_device nvmf_tcp | jq -r '.handle') == 'nvmf_tcp:plugin1-device2:nop' ]]
46
47killprocess $smapid
48
49# Check that it's possible to enable only a single device from a plugin
50PYTHONPATH=$testdir/plugins $rootdir/scripts/sma.py -c <(
51	cat <<- EOF
52		plugins:
53		  - 'plugin1'
54		devices:
55		  - name: 'plugin1-device2'
56	EOF
57) &
58smapid=$!
59sma_waitforlisten
60
61[[ $(create_device nvmf_tcp | jq -r '.handle') == 'nvmf_tcp:plugin1-device2:nop' ]]
62NOT create_device nvme
63
64killprocess $smapid
65
66# Load two different plugins, but only enable devices from one of them
67PYTHONPATH=$testdir/plugins $rootdir/scripts/sma.py -c <(
68	cat <<- EOF
69		plugins:
70		  - 'plugin1'
71		  - 'plugin2'
72		devices:
73		  - name: 'plugin1-device1'
74		  - name: 'plugin1-device2'
75	EOF
76) &
77smapid=$!
78sma_waitforlisten
79
80[[ $(create_device nvme | jq -r '.handle') == 'nvme:plugin1-device1:nop' ]]
81[[ $(create_device nvmf_tcp | jq -r '.handle') == 'nvmf_tcp:plugin1-device2:nop' ]]
82
83killprocess $smapid
84
85# Check the same but take devices defined by the other plugin
86PYTHONPATH=$testdir/plugins $rootdir/scripts/sma.py -c <(
87	cat <<- EOF
88		plugins:
89		  - 'plugin1'
90		  - 'plugin2'
91		devices:
92		  - name: 'plugin2-device1'
93		  - name: 'plugin2-device2'
94	EOF
95) &
96smapid=$!
97sma_waitforlisten
98
99[[ $(create_device nvme | jq -r '.handle') == 'nvme:plugin2-device1:nop' ]]
100[[ $(create_device nvmf_tcp | jq -r '.handle') == 'nvmf_tcp:plugin2-device2:nop' ]]
101
102killprocess $smapid
103
104# Now pick a device from each plugin
105PYTHONPATH=$testdir/plugins $rootdir/scripts/sma.py -c <(
106	cat <<- EOF
107		plugins:
108		  - 'plugin1'
109		  - 'plugin2'
110		devices:
111		  - name: 'plugin1-device1'
112		  - name: 'plugin2-device2'
113	EOF
114) &
115smapid=$!
116sma_waitforlisten
117
118[[ $(create_device nvme | jq -r '.handle') == 'nvme:plugin1-device1:nop' ]]
119[[ $(create_device nvmf_tcp | jq -r '.handle') == 'nvmf_tcp:plugin2-device2:nop' ]]
120
121killprocess $smapid
122
123# Check the same, but register plugins via a env var
124PYTHONPATH=$testdir/plugins SMA_PLUGINS=plugin1:plugin2 $rootdir/scripts/sma.py -c <(
125	cat <<- EOF
126		devices:
127		  - name: 'plugin1-device1'
128		  - name: 'plugin2-device2'
129	EOF
130) &
131smapid=$!
132sma_waitforlisten
133
134[[ $(create_device nvme | jq -r '.handle') == 'nvme:plugin1-device1:nop' ]]
135[[ $(create_device nvmf_tcp | jq -r '.handle') == 'nvmf_tcp:plugin2-device2:nop' ]]
136
137killprocess $smapid
138
139# Register one plugin in a config and the other through env var
140PYTHONPATH=$testdir/plugins SMA_PLUGINS=plugin1 $rootdir/scripts/sma.py -c <(
141	cat <<- EOF
142		plugins:
143		  - 'plugin2'
144		devices:
145		  - name: 'plugin1-device1'
146		  - name: 'plugin2-device2'
147	EOF
148) &
149smapid=$!
150sma_waitforlisten
151
152[[ $(create_device nvme | jq -r '.handle') == 'nvme:plugin1-device1:nop' ]]
153[[ $(create_device nvmf_tcp | jq -r '.handle') == 'nvmf_tcp:plugin2-device2:nop' ]]
154
155killprocess $smapid
156
157# Check registering external crypto engines
158crypto_engines=(crypto-plugin1 crypto-plugin2)
159for crypto in "${crypto_engines[@]}"; do
160	PYTHONPATH=$testdir/plugins $rootdir/scripts/sma.py -c <(
161		cat <<- EOF
162			plugins:
163			  - 'plugin1'
164			  - 'plugin2'
165			devices:
166			  - name: 'plugin1-device1'
167			  - name: 'plugin2-device2'
168			crypto:
169			  name: '$crypto'
170		EOF
171	) &
172	smapid=$!
173	sma_waitforlisten
174
175	[[ $(create_device nvme | jq -r '.handle') == nvme:plugin1-device1:$crypto ]]
176	[[ $(create_device nvmf_tcp | jq -r '.handle') == nvmf_tcp:plugin2-device2:$crypto ]]
177
178	killprocess $smapid
179done
180
181cleanup
182trap - SIGINT SIGTERM EXIT
183