Skip to content

Commit

Permalink
Merge branch 'main' into dap/drafts/reconfigurator-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davepacheco committed Aug 27, 2024
2 parents e85d012 + dd85331 commit 251e665
Show file tree
Hide file tree
Showing 72 changed files with 2,248 additions and 2,003 deletions.
230 changes: 172 additions & 58 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,12 @@ api_identity = { path = "api_identity" }
approx = "0.5.1"
assert_matches = "1.5.0"
assert_cmd = "2.0.16"
async-bb8-diesel = { git = "https://github.com/oxidecomputer/async-bb8-diesel", rev = "ed7ab5ef0513ba303d33efd41d3e9e381169d59b" }
async-bb8-diesel = "0.2"
async-trait = "0.1.81"
atomicwrites = "0.4.3"
authz-macros = { path = "nexus/authz-macros" }
backoff = { version = "0.4.0", features = [ "tokio" ] }
base64 = "0.22.1"
bb8 = "0.8.5"
bcs = "0.1.6"
bincode = "1.3.3"
bootstore = { path = "bootstore" }
Expand Down Expand Up @@ -503,6 +502,7 @@ bhyve_api = { git = "https://github.com/oxidecomputer/propolis", rev = "24a74d0c
propolis-client = { git = "https://github.com/oxidecomputer/propolis", rev = "24a74d0c76b6a63961ecef76acb1516b6e66c5c9" }
propolis-mock-server = { git = "https://github.com/oxidecomputer/propolis", rev = "24a74d0c76b6a63961ecef76acb1516b6e66c5c9" }
proptest = "1.5.0"
qorb = { git = "https://github.com/oxidecomputer/qorb", branch = "master" }
quote = "1.0"
rand = "0.8.5"
rand_core = "0.6.4"
Expand Down Expand Up @@ -586,7 +586,7 @@ textwrap = "0.16.1"
test-strategy = "0.3.1"
thiserror = "1.0"
tofino = { git = "https://github.com/oxidecomputer/tofino", branch = "main" }
tokio = "1.38.1"
tokio = "1.39.3"
tokio-postgres = { version = "0.7", features = [ "with-chrono-0_4", "with-uuid-1" ] }
tokio-stream = "0.1.15"
tokio-tungstenite = "0.20"
Expand Down
9 changes: 3 additions & 6 deletions clients/nexus-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,11 @@ impl From<omicron_common::api::internal::nexus::VmmRuntimeState>
}
}

impl From<omicron_common::api::internal::nexus::SledInstanceState>
for types::SledInstanceState
impl From<omicron_common::api::internal::nexus::SledVmmState>
for types::SledVmmState
{
fn from(
s: omicron_common::api::internal::nexus::SledInstanceState,
) -> Self {
fn from(s: omicron_common::api::internal::nexus::SledVmmState) -> Self {
Self {
propolis_id: s.propolis_id,
vmm_state: s.vmm_state.into(),
migration_in: s.migration_in.map(Into::into),
migration_out: s.migration_out.map(Into::into),
Expand Down
30 changes: 15 additions & 15 deletions clients/sled-agent-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! Interface for making API requests to a Sled Agent
use async_trait::async_trait;
use omicron_uuid_kinds::PropolisUuid;
use schemars::JsonSchema;
use serde::Deserialize;
use serde::Serialize;
Expand Down Expand Up @@ -161,12 +162,11 @@ impl From<types::VmmRuntimeState>
}
}

impl From<types::SledInstanceState>
for omicron_common::api::internal::nexus::SledInstanceState
impl From<types::SledVmmState>
for omicron_common::api::internal::nexus::SledVmmState
{
fn from(s: types::SledInstanceState) -> Self {
fn from(s: types::SledVmmState) -> Self {
Self {
propolis_id: s.propolis_id,
vmm_state: s.vmm_state.into(),
migration_in: s.migration_in.map(Into::into),
migration_out: s.migration_out.map(Into::into),
Expand Down Expand Up @@ -448,33 +448,33 @@ impl From<types::SledIdentifiers>
/// are bonus endpoints, not generated in the real client.
#[async_trait]
pub trait TestInterfaces {
async fn instance_single_step(&self, id: Uuid);
async fn instance_finish_transition(&self, id: Uuid);
async fn instance_simulate_migration_source(
async fn vmm_single_step(&self, id: PropolisUuid);
async fn vmm_finish_transition(&self, id: PropolisUuid);
async fn vmm_simulate_migration_source(
&self,
id: Uuid,
id: PropolisUuid,
params: SimulateMigrationSource,
);
async fn disk_finish_transition(&self, id: Uuid);
}

#[async_trait]
impl TestInterfaces for Client {
async fn instance_single_step(&self, id: Uuid) {
async fn vmm_single_step(&self, id: PropolisUuid) {
let baseurl = self.baseurl();
let client = self.client();
let url = format!("{}/instances/{}/poke-single-step", baseurl, id);
let url = format!("{}/vmms/{}/poke-single-step", baseurl, id);
client
.post(url)
.send()
.await
.expect("instance_single_step() failed unexpectedly");
}

async fn instance_finish_transition(&self, id: Uuid) {
async fn vmm_finish_transition(&self, id: PropolisUuid) {
let baseurl = self.baseurl();
let client = self.client();
let url = format!("{}/instances/{}/poke", baseurl, id);
let url = format!("{}/vmms/{}/poke", baseurl, id);
client
.post(url)
.send()
Expand All @@ -493,14 +493,14 @@ impl TestInterfaces for Client {
.expect("disk_finish_transition() failed unexpectedly");
}

async fn instance_simulate_migration_source(
async fn vmm_simulate_migration_source(
&self,
id: Uuid,
id: PropolisUuid,
params: SimulateMigrationSource,
) {
let baseurl = self.baseurl();
let client = self.client();
let url = format!("{baseurl}/instances/{id}/sim-migration-source");
let url = format!("{baseurl}/vmms/{id}/sim-migration-source");
client
.post(url)
.json(&params)
Expand Down
10 changes: 3 additions & 7 deletions common/src/api/internal/nexus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,9 @@ pub struct VmmRuntimeState {
pub time_updated: DateTime<Utc>,
}

/// A wrapper type containing a sled's total knowledge of the state of a
/// specific VMM and the instance it incarnates.
/// A wrapper type containing a sled's total knowledge of the state of a VMM.
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
pub struct SledInstanceState {
/// The ID of the VMM whose state is being reported.
pub propolis_id: PropolisUuid,

pub struct SledVmmState {
/// The most recent state of the sled's VMM process.
pub vmm_state: VmmRuntimeState,

Expand All @@ -142,7 +138,7 @@ impl Migrations<'_> {
}
}

impl SledInstanceState {
impl SledVmmState {
pub fn migrations(&self) -> Migrations<'_> {
Migrations {
migration_in: self.migration_in.as_ref(),
Expand Down
24 changes: 24 additions & 0 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,27 @@ where
async fn never_bail() -> Result<bool, Error> {
Ok(false)
}

/// A wrapper struct that does nothing other than elide the inner value from
/// [`std::fmt::Debug`] output.
///
/// We define this within Omicron instead of using one of the many available
/// crates that do the same thing because it's trivial to do so, and we want the
/// flexibility to add traits to this type without needing to wait on upstream
/// to add an optional dependency.
///
/// If you want to use this for secrets, consider that it might not do
/// everything you expect (it does not zeroize memory on drop, nor get in the
/// way of you removing the inner value from this wrapper struct).
#[derive(
Clone, Copy, serde::Deserialize, serde::Serialize, schemars::JsonSchema,
)]
#[repr(transparent)]
#[serde(transparent)]
pub struct NoDebug<T>(pub T);

impl<T> std::fmt::Debug for NoDebug<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "..")
}
}
13 changes: 7 additions & 6 deletions dev-tools/omdb/src/bin/omdb/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ impl DbUrlOptions {
eprintln!("note: using database URL {}", &db_url);

let db_config = db::Config { url: db_url.clone() };
let pool = Arc::new(db::Pool::new(&log.clone(), &db_config));
let pool =
Arc::new(db::Pool::new_single_host(&log.clone(), &db_config));

// Being a dev tool, we want to try this operation even if the schema
// doesn't match what we expect. So we use `DataStore::new_unchecked()`
Expand Down Expand Up @@ -4224,7 +4225,7 @@ async fn cmd_db_inventory(
}

async fn cmd_db_inventory_baseboard_ids(
conn: &DataStoreConnection<'_>,
conn: &DataStoreConnection,
limit: NonZeroU32,
) -> Result<(), anyhow::Error> {
#[derive(Tabled)]
Expand Down Expand Up @@ -4261,7 +4262,7 @@ async fn cmd_db_inventory_baseboard_ids(
}

async fn cmd_db_inventory_cabooses(
conn: &DataStoreConnection<'_>,
conn: &DataStoreConnection,
limit: NonZeroU32,
) -> Result<(), anyhow::Error> {
#[derive(Tabled)]
Expand Down Expand Up @@ -4302,7 +4303,7 @@ async fn cmd_db_inventory_cabooses(
}

async fn cmd_db_inventory_physical_disks(
conn: &DataStoreConnection<'_>,
conn: &DataStoreConnection,
limit: NonZeroU32,
args: InvPhysicalDisksArgs,
) -> Result<(), anyhow::Error> {
Expand Down Expand Up @@ -4359,7 +4360,7 @@ async fn cmd_db_inventory_physical_disks(
}

async fn cmd_db_inventory_rot_pages(
conn: &DataStoreConnection<'_>,
conn: &DataStoreConnection,
limit: NonZeroU32,
) -> Result<(), anyhow::Error> {
#[derive(Tabled)]
Expand Down Expand Up @@ -4394,7 +4395,7 @@ async fn cmd_db_inventory_rot_pages(
}

async fn cmd_db_inventory_collections_list(
conn: &DataStoreConnection<'_>,
conn: &DataStoreConnection,
limit: NonZeroU32,
) -> Result<(), anyhow::Error> {
#[derive(Tabled)]
Expand Down
24 changes: 24 additions & 0 deletions nexus-config/src/postgres_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! Common objects used for configuration
use std::fmt;
use std::net::SocketAddr;
use std::ops::Deref;
use std::str::FromStr;

Expand Down Expand Up @@ -32,6 +33,29 @@ impl PostgresConfigWithUrl {
pub fn url(&self) -> String {
self.url_raw.clone()
}

/// Accesses the first ip / port pair within the URL.
///
/// # Panics
///
/// This method makes the assumption that the hostname has at least one
/// "host IP / port" pair which can be extracted. If the supplied URL
/// does not have such a pair, this function will panic.
// Yes, panicking in the above scenario sucks. But this type is already
// pretty ubiquitous within Omicron, and integration with the qorb
// connection pooling library requires access to database by SocketAddr.
pub fn address(&self) -> SocketAddr {
let tokio_postgres::config::Host::Tcp(host) =
&self.config.get_hosts()[0]
else {
panic!("Non-TCP hostname");
};
let ip: std::net::IpAddr =
host.parse().expect("Failed to parse host as IP address");

let port = self.config.get_ports()[0];
SocketAddr::new(ip, port)
}
}

impl FromStr for PostgresConfigWithUrl {
Expand Down
6 changes: 4 additions & 2 deletions nexus/db-queries/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,22 @@ omicron-rpaths.workspace = true
anyhow.workspace = true
async-bb8-diesel.workspace = true
async-trait.workspace = true
bb8.workspace = true
camino.workspace = true
chrono.workspace = true
const_format.workspace = true
diesel.workspace = true
diesel-dtrace.workspace = true
dropshot.workspace = true
futures.workspace = true
internal-dns.workspace = true
ipnetwork.workspace = true
macaddr.workspace = true
once_cell.workspace = true
oxnet.workspace = true
paste.workspace = true
# See omicron-rpaths for more about the "pq-sys" dependency.
pq-sys = "*"
qorb = { workspace = true, features = [ "qtop" ] }
rand.workspace = true
ref-cast.workspace = true
schemars.workspace = true
Expand All @@ -45,8 +46,9 @@ strum.workspace = true
swrite.workspace = true
thiserror.workspace = true
tokio = { workspace = true, features = ["full"] }
uuid.workspace = true
url.workspace = true
usdt.workspace = true
uuid.workspace = true

db-macros.workspace = true
nexus-auth.workspace = true
Expand Down
Loading

0 comments on commit 251e665

Please sign in to comment.