Skip to content

Commit

Permalink
simplify query; add test
Browse files Browse the repository at this point in the history
  • Loading branch information
zephraph committed Jan 31, 2024
1 parent 8a37249 commit eaf76f9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
7 changes: 4 additions & 3 deletions nexus/db-queries/src/db/datastore/utilization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ impl DataStore {
}
.select(SiloUtilization::as_select())
.filter(
dsl::silo_discoverable.eq(true).or(dsl::cpus_allocated
.gt(0)
dsl::silo_discoverable
.eq(true)
.or(dsl::cpus_allocated.gt(0))
.or(dsl::memory_allocated.gt(0))
.or(dsl::storage_allocated.gt(0))),
.or(dsl::storage_allocated.gt(0)),
)
.load_async(&*self.pool_connection_authorized(opctx).await?)
.await
Expand Down
43 changes: 42 additions & 1 deletion nexus/tests/integration_tests/utilization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,25 @@ async fn test_utilization(cptestctx: &ControlPlaneTestContext) {

create_default_ip_pool(&client).await;

// set high quota for test silo
let _ = NexusRequest::object_put(
client,
"/v1/system/silos/test-suite-silo/quotas",
Some(&params::SiloQuotasCreate::arbitrarily_high_default()),
)
.authn_as(AuthnMode::PrivilegedUser)
.execute()
.await;

let current_util = objects_list_page_authz::<SiloUtilization>(
client,
"/v1/system/utilization/silos",
)
.await
.items;

// `default-silo` should be the only silo that shows up because
// it has a default quota set
assert_eq!(current_util.len(), 2);

assert_eq!(current_util[0].silo_name, "default-silo");
Expand All @@ -47,7 +59,36 @@ async fn test_utilization(cptestctx: &ControlPlaneTestContext) {

assert_eq!(current_util[1].silo_name, "test-suite-silo");
assert_eq!(current_util[1].provisioned, SiloQuotasCreate::empty().into());
assert_eq!(current_util[1].allocated, SiloQuotasCreate::empty().into());
assert_eq!(
current_util[1].allocated,
SiloQuotasCreate::arbitrarily_high_default().into()
);

let _ = NexusRequest::object_put(
client,
"/v1/system/silos/test-suite-silo/quotas",
Some(&params::SiloQuotasCreate::empty()),
)
.authn_as(AuthnMode::PrivilegedUser)
.execute()
.await;

let current_util = objects_list_page_authz::<SiloUtilization>(
client,
"/v1/system/utilization/silos",
)
.await
.items;

// Now that default-silo is the only one with a quota, it should be the only result
assert_eq!(current_util.len(), 1);

assert_eq!(current_util[0].silo_name, "default-silo");
assert_eq!(current_util[0].provisioned, SiloQuotasCreate::empty().into());
assert_eq!(
current_util[0].allocated,
SiloQuotasCreate::arbitrarily_high_default().into()
);

let _ = create_project(&client, &PROJECT_NAME).await;
let _ = create_instance(client, &PROJECT_NAME, &INSTANCE_NAME).await;
Expand Down

0 comments on commit eaf76f9

Please sign in to comment.