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

ExitWithError() - continue tightening #22346

Merged

Conversation

edsantiago
Copy link
Member

Followup to #22270 : wherever possible/practical, extend command
error checks to include explicit exit status codes and error strings.

A small number of tests were broken, as in, not actually testing
what they claimed to be testing. I've done my best to fix those.

Signed-off-by: Ed Santiago santiago@redhat.com

None

@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 Apr 11, 2024
Copy link
Member Author

@edsantiago edsantiago left a comment

Choose a reason for hiding this comment

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

Pointing out a few areas that merit special attention

Comment on lines -178 to -183
if IsRemote() {
Expect(result).To(ExitWithError())
Expect(result.ErrorToString()).To(ContainSubstring("unknown flag"))
result := podmanTest.Podman([]string{"import", "-q", outfile})
result.WaitWithDefaultTimeout()
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Click the expand-up arrow. Note the SkipIfRemote().

@@ -197,7 +198,7 @@ var _ = Describe("Podman inspect", func() {
})

It("podman [image, container] inspect on container", func() {
ctrName := "testCtr"
ctrName := "testctr"
Copy link
Member Author

Choose a reason for hiding this comment

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

With caps, "image inspect" was barfing with "repository name must be lowercase"

Comment on lines 91 to 93
result = podmanTest.Podman([]string{"load", "-i", outfile})
result.WaitWithDefaultTimeout()
Expect(result).Should(ExitCleanly())
Copy link
Member Author

Choose a reason for hiding this comment

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

Judgment call: I could not figure out the point of this load. That is already tested elsewhere.

@@ -595,14 +595,10 @@ var _ = Describe("Podman logs", func() {
defer cleanup()
logc := podmanTest.Podman([]string{"run", "--log-driver", "journald", "--log-opt", "tag=äöüß", ALPINE, "echo", "podman"})
logc.WaitWithDefaultTimeout()
Expect(logc).To(Exit(126))
// FIXME-2023-09-26: conmon <2.1.8 logs to stdout; clean this up once >=2.1.8 is universal
Copy link
Member Author

Choose a reason for hiding this comment

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

conmon is 2.1.10 everywhere now.

Comment on lines -102 to +104
dis := podmanTest.Podman([]string{"network", "connect", "foobar", "test"})
session := podmanTest.Podman([]string{"create", "--name", "testContainer", "--network", "bridge", ALPINE})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Copy link
Member Author

Choose a reason for hiding this comment

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

This test was completely broken. PLEASE REVIEW CAREFULLY! I don't know if this is the test intention.

Copy link
Member

Choose a reason for hiding this comment

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

looks good

@@ -427,15 +428,19 @@ var _ = Describe("Podman network create", func() {
})

It("podman network create with invalid IP", func() {
nc := podmanTest.Podman([]string{"network", "create", "--subnet", "10.11.0/17000", stringid.GenerateRandomID()})
Copy link
Member Author

Choose a reason for hiding this comment

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

Another test that was completely broken. PLEASE REVIEW THIS CAREFULLY.

Copy link
Member

Choose a reason for hiding this comment

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

chnage looks good but you may want to rename the test to include ip-range

Copy link
Member Author

Choose a reason for hiding this comment

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

Before I do that, is it possible that I misunderstood the point of the test? What would you expect "invalid IP" to mean in the context of "network create"??

Copy link
Member

Choose a reason for hiding this comment

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

My initial gut was running a container with --ip that is not part of the network subnet but AFAIK we already have tests for that. I also see that we handle invalid subnet before in a different test, so that leaves --gateway which also accepts a ip.

Copy link
Member Author

Choose a reason for hiding this comment

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

added gateway test. Renamed test.

})

It("podman network create with invalid network name", func() {
nc := podmanTest.Podman([]string{"network", "create", "foo "})
Copy link
Member Author

Choose a reason for hiding this comment

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

Extra space was making impossible to strcmp() error message. I could not figure out why.

@edsantiago edsantiago force-pushed the exitwitherror-part2 branch from dcc20c6 to 2a37039 Compare April 11, 2024 14:47
})

It("podman load bogus file", func() {
save := podmanTest.Podman([]string{"load", "-i", "foobar.tar"})
save.WaitWithDefaultTimeout()
Expect(save).To(ExitWithError())
Expect(save).To(ExitWithError(125, "stat foobar.tar: no such file or directory"))
Copy link
Member

Choose a reason for hiding this comment

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

FYI all (most?) of these stat <name>: ... will conflict with #22334 and need to be changed to faccessat

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the heads-up. I've set to draft, to prevent this from merging. (Not that I expect it to pass remote/rootless/runc/etc tests anyway. I'm just trying to find out what the snags are).

Comment on lines -102 to +104
dis := podmanTest.Podman([]string{"network", "connect", "foobar", "test"})
session := podmanTest.Podman([]string{"create", "--name", "testContainer", "--network", "bridge", ALPINE})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Copy link
Member

Choose a reason for hiding this comment

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

looks good

@@ -427,15 +428,19 @@ var _ = Describe("Podman network create", func() {
})

It("podman network create with invalid IP", func() {
nc := podmanTest.Podman([]string{"network", "create", "--subnet", "10.11.0/17000", stringid.GenerateRandomID()})
Copy link
Member

Choose a reason for hiding this comment

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

chnage looks good but you may want to rename the test to include ip-range

@edsantiago edsantiago marked this pull request as draft April 11, 2024 14:56
@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 11, 2024
@edsantiago edsantiago force-pushed the exitwitherror-part2 branch from 2a37039 to a554989 Compare April 11, 2024 17:17
Copy link
Member Author

@edsantiago edsantiago left a comment

Choose a reason for hiding this comment

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

OMG it passed CI. A few more special-attention-please comments from my part.

This is still blocked and draft because I don't want to collide with #22334 but I think it's ready for review. Once 22334 merges I will rebase, update error messages as needed, and then post whether my rebase-repush was trivial or if anything else noteworthy was necessary.

@@ -1234,7 +1234,7 @@ func (s *BoltState) networkModify(ctr *Container, network string, opts types.Per
netConnected := ctrNetworksBkt.Get([]byte(network))

if new && netConnected != nil {
return fmt.Errorf("container %s is already connected to network %q: %w", ctr.ID(), network, define.ErrNetworkConnected)
return fmt.Errorf("container %s is already connected to network %s: %w", ctr.ID(), network, define.ErrNetworkConnected)
Copy link
Member Author

Choose a reason for hiding this comment

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

DANGER DANGER DANGER DANGER! I am mucking with non-test code! My thinking is, I would really like consistent error messages.

Copy link
Member

Choose a reason for hiding this comment

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

How is this more consistent? The error 2 lines below still uses %q.
I am in favor of consistency but I would argue this needs much broader vetting of error messages first and a consent from the team on what the right way way is, i.e. when to use %q vs %s, right now this seems rather arbitrarily chosen.

Copy link
Member Author

Choose a reason for hiding this comment

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

I meant consistent between podman and podman-remote. Right now each one emits a different message, which is evil. I did not make that clear, and apologize for that.

I could instead add a conditional to the e2e test (if remote, Expect one thing, otherwise, Expect another). Or I could break this PR down into smaller parts. I'm tempted to do the latter. Suggestions welcome.

Copy link
Member

Choose a reason for hiding this comment

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

How the hell do podman vs podman-remote generate different messages here? This error is coming straight from the db backend, are you sure this is remote vs local not boltdb vs sqlite?

I see what you are trying to do but IMO changing a few messages makes things worse unless we have a overall agreement first on what the right way to change it is. And IMO changing one message only while leaving others the same way makes podman error messages less consistent overall.

Copy link
Member Author

Choose a reason for hiding this comment

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

Final (I hope) followup: I've removed my changes to the code base, and gone with if/else IsRemote() or boltb conditionals in the tests. I find that distasteful but I hope it will let us move forward.

@@ -525,7 +525,7 @@ func (ic *ContainerEngine) ContainerInspect(ctx context.Context, namesOrIds []st
// ErrNoSuchCtr is non-fatal, other errors will be
// treated as fatal.
if errors.Is(err, define.ErrNoSuchCtr) {
errs = append(errs, fmt.Errorf("no such container %s", name))
errs = append(errs, fmt.Errorf("no such container %q", name))
Copy link
Member Author

Choose a reason for hiding this comment

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

Same.

session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError())

// FIXME-someday: figure out why message differs in podman-remote
Copy link
Member Author

Choose a reason for hiding this comment

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

Eh, I tried, got nowhere. Probably five more minutes would've gotten me there but that's what I said three times before that already.

@@ -427,15 +428,19 @@ var _ = Describe("Podman network create", func() {
})

It("podman network create with invalid IP", func() {
nc := podmanTest.Podman([]string{"network", "create", "--subnet", "10.11.0/17000", stringid.GenerateRandomID()})
Copy link
Member Author

Choose a reason for hiding this comment

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

added gateway test. Renamed test.

Expect(session).Should(ExitWithError())
Expect(session.ErrorToString()).To(ContainSubstring("network not found"))
expectMessage := fmt.Sprintf("network %s: ", netID[1:])
// FIXME-someday: figure out why this part does not show up in remote
Copy link
Member Author

Choose a reason for hiding this comment

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

Another rathole

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 21, 2024
@edsantiago edsantiago force-pushed the exitwitherror-part2 branch from a554989 to f42dfde Compare April 22, 2024 12:01
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 22, 2024
@edsantiago edsantiago force-pushed the exitwitherror-part2 branch 2 times, most recently from a9274d5 to d01b207 Compare April 22, 2024 14:47
@edsantiago edsantiago marked this pull request as ready for review April 22, 2024 16:34
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 22, 2024
edsantiago added a commit to edsantiago/libpod that referenced this pull request Apr 24, 2024
Followup to containers#22270: wherever possible/practical, extend command
error checks to include explicit exit status codes and error strings.

Because containers#22346 is stalled, these are some trivial easy-to-review
changes that get us closer to the goal.

Signed-off-by: Ed Santiago <santiago@redhat.com>
edsantiago added a commit to edsantiago/libpod that referenced this pull request Apr 24, 2024
Followup to [1]containers#22270: wherever possible/practical, extend command
error checks to include explicit exit status codes and error strings.

Just trying to shrink down containers#22346 to a manageable, reviewable size.

Signed-off-by: Ed Santiago <santiago@redhat.com>
@edsantiago edsantiago force-pushed the exitwitherror-part2 branch from d01b207 to 0aca6a0 Compare April 25, 2024 21:27
Copy link

Ephemeral COPR build failed. @containers/packit-build please check.

@edsantiago edsantiago force-pushed the exitwitherror-part2 branch 2 times, most recently from bf25023 to 734faf3 Compare April 29, 2024 21:15
@edsantiago
Copy link
Member Author

@containers/podman-maintainers should I split this into smaller chunks?

@Luap99
Copy link
Member

Luap99 commented Apr 30, 2024

@containers/podman-maintainers should I split this into smaller chunks?

I am fine with it, I have now reviewed everything anyway. Just noticed the one blocker above.

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 but we really should work on consistent error messages in the near future...

Copy link
Contributor

openshift-ci bot commented Apr 30, 2024

[APPROVALNOTIFIER] This PR is APPROVED

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

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

Followup to containers#22270 : wherever possible/practical, extend command
error checks to include explicit exit status codes and error strings.

A small number of tests were broken, as in, not actually testing
what they claimed to be testing. I've done my best to fix those.

Signed-off-by: Ed Santiago <santiago@redhat.com>
@edsantiago edsantiago force-pushed the exitwitherror-part2 branch from 0eacdc3 to 641cd7c Compare May 8, 2024 00:57
@mheon
Copy link
Member

mheon commented May 8, 2024

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label May 8, 2024
@openshift-merge-bot openshift-merge-bot bot merged commit 092d040 into containers:main May 8, 2024
91 checks passed
@edsantiago edsantiago deleted the exitwitherror-part2 branch May 8, 2024 19:39
@stale-locking-app stale-locking-app bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Aug 7, 2024
@stale-locking-app stale-locking-app bot locked as resolved and limited conversation to collaborators Aug 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. release-note-none
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants