Skip to content

Commit

Permalink
Everything done but database migrations
Browse files Browse the repository at this point in the history
Created using spr 1.3.6-beta.1
  • Loading branch information
sunshowers committed Feb 23, 2024
1 parent 0327599 commit 6116a33
Show file tree
Hide file tree
Showing 25 changed files with 752 additions and 506 deletions.
5 changes: 1 addition & 4 deletions nexus/db-model/src/sled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,7 @@ impl SledUpdate {
revision: self.revision,
// By default, sleds start in-service.
policy: DbSledPolicy::InService,
// By default, sleds start in the "active" state.
//
// XXX In the future there probably needs to be an "uninitialized"
// state here.
// Currently, new sleds start in the "active" state.
state: SledState::Active,
usable_hardware_threads: self.usable_hardware_threads,
usable_physical_ram: self.usable_physical_ram,
Expand Down
11 changes: 11 additions & 0 deletions nexus/db-model/src/sled_policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

//! Database representation of a sled's operator-defined policy.
//!
//! This is related to, but different from `SledState`: a sled's **policy** is
//! what the operator has specified, while its **state** refers to what's
//! currently on it, as determined by Nexus.
//!
//! For example, a sled might be in the `Active` state, but have a policy of
//! `Expunged` -- this would mean that Nexus knows about resources currently
//! provisioned on the sled, but the operator has said that it should be marked
//! as gone.

use super::impl_enum_type;
use nexus_types::external_api::views::{SledPolicy, SledProvisionPolicy};
use serde::{Deserialize, Serialize};
Expand Down
19 changes: 19 additions & 0 deletions nexus/db-model/src/sled_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

//! Database representation of a sled's state as understood by Nexus.
//!
//! This is related to, but different from `SledPolicy`: a sled's **policy** is
//! what the operator has specified, while its **state** refers to what's
//! currently on it, as determined by Nexus.
//!
//! For example, a sled might be in the `Active` state, but have a policy of
//! `Expunged` -- this would mean that Nexus knows about resources currently
//! provisioned on the sled, but the operator has said that it should be marked
//! as gone.

use super::impl_enum_type;
use nexus_types::external_api::views;
use serde::{Deserialize, Serialize};
use std::fmt;
use strum::EnumIter;

impl_enum_type!(
Expand All @@ -21,6 +33,13 @@ impl_enum_type!(
Decommissioned => b"decommissioned"
);

impl fmt::Display for SledState {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// Forward to the canonical implementation in nexus-types.
views::SledState::from(*self).fmt(f)
}
}

impl From<SledState> for views::SledState {
fn from(state: SledState) -> Self {
match state {
Expand Down
3 changes: 2 additions & 1 deletion nexus/db-queries/src/authz/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ mod test {
let logctx = dev::test_setup_log("test_unregistered_resource");
let mut db = test_setup_database(&logctx.log).await;
let (opctx, datastore) =
crate::db::datastore::datastore_test(&logctx, &db).await;
crate::db::datastore::test_utils::datastore_test(&logctx, &db)
.await;

// Define a resource that we "forget" to register with Oso.
use super::AuthorizedResource;
Expand Down
6 changes: 4 additions & 2 deletions nexus/db-queries/src/authz/policy_test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ use uuid::Uuid;
async fn test_iam_roles_behavior() {
let logctx = dev::test_setup_log("test_iam_roles");
let mut db = test_setup_database(&logctx.log).await;
let (opctx, datastore) = db::datastore::datastore_test(&logctx, &db).await;
let (opctx, datastore) =
db::datastore::test_utils::datastore_test(&logctx, &db).await;

// Before we can create the resources, users, and role assignments that we
// need, we must grant the "test-privileged" user privileges to fetch and
Expand Down Expand Up @@ -328,7 +329,8 @@ async fn test_conferred_roles() {
// To start, this test looks a lot like the test above.
let logctx = dev::test_setup_log("test_conferred_roles");
let mut db = test_setup_database(&logctx.log).await;
let (opctx, datastore) = db::datastore::datastore_test(&logctx, &db).await;
let (opctx, datastore) =
db::datastore::test_utils::datastore_test(&logctx, &db).await;

// Before we can create the resources, users, and role assignments that we
// need, we must grant the "test-privileged" user privileges to fetch and
Expand Down
9 changes: 6 additions & 3 deletions nexus/db-queries/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@ mod test {
let logctx = dev::test_setup_log("test_background_context");
let mut db = test_setup_database(&logctx.log).await;
let (_, datastore) =
crate::db::datastore::datastore_test(&logctx, &db).await;
crate::db::datastore::test_utils::datastore_test(&logctx, &db)
.await;
let opctx = OpContext::for_background(
logctx.log.new(o!()),
Arc::new(authz::Authz::new(&logctx.log)),
Expand Down Expand Up @@ -382,7 +383,8 @@ mod test {
let logctx = dev::test_setup_log("test_background_context");
let mut db = test_setup_database(&logctx.log).await;
let (_, datastore) =
crate::db::datastore::datastore_test(&logctx, &db).await;
crate::db::datastore::test_utils::datastore_test(&logctx, &db)
.await;
let opctx = OpContext::for_tests(logctx.log.new(o!()), datastore);

// Like in test_background_context(), this is essentially a test of the
Expand All @@ -403,7 +405,8 @@ mod test {
let logctx = dev::test_setup_log("test_child_context");
let mut db = test_setup_database(&logctx.log).await;
let (_, datastore) =
crate::db::datastore::datastore_test(&logctx, &db).await;
crate::db::datastore::test_utils::datastore_test(&logctx, &db)
.await;
let opctx = OpContext::for_background(
logctx.log.new(o!()),
Arc::new(authz::Authz::new(&logctx.log)),
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/datastore/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ impl RunQueryDsl<DbConnection> for InsertTargetQuery {}
#[cfg(test)]
mod tests {
use super::*;
use crate::db::datastore::datastore_test;
use crate::db::datastore::test_utils::datastore_test;
use nexus_deployment::blueprint_builder::BlueprintBuilder;
use nexus_deployment::blueprint_builder::Ensure;
use nexus_inventory::now_db_precision;
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/datastore/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ impl DataStore {
mod tests {
use super::*;

use crate::db::datastore::datastore_test;
use crate::db::datastore::test_utils::datastore_test;
use nexus_test_utils::db::test_setup_database;
use nexus_types::external_api::params;
use omicron_common::api::external;
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/datastore/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ impl DnsVersionUpdateBuilder {

#[cfg(test)]
mod test {
use crate::db::datastore::datastore_test;
use crate::db::datastore::test_utils::datastore_test;
use crate::db::datastore::DnsVersionUpdateBuilder;
use crate::db::DataStore;
use crate::db::TransactionError;
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/datastore/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1914,8 +1914,8 @@ impl DataStoreInventoryTest for DataStore {

#[cfg(test)]
mod test {
use crate::db::datastore::datastore_test;
use crate::db::datastore::inventory::DataStoreInventoryTest;
use crate::db::datastore::test_utils::datastore_test;
use crate::db::datastore::DataStoreConnection;
use crate::db::schema;
use anyhow::Context;
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/datastore/ip_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ mod test {
use std::num::NonZeroU32;

use crate::authz;
use crate::db::datastore::datastore_test;
use crate::db::datastore::test_utils::datastore_test;
use crate::db::model::{IpPool, IpPoolResource, IpPoolResourceType};
use assert_matches::assert_matches;
use nexus_test_utils::db::test_setup_database;
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/datastore/ipv4_nat_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ fn ipv4_nat_next_version() -> diesel::expression::SqlLiteral<BigInt> {
mod test {
use std::{net::Ipv4Addr, str::FromStr};

use crate::db::datastore::datastore_test;
use crate::db::datastore::test_utils::datastore_test;
use chrono::Utc;
use nexus_db_model::{Ipv4NatEntry, Ipv4NatValues, MacAddr, Vni};
use nexus_test_utils::db::test_setup_database;
Expand Down
Loading

0 comments on commit 6116a33

Please sign in to comment.