Skip to content

Commit

Permalink
propolis-mock-server should expose more types (#808)
Browse files Browse the repository at this point in the history
  • Loading branch information
davepacheco authored Nov 13, 2024
1 parent 3a741e6 commit aadc099
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion bin/mock-server/src/lib/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use dropshot::{
TypedBody, WebsocketConnection,
};
use futures::SinkExt;
use slog::{error, info, Logger};
use slog::{error, info, o, Logger};
use thiserror::Error;
use tokio::sync::{watch, Mutex};
use tokio_tungstenite::tungstenite::protocol::{Role, WebSocketConfig};
Expand Down Expand Up @@ -654,6 +654,10 @@ mod serial {

/// Returns a Dropshot [`ApiDescription`] object to launch a mock Propolis
/// server.
///
/// This function should be avoided in favor of `start()` because using this
/// function requires that the consumer and Propolis update Dropshot
/// dependencies in lockstep due to the sharing of various types.
pub fn api() -> ApiDescription<Arc<Context>> {
let mut api = ApiDescription::new();
api.register(instance_ensure).unwrap();
Expand All @@ -664,3 +668,29 @@ pub fn api() -> ApiDescription<Arc<Context>> {
api.register(instance_serial_history_get).unwrap();
api
}

// These types need to be exposed so that consumers have names for them without
// having to maintain a dropshot dependency in lockstep with their dependency on
// this crate.

/// configuration for the dropshot server
pub type Config = dropshot::ConfigDropshot;
/// the dropshot server itself
pub type Server = dropshot::HttpServer<Arc<Context>>;
/// errors returned from attempting to start a dropshot server
// Dropshot should expose this, but it's going to be removed anyway.
pub type ServerStartError = Box<dyn std::error::Error + Send + Sync>;

/// Starts a Propolis mock server
pub fn start(config: Config, log: Logger) -> Result<Server, ServerStartError> {
let propolis_log = log.new(o!("component" => "propolis-server-mock"));
let dropshot_log = log.new(o!("component" => "dropshot"));
let private = Arc::new(Context::new(propolis_log));
let starter = dropshot::HttpServerStarter::new(
&config,
api(),
private,
&dropshot_log,
)?;
Ok(starter.start())
}

0 comments on commit aadc099

Please sign in to comment.