-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split out mock propolis-server from real thing
The simulated sled-agent in Omicron uses the Propolis mock server as a stand-in for a real VM instance. In order to break an awkward dependencies situation, it would be nice if the mock server did not haul in all everything which propolis-server requires. Fixes #553
- Loading branch information
Showing
11 changed files
with
556 additions
and
263 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
[package] | ||
name = "propolis-mock-server" | ||
version = "0.0.0" | ||
license = "MPL-2.0" | ||
edition = "2021" | ||
|
||
[lib] | ||
name = "propolis_mock_server" | ||
path = "src/lib/lib.rs" | ||
doc = false | ||
doctest = false | ||
test = false | ||
|
||
[[bin]] | ||
name = "propolis-mock-server" | ||
path = "src/main.rs" | ||
doc = false | ||
doctest = false | ||
test = false | ||
|
||
[dependencies] | ||
atty.workspace = true | ||
anyhow.workspace = true | ||
clap = { workspace = true, features = ["derive"] } | ||
base64.workspace = true | ||
dropshot = { workspace = true } | ||
futures.workspace = true | ||
hyper.workspace = true | ||
propolis-client = { workspace = true, features = ["generated"] } | ||
serde_json.workspace = true | ||
slog.workspace = true | ||
slog-async.workspace = true | ||
slog-dtrace.workspace = true | ||
slog-term.workspace = true | ||
slog-bunyan.workspace = true | ||
thiserror.workspace = true | ||
tokio = { workspace = true, features = ["full"] } | ||
tokio-tungstenite.workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
//! Bits copied from propolis-server, rather than splitting them out into some | ||
//! shared dependency | ||
use propolis_client::handmade::api; | ||
use propolis_client::instance_spec::{v0::builder::SpecBuilderError, PciPath}; | ||
|
||
use thiserror::Error; | ||
|
||
#[derive(Clone, Copy, Debug)] | ||
pub(crate) enum SlotType { | ||
Nic, | ||
Disk, | ||
CloudInit, | ||
} | ||
|
||
#[allow(unused)] | ||
#[derive(Debug, Error)] | ||
pub(crate) enum ServerSpecBuilderError { | ||
#[error(transparent)] | ||
InnerBuilderError(#[from] SpecBuilderError), | ||
|
||
#[error("The string {0} could not be converted to a PCI path")] | ||
PciPathNotParseable(String), | ||
|
||
#[error( | ||
"Could not translate PCI slot {0} for device type {1:?} to a PCI path" | ||
)] | ||
PciSlotInvalid(u8, SlotType), | ||
|
||
#[error("Unrecognized storage device interface {0}")] | ||
UnrecognizedStorageDevice(String), | ||
|
||
#[error("Unrecognized storage backend type {0}")] | ||
UnrecognizedStorageBackend(String), | ||
|
||
#[error("Device {0} requested missing backend {1}")] | ||
DeviceMissingBackend(String, String), | ||
|
||
#[error("Error in server config TOML: {0}")] | ||
ConfigTomlError(String), | ||
|
||
#[error("Error serializing {0} into spec element: {1}")] | ||
SerializationError(String, serde_json::error::Error), | ||
} | ||
|
||
pub(crate) fn slot_to_pci_path( | ||
slot: api::Slot, | ||
ty: SlotType, | ||
) -> Result<PciPath, ServerSpecBuilderError> { | ||
match ty { | ||
// Slots for NICS: 0x08 -> 0x0F | ||
SlotType::Nic if slot.0 <= 7 => PciPath::new(0, slot.0 + 0x8, 0), | ||
// Slots for Disks: 0x10 -> 0x17 | ||
SlotType::Disk if slot.0 <= 7 => PciPath::new(0, slot.0 + 0x10, 0), | ||
// Slot for CloudInit | ||
SlotType::CloudInit if slot.0 == 0 => PciPath::new(0, slot.0 + 0x18, 0), | ||
_ => return Err(ServerSpecBuilderError::PciSlotInvalid(slot.0, ty)), | ||
} | ||
.map_err(|_| ServerSpecBuilderError::PciSlotInvalid(slot.0, ty)) | ||
} |
Oops, something went wrong.