Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
rcgoodfellow committed Oct 3, 2023
1 parent e5a2b5a commit 28d4b25
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 37 deletions.
32 changes: 28 additions & 4 deletions dev-tools/omdb/src/bin/omdb/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use nexus_db_model::DnsGroup;
use nexus_db_model::DnsName;
use nexus_db_model::DnsVersion;
use nexus_db_model::DnsZone;
use nexus_db_model::ExternalIp;
use nexus_db_model::Instance;
use nexus_db_model::Project;
use nexus_db_model::Region;
Expand Down Expand Up @@ -1133,10 +1134,18 @@ async fn cmd_db_eips(
limit: NonZeroU32,
verbose: bool,
) -> Result<(), anyhow::Error> {
/*
let ips = datastore
.lookup_external_ips(&opctx)
.await
.context("listing external ips")?;
*/
use db::schema::external_ip::dsl;
let ips: Vec<ExternalIp> = dsl::external_ip
.filter(dsl::time_deleted.is_null())
.select(ExternalIp::as_select())
.get_results_async(datastore.pool_for_tests().await?)
.await?;

check_limit(&ips, limit, || String::from("listing external ips"));

Expand Down Expand Up @@ -1199,26 +1208,41 @@ async fn cmd_db_eips(
Owner::Service { kind: format!("{:?}", service.1.kind) }
} else {
use db::schema::instance::dsl as instance_dsl;
let instance = instance_dsl::instance
let instance = match instance_dsl::instance
.filter(instance_dsl::id.eq(owner_id))
.limit(1)
.select(Instance::as_select())
.load_async(datastore.pool_for_tests().await?)
.await
.context("loading requested instance")?
.pop()
.context("requested instance not found")?;
{
Some(instance) => instance,
None => {
eprintln!("instance with id {owner_id} not found");
continue;
}
};

use db::schema::project::dsl as project_dsl;
let project = project_dsl::project
let project = match project_dsl::project
.filter(project_dsl::id.eq(instance.project_id))
.limit(1)
.select(Project::as_select())
.load_async(datastore.pool_for_tests().await?)
.await
.context("loading requested project")?
.pop()
.context("requested project not found")?;
{
Some(instance) => instance,
None => {
eprintln!(
"project with id {} not found",
instance.project_id
);
continue;
}
};

Owner::Instance {
project: project.name().to_string(),
Expand Down
18 changes: 0 additions & 18 deletions dev-tools/omdb/tests/successes.out
Original file line number Diff line number Diff line change
Expand Up @@ -84,24 +84,6 @@ stderr:
note: using database URL postgresql://root@[::1]:REDACTED_PORT/omicron?sslmode=disable
note: database schema version matches expected (5.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
2 changes: 1 addition & 1 deletion dev-tools/omdb/tests/test_all_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ async fn test_omdb_usage_errors() {
&["db", "dns", "diff"],
&["db", "dns", "names"],
&["db", "services"],
&["db", "network"],
&["nexus"],
&["nexus", "background-tasks"],
&["sled-agent"],
Expand Down Expand Up @@ -69,7 +70,6 @@ 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
18 changes: 18 additions & 0 deletions dev-tools/omdb/tests/usage_errors.out
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,24 @@ Commands:
Options:
-h, --help Print help
=============================================
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"]
termination: Exited(2)
---------------------------------------------
Expand Down
14 changes: 0 additions & 14 deletions nexus/db-queries/src/db/datastore/external_ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,18 +282,4 @@ impl DataStore {
.await
.map_err(|e| public_error_from_diesel(e, ErrorHandler::Server))
}

/// Fetch all external IP addresses of any kind for the provided instance
pub async fn lookup_external_ips(
&self,
opctx: &OpContext,
) -> LookupResult<Vec<ExternalIp>> {
use db::schema::external_ip::dsl;
dsl::external_ip
.filter(dsl::time_deleted.is_null())
.select(ExternalIp::as_select())
.get_results_async(self.pool_authorized(opctx).await?)
.await
.map_err(|e| public_error_from_diesel_pool(e, ErrorHandler::Server))
}
}

0 comments on commit 28d4b25

Please sign in to comment.