Skip to content

Commit

Permalink
test: Improve usage of lxd sql in tests (#14674)
Browse files Browse the repository at this point in the history
Support for the `--format` flag was added in #14670. This PR uses the
format flag where possible in our test suite to avoid e.g. grepping for
table formatted output.

In some cases I've changed queries to use a `SELECT count(*) FROM ...`
instead of a `SELECT * FROM ...` where the output was piped into a word
count or grepped with the -c flag.
  • Loading branch information
tomponline authored Dec 17, 2024
2 parents f9bd610 + 363e84b commit e57536c
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 55 deletions.
2 changes: 1 addition & 1 deletion test/suites/auth.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ test_authorization() {
# Test permission is removed automatically when instance is removed.
lxc auth group permission add test-group instance c1 can_exec project=default # Valid
lxc rm c1 --force
! lxd sql global "SELECT * FROM auth_groups_permissions WHERE entitlement = 'can_exec'" | grep c1 || false # Permission should be removed when instance is removed.
[ "$(lxd sql global --format csv "SELECT count(*) FROM auth_groups_permissions WHERE entitlement = 'can_exec'")" = 0 ] # Permission should be removed when instance is removed.

# Network permissions
! lxc auth group permission add test-group network n1 can_view project=default || false # Not found
Expand Down
4 changes: 2 additions & 2 deletions test/suites/backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ EOF
lxc exec c1 --project test -- hostname

# Test recover after pool DB config deletion too.
poolConfigBefore=$(lxd sql global "SELECT key,value FROM storage_pools_config JOIN storage_pools ON storage_pools.id = storage_pools_config.storage_pool_id WHERE storage_pools.name = '${poolName}' ORDER BY key")
poolConfigBefore=$(lxd sql global --format csv "SELECT key,value FROM storage_pools_config JOIN storage_pools ON storage_pools.id = storage_pools_config.storage_pool_id WHERE storage_pools.name = '${poolName}' ORDER BY key")
poolSource=$(lxc storage get "${poolName}" source)
poolExtraConfig=""

Expand Down Expand Up @@ -259,7 +259,7 @@ EOF

# Check recovered pool config (from instance backup file) matches what originally was there.
lxc storage show "${poolName}"
poolConfigAfter=$(lxd sql global "SELECT key,value FROM storage_pools_config JOIN storage_pools ON storage_pools.id = storage_pools_config.storage_pool_id WHERE storage_pools.name = '${poolName}' ORDER BY key")
poolConfigAfter=$(lxd sql global --format csv "SELECT key,value FROM storage_pools_config JOIN storage_pools ON storage_pools.id = storage_pools_config.storage_pool_id WHERE storage_pools.name = '${poolName}' ORDER BY key")
echo "Before:"
echo "${poolConfigBefore}"

Expand Down
Loading

0 comments on commit e57536c

Please sign in to comment.