Skip to content

Commit a8524a3

Browse files
authored
gateway: versionify; use progenitor client in tests (#8917)
Ticks another box on #8727.
1 parent 33ad127 commit a8524a3

File tree

26 files changed

+203
-183
lines changed

26 files changed

+203
-183
lines changed

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

clients/gateway-client/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ use types::ComponentFirmwareHashStatus;
4848
// call into each other. Since `gateway` is a lower-level service and never
4949
// calls into Nexus, the current scheme is okay.)
5050
progenitor::generate_api!(
51-
spec = "../../openapi/gateway.json",
51+
spec = "../../openapi/gateway/gateway-latest.json",
5252
interface = Positional,
5353
inner_type = slog::Logger,
5454
pre_hook = (|log: &slog::Logger, request: &reqwest::Request| {
@@ -70,6 +70,7 @@ progenitor::generate_api!(
7070
RotImageError = { derives = [ thiserror::Error, PartialEq, Eq, PartialOrd, Ord] },
7171
RotState = { derives = [PartialEq, Eq, PartialOrd, Ord] },
7272
SpComponentCaboose = { derives = [PartialEq, Eq] },
73+
SpComponentInfo = { derives = [PartialEq, Eq] },
7374
SpIdentifier = { derives = [Copy, PartialEq, Hash, Eq] },
7475
SpIgnition = { derives = [PartialEq, Eq, PartialOrd, Ord] },
7576
SpIgnitionSystemType = { derives = [Copy, PartialEq, Eq, PartialOrd, Ord] },
@@ -82,6 +83,8 @@ progenitor::generate_api!(
8283
RotSlot = gateway_types::rot::RotSlot,
8384
Ena = ereport_types::Ena,
8485
Ereport = ereport_types::Ereport,
86+
Ereports = ereport_types::Ereports,
87+
TaskDump = gateway_types::task_dump::TaskDump,
8588
TypedUuidForEreporterRestartKind = omicron_uuid_kinds::EreporterRestartUuid,
8689
TypedUuidForMupdateKind = omicron_uuid_kinds::MupdateUuid,
8790
},

dev-tools/mgs-dev/src/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ impl MgsRunArgs {
8181
.await;
8282
println!("mgs-dev: MGS is running.");
8383

84-
let addr = gwtestctx.client.bind_address;
85-
println!("mgs-dev: MGS API: http://{:?}", addr);
84+
println!("mgs-dev: MGS API: {}", gwtestctx.client.baseurl());
8685

8786
// Wait for a signal.
8887
let caught_signal = signal_stream.next().await;

dev-tools/omdb/tests/successes.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ SP DETAILS: type "Switch" slot 1
231231

232232
---------------------------------------------
233233
stderr:
234-
note: using MGS URL http://[::1]:REDACTED_PORT/
234+
note: using MGS URL http://[::1]:REDACTED_PORT
235235
=============================================
236236
EXECUTING COMMAND: omdb ["nexus", "background-tasks", "doc"]
237237
termination: Exited(0)

dev-tools/omdb/tests/test_all_output.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,12 @@ async fn test_omdb_success_cases(cptestctx: &ControlPlaneTestContext) {
138138
let postgres_url = cptestctx.database.listen_url();
139139
let nexus_internal_url =
140140
format!("http://{}/", cptestctx.internal_client.bind_address);
141-
let mgs_url = format!(
142-
"http://{}/",
143-
cptestctx
144-
.gateway
145-
.get(&SwitchLocation::Switch0)
146-
.expect("nexus_test always sets up MGS on switch 0")
147-
.client
148-
.bind_address
149-
);
141+
let mgs_url = cptestctx
142+
.gateway
143+
.get(&SwitchLocation::Switch0)
144+
.expect("nexus_test always sets up MGS on switch 0")
145+
.client
146+
.baseurl();
150147
let ox_url = format!("http://{}/", cptestctx.oximeter.server_address());
151148
let ox_test_producer = cptestctx.producer.address().ip();
152149
let ch_url = format!("http://{}/", cptestctx.clickhouse.http_address());

dev-tools/omicron-dev/src/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,9 @@ impl RunAllArgs {
149149
);
150150
for (location, gateway) in &cptestctx.gateway {
151151
println!(
152-
"omicron-dev: management gateway: http://{} ({})",
153-
gateway.client.bind_address, location,
152+
"omicron-dev: management gateway: {} ({})",
153+
gateway.client.baseurl(),
154+
location,
154155
);
155156
}
156157
println!("omicron-dev: silo name: {}", cptestctx.silo_name,);

dev-tools/openapi-manager/src/omicron.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub fn all_apis() -> Vec<ManagedApiConfig> {
9898
},
9999
ManagedApiConfig {
100100
title: "Oxide Management Gateway Service API",
101-
versions: Versions::new_lockstep(semver::Version::new(0, 0, 1)),
101+
versions: Versions::new_versioned(gateway_api::supported_versions()),
102102
description: "API for interacting with the Oxide \
103103
control plane's gateway service",
104104
boundary: ApiBoundary::Internal,

gateway-api/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ gateway-types.workspace = true
1414
omicron-common.workspace = true
1515
omicron-uuid-kinds.workspace = true
1616
omicron-workspace-hack.workspace = true
17+
openapi-manager-types.workspace = true
1718
schemars.workspace = true
19+
semver.workspace = true
1820
serde.workspace = true
1921
uuid.workspace = true

gateway-api/src/lib.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,40 @@ use gateway_types::{
2626
SpComponentResetError, SpUpdateStatus,
2727
},
2828
};
29+
use openapi_manager_types::{
30+
SupportedVersion, SupportedVersions, api_versions,
31+
};
2932
use schemars::JsonSchema;
3033
use serde::Deserialize;
3134
use uuid::Uuid;
3235

36+
api_versions!([
37+
// WHEN CHANGING THE API (part 1 of 2):
38+
//
39+
// +- Pick a new semver and define it in the list below. The list MUST
40+
// | remain sorted, which generally means that your version should go at
41+
// | the very top.
42+
// |
43+
// | Duplicate this line, uncomment the *second* copy, update that copy for
44+
// | your new API version, and leave the first copy commented out as an
45+
// | example for the next person.
46+
// v
47+
// (next_int, IDENT),
48+
(1, INITIAL),
49+
]);
50+
51+
// WHEN CHANGING THE API (part 2 of 2):
52+
//
53+
// The call to `api_versions!` above defines constants of type
54+
// `semver::Version` that you can use in your Dropshot API definition to specify
55+
// the version when a particular endpoint was added or removed. For example, if
56+
// you used:
57+
//
58+
// (2, ADD_FOOBAR)
59+
//
60+
// Then you could use `VERSION_ADD_FOOBAR` as the version in which endpoints
61+
// were added or removed.
62+
3363
/// This endpoint is used to upload SP and ROT Hubris archives as well as phase 1 host OS
3464
/// images. The phase 1 image is 32 MiB, driven by the QSPI flash on hardware.
3565
const SP_COMPONENT_UPDATE_MAX_BYTES: usize = 64 * 1024 * 1024;

gateway-test-utils/src/setup.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use camino::Utf8Path;
88
use camino::Utf8PathBuf;
9-
use dropshot::test_util::ClientTestContext;
109
use dropshot::test_util::LogContext;
1110
use gateway_messages::SpPort;
1211
use omicron_gateway::MgsArguments;
@@ -18,7 +17,6 @@ use omicron_test_utils::dev::poll::CondCheckError;
1817
use qorb::resolver::AllBackends;
1918
use qorb::resolver::Resolver;
2019
use qorb::resolvers::fixed::FixedResolver;
21-
use slog::o;
2220
use sp_sim::SimRack;
2321
use sp_sim::SimulatedSp;
2422
use std::collections::HashSet;
@@ -37,8 +35,9 @@ pub const DEFAULT_SP_SIM_CONFIG: &str =
3735
concat!(env!("CARGO_MANIFEST_DIR"), "/configs/sp_sim_config.test.toml");
3836

3937
pub struct GatewayTestContext {
40-
pub client: ClientTestContext,
38+
pub client: gateway_client::Client,
4139
pub server: omicron_gateway::Server,
40+
pub port: u16,
4241
pub simrack: SimRack,
4342
pub logctx: LogContext,
4443
pub gateway_id: Uuid,
@@ -47,13 +46,6 @@ pub struct GatewayTestContext {
4746
}
4847

4948
impl GatewayTestContext {
50-
pub fn client(&self) -> gateway_client::Client {
51-
gateway_client::Client::new(
52-
&self.client.url("/").to_string(),
53-
self.logctx.log.new(slog::o!("component" => "MgsClient")),
54-
)
55-
}
56-
5749
pub fn mgs_backends(&self) -> watch::Receiver<AllBackends> {
5850
self.resolver_backends.clone()
5951
}
@@ -268,9 +260,9 @@ pub async fn test_setup_with_config(
268260
.dropshot_server_for_address(localhost_port_0)
269261
.unwrap()
270262
.local_addr();
271-
let client = ClientTestContext::new(
272-
server_addr,
273-
log.new(o!("component" => "client test context")),
263+
let client = gateway_client::Client::new(
264+
&format!("http://{server_addr}"),
265+
logctx.log.new(slog::o!("component" => "MgsClient")),
274266
);
275267

276268
let mut resolver = FixedResolver::new(std::iter::once(server_addr));
@@ -279,6 +271,7 @@ pub async fn test_setup_with_config(
279271
GatewayTestContext {
280272
client,
281273
server,
274+
port: server_addr.port(),
282275
simrack,
283276
logctx,
284277
gateway_id,

0 commit comments

Comments
 (0)