Skip to content

Commit b6f80ef

Browse files
committed
clean up tempdirs after tests
1 parent 88dd21c commit b6f80ef

File tree

4 files changed

+21
-15
lines changed

4 files changed

+21
-15
lines changed

illumos-utils/src/running_zone.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ impl ZoneBuilderFactory {
10081008

10091009
/// For use in unit tests that don't require actual zone creation to occur.
10101010
pub fn fake(
1011-
temp_dir: Option<&String>,
1011+
temp_dir: Option<&str>,
10121012
zones_api: Arc<dyn crate::zone::Api>,
10131013
) -> Self {
10141014
let temp_dir = match temp_dir {

sled-agent/config-reconciler/src/reconciler_task/zones.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@ mod tests {
682682
use super::*;
683683
use crate::CurrentlyManagedZpoolsReceiver;
684684
use anyhow::anyhow;
685+
use camino_tempfile::Utf8TempDir;
685686
use illumos_utils::dladm::Etherstub;
686687
use illumos_utils::dladm::EtherstubVnic;
687688
use illumos_utils::link::VnicAllocator;
@@ -702,6 +703,7 @@ mod tests {
702703
struct FakeZoneBuilder {
703704
vnic_alloc: VnicAllocator<Etherstub>,
704705
factory: ZoneBuilderFactory,
706+
tempdir: Utf8TempDir,
705707
}
706708

707709
impl FakeZoneBuilder {
@@ -712,11 +714,14 @@ mod tests {
712714
vnic_source,
713715
illumos_utils::fakes::dladm::Dladm::new(),
714716
);
717+
let tempdir =
718+
Utf8TempDir::with_prefix("test-config-reconciler-zones-")
719+
.expect("created temp dir");
715720
let factory = ZoneBuilderFactory::fake(
716-
None,
721+
Some(tempdir.path().as_str()),
717722
illumos_utils::fakes::zone::Zones::new(),
718723
);
719-
Self { vnic_alloc, factory }
724+
Self { vnic_alloc, factory, tempdir }
720725
}
721726

722727
async fn make_running_zone(
@@ -891,7 +896,8 @@ mod tests {
891896
OmicronZones::new(nonexistent_mount_config(), TimeSyncConfig::Skip);
892897

893898
let fake_zone_id = OmicronZoneUuid::new_v4();
894-
let fake_zone = FakeZoneBuilder::new()
899+
let fake_zone_builder = FakeZoneBuilder::new();
900+
let fake_zone = fake_zone_builder
895901
.make_running_zone("test", logctx.log.clone())
896902
.await;
897903
zones.zones.insert(OmicronZone {
@@ -1011,7 +1017,8 @@ mod tests {
10111017
}
10121018

10131019
// Set up our fake sled-agent to return success.
1014-
let fake_zone = FakeZoneBuilder::new()
1020+
let fake_zone_builder = FakeZoneBuilder::new();
1021+
let fake_zone = fake_zone_builder
10151022
.make_running_zone("test", logctx.log.clone())
10161023
.await;
10171024
sled_agent_facilities.push_start_response(Ok(fake_zone));
@@ -1066,7 +1073,8 @@ mod tests {
10661073
},
10671074
image_source: OmicronZoneImageSource::InstallDataset,
10681075
};
1069-
let fake_zone = FakeZoneBuilder::new()
1076+
let fake_zone_builder = FakeZoneBuilder::new();
1077+
let fake_zone = fake_zone_builder
10701078
.make_running_zone("test", logctx.log.clone())
10711079
.await;
10721080

sled-agent/src/instance.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2428,7 +2428,7 @@ mod tests {
24282428
propolis_addr: SocketAddr,
24292429
nexus_client: NexusClient,
24302430
storage_handle: StorageHandle,
2431-
temp_dir: &String,
2431+
temp_dir: &str,
24322432
) -> (Instance, MetricsRx) {
24332433
let id = InstanceUuid::new_v4();
24342434
let propolis_id = PropolisUuid::from_untyped_uuid(PROPOLIS_ID);
@@ -2524,7 +2524,7 @@ mod tests {
25242524
log: &Logger,
25252525
storage_handle: StorageHandle,
25262526
nexus_client: NexusClient,
2527-
temp_dir: &String,
2527+
temp_dir: &str,
25282528
) -> (InstanceManagerServices, MetricsRx) {
25292529
let vnic_allocator = VnicAllocator::new(
25302530
"Instance",
@@ -2579,7 +2579,7 @@ mod tests {
25792579
log,
25802580
storage_harness.handle().clone(),
25812581
nexus.nexus_client.clone(),
2582-
&temp_guard.path().to_string(),
2582+
temp_guard.path().as_str(),
25832583
);
25842584

25852585
let InstanceManagerServices {
@@ -2643,7 +2643,6 @@ mod tests {
26432643
let storage_handle = storage_harness.handle().clone();
26442644

26452645
let temp_guard = Utf8TempDir::new().unwrap();
2646-
let temp_dir = temp_guard.path().to_string();
26472646

26482647
let (inst, mut metrics_rx) = timeout(
26492648
TIMEOUT_DURATION,
@@ -2652,7 +2651,7 @@ mod tests {
26522651
propolis_addr,
26532652
nexus_client,
26542653
storage_handle,
2655-
&temp_dir,
2654+
temp_guard.path().as_str(),
26562655
),
26572656
)
26582657
.await
@@ -2729,7 +2728,6 @@ mod tests {
27292728
let storage_handle = storage_harness.handle().clone();
27302729

27312730
let temp_guard = Utf8TempDir::new().unwrap();
2732-
let temp_dir = temp_guard.path().to_string();
27332731

27342732
let (inst, _) = timeout(
27352733
TIMEOUT_DURATION,
@@ -2739,7 +2737,7 @@ mod tests {
27392737
SocketAddr::V6(SocketAddrV6::new(Ipv6Addr::LOCALHOST, 1, 0, 0)),
27402738
nexus_client,
27412739
storage_handle,
2742-
&temp_dir,
2740+
temp_guard.path().as_str(),
27432741
),
27442742
)
27452743
.await
@@ -3142,7 +3140,7 @@ mod tests {
31423140
&log,
31433141
storage_harness.handle().clone(),
31443142
nexus_client,
3145-
&temp_guard.path().to_string(),
3143+
temp_guard.path().as_str(),
31463144
);
31473145
let propolis_id = PropolisUuid::new_v4();
31483146
let propolis_addr = SocketAddr::V4(SocketAddrV4::new(

sled-agent/src/services.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1744,7 +1744,7 @@ impl ServiceManager {
17441744
let mut zone_builder = match self.inner.system_api.fake_install_dir() {
17451745
None => ZoneBuilderFactory::new().builder(),
17461746
Some(dir) => ZoneBuilderFactory::fake(
1747-
Some(&dir.as_str().to_string()),
1747+
Some(&dir.as_str()),
17481748
illumos_utils::fakes::zone::Zones::new(),
17491749
)
17501750
.builder(),

0 commit comments

Comments
 (0)