github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/tests/includes/storage.sh (about) 1 # assert_storage function will match that a given query exists in the output. 2 assert_storage() { 3 local name query 4 name=${1:?"name is missing"} 5 query=${2:?"query is missing"} 6 7 juju storage --format json | jq "${query}" | check "${name}" 8 } 9 10 # life_status checks for the life status for a given application storage. Uses a combination of the storage name and its unit index to query. 11 life_status() { 12 local name unit_index 13 name=${1} 14 unit_index=${2} 15 16 echo ".storage[\"$name/$unit_index\"][\"life\"]" 17 } 18 19 # kind_name checks for the storage kind using the combination of the storage name and its unit index to query. 20 kind_name() { 21 local name unit_index 22 name=${1} 23 unit_index=${2} 24 25 echo ".storage[\"$name/$unit_index\"][\"kind\"]" 26 } 27 28 # label checks for the storage label for a given application. The key's index is the application index. 29 label() { 30 local app_index 31 app_index=${1} 32 33 echo ".storage | keys[$app_index]" 34 } 35 36 # used to query for a storage's attached unit using the combination of the storage application name and its storage unit index. 37 unit_attachment() { 38 local name app_index unit_index 39 name=${1} 40 app_index=${2} 41 unit_index=${3} 42 43 echo ".storage[\"$name/$app_index\"] | .attachments | .units | keys[$unit_index]" 44 } 45 46 # unit_state queries for a storage application's attached unit life status using a combination of the storage application name and application index together with 47 # the storage unit name and storage unit index to filter. 48 unit_state() { 49 local app_name app_index unit_name unit_index 50 app_name=${1} 51 app_index=${2} 52 unit_name=${3} 53 unit_index=${4} 54 55 echo ".storage[\"$app_name/$app_index\"] | .attachments | .units[\"$unit_name/$unit_index\"][\"life\"]" 56 } 57 58 ## checks if the given storage unit exists. 59 unit_exist() { 60 local name 61 name=${1} 62 juju storage --format json | jq "any(paths; .[-1] == \"${name}\")" 63 } 64 65 # filesystem_status used to check for the current status of the given volume for a filesystem matched by the volume number and volume index combination e.g 0/0, 2/1, 3/1 66 filesystem_status() { 67 local name volume_num volume_index 68 volume_num=${1} 69 volume_index=${2} 70 71 if [ -z "$volume_index" ]; then 72 name="$volume_num" 73 else 74 name="$volume_num/$volume_index" 75 fi 76 echo ".filesystems | .[\"$name\"] | .status" 77 }