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

cmd/create: Require valid terminal when prompting to pull an image #1428

Merged

Conversation

HarryMichal
Copy link
Member

To limit the possible misbehaviour of Toolbx when ued in scripting, require the presence of valid terminal on stdin when an image needs to be pulled to create a new toolbx.

@HarryMichal HarryMichal added 3. Enhancement Improvement to an existing feature 2. CLI Issue is related to the command line interface 7. Needs tests The work needs new test cases added labels Dec 19, 2023
@HarryMichal HarryMichal force-pushed the skopeo-inspect-async-no-terminal branch from b8babd1 to 213897d Compare December 19, 2023 15:20
Copy link

Build failed.
https://softwarefactory-project.io/zuul/t/local/buildset/b1fea5a5e20e4743a1d04426dd0a3e92

✔️ unit-test SUCCESS in 7m 08s
✔️ unit-test-migration-path-for-coreos-toolbox SUCCESS in 3m 22s
✔️ unit-test-restricted SUCCESS in 5m 55s
system-test-fedora-rawhide FAILURE in 28m 50s
system-test-fedora-39 FAILURE in 28m 35s
system-test-fedora-38 FAILURE in 30m 58s

Copy link
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.

Cool!

src/cmd/create.go Outdated Show resolved Hide resolved
Copy link
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.

This test failure:

not ok 77 create: With a custom image that needs an authentication file in 589ms
fedora-rawhide | # (from function `assert_line' in file test/system/libs/bats-assert/src/assert.bash, line 488,
fedora-rawhide | #  in test file test/system/101-create.bats, line 685)
fedora-rawhide | #   `assert_line --index 0 "Error: failed to pull image $DOCKER_REG_URI/$image"' failed
fedora-rawhide | #
fedora-rawhide | # -- line differs --
fedora-rawhide | # index    : 0
fedora-rawhide | # expected : Error: failed to pull image localhost:50000/fedora-toolbox:34
fedora-rawhide | # actual   : Error: User interaction required to pull a new image. Stopping now.
fedora-rawhide | # --

... seems to say that even when toolbox create was run non-interactively with the --assumeyes option, it still gave the error about requiring user interaction, instead of saying that it failed to pull the image.

Once --assumeyes has been given, it shouldn't worry about the standard input stream not being connected to a terminal device.

src/cmd/create.go Outdated Show resolved Hide resolved
@debarshiray debarshiray force-pushed the skopeo-inspect-async-no-terminal branch from 213897d to 925e75a Compare December 20, 2023 00:52
debarshiray pushed a commit to HarryMichal/toolbox that referenced this pull request Dec 20, 2023
It doesn't make sense to show the image download prompt when the
standard input and output streams are redirected to something other than
a terminal device.

During such non-interactive use, there's no way for the user to see the
prompt and the size of the image and then make a decision based on them.
The decision has to be made differently and earlier.  The user will
either never download or always download or will use 'skopeo inspect'
to decide for themself.

Secondly, when the input and output are not connected to a terminal, the
terminal escape sequences and the terminal-specific ioctl(2) requests
used to show the prompt won't work anyway.

containers#1428
Copy link

Build succeeded.
https://softwarefactory-project.io/zuul/t/local/buildset/caa3c7b1627c4a4ca22a801d74078a93

✔️ unit-test SUCCESS in 8m 47s
✔️ unit-test-migration-path-for-coreos-toolbox SUCCESS in 3m 39s
✔️ unit-test-restricted SUCCESS in 6m 07s
✔️ system-test-fedora-rawhide SUCCESS in 31m 56s
✔️ system-test-fedora-39 SUCCESS in 30m 59s
✔️ system-test-fedora-38 SUCCESS in 29m 18s

@debarshiray
Copy link
Member

This test failure:

[...]

... seems to say that even when toolbox create was run non-interactively with the --assumeyes option, it still gave the error about requiring user interaction, instead of saying that it failed to pull the image.

Once --assumeyes has been given, it shouldn't worry about the standard input stream not being connected to a terminal device.

I took the liberty to fix this to get the tests to pass, and addressed the above nits.

The fact that this tripped up the tests suggests that we should add some new tests for this new error as well. :)

@debarshiray debarshiray force-pushed the skopeo-inspect-async-no-terminal branch from 925e75a to 8b8a2dc Compare December 20, 2023 23:24
debarshiray pushed a commit to HarryMichal/toolbox that referenced this pull request Dec 20, 2023
It doesn't make sense to show the image download prompt when the
standard input or output stream is redirected to something other than a
terminal device.

During such non-interactive use, there's no way for the user to see the
prompt and the size of the image and then make a decision based on them.
The decision has to be made differently and earlier.  The user will
either never download or always download or will use 'skopeo inspect'
to decide for themself.

Secondly, when the input and output are not connected to a terminal, the
terminal escape sequences and the terminal-specific ioctl(2) requests
used to show the prompt won't work anyway.

Some changes by Debarshi Ray.

containers#1428
It doesn't make sense to show the image download prompt when the
standard input or output stream is redirected to something other than a
terminal device.

During such non-interactive use, there's no way for the user to see the
prompt and the size of the image and then make a decision based on them.
The decision has to be made differently and earlier.  The user will
either never download or always download or will use 'skopeo inspect'
to decide for themself.

Secondly, when the input and output are not connected to a terminal, the
terminal escape sequences and the terminal-specific ioctl(2) requests
used to show the prompt won't work anyway.

Some changes by Debarshi Ray.

containers#1428
@debarshiray debarshiray force-pushed the skopeo-inspect-async-no-terminal branch from 8b8a2dc to 55c0e63 Compare December 20, 2023 23:37
Copy link

Build succeeded.
https://softwarefactory-project.io/zuul/t/local/buildset/3877c7fe79164a8aaf9a3b661707ad26

✔️ unit-test SUCCESS in 7m 13s
✔️ unit-test-migration-path-for-coreos-toolbox SUCCESS in 3m 06s
✔️ unit-test-restricted SUCCESS in 6m 20s
✔️ system-test-fedora-rawhide SUCCESS in 46m 59s
✔️ system-test-fedora-39 SUCCESS in 41m 45s
✔️ system-test-fedora-38 SUCCESS in 37m 09s

@debarshiray debarshiray merged commit 55c0e63 into containers:main Dec 21, 2023
2 checks passed
@debarshiray
Copy link
Member

The fact that this tripped up the tests suggests that we should add some new tests for this new error as well. :)

Added some tests and merged. Thanks, @HarryMichal !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2. CLI Issue is related to the command line interface 3. Enhancement Improvement to an existing feature 7. Needs tests The work needs new test cases added
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants