Skip to content
Open
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
20 changes: 18 additions & 2 deletions dev-tools/omicron-dev/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,18 @@ enum OmicronDevCmd {

#[derive(Clone, Debug, Args)]
struct RunAllArgs {
/// Nexus external API listen port. Use `0` to request any available port.
/// Nexus external API listen port. Use `0` to request any available port.
#[clap(long, action)]
nexus_listen_port: Option<u16>,
/// CockroachDB listen port. Use `0` to request any available port.
#[clap(long)]
db_listen_port: Option<u16>,
/// Internal DNS listen port. Use `0` to request any available port.
#[clap(long)]
internal_dns_listen_port: Option<u16>,
/// Management gateway listen port. Use `0` to request any available port.
#[clap(long)]
mgs_listen_port: Option<u16>,
/// Override the gateway server configuration file.
#[clap(long, default_value = DEFAULT_SP_SIM_CONFIG)]
gateway_config: Utf8PathBuf,
Expand Down Expand Up @@ -90,7 +99,14 @@ impl RunAllArgs {
println!("omicron-dev: setting up all services ... ");
let cptestctx = nexus_test_utils::omicron_dev_setup_with_config::<
omicron_nexus::Server,
>(&mut config, 0, self.gateway_config.clone())
>(
&mut config,
0,
self.gateway_config.clone(),
self.db_listen_port,
self.internal_dns_listen_port,
self.mgs_listen_port,
)
.await
.context("error setting up services")?;

Expand Down
5 changes: 4 additions & 1 deletion nexus/db-queries/src/db/pub_test_utils/crdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub async fn test_setup_database(log: &Logger) -> dev::db::CockroachInstance {
dev::test_setup_database(
log,
dev::StorageSource::CopyFromSeed { input_tar },
None,
)
.await
}
Expand All @@ -45,18 +46,20 @@ pub async fn test_setup_database(log: &Logger) -> dev::db::CockroachInstance {
pub async fn test_setup_database_empty(
log: &Logger,
) -> dev::db::CockroachInstance {
dev::test_setup_database(log, dev::StorageSource::DoNotPopulate).await
dev::test_setup_database(log, dev::StorageSource::DoNotPopulate, None).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,
listen_port: Option<u16>,
) -> dev::db::CockroachInstance {
dev::test_setup_database(
log,
dev::StorageSource::CopyFromSeed { input_tar },
listen_port,
)
.await
}
8 changes: 7 additions & 1 deletion nexus/test-utils/src/nexus_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,14 @@ pub async fn omicron_dev_setup_with_config<N: NexusServer>(
config: &mut NexusConfig,
extra_sled_agents: u16,
gateway_config_file: Utf8PathBuf,
db_listen_port: Option<u16>,
internal_dns_listen_port: Option<u16>,
mgs_listen_port: Option<u16>,
) -> Result<ControlPlaneTestContext<N>> {
let starter = ControlPlaneStarter::<N>::new("omicron-dev", config);
let mut starter = ControlPlaneStarter::<N>::new("omicron-dev", config);
starter.db_listen_port(db_listen_port);
starter.internal_dns_listen_port(internal_dns_listen_port);
starter.mgs_listen_port(mgs_listen_port);

let log = &starter.logctx.log;
debug!(log, "Ensuring seed tarball exists");
Expand Down
43 changes: 39 additions & 4 deletions nexus/test-utils/src/starter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ pub struct ControlPlaneStarter<'a, N: NexusServer> {
pub password: Option<String>,

pub simulated_upstairs: Arc<sim::SimulatedUpstairs>,

db_listen_port: Option<u16>,
internal_dns_listen_port: Option<u16>,
mgs_listen_port: Option<u16>,
}

type StepInitFn<'a, N> = Box<
Expand Down Expand Up @@ -216,9 +220,24 @@ impl<'a, N: NexusServer> ControlPlaneStarter<'a, N> {
simulated_upstairs: Arc::new(sim::SimulatedUpstairs::new(
simulated_upstairs_log,
)),
db_listen_port: None,
internal_dns_listen_port: None,
mgs_listen_port: None,
}
}

pub fn db_listen_port(&mut self, port: Option<u16>) {
self.db_listen_port = port;
}

pub fn internal_dns_listen_port(&mut self, port: Option<u16>) {
self.internal_dns_listen_port = port;
}

pub fn mgs_listen_port(&mut self, port: Option<u16>) {
self.mgs_listen_port = port;
}

pub async fn init_with_steps(
&mut self,
steps: Vec<(&str, StepInitFn<'a, N>)>,
Expand Down Expand Up @@ -266,7 +285,12 @@ impl<'a, N: NexusServer> ControlPlaneStarter<'a, N> {
}
#[cfg(feature = "omicron-dev")]
PopulateCrdb::FromSeed { input_tar } => {
crdb::test_setup_database_from_seed(log, input_tar).await
crdb::test_setup_database_from_seed(
log,
input_tar,
self.db_listen_port,
)
.await
}
PopulateCrdb::Empty => crdb::test_setup_database_empty(log).await,
};
Expand Down Expand Up @@ -1200,7 +1224,18 @@ impl<'a, N: NexusServer> ControlPlaneStarter<'a, N> {
/// Set up an internal DNS server on the first sled agent
pub async fn start_internal_dns(&mut self) {
let log = self.logctx.log.new(o!("component" => "internal_dns_server"));
let dns = dns_server::TransientServer::new(&log).await.unwrap();
let dns_addr = SocketAddrV6::new(
Ipv6Addr::LOCALHOST,
self.internal_dns_listen_port.unwrap_or(0),
0,
0,
);
let dns = dns_server::TransientServer::new_with_address(
&log,
dns_addr.into(),
)
.await
.unwrap();

let SocketAddr::V6(dns_address) = dns.dns_server.local_address() else {
panic!("Unsupported IPv4 DNS address");
Expand Down Expand Up @@ -1621,7 +1656,7 @@ pub(crate) async fn setup_with_config_impl<N: NexusServer>(
builder
.start_gateway(
SwitchLocation::Switch0,
None,
builder.mgs_listen_port,
mgs_config,
)
.boxed()
Expand Down Expand Up @@ -1665,7 +1700,7 @@ pub(crate) async fn setup_with_config_impl<N: NexusServer>(
builder
.start_gateway(
SwitchLocation::Switch1,
None,
builder.mgs_listen_port,
gateway_config_file,
)
.boxed()
Expand Down
5 changes: 4 additions & 1 deletion test-utils/src/dev/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,21 @@ pub enum StorageSource {
pub async fn test_setup_database(
log: &Logger,
source: StorageSource,
listen_port: Option<u16>,
) -> db::CockroachInstance {
usdt::register_probes().expect("Failed to register USDT DTrace probes");
setup_database(log, source).await.unwrap()
setup_database(log, source, listen_port).await.unwrap()
}

// TODO: switch to anyhow entirely -- this function is currently a mishmash of
// anyhow and unwrap/expect calls.
async fn setup_database(
log: &Logger,
storage_source: StorageSource,
listen_port: Option<u16>,
) -> Result<db::CockroachInstance> {
let builder = db::CockroachStarterBuilder::new();
let builder = builder.listen_port(listen_port.unwrap_or(0));
let builder = match &storage_source {
StorageSource::DoNotPopulate | StorageSource::CopyFromSeed { .. } => {
builder
Expand Down
1 change: 1 addition & 0 deletions test-utils/src/dev/seed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ pub async fn test_setup_database_seed(
super::StorageSource::PopulateLatest {
output_dir: tmp_seed_dir.path().to_owned(),
},
None,
)
.await
.context("failed to setup database")?;
Expand Down
Loading