Skip to content

Commit

Permalink
More changes -- will update summary
Browse files Browse the repository at this point in the history
Created using spr 1.3.4
  • Loading branch information
sunshowers committed Oct 5, 2023
1 parent edd6b16 commit 9f7bddd
Show file tree
Hide file tree
Showing 13 changed files with 322 additions and 230 deletions.
6 changes: 2 additions & 4 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ members = [
"caboose-util",
"certificates",
"common",
"crdb-seed",
"ddm-admin-client",
"deploy",
"dev-tools/crdb-seed",
"dev-tools/omdb",
"dev-tools/omicron-dev",
"dev-tools/xtask",
Expand Down Expand Up @@ -76,6 +76,7 @@ default-members = [
"ddm-admin-client",
"dpd-client",
"deploy",
"dev-tools/crdb-seed",
"dev-tools/omdb",
"dev-tools/omicron-dev",
"dev-tools/xtask",
Expand Down
129 changes: 0 additions & 129 deletions crdb-seed/src/main.rs

This file was deleted.

5 changes: 1 addition & 4 deletions crdb-seed/Cargo.toml → dev-tools/crdb-seed/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@ name = "crdb-seed"
version = "0.1.0"
edition = "2021"
license = "MPL-2.0"
readme = "README.md"

[dependencies]
anyhow.workspace = true
camino.workspace = true
camino-tempfile.workspace = true
dropshot.workspace = true
hex.workspace = true
omicron-test-utils.workspace = true
ring.workspace = true
slog.workspace = true
tokio.workspace = true
omicron-workspace-hack.workspace = true
11 changes: 11 additions & 0 deletions dev-tools/crdb-seed/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# crdb-seed

This is a small utility that creates a seed tarball for our CockroachDB instance
in the temporary directory. It is used as a setup script for nextest (see
`.config/nextest.rs`).

This utility hashes inputs and attempts to reuse a tarball if it already exists
(see `digest_unique_to_schema` in `omicron/test-utils/src/dev/seed.rs`).

To invalidate the tarball and cause it to be recreated from scratch, set
`CRDB_SEED_INVALIDATE=1` in the environment.
38 changes: 38 additions & 0 deletions dev-tools/crdb-seed/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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/.

use anyhow::{Context, Result};
use dropshot::{test_util::LogContext, ConfigLogging, ConfigLoggingLevel};
use omicron_test_utils::dev::seed::{
ensure_seed_tarball_exists, should_invalidate_seed,
};
use std::io::Write;

#[tokio::main]
async fn main() -> Result<()> {
// TODO: dropshot is v heavyweight for this, we should be able to pull in a
// smaller binary
let logctx = LogContext::new(
"crdb_seeding",
&ConfigLogging::StderrTerminal { level: ConfigLoggingLevel::Info },
);
let (seed_tar, status) =
ensure_seed_tarball_exists(&logctx.log, should_invalidate_seed())
.await?;
status.log(&logctx.log, &seed_tar);

if let Ok(env_path) = std::env::var("NEXTEST_ENV") {
let mut file = std::fs::File::create(&env_path)
.context("failed to open NEXTEST_ENV file")?;
writeln!(file, "CRDB_SEED_TAR={seed_tar}")
.context("failed to write to NEXTEST_ENV file")?;
} else {
slog::warn!(
logctx.log,
"NEXTEST_ENV not set (is this script running under nextest?)"
);
}

Ok(())
}
2 changes: 0 additions & 2 deletions dev-tools/omicron-dev/src/bin/omicron-dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,6 @@ async fn cmd_run_all(args: &RunAllArgs) -> Result<(), anyhow::Error> {
config.deployment.dropshot_external.dropshot.bind_address.set_port(p);
}

// Start up a ControlPlaneTestContext, which tautologically sets up
// everything needed for a simulated control plane.
println!("omicron-dev: setting up all services ... ");
let cptestctx = nexus_test_utils::test_setup_with_config::<
omicron_nexus::Server,
Expand Down
15 changes: 14 additions & 1 deletion nexus/test-utils/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn seed_tar() -> Utf8PathBuf {
}

/// Wrapper around [`dev::test_setup_database`] which uses a seed tarball
/// provided at build-time.
/// provided from the environment.
pub async fn test_setup_database(log: &Logger) -> dev::db::CockroachInstance {
let input_tar = seed_tar();
dev::test_setup_database(
Expand All @@ -34,6 +34,19 @@ pub async fn test_setup_database(log: &Logger) -> dev::db::CockroachInstance {
.await
}

/// Wrapper around [`dev::test_setup_database`] which uses a seed tarball
/// provided as an argument.
pub async fn test_setup_database_from_seed(
log: &Logger,
input_tar: Utf8PathBuf,
) -> dev::db::CockroachInstance {
dev::test_setup_database(
log,
dev::StorageSource::CopyFromSeed { input_tar },
)
.await
}

/// Creates a new database with no data populated.
///
/// Primarily used for schema change and migration testing.
Expand Down
47 changes: 40 additions & 7 deletions nexus/test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
//! Integration testing facilities for Nexus
use anyhow::Context;
use anyhow::Result;
use camino::Utf8Path;
use camino::Utf8PathBuf;
use dns_service_client::types::DnsConfigParams;
use dropshot::test_util::ClientTestContext;
use dropshot::test_util::LogContext;
Expand Down Expand Up @@ -283,15 +285,37 @@ impl<'a, N: NexusServer> ControlPlaneTestContextBuilder<'a, N> {
}
}

pub async fn start_crdb(&mut self, populate: bool) {
pub async fn ensure_seed_tarball_exists(&self) -> Result<Utf8PathBuf> {
let log = &self.logctx.log;
debug!(log, "Ensuring seed tarball exists");

// Start up a ControlPlaneTestContext, which tautologically sets up
// everything needed for a simulated control plane.
let why_invalidate =
omicron_test_utils::dev::seed::should_invalidate_seed();
let (seed_tar, status) =
omicron_test_utils::dev::seed::ensure_seed_tarball_exists(
log,
why_invalidate,
)
.await
.context("ensuring seed tarball exists")?;
status.log(log, &seed_tar);
Ok(seed_tar)
}

pub async fn start_crdb(&mut self, populate: StartCrdbPopulate) {
let log = &self.logctx.log;
debug!(log, "Starting CRDB");

// Start up CockroachDB.
let database = if populate {
db::test_setup_database(log).await
} else {
db::test_setup_database_empty(log).await
let database = match populate {
StartCrdbPopulate::FromSeed { input_tar } => {
db::test_setup_database_from_seed(log, input_tar).await
}
StartCrdbPopulate::Empty => {
db::test_setup_database_empty(log).await
}
};

eprintln!("DB URL: {}", database.pg_config());
Expand Down Expand Up @@ -759,6 +783,15 @@ impl<'a, N: NexusServer> ControlPlaneTestContextBuilder<'a, N> {
}
}

#[derive(Clone, Debug)]
pub enum StartCrdbPopulate {
/// Populate Cockroach from the seed at this tarball.
FromSeed { input_tar: Utf8PathBuf },

/// Do not populate Cockroach.
Empty,
}

pub async fn test_setup_with_config<N: NexusServer>(
test_name: &str,
config: &mut omicron_common::nexus_config::Config,
Expand All @@ -768,8 +801,8 @@ pub async fn test_setup_with_config<N: NexusServer>(
let mut builder =
ControlPlaneTestContextBuilder::<N>::new(test_name, config);

let populate = true;
builder.start_crdb(populate).await;
let input_tar = builder.ensure_seed_tarball_exists().await.unwrap();
builder.start_crdb(StartCrdbPopulate::FromSeed { input_tar }).await;
builder.start_clickhouse().await;
builder.start_dendrite(SwitchLocation::Switch0).await;
builder.start_dendrite(SwitchLocation::Switch1).await;
Expand Down
2 changes: 2 additions & 0 deletions test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ camino-tempfile.workspace = true
dropshot.workspace = true
futures.workspace = true
headers.workspace = true
hex.workspace = true
http.workspace = true
libc.workspace = true
omicron-common.workspace = true
pem.workspace = true
ring.workspace = true
rustls.workspace = true
slog.workspace = true
subprocess.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion test-utils/src/dev/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ pub enum CockroachStartError {
/// You are **required** to invoke [`CockroachInstance::wait_for_shutdown()`] or
/// [`CockroachInstance::cleanup()`] before this object is dropped.
#[derive(Debug)]
pub struct CockroachInstance {
pub struct CockroachInstance {
/// child process id
pid: u32,
/// PostgreSQL config to use to connect to CockroachDB as a SQL client
Expand Down
Loading

0 comments on commit 9f7bddd

Please sign in to comment.