Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 48 additions & 7 deletions petri/src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ impl<T: PetriVmmBackend> PetriVmBuilder<T> {
/// event (if configured). Does not configure and start pipette. Should
/// only be used for testing platforms that pipette does not support.
pub async fn run_without_agent(self) -> anyhow::Result<PetriVm<T>> {
self.run_core().await
let (vm, _) = self.run_core(false).await?;
Ok(vm)
}

/// Build and run the VM, then wait for the VM to emit the expected boot
Expand All @@ -237,12 +238,14 @@ impl<T: PetriVmmBackend> PetriVmBuilder<T> {
assert!(self.config.agent_image.is_some());
assert!(self.config.agent_image.as_ref().unwrap().contains_pipette());

let mut vm = self.run_core().await?;
let client = vm.wait_for_agent().await?;
Ok((vm, client))
let (vm, agent) = self.run_core(true).await?;
Ok((vm, agent.unwrap()))
}

async fn run_core(self) -> anyhow::Result<PetriVm<T>> {
async fn run_core(
self,
with_agent: bool,
) -> anyhow::Result<(PetriVm<T>, Option<PipetteClient>)> {
let arch = self.config.arch;
let expect_reset = self.expect_reset();

Expand All @@ -268,9 +271,22 @@ impl<T: PetriVmmBackend> PetriVmBuilder<T> {
vm.wait_for_reset_core().await?;
}

let client = if with_agent {
Some(vm.wait_for_agent().await?)
} else {
None
};

if with_agent {
let result = vm.set_console_loglevel(3).await;
if result.is_err() {
tracing::warn!("failed to set console loglevel: {}", result.unwrap_err());
}
}

vm.wait_for_expected_boot_event().await?;

Ok(vm)
Ok((vm, client))
}

fn expect_reset(&self) -> bool {
Expand Down Expand Up @@ -675,7 +691,12 @@ impl<T: PetriVmmBackend> PetriVm<T> {
/// Wait for the VM to reset and pipette to connect.
pub async fn wait_for_reset(&mut self) -> anyhow::Result<PipetteClient> {
self.wait_for_reset_no_agent().await?;
self.wait_for_agent().await
let client = self.wait_for_agent().await?;
let result = self.set_console_loglevel(3).await;
if result.is_err() {
tracing::warn!("failed to set console loglevel: {}", result.unwrap_err());
}
Ok(client)
}

async fn wait_for_reset_core(&mut self) -> anyhow::Result<()> {
Expand Down Expand Up @@ -866,6 +887,26 @@ impl<T: PetriVmmBackend> PetriVm<T> {
anyhow::bail!("VM is not configured with OpenHCL")
}
}

async fn set_console_loglevel(&self, level: u8) -> anyhow::Result<()> {
match self.openhcl_diag() {
Ok(diag) => {
diag.kmsg().await?;
let res = diag
.run_vtl2_command("dmesg", &["-n", &level.to_string()])
.await?;

if !res.exit_status.success() {
anyhow::bail!("failed to set console loglevel: {:?}", res);
}
}
Err(e) => {
anyhow::bail!("failed to open VTl2 diagnostic channel: {}", e);
}
};

Ok(())
}
}

/// A running VM that tests can interact with.
Expand Down
Loading