Skip to content

Fixes for Toolbx forwarding#1052

Closed
martymichal wants to merge 3 commits intocontainers:mainfrom
martymichal:cmd/forwarding-fixes
Closed

Fixes for Toolbx forwarding#1052
martymichal wants to merge 3 commits intocontainers:mainfrom
martymichal:cmd/forwarding-fixes

Conversation

@martymichal
Copy link
Copy Markdown
Member

@martymichal martymichal commented May 13, 2022

See commit messages for detailed information.

Fixes #957

@martymichal martymichal added 6. Minor Change Should not cause breakage 3. Bugfix Fixes a bug 2. Container Realm The issue is related to what happens inside of a toolbox container 3. Refinement Reduces technical debt of the codebase 2. Testing Related to testing of Toolbox - unit, system,.. 2. Under The Hood Multiple areas of the app are influenced by this ticket labels May 13, 2022
@martymichal martymichal force-pushed the cmd/forwarding-fixes branch from b8e4d77 to 42a86c1 Compare May 13, 2022 06:23
@softwarefactory-project-zuul
Copy link
Copy Markdown

Build failed.

✔️ unit-test SUCCESS in 7m 20s
system-test-fedora-rawhide FAILURE in 15m 56s
system-test-fedora-36 FAILURE in 10m 57s
system-test-fedora-35 FAILURE in 12m 13s
system-test-fedora-34 FAILURE in 12m 40s

@debarshiray
Copy link
Copy Markdown
Member

recheck

@softwarefactory-project-zuul
Copy link
Copy Markdown

Merge Failed.

This change or one of its cross-repo dependencies was unable to be automatically merged with the current state of its repository. Please rebase the change and upload a new patchset.
Warning:
Error merging github.com/containers/toolbox for 1052,42a86c13f0c3ff51c29b9278ce2a61544c688e3c

Copy link
Copy Markdown
Member

@debarshiray debarshiray left a comment

Choose a reason for hiding this comment

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

I managed to finally fish this out from my backlog. Sorry about that.

debarshiray pushed a commit to debarshiray/toolbox that referenced this pull request Sep 4, 2024
debarshiray pushed a commit to debarshiray/toolbox that referenced this pull request Sep 5, 2024
debarshiray pushed a commit to debarshiray/toolbox that referenced this pull request Sep 9, 2024
Copy link
Copy Markdown
Member

@debarshiray debarshiray left a comment

Choose a reason for hiding this comment

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

Don't we also need to handle the help functions in the same way?

debarshiray pushed a commit to debarshiray/toolbox that referenced this pull request Sep 9, 2024
debarshiray added a commit to debarshiray/toolbox that referenced this pull request Sep 9, 2024
The test suite uses its own separate local container/storage store to
isolate itself from the default store, so that the tests' interactions
with containers and images don't affect anything else.  This is done by
using the CONTAINERS_STORAGE_CONF environment variable [1] to specify a
separate storage.conf(5) file [2].

Therefore, when running the test suite, the CONTAINERS_STORAGE_CONF
environment variable must be preserved when forwarding toolbox(1)
invocations inside containers to the host.  Otherwise, the initial
toolbox(1) invocation on the host and the forwarded invocation running
on the host won't use the same local container/storage store.

This problem only impacts test cases that cover toolbox(1) code paths
that invoke podman(1).

[1] https://docs.podman.io/en/latest/markdown/podman.1.html

[2] https://manpages.debian.org/testing/containers-storage/containers-storage.conf.5.en.html

containers#957
containers#1052
debarshiray added a commit to debarshiray/toolbox that referenced this pull request Sep 9, 2024
When 'toolbox run' is invoked on the host, an exit code of 126 from
'podman exec' means that the specified command couldn't be invoked
because it's not an executable.  eg., the command was actually a
directory.  Note that this doesn't mean that the command couldn't be
found.  That's denoted by exit code 127.

Secondly, Toolbx containers always have an executable toolbox(1) binary
at /usr/bin/toolbox and it's assumed that /usr/bin is always part of the
PATH environment variable.

When 'toolbox run toolbox ...' is invoked, the inner toolbox(1)
invocation will be forwarded back to the host by the Toolbx container's
/usr/bin/toolbox, which is always present as an executable.  Hence, if
the outer 'podman exec' on the host fails with an exit code of 126,
then it doesn't mean that the container didn't have a working toolbox(1)
executable, but that some subordinate process started by the container's
toolbox(1) failed with that exit code.

