From 39b94d4b0f61e1be3752384978483ba4bc126354 Mon Sep 17 00:00:00 2001 From: David Pacheco Date: Wed, 13 Nov 2024 10:14:27 -0800 Subject: [PATCH 1/4] propolis-mock-server should expose more types --- bin/mock-server/src/lib/lib.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/bin/mock-server/src/lib/lib.rs b/bin/mock-server/src/lib/lib.rs index 0c14738e7..9d6568a8a 100644 --- a/bin/mock-server/src/lib/lib.rs +++ b/bin/mock-server/src/lib/lib.rs @@ -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> { let mut api = ApiDescription::new(); api.register(instance_ensure).unwrap(); @@ -664,3 +668,26 @@ pub fn api() -> ApiDescription> { 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>; +/// errors returned from attempting to start a dropshot server +pub type ServerStartError = dropshot::GenericError; + +/// Starts a Propolis mock server +pub async fn start( + config: Config, + log: Logger, +) -> Result { + 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)); + dropshot::HttpServerStarter::new(&config, api(), private, &dropshot_log)? + .start() +} From 364413d21aa83a8427c317bbb3ad9733a1e2b97b Mon Sep 17 00:00:00 2001 From: David Pacheco Date: Wed, 13 Nov 2024 10:28:12 -0800 Subject: [PATCH 2/4] fixes --- bin/mock-server/src/lib/lib.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/bin/mock-server/src/lib/lib.rs b/bin/mock-server/src/lib/lib.rs index 9d6568a8a..14aa76fe4 100644 --- a/bin/mock-server/src/lib/lib.rs +++ b/bin/mock-server/src/lib/lib.rs @@ -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}; @@ -678,7 +678,8 @@ pub type Config = dropshot::ConfigDropshot; /// the dropshot server itself pub type Server = dropshot::HttpServer>; /// errors returned from attempting to start a dropshot server -pub type ServerStartError = dropshot::GenericError; +// Dropshot should expose this, but it's going to be removed anyway. +pub type ServerStartError = Box; /// Starts a Propolis mock server pub async fn start( @@ -688,6 +689,11 @@ pub async fn start( 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)); - dropshot::HttpServerStarter::new(&config, api(), private, &dropshot_log)? - .start() + let starter = dropshot::HttpServerStarter::new( + &config, + api(), + private, + &dropshot_log, + )?; + Ok(starter.start()) } From fea74a6e5a083dfb2d62245e9b01af3e192a091c Mon Sep 17 00:00:00 2001 From: David Pacheco Date: Wed, 13 Nov 2024 10:36:30 -0800 Subject: [PATCH 3/4] does not need to be async --- bin/mock-server/src/lib/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/mock-server/src/lib/lib.rs b/bin/mock-server/src/lib/lib.rs index 14aa76fe4..9129dd913 100644 --- a/bin/mock-server/src/lib/lib.rs +++ b/bin/mock-server/src/lib/lib.rs @@ -682,7 +682,7 @@ pub type Server = dropshot::HttpServer>; pub type ServerStartError = Box; /// Starts a Propolis mock server -pub async fn start( +pub fn start( config: Config, log: Logger, ) -> Result { From c753e479ddb9111af5223638e64ee9873c179bc9 Mon Sep 17 00:00:00 2001 From: David Pacheco Date: Wed, 13 Nov 2024 10:37:39 -0800 Subject: [PATCH 4/4] rustfmt --- bin/mock-server/src/lib/lib.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/bin/mock-server/src/lib/lib.rs b/bin/mock-server/src/lib/lib.rs index 9129dd913..9603fb882 100644 --- a/bin/mock-server/src/lib/lib.rs +++ b/bin/mock-server/src/lib/lib.rs @@ -682,10 +682,7 @@ pub type Server = dropshot::HttpServer>; pub type ServerStartError = Box; /// Starts a Propolis mock server -pub fn start( - config: Config, - log: Logger, -) -> Result { +pub fn start(config: Config, log: Logger) -> Result { 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));