Skip to content

Commit

Permalink
Run existing-net-test in a Kubernetes local network
Browse files Browse the repository at this point in the history
  • Loading branch information
ndr-ds committed Dec 4, 2024
1 parent f4c382a commit 8317398
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 15 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 16 additions & 14 deletions linera-service/src/cli_wrappers/local_kubernetes_net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -62,14 +62,14 @@ pub struct LocalKubernetesNet {
network: Network,
testing_prng_seed: Option<u64>,
next_client_id: usize,
tmp_dir: Arc<TempDir>,
binaries: BuildArg,
no_build: bool,
docker_image_name: String,
kubectl_instance: Arc<Mutex<KubectlInstance>>,
kind_clusters: Vec<KindCluster>,
num_initial_validators: usize,
num_shards: usize,
path_provider: PathProvider,
}

#[cfg(with_testing)]
Expand All @@ -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),
Expand All @@ -103,6 +104,7 @@ impl SharedLocalKubernetesNetTestingConfig {
no_build: false,
docker_image_name: String::from("linera:latest"),
policy: ResourceControlPolicy::devnet(),
path_provider,
})
}
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -319,32 +319,36 @@ impl LocalKubernetesNet {
kind_clusters: Vec<KindCluster>,
num_initial_validators: usize,
num_shards: usize,
path_provider: PathProvider,
) -> Result<Self> {
Ok(Self {
network,
testing_prng_seed,
next_client_id: 0,
tmp_dir: Arc::new(tempdir()?),
binaries,
no_build,
docker_image_name,
kubectl_instance: Arc::new(Mutex::new(kubectl_instance)),
kind_clusters,
num_initial_validators,
num_shards,
path_provider,
})
}

async fn command_for_binary(&self, name: &'static str) -> Result<Command> {
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<String> {
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;
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion linera-service/src/linera/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1594,7 +1594,7 @@ async fn run(options: &ClientOptions) -> Result<i32, anyhow::Error> {
binaries,
no_build,
docker_image_name,
path: _,
path,
storage: _,
external_protocol: _,
} => {
Expand All @@ -1609,6 +1609,7 @@ async fn run(options: &ClientOptions) -> Result<i32, anyhow::Error> {
*no_build,
docker_image_name.clone(),
policy_config.into_policy(),
path,
)
.boxed()
.await?;
Expand Down
3 changes: 3 additions & 0 deletions linera-service/src/linera/net_up_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ pub async fn handle_net_up_kubernetes(
no_build: bool,
docker_image_name: String,
policy: ResourceControlPolicy,
path: &Option<String>,
) -> anyhow::Result<()> {
if num_initial_validators < 1 {
panic!("The local test network must have at least one validator.");
Expand All @@ -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,
Expand All @@ -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?;
Expand Down

0 comments on commit 8317398

Please sign in to comment.