Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion petri/petri-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ fn main() -> anyhow::Result<()> {
})?;

let disk = image
.build()
.build(petri::disk_image::ImageType::Raw)
.context("failed to build disk image")?
.context("no files for the this platform")?;
disk.persist(output)
Expand Down
24 changes: 22 additions & 2 deletions petri/src/disk_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,21 @@ use std::ops::Range;
use std::path::Path;

/// The description and artifacts needed to build a pipette disk image for a VM.
#[derive(Debug)]
pub struct AgentImage {
os_flavor: OsFlavor,
pipette: Option<ResolvedArtifact>,
extras: Vec<(String, ResolvedArtifact)>,
}

/// Disk image type
pub enum ImageType {
/// Raw image
Raw,
/// Fixed VHD1
Vhd,
}

impl AgentImage {
/// Resolves the artifacts needed to build a disk image for a VM.
pub fn new(os_flavor: OsFlavor) -> Self {
Expand Down Expand Up @@ -77,7 +86,7 @@ impl AgentImage {

/// Builds a disk image containing pipette and any files needed for the guest VM
/// to run pipette.
pub fn build(&self) -> anyhow::Result<Option<tempfile::NamedTempFile>> {
pub fn build(&self, image_type: ImageType) -> anyhow::Result<Option<tempfile::NamedTempFile>> {
let mut files = self
.extras
.iter()
Expand Down Expand Up @@ -129,12 +138,23 @@ impl AgentImage {
if files.is_empty() {
Ok(None)
} else {
let mut image_file = tempfile::NamedTempFile::new()?;
let mut image_file = match image_type {
ImageType::Raw => tempfile::NamedTempFile::new()?,
ImageType::Vhd => tempfile::Builder::new().suffix(".vhd").tempfile()?,
};

image_file
.as_file()
.set_len(64 * 1024 * 1024)
.context("failed to set file size")?;

build_fat32_disk_image(&mut image_file, "CIDATA", volume_label, &files)?;

if matches!(image_type, ImageType::Vhd) {
disk_vhd1::Vhd1Disk::make_fixed(image_file.as_file())
.context("failed to make vhd for agent image")?;
}

Ok(Some(image_file))
}
}
Expand Down
8 changes: 5 additions & 3 deletions petri/src/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;

/// A source of [`PetriLogFile`] log files for test output.
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct PetriLogSource(Arc<LogSourceInner>);

#[derive(Debug)]
struct LogSourceInner {
root_path: PathBuf,
json_log: JsonLog,
Expand Down Expand Up @@ -156,7 +157,7 @@ impl PetriLogSource {
}
}

#[derive(Clone)]
#[derive(Clone, Debug)]
struct JsonLog(Arc<File>);

impl JsonLog {
Expand Down Expand Up @@ -199,6 +200,7 @@ impl JsonLog {
}
}

#[derive(Debug)]
struct LogFileInner {
file: File,
json_log: JsonLog,
Expand Down Expand Up @@ -242,7 +244,7 @@ impl std::io::Write for LogWriter<'_> {
/// Generally, you should use [`tracing`] for test-generated logging. This type
/// is for writing fully-formed text entries that come from an external source,
/// such as another process or a guest serial port.
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct PetriLogFile(Arc<LogFileInner>);

impl PetriLogFile {
Expand Down
Loading
Loading