Skip to content
Closed
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
112 changes: 0 additions & 112 deletions linera-service/src/cli_wrappers/local_kubernetes_net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ use linera_base::{
};
use linera_execution::ResourceControlPolicy;
use tokio::process::Command;
#[cfg(with_testing)]
use {
crate::cli_wrappers::wallet::FaucetOption, linera_base::command::current_binary_parent,
tokio::sync::OnceCell,
};

use crate::cli_wrappers::{
docker::{BuildArg, DockerImage},
Expand All @@ -30,12 +25,6 @@ use crate::cli_wrappers::{
ClientWrapper, LineraNet, LineraNetConfig, Network, OnClientDrop,
};

#[cfg(with_testing)]
static SHARED_LOCAL_KUBERNETES_TESTING_NET: OnceCell<(
Arc<Mutex<LocalKubernetesNet>>,
ClientWrapper,
)> = OnceCell::const_new();

/// The information needed to start a [`LocalKubernetesNet`].
pub struct LocalKubernetesNetConfig {
pub network: Network,
Expand All @@ -51,11 +40,6 @@ pub struct LocalKubernetesNetConfig {
pub path_provider: PathProvider,
}

/// A wrapper of [`LocalKubernetesNetConfig`] to create a shared local Kubernetes network
/// or use an existing one.
#[cfg(with_testing)]
pub struct SharedLocalKubernetesNetTestingConfig(LocalKubernetesNetConfig);

/// A set of Linera validators running locally as native processes.
#[derive(Clone)]
pub struct LocalKubernetesNet {
Expand All @@ -72,43 +56,6 @@ pub struct LocalKubernetesNet {
path_provider: PathProvider,
}

#[cfg(with_testing)]
impl SharedLocalKubernetesNetTestingConfig {
// The second argument is sometimes used locally to use specific binaries for tests.
pub fn new(network: Network, mut binaries: BuildArg) -> Self {
if std::env::var("LINERA_TRY_RELEASE_BINARIES").unwrap_or_default() == "true"
&& matches!(binaries, BuildArg::Build)
{
// For cargo test, current binary should be in debug mode
let current_binary_parent =
current_binary_parent().expect("Fetching current binaries path should not fail");
// But binaries for cluster should be release mode
let binaries_dir = current_binary_parent
.parent()
.expect("Getting parent should not fail")
.join("release");
if binaries_dir.exists() {
// If release exists, use those binaries
binaries = BuildArg::Directory(binaries_dir);
}
}
let path_provider = PathProvider::create_temporary_directory().unwrap();
Self(LocalKubernetesNetConfig {
network,
testing_prng_seed: Some(37),
num_other_initial_chains: 2,
initial_amount: Amount::from_tokens(2000),
num_initial_validators: 4,
num_shards: 4,
binaries,
no_build: false,
docker_image_name: String::from("linera:latest"),
policy: ResourceControlPolicy::devnet(),
path_provider,
})
}
}

#[async_trait]
impl LineraNetConfig for LocalKubernetesNetConfig {
type Net = LocalKubernetesNet;
Expand Down Expand Up @@ -159,65 +106,6 @@ impl LineraNetConfig for LocalKubernetesNetConfig {
}
}

#[cfg(with_testing)]
#[async_trait]
impl LineraNetConfig for SharedLocalKubernetesNetTestingConfig {
type Net = Arc<Mutex<LocalKubernetesNet>>;

async fn instantiate(self) -> Result<(Self::Net, ClientWrapper)> {
let (net, initial_client) = SHARED_LOCAL_KUBERNETES_TESTING_NET
.get_or_init(|| async {
let (net, initial_client) = self
.0
.instantiate()
.await
.expect("Instantiating LocalKubernetesNetConfig should not fail");
(Arc::new(Mutex::new(net)), initial_client)
})
.await;

let mut net = net.clone();
let client = net.make_client().await;
// The tests assume we've created a genesis config with 2
// chains with 10 tokens each.
client.wallet_init(&[], FaucetOption::None).await.unwrap();
for _ in 0..2 {
initial_client
.open_and_assign(&client, Amount::from_tokens(10))
.await
.unwrap();
}

Ok((net, client))
}

async fn policy(&self) -> ResourceControlPolicy {
self.0.policy().await
}
}

#[async_trait]
impl LineraNet for Arc<Mutex<LocalKubernetesNet>> {
async fn ensure_is_running(&mut self) -> Result<()> {
let self_clone = self.clone();
let mut self_lock = self_clone.lock().await;

self_lock.ensure_is_running().await
}

async fn make_client(&mut self) -> ClientWrapper {
let self_clone = self.clone();
let mut self_lock = self_clone.lock().await;

self_lock.make_client().await
}

async fn terminate(&mut self) -> Result<()> {
// Users are responsible for killing the clusters if they want to
Ok(())
}
}

#[async_trait]
impl LineraNet for LocalKubernetesNet {
async fn ensure_is_running(&mut self) -> Result<()> {
Expand Down
Loading
Loading