Therefore, handle this as a special case to avoid showing an extra error
message.  Otherwise, it leads to:
  $ toolbox run toolbox run /etc
  bash: line 1: /etc: Is a directory
  bash: line 1: exec: /etc: cannot execute: Is a directory
  Error: failed to invoke command /etc in container fedora-toolbox-40
  Error: failed to invoke command toolbox in container fedora-toolbox-40
  $ echo "$?"
  126

Instead, it will now be:
  $ toolbox run toolbox run /etc
  bash: line 1: /etc: Is a directory
  bash: line 1: exec: /etc: cannot execute: Is a directory
  Error: failed to invoke command /etc in container fedora-toolbox-40
  $ echo "$?"
  126

containers#957
containers#1052
debarshiray added a commit to debarshiray/toolbox that referenced this pull request Sep 9, 2024
When 'toolbox run' is invoked on the host, an exit code of 127 from
'podman exec' means either that the specified command couldn't be found
or that the working directory didn't exist.  The only way to tell these
two scenarios apart is to actually look inside the container.

Secondly, Toolbx containers always have an executable toolbox(1) binary
at /usr/bin/toolbox and it's assumed that /usr/bin is always part of the
PATH environment variable.

When 'toolbox run toolbox ...' is invoked, the inner toolbox(1)
invocation will be forwarded back to the host by the Toolbx container's
/usr/bin/toolbox, which is always present as an executable.  Hence, if
the outer 'podman exec' on the host fails with an exit code of 127,
then it doesn't mean that the container didn't have a toolbox(1)
executable, but that some subordinate process started by the container's
toolbox(1) failed with that exit code.

Therefore, handle this as a special case to avoid losing the exit code.
Otherwise, it leads to:
  $ toolbox run toolbox run non-existent-command
  bash: line 1: exec: non-existent-command: not found
  Error: command non-existent-command not found in container
      fedora-toolbox-40
  $ echo "$?"
  0

Instead, it will now be:
  $ toolbox run toolbox run non-existent-command
  bash: line 1: exec: non-existent-command: not found
  Error: command non-existent-command not found in container
      fedora-toolbox-40
  $ echo "$?"
  127

containers#957
containers#1052
@debarshiray
Copy link
Copy Markdown
Member

Don't we also need to handle the help functions in the same way?

To answer my own question:

First of all, if man(1) is missing from the host, we show a hard-coded very brief summary. So, we don't need to propagate any errors or exit codes because of that.

Secondly, the help functions deal with the --help flag. By that point, the command line parsing has ensured that the flag is being used against a legitimate command. So, we don't need to worry about missing manual pages for bogus commands.

Things like toolbox help foo are handled by the help command's main help() function, which already propagates errors and exit codes like the other commands.

This leaves us with the scenario where flatpak-spawn(1) is missing from the container. Unfortunately, Cobra's help functions cannot return an error, and currently we have this behaviour:

⬢$ toolbox create --help
Error: flatpak-spawn(1) not found
⬢$ echo $?
0

Ideally, we would have returned a non-zero exit code, but it's probably not a big enough problem and we can set it aside for another day. Ultimately, Toolbx containers are expected to have flatpak-spawn(1).

Copy link
Copy Markdown
Member

@debarshiray debarshiray left a comment

Choose a reason for hiding this comment

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

I believe we have now resurrected and merged all the commits to fix #957 through:

$PODMAN rm --all --force >/dev/null
$PODMAN rmi --all --force >/dev/null
$PODMAN rm --all --force
$PODMAN rmi --all --force
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 don't necessarily disagree that more logs can be better, especially in test suites, but I would like to understand if there was a specific problem that this change was addressing.

As far as I understand, it's only the standard output stream that is being silenced, and error messages are still free to make their way to the standard error stream. So, if there was indeed a problem, then it would be good to document it in the Git commit message to inform future decisions.

Anyway, this particular commit isn't the main thrust of this pull request. We can resurrect it later if needed.

@debarshiray
Copy link
Copy Markdown
Member

Closing. My apologies that it took so long to get to it.

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

Labels

2. Container Realm The issue is related to what happens inside of a toolbox container 2. Testing Related to testing of Toolbox - unit, system,.. 2. Under The Hood Multiple areas of the app are influenced by this ticket 3. Bugfix Fixes a bug 3. Refinement Reduces technical debt of the codebase 6. Minor Change Should not cause breakage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

toolbox create command (ran from within toolbx) is not failing when container already exists.

2 participants