Skip to content

Commit 925ea1d

Browse files
authored
[bootstrap-agent] Refactor rack_ops (#3833)
Moves it from under `bootstrap/agent/` to just under `bootstrap/`, and removes its dependency on `Agent`. Part of #3827.
1 parent 42a2ec3 commit 925ea1d

File tree

5 files changed

+54
-31
lines changed

5 files changed

+54
-31
lines changed

sled-agent/src/bin/sled-agent.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ use camino::Utf8PathBuf;
88
use clap::{Parser, Subcommand};
99
use omicron_common::cmd::fatal;
1010
use omicron_common::cmd::CmdError;
11+
use omicron_sled_agent::bootstrap::RssAccessError;
1112
use omicron_sled_agent::bootstrap::{
12-
agent as bootstrap_agent, config::Config as BootstrapConfig,
13-
server as bootstrap_server,
13+
config::Config as BootstrapConfig, server as bootstrap_server,
1414
};
1515
use omicron_sled_agent::rack_setup::config::SetupServiceConfig as RssConfig;
1616
use omicron_sled_agent::{config::Config as SledConfig, server as sled_server};
@@ -121,10 +121,7 @@ async fn do_run() -> Result<(), CmdError> {
121121
match server.agent().start_rack_initialize(rss_config) {
122122
// If the rack has already been initialized, we shouldn't
123123
// abandon the server.
124-
Ok(_)
125-
| Err(
126-
bootstrap_agent::RssAccessError::AlreadyInitialized,
127-
) => {}
124+
Ok(_) | Err(RssAccessError::AlreadyInitialized) => {}
128125
Err(e) => {
129126
return Err(CmdError::Failure(e.to_string()));
130127
}

sled-agent/src/bootstrap/agent.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use super::hardware::HardwareMonitor;
1212
use super::http_entrypoints::RackOperationStatus;
1313
use super::params::RackInitializeRequest;
1414
use super::params::StartSledAgentRequest;
15+
use super::rack_ops::{RackInitId, RackResetId, RssAccess, RssAccessError};
1516
use super::secret_retriever::LrtqOrHardcodedSecretRetriever;
1617
use super::views::SledAgentResponse;
1718
use crate::config::Config as SledConfig;
@@ -49,13 +50,6 @@ use thiserror::Error;
4950
use tokio::sync::Mutex;
5051
use tokio::task::JoinHandle;
5152

52-
mod rack_ops;
53-
54-
pub use rack_ops::RackInitId;
55-
pub use rack_ops::RackResetId;
56-
use rack_ops::RssAccess;
57-
pub use rack_ops::RssAccessError;
58-
5953
/// Describes errors which may occur while operating the bootstrap service.
6054
#[derive(Error, Debug)]
6155
pub enum BootstrapError {
@@ -852,14 +846,20 @@ impl Agent {
852846
self: &Arc<Self>,
853847
request: RackInitializeRequest,
854848
) -> Result<RackInitId, RssAccessError> {
855-
self.rss_access.start_initializing(self, request)
849+
self.rss_access.start_initializing(
850+
&self.parent_log,
851+
self.ip,
852+
&self.storage_resources,
853+
&self.bootstore,
854+
request,
855+
)
856856
}
857857

858858
/// Spawn a task to run rack reset.
859859
pub fn start_rack_reset(
860860
self: &Arc<Self>,
861861
) -> Result<RackResetId, RssAccessError> {
862-
self.rss_access.start_reset(self)
862+
self.rss_access.start_reset(&self.parent_log, self.ip)
863863
}
864864

865865
/// Get the status of a spawned initialize or reset operation.

sled-agent/src/bootstrap/http_entrypoints.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
//! Note that the bootstrap agent also communicates over Sprockets,
88
//! and has a separate interface for establishing the trust quorum.
99
10-
use super::agent::{RackInitId, RackResetId};
1110
use crate::bootstrap::agent::Agent;
1211
use crate::bootstrap::params::RackInitializeRequest;
12+
use crate::bootstrap::rack_ops::{RackInitId, RackResetId};
1313
use crate::updates::Component;
1414
use dropshot::{
1515
endpoint, ApiDescription, HttpError, HttpResponseOk,

sled-agent/src/bootstrap/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ mod hardware;
1212
mod http_entrypoints;
1313
mod maghemite;
1414
pub(crate) mod params;
15+
mod rack_ops;
1516
pub(crate) mod rss_handle;
1617
mod secret_retriever;
1718
pub mod server;
1819
mod sprockets_server;
1920
mod views;
21+
22+
pub use rack_ops::RssAccessError;

sled-agent/src/bootstrap/agent/rack_ops.rs renamed to sled-agent/src/bootstrap/rack_ops.rs

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@
44

55
//! Internal API for rack-level bootstrap agent operations.
66
7-
use super::Agent;
87
use crate::bootstrap::http_entrypoints::RackOperationStatus;
98
use crate::bootstrap::params::RackInitializeRequest;
109
use crate::bootstrap::rss_handle::RssHandle;
1110
use crate::rack_setup::service::SetupServiceError;
11+
use crate::storage_manager::StorageResources;
12+
use bootstore::schemes::v0 as bootstore;
1213
use schemars::JsonSchema;
1314
use serde::Deserialize;
1415
use serde::Serialize;
16+
use slog::Logger;
1517
use std::mem;
18+
use std::net::Ipv6Addr;
1619
use std::sync::Arc;
1720
use std::sync::Mutex;
1821
use tokio::sync::oneshot;
@@ -164,9 +167,12 @@ impl RssAccess {
164167
}
165168
}
166169

167-
pub(super) fn start_initializing(
170+
pub(crate) fn start_initializing(
168171
&self,
169-
agent: &Arc<Agent>,
172+
parent_log: &Logger,
173+
global_zone_bootstrap_ip: Ipv6Addr,
174+
storage_resources: &StorageResources,
175+
bootstore_node_handle: &bootstore::NodeHandle,
170176
request: RackInitializeRequest,
171177
) -> Result<RackInitId, RssAccessError> {
172178
let mut status = self.status.lock().unwrap();
@@ -200,10 +206,19 @@ impl RssAccess {
200206
*status = RssStatus::Initializing { id, completion };
201207
mem::drop(status);
202208

203-
let agent = Arc::clone(agent);
209+
let parent_log = parent_log.clone();
210+
let storage_resources = storage_resources.clone();
211+
let bootstore_node_handle = bootstore_node_handle.clone();
204212
let status = Arc::clone(&self.status);
205213
tokio::spawn(async move {
206-
let result = rack_initialize(&agent, request).await;
214+
let result = rack_initialize(
215+
&parent_log,
216+
global_zone_bootstrap_ip,
217+
storage_resources,
218+
bootstore_node_handle,
219+
request,
220+
)
221+
.await;
207222
let new_status = match result {
208223
Ok(()) => RssStatus::Initialized { id: Some(id) },
209224
Err(err) => RssStatus::InitializationFailed { id, err },
@@ -223,7 +238,8 @@ impl RssAccess {
223238

224239
pub(super) fn start_reset(
225240
&self,
226-
agent: &Arc<Agent>,
241+
parent_log: &Logger,
242+
global_zone_bootstrap_ip: Ipv6Addr,
227243
) -> Result<RackResetId, RssAccessError> {
228244
let mut status = self.status.lock().unwrap();
229245

@@ -255,10 +271,11 @@ impl RssAccess {
255271
*status = RssStatus::Resetting { id, completion };
256272
mem::drop(status);
257273

258-
let agent = Arc::clone(agent);
274+
let parent_log = parent_log.clone();
259275
let status = Arc::clone(&self.status);
260276
tokio::spawn(async move {
261-
let result = rack_reset(&agent).await;
277+
let result =
278+
rack_reset(&parent_log, global_zone_bootstrap_ip).await;
262279
let new_status = match result {
263280
Ok(()) => {
264281
RssStatus::Uninitialized { reset_id: Some(id) }
@@ -323,19 +340,25 @@ enum RssStatus {
323340
}
324341

325342
async fn rack_initialize(
326-
agent: &Agent,
343+
parent_log: &Logger,
344+
global_zone_bootstrap_ip: Ipv6Addr,
345+
storage_resources: StorageResources,
346+
bootstore_node_handle: bootstore::NodeHandle,
327347
request: RackInitializeRequest,
328348
) -> Result<(), SetupServiceError> {
329349
RssHandle::run_rss(
330-
&agent.parent_log,
350+
parent_log,
331351
request,
332-
agent.ip,
333-
agent.storage_resources.clone(),
334-
agent.get_bootstore_node_handle(),
352+
global_zone_bootstrap_ip,
353+
storage_resources,
354+
bootstore_node_handle,
335355
)
336356
.await
337357
}
338358

339-
async fn rack_reset(agent: &Agent) -> Result<(), SetupServiceError> {
340-
RssHandle::run_rss_reset(&agent.parent_log, agent.ip).await
359+
async fn rack_reset(
360+
parent_log: &Logger,
361+
global_zone_bootstrap_ip: Ipv6Addr,
362+
) -> Result<(), SetupServiceError> {
363+
RssHandle::run_rss_reset(parent_log, global_zone_bootstrap_ip).await
341364
}

0 commit comments

Comments
 (0)