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

Drop in Interactive shell #58

Merged
merged 4 commits into from
Jan 31, 2024
Merged

Conversation

chantra
Copy link
Collaborator

@chantra chantra commented Jan 25, 2024

When the magic command - is passed, and we are running in kernel mode, get a
shell prompt in the VM.

To do this, we can re-use the existing run framework with some changes:

  • standard streams to the qemu command are not changed and instead are inherited
  • child std is not streamed to the UI anymore.
  • the command is not sent over qga anymore, we just wait for the qemu command to
    return (e.g when user exit its bash prompt) and exit

Fixes #54

Tested by running

RUST_LOG=debug cargo run -- -k kernels/bzImage-x86_64 -

and confirming no existing tests are broken.

Also could get it to work cross-platform:

cargo run --  -k ./kernels/Image-arm64 -r ./rootfs/ubuntu-lunar-arm64 -a aarch64 -

@chantra
Copy link
Collaborator Author

chantra commented Jan 25, 2024

This is currently a PoC, but it does seem functional without being too intrusive.

It does help to be able to get a shell in the VM when tests are failure and further troubleshooting is needed.
Feedback welcome.

@chantra
Copy link
Collaborator Author

chantra commented Jan 25, 2024

The error seems unrelated. I believe I had it happening on my computer sporadically too.

[2024-01-25T01:59:53Z WARN  vmtest::qga] QGA sync failed, retrying: Resource temporarily unavailable (os error 11)
[2024-01-25T01:59:54Z INFO  vmtest::qga] Connecting to QGA (9)
[2024-01-25T01:59:59Z WARN  vmtest::qga] QGA sync failed, retrying: Resource temporarily unavailable (os error 11)
[2024-01-25T02:00:00Z DEBUG vmtest::qemu] Child still alive, killing
[2024-01-25T02:00:00Z DEBUG vmtest::qemu] qemu stderr: WARNING: Image format was not specified for '/home/runner/work/vmtest/vmtest/tests/.assets/image-not-uefi.raw' and probing guessed raw.
             Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
             Specify the 'raw' format explicitly to remove the restrictions.
Failed to connect QGA

    
thread 'test_run' panicked at tests/test.rs:42:5:
assertion `left == right` failed
  left: 1
 right: 0
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Caused by:
    Timed out waiting for QGA connection
FAILED
FAILED

Copy link
Owner

@danobi danobi left a comment

Choose a reason for hiding this comment

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

nice, seems quite reasonable. maybe add some kind of pexpect style integration test as well?

@@ -35,6 +35,7 @@ const COMMAND_TEMPLATE: &str = include_str!("init/command.template");
const ROOTFS_9P_FS_MOUNT_TAG: &str = "/dev/root";
const SHARED_9P_FS_MOUNT_TAG: &str = "vmtest-shared";
const COMMAND_OUTPUT_PORT_NAME: &str = "org.qemu.virtio_serial.0";
const MAGIC_INTERACTIVE_COMMAND: &str = "-";
Copy link
Owner

Choose a reason for hiding this comment

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

Unixy :)

@chantra
Copy link
Collaborator Author

chantra commented Jan 26, 2024

maybe add some kind of pexpect style integration test as well?

yeah, good idea.

We used to let init block on `qemu-qa`, run commands, and then terminate the
VM through QMP.

By blocking on a bash process, we obtain the same outcome, but then we can
also re-use the same init script to get an interactive prompt in the VM, which
in turn can help with danobi#54.

Signed-off-by: Manu Bretelle <[email protected]>
When the magic command `-` is passed, and we are running in kernel mode, get a
shell prompt in the VM.

To do this, we can re-use the existing `run` framework with some changes:
- standard streams to the qemu command are not changed and instead are inherited
- child std is not streamed to the UI anymore.
- the command is not sent over qga anymore, we just wait for the qemu command to
  return (e.g when user exit its bash prompt) and exit

Fixes danobi#54

Tested by running
```
RUST_LOG=debug cargo run -- -k kernels/bzImage-x86_64 -
```
and confirming no existing tests are broken.

Also could get it to work cross-platform:
```
cargo run --  -k ./kernels/Image-arm64 -r ./rootfs/ubuntu-lunar-arm64 -a aarch64 -
```

Signed-off-by: Manu Bretelle <[email protected]>
Add a test that will boot vmtest with a kernel in interactive shell mode.
We need to sleep a bit in order to have vmtest mount shared folder with QGA.

Signed-off-by: Manu Bretelle <[email protected]>
@chantra
Copy link
Collaborator Author

chantra commented Jan 29, 2024

ok, added a rexpect test and updated the documentation.

Copy link
Owner

@danobi danobi left a comment

Choose a reason for hiding this comment

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

really nice!

btw, could we update the help message with something like [-] to indicate there's special handling? I think that's a pretty standard hint for coreutils style tools

@chantra
Copy link
Collaborator Author

chantra commented Jan 31, 2024

The current diff prints:

Usage: vmtest [OPTIONS] [COMMAND]...

Arguments:
  [COMMAND]...  Command to run in kernel mode. `-` to get an interactive shell

I could make it something like:

Usage: vmtest [OPTIONS] [[COMMAND][-]]...

Arguments:
  [[COMMAND][-]]...  Command to run in kernel mode. `-` to get an interactive shell
...

instead.
Is this what you mean?

@danobi
Copy link
Owner

danobi commented Jan 31, 2024

Ah, missed that in the final commit. LGTM as is

@chantra chantra merged commit c7c84d3 into danobi:master Jan 31, 2024
1 check passed
@chantra chantra deleted the interactive_shell branch January 31, 2024 20:15
/// Interactive mode means we are not running a command and we are not
/// running in image mode.
fn interactive(&self) -> bool {
self.command == MAGIC_INTERACTIVE_COMMAND && !self.image

Choose a reason for hiding this comment

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

@chantra why !self.image?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

IIRC, but I have not played with images much, the image does not depend on a init file, which is what provides the root prompt here. I don't think it is just a matter of removing the check on whether or not this is running in an image to have it magically work, but I may be wrong.

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.

drop into an interactive shell
3 participants