Skip to content

Commit

Permalink
plumb repo depot port to nexus; sim repo depot fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
iliana committed Nov 21, 2024
1 parent 3edc4bd commit e0d12d2
Show file tree
Hide file tree
Showing 26 changed files with 157 additions and 63 deletions.
1 change: 1 addition & 0 deletions nexus/db-model/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,7 @@ table! {
sled_policy -> crate::sled_policy::SledPolicyEnum,
sled_state -> crate::SledStateEnum,
sled_agent_gen -> Int8,
repo_depot_port -> Int4,
}
}

Expand Down
10 changes: 10 additions & 0 deletions nexus/db-model/src/sled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ pub struct Sled {
/// This is specifically distinct from `rcgen`, which is incremented by
/// child resources as part of `DatastoreCollectionConfig`.
pub sled_agent_gen: Generation,

// ServiceAddress (Repo Depot API). Uses `ip`.
pub repo_depot_port: SqlU16,
}

impl Sled {
Expand Down Expand Up @@ -169,6 +172,7 @@ impl From<Sled> for params::SledAgentInfo {
};
Self {
sa_address: sled.address(),
repo_depot_port: sled.repo_depot_port.into(),
role,
baseboard: Baseboard {
serial: sled.serial_number.clone(),
Expand Down Expand Up @@ -220,6 +224,9 @@ pub struct SledUpdate {
pub ip: ipv6::Ipv6Addr,
pub port: SqlU16,

// ServiceAddress (Repo Depot API). Uses `ip`.
pub repo_depot_port: SqlU16,

// Generation number - owned and incremented by sled-agent.
pub sled_agent_gen: Generation,
}
Expand All @@ -228,6 +235,7 @@ impl SledUpdate {
pub fn new(
id: Uuid,
addr: SocketAddrV6,
repo_depot_port: u16,
baseboard: SledBaseboard,
hardware: SledSystemHardware,
rack_id: Uuid,
Expand All @@ -247,6 +255,7 @@ impl SledUpdate {
reservoir_size: hardware.reservoir_size,
ip: addr.ip().into(),
port: addr.port().into(),
repo_depot_port: repo_depot_port.into(),
sled_agent_gen,
}
}
Expand Down Expand Up @@ -282,6 +291,7 @@ impl SledUpdate {
reservoir_size: self.reservoir_size,
ip: self.ip,
port: self.port,
repo_depot_port: self.repo_depot_port,
last_used_address,
sled_agent_gen: self.sled_agent_gen,
}
Expand Down
1 change: 1 addition & 0 deletions nexus/db-queries/src/db/datastore/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ mod test {
let sled = SledUpdate::new(
*sled_id.as_untyped_uuid(),
"[::1]:0".parse().unwrap(),
0,
SledBaseboard {
serial_number: "test-sn".to_string(),
part_number: "test-pn".to_string(),
Expand Down
5 changes: 5 additions & 0 deletions nexus/db-queries/src/db/datastore/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ mod test {
use nexus_db_model::{to_db_typed_uuid, Generation};
use nexus_types::external_api::params;
use nexus_types::silo::DEFAULT_SILO_ID;
use omicron_common::address::REPO_DEPOT_PORT;
use omicron_common::api::external::{
ByteCount, Error, IdentityMetadataCreateParams, LookupType, Name,
};
Expand Down Expand Up @@ -684,12 +685,14 @@ mod test {
0,
0,
);
let bogus_repo_depot_port = 8081;
let rack_id = Uuid::new_v4();
let sled_id = SledUuid::new_v4();

let sled_update = SledUpdate::new(
sled_id.into_untyped_uuid(),
bogus_addr,
bogus_repo_depot_port,
sled_baseboard_for_test(),
sled_system_hardware_for_test(),
rack_id,
Expand Down Expand Up @@ -1691,6 +1694,7 @@ mod test {
let sled1 = db::model::SledUpdate::new(
sled1_id,
addr1,
REPO_DEPOT_PORT,
sled_baseboard_for_test(),
sled_system_hardware_for_test(),
rack_id,
Expand All @@ -1703,6 +1707,7 @@ mod test {
let sled2 = db::model::SledUpdate::new(
sled2_id,
addr2,
REPO_DEPOT_PORT,
sled_baseboard_for_test(),
sled_system_hardware_for_test(),
rack_id,
Expand Down
2 changes: 2 additions & 0 deletions nexus/db-queries/src/db/datastore/physical_disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,12 @@ mod test {
async fn create_test_sled(db: &DataStore) -> Sled {
let sled_id = Uuid::new_v4();
let addr = SocketAddrV6::new(Ipv6Addr::LOCALHOST, 0, 0, 0);
let repo_depot_port = 0;
let rack_id = Uuid::new_v4();
let sled_update = SledUpdate::new(
sled_id,
addr,
repo_depot_port,
sled_baseboard_for_test(),
sled_system_hardware_for_test(),
rack_id,
Expand Down
2 changes: 2 additions & 0 deletions nexus/db-queries/src/db/datastore/rack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1239,9 +1239,11 @@ mod test {

async fn create_test_sled(db: &DataStore, sled_id: Uuid) -> Sled {
let addr = SocketAddrV6::new(Ipv6Addr::LOCALHOST, 0, 0, 0);
let repo_depot_port = 0;
let sled_update = SledUpdate::new(
sled_id,
addr,
repo_depot_port,
sled_baseboard_for_test(),
sled_system_hardware_for_test(),
rack_id(),
Expand Down
3 changes: 3 additions & 0 deletions nexus/db-queries/src/db/datastore/sled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ impl DataStore {
dsl::time_modified.eq(now),
dsl::ip.eq(sled_update.ip),
dsl::port.eq(sled_update.port),
dsl::repo_depot_port.eq(sled_update.repo_depot_port),
dsl::rack_id.eq(sled_update.rack_id),
dsl::is_scrimlet.eq(sled_update.is_scrimlet()),
dsl::usable_hardware_threads
Expand Down Expand Up @@ -1489,9 +1490,11 @@ pub(in crate::db::datastore) mod test {
pub(crate) fn test_new_sled_update() -> SledUpdate {
let sled_id = Uuid::new_v4();
let addr = SocketAddrV6::new(Ipv6Addr::LOCALHOST, 0, 0, 0);
let repo_depot_port = 0;
SledUpdate::new(
sled_id,
addr,
repo_depot_port,
sled_baseboard_for_test(),
sled_system_hardware_for_test(),
rack_id(),
Expand Down
1 change: 1 addition & 0 deletions nexus/db-queries/src/db/datastore/vpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3058,6 +3058,7 @@ mod tests {
.sled_upsert(SledUpdate::new(
sled_id.into_untyped_uuid(),
"[::1]:0".parse().unwrap(),
0,
sled_baseboard_for_test(),
sled_system_hardware_for_test(),
rack_id,
Expand Down
1 change: 1 addition & 0 deletions nexus/reconfigurator/execution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ mod tests {
let sled = SledUpdate::new(
sled_id.into_untyped_uuid(),
"[::1]:0".parse().unwrap(),
0,
SledBaseboard {
serial_number: format!("test-{sled_id}"),
part_number: "test-sled".to_string(),
Expand Down
2 changes: 2 additions & 0 deletions nexus/src/app/background/tasks/blueprint_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,11 @@ mod test {
let SocketAddr::V6(addr) = server.addr() else {
panic!("Expected Ipv6 address. Got {}", server.addr());
};
let bogus_repo_depot_port = 0;
let update = SledUpdate::new(
sled_id.into_untyped_uuid(),
addr,
bogus_repo_depot_port,
SledBaseboard {
serial_number: i.to_string(),
part_number: "test".into(),
Expand Down
1 change: 1 addition & 0 deletions nexus/src/app/background/tasks/inventory_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ mod test {
let sled = SledUpdate::new(
Uuid::new_v4(),
SocketAddrV6::new(Ipv6Addr::LOCALHOST, 1200 + i, 0, 0),
1200 + i,
SledBaseboard {
serial_number: format!("serial-{}", i),
part_number: String::from("fake-sled"),
Expand Down
4 changes: 2 additions & 2 deletions nexus/src/app/background/tasks/tuf_artifact_replication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ use nexus_db_queries::db::{
use nexus_networking::sled_client_from_address;
use nexus_types::deployment::SledFilter;
use nexus_types::internal_api::background::TufArtifactReplicationStatus;
use omicron_common::{address::REPO_DEPOT_PORT, update::ArtifactHash};
use omicron_common::update::ArtifactHash;
use omicron_uuid_kinds::{GenericUuid, SledUuid};
use rand::seq::SliceRandom;
use slog_error_chain::InlineErrorChain;
Expand Down Expand Up @@ -200,7 +200,7 @@ impl ArtifactReplication {
),
depot_base_url: format!(
"http://{}",
sled.address_with_port(REPO_DEPOT_PORT)
sled.address_with_port(sled.repo_depot_port.into())
),
})
.collect::<Vec<_>>();
Expand Down
1 change: 1 addition & 0 deletions nexus/src/app/sled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ impl super::Nexus {
let sled = db::model::SledUpdate::new(
id,
info.sa_address,
info.repo_depot_port,
db::model::SledBaseboard {
serial_number: info.baseboard.serial,
part_number: info.baseboard.part,
Expand Down
2 changes: 2 additions & 0 deletions nexus/tests/integration_tests/rack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ async fn test_sled_list_uninitialized(cptestctx: &ControlPlaneTestContext) {
let sled_uuid = Uuid::new_v4();
let sa = SledAgentInfo {
sa_address: "[fd00:1122:3344:0100::1]:8080".parse().unwrap(),
repo_depot_port: 8081,
role: SledRole::Gimlet,
baseboard,
usable_hardware_threads: 32,
Expand Down Expand Up @@ -211,6 +212,7 @@ async fn test_sled_add(cptestctx: &ControlPlaneTestContext) {
.sled_upsert(SledUpdate::new(
sled_id.into_untyped_uuid(),
"[::1]:0".parse().unwrap(),
0,
SledBaseboard {
serial_number: baseboard.serial.clone(),
part_number: baseboard.part.clone(),
Expand Down
3 changes: 3 additions & 0 deletions nexus/types/src/internal_api/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ pub struct SledAgentInfo {
/// The address of the sled agent's API endpoint
pub sa_address: SocketAddrV6,

/// The port of the Repo Depot API endpoint, on the same IP as `sa_address`
pub repo_depot_port: u16,

/// Describes the responsibilities of the sled
pub role: SledRole,

Expand Down
7 changes: 7 additions & 0 deletions openapi/nexus-internal.json
Original file line number Diff line number Diff line change
Expand Up @@ -5453,6 +5453,12 @@
}
]
},
"repo_depot_port": {
"description": "The port of the Repo Depot API endpoint, on the same IP as `sa_address`",
"type": "integer",
"format": "uint16",
"minimum": 0
},
"reservoir_size": {
"description": "Amount of RAM dedicated to the VMM reservoir\n\nMust be smaller than \"usable_physical_ram\"",
"allOf": [
Expand Down Expand Up @@ -5492,6 +5498,7 @@
"baseboard",
"decommissioned",
"generation",
"repo_depot_port",
"reservoir_size",
"role",
"sa_address",
Expand Down
6 changes: 5 additions & 1 deletion schema/crdb/dbinit.sql
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,11 @@ CREATE TABLE IF NOT EXISTS omicron.public.sled (
sled_state omicron.public.sled_state NOT NULL,

/* Generation number owned and incremented by the sled-agent */
sled_agent_gen INT8 NOT NULL DEFAULT 1
sled_agent_gen INT8 NOT NULL DEFAULT 1,

/* The bound port of the Repo Depot API server, running on the same IP as
the sled agent server. */
repo_depot_port INT4 CHECK (port BETWEEN 0 AND 65535) NOT NULL
);

-- Add an index that ensures a given physical sled (identified by serial and
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions schema/crdb/tuf-artifact-replication/up02.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ALTER TABLE omicron.public.sled
ADD COLUMN IF NOT EXISTS repo_depot_port INT4
CHECK (port BETWEEN 0 AND 65535)
NOT NULL DEFAULT 0;
2 changes: 2 additions & 0 deletions schema/crdb/tuf-artifact-replication/up03.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE omicron.public.sled
ALTER COLUMN repo_depot_port DROP DEFAULT;
58 changes: 28 additions & 30 deletions sled-agent/src/artifact_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::net::SocketAddrV6;
use std::str::FromStr;
use std::time::Duration;

use camino::{Utf8Path, Utf8PathBuf};
use camino::Utf8PathBuf;
use camino_tempfile::{NamedUtf8TempFile, Utf8TempPath};
use dropshot::{
Body, ConfigDropshot, FreeformBody, HttpError, HttpResponseOk, Path,
Expand All @@ -29,7 +29,6 @@ use dropshot::{
use futures::{Stream, TryStreamExt};
use http::StatusCode;
use omicron_common::address::REPO_DEPOT_PORT;
use omicron_common::disk::{DatasetKind, DatasetsConfig};
use omicron_common::update::ArtifactHash;
use repo_depot_api::*;
use sha2::{Digest, Sha256};
Expand All @@ -38,7 +37,7 @@ use sled_storage::dataset::M2_ARTIFACT_DATASET;
use sled_storage::error::Error as StorageError;
use sled_storage::manager::StorageHandle;
use slog::{error, info, Logger};
use slog_error_chain::SlogInlineError;
use slog_error_chain::{InlineErrorChain, SlogInlineError};
use tokio::fs::{File, OpenOptions};
use tokio::io::AsyncWriteExt;

Expand Down Expand Up @@ -445,25 +444,10 @@ pub(crate) trait DatasetsManager: Sync {
) -> Result<impl Iterator<Item = Utf8PathBuf> + '_, StorageError>;
}

/// Iterator `.filter().map()` common to `DatasetsManager` implementations.
pub(crate) fn filter_dataset_mountpoints(
config: DatasetsConfig,
root: &Utf8Path,
) -> impl Iterator<Item = Utf8PathBuf> + '_ {
config
.datasets
.into_values()
.filter(|dataset| *dataset.name.dataset() == DatasetKind::Update)
.map(|dataset| dataset.name.mountpoint(root))
}

impl DatasetsManager for StorageHandle {
async fn artifact_storage_paths(
&self,
) -> Result<impl Iterator<Item = Utf8PathBuf> + '_, StorageError> {
// TODO: When datasets are managed by Reconfigurator (#6229),
// this should be changed to use `self.datasets_config_list()` and
// `filter_dataset_mountpoints`.
Ok(self
.get_latest_disks()
.await
Expand Down Expand Up @@ -687,25 +671,33 @@ pub(crate) enum Error {
impl From<Error> for HttpError {
fn from(err: Error) -> HttpError {
match err {
// 4xx errors
Error::HashMismatch { .. } => {
HttpError::for_bad_request(None, err.to_string())
}
Error::NotFound { .. } => {
HttpError::for_not_found(None, err.to_string())
}
Error::AlreadyInProgress { .. } => HttpError::for_client_error(
None,
StatusCode::CONFLICT,
err.to_string(),
),

// 5xx errors: ensure the error chain is logged
Error::Body(inner) => inner,
Error::DatasetConfig(_) | Error::NoUpdateDataset => {
HttpError::for_unavail(None, err.to_string())
HttpError::for_unavail(
None,
InlineErrorChain::new(&err).to_string(),
)
}
Error::DepotCopy { .. }
| Error::File { .. }
| Error::FileRename { .. }
| Error::Join(_) => HttpError::for_internal_error(err.to_string()),
Error::HashMismatch { .. } => {
HttpError::for_bad_request(None, err.to_string())
}
Error::NotFound { .. } => {
HttpError::for_not_found(None, err.to_string())
}
| Error::Join(_) => HttpError::for_internal_error(
InlineErrorChain::new(&err).to_string(),
),
}
}
}
Expand Down Expand Up @@ -765,10 +757,16 @@ mod test {
&self,
) -> Result<impl Iterator<Item = camino::Utf8PathBuf> + '_, StorageError>
{
Ok(super::filter_dataset_mountpoints(
self.datasets.clone(),
self.mountpoint_root.path(),
))
Ok(self
.datasets
.datasets
.values()
.filter(|dataset| {
*dataset.name.dataset() == DatasetKind::Update
})
.map(|dataset| {
dataset.name.mountpoint(self.mountpoint_root.path())
}))
}
}

Expand Down
Loading

0 comments on commit e0d12d2

Please sign in to comment.