Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test volume idempotency with unittests #556

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

sshnaidm
Copy link
Member

No description provided.

Andrew and others added 8 commits March 28, 2024 13:17
This is a fix for bug containers#355.

This compares the arguments podman recieved for the currently existing
container with the (effective) arguments to come.

This approach was taken over parsing Mounts from inspect because:

1. This line from https://github.com/containers/podman/blob/e084f0ee1e1ded564110e84eefca9f18b5669adf/libpod/container_inspect.go#L224
   regarding inspect's Mount value:

   "Only includes user-specified mounts. Only includes bind mounts and named volumes, not tmpfs volumes."

   Thus an incomplete solution would result.

2. The code required to parse so that it could be compared with the
   stuff to come was getting silly-level complex.

3. Anonymous volumes were impossible to decipher as both Name and
   Source are filled in with the podman-generated values.

Thus we compare the arguments podman create was run with to make the
existing container with the closest values to those arguments in the
new config.

This resulted in simpler code that takes care of the issue of anonymous
volumes.

The downside is that if someone moves, say, a tmpfs from mount to tmpfs
(or vice versa) that would reult in exactly the same result this will
be considered a different config. This can (possibly) be fixed if and
when it becomes an actual issue.

Signed-off-by: Andrew <rubiksdot@grue.cc>
The old code removed unnecessary slashes via the _clean_volume()
function. I accidentally got rid of it and have re-introduced it
here as self._clean_path().

The rename is because it is used outside of mere check of volumes
but the internal code is as before.

Signed-off-by: Andrew <rubiksdot@grue.cc>
Began sorting in self._clean_path_in_mount_str() as an early
defense against ordering of mount arguments changing. This steels
against false comparison errors later.

Fixed lots of embarrassing string in list context errors. Oops! :(

Signed-off-by: Andrew <rubiksdot@grue.cc>
Made _clean_path() squash multiple consecutive slashes into one as
3+ slashes are just as meaningful as 1.

Slash handling is now done properly diffparam_volume().

Signed-off-by: Andrew <rubiksdot@grue.cc>
Combine diffparam_mount(), diffparam_tmpfs() and diffparam_volume()
and add handling of VOLUME into one function that allows for movement
of definitions between the various ways of specifying mount points
as long as the options are equivalent.

This necessitated translations of the various ways of defining
mount points into one single "language" so that the definitions
may be compared and checked for similarity. prep_mount_args_for_comp()
does this work and includes within it the default options for the
various CLI arguments and VOLUME.

The consequence of this is that the diff returned by the function
no longer literally represents the real-life arguments passed but,
rather, the translations of those arguments.

Signed-off-by: Andrew <rubiksdot@grue.cc>
Fixes:

ERROR: Found 7 pylint issue(s) which need to be resolved:
ERROR: plugins/module_utils/podman/podman_container_lib.py:1288:37: ansible-format-automatic-specification: Format string contains automatic field numbering specification
...
ERROR: plugins/module_utils/podman/podman_container_lib.py:1400:27: ansible-format-automatic-specification: Format string contains automatic field numbering specification

also:

File "/tmp/ansible_containers.podman.podman_container_payload_6atuqv63/ansible_containers.podman.podman_container_payload.zip/ansible_collections/containers/podman/plugins/module_utils/podman/podman_container_lib.py", line 1405, in diffparam_volumes_all
KeyError: 'config'

Signed-off-by: Andrew <rubiksdot@grue.cc>
Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant