From 8317398470b410d879d65272e439a7afc6329fa4 Mon Sep 17 00:00:00 2001 From: Andre da Silva Date: Tue, 3 Dec 2024 01:03:15 -0300 Subject: [PATCH] Run existing-net-test in a Kubernetes local network --- .github/workflows/rust.yml | 28 +++++++++++++++++ .../src/cli_wrappers/local_kubernetes_net.rs | 30 ++++++++++--------- linera-service/src/linera/main.rs | 3 +- linera-service/src/linera/net_up_utils.rs | 3 ++ 4 files changed, 49 insertions(+), 15 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 06157c65fe7..bf6802541e8 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -69,6 +69,34 @@ jobs: run: | cargo test -p linera-service existing_net_grpc --features existing-net + existing-kubernetes-net-test: + runs-on: ubuntu-latest-16-cores + timeout-minutes: 40 + + steps: + - uses: actions/checkout@v3 + - uses: actions-rust-lang/setup-rust-toolchain@v1 + - name: Install Protoc + uses: arduino/setup-protoc@v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + - name: Run the validators + run: | + cargo build --release --bin linera --bin linera-proxy --bin linera-server --features kubernetes,scylladb,metrics + strip target/release/linera + strip target/release/linera-proxy + strip target/release/linera-server + mkdir /tmp/local-linera-net + cargo run --features kubernetes --release --bin linera -- net up --kubernetes --binaries --policy-config devnet --path /tmp/local-linera-net --validators 4 --shards 4 & + - name: Create two epochs and run the faucet + run: | + cargo run --release --bin linera -- resource-control-policy --block 0.0000001 + cargo run --release --bin linera -- resource-control-policy --block 0.000000 + cargo run --release --bin linera -- faucet --amount 1000 --port 8079 69705f85ac4c9fef6c02b4d83426aaaf05154c645ec1c61665f8e450f0468bc0 & + - name: Run the existing-net tests + run: | + cargo test -p linera-service existing_net_grpc --features existing-net + execution-wasmtime-test: runs-on: ubuntu-latest timeout-minutes: 10 diff --git a/linera-service/src/cli_wrappers/local_kubernetes_net.rs b/linera-service/src/cli_wrappers/local_kubernetes_net.rs index 92c9af39f44..9fbd1191317 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 bef2749c3cd..7cd973aef90 100644 --- a/linera-service/src/linera/main.rs +++ b/linera-service/src/linera/main.rs @@ -1594,7 +1594,7 @@ async fn run(options: &ClientOptions) -> Result { binaries, no_build, docker_image_name, - path: _, + path, storage: _, external_protocol: _, } => { @@ -1609,6 +1609,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 669527bc2e4..308be6fc1d3 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?;