Skip to content
Snippets Groups Projects
Unverified Commit 8b620fb9 authored by Javier Viola's avatar Javier Viola Committed by GitHub
Browse files

fix(orchestrator): compute args_output in add_node/collator (#199)

parent c70e180a
Branches
No related merge requests found
Pipeline #460359 passed with stage
in 10 minutes and 48 seconds
......@@ -144,8 +144,15 @@ impl<T: FileSystem> Network<T> {
default_args: self.initial_spec.relaychain.default_args.iter().collect(),
};
let node_spec =
let mut node_spec =
network_spec::node::NodeSpec::from_ad_hoc(&name, options.into(), &chain_context)?;
node_spec.available_args_output = Some(
self.initial_spec
.node_available_args_output(&node_spec, self.ns.clone())
.await?,
);
let base_dir = self.ns.base_dir().to_string_lossy();
let scoped_fs = ScopedFilesystem::new(&self.filesystem, &base_dir);
......@@ -288,9 +295,15 @@ impl<T: FileSystem> Network<T> {
));
}
let node_spec =
let mut node_spec =
network_spec::node::NodeSpec::from_ad_hoc(name.into(), options.into(), &chain_context)?;
node_spec.available_args_output = Some(
self.initial_spec
.node_available_args_output(&node_spec, self.ns.clone())
.await?,
);
let node = spawner::spawn_node(&node_spec, global_files_to_inject, &ctx).await?;
let para = self.parachains.get_mut(&para_id).unwrap();
para.collators.push(node.clone());
......
......@@ -7,7 +7,7 @@ use configuration::{
shared::constants::THIS_IS_A_BUG, GlobalSettings, HrmpChannelConfig, NetworkConfig,
};
use futures::future::try_join_all;
use provider::ProviderNamespace;
use provider::{ProviderError, ProviderNamespace};
use tracing::debug;
use crate::errors::OrchestratorError;
......@@ -82,6 +82,48 @@ impl NetworkSpec {
Ok(())
}
//
pub async fn node_available_args_output(
&self,
node_spec: &NodeSpec,
ns: Arc<dyn ProviderNamespace + Send + Sync>,
) -> Result<String, ProviderError> {
// try to find a node that use the same combination of image/cmd
let cmp_fn = |ad_hoc: &&NodeSpec| -> bool {
ad_hoc.image == node_spec.image && ad_hoc.command == node_spec.command
};
// check if we already had computed the args output for this cmd/[image]
let node = self.relaychain.nodes.iter().find(cmp_fn);
let node = if let Some(node) = node {
Some(node)
} else {
let node = self
.parachains
.iter()
.find_map(|para| para.collators.iter().find(cmp_fn));
node
};
let output = if let Some(node) = node {
node.available_args_output.clone().expect(&format!(
"args_output should be set for running nodes {THIS_IS_A_BUG}"
))
} else {
// we need to compute the args output
let image = node_spec
.image
.as_ref()
.map(|image| image.as_str().to_string());
let command = node_spec.command.as_str().to_string();
ns.get_node_available_args((command, image)).await?
};
Ok(output)
}
// collect mutable references to all nodes from relaychain and parachains
fn collect_network_nodes(&mut self) -> Vec<&mut NodeSpec> {
vec![
......
......@@ -6,6 +6,7 @@ use std::{
use configuration::{NetworkConfig, NetworkConfigBuilder};
use futures::{stream::StreamExt, Future};
use orchestrator::{AddCollatorOptions, AddNodeOptions};
use serde_json::json;
use support::fs::local::LocalFileSystem;
use zombienet_sdk::{Network, NetworkConfigExt, OrchestratorError, PROVIDERS};
......@@ -57,7 +58,6 @@ async fn ci_k8s_basic_functionalities_should_works() {
let config = small_network();
let spawn_fn = get_spawn_fn();
#[allow(unused_mut)]
let mut network = spawn_fn(config).await.unwrap();
// Optionally detach the network
// network.detach().await;
......@@ -129,6 +129,31 @@ async fn ci_k8s_basic_functionalities_should_works() {
println!("Block (para) #{}", block.unwrap().header().number);
}
// add node
let opts = AddNodeOptions {
rpc_port: Some(9444),
is_validator: true,
..Default::default()
};
network.add_node("new1", opts).await.unwrap();
// add collator
let col_opts = AddCollatorOptions {
command: Some("polkadot-parachain".try_into().unwrap()),
image: Some(
"docker.io/parity/polkadot-parachain:1.7.0"
.try_into()
.unwrap(),
),
..Default::default()
};
network
.add_collator("new-col-1", col_opts, 2000)
.await
.unwrap();
// tear down (optional if you don't detach the network)
// network.destroy().await.unwrap();
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment