Skip to content

Commit

Permalink
draw the rest of the owl
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkw committed Dec 3, 2024
1 parent b1392f7 commit b08747a
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 43 deletions.
5 changes: 3 additions & 2 deletions nexus/src/app/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ impl From<SledAgentInstanceError> for omicron_common::api::external::Error {

impl From<SledAgentInstanceError> for dropshot::HttpError {
fn from(value: SledAgentInstanceError) -> Self {
use dropshot::ErrorStatusCode;
use dropshot::HttpError;
use progenitor_client::Error as ClientError;
// See RFD 486 §6.3:
Expand All @@ -118,9 +119,9 @@ impl From<SledAgentInstanceError> for dropshot::HttpError {
// See https://github.com/oxidecomputer/dropshot/issues/693
let mut error = HttpError::for_internal_error(e.to_string());
error.status_code = if e.is_timeout() {
http::StatusCode::GATEWAY_TIMEOUT
ErrorStatusCode::GATEWAY_TIMEOUT
} else {
http::StatusCode::BAD_GATEWAY
ErrorStatusCode::BAD_GATEWAY
};
error
}
Expand Down
2 changes: 1 addition & 1 deletion nexus/test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1694,7 +1694,7 @@ pub async fn start_dns_server(
},
&dropshot::ConfigDropshot {
bind_address: "[::1]:0".parse().unwrap(),
request_body_max_bytes: 8 * 1024,
default_request_body_max_bytes: 8 * 1024,
default_handler_task_mode: HandlerTaskMode::Detached,
log_headers: vec![],
},
Expand Down
3 changes: 1 addition & 2 deletions sled-agent/src/artifact_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use dropshot::{
RequestContext, ServerBuilder, StreamingBody,
};
use futures::{Stream, TryStreamExt};
use http::StatusCode;
use omicron_common::address::REPO_DEPOT_PORT;
use omicron_common::disk::{DatasetKind, DatasetsConfig};
use omicron_common::update::ArtifactHash;
Expand Down Expand Up @@ -689,7 +688,7 @@ impl From<Error> for HttpError {
match err {
Error::AlreadyInProgress { .. } => HttpError::for_client_error(
None,
StatusCode::CONFLICT,
dropshot::ClientErrorStatusCode::CONFLICT,
err.to_string(),
),
Error::Body(inner) => inner,
Expand Down
2 changes: 1 addition & 1 deletion sled-agent/src/boot_disk_os_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl From<&BootDiskOsWriteError> for HttpError {
| BootDiskOsWriteError::FailedReadingDisk { .. }
| BootDiskOsWriteError::WrittenImageHashMismatch { .. } => {
HttpError {
status_code: http::StatusCode::SERVICE_UNAVAILABLE,
status_code: dropshot::ErrorStatusCode::SERVICE_UNAVAILABLE,
error_code: None,
external_message: message.clone(),
internal_message: message,
Expand Down
5 changes: 2 additions & 3 deletions sled-agent/src/bootstrap/http_entrypoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use dropshot::{
ApiDescription, HttpError, HttpResponseOk, HttpResponseUpdatedNoContent,
RequestContext, TypedBody,
};
use http::StatusCode;
use omicron_common::api::external::Error;
use omicron_uuid_kinds::RackInitUuid;
use omicron_uuid_kinds::RackResetUuid;
Expand Down Expand Up @@ -143,9 +142,9 @@ impl BootstrapAgentApi for BootstrapAgentImpl {
match ctx.sled_reset_tx.try_send(response_tx) {
Ok(()) => (),
Err(TrySendError::Full(_)) => {
return Err(HttpError::for_status(
return Err(HttpError::for_client_error_with_status(
Some("ResetPending".to_string()),
StatusCode::TOO_MANY_REQUESTS,
dropshot::ClientErrorStatusCode::TOO_MANY_REQUESTS,
));
}
Err(TrySendError::Closed(_)) => {
Expand Down
2 changes: 1 addition & 1 deletion sled-agent/src/bootstrap/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ fn start_dropshot_server(
context: BootstrapServerContext,
) -> Result<HttpServer<BootstrapServerContext>, StartError> {
let mut dropshot_config = dropshot::ConfigDropshot::default();
dropshot_config.request_body_max_bytes = 1024 * 1024;
dropshot_config.default_request_body_max_bytes = 1024 * 1024;
dropshot_config.bind_address = SocketAddr::V6(SocketAddrV6::new(
context.global_zone_bootstrap_ip,
BOOTSTRAP_AGENT_HTTP_PORT,
Expand Down
14 changes: 7 additions & 7 deletions sled-agent/src/http_entrypoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ use bootstore::schemes::v0::NetworkConfig;
use camino::Utf8PathBuf;
use display_error_chain::DisplayErrorChain;
use dropshot::{
ApiDescription, Body, FreeformBody, HttpError, HttpResponseAccepted,
HttpResponseCreated, HttpResponseDeleted, HttpResponseHeaders,
HttpResponseOk, HttpResponseUpdatedNoContent, Path, Query, RequestContext,
StreamingBody, TypedBody,
ApiDescription, Body, ErrorStatusCode, FreeformBody, HttpError,
HttpResponseAccepted, HttpResponseCreated, HttpResponseDeleted,
HttpResponseHeaders, HttpResponseOk, HttpResponseUpdatedNoContent, Path,
Query, RequestContext, StreamingBody, TypedBody,
};
use nexus_sled_agent_shared::inventory::{
Inventory, OmicronZonesConfig, SledRole,
Expand Down Expand Up @@ -704,7 +704,7 @@ impl SledAgentApi for SledAgentImpl {
.map_err(|e| {
let message = format!("Failed to add sled to rack cluster: {e}");
HttpError {
status_code: http::StatusCode::INTERNAL_SERVER_ERROR,
status_code: ErrorStatusCode::INTERNAL_SERVER_ERROR,
error_code: None,
external_message: message.clone(),
internal_message: message,
Expand Down Expand Up @@ -755,7 +755,7 @@ impl SledAgentApi for SledAgentImpl {
DisplayErrorChain::new(&err)
);
return Err(HttpError {
status_code: http::StatusCode::SERVICE_UNAVAILABLE,
status_code: ErrorStatusCode::SERVICE_UNAVAILABLE,
error_code: None,
external_message: message.clone(),
internal_message: message,
Expand All @@ -764,7 +764,7 @@ impl SledAgentApi for SledAgentImpl {
None => {
let message = format!("no disk found for slot {boot_disk:?}",);
return Err(HttpError {
status_code: http::StatusCode::SERVICE_UNAVAILABLE,
status_code: ErrorStatusCode::SERVICE_UNAVAILABLE,
error_code: None,
external_message: message.clone(),
internal_message: message,
Expand Down
4 changes: 2 additions & 2 deletions sled-agent/src/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2359,7 +2359,7 @@ impl ServiceManager {
bind_address: SocketAddr::new(*opte_ip, nexus_port),
// This has to be large enough to support:
// - bulk writes to disks
request_body_max_bytes: 8192 * 1024,
default_request_body_max_bytes: 8192 * 1024,
default_handler_task_mode:
HandlerTaskMode::Detached,
log_headers: vec![],
Expand All @@ -2371,7 +2371,7 @@ impl ServiceManager {
// other things, the initial list of TLS
// certificates provided by the customer during
// rack setup.
request_body_max_bytes: 10 * 1024 * 1024,
default_request_body_max_bytes: 10 * 1024 * 1024,
default_handler_task_mode: HandlerTaskMode::Detached,
log_headers: vec![],
},
Expand Down
2 changes: 1 addition & 1 deletion sled-agent/src/sim/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl Config {
nexus_address,
dropshot: ConfigDropshot {
bind_address: SocketAddr::new(Ipv6Addr::LOCALHOST.into(), 0),
request_body_max_bytes: 1024 * 1024,
default_request_body_max_bytes: 1024 * 1024,
..Default::default()
},
storage: ConfigStorage {
Expand Down
3 changes: 2 additions & 1 deletion sled-agent/src/sim/http_entrypoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use super::collection::PokeMode;
use camino::Utf8PathBuf;
use dropshot::endpoint;
use dropshot::ApiDescription;
use dropshot::ErrorStatusCode;
use dropshot::FreeformBody;
use dropshot::HttpError;
use dropshot::HttpResponseAccepted;
Expand Down Expand Up @@ -660,7 +661,7 @@ fn method_unimplemented<T>() -> Result<T, HttpError> {
// Use a client error here (405 Method Not Allowed vs 501 Not
// Implemented) even though it isn't strictly accurate here, so tests
// get to see the error message.
status_code: http::StatusCode::METHOD_NOT_ALLOWED,
status_code: ErrorStatusCode::METHOD_NOT_ALLOWED,
error_code: None,
external_message: "Method not implemented in sled-agent-sim"
.to_string(),
Expand Down
4 changes: 2 additions & 2 deletions sled-agent/src/sim/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1029,15 +1029,15 @@ impl Storage {
if stored_config.generation > config.generation {
return Err(HttpError::for_client_error(
None,
http::StatusCode::BAD_REQUEST,
dropshot::ClientErrorStatusCode::BAD_REQUEST,
"Generation number too old".to_string(),
));
} else if stored_config.generation == config.generation
&& *stored_config != config
{
return Err(HttpError::for_client_error(
None,
http::StatusCode::BAD_REQUEST,
dropshot::ClientErrorStatusCode::BAD_REQUEST,
"Generation number unchanged but data is different"
.to_string(),
));
Expand Down
48 changes: 29 additions & 19 deletions sled-agent/src/sled_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ impl From<Error> for omicron_common::api::external::Error {
// Provide a more specific HTTP error for some sled agent errors.
impl From<Error> for dropshot::HttpError {
fn from(err: Error) -> Self {
use dropshot::ClientErrorStatusCode;
use dropshot::ErrorStatusCode;

const NO_SUCH_INSTANCE: &str = "NO_SUCH_INSTANCE";
const INSTANCE_CHANNEL_FULL: &str = "INSTANCE_CHANNEL_FULL";
match err {
Expand All @@ -213,25 +216,32 @@ impl From<Error> for dropshot::HttpError {
)
}
crate::instance::Error::Propolis(propolis_error) => {
// Work around dropshot#693: HttpError::for_status
// only accepts client errors and asserts on server
// errors, so convert server errors by hand.
match propolis_error.status() {
None => HttpError::for_internal_error(
if let Some(status_code) =
propolis_error.status().and_then(|status| {
ErrorStatusCode::try_from(status).ok()
})
{
if let Ok(status_code) =
status_code.as_client_error()
{
return HttpError::for_client_error_with_status(
None,
status_code,
);
}

if status_code
== ErrorStatusCode::SERVICE_UNAVAILABLE
{
return HttpError::for_unavail(
None,
propolis_error.to_string(),
),

Some(status_code) if status_code.is_client_error() => {
HttpError::for_status(None, status_code)
},

Some(status_code) => match status_code {
http::status::StatusCode::SERVICE_UNAVAILABLE =>
HttpError::for_unavail(None, propolis_error.to_string()),
_ =>
HttpError::for_internal_error(propolis_error.to_string()),
}
);
}
}
HttpError::for_internal_error(
propolis_error.to_string(),
)
}
crate::instance::Error::Transition(omicron_error) => {
// Preserve the status associated with the wrapped
Expand All @@ -242,7 +252,7 @@ impl From<Error> for dropshot::HttpError {
crate::instance::Error::Terminating => {
HttpError::for_client_error(
Some(NO_SUCH_INSTANCE.to_string()),
http::StatusCode::GONE,
ClientErrorStatusCode::GONE,
instance_error.to_string(),
)
}
Expand Down Expand Up @@ -270,7 +280,7 @@ impl From<Error> for dropshot::HttpError {
BundleError::InstanceTerminating => {
HttpError::for_client_error(
Some(NO_SUCH_INSTANCE.to_string()),
http::StatusCode::GONE,
ClientErrorStatusCode::GONE,
inner.to_string(),
)
}
Expand Down
1 change: 0 additions & 1 deletion wicketd/src/http_entrypoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use dropshot::Path;
use dropshot::RequestContext;
use dropshot::StreamingBody;
use dropshot::TypedBody;
use http::StatusCode;
use internal_dns_resolver::Resolver;
use omicron_common::api::internal::shared::SwitchLocation;
use omicron_uuid_kinds::RackInitUuid;
Expand Down

0 comments on commit b08747a

Please sign in to comment.