From 94a5c85a3e76284b2a3f739a1380fc961d61dae5 Mon Sep 17 00:00:00 2001 From: Sean Klein Date: Wed, 10 Feb 2021 14:55:12 -0500 Subject: [PATCH] Integrate updated Dropshot API for HttpServerStarter (#34) --- Cargo.lock | 143 ++++++++++++++---------------------- src/oxide_controller/mod.rs | 28 ++----- src/sled_agent/mod.rs | 18 ++--- tests/common/mod.rs | 11 +-- tests/test_basic.rs | 6 +- 5 files changed, 72 insertions(+), 134 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4c20e1b1d3..3bfc9c3a90 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,27 +30,6 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" -[[package]] -name = "async-stream" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3670df70cbc01729f901f94c887814b3c68db038aad1329a418bae178bc5295c" -dependencies = [ - "async-stream-impl", - "futures-core", -] - -[[package]] -name = "async-stream-impl" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3548b8efc9f8e8a5a0a2808c5bd8451a9031b9e5b879a79590304ae928b0a70" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "async-trait" version = "0.1.42" @@ -88,7 +67,7 @@ dependencies = [ "futures-core", "getrandom 0.2.2", "instant", - "pin-project 1.0.4", + "pin-project 1.0.5", "rand", "tokio", ] @@ -225,8 +204,8 @@ dependencies = [ [[package]] name = "dropshot" -version = "0.3.0" -source = "git+https://github.com/oxidecomputer/dropshot#4f3c1c0a3362efa17a176afed7b807b595c9b731" +version = "0.4.1-dev" +source = "git+https://github.com/oxidecomputer/dropshot#ccb458e3076518642f7a7759737a364e08591f9d" dependencies = [ "async-trait", "base64 0.12.3", @@ -256,12 +235,11 @@ dependencies = [ [[package]] name = "dropshot_endpoint" -version = "0.3.0" -source = "git+https://github.com/oxidecomputer/dropshot#4f3c1c0a3362efa17a176afed7b807b595c9b731" +version = "0.4.1-dev" +source = "git+https://github.com/oxidecomputer/dropshot#ccb458e3076518642f7a7759737a364e08591f9d" dependencies = [ "proc-macro2", "quote", - "schemars", "serde", "serde_tokenstream", "syn", @@ -419,7 +397,7 @@ checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" dependencies = [ "cfg-if 1.0.0", "libc", - "wasi 0.10.1+wasi-snapshot-preview1", + "wasi 0.10.2+wasi-snapshot-preview1", ] [[package]] @@ -500,9 +478,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.3.4" +version = "1.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9" +checksum = "615caabe2c3160b313d52ccc905335f4ed5f10881dd63dc5699d47e90be85691" [[package]] name = "httpdate" @@ -512,9 +490,9 @@ checksum = "494b4d60369511e7dea41cf646832512a94e542f68bb9c49e54518e0f468eb47" [[package]] name = "hyper" -version = "0.14.2" +version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12219dc884514cb4a6a03737f4413c0e01c23a1b059b0156004b23f1e19dccbe" +checksum = "e8e946c2b1349055e0b72ae281b238baf1a3ea7307c7e9f9d64673bdd9c26ac7" dependencies = [ "bytes", "futures-channel", @@ -526,7 +504,7 @@ dependencies = [ "httparse", "httpdate", "itoa", - "pin-project 1.0.4", + "pin-project 1.0.5", "socket2", "tokio", "tower-service", @@ -536,9 +514,9 @@ dependencies = [ [[package]] name = "idna" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" +checksum = "de910d521f7cc3135c4de8db1cb910e0b5ed1dc6f57c381cd07e8e661ce10094" dependencies = [ "matches", "unicode-bidi", @@ -579,9 +557,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.82" +version = "0.2.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89203f3fba0a3795506acaad8ebce3c80c0af93f994d5a1d7a0b1eeb23271929" +checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c" [[package]] name = "linked-hash-map" @@ -600,11 +578,11 @@ dependencies = [ [[package]] name = "log" -version = "0.4.13" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcf3805d4480bb5b86070dcfeb9e2cb2ebc148adb753c5cca5f884d1d65a42b2" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", ] [[package]] @@ -786,11 +764,11 @@ dependencies = [ [[package]] name = "pin-project" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95b70b68509f17aa2857863b6fa00bf21fc93674c7a8893de2f469f6aa7ca2f2" +checksum = "96fa8ebb90271c4477f144354485b8068bd8f6b78b428b01ba892ca26caf0b63" dependencies = [ - "pin-project-internal 1.0.4", + "pin-project-internal 1.0.5", ] [[package]] @@ -806,9 +784,9 @@ dependencies = [ [[package]] name = "pin-project-internal" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "caa25a6393f22ce819b0f50e0be89287292fda8d425be38ee0ca14c4931d9e71" +checksum = "758669ae3558c6f74bd2a18b41f7ac0b5a195aea6639d6a9b5e5d1ad5ba24c0b" dependencies = [ "proc-macro2", "quote", @@ -996,18 +974,18 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "serde" -version = "1.0.120" +version = "1.0.123" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "166b2349061381baf54a58e4b13c89369feb0ef2eaa57198899e2312aac30aab" +checksum = "92d5161132722baa40d802cc70b15262b98258453e85e5d1d365c757c73869ae" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.120" +version = "1.0.123" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ca2a8cb5805ce9e3b95435e3765b7b553cecc762d938d409434338386cb5775" +checksum = "9391c295d64fc0abb2c556bad848f33cb8296276b1ad2677d1ae1ace4f258f31" dependencies = [ "proc-macro2", "quote", @@ -1027,9 +1005,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.61" +version = "1.0.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fceb2595057b6891a4ee808f70054bd2d12f0e97f1cbb78689b59f676df325a" +checksum = "ea1c6153794552ea7cf7cf63b1231a25de00ec90db326ba6264440fa08e31486" dependencies = [ "itoa", "ryu", @@ -1061,9 +1039,9 @@ dependencies = [ [[package]] name = "serde_yaml" -version = "0.8.15" +version = "0.8.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "971be8f6e4d4a47163b405a3df70d14359186f9ab0f3a3ec37df144ca1ce089f" +checksum = "bdd2af560da3c1fdc02cb80965289254fc35dff869810061e2d8290ee48848ae" dependencies = [ "dtoa", "linked-hash-map", @@ -1130,9 +1108,9 @@ dependencies = [ [[package]] name = "slog-term" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bab1d807cf71129b05ce36914e1dbb6fbfbdecaf686301cb457f4fa967f9f5b6" +checksum = "c76d88c965d3c60da712ef89ba2bca3fd118ed6dead726a9b7153eaddd7a56b1" dependencies = [ "atty", "chrono", @@ -1200,9 +1178,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.58" +version = "1.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc60a3d73ea6594cd712d830cc1f0390fd71542d8c8cd24e70cc54cdfd5e05d5" +checksum = "c700597eca8a5a762beb35753ef6b94df201c81cca676604f547495a0d7f0081" dependencies = [ "proc-macro2", "quote", @@ -1236,11 +1214,11 @@ dependencies = [ [[package]] name = "thread_local" -version = "1.1.0" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb9bc092d0d51e76b2b19d9d85534ffc9ec2db959a2523cdae0697e2972cd447" +checksum = "8018d24e04c95ac8790716a5987d0fec4f8b27249ffa0f7d33f1369bdfb88cbd" dependencies = [ - "lazy_static", + "once_cell", ] [[package]] @@ -1255,9 +1233,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.1.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccf8dbc19eb42fba10e8feaaec282fb50e2c14b2726d6301dbfeed0f73306a6f" +checksum = "317cca572a0e89c3ce0ca1f1bdc9369547fe318a683418e42ac8f59d14701023" dependencies = [ "tinyvec_macros", ] @@ -1270,9 +1248,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.0.2" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ca04cec6ff2474c638057b65798f60ac183e5e79d3448bb7163d36a39cff6ec" +checksum = "e8190d04c665ea9e6b6a0dc45523ade572c088d2e6566244c1122671dbf4ae3a" dependencies = [ "autocfg", "bytes", @@ -1290,40 +1268,27 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "1.0.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42517d2975ca3114b22a16192634e8241dc5cc1f130be194645970cc1c371494" +checksum = "caf7b11a536f46a809a8a9f0bb4237020f70ecbf115b842360afb127ea2fda57" dependencies = [ "proc-macro2", "quote", "syn", ] -[[package]] -name = "tokio-stream" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76066865172052eb8796c686f0b441a93df8b08d40a950b062ffb9a426f00edd" -dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", -] - [[package]] name = "tokio-util" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "feb971a26599ffd28066d387f109746df178eff14d5ea1e235015c5601967a4b" +checksum = "ebb7cb2f00c5ae8df755b252306272cd1790d39728363936e01827e11f0b017b" dependencies = [ - "async-stream", "bytes", "futures-core", "futures-sink", "log", "pin-project-lite", "tokio", - "tokio-stream", ] [[package]] @@ -1337,15 +1302,15 @@ dependencies = [ [[package]] name = "tower-service" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860" +checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" [[package]] name = "tracing" -version = "0.1.22" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f47026cdc4080c07e49b37087de021820269d996f581aac150ef9e5583eefe3" +checksum = "f7d40a22fd029e33300d8d89a5cc8ffce18bb7c587662f54629e94c9de5487f3" dependencies = [ "cfg-if 1.0.0", "pin-project-lite", @@ -1388,9 +1353,9 @@ dependencies = [ [[package]] name = "unicode-normalization" -version = "0.1.16" +version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a13e63ab62dbe32aeee58d1c5408d35c36c392bba5d9d3142287219721afe606" +checksum = "07fbfce1c8a97d547e8b5334978438d9d6ec8c20e38f56d4a4374d181493eaef" dependencies = [ "tinyvec", ] @@ -1465,9 +1430,9 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] name = "wasi" -version = "0.10.1+wasi-snapshot-preview1" +version = "0.10.2+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93c6c3420963c5c64bca373b25e77acb562081b9bb4dd5bb864187742186cea9" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] name = "winapi" diff --git a/src/oxide_controller/mod.rs b/src/oxide_controller/mod.rs index 3b0f710814..d2a5b0467d 100644 --- a/src/oxide_controller/mod.rs +++ b/src/oxide_controller/mod.rs @@ -21,7 +21,6 @@ use http_entrypoints_internal::controller_internal_api; use slog::Logger; use std::sync::Arc; -use tokio::task::JoinHandle; use uuid::Uuid; /** @@ -49,11 +48,6 @@ pub struct OxideControllerServer { pub http_server_external: dropshot::HttpServer, /** dropshot server for internal API */ pub http_server_internal: dropshot::HttpServer, - - /** task handle for the external API server */ - join_handle_external: JoinHandle>, - /** task handle for the internal API server */ - join_handle_internal: JoinHandle>, } impl OxideControllerServer { @@ -71,7 +65,7 @@ impl OxideControllerServer { let apictx = ControllerServerContext::new(rack_id, ctxlog); let c1 = Arc::clone(&apictx); - let mut http_server_external = dropshot::HttpServer::new( + let http_server_starter_external = dropshot::HttpServerStarter::new( &config.dropshot_external, controller_external_api(), c1, @@ -80,7 +74,7 @@ impl OxideControllerServer { .map_err(|error| format!("initializing external server: {}", error))?; let c2 = Arc::clone(&apictx); - let mut http_server_internal = dropshot::HttpServer::new( + let http_server_starter_internal = dropshot::HttpServerStarter::new( &config.dropshot_internal, controller_internal_api(), c2, @@ -88,15 +82,13 @@ impl OxideControllerServer { ) .map_err(|error| format!("initializing internal server: {}", error))?; - let join_handle_external = http_server_external.run(); - let join_handle_internal = http_server_internal.run(); + let http_server_external = http_server_starter_external.start(); + let http_server_internal = http_server_starter_internal.start(); Ok(OxideControllerServer { apictx, http_server_external, http_server_internal, - join_handle_external, - join_handle_internal, }) } @@ -107,15 +99,9 @@ impl OxideControllerServer { * immediately after calling `start()`, the program will block indefinitely * or until something else initiates a graceful shutdown. */ - pub async fn wait_for_finish(mut self) -> Result<(), String> { - let result_external = self - .http_server_external - .wait_for_shutdown(self.join_handle_external) - .await; - let result_internal = self - .http_server_internal - .wait_for_shutdown(self.join_handle_internal) - .await; + pub async fn wait_for_finish(self) -> Result<(), String> { + let result_external = self.http_server_external.await; + let result_internal = self.http_server_internal.await; match (result_external, result_internal) { (Ok(()), Ok(())) => Ok(()), diff --git a/src/sled_agent/mod.rs b/src/sled_agent/mod.rs index a9a9ca84d1..7de6130d78 100644 --- a/src/sled_agent/mod.rs +++ b/src/sled_agent/mod.rs @@ -1,5 +1,5 @@ /*! - * Library interface to the sled agent +* Library interface to the sled agent */ mod config; @@ -19,7 +19,6 @@ use crate::ControllerClient; use sled_agent::SledAgent; use slog::Logger; use std::sync::Arc; -use tokio::task::JoinHandle; /** * Packages up a [`SledAgent`], running the sled agent API under a Dropshot @@ -30,8 +29,6 @@ pub struct SledAgentServer { pub sled_agent: Arc, /** dropshot server for the API */ pub http_server: dropshot::HttpServer, - /** task handle for the dropshot server */ - join_handle: JoinHandle>, } impl SledAgentServer { @@ -63,15 +60,14 @@ impl SledAgentServer { let sa = Arc::clone(&sled_agent); let dropshot_log = log.new(o!("component" => "dropshot")); - let mut http_server = dropshot::HttpServer::new( + let http_server = dropshot::HttpServerStarter::new( &config.dropshot, http_entrypoints::sa_api(), sa, &dropshot_log, ) - .map_err(|error| format!("initializing server: {}", error))?; - - let join_handle = http_server.run(); + .map_err(|error| format!("initializing server: {}", error))? + .start(); /* * Notify the control plane that we're up, and continue trying this @@ -105,7 +101,7 @@ impl SledAgentServer { .expect( "Expected an infinite retry loop contacting the Oxide controller", ); - Ok(SledAgentServer { sled_agent, http_server, join_handle }) + Ok(SledAgentServer { sled_agent, http_server }) } /** @@ -115,8 +111,8 @@ impl SledAgentServer { * immediately after calling `start()`, the program will block indefinitely * or until something else initiates a graceful shutdown. */ - pub async fn wait_for_finish(mut self) -> Result<(), String> { - self.http_server.wait_for_shutdown(self.join_handle).await + pub async fn wait_for_finish(self) -> Result<(), String> { + self.http_server.await } } diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 4c67569d28..f5459fcb15 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -31,14 +31,9 @@ pub struct ControlPlaneTestContext { impl ControlPlaneTestContext { pub async fn teardown(self) { - self.server.http_server_external.close(); - self.server.http_server_internal.close(); - /* - * TODO-correctness - * can we (/ how do we?) wait for these things to shut down? We want to - * use wait_for_finish() here on the http servers. - */ - self.sled_agent.http_server.close(); + self.server.http_server_external.close().await.unwrap(); + self.server.http_server_internal.close().await.unwrap(); + self.sled_agent.http_server.close().await.unwrap(); self.logctx.cleanup_successful(); } } diff --git a/tests/test_basic.rs b/tests/test_basic.rs index 2a40b4bd22..06c0ee2d5c 100644 --- a/tests/test_basic.rs +++ b/tests/test_basic.rs @@ -615,11 +615,7 @@ async fn test_sleds_list() { /* Tear down the agents. */ for sa in sas { - /* - * TODO-correctness see note in testctx.teardown() about shutting down - * sled agents. - */ - sa.http_server.close(); + sa.http_server.close().await.unwrap(); } testctx.teardown().await;