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 1c22bda commit db0835b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 14 deletions.
32 changes: 18 additions & 14 deletions dev-tools/omdb/src/bin/omdb/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ enum DbCommands {
Services(ServicesArgs),
/// Print information about sleds
Sleds,
/// Print information about the network
Network(NetworkArgs),
}

Expand Down Expand Up @@ -166,6 +167,7 @@ struct NetworkArgs {
#[command(subcommand)]
command: NetworkCommands,

/// Print out raw data structures from the data store.
#[clap(long)]
verbose: bool,
}
Expand Down Expand Up @@ -960,14 +962,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 @@ -985,7 +991,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 @@ -996,7 +1002,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 @@ -1019,14 +1025,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
2 changes: 2 additions & 0 deletions dev-tools/omdb/tests/usage_errors.out
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ Commands:
dns Print information about internal and external DNS
services Print information about control plane services
sleds Print information about sleds
network Print information about the network
help Print this message or the help of the given subcommand(s)

Options:
Expand All @@ -110,6 +111,7 @@ Commands:
dns Print information about internal and external DNS
services Print information about control plane services
sleds Print information about sleds
network Print information about the network
help Print this message or the help of the given subcommand(s)

Options:
Expand Down

0 comments on commit db0835b

Please sign in to comment.