Skip to content

System tests refactor - #517

Merged
debarshiray merged 4 commits into
containers:masterfrom
juanje:system-tests-refactor
Feb 19, 2021
Merged

debarshiray merged 4 commits into
containers:masterfrom
juanje:system-tests-refactor

Conversation

@juanje

@juanje juanje commented Jul 27, 2020

Copy link
Copy Markdown
Contributor

I'd like to propose a refactor of the system's tests. The main reason is that the tests have dependencies between them and with external conditions. By definition, tests should be able to work isolated and without any order or dependency.

Also, I think that using very common libraries for BATS as bats-support and bats-assert might make the tests more explicit and easy to maintain (and to contribute).

The helper was a bit complex for this project. It might fix a more complex project like libpod, but I think here makes less sense and make it harder to debug.

I implemented the same tests, but using some extra asserts (mostly for exit codes) and a couple of tests more. If you like the tests, I'd like to add some more.

The README.md and the Ansible playbooks are updated as well, but it can be improved.

There are also some notes because I found some possible bugs or improvements (at Toolbox) while I was writing the tests.

@softwarefactory-delete-me

Copy link
Copy Markdown

Build failed.

@juanje

juanje commented Jul 27, 2020

Copy link
Copy Markdown
Contributor Author

Some tests have failed due the inconsistency of the registry (or the network), I need to work on that to make it more reliable.
I was looking for ways to mock the repository and use local images, so it doesn't rely on the network.

Pull the images first (in some tests) is an option, but then it doesn't test the toolbox's mechanism to pull the images the first time or when is asked for an image that is not been pulled yet.

@softwarefactory-delete-me

Copy link
Copy Markdown

Build failed.

@softwarefactory-delete-me

Copy link
Copy Markdown

Build failed.

@softwarefactory-delete-me

Copy link
Copy Markdown

Build failed.

@juanje

juanje commented Jul 28, 2020

Copy link
Copy Markdown
Contributor Author

I added some helpers for pulling the images before using them on tests, but the registry is failing a lot today 😞
Some errors 503 from the server and errors like this one:

Trying to pull registry.fedoraproject.org/f33/fedora-toolbox:33...
Getting image source signatures
Copying blob sha256:e159cba4da71e8f92486a69703e5c387b05070a1d06adfce03f2ae1dc50721b8
Copying blob sha256:782585b12f5b57ac30c39f43740dffcba7e28e9482e8a2c75a5e81547b925ebd
  unexpected EOF
Error: unable to pull registry.fedoraproject.org/f33/fedora-toolbox:33: Error writing blob: error storing blob to file "/var/tmp/storage649780343/2": unexpected EOF

@martymichal

Copy link
Copy Markdown
Member

Hi @juanje! Thank you for working on this. Much appreciated!

I added some helpers for pulling the images before using them on tests, but the registry is failing a lot today disappointed
Some errors 503 from the server and errors like this one:

Trying to pull registry.fedoraproject.org/f33/fedora-toolbox:33...
Getting image source signatures
Copying blob sha256:e159cba4da71e8f92486a69703e5c387b05070a1d06adfce03f2ae1dc50721b8
Copying blob sha256:782585b12f5b57ac30c39f43740dffcba7e28e9482e8a2c75a5e81547b925ebd
  unexpected EOF
Error: unable to pull registry.fedoraproject.org/f33/fedora-toolbox:33: Error writing blob: error storing blob to file "/var/tmp/storage649780343/2": unexpected EOF

Yes, the 503 errors were my main motivation to make the tests depend on each other because pulling from registry.fedoraproject.org is very unreliable and causes the CI to flake a lot. I think we should contact the registry's maintainers and try to solve this as this is an long-going issue.

Pull the images first (in some tests) is an option, but then it doesn't test the toolbox's mechanism to pull the images the first
time or when is asked for an image that is not been pulled yet.

I'm perfectly fine with adding a helper function for pulling the images. Toolbox's image pulling mechanism is simply a wrapper around the podman pull command. It is not Toolbox's (or Podman's) fault that registry.fedoraproject.org is unreliable.

Also, I think that using very common libraries for BATS as bats-support and bats-assert might make the tests more explicit
and easy to maintain (and to contribute).

Definitely, yes! I'm aware of those libraries but I was hesitant to use those because they are not packaged in Fedora (just the original bats from which bats-core and family were forked.

I implemented the same tests, but using some extra asserts (mostly for exit codes) and a couple of tests more. If you like
the tests, I'd like to add some more.

I'd love to see more tests but first we need to figure out solutions for some of the problems we're facing now (unreliable registry, #410 - this one might be solved thanks to your update).

Also, in the future, we'd like to hook up Toolbox's tests with Podman's. We still have to discuss this matter with Podman developers to get more info about this, though.

Again, thank you for working on this!

@softwarefactory-delete-me

Copy link
Copy Markdown

Build succeeded.

@juanje

juanje commented Jul 28, 2020

Copy link
Copy Markdown
Contributor Author

Hi @juanje! Thank you for working on this. Much appreciated!

Thanks to you, for all the good work you're putting here. I use Toolbox a lot since I installed Silverblue a month ago or so, and I love it 🥰
I'd love to help to make it more robust and useful. Maybe I can't help (yet) much with the Go part, but anything else can help, I will.

Yes, the 503 errors were my main motivation to make the tests depend on each other because pulling from registry.fedoraproject.org is very unreliable and causes the CI to flake a lot. I think we should contact the registry's maintainers and try to solve this as this is an long-going issue.

I was thinking abut this. I saw it failing now and then with Podman or Buildah, I guess is a known issue, but it must be affecting a lot of people.

I'm perfectly fine with adding a helper function for pulling the images. Toolbox's image pulling mechanism is simply a wrapper around the podman pull command. It is not Toolbox's (or Podman's) fault that registry.fedoraproject.org is unreliable.

