diff --git a/linera-service/src/cli_wrappers/local_kubernetes_net.rs b/linera-service/src/cli_wrappers/local_kubernetes_net.rs index 92c9af39f44e..9fbd11913176 100644 --- a/linera-service/src/cli_wrappers/local_kubernetes_net.rs +++ b/linera-service/src/cli_wrappers/local_kubernetes_net.rs @@ -13,7 +13,6 @@ use linera_base::{ data_types::Amount, }; use linera_execution::ResourceControlPolicy; -use tempfile::{tempdir, TempDir}; use tokio::process::Command; #[cfg(with_testing)] use { @@ -49,6 +48,7 @@ pub struct LocalKubernetesNetConfig { pub no_build: bool, pub docker_image_name: String, pub policy: ResourceControlPolicy, + pub path_provider: PathProvider, } /// A wrapper of [`LocalKubernetesNetConfig`] to create a shared local Kubernetes network @@ -62,7 +62,6 @@ pub struct LocalKubernetesNet { network: Network, testing_prng_seed: Option, next_client_id: usize, - tmp_dir: Arc, binaries: BuildArg, no_build: bool, docker_image_name: String, @@ -70,6 +69,7 @@ pub struct LocalKubernetesNet { kind_clusters: Vec, num_initial_validators: usize, num_shards: usize, + path_provider: PathProvider, } #[cfg(with_testing)] @@ -92,6 +92,7 @@ impl SharedLocalKubernetesNetTestingConfig { binaries = BuildArg::Directory(binaries_dir); } } + let path_provider = PathProvider::create_temporary_directory().unwrap(); Self(LocalKubernetesNetConfig { network, testing_prng_seed: Some(37), @@ -103,6 +104,7 @@ impl SharedLocalKubernetesNetTestingConfig { no_build: false, docker_image_name: String::from("linera:latest"), policy: ResourceControlPolicy::devnet(), + path_provider, }) } } @@ -134,6 +136,7 @@ impl LineraNetConfig for LocalKubernetesNetConfig { clusters, self.num_initial_validators, self.num_shards, + self.path_provider, )?; let client = net.make_client().await; @@ -257,11 +260,8 @@ impl LineraNet for LocalKubernetesNet { } async fn make_client(&mut self) -> ClientWrapper { - let path_provider = PathProvider::TemporaryDirectory { - tmp_dir: self.tmp_dir.clone(), - }; let client = ClientWrapper::new( - path_provider, + self.path_provider.clone(), self.network, self.testing_prng_seed, self.next_client_id, @@ -319,12 +319,12 @@ impl LocalKubernetesNet { kind_clusters: Vec, num_initial_validators: usize, num_shards: usize, + path_provider: PathProvider, ) -> Result { Ok(Self { network, testing_prng_seed, next_client_id: 0, - tmp_dir: Arc::new(tempdir()?), binaries, no_build, docker_image_name, @@ -332,19 +332,23 @@ impl LocalKubernetesNet { kind_clusters, num_initial_validators, num_shards, + path_provider, }) } async fn command_for_binary(&self, name: &'static str) -> Result { let path = resolve_binary(name, env!("CARGO_PKG_NAME")).await?; let mut command = Command::new(path); - command.current_dir(self.tmp_dir.path()); + command.current_dir(self.path_provider.path()); Ok(command) } fn configuration_string(&self, server_number: usize) -> Result { let n = server_number; - let path = self.tmp_dir.path().join(format!("validator_{n}.toml")); + let path = self + .path_provider + .path() + .join(format!("validator_{n}.toml")); let port = 19100 + server_number; let internal_port = 20100; let metrics_port = 21100; @@ -418,13 +422,11 @@ impl LocalKubernetesNet { .join("kubernetes") .join("linera-validator") .join("working"); - fs_err::copy( - self.tmp_dir.path().join("genesis.json"), - base_dir.join("genesis.json"), - )?; + let path = self.path_provider.path(); + fs_err::copy(path.join("genesis.json"), base_dir.join("genesis.json"))?; let kubectl_instance_clone = self.kubectl_instance.clone(); - let tmp_dir_path_clone = self.tmp_dir.path().to_path_buf(); + let tmp_dir_path_clone = path.to_path_buf(); let num_shards = self.num_shards; let mut validators_initialization_futures = Vec::new(); diff --git a/linera-service/src/linera/main.rs b/linera-service/src/linera/main.rs index 778b8c0214d0..6c9811d83076 100644 --- a/linera-service/src/linera/main.rs +++ b/linera-service/src/linera/main.rs @@ -1635,7 +1635,7 @@ async fn run(options: &ClientOptions) -> Result { binaries, no_build, docker_image_name, - path: _, + path, storage: _, external_protocol: _, } => { @@ -1650,6 +1650,7 @@ async fn run(options: &ClientOptions) -> Result { *no_build, docker_image_name.clone(), policy_config.into_policy(), + path, ) .boxed() .await?; diff --git a/linera-service/src/linera/net_up_utils.rs b/linera-service/src/linera/net_up_utils.rs index 669527bc2e4a..308be6fc1d34 100644 --- a/linera-service/src/linera/net_up_utils.rs +++ b/linera-service/src/linera/net_up_utils.rs @@ -113,6 +113,7 @@ pub async fn handle_net_up_kubernetes( no_build: bool, docker_image_name: String, policy: ResourceControlPolicy, + path: &Option, ) -> anyhow::Result<()> { if num_initial_validators < 1 { panic!("The local test network must have at least one validator."); @@ -124,6 +125,7 @@ pub async fn handle_net_up_kubernetes( let shutdown_notifier = CancellationToken::new(); tokio::spawn(listen_for_shutdown_signals(shutdown_notifier.clone())); + let path_provider = PathProvider::new(path)?; let config = LocalKubernetesNetConfig { network: Network::Grpc, testing_prng_seed, @@ -135,6 +137,7 @@ pub async fn handle_net_up_kubernetes( no_build, docker_image_name, policy, + path_provider, }; let (mut net, client1) = config.instantiate().await?; net_up(extra_wallets, &mut net, client1).await?;