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