That's right.
I tried to let Toolbox to pull internally the images just at the tests where we really want to test that functionality (e.g., toolbox create when there is not toolbox's image downloaded) and call the helper function for the rest.

I'd love to see more tests but first we need to figure out solutions for some of the problems we're facing now (unreliable registry, #410 - this one might be solved thanks to your update).

I got all the tests working (the registry issue might give some problems, but I think now is more resilient), I'd like to see your thoughts about them (when you have time).
If you like them but have some critics, improvements or anything, just tell me and I'll adjust them.

I add some asserts for the exit status of the commands, to make sure it was the right one. Actually, I found some cases where (I think) toolbox should return an exit code 1 (when a command fails), but it returns 0. I commented this at the tests, so I don't forget but let the tests have similar behavior to the current tests.

For the tests and helper functions I tried to follow this Shell Style Guide and use ShellCheck, so the code is clear, consistent and easy maintain. But if you prefer another style, I can adapt it.

Also, in the future, we'd like to hook up Toolbox's tests with Podman's. We still have to discuss this matter with Podman developers to get more info about this, though.

Again, thank you for working on this!

Thanks to you @HarryMichal for take the time to review this and reply 😄

@martymichal martymichal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just quickly went through this, did not even run the tests locally or in a VM. I pointed out a few things that caught my attention.

I'll do a follow-up review in the future.

Comment thread test/system/README.md Resolved
Comment thread test/system/rmi.bats Resolved
Comment thread test/system/run.bats Resolved
Comment thread test/system/version.bats Resolved
@softwarefactory-delete-me

Copy link
Copy Markdown

Build failed.

@softwarefactory-delete-me

Copy link
Copy Markdown

Build succeeded.

@juanje
juanje marked this pull request as draft August 1, 2020 18:36
@softwarefactory-delete-me

Copy link
Copy Markdown

Build failed.

@softwarefactory-delete-me

Copy link
Copy Markdown

Build failed.

@juanje
juanje force-pushed the system-tests-refactor branch from 453638e to 1e6b5ac Compare August 10, 2020 18:17
@softwarefactory-delete-me

Copy link
Copy Markdown

Build failed.

@juanje
juanje force-pushed the system-tests-refactor branch from 1e6b5ac to 2b5bf11 Compare August 10, 2020 18:29
@softwarefactory-delete-me

Copy link
Copy Markdown

Build failed.

@juanje
juanje force-pushed the system-tests-refactor branch from 2b5bf11 to 9769d43 Compare August 10, 2020 18:41
@softwarefactory-delete-me

Copy link
Copy Markdown

Build failed.

@softwarefactory-delete-me

Copy link
Copy Markdown

Build succeeded.

@softwarefactory-delete-me

Copy link
Copy Markdown

Build succeeded.

@juanje
juanje force-pushed the system-tests-refactor branch 2 times, most recently from 03e9a66 to 17d880f Compare August 10, 2020 19:58
@softwarefactory-delete-me

Copy link
Copy Markdown

Build succeeded.

@juanje
juanje marked this pull request as ready for review August 10, 2020 20:05
@juanje
juanje requested a review from martymichal August 10, 2020 20:06
@juanje

juanje commented Aug 10, 2020 •

Copy link
Copy Markdown
Contributor Author

Hi @HarryMichal,

I've been working on some of the feedback you gave me. Also, I did some more changes:

  • Refactorized the Ansible playbooks as well. The playbooks were identical (almost) and can be unified.
  • Added some tasks for mock the toolbox images and fine tune some current tasks.
  • Used Skopeo to create a local copy of the images, so they only get pulled once. Then (at the tests) used again skopeo to restore the images (once deleted), so we don't depend on the reliability of the servers.
  • Modified a bit the test's convention and I change all the titles to follow the convention.
  • Moved the test for the version command to a non-existent command.

There are also more minor changes, improvements and a couple the tests more.
For example, a test for the issue #523. I skip it because it was failing and I wanted to get the test working and merged before add test for current bugs, but I didn't want to forget about the issue.
Also, I added several assertions to some existing tests to make them more robust.

Now there are 27 test and look like this:

 ✓ create: Try to create the default container
 ✓ create: Try to create a container with a valid custom name ('not-running')
 ✓ create: Try to create a container with a custom image and name ('running';f29)
 ✓ create: Try to create a container with invalid custom name (it should fail)
 ✓ help: Try to run toolbox with no command (it should fail and show usage screen)
 ✓ help: Try command 'help' (it should show usage screen)
 ✓ help: Try flag '--help' (it should show usage screen)
 ✓ help: Try non-existent command (it should fail and show the usage screen)
 ✓ list: Try to run 'list' with zero containers and zero images (the list should be empty)
 ✓ list: Try to list the containers (-c flag) with zero containers (the list should be empty)
 ✓ list: Try to list the images (-i flag) with zero images (the list should be empty)
 ✓ list: Try to list images and containers (no flag) with zero toolbox's containers and images, but other image (the list should be empty)
 ✓ list: Try to list images and containers (no flag) with 3 containers and 2 images (the list should have 3 images and 2 containers)
 ✓ rm: Try to remove a non-existent container (it should fail)
 ✓ rm: Try to remove a running container named 'running' (it should fail)
 ✓ rm: Try to remove a not running container named 'not-running'
 ✓ rm: Try to force remove the running container 'running'
 ✓ rm: Try to force remove all remaining containers (with 2 containers created and 1 running)
 ✓ rmi: Try to remove all images with the default image present
 - rmi: Try to remove all images with the default image present and running (it should fail) (skipped: The implementation need some fixes)
 ✓ rmi: Try to remove all images with the default image present and running (with flag --force)
 ✓ run: Try to run echo 'Hello World' with no containers created (it should fail)
 ✓ run: Try to run echo 'Hello World' inside of the default container
 ✓ run: Try to run echo 'Hello World' inside of the 'running' container
 ✓ run: Try to run echo 'Hello World' again in the 'running' container after being stopped and exit
 - run: Try to run sudo (with no passowrd) inside of the default container (skipped: This is a new test and fails due a bug: #523)
 ✓ version: Try flag --version (it should show the version number)

27 tests, 0 failures, 2 skipped

Now they all follow the convention and I think the prefix (the command tested) helps to see quickly what fails or succeeds.
Due the mock images, the tests are faster. Even that now the images and containers get clean up more, to isolate better the tests.
Now the tests can be run in any order or to run just one.

Sorry for give you this amount of changes, I know that maybe is too much for review 😞
Anyway, thanks for your time.

@martymichal martymichal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I perused the list of changes and found a few things that either need to be changed or discussed. Overall, I like where the PR has gotten and I'm confident this could get merged in the future.

Few more notes:

  • I'd probably keep the numbering for the test files (e.g. instead of create.bats keep it 102-create.bats). It gives the power to change the order in which the tests are executed while currently they are executed alphabetically.
  • I noticed you removed helpers.bats because you started relying on bats-support + bats-assert. That is definitely fine but I think that file will probably have to stay (even though the content will be different). The reason is that currently, the smart use of Skopeo to cache the images is done purely by Zuul but I think the tests will have to use some helper functions at least in that regard because the tests will most likely be run in different environments. I still need to examine this area more, so this is not exactly a very strong point now :).

Thank you for your continuous work on this! I'll try to check this out on my machine and play with it a bit.

Comment thread .gitignore Resolved
Comment thread playbooks/setup-env.yaml Resolved
Comment thread playbooks/setup-env.yaml Resolved
Comment thread test/system/README.md Resolved
Comment thread test/system/README.md Resolved
Comment thread test/system/README.md Resolved
@debarshiray

Copy link
Copy Markdown
Member

The rebase against current master was a bit more involved than I expected. Given my general lack of Ansible skills, I split things up a bit into smaller PRs to be sure that I didn't mess something up:

debarshiray pushed a commit to debarshiray/toolbox that referenced this pull request Feb 19, 2021
Since commit b27795a, each section of the test suite starts
and ends with a clean Podman state. This includes removing all images
from the local containers storage. Therefore, the images get downloaded
multiple times during the course of the test suite.

This commit restores the earlier behaviour where the images would get
downloaded only once, by copying them to separate directories outside
the local containers storage and then restoring them when the tests
are run.

containers#517
debarshiray pushed a commit to debarshiray/toolbox that referenced this pull request Feb 19, 2021
Since commit b27795a, each section of the test suite starts
and ends with a clean Podman state. This includes removing all images
from the local containers storage. Therefore, the images get downloaded
multiple times during the course of the test suite.

This commit restores the earlier behaviour where the images would get
downloaded only once, by copying them to separate directories outside
the local containers storage and then restoring them when the tests
are run.

containers#517
containers#704
debarshiray pushed a commit to debarshiray/toolbox that referenced this pull request Feb 19, 2021
Since commit b27795a, each section of the test suite starts
and ends with a clean Podman state. This includes removing all images
from the local containers storage. Therefore, the images get downloaded
multiple times during the course of the test suite.

This commit restores the earlier behaviour where the images would get
downloaded only once, by copying them to separate directories outside
the local containers storage and then restoring them when the tests
are run.

containers#517
containers#704
debarshiray pushed a commit to debarshiray/toolbox that referenced this pull request Feb 19, 2021
Since commit b27795a, each section of the test suite starts
and ends with a clean Podman state. This includes removing all images
from the local containers storage. Therefore, the images get downloaded
multiple times during the course of the test suite.

This commit restores the earlier behaviour where the images would get
downloaded only once, by copying them to separate directories outside
the local containers storage and then restoring them when the tests
are run.

containers#517
containers#704
@debarshiray
debarshiray force-pushed the system-tests-refactor branch from 77dc92f to 05c9c06 Compare February 19, 2021 19:47
@debarshiray

Copy link
Copy Markdown
Member

recheck

@softwarefactory-delete-me

Copy link
Copy Markdown

Build failed.

@debarshiray

Copy link
Copy Markdown
Member

recheck

@softwarefactory-delete-me

Copy link
Copy Markdown

Build failed.

@debarshiray
debarshiray merged commit 05c9c06 into containers:master Feb 19, 2021
@debarshiray

Copy link
Copy Markdown
Member

Thanks for all the work on this, @juanje & @HarryMichal ! Much appreciated.

@martymichal

Copy link
Copy Markdown
Member

All the glory goes to @juanje. He did an amazing job! 🎉

@juanje

juanje commented Feb 19, 2021

Copy link
Copy Markdown
Contributor Author

Thanks to both @debarshiray and @HarryMichal for letting me contribute my grain of sand to this project. You're doing a great job!
I'll try to help any way I can to the project. I'll be happy to add more test to improve the coverage or keep the current ones updated now that this is been merged 😄

I think this project is great for developers and for normal users that like the terminal.

martymichal added a commit to martymichal/toolbox that referenced this pull request May 26, 2021
Since the rewrite of the system test suite[0] we've relied on the Zuul
playbooks for taking care of caching images using Skopeo for increasing
the reliability of the tests (in the past the instability of the Fedora
registry caused problems). This state is problematic if we want to use
the tests in other environments than the Zuul CI. This moves the caching
from Zuul into the system tests.

Currently, Bats does not support officially suite-wide setup and
teardown functions. The solution I chose was to add two new test files
that are executed before and after all tests. This may complicate the
execution of cherry-picked tests but that is not a very common use case
anyway.

The tests are now to some extent capable of adjusting to the host
environment. This is meant in the sense of: I'm running on RHEL, the
"default image" is UBI; I'm running on Fedora, the "default image" is
fedora-toolbox. This mechanism relies on os-release, which is the same
as what Toolbox itself uses.

Along the road I chose to update the f29/fedora-toolbox:29 image to the
fedora-toolbox:32 image because I did not want to maintain two versions
of images (the name changed some time ago[1]). I also introduced or
modified a number of helper functions to make better use of the caching
and default system recognition.

[0] containers#517
[1] containers#615
martymichal added a commit to martymichal/toolbox that referenced this pull request May 26, 2021
Since the rewrite of the system test suite[0] we've relied on the Zuul
playbooks for taking care of caching images using Skopeo for increasing
the reliability of the tests (in the past the instability of the Fedora
registry caused problems). This state is problematic if we want to use
the tests in other environments than the Zuul CI. This moves the caching
from Zuul into the system tests.

Currently, Bats does not support officially suite-wide setup and
teardown functions. The solution I chose was to add two new test files
that are executed before and after all tests. This may complicate the
execution of cherry-picked tests but that is not a very common use case
anyway.

The tests are now to some extent capable of adjusting to the host
environment. This is meant in the sense of: I'm running on RHEL, the
"default image" is UBI; I'm running on Fedora, the "default image" is
fedora-toolbox. This mechanism relies on os-release, which is the same
as what Toolbox itself uses.

Along the road I chose to update the f29/fedora-toolbox:29 image to the
fedora-toolbox:32 image because I did not want to maintain two versions
of images (the name changed some time ago[1]). I also introduced or
modified a number of helper functions to make better use of the caching
and default system recognition.

[0] containers#517
[1] containers#615
martymichal added a commit to martymichal/toolbox that referenced this pull request May 26, 2021
Since the rewrite of the system test suite[0] we've relied on the Zuul
playbooks for taking care of caching images using Skopeo for increasing
the reliability of the tests (in the past the instability of the Fedora
registry caused problems). This state is problematic if we want to use
the tests in other environments than the Zuul CI. This moves the caching
from Zuul into the system tests.

Currently, Bats does not support officially suite-wide setup and
teardown functions. The solution I chose was to add two new test files
that are executed before and after all tests. This may complicate the
execution of cherry-picked tests but that is not a very common use case
anyway.

The tests are now to some extent capable of adjusting to the host
environment. This is meant in the sense of: I'm running on RHEL, the
"default image" is UBI; I'm running on Fedora, the "default image" is
fedora-toolbox. This mechanism relies on os-release, which is the same
as what Toolbox itself uses.

Along the road I chose to update the f29/fedora-toolbox:29 image to the
fedora-toolbox:32 image because I did not want to maintain two versions
of images (the name changed some time ago[1]). I also introduced or
modified a number of helper functions to make better use of the caching
and default system recognition.

[0] containers#517
[1] containers#615
martymichal added a commit to martymichal/toolbox that referenced this pull request May 31, 2021
Since the rewrite of the system test suite[0] we've relied on the Zuul
playbooks for taking care of caching images using Skopeo for increasing
the reliability of the tests (in the past the instability of the Fedora
registry caused problems). This state is problematic if we want to use
the tests in other environments than the Zuul CI. This moves the caching
from Zuul into the system tests.

Currently, Bats does not support officially suite-wide setup and
teardown functions. The solution I chose was to add two new test files
that are executed before and after all tests. This may complicate the
execution of cherry-picked tests but that is not a very common use case
anyway.

The tests are now to some extent capable of adjusting to the host
environment. This is meant in the sense of: I'm running on RHEL, the
"default image" is UBI; I'm running on Fedora, the "default image" is
fedora-toolbox. This mechanism relies on os-release, which is the same
as what Toolbox itself uses.

Along the road I chose to update the f29/fedora-toolbox:29 image to the
fedora-toolbox:32 image because I did not want to maintain two versions
of images (the name changed some time ago[1]). I also introduced or
modified a number of helper functions to make better use of the caching
and default system recognition.

[0] containers#517
[1] containers#615

containers#774
martymichal added a commit to martymichal/toolbox that referenced this pull request May 31, 2021
Since the rewrite of the system test suite[0] we've relied on the Zuul
playbooks for taking care of caching images using Skopeo for increasing
the reliability of the tests (in the past the instability of the Fedora
registry caused problems). This state is problematic if we want to use
the tests in other environments than the Zuul CI. This moves the caching
from Zuul into the system tests.

Currently, Bats does not support officially suite-wide setup and
teardown functions. The solution I chose was to add two new test files
that are executed before and after all tests. This may complicate the
execution of cherry-picked tests but that is not a very common use case
anyway.

The tests are now to some extent capable of adjusting to the host
environment. This is meant in the sense of: I'm running on RHEL, the
"default image" is UBI; I'm running on Fedora, the "default image" is
fedora-toolbox. This mechanism relies on os-release, which is the same
as what Toolbox itself uses.

[0] containers#517

containers#774
martymichal added a commit that referenced this pull request May 31, 2021
Since the rewrite of the system test suite[0] we've relied on the Zuul
playbooks for taking care of caching images using Skopeo for increasing
the reliability of the tests (in the past the instability of the Fedora
registry caused problems). This state is problematic if we want to use
the tests in other environments than the Zuul CI. This moves the caching
from Zuul into the system tests.

Currently, Bats does not support officially suite-wide setup and
teardown functions. The solution I chose was to add two new test files
that are executed before and after all tests. This may complicate the
execution of cherry-picked tests but that is not a very common use case
anyway.

The tests are now to some extent capable of adjusting to the host
environment. This is meant in the sense of: I'm running on RHEL, the
"default image" is UBI; I'm running on Fedora, the "default image" is
fedora-toolbox. This mechanism relies on os-release, which is the same
as what Toolbox itself uses.

[0] #517

#774
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2. CI Automation of testing, analysis and other actions 3. Enhancement Improvement to an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants