Files
Sergio Cazzolato ddfc54bd59 tests: use new snaps.name and snaps.cleanup tools (#11599)
* Squashed 'tests/lib/external/snapd-testing-tools/' changes from 872b64e05b..1a986df8d5

1a986df8d5 Merge pull request #17 from snapcore/new-snaps-cleanup-tool
29600af53a Fixing os.paths test for arch linux
e5cdb06053 Minor fixes based on comment reviews
89a0073b88 Run cleanup tests just on systems with snapd pre-installed
19d216a1b9 New tools to get os paths, snap names and cleanup the snaps
a36ee8451a Merge pull request #16 from snapcore/add-codespell
f837691b62 Adding codespell tool to github workflow
58418c3f7e Merge pull request #15 from snapcore/testing-jammy
f015a34899 Fix issue about how info is saved for Debug output
1ee4240e79 Adding jammy to the test systems in spread.yaml
61a4c3142d Merge pull request #14 from snapcore/include-support-s390x
3a1a65f6e1 Update the comments about shellchek
5ddfb7e1db New support for s390x arch in os.query tool
575f5d2016 Merge pull request #13 from snapcore/new-utils-section
4701612434 avoid installing and removing snapd in ubuntu focal
4d0317633d shellcheck in xenial is not needed
d95cb2e627 Moving some tools to the new utils section
839a0ce808 Merge pull request #10 from snapcore/new-spread-shellcheck-tool
5d5efd6fbe Merge pull request #12 from snapcore/run-shellchek-in-old-version
497b7d691f Force testing shellchek with versions 0.8 and 0.7
b3cb5a5a0a Update the copyright
5cfa7cb84d New shellcheck for spread tasks

git-subtree-dir: tests/lib/external/snapd-testing-tools
git-subtree-split: 1a986df8d5e66459ec9aa2498a1e9c7d7e419284

* Using new snaps.name and snaps.cleanup tools

These tools are imported from snapd-testing-tools

* cleanup tool will not be in bin

* Fix shellcheck

* Update missing tests

* Fix shellcheck

* Squashed 'tests/lib/external/snapd-testing-tools/' changes from 1a986df8d5..53ca1b3b70

53ca1b3b70 Merge pull request #21 from snapcore/fix-some-shellcheks
d380a8065e Fix shellchecks
ad410d44cd Merge pull request #20 from snapcore/fixes-on-remote-tools
80bfd6d85b Updates based on review comments in snapd project
5c77d93bd6 Merge pull request #18 from snapcore/tests-new-remote-tools
3cef4b69b4 Updating timeouts
2c6bf4bd48 Using local vars and removing wait-for tool
8642893803 Test fixes
a14ec4ea88 New remote tools
4545a5e5be Merge branch 'main' into tests-new-remote-tools
a791ae89cb New remote tools

git-subtree-dir: tests/lib/external/snapd-testing-tools
git-subtree-split: 53ca1b3b709e685b7910e4b559f182dd78039029

* Make snaps.name executable
2022-05-13 15:11:54 -03:00
..
2022-02-23 05:33:28 -06:00

ONCE THINGS ARE MADE UNIFORM THIS SHOULD BECOME A README WITHOUT THE TODO PART!

This "tools" directory collects useful utility commands that can be
used in our spread test suites. (They are separate from the shell
function libraries *.sh in the level above.)

Commands here should have names that clarify their purpose, longish
names using '-' as word separator are expected. Commands that take
themselves a full command to execute should usually end in '-do'.

The commands might take one or multiple subcommands themselves if
meaningful, subcommands should also use '-' as internal word
separator.

If a subcommand executes other commands it should usually be called
"exec".

All the commands invoked without arguments should either do something
informative/non-destructive or print usage.

All the commands should support at least a -h help option.

To invoke a command here tests can do "$TESTSTOOLS"/cmd.

Commands that are used very often or that are particularly useful to
debug at a spread -debug shell prompt can be promoted to be on the
PATH during tests, if an acceptable name can be found for them.

This is done by putting symlinks to here from tests/bin which itself
will be on the PATH.

Commands expected to be on the PATH should follow more specific naming
conventions, the name should either hint at testing or trade that off
for brevity, but only when appropriate:

* really frequently used commands can have short/pithy names (not, retry...)

* commands that manage or deal with cross-test/cross-task state should be
  prefixed with "tests." (tests.session)

* otherwise the command should take some form of suffix like ".query", ".check"
  that hints at observing, checking the system

In general if none of these apply they should continue to be invoked
via $TESTSTOOLS, or possibly have a tests/lib/*.sh wrapping them if
appropriate.

TODO:

[done] rename tests/lib/bin to tests/lib/tools, define TESTSTOOLS in
spread.yaml pointing at it

[done] create tests/bin, have ultimately this on the PATH and not tools:
  drop tests/lib/tools from PATH in spread.yaml and debian/tests/integrationtests

symlinks and renames (plus fixes):

[done] tests/bin/MATCH -> tests/lib/tools/MATCH
[done] tests/bin/REBOOT -> tests/lib/tools/REBOOT
[done] tests/bin/not -> tests/lib/tools/not
[done] tests/bin/retry -> tests/lib/tools/retry (was retry-tool)

[done] tests/bin/tests.session -> tests/lib/tools/tests.session (was session-tool)
  [done] fix to have -h
  [done] convert --ACTION into subcommands
  [done] require "exec" subcommand to execute a command

[done] tests/lib/tools/memory-observe-do (was memory-tool)
[done] tests/lib/tools/version-compare (was version-tool)

[done] tests/bin/mountinfo.query -> tests/lib/tools/mountinfo.query (was mountinfo-tool)
  (we might not do this and keep just tests/lib/tools/mountinfo and call it the long way)

[done] tests/bin/snapd.tool -> tests/lib/tools/snapd.tool (was snap-tool)
  [done] fix no args
  [done] fix to have -h
  (we might not do this, this would be a special case, the name has
   snapd in itself, it makes sense in /bin mostly for debugging,
   otherwise it could stay just in tools as in itself it is not called
   that often by tests, it would just become snapd-tool)

We are then left with a mixture of commands with maybe one or a couple
subcommands dealing with system state:

* simple option rename them with a -state suffix in most cases:

[done] user-tool -> test/lib/tools/user-state
  [done] fix with no args
  [done] fix -h help

[done] apt-tool -> tests/lib/tools/apt-state
  [done] fix no args
  [done] fix to have -h

[done] lxd-tool -> tests/lib/tools/lxd-state
  [done] fix no args
  [done] fix to have -h

[done] invariant-tool -> tests/lib/tools/tests.invariant? then it could also live in /bin
  [done] fix to have -h

* more complicated option, have a tests.state trampoline command in tests/bin
  that given `tests.state WHAT ARGS` invokes `tests/lib/tools/state-WHAT ARGS`

  then we would have in tools:

  state-apt (was apt-tool)
  state-lxd-undo-mount-changes (was lxd-tool)
  state-remove-user-with-group (was user-tool)

  tests.state without arguments or with -h would invoke all the state-* commands
  appropriately to show usage info

  invariant-tool could possibly become `tests.state invariant` or be
  dealt with separately