Skip to content

Commit e974959

Browse files
authored
[3/n] [reconfigurator-cli] drop dependency on reconfigurator-execution (#6783)
The only functions from reconfigurator-execution currently pulled in are these helper methods. Move them into nexus-types so that reconfigurator-cli no longer has to pull in the execution crate and all of its dependencies (particularly nexus-db-model and nexus-db-queries). There is one downside, which is that `Overridables`'s `#[cfg(test)]` methods are no longer marked that way. However, it does make the overrides available to places such as the reconfigurator-cli. (It would be interesting to have a test-related overlay feature in omicron, i.e. a `testing` feature in many of our crates, but we don't have that yet.) I had to move some of the silo fixed data into nexus-types as well -- as part of that I took the opportunity to switch to const methods for a couple of UUIDs.
1 parent 1a6343e commit e974959

37 files changed

+471
-400
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev-tools/reconfigurator-cli/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ humantime.workspace = true
2121
indexmap.workspace = true
2222
nexus-inventory.workspace = true
2323
nexus-reconfigurator-planning.workspace = true
24-
nexus-reconfigurator-execution.workspace = true
2524
nexus-sled-agent-shared.workspace = true
2625
nexus-types.workspace = true
2726
omicron-common.workspace = true

dev-tools/reconfigurator-cli/src/main.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ use clap::{Args, Parser, Subcommand};
1313
use dns_service_client::DnsDiff;
1414
use indexmap::IndexMap;
1515
use nexus_inventory::CollectionBuilder;
16-
use nexus_reconfigurator_execution::blueprint_external_dns_config;
17-
use nexus_reconfigurator_execution::blueprint_internal_dns_config;
1816
use nexus_reconfigurator_planning::blueprint_builder::BlueprintBuilder;
1917
use nexus_reconfigurator_planning::blueprint_builder::EnsureMultiple;
2018
use nexus_reconfigurator_planning::planner::Planner;
2119
use nexus_reconfigurator_planning::system::{
2220
SledBuilder, SledHwInventory, SystemDescription,
2321
};
2422
use nexus_sled_agent_shared::inventory::OmicronZonesConfig;
25-
use nexus_sled_agent_shared::inventory::SledRole;
2623
use nexus_sled_agent_shared::inventory::ZoneKind;
24+
use nexus_types::deployment::execution;
25+
use nexus_types::deployment::execution::blueprint_external_dns_config;
26+
use nexus_types::deployment::execution::blueprint_internal_dns_config;
2727
use nexus_types::deployment::BlueprintZoneFilter;
2828
use nexus_types::deployment::OmicronZoneNic;
2929
use nexus_types::deployment::PlanningInput;
@@ -882,10 +882,7 @@ fn cmd_blueprint_diff(
882882

883883
fn make_sleds_by_id(
884884
sim: &ReconfiguratorSim,
885-
) -> Result<
886-
BTreeMap<SledUuid, nexus_reconfigurator_execution::Sled>,
887-
anyhow::Error,
888-
> {
885+
) -> Result<BTreeMap<SledUuid, execution::Sled>, anyhow::Error> {
889886
let collection = sim
890887
.system
891888
.to_collection_builder()
@@ -897,10 +894,10 @@ fn make_sleds_by_id(
897894
.sled_agents
898895
.iter()
899896
.map(|(sled_id, sled_agent_info)| {
900-
let sled = nexus_reconfigurator_execution::Sled::new(
897+
let sled = execution::Sled::new(
901898
*sled_id,
902899
sled_agent_info.sled_agent_address,
903-
sled_agent_info.sled_role == SledRole::Scrimlet,
900+
sled_agent_info.sled_role,
904901
);
905902
(*sled_id, sled)
906903
})

nexus/db-fixed-data/src/project.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

55
use nexus_db_model as model;
6-
use nexus_types::external_api::params;
6+
use nexus_types::{external_api::params, silo::INTERNAL_SILO_ID};
77
use omicron_common::api::external::IdentityMetadataCreateParams;
88
use once_cell::sync::Lazy;
99

@@ -21,7 +21,7 @@ pub static SERVICES_PROJECT_ID: Lazy<uuid::Uuid> = Lazy::new(|| {
2121
pub static SERVICES_PROJECT: Lazy<model::Project> = Lazy::new(|| {
2222
model::Project::new_with_id(
2323
*SERVICES_PROJECT_ID,
24-
*super::silo::INTERNAL_SILO_ID,
24+
INTERNAL_SILO_ID,
2525
params::ProjectCreate {
2626
identity: IdentityMetadataCreateParams {
2727
name: SERVICES_DB_NAME.parse().unwrap(),

nexus/db-fixed-data/src/silo.rs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,26 @@
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

55
use nexus_db_model as model;
6-
use nexus_types::external_api::{params, shared};
6+
use nexus_types::{
7+
external_api::{params, shared},
8+
silo::{
9+
default_silo_name, internal_silo_name, DEFAULT_SILO_ID,
10+
INTERNAL_SILO_ID,
11+
},
12+
};
713
use omicron_common::api::external::IdentityMetadataCreateParams;
814
use once_cell::sync::Lazy;
915

10-
pub static DEFAULT_SILO_ID: Lazy<uuid::Uuid> = Lazy::new(|| {
11-
"001de000-5110-4000-8000-000000000000"
12-
.parse()
13-
.expect("invalid uuid for builtin silo id")
14-
});
15-
1616
/// "Default" Silo
1717
///
1818
/// This was historically used for demos and the unit tests. The plan is to
1919
/// remove it per omicron#2305.
2020
pub static DEFAULT_SILO: Lazy<model::Silo> = Lazy::new(|| {
2121
model::Silo::new_with_id(
22-
*DEFAULT_SILO_ID,
22+
DEFAULT_SILO_ID,
2323
params::SiloCreate {
2424
identity: IdentityMetadataCreateParams {
25-
name: "default-silo".parse().unwrap(),
25+
name: default_silo_name().clone(),
2626
description: "default silo".to_string(),
2727
},
2828
// This quota is actually _unused_ because the default silo
@@ -38,21 +38,14 @@ pub static DEFAULT_SILO: Lazy<model::Silo> = Lazy::new(|| {
3838
.unwrap()
3939
});
4040

41-
/// UUID of built-in internal silo.
42-
pub static INTERNAL_SILO_ID: Lazy<uuid::Uuid> = Lazy::new(|| {
43-
"001de000-5110-4000-8000-000000000001"
44-
.parse()
45-
.expect("invalid uuid for builtin silo id")
46-
});
47-
4841
/// Built-in Silo to house internal resources. It contains no users and
4942
/// can't be logged into.
5043
pub static INTERNAL_SILO: Lazy<model::Silo> = Lazy::new(|| {
5144
model::Silo::new_with_id(
52-
*INTERNAL_SILO_ID,
45+
INTERNAL_SILO_ID,
5346
params::SiloCreate {
5447
identity: IdentityMetadataCreateParams {
55-
name: "oxide-internal".parse().unwrap(),
48+
name: internal_silo_name().clone(),
5649
description: "Built-in internal Silo.".to_string(),
5750
},
5851
// The internal silo contains no virtual resources, so it has no allotted capacity.

nexus/db-fixed-data/src/silo_user.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
use super::role_builtin;
77
use nexus_db_model as model;
8-
use nexus_types::identity::Asset;
8+
use nexus_types::{identity::Asset, silo::DEFAULT_SILO_ID};
99
use once_cell::sync::Lazy;
1010

1111
/// Test user that's granted all privileges, used for automated testing and
@@ -15,7 +15,7 @@ use once_cell::sync::Lazy;
1515
// not automatically at Nexus startup. See omicron#2305.
1616
pub static USER_TEST_PRIVILEGED: Lazy<model::SiloUser> = Lazy::new(|| {
1717
model::SiloUser::new(
18-
*crate::silo::DEFAULT_SILO_ID,
18+
DEFAULT_SILO_ID,
1919
// "4007" looks a bit like "root".
2020
"001de000-05e4-4000-8000-000000004007".parse().unwrap(),
2121
"privileged".into(),
@@ -39,7 +39,7 @@ pub static ROLE_ASSIGNMENTS_PRIVILEGED: Lazy<Vec<model::RoleAssignment>> =
3939
model::IdentityType::SiloUser,
4040
USER_TEST_PRIVILEGED.id(),
4141
role_builtin::SILO_ADMIN.resource_type,
42-
*crate::silo::DEFAULT_SILO_ID,
42+
DEFAULT_SILO_ID,
4343
role_builtin::SILO_ADMIN.role_name,
4444
),
4545
]
@@ -51,7 +51,7 @@ pub static ROLE_ASSIGNMENTS_PRIVILEGED: Lazy<Vec<model::RoleAssignment>> =
5151
// not automatically at Nexus startup. See omicron#2305.
5252
pub static USER_TEST_UNPRIVILEGED: Lazy<model::SiloUser> = Lazy::new(|| {
5353
model::SiloUser::new(
54-
*crate::silo::DEFAULT_SILO_ID,
54+
DEFAULT_SILO_ID,
5555
// 60001 is the decimal uid for "nobody" on Helios.
5656
"001de000-05e4-4000-8000-000000060001".parse().unwrap(),
5757
"unprivileged".into(),

nexus/db-model/src/sled.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ use crate::sled_policy::DbSledPolicy;
1111
use chrono::{DateTime, Utc};
1212
use db_macros::Asset;
1313
use nexus_sled_agent_shared::inventory::SledRole;
14+
use nexus_types::deployment::execution;
1415
use nexus_types::{
1516
external_api::{shared, views},
1617
identity::Asset,
1718
internal_api::params,
1819
};
20+
use omicron_uuid_kinds::{GenericUuid, SledUuid};
1921
use std::net::Ipv6Addr;
2022
use std::net::SocketAddrV6;
2123
use uuid::Uuid;
@@ -140,6 +142,20 @@ impl From<Sled> for views::Sled {
140142
}
141143
}
142144

145+
impl From<Sled> for execution::Sled {
146+
fn from(sled: Sled) -> Self {
147+
Self::new(
148+
SledUuid::from_untyped_uuid(sled.id()),
149+
sled.address(),
150+
if sled.is_scrimlet {
151+
SledRole::Scrimlet
152+
} else {
153+
SledRole::Gimlet
154+
},
155+
)
156+
}
157+
}
158+
143159
impl From<Sled> for params::SledAgentInfo {
144160
fn from(sled: Sled) -> Self {
145161
let role = if sled.is_scrimlet {

nexus/db-queries/src/db/datastore/instance.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1954,6 +1954,7 @@ mod tests {
19541954
use nexus_test_utils::db::test_setup_database;
19551955
use nexus_types::external_api::params;
19561956
use nexus_types::identity::Asset;
1957+
use nexus_types::silo::DEFAULT_SILO_ID;
19571958
use omicron_common::api::external;
19581959
use omicron_common::api::external::ByteCount;
19591960
use omicron_common::api::external::IdentityMetadataCreateParams;
@@ -1963,7 +1964,7 @@ mod tests {
19631964
datastore: &DataStore,
19641965
opctx: &OpContext,
19651966
) -> (authz::Project, Project) {
1966-
let silo_id = *nexus_db_fixed_data::silo::DEFAULT_SILO_ID;
1967+
let silo_id = DEFAULT_SILO_ID;
19671968
let project_id = Uuid::new_v4();
19681969
datastore
19691970
.project_create(

nexus/db-queries/src/db/datastore/migration.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ mod tests {
184184
use nexus_db_model::Project;
185185
use nexus_test_utils::db::test_setup_database;
186186
use nexus_types::external_api::params;
187+
use nexus_types::silo::DEFAULT_SILO_ID;
187188
use omicron_common::api::external::ByteCount;
188189
use omicron_common::api::external::IdentityMetadataCreateParams;
189190
use omicron_test_utils::dev;
@@ -194,7 +195,7 @@ mod tests {
194195
datastore: &DataStore,
195196
opctx: &OpContext,
196197
) -> authz::Instance {
197-
let silo_id = *nexus_db_fixed_data::silo::DEFAULT_SILO_ID;
198+
let silo_id = DEFAULT_SILO_ID;
198199
let project_id = Uuid::new_v4();
199200
let instance_id = InstanceUuid::new_v4();
200201

nexus/db-queries/src/db/datastore/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -444,11 +444,11 @@ mod test {
444444
use futures::StreamExt;
445445
use nexus_config::RegionAllocationStrategy;
446446
use nexus_db_fixed_data::silo::DEFAULT_SILO;
447-
use nexus_db_fixed_data::silo::DEFAULT_SILO_ID;
448447
use nexus_db_model::IpAttachState;
449448
use nexus_db_model::{to_db_typed_uuid, Generation};
450449
use nexus_test_utils::db::test_setup_database;
451450
use nexus_types::external_api::params;
451+
use nexus_types::silo::DEFAULT_SILO_ID;
452452
use omicron_common::api::external::{
453453
ByteCount, Error, IdentityMetadataCreateParams, LookupType, Name,
454454
};
@@ -552,8 +552,8 @@ mod test {
552552
// Associate silo with user
553553
let authz_silo = authz::Silo::new(
554554
authz::FLEET,
555-
*DEFAULT_SILO_ID,
556-
LookupType::ById(*DEFAULT_SILO_ID),
555+
DEFAULT_SILO_ID,
556+
LookupType::ById(DEFAULT_SILO_ID),
557557
);
558558
datastore
559559
.silo_user_create(
@@ -572,7 +572,7 @@ mod test {
572572
.fetch()
573573
.await
574574
.unwrap();
575-
assert_eq!(*DEFAULT_SILO_ID, db_silo_user.silo_id);
575+
assert_eq!(DEFAULT_SILO_ID, db_silo_user.silo_id);
576576

577577
// fetch the one we just created
578578
let (.., fetched) = LookupPath::new(&opctx, &datastore)
@@ -630,7 +630,7 @@ mod test {
630630
Arc::new(authz::Authz::new(&logctx.log)),
631631
authn::Context::for_test_user(
632632
silo_user_id,
633-
*DEFAULT_SILO_ID,
633+
DEFAULT_SILO_ID,
634634
SiloAuthnPolicy::try_from(&*DEFAULT_SILO).unwrap(),
635635
),
636636
Arc::clone(&datastore) as Arc<dyn nexus_auth::storage::Storage>,
@@ -1726,8 +1726,8 @@ mod test {
17261726
// Create a new Silo user so that we can lookup their keys.
17271727
let authz_silo = authz::Silo::new(
17281728
authz::FLEET,
1729-
*DEFAULT_SILO_ID,
1730-
LookupType::ById(*DEFAULT_SILO_ID),
1729+
DEFAULT_SILO_ID,
1730+
LookupType::ById(DEFAULT_SILO_ID),
17311731
);
17321732
let silo_user_id = Uuid::new_v4();
17331733
datastore
@@ -1777,7 +1777,7 @@ mod test {
17771777
.fetch()
17781778
.await
17791779
.unwrap();
1780-
assert_eq!(authz_silo.id(), *DEFAULT_SILO_ID);
1780+
assert_eq!(authz_silo.id(), DEFAULT_SILO_ID);
17811781
assert_eq!(authz_silo_user.id(), silo_user_id);
17821782
assert_eq!(found.silo_user_id, ssh_key.silo_user_id);
17831783
assert_eq!(found.public_key, ssh_key.public_key);

nexus/db-queries/src/db/datastore/project.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use async_bb8_diesel::AsyncRunQueryDsl;
2626
use chrono::Utc;
2727
use diesel::prelude::*;
2828
use nexus_db_fixed_data::project::SERVICES_PROJECT;
29-
use nexus_db_fixed_data::silo::INTERNAL_SILO_ID;
29+
use nexus_types::silo::INTERNAL_SILO_ID;
3030
use omicron_common::api::external::http_pagination::PaginatedBy;
3131
use omicron_common::api::external::CreateResult;
3232
use omicron_common::api::external::DeleteResult;
@@ -103,7 +103,7 @@ impl DataStore {
103103
debug!(opctx.log, "attempting to create built-in projects");
104104

105105
let (authz_silo,) = db::lookup::LookupPath::new(&opctx, self)
106-
.silo_id(*INTERNAL_SILO_ID)
106+
.silo_id(INTERNAL_SILO_ID)
107107
.lookup_for(authz::Action::CreateChild)
108108
.await?;
109109

nexus/db-queries/src/db/datastore/rack.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ use diesel::prelude::*;
3333
use diesel::result::Error as DieselError;
3434
use diesel::upsert::excluded;
3535
use ipnetwork::IpNetwork;
36-
use nexus_db_fixed_data::silo::INTERNAL_SILO_ID;
3736
use nexus_db_fixed_data::vpc_subnet::DNS_VPC_SUBNET;
3837
use nexus_db_fixed_data::vpc_subnet::NEXUS_VPC_SUBNET;
3938
use nexus_db_fixed_data::vpc_subnet::NTP_VPC_SUBNET;
@@ -57,6 +56,7 @@ use nexus_types::external_api::shared::IdentityType;
5756
use nexus_types::external_api::shared::IpRange;
5857
use nexus_types::external_api::shared::SiloRole;
5958
use nexus_types::identity::Resource;
59+
use nexus_types::silo::INTERNAL_SILO_ID;
6060
use omicron_common::api::external::AllowedSourceIps;
6161
use omicron_common::api::external::DataPageParams;
6262
use omicron_common::api::external::Error;
@@ -983,7 +983,7 @@ impl DataStore {
983983
db::model::IpPoolResource {
984984
ip_pool_id: internal_pool_id,
985985
resource_type: db::model::IpPoolResourceType::Silo,
986-
resource_id: *INTERNAL_SILO_ID,
986+
resource_id: INTERNAL_SILO_ID,
987987
is_default: true,
988988
},
989989
)

nexus/db-queries/src/db/datastore/virtual_provisioning_collection.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ mod test {
333333
use nexus_db_model::SiloQuotasUpdate;
334334
use nexus_test_utils::db::test_setup_database;
335335
use nexus_types::external_api::params;
336+
use nexus_types::silo::DEFAULT_SILO_ID;
336337
use omicron_common::api::external::IdentityMetadataCreateParams;
337338
use omicron_test_utils::dev;
338339
use uuid::Uuid;
@@ -380,7 +381,7 @@ mod test {
380381
opctx: &OpContext,
381382
) -> TestData {
382383
let fleet_id = *nexus_db_fixed_data::FLEET_ID;
383-
let silo_id = *nexus_db_fixed_data::silo::DEFAULT_SILO_ID;
384+
let silo_id = DEFAULT_SILO_ID;
384385
let project_id = Uuid::new_v4();
385386

386387
let (authz_project, _project) = datastore

nexus/reconfigurator/execution/src/cockroachdb.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub(crate) async fn ensure_settings(
3333
#[cfg(test)]
3434
mod test {
3535
use super::*;
36-
use crate::overridables::Overridables;
36+
use crate::test_utils::overridables_for_test;
3737
use crate::test_utils::realize_blueprint_and_expect;
3838
use nexus_db_queries::authn;
3939
use nexus_db_queries::authz;
@@ -98,7 +98,7 @@ mod test {
9898
)
9999
.await;
100100
// Execute the initial blueprint.
101-
let overrides = Overridables::for_test(cptestctx);
101+
let overrides = overridables_for_test(cptestctx);
102102
_ = realize_blueprint_and_expect(
103103
&opctx, datastore, resolver, &blueprint, &overrides,
104104
)

0 commit comments

Comments
 (0)