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

Refactor Podman E2E helpers to allow passing/adding more options to the low-level executor #25097

Merged
merged 8 commits into from
Jan 23, 2025

Conversation

mtrmac
Copy link
Collaborator

@mtrmac mtrmac commented Jan 22, 2025

This, primarily, replaces PodmanAsUserBase (called with 9 parameters) with PodmanExecBaseWithOptions called with PodmanExecOptions, where the caller can only specify the relevant options, and by name; and it threads PodmanExecOptions through the call stack, so that E2E tests can set these options directly.

This simplifies the call stack and eliminates the need for various helpers. My primary motivation is that, for #25007 (comment) , I want to add a “do not log Podman output to the Ginkgo log” option, and this will allow doing that without adding a one more (unnamed) boolean parameter, or perhaps a new set of helpers, throughout the call stack.

Tests can now, in addition to Podman(), call PodmanWithOptions(), and also (following the theme of #24977 ), PodmanExitCleanlyWithOptions.

And, in the future, maybe PodmanExecOptions could be extended with an expected exit code, or perhaps even an expected log output, making the test invocation even more declarative — but that’s not this PR.


Warning: I don’t fully understand the current code.

  • I don’t know why the remote code manually calls makeOptions when the non-remote code relies on setting the PodmanMakeOptions upcall (which also seems to be involved in the remote code?)
  • I don’t know why various helpers in common_test.go and in test/utils/utils.go bypass the difference above (e.g. don’t call .Podman(), and call PodmanAsUserBase directly and perhaps directly construct a PodmanSessionIntegration

There is quite likely a deeper logic to this which I couldn’t figure out. Or maybe these are just inconsistencies accrued over time with copy&paste. This PR is intended to be a refactoring with no change to how tests operate; it doesn’t have the ambition to clean these questions up.

Does this PR introduce a user-facing change?

None

... replacing the many parameters with a struct with named fields.

This makes the meaning of parameters more explicit, and more importantly
it makes it easier to just edit _one_ of the parameters without requiring
specialized wrappers for every single case.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
This will make it easier to structure the API, at the cost
of making it a bit more opaque about which parts of PodmanExecOptions
are implemented where.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Eliminate this helper / indirection, and pass around
PodmanExecOptions explicitly.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Pass exactly the same PodmanExecOptions to makeOptions
and to PodmanExecBaseWithOptions.  This will allow
simplifying the code further.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
... and, to an extent, centralize the PodmanSessionIntegration
creation in that function.

This reduces duplication, and we will further eliminate
some of the callers.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Instaed, inline the implementation into callers, calling
PodmanWithOptions directly, demonstrating how to use
PodmanWithOptions.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
@openshift-ci openshift-ci bot added release-note-none approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Jan 22, 2025
}

// PodmanExecBaseWithOptions execs podman with the specified args, and in an environment defined by options
func (p *PodmanTest) PodmanExecBaseWithOptions(args []string, options PodmanExecOptions) *PodmanSession {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This name is fairly ridiculous … I considered reusing the now-available PodmanBase name, but I left it as is because it seems to me that most users should call something higher-level, and a long tedious name is a bit of a hint to use something else.

Copy link
Member

Choose a reason for hiding this comment

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

it is a test suite, fine by me.

@mtrmac
Copy link
Collaborator Author

mtrmac commented Jan 22, 2025

See individual commits for details — that’s probably a more convenient way to review.

It seems this utility is not all that generally useful,
so eliminate it from the global namespace and use
PodmanWithOptions directly.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
This is a generalization of PodmanExitCleanly, scalable
to an arbitrary number of possible options.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
@baude
Copy link
Member

baude commented Jan 23, 2025

lgtm thanks @mtrmac

Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

LGTM

This looks nice but I guess we really need to start add documentation on how to write new tests, i.e. especially around the use of ...ExitCleanly()

Copy link
Contributor

openshift-ci bot commented Jan 23, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Luap99, mtrmac

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@Luap99
Copy link
Member

Luap99 commented Jan 23, 2025

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jan 23, 2025
@openshift-merge-bot openshift-merge-bot bot merged commit c8fc73e into containers:main Jan 23, 2025
56 checks passed
@mtrmac
Copy link
Collaborator Author

mtrmac commented Jan 23, 2025

This looks nice but I guess we really need to start add documentation on how to write new tests, i.e. especially around the use of ...ExitCleanly()

I’d be happy to do that, but I would be submitting a PR where half of the helpers get a comment saying “careful, mitr doesn’t understand why this exists / deviates”.

@mtrmac mtrmac deleted the PodmanOptions branch January 23, 2025 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. release-note-none
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants