Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add expectorate tests to manage changes to API dependencies #6831

Merged
merged 2 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions dev-tools/ls-apis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ petgraph.workspace = true
serde.workspace = true
toml.workspace = true
omicron-workspace-hack.workspace = true

[dev-dependencies]
expectorate.workspace = true
omicron-test-utils.workspace = true
subprocess.workspace = true
9 changes: 9 additions & 0 deletions dev-tools/ls-apis/api-manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ client_package_name = "bootstrap-agent-client"
label = "Bootstrap Agent"
server_package_name = "bootstrap-agent-api"

[[apis]]
client_package_name = "clickhouse-admin-client"
label = "Clickhouse Cluster Admin"
server_package_name = "clickhouse-admin-api"
notes = """
This is the server running inside multi-node Clickhouse zones that's \
responsible for local configuration and monitoring.
"""

[[apis]]
client_package_name = "cockroach-admin-client"
label = "CockroachDB Cluster Admin"
Expand Down
26 changes: 25 additions & 1 deletion dev-tools/ls-apis/src/system_apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,17 @@ impl SystemApis {
// Load Cargo metadata and validate it against the manifest.
let (workspaces, warnings) = Workspaces::load(&api_metadata)?;
if !warnings.is_empty() {
// We treat these warnings as fatal here.
for e in warnings {
eprintln!("warning: {:#}", e);
eprintln!("error: {:#}", e);
}

bail!(
"found inconsistency between API manifest ({}) and \
information found from the Cargo dependency tree \
(see above)",
&args.api_manifest_path
);
}

// Create an index of server package names, mapping each one to the API
Expand Down Expand Up @@ -436,6 +444,22 @@ impl<'a> ServerComponentsTracker<'a> {
return;
}

// TODO Work around omicron#6829.
// Through the dependency tree, omicron-nexus appears to export the
// clickhouse-admin-api, but it doesn't really.
// This is just like the Crucible Pantry one above in that we can't
// build our data model unless we ignore it so we have to hardcode this
// here rather than use "dependency_filter_rules".
if **server_pkgname == "omicron-nexus"
&& *api.client_package_name == "clickhouse-admin-client"
{
eprintln!(
"note: ignoring Cargo dependency from crucible-pantry -> \
... -> crucible-control-client",
);
return;
}

if let Some((previous, _)) = self.api_producers.insert(
api.client_package_name.clone(),
(server_pkgname.clone(), dep_path.clone()),
Expand Down
6 changes: 3 additions & 3 deletions dev-tools/ls-apis/src/workspaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Workspaces {
/// The data found is validated against `api_metadata`.
///
/// On success, returns `(workspaces, warnings)`, where `warnings` is a list
/// of potential inconsistencies between API metadata and Cargo metadata.
/// of inconsistencies between API metadata and Cargo metadata.
pub fn load(
api_metadata: &AllApiMetadata,
) -> Result<(Workspaces, Vec<anyhow::Error>)> {
Expand Down Expand Up @@ -114,8 +114,8 @@ impl Workspaces {
client_pkgnames_unused.remove(client_pkgname);
} else {
warnings.push(anyhow!(
"workspace {}: found client package missing from API \
manifest: {}",
"workspace {}: found Progenitor-based client package \
missing from API manifest: {}",
workspace.name(),
client_pkgname
));
Expand Down
77 changes: 77 additions & 0 deletions dev-tools/ls-apis/tests/api_dependencies.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
Bootstrap Agent (client: bootstrap-agent-client)
consumed by: omicron-sled-agent (omicron/sled-agent)
consumed by: wicketd (omicron/wicketd)

Clickhouse Cluster Admin (client: clickhouse-admin-client)
consumed by: omicron-nexus (omicron/nexus)

CockroachDB Cluster Admin (client: cockroach-admin-client)
consumed by: omicron-nexus (omicron/nexus)

Crucible Agent (client: crucible-agent-client)
consumed by: omicron-nexus (omicron/nexus)

Crucible Control (for testing only) (client: crucible-control-client)

Crucible Pantry (client: crucible-pantry-client)
consumed by: omicron-nexus (omicron/nexus)

Maghemite DDM Admin (client: ddm-admin-client)
consumed by: installinator (omicron/installinator)
consumed by: mgd (maghemite/mgd)
consumed by: omicron-sled-agent (omicron/sled-agent)
consumed by: wicketd (omicron/wicketd)

DNS Server (client: dns-service-client)
consumed by: omicron-nexus (omicron/nexus)
consumed by: omicron-sled-agent (omicron/sled-agent)

Dendrite DPD (client: dpd-client)
consumed by: ddmd (maghemite/ddmd)
consumed by: mgd (maghemite/mgd)
consumed by: omicron-nexus (omicron/nexus)
consumed by: omicron-sled-agent (omicron/sled-agent)
consumed by: tfportd (dendrite/tfportd)
consumed by: wicketd (omicron/wicketd)

Downstairs Controller (debugging only) (client: dsc-client)

Management Gateway Service (client: gateway-client)
consumed by: dpd (dendrite/dpd)
consumed by: omicron-nexus (omicron/nexus)
consumed by: omicron-sled-agent (omicron/sled-agent)
consumed by: wicketd (omicron/wicketd)

Wicketd Installinator (client: installinator-client)
consumed by: installinator (omicron/installinator)

Maghemite MG Admin (client: mg-admin-client)
consumed by: omicron-nexus (omicron/nexus)
consumed by: omicron-sled-agent (omicron/sled-agent)

Nexus Internal API (client: nexus-client)
consumed by: dpd (dendrite/dpd)
consumed by: omicron-nexus (omicron/nexus)
consumed by: omicron-sled-agent (omicron/sled-agent)
consumed by: oximeter-collector (omicron/oximeter/collector)
consumed by: propolis-server (propolis/bin/propolis-server)

External API (client: oxide-client)

Oximeter (client: oximeter-client)
consumed by: omicron-nexus (omicron/nexus)

Propolis (client: propolis-client)
consumed by: omicron-nexus (omicron/nexus)
consumed by: omicron-sled-agent (omicron/sled-agent)

Crucible Repair (client: repair-client)
consumed by: crucible-downstairs (crucible/downstairs)

Sled Agent (client: sled-agent-client)
consumed by: dpd (dendrite/dpd)
consumed by: omicron-nexus (omicron/nexus)
consumed by: omicron-sled-agent (omicron/sled-agent)

Wicketd (client: wicketd-client)

29 changes: 29 additions & 0 deletions dev-tools/ls-apis/tests/test_dependencies.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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/.

//! The tests here are intended help us catch cases where we're introducing new
//! API dependencies, and particular circular API dependencies. It's okay if
//! API dependencies change, but it's important to make sure we're not
//! introducing new barriers to online upgrade.
//!
//! This isn't (supposed to be) a test for the `ls-apis` tool itself.

use omicron_test_utils::dev::test_cmds::assert_exit_code;
use omicron_test_utils::dev::test_cmds::path_to_executable;
use omicron_test_utils::dev::test_cmds::run_command;
use omicron_test_utils::dev::test_cmds::EXIT_SUCCESS;

/// name of the "ls-apis" executable
const CMD_LS_APIS: &str = env!("CARGO_BIN_EXE_ls-apis");

#[test]
fn test_api_dependencies() {
let cmd_path = path_to_executable(CMD_LS_APIS);
let exec = subprocess::Exec::cmd(cmd_path).arg("apis");
let (exit_status, stdout_text, stderr_text) = run_command(exec);
assert_exit_code(exit_status, EXIT_SUCCESS, &stderr_text);

println!("stderr:\n------\n{}\n-----", stderr_text);
expectorate::assert_contents("tests/api_dependencies.out", &stdout_text);
}
Loading