Commit Graph

84 Commits

Author SHA1 Message Date
Penn Bauman e805291a10 test/system: Support host operating systems without VERSION_ID
The VERSION_ID field in os-release(5) is optional [1].  It's absent on
Arch Linux, which follows a rolling-release model and uses the BUILD_ID
field instead:
  BUILD_ID=rolling

A subsequent commit will run the CI on Arch Linux.  Hence, the code to
get the default release from the host operating system can no longer
assume the presence of the VERSION_ID field in os-release(5).

Note that the arch-toolbox image is tagged with 'latest', in accordance
with OCI conventions, not 'rolling' [2,3], which is the os-release(5)
BUILD_ID.

A similar change was made to toolbox(1) in commits 2ee82affeb and
d14fd7bb50.

[1] https://www.freedesktop.org/software/systemd/man/os-release.html

[2] Commit 2568528cb7
    https://github.com/containers/toolbox/commit/2568528cb7f52663
    https://github.com/containers/toolbox/pull/861

[3] Commit a4e5861ae5
    https://github.com/containers/toolbox/commit/a4e5861ae5c93625
    https://github.com/containers/toolbox/pull/1308

https://github.com/containers/toolbox/issues/1438
https://github.com/containers/toolbox/pull/1535
2024-11-17 11:26:29 +01:00
Debarshi Ray fbffd45384 playbooks, test/system: Drop the PODMAN and SKOPEO environment variables
The toolbox(1) binary always relies on the PATH environment variable to
find the podman(1) and skopeo(1) binaries.  There's no way to override
those with the PODMAN and SKOPEO environment variables, and they only
affect any direct use of podman(1) and skopeo(1) within the test suite.

Therefore, offering the PODMAN and SKOPEO environment variables in their
current form is needlessly confusing and misleading, and can lead to
surprises arising from different podman(1) and skopeo(1) binaries being
used in different places.  Either toolbox(1) should also honour them or
the test suite shouldn't offer them.  The former is more complicated
without any obvious need for it, so the latter was chosen.

https://github.com/containers/toolbox/pull/1592
2024-11-14 02:06:33 +01:00
Debarshi Ray ed14cd483a Revert "playbooks, test/system: Work around bug in pasta(1) networks"
The bug in pasta(1) that necessitated this workaround has since been
fixed in passt 2024_05_10.7288448 [1].  Some host operating systems like
CentOS Stream 10 no longer have slirp4netns(1), and it's generally
better to test the defaults.

This reverts commit b58f9a5108.

[1] https://github.com/containers/podman/issues/22575
    https://archives.passt.top/passt-dev/20240508090338.2735208-1-sbrivio@redhat.com/
    https://archives.passt.top/passt-user/20240510225714.6aa8e6c0@elisabeth/

https://github.com/containers/toolbox/pull/1562
2024-10-04 22:17:50 +02:00
Debarshi Ray 987f5e2592 .zuul, playbooks, test/system: Optimize the CI on Fedora nodes
The test suite has expanded to 415 system tests.  These tests can be
very I/O intensive, because many of them copy OCI images from the test
suite's image cache directory to its local container/storage store,
create containers, and then delete everything to run the next test with
a clean slate.  This makes the system tests slow.

Unfortunately, Zuul's max-job-timeout setting defaults to an upper limit
of 3 hours or 10800 seconds for jobs [1], and this is what Software
Factory uses [2].  So, there comes a point beyond which the CI can't be
prevented from timing out by increasing the timeout.

One way of scaling past this maximum time limit is to run the tests in
parallel across multiple nodes.  This has been implemented by splitting
the system tests into different groups, which are run separately by
different nodes.

First, the tests were grouped into those that test commands and options
accepted by the toolbox(1) binary, and those that test the runtime
environment within the Toolbx containers.  The first group has more
tests, but runs faster, because many of them test error handling and
don't do much I/O.

The runtime environment tests take especially long on Fedora Rawhide
nodes, which are often slower than the stable Fedora nodes.  Possibly
because Rawhide uses Linux kernels that are built with debugging
enabled, which makes it slower.  Therefore, this group of tests were
further split for Rawhide nodes by the Toolbx images they use.  Apart
from reducing the number of tests in each group, this should also reduce
the amount of time spent in downloading the images.

The split has been implemented with Bats' tagging system that is
available from Bats 1.8.0 [3].  Fortunately, commit 87eaeea6f0
already added a dependency on Bats >= 1.10.0.  So, there's nothing to
worry about.

At the moment, Bats doesn't expose the tags being used to run the test
suite to setup_suite() and teardown_suite() [4].  Therefore, the
TOOLBX_TEST_SYSTEM_TAGS environment variable was used to optimize the
contents of setup_suite().

[1] https://zuul-ci.org/docs/zuul/latest/tenants.html

[2] Commit 83f28c52e4
    https://github.com/containers/toolbox/commit/83f28c52e47c2d44
    https://github.com/containers/toolbox/pull/1548

[3] https://bats-core.readthedocs.io/en/stable/writing-tests.html

[4] https://github.com/bats-core/bats-core/issues/1006

https://github.com/containers/toolbox/pull/1551
2024-09-28 01:28:58 +02:00
Debarshi Ray 67d40024ce test/system: Consolidate teardown() to remove both containers & images
It's far more consistent and understandable if all tests start with a
clean state without any containers or images present.  Otherwise, the
subtle side-effects of having some image left behind from a previous
test can lead to surprises, and there's no need to spend time wondering
whether some tests should only clean up the containers or both
containers and images.

This additional work of cleaning up the images for all tests makes it
necessary to increase the timeout for all Fedora nodes to prevent the CI
from timing out.

https://github.com/containers/toolbox/pull/1526
2024-08-29 21:13:44 +02:00
Debarshi Ray 26640d2f14 test/system: Drop unnecessary port configuration from registry container
The specific port used by the local temporary Docker registry inside the
container doesn't matter.  The container is running only one service and
its users only see the corresponding port on the host operating system.
The default port within the container is 5000 [1] and there's no reason
to change it.

[1] https://github.com/distribution/distribution-library-image

https://github.com/containers/toolbox/pull/1484
2024-05-07 11:11:03 +02:00
Debarshi Ray 70ab04867b test/system: Reorder alphabetically
https://github.com/containers/toolbox/pull/1484
2024-05-07 03:43:42 +02:00
Debarshi Ray 95dd30547c test/system: Use long options, instead of their shorter aliases
The long options are easier to grep(1) for in the sources than their
shorter aliases.

https://github.com/containers/toolbox/pull/1484
2024-05-07 03:40:42 +02:00
Debarshi Ray b58f9a5108 playbooks, test/system: Work around bug in pasta(1) networks
Podman 5.0 switched to using pasta(1), instead of slirp4netns(1), by
default for rootless containers.  This change has led to a regression
causing 'skopeo copy' to get stuck uploading an OCI image to the local
temporary Docker registry run by the tests as a Podman container [1],
which breaks the test suite on Fedora 40 onwards.

Work around this by forcing the use of slirp4netns(1).

Note that the slirp4nets package needs to be explicitly installed on
Fedora 40 onwards, because the dependency in containers-common-extra
changed from Recommends to Suggests [2].

[1] https://github.com/containers/podman/issues/22575

[2] Fedora containers-common commit 17934d87b2686ab5
    Fedora containers-common commit 13c232f064113860
    https://src.fedoraproject.org/rpms/containers-common/c/17934d87b2686ab5
    https://src.fedoraproject.org/rpms/containers-common/c/13c232f064113860

https://github.com/containers/toolbox/pull/1468
2024-05-02 15:08:37 +02:00
Debarshi Ray 3a549a6252 test/system: Limit the scope of temporary files used by all tests
BATS_RUN_DIR is the directory used by Bats for its own internal
temporary files, and BATS_SUITE_TMPDIR is for creating files common to
all tests in the test suite [1].  It's better to stay away from Bats'
own internal temporary files to avoid unexpected collisions.

[1] https://bats-core.readthedocs.io/en/stable/writing-tests.html

https://github.com/containers/toolbox/pull/1452
2024-02-20 01:09:25 +01:00
Debarshi Ray c3403dae8c Drop one "o" and rename the project as "Toolbx"
This is meant to make the project more searchable on the Internet.  More
and more people have been pointing out that "toolbox" is terribly
difficult to search for, and it's impossible to find any decent
Internet real estate by that name.

Some exceptions:

  * The code repository is still https://github.com/containers/toolbox.
    It will be renamed after giving a heads-up to other contributors.

  * The name of the binary is still 'toolbox'.  The name is embedded
    into existing Toolbx containers as their entry point, which is bind
    mounted from the host operating system when the containers are
    started.  Trivially renaming the binary will prevent these
    containers from starting.

  * For similar reasons, the TOOLBOX_PATH environment variable is still
    the same.

  * For similar reasons, the profile.d file to be read by the shell on
    start-up is still called toolbox.sh.

  * The label used to identify Toolbx containers and images is still
    called com.github.containers.toolbox.  There are many existing
    Toolbx containers, and many Toolbx images beyond the control of the
    Toolbx project that use this label to identity themselves.  Simply
    renaming the label will prevent these containers and images from
    being recognized.

  * The names of the built-in Toolbx images still retain the word
    'toolbox'.  Images under the new name need to be published on the
    OCI registries and the toolbox(1) binary needs to be taught to
    handle both old and new names, wherever necessary, for backwards
    compatibility.

  * The stamp file used to identify Toolbx containers is still called
    /run/.toolboxenv because it's used by various external programs and
    users to identify Toolbx containers.

  * The OSC 777 escape sequence to track and preserve the user's current
    Toolbx container [1] still emits 'toolbox' as the name of the
    container runtime.  Changing the escape sequence can break terminal
    emulation applications, like Prompt [2], that consume it.  Hence, it
    needs to be done carefully.

  * The runtime directories at /run/toolbox, when used as root, and
    $XDG_RUNTIME_DIR/toolbox, when used rootless, weren't renamed.

    When used as root, /run/toolbox is embedded into existing Toolbx
    containers as a bind mount from the host.  Trivially renaming the
    path will prevent these containers from starting.

    Secondly, both these paths are used to synchronize container
    start-up.  If the paths are trivially renamed, and the toolbox(1)
    binary is updated and used without stopping all existing containers,
    then it won't be able to enter containers that were already started.
    Strictly speaking, this scenario isn't supported, since updates are
    always expected to be "offline" [3].  However, it's worth noting
    because solving the previous problem might also address this.

  * The configuration file for RPM is still called
    /usr/lib/rpm/macros.d/macros.toolbox.

[1] https://gitlab.freedesktop.org/terminal-wg/specifications/-/issues/17

[2] https://gitlab.gnome.org/chergert/prompt

[3] https://www.freedesktop.org/software/systemd/man/latest/systemd.offline-updates.html

https://github.com/containers/toolbox/issues/1399
2024-02-06 18:24:26 +01:00
Debarshi Ray 4362c39c13 test/system: Silence SC2154
Otherwise https://www.shellcheck.net/ would complain:
  Line 343:
  if [ "$status" -ne 0 ]; then
        ^-----^ SC2154 (warning): status is referenced but not assigned.

See: https://www.shellcheck.net/wiki/SC2154

https://github.com/containers/toolbox/pull/1378
2023-09-25 18:13:58 +02:00
Debarshi Ray 574dbc920c test/system: Specify explit return values
This removes any ambiguities and makes it clear what value is being
returned.

https://github.com/containers/toolbox/pull/1378
2023-09-25 18:13:54 +02:00
Debarshi Ray 0d43d22b5b test/system: Simplify checking if the image exists or not
Bats' 'run' helper is not necessary to merely check if a command
succeeded or not [1].  In this case, it's idiomatic to use the command
as the condition for an 'if' branch.

[1] https://bats-core.readthedocs.io/en/stable/writing-tests.html

https://github.com/containers/toolbox/pull/1378
2023-09-25 18:13:50 +02:00
Debarshi Ray 9f85e13da9 test/system: Use the standard error output for error messages
https://github.com/containers/toolbox/pull/1377
2023-09-25 17:21:52 +02:00
Debarshi Ray 5ac8567bad test/system: Specify an explit return value
This removes any ambiguities and makes it clear what value is being
returned.

https://github.com/containers/toolbox/pull/1377
2023-09-25 16:08:14 +02:00
Debarshi Ray 61e2c970f8 test/system: Make it easier to spot failures to download & cache images
Currently, if 'skopeo copy ...' fails to download and cache an OCI image
during setup_suite(), the test suite doesn't immediately fail, but
continues.  It only fails later when trying to set up the Docker
registry and contains a lot of noise:
  not ok 1 setup_suite
  # (from function `assert_success' in file
       test/system/libs/bats-assert/src/assert.bash, line 114,
  #  from function `_setup_docker_registry' in file
       test/system/libs/helpers.bash, line 211,
  #  from function `setup_suite' in test file
       test/system/setup_suite.bash, line 59)
  #   `_setup_docker_registry' failed
  # Failed to cache image registry.fedoraproject.org/fedora-toolbox:38
      to /tmp/bats-run-GyTP7A/image-cache/fedora-toolbox-38
  #
  # -- command failed --
  # status : 1
  # output : time="2023-09-25T12:19:52+02:00" level=fatal
      msg="initializing source
        docker://registry.fedoraproject.org/fedora-toolbox:38-foo:
        reading manifest 38-foo in
        registry.fedoraproject.org/fedora-toolbox: manifest unknown"
  # --
  #
  # Failed to cache image quay.io/toolbx/arch-toolbox:latest to
      /tmp/bats-run-GyTP7A/image-cache/arch-toolbox-latest
  #
  # -- command failed --
  # status : 1
  # output : time="2023-09-25T12:20:48+02:00" level=fatal
      msg="initializing source
        docker://quay.io/toolbx/arch-toolbox:latest-foo: reading
        manifest latest-foo in quay.io/toolbx/arch-toolbox: manifest
        unknown"
  # --
  #
  # Failed to cache image registry.fedoraproject.org/fedora-toolbox:34
      to /tmp/bats-run-GyTP7A/image-cache/fedora-toolbox-34
  #
  # -- command failed --
  # status : 1
  # output : time="2023-09-25T12:21:42+02:00" level=fatal
      msg="initializing source
        docker://registry.fedoraproject.org/fedora-toolbox:34-foo:
        reading manifest 34-foo in
        registry.fedoraproject.org/fedora-toolbox: manifest unknown"
  # --
  #
  # ...
  #
  # -- command failed --
  # status : 1
  # output : time="2023-09-25T12:26:33+02:00" level=fatal
      msg="determining manifest MIME type for
        dir:/tmp/bats-run-GyTP7A/image-cache/fedora-toolbox-34: open
        /tmp/bats-run-GyTP7A/image-cache/fedora-toolbox-34/manifest.json:
        no such file or directory"
  # --
  #
  # docker-registry
  # 27fa141e291e64e4c7a148c88ddab219ff2bfb5802a2982dc4188dc11f41692d
  # Untagged: quay.io/toolbox_tests/registry:latest
  # Deleted: fea5a12cde107bb407bc44ede6dd9edea1d2b4171cd8e52b0cb330bf45e517e1

It makes it look as if the root cause of the failure is related to
setting up the Docker registry, which it isn't, and all that noise makes
it difficult to spot the actual problem.

Instead, from now on, it will be more obvious:
  not ok 1 setup_suite
  # (from function `setup_suite' in test file
       test/system/setup_suite.bash, line 44)
  #   `_pull_and_cache_distro_image "$system_id" "$system_version" ||
         false' failed
  # Failed to cache image registry.fedoraproject.org/fedora-toolbox:38
      to /tmp/bats-run-62b8CU/image-cache/fedora-toolbox-38
  # time="2023-09-25T13:55:42+02:00" level=fatal msg="initializing
      source docker://registry.fedoraproject.org/fedora-toolbox:38-foo:
      reading manifest 38-foo in
      registry.fedoraproject.org/fedora-toolbox: manifest unknown"

Note that Bats' 'run' helper [1] isn't designed to work inside
setup_suite().  eg., 'run --separate-stderr' doesn't work because
BATS_TEST_TMPDIR isn't defined.

[1] https://bats-core.readthedocs.io/en/stable/writing-tests.html

https://github.com/containers/toolbox/pull/1377
2023-09-25 16:02:25 +02:00
Debarshi Ray 74bf1af983 test/system: Remove stray 'podman ...' error in setup_suite() failures
If setup_suite() fails for some reason, then an unrelated message from
'podman system reset' would show up:
  not ok 1 setup_suite
  # (from function `setup_suite' in test file
       test/system/setup_suite.bash, line 43)
  #   `_pull_and_cache_distro_image foo || false' failed
  # Requested distro (foo) does not have a matching image
  #  A "/home/rishi/.cache/toolbox/system-test-storage/storage.conf"
       config file exists.
  # Remove this file if you did not modify the configuration.

This extra error message from 'podman system reset' serves no purpose
because it's not related to the cause of the setup_suite() failure.
It's just noise and it's better to silence it.

https://github.com/containers/toolbox/pull/1375
2023-09-23 00:29:36 +02:00
Debarshi Ray 9415797e8b test/system: Use long options, instead of their shorter aliases
The long options are easier to grep(1) for in the sources than their
shorter aliases.

https://github.com/containers/toolbox/pull/1375
2023-09-23 00:19:56 +02:00
Debarshi Ray 66a7ad7c97 test/system: Remove stray 'podman stop' error in setup_suite() failures
If setup_suite() fails for some reason, causing the Docker registry to
not be created, then an unrelated message from 'podman stop' would show
up:
  not ok 1 setup_suite
  # (from function `setup_suite' in test file
       test/system/setup_suite.bash, line 43)
  #   `_pull_and_cache_distro_image foo || false' failed
  # Requested distro (foo) does not have a matching image
  # Error: no container with name or ID "docker-registry" found: no such
      container
  # ...
  # ...

This extra error message from 'podman stop' serves no purpose because
it's not related to the cause of the setup_suite() failure.  It's just
noise and it's better to silence it.

https://github.com/containers/toolbox/pull/1375
2023-09-23 00:19:56 +02:00
Debarshi Ray e1745ef9c2 test/system: Ensure failure if an invalid distribution is specified
Contrary to what the documentation might seem to imply [1], Bats' 'fail'
helper only aborts a test case under certain circumstances.  eg., when
called from setup_suite(), but not from within a child function, and a
@test case, but not from within the 'run' helper.

If 'fail' is called from within 'run', then the code after it will
continue to execute.  The test case will only fail if 'run' eventually
catches a non-zero exit code that's caught by 'assert_success' [2].
Similarly, it doesn't abort if called from within a child function in
setup_suite().

Currently, _pull_and_cache_distro_image() is a child function called
from setup_suite().  So 'fail' won't abort if an invalid distribution is
specified.

Fortunately, pull_distro_image() is being called from within @test
cases, but outside 'run'.  So, there's no problem with it now.  However,
some future code changes can unknowingly alter this reality and it too
can run into unexpected behaviour.

Therefore, it's better to be safe, and explicitly specify a non-zero
exit code after 'fail'.  It will ensure that it works as expected under
all circumstances.

[1] https://github.com/bats-core/bats-support

[2] https://github.com/bats-core/bats-assert

https://github.com/containers/toolbox/pull/1375
2023-09-23 00:04:32 +02:00
Debarshi Ray a7feb00996 test/system: Make it easier to debug why a container didn't initialize
Currently, if a Toolbx container's entry point fails to initialize the
container, there's no way to see the debug logs and error messages from
the entry point:
  not ok 106 container: Check container starts without issues
  # (from function `assert_success' in file
       test/system/libs/bats-assert/src/assert.bash, line 114,
  #  in test file test/system/103-container.bats, line 39)
  #   `assert_success' failed
  #
  # -- command failed --
  # status : 1
  # output :
  # --
  #

Instead, from now on, they will be visible:
  not ok 106 container: Check container starts without issues
  # (from function `assert_success' in file
       test/system/libs/bats-assert/src/assert.bash, line 114,
  #  in test file test/system/103-container.bats, line 39)
  #   `assert_success' failed
  #
  # -- command failed --
  # status : 1
  # output (90 lines):
  #   Failed to initialize container fedora-toolbox-38
  #   level=debug msg="Running as real user ID 0"
  #   level=debug msg="Resolved absolute path to the executable as
        /usr/bin/toolbox"
  #   level=debug msg="TOOLBOX_PATH is /opt/bin/toolbox"
  #   level=debug msg="Migrating to newer Podman"
  #   level=debug msg="Migration not needed: running inside a container"
  #   level=debug msg="Setting up configuration"
  #   ...
  # --
  #

https://github.com/containers/toolbox/pull/1374
2023-09-22 18:24:54 +02:00
Debarshi Ray 6e5bffe9a0 test/system: Style fix
https://github.com/containers/toolbox/pull/1374
2023-09-22 18:24:50 +02:00
Debarshi Ray 0146d223d5 test/system: Make it easier to debug 'podman logs' failures
Bats' 'run' helper returns with an exit code of 0 even when the command
that it was given to run failed with a non-zero exit code [1].  This is
to enable making further assertions about the command after 'run' has
finished.  If there's nothing that checks for failures, then it will
continue as if everything is alright.

Therefore, currently, if 'podman logs' fails, there's no indication of
it and the test only fails later because it thinks that the container
failed to initialize:
  not ok 106 container: Check container starts without issues
  # (from function `assert_success' in file
       test/system/libs/bats-assert/src/assert.bash, line 114,
  #  in test file test/system/103-container.bats, line 39)
  #   `assert_success' failed
  #
  # -- command failed --
  # status : 1
  # output :
  # --
  #

Instead, from now on, it will be more obvious:
  not ok 106 container: Check container starts without issues
  # (from function `assert_success' in file
       test/system/libs/bats-assert/src/assert.bash, line 114,
  #  in test file test/system/103-container.bats, line 39)
  #   `assert_success' failed
  #
  # -- command failed --
  # status : 125
  # output (2 lines):
  #   Failed to invoke '/usr/bin/podman logs'
  #   Error: no container with name or ID "foo" found: no such container
  # --
  #

One alternative was to use 'assert_success' [2] to assert that the
command given to 'run' succeeded.  That would show the 'podman logs'
failure as:
  not ok 106 container: Check container starts without issues
  # (from function `assert_success' in file
       test/system/libs/bats-assert/src/assert.bash, line 114,
  #  in test file test/system/103-container.bats, line 39)
  #   `assert_success' failed
  #
  # -- command failed --
  # status : 1
  # output (29 lines):
  #
  #   -- command failed --
  #   status : 125
  #   output : Error: no container with name or ID "foo" found: no such
        container
  #   --
  #
  # ...
  #
  #   -- command failed --
  #   status : 125
  #   output : Error: no container with name or ID "foo" found: no such
        container
  #   --
  # --
  #

However, it's a bit too noisy because of the 'assert_success' not
terminating container_started() and continuing to loop for the remaining
attempts.

[1] https://bats-core.readthedocs.io/en/stable/writing-tests.html

[2] https://github.com/bats-core/bats-assert

https://github.com/containers/toolbox/pull/1372
2023-09-22 18:21:08 +02:00
Debarshi Ray a27b480cef test/system: Rename a variable
A subsequent commit will use this variable to set the return value for a
different condition.  Therefore, the name needs to be changed to suit
the purpose.

https://github.com/containers/toolbox/pull/1372
2023-09-22 18:21:08 +02:00
Debarshi Ray d3161ea60e test/system: Limit the scope of the return value to the function
This should prevent this function from overwriting variables of the
same name beyond the function and causing hard-to-debug problems.

https://github.com/containers/toolbox/pull/1372
2023-09-22 18:20:43 +02:00
Debarshi Ray 12da2b845f test/system: Limit the scope of the loop counters to the functions
This should prevent these functions from overwriting variables of the
same name beyond the function and causing hard-to-debug problems [1].

[1] Bats commit 502dc47dd063c187
    https://github.com/bats-core/bats-core/commit/502dc47dd063c187
    https://github.com/bats-core/bats-core/issues/726

https://github.com/containers/toolbox/pull/1373
2023-09-21 22:14:58 +02:00
Debarshi Ray 8f6e47a191 test/system: Avoid future problems caused by Bat's 'run' overwriting 'i'
Until Bats 1.10.0, 'run' with options had a bug where it would overwrite
the value of the 'i' variable even outside 'run' [1].

In these particular instances, no options are being passed to 'run',
and, hence, currently there's no problem.  However, in case a future
commit adds an option, then it could lead to hard-to-debug problems.
eg., --separate-stderr sets 'i' to 1, --show-output-of-passing-tests
sets it to 2, etc..  Therefore, depending on the flag and the loop, the
loop might get terminated prematurely or run infinitely or something
else.

Moreover, Bats 1.10.0 is only available in Fedora >= 39 and is absent
from Fedoras 37 and 38.  Therefore, it's not possible to consider this
bug fixed.

Hence, it's better to preemptively work around it to avoid any future
issues.

[1] Bats commit 502dc47dd063c187
    https://github.com/bats-core/bats-core/commit/502dc47dd063c187
    https://github.com/bats-core/bats-core/issues/726

https://github.com/containers/toolbox/pull/1373
2023-09-21 19:22:24 +02:00
Debarshi Ray c586cc9278 test/commit: Simplify a 'for' loop
An ascending 'for' loop is more idiomatic than its descending
counterpart.

https://github.com/containers/toolbox/pull/1373
2023-09-21 19:22:17 +02:00
Debarshi Ray 5c0372e959 test/system: Silence SC2034
Otherwise https://www.shellcheck.net/ would complain:
  Line 442:
  for TRIES in 1 2 3 4 5; do
  ^-^ SC2034 (warning): TRIES appears unused. Verify use (or export if
      used externally).

See: https://www.shellcheck.net/wiki/SC2034

This also makes the code consistent with the rest.

https://github.com/containers/toolbox/pull/1371
2023-09-20 15:16:50 +02:00
Debarshi Ray 7d24e98070 test/system: Silence SC2154
Otherwise https://www.shellcheck.net/ would complain:
  Line 33:
  assert [ ${#stderr_lines[@]} -eq 0 ]
           ^-----------------^ SC2154 (warning): stderr_lines is
                               referenced but not assigned.

See: https://www.shellcheck.net/wiki/SC2154

https://github.com/containers/toolbox/pull/1369
2023-09-20 01:33:29 +02:00
Debarshi Ray 74d2f2180d test/system: Silence SC1090
Otherwise https://www.shellcheck.net/ would complain:
  Line 505:
  . "$os_release"
    ^-----------^ SC1090 (warning): ShellCheck can't follow non-constant
                  source. Use a directive to specify location.

See: https://www.shellcheck.net/wiki/SC1090

https://github.com/containers/toolbox/pull/1368
2023-09-20 00:04:49 +02:00
Debarshi Ray 363c3f83ca test/system: Style fix
https://github.com/containers/toolbox/pull/1367
2023-09-19 23:40:42 +02:00
Debarshi Ray 5c6b566371 test/system: Use existing wrapper for 'podman start'
https://github.com/containers/toolbox/pull/1367
2023-09-19 23:40:36 +02:00
Debarshi Ray 3d14504e62 test/system: Simplify checking if the container started or not
Bats' 'run' helper is not necessary to merely check if a command
succeeded or not [1].  It also complicates using pipes to feed the
output of 'podman logs' into grep(1) [1].

In this case, it's idiomatic to pipe the 'output' directly to grep(1)
and use it as the condition for an 'if' branch.

[1] https://bats-core.readthedocs.io/en/stable/writing-tests.html

https://github.com/containers/toolbox/pull/1367
2023-09-19 19:46:28 +02:00
Debarshi Ray d6bcbc49dd test/system: Silence SC2046
Otherwise https://www.shellcheck.net/ would complain:
  Line 336:
  pull_distro_image $(get_system_id) $(get_system_version)
                    ^--------------^ SC2046 (warning): Quote this to
                                     prevent word splitting.

See: https://www.shellcheck.net/wiki/SC2046

https://github.com/containers/toolbox/pull/1366
2023-09-19 17:00:53 +02:00
Debarshi Ray 3c2adf57aa test/system: Silence SC2086
Otherwise https://www.shellcheck.net/ would complain:
  Line 28:
  run --separate-stderr $TOOLBOX --version
                        ^------^ SC2086 (info): Double quote to prevent
                                 globbing and word splitting.

See: https://www.shellcheck.net/wiki/SC2086

https://github.com/containers/toolbox/pull/1365
2023-09-19 14:29:17 +02:00
Debarshi Ray fd7ca125fc test/system: Replace the shebangs with 'shell' directives
These files aren't marked as executable, and shouldn't be, because they
aren't meant to be standalone executable scripts.  They're meant to be
part of a test suite driven by Bats.  Therefore, it doesn't make sense
for them to have shebangs, because it gives the opposite impression.

The shebangs were actually being used by external tools like Coverity to
deduce the shell when running shellcheck(1).  Shellcheck's inline
'shell' directive is a more obvious way to achieve that.

https://github.com/containers/toolbox/pull/1363
2023-09-14 15:18:04 +02:00
Debarshi Ray a055e78d42 test/system: Silence SC2004
Otherwise https://www.shellcheck.net/ would complain
  Line 110:
  for ((i = ${num_of_retries}; i > 0; i--)); do
            ^---------------^ SC2004 (style): $/${} is unnecessary on
                              arithmetic variables.

See: https://www.shellcheck.net/wiki/SC2004

https://github.com/containers/toolbox/pull/1347
2023-08-11 17:21:55 +02:00
Debarshi Ray 341ae55f9d test/system: Avoid conditionals only supported by Bash's built-in 'test'
The '[' and 'test' implementations from GNU coreutils don't support '-v'
as a way to check if a shell variable is set [1].  Only Bash's built-in
implementations do.

This is quite confusing and makes it difficult to find out what '-v'
actually does.  eg., 'man --all test' only shows the manual for the GNU
coreutils version, which doesn't list '-v' [1], and, 'man --all [' only
shows the manual for Bash's built-ins, which also doesn't list '-v'.
One has to go to the bash(1) manual to find it [2].

Elsewhere in the code base [3], the same thing is accomplished with '-z'
and parameter substitution, which are more widely supported and, hence,
easier to find documentation for.

[1] https://manpages.debian.org/testing/coreutils/test.1.en.html

[2] https://linux.die.net/man/1/bash

[3] Commit 84ae385f33
    https://github.com/containers/toolbox/pull/1334

https://github.com/containers/toolbox/pull/1341
2023-07-14 00:17:48 +02:00
Debarshi Ray 21299a3c5b test/system: Fix typos in conditional expressions
'[' is a command that's the same as 'test' and they might be implemented
as standalone executables or shell built-ins.  Therefore, the negation
(ie., '!') has to cover the entire command to operate on its exit code.
Instead, if it's writtten as '[ ! ... ]', then the negation becomes an
argument to '[', which isn't the same thing.

Fallout from 54a2ca1ead

https://github.com/containers/toolbox/pull/1341
2023-07-14 00:17:02 +02:00
Debarshi Ray db9a906b50 test/system: Simplify the check for Fedora Rawhide
First, it's not a good idea to use awk(1) as a grep(1) replacement.
Unless one really needs the AWK programming language, it's better to
stick to grep(1) because it's simpler.

Secondly, it's better to look for a specific os-release(5) field instead
of looking for the occurrence of 'rawhide' anywhere in the file, because
it lowers the possibility of false positives.

https://github.com/containers/toolbox/pull/1332
2023-07-04 18:20:59 +02:00
Debarshi Ray ea91335ebb test/system: Limit the scope of temporary files used by a single test
BATS_TMPDIR is the base directory used by Bats for all temporary files
and directories, and BATS_TEST_TMPDIR is unique to each test [1].  It's
better to limit the scope of the tests' temporary files as much as
possible to avoid unexpected collisions with Bats' own internal
temporary files.

[1] https://bats-core.readthedocs.io/en/stable/writing-tests.html

https://github.com/containers/toolbox/pull/1327
2023-06-30 20:45:48 +02:00
Debarshi Ray 4322824061 test/system: Fix reading the os-release(5) VERSION_ID on Ubuntu
The current approach of extracting the VERSION_ID field from
os-release(5) assumes that the value is not quoted.  There's no
guarantee that this will be the case.  It only happens to be so on
Fedora by chance, and is different on Ubuntu:
  $ cat /etc/os-release
  ...
  VERSION_ID="22.04"
  ...

This means that "22.04", including the double quotes, is read as the
value of VERSION_ID on Ubuntu, not 22.04.  This is wrong because this
value can't be used as is in image and container names.  There's no
image called quay.io/toolbx/ubuntu-toolbox:"22.04" and double quotes are
not allowed in container names.

Instead, use the same approach as profile.d/toolbox.sh and the old POSIX
shell implementation that doesn't rely on the quoting of the
os-release(5) values.

Fallout from b27795a03e

https://github.com/containers/toolbox/pull/1320
2023-06-23 13:58:42 +02:00
Debarshi Ray 62c31ca8ea test/system: Fix reading the os-release(5) ID on Ubuntu
The current approach of selecting all the os-release(5) fields that have
'ID' in their name (eg., ID, VERSION_ID, PLATFORM_ID, VARIANT_ID, etc.)
and then picking the first one, assumes that the ID field will always be
placed above the others in os-release(5).  There's no guarantee that
this will be the case.  It only happens to be so on Fedora by chance,
and is different on Ubuntu:
  $ cat /etc/os-release
  ...
  VERSION_ID="22.04"
  ...
  ID=ubuntu
  ID_LIKE=debian
  ...

This means that "22.04" is read as the value of ID on Ubuntu, which is
clearly wrong.

Instead, use the same approach as profile.d/toolbox.sh and the old POSIX
shell implementation that doesn't rely on the order of the os-release(5)
fields.

Fallout from 54a2ca1ead

https://github.com/containers/toolbox/pull/1320
2023-06-23 13:27:07 +02:00
Debarshi Ray 2ee82affeb pkg/utils: Offer built-in support for Arch Linux
This allows using the 'distro' option to create and enter Arch Linux
containers.  Due to Arch's rolling-release model, the 'release' option
isn't required.  If 'release' is used, the accepted values are 'latest'
and 'rolling'.

https://github.com/containers/toolbox/pull/1311
2023-06-12 22:26:46 +02:00
Debarshi Ray b6ca18ead1 pkg/utils, test/system: Use the Ubuntu images from quay.io/toolbx/...
https://github.com/containers/toolbox/pull/1306
2023-06-08 15:35:44 +02:00
Ievgen Popovych a84a358b3b pkg/utils, test/system: Offer built-in support for Ubuntu
This allows using the --distro and --release options to create and enter
Ubuntu containers.

Note that Ubuntu 4.10 was the first ever Ubuntu release [1].  Hence,
values older than that are not permitted for the --release option.

Some changes by Debarshi Ray.

[1] https://wiki.ubuntu.com/Releases

https://github.com/containers/toolbox/pull/483
https://github.com/containers/toolbox/pull/1284

Signed-off-by: Ievgen Popovych <jmennius@gmail.com>
2023-03-28 00:14:19 +02:00
Debarshi Ray 44cbdb1f18 test/system: Ensure that both non-Toolbx containers & images are skipped
https://github.com/containers/toolbox/pull/1273
2023-03-22 12:05:06 +01:00
Debarshi Ray 052666840a Fix spelling mistakes
The noun is 'setup' and the verb is 'set up'.  Similarly 'lookup' and
'look up'.

Original patch from Erik Sjölund for Podman [1,2].

[1] Podman commit aa4279ae151fa9df
    https://github.com/containers/podman/commit/aa4279ae151fa9df
    https://github.com/containers/podman/pull/14658

[2] Podman commit 2827140907255ed0
    https://github.com/containers/podman/commit/2827140907255ed0
    https://github.com/containers/podman/pull/14659

https://github.com/containers/toolbox/pull/1223
2023-01-31 15:53:15 +01:00