Skip to content

Commit

Permalink
feat(xtask): allow starting the hypervisor using sudo
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Kröning <martin.kroening@eonerc.rwth-aachen.de>
  • Loading branch information
mkroening committed Dec 10, 2024
1 parent abb2975 commit 20c3eda
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
15 changes: 14 additions & 1 deletion xtask/src/ci/firecracker.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::env;
use std::path::Path;

use anyhow::Result;
Expand All @@ -9,6 +10,10 @@ use crate::build::Build;
/// Run hermit-rs images on Firecracker.
#[derive(Args)]
pub struct Firecracker {
/// Run Firecracker using `sudo`.
#[arg(long)]
sudo: bool,

#[command(flatten)]
build: Build,

Expand All @@ -34,9 +39,17 @@ impl Firecracker {
let config_path = Path::new("firecracker_vm_config.json");
sh.write_file(config_path, config)?;

let firecracker = env::var("FIRECRACKER").unwrap_or_else(|_| "firecracker".to_string());
let program = if self.sudo {
"sudo"
} else {
firecracker.as_str()
};
let arg = self.sudo.then_some(firecracker.as_str());

let log_path = Path::new("firecracker.log");
sh.write_file(log_path, "")?;
cmd!(sh, "firecracker --no-api --config-file {config_path} --log-path {log_path} --level Info --show-level --show-log-origin").run()?;
cmd!(sh, "{program} {arg...} --no-api --config-file {config_path} --log-path {log_path} --level Info --show-level --show-log-origin").run()?;
let log = sh.read_file(log_path)?;

eprintln!("firecracker log");
Expand Down
10 changes: 8 additions & 2 deletions xtask/src/ci/qemu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ pub struct Qemu {
#[arg(long)]
accel: bool,

/// Run QEMU using `sudo`.
#[arg(long)]
sudo: bool,

/// Enable the `microvm` machine type.
#[arg(long)]
microvm: bool,
Expand Down Expand Up @@ -60,9 +64,11 @@ impl Qemu {

let target = self.build.target();
let arch = target.arch();
let qemu = env::var_os("QEMU").unwrap_or_else(|| format!("qemu-system-{arch}").into());
let qemu = env::var("QEMU").unwrap_or_else(|_| format!("qemu-system-{arch}"));
let program = if self.sudo { "sudo" } else { qemu.as_str() };
let arg = self.sudo.then_some(qemu.as_str());

let qemu = cmd!(sh, "{qemu}")
let qemu = cmd!(sh, "{program} {arg...}")
.args(&["-display", "none"])
.args(&["-serial", "stdio"])
.args(self.machine_args())
Expand Down

0 comments on commit 20c3eda

Please sign in to comment.