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

Quiet sled agent tests #1512

Merged
merged 2 commits into from
Jul 29, 2022
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
16 changes: 7 additions & 9 deletions sled-agent/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,7 @@ mod test {
ByteCount, Generation, InstanceCpuCount, InstanceState,
};
use omicron_common::api::internal::nexus::InstanceRuntimeState;
use omicron_test_utils::dev::test_setup_log;
use std::net::IpAddr;
use std::net::Ipv4Addr;

Expand All @@ -821,14 +822,6 @@ mod test {
PROPOLIS_UUID_STR.parse().unwrap()
}

fn logger() -> Logger {
dropshot::ConfigLogging::StderrTerminal {
level: dropshot::ConfigLoggingLevel::Info,
}
.to_logger("test-logger")
.unwrap()
}

fn new_initial_instance() -> InstanceHardware {
InstanceHardware {
runtime: InstanceRuntimeState {
Expand Down Expand Up @@ -874,7 +867,8 @@ mod test {
expected = "Propolis client should be initialized before usage"
)]
async fn transition_before_start() {
let log = logger();
let logctx = test_setup_log("transition_before_start");
let log = &logctx.log;
let vnic_allocator = VnicAllocator::new(
"Test".to_string(),
Etherstub("mylink".to_string()),
Expand All @@ -899,6 +893,10 @@ mod test {
)
.unwrap();

// Remove the logfile before we expect to panic, or it'll never be
// cleaned up.
logctx.cleanup_successful();

// Trying to transition before the instance has been initialized will
// result in a panic.
inst.transition(InstanceRuntimeStateRequested {
Expand Down
23 changes: 11 additions & 12 deletions sled-agent/src/instance_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ mod test {
ByteCount, Generation, InstanceCpuCount, InstanceState,
};
use omicron_common::api::internal::nexus::InstanceRuntimeState;
use omicron_test_utils::dev::test_setup_log;
use std::net::IpAddr;
use std::net::Ipv4Addr;

Expand All @@ -247,14 +248,6 @@ mod test {
INST_UUID_STR.parse().unwrap()
}

fn logger() -> Logger {
dropshot::ConfigLogging::StderrTerminal {
level: dropshot::ConfigLoggingLevel::Info,
}
.to_logger("test-logger")
.unwrap()
}

fn new_initial_instance() -> InstanceHardware {
InstanceHardware {
runtime: InstanceRuntimeState {
Expand Down Expand Up @@ -285,7 +278,8 @@ mod test {
#[tokio::test]
#[serial_test::serial]
async fn ensure_instance() {
let log = logger();
let logctx = test_setup_log("ensure_instance");
let log = &logctx.log;
let lazy_nexus_client =
LazyNexusClient::new(log.clone(), std::net::Ipv6Addr::LOCALHOST)
.unwrap();
Expand All @@ -300,7 +294,7 @@ mod test {
dladm_get_vnics_ctx.expect().return_once(|| Ok(vec![]));

let im = InstanceManager::new(
log,
log.clone(),
lazy_nexus_client,
Etherstub("mylink".to_string()),
std::net::Ipv6Addr::new(
Expand Down Expand Up @@ -366,12 +360,15 @@ mod test {
// the entry is automatically removed from the instance manager.
ticket.lock().unwrap().take();
assert_eq!(im.inner.instances.lock().unwrap().len(), 0);

logctx.cleanup_successful();
}

#[tokio::test]
#[serial_test::serial]
async fn ensure_instance_repeatedly() {
let log = logger();
let logctx = test_setup_log("ensure_instance_repeatedly");
let log = &logctx.log;
let lazy_nexus_client =
LazyNexusClient::new(log.clone(), std::net::Ipv6Addr::LOCALHOST)
.unwrap();
Expand All @@ -385,7 +382,7 @@ mod test {
dladm_get_vnics_ctx.expect().return_once(|| Ok(vec![]));

let im = InstanceManager::new(
log,
log.clone(),
lazy_nexus_client,
Etherstub("mylink".to_string()),
std::net::Ipv6Addr::new(
Expand Down Expand Up @@ -449,5 +446,7 @@ mod test {
assert_eq!(im.inner.instances.lock().unwrap().len(), 1);
ticket.lock().unwrap().take();
assert_eq!(im.inner.instances.lock().unwrap().len(), 0);

logctx.cleanup_successful();
}
}