Skip to content

Commit c9846d1

Browse files
authored
Add VolumeInfo to crutest-cli (#1934)
Added the volume-info command to crutest cli. This will get the VolumeInfo, make it json, and send it over to the CLI.
1 parent c59a136 commit c9846d1

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

crutest/src/cli.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ enum CliCommand {
197197
},
198198
/// Get the upstairs UUID
199199
Uuid,
200+
/// Request volume info as JSON
201+
VolumeInfo,
200202
}
201203

202204
/*
@@ -546,6 +548,9 @@ async fn cmd_to_msg(
546548
CliCommand::WriteUnwritten { offset } => {
547549
fw.send(CliMessage::WriteUnwritten(offset)).await?;
548550
}
551+
CliCommand::VolumeInfo => {
552+
fw.send(CliMessage::VolumeInfoPlease).await?;
553+
}
549554
}
550555
/*
551556
* Now, wait for our response
@@ -558,6 +563,9 @@ async fn cmd_to_msg(
558563
Some(CliMessage::Info(vi)) => {
559564
println!("Got info: {:?}", vi);
560565
}
566+
Some(CliMessage::VolumeInfoJson(json)) => {
567+
println!("{}", json);
568+
}
561569
Some(CliMessage::DoneOk) => {
562570
println!("Ok");
563571
}
@@ -989,6 +997,15 @@ async fn process_cli_command(
989997
let uuid = volume.get_uuid().await?;
990998
fw.send(CliMessage::MyUuid(uuid)).await
991999
}
1000+
CliMessage::VolumeInfoPlease => {
1001+
match volume.query_volume_info().await {
1002+
Ok(vi) => {
1003+
let json = serde_json::to_string_pretty(&vi).unwrap();
1004+
fw.send(CliMessage::VolumeInfoJson(json)).await
1005+
}
1006+
Err(e) => fw.send(CliMessage::Error(e)).await,
1007+
}
1008+
}
9921009
CliMessage::Verify => {
9931010
if let Some(di) = di_option {
9941011
match verify_volume(volume, di, false).await {

crutest/src/protocol.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ pub enum CliMessage {
5858
WriteUnwritten(usize),
5959
Unknown(u32, BytesMut),
6060
Uuid,
61+
VolumeInfoPlease,
62+
VolumeInfoJson(String),
6163
}
6264

6365
#[derive(Debug)]
@@ -317,6 +319,20 @@ mod tests {
317319
Ok(())
318320
}
319321

322+
#[test]
323+
fn rt_volume_info_please() -> Result<()> {
324+
let input = CliMessage::VolumeInfoPlease;
325+
assert_eq!(input, round_trip(&input)?);
326+
Ok(())
327+
}
328+
329+
#[test]
330+
fn rt_volume_info_json() -> Result<()> {
331+
let input = CliMessage::VolumeInfoJson(r#"{"volume": {}}"#.to_string());
332+
assert_eq!(input, round_trip(&input)?);
333+
Ok(())
334+
}
335+
320336
// ZZZ tests for readresponse, Error
321337
#[test]
322338
fn correctly_detect_truncated_message() -> Result<()> {

0 commit comments

Comments
 (0)