Skip to content

Commit

Permalink
fix tests, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rcgoodfellow committed Sep 27, 2023
1 parent 2ddc0a9 commit cea99a3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
31 changes: 17 additions & 14 deletions dev-tools/omdb/src/bin/omdb/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ struct NetworkArgs {
#[command(subcommand)]
command: NetworkCommands,

/// Print out raw data structures from the data store.
#[clap(long)]
verbose: bool,
}
Expand Down Expand Up @@ -1012,14 +1013,18 @@ async fn cmd_db_eips(
owner: Owner,
}

if verbose {
for ip in &ips {
if verbose {
println!("{ip:#?}");
}
}
return Ok(());
}

let mut rows = Vec::new();

for ip in &ips {
if verbose {
println!("{ip:#?}");
continue;
}

let owner = if let Some(owner_id) = ip.parent_id {
if ip.is_service {
let service = LookupPath::new(opctx, datastore)
Expand All @@ -1037,7 +1042,7 @@ async fn cmd_db_eips(
.await
.context("loading requested instance")?
.pop()
.context("loading requested instance")?;
.context("requested instance not found")?;

use db::schema::project::dsl as project_dsl;
let project = project_dsl::project
Expand All @@ -1048,7 +1053,7 @@ async fn cmd_db_eips(
.await
.context("loading requested project")?
.pop()
.context("loading requested instance")?;
.context("requested project not found")?;

Owner::Instance {
project: project.name().to_string(),
Expand All @@ -1071,14 +1076,12 @@ async fn cmd_db_eips(
rows.push(row);
}

if !verbose {
rows.sort_by(|a, b| a.ip.cmp(&b.ip));
let table = tabled::Table::new(rows)
.with(tabled::settings::Style::empty())
.to_string();
rows.sort_by(|a, b| a.ip.cmp(&b.ip));
let table = tabled::Table::new(rows)
.with(tabled::settings::Style::empty())
.to_string();

println!("{}", table);
}
println!("{}", table);

Ok(())
}
Expand Down
18 changes: 18 additions & 0 deletions dev-tools/omdb/tests/successes.out
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,24 @@ stderr:
note: using database URL postgresql://root@[::1]:REDACTED_PORT/omicron?sslmode=disable
note: database schema version matches expected (4.0.0)
=============================================
EXECUTING COMMAND: omdb ["db", "network"]
termination: Exited(2)
---------------------------------------------
stdout:
---------------------------------------------
stderr:
Print information about the network

Usage: omdb db network [OPTIONS] <COMMAND>

Commands:
list-eips List external IPs
help Print this message or the help of the given subcommand(s)

Options:
--verbose Print out raw data structures from the data store
-h, --help Print help
=============================================
EXECUTING COMMAND: omdb ["nexus", "background-tasks", "doc"]
termination: Exited(0)
---------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions dev-tools/omdb/tests/test_all_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ async fn test_omdb_success_cases(cptestctx: &ControlPlaneTestContext) {
&["db", "services", "list-instances"],
&["db", "services", "list-by-sled"],
&["db", "sleds"],
&["db", "network"],
&["nexus", "background-tasks", "doc"],
&["nexus", "background-tasks", "show"],
// We can't easily test the sled agent output because that's only
Expand Down

0 comments on commit cea99a3

Please sign in to comment.