Skip to content

Commit 1bdd25f

Browse files
committed
Optionally configure crdb listen port in dev.
At the moment, omicron-dev starts crdb on port 0, which tells the database to use any available port. This is fine for most use cases, but less fine for running a second nexus alongside an existing run-all: https://github.com/oxidecomputer/omicron/blob/main/docs/how-to-run-simulated.adoc#using-both-omicron-dev-run-all-and-running-nexus-manually. This process involves copying the randomly selected ports from the output of run-all and writing them to a custom nexus config. To make the process simpler, this patch allows the user to configure the crdb listen port, defaulting to the current choice of 0.
1 parent 8759bbd commit 1bdd25f

9 files changed

Lines changed: 36 additions & 12 deletions

File tree

dev-tools/omicron-dev/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ nexus-config.workspace = true
2222
nexus-test-interface.workspace = true
2323
nexus-test-utils = { workspace = true, features = ["omicron-dev"] }
2424
omicron-nexus.workspace = true
25+
omicron-test-utils.workspace = true
2526
omicron-workspace-hack.workspace = true
2627
oxide-tokio-rt.workspace = true
2728
# See omicron-rpaths for more about the "pq-sys" dependency.

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use libc::SIGINT;
1111
use nexus_config::NexusConfig;
1212
use nexus_test_interface::NexusServer;
1313
use nexus_test_utils::resource_helpers::DiskTest;
14+
use omicron_test_utils::COCKROACHDB_DEFAULT_LISTEN_PORT;
1415
use signal_hook_tokio::Signals;
1516
use std::fs;
1617

@@ -51,6 +52,9 @@ struct RunAllArgs {
5152
/// Nexus external API listen port. Use `0` to request any available port.
5253
#[clap(long, action)]
5354
nexus_listen_port: Option<u16>,
55+
/// CockroachDB listen port. Use `0` to request any available port.
56+
#[clap(long, default_value_t = COCKROACHDB_DEFAULT_LISTEN_PORT)]
57+
db_listen_port: u16,
5458
/// Override the gateway server configuration file.
5559
#[clap(long, default_value = DEFAULT_SP_SIM_CONFIG)]
5660
gateway_config: Utf8PathBuf,
@@ -88,11 +92,14 @@ impl RunAllArgs {
8892
}
8993

9094
println!("omicron-dev: setting up all services ... ");
91-
let cptestctx = nexus_test_utils::omicron_dev_setup_with_config::<
92-
omicron_nexus::Server,
93-
>(&mut config, 0, self.gateway_config.clone())
94-
.await
95-
.context("error setting up services")?;
95+
let cptestctx =
96+
nexus_test_utils::omicron_dev_setup_with_config::<
97+
omicron_nexus::Server,
98+
>(
99+
&mut config, 0, self.gateway_config.clone(), self.db_listen_port
100+
)
101+
.await
102+
.context("error setting up services")?;
96103

97104
println!("omicron-dev: Adding disks to first sled agent");
98105

nexus/db-queries/src/db/pub_test_utils/crdb.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pub async fn test_setup_database(log: &Logger) -> dev::db::CockroachInstance {
3535
dev::test_setup_database(
3636
log,
3737
dev::StorageSource::CopyFromSeed { input_tar },
38+
dev::db::COCKROACHDB_DEFAULT_LISTEN_PORT,
3839
)
3940
.await
4041
}
@@ -45,18 +46,25 @@ pub async fn test_setup_database(log: &Logger) -> dev::db::CockroachInstance {
4546
pub async fn test_setup_database_empty(
4647
log: &Logger,
4748
) -> dev::db::CockroachInstance {
48-
dev::test_setup_database(log, dev::StorageSource::DoNotPopulate).await
49+
dev::test_setup_database(
50+
log,
51+
dev::StorageSource::DoNotPopulate,
52+
dev::db::COCKROACHDB_DEFAULT_LISTEN_PORT,
53+
)
54+
.await
4955
}
5056

5157
/// Wrapper around [`dev::test_setup_database`] which uses a seed tarball
5258
/// provided as an argument.
5359
pub async fn test_setup_database_from_seed(
5460
log: &Logger,
5561
input_tar: Utf8PathBuf,
62+
listen_port: u16,
5663
) -> dev::db::CockroachInstance {
5764
dev::test_setup_database(
5865
log,
5966
dev::StorageSource::CopyFromSeed { input_tar },
67+
listen_port,
6068
)
6169
.await
6270
}

nexus/test-utils/src/nexus_test.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ pub async fn omicron_dev_setup_with_config<N: NexusServer>(
361361
config: &mut NexusConfig,
362362
extra_sled_agents: u16,
363363
gateway_config_file: Utf8PathBuf,
364+
listen_port: u16,
364365
) -> Result<ControlPlaneTestContext<N>> {
365366
let starter = ControlPlaneStarter::<N>::new("omicron-dev", config);
366367

@@ -382,7 +383,7 @@ pub async fn omicron_dev_setup_with_config<N: NexusServer>(
382383

383384
Ok(setup_with_config_impl(
384385
starter,
385-
PopulateCrdb::FromSeed { input_tar: seed_tar },
386+
PopulateCrdb::FromSeed { input_tar: seed_tar, listen_port },
386387
sim::SimMode::Auto,
387388
None,
388389
extra_sled_agents,

nexus/test-utils/src/starter.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,9 @@ impl<'a, N: NexusServer> ControlPlaneStarter<'a, N> {
265265
crdb::test_setup_database(log).await
266266
}
267267
#[cfg(feature = "omicron-dev")]
268-
PopulateCrdb::FromSeed { input_tar } => {
269-
crdb::test_setup_database_from_seed(log, input_tar).await
268+
PopulateCrdb::FromSeed { input_tar, listen_port } => {
269+
crdb::test_setup_database_from_seed(log, input_tar, listen_port)
270+
.await
270271
}
271272
PopulateCrdb::Empty => crdb::test_setup_database_empty(log).await,
272273
};
@@ -1829,7 +1830,7 @@ pub(crate) enum PopulateCrdb {
18291830

18301831
/// Populate Cockroach from the seed located at this path.
18311832
#[cfg(feature = "omicron-dev")]
1832-
FromSeed { input_tar: camino::Utf8PathBuf },
1833+
FromSeed { input_tar: camino::Utf8PathBuf, listen_port: u16 },
18331834

18341835
/// Do not populate Cockroach.
18351836
Empty,

test-utils/src/dev/db.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const COCKROACHDB_START_TIMEOUT_DEFAULT: Duration = Duration::from_secs(30);
3333
// This is appropriate for the test suite and may be useful in some cases for
3434
// omicron-dev. However, omicron-dev by default chooses a specific port so that
3535
// we can ship a Nexus configuration that will use the same port.
36-
const COCKROACHDB_DEFAULT_LISTEN_PORT: u16 = 0;
36+
pub const COCKROACHDB_DEFAULT_LISTEN_PORT: u16 = 0;
3737

3838
/// CockroachDB database name
3939
// This MUST be kept in sync with dbinit.sql and dbwipe.sql.

test-utils/src/dev/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,21 @@ pub enum StorageSource {
6262
pub async fn test_setup_database(
6363
log: &Logger,
6464
source: StorageSource,
65+
listen_port: u16,
6566
) -> db::CockroachInstance {
6667
usdt::register_probes().expect("Failed to register USDT DTrace probes");
67-
setup_database(log, source).await.unwrap()
68+
setup_database(log, source, listen_port).await.unwrap()
6869
}
6970

7071
// TODO: switch to anyhow entirely -- this function is currently a mishmash of
7172
// anyhow and unwrap/expect calls.
7273
async fn setup_database(
7374
log: &Logger,
7475
storage_source: StorageSource,
76+
listen_port: u16,
7577
) -> Result<db::CockroachInstance> {
7678
let builder = db::CockroachStarterBuilder::new();
79+
let builder = builder.listen_port(listen_port);
7780
let builder = match &storage_source {
7881
StorageSource::DoNotPopulate | StorageSource::CopyFromSeed { .. } => {
7982
builder

test-utils/src/dev/seed.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ pub async fn test_setup_database_seed(
173173
super::StorageSource::PopulateLatest {
174174
output_dir: tmp_seed_dir.path().to_owned(),
175175
},
176+
super::db::COCKROACHDB_DEFAULT_LISTEN_PORT,
176177
)
177178
.await
178179
.context("failed to setup database")?;

test-utils/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ use headers::authorization::Credentials;
1515
pub mod certificates;
1616
pub mod dev;
1717

18+
pub use dev::db::COCKROACHDB_DEFAULT_LISTEN_PORT;
19+
1820
#[macro_use]
1921
extern crate slog;
2022

0 commit comments

Comments
 (0)