Skip to content

Commit

Permalink
[cluster-test] remove re-serialization in CT
Browse files Browse the repository at this point in the history
Closes: diem#5816
  • Loading branch information
zihaoccc authored and bors-libra committed Sep 1, 2020
1 parent 7371a80 commit 39fca8b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 76 deletions.
123 changes: 54 additions & 69 deletions testsuite/cluster-test/src/cluster_swarm/cluster_swarm_kube.rs
Expand Up @@ -26,9 +26,7 @@ use crate::instance::{
};
use k8s_openapi::api::batch::v1::Job;
use kube::api::ListParams;
use libra_config::config::{
NodeConfig, PersistableConfig, SafetyRulesConfig, DEFAULT_JSON_RPC_PORT,
};
use libra_config::config::DEFAULT_JSON_RPC_PORT;
use reqwest::Client as HttpClient;
use rusoto_core::Region;
use rusoto_s3::{PutObjectRequest, S3Client, S3};
Expand Down Expand Up @@ -674,14 +672,14 @@ impl ClusterSwarmKube {
node,
pod_name,
format!("{}parser.conf", dir).as_str(),
parsers_config.into_bytes(),
parsers_config.as_bytes(),
)
.await?;
self.put_file(
node,
pod_name,
format!("{}fluent-bit.conf", dir).as_str(),
fluentbit_config.into_bytes(),
fluentbit_config.as_bytes(),
)
.await?;
Ok(())
Expand All @@ -690,8 +688,13 @@ impl ClusterSwarmKube {
async fn put_genesis_file(&self, pod_name: &str, node: &str) -> Result<()> {
let genesis = std::fs::read(GENESIS_PATH)
.map_err(|e| format_err!("Failed to read {} : {}", GENESIS_PATH, e))?;
self.put_file(node, pod_name, "/opt/libra/etc/genesis.blob", genesis)
.await?;
self.put_file(
node,
pod_name,
"/opt/libra/etc/genesis.blob",
genesis.as_slice(),
)
.await?;
Ok(())
}

Expand All @@ -702,64 +705,52 @@ impl ClusterSwarmKube {
node: &str,
) -> Result<()> {
let node_config = match &instance_config.application_config {
Validator(validator_config) => {
let config = format!(
include_str!("configs/validator.yaml"),
vault_addr = validator_config
.vault_addr
.as_ref()
.unwrap_or(&"".to_string()),
vault_ns = validator_config
.vault_namespace
.as_ref()
.unwrap_or(&"".to_string()),
safety_rules_addr = validator_config
.safety_rules_addr
.as_ref()
.unwrap_or(&"".to_string()),
);
Some(serde_yaml::to_vec(&NodeConfig::parse(&config).map_err(
|e| format_err!("Failed to parse config template : {}", e),
)?)?)
}
Fullnode(fullnode_config) => {
let config = format!(
include_str!("configs/fullnode.yaml"),
vault_addr = fullnode_config
.vault_addr
.as_ref()
.unwrap_or(&"".to_string()),
vault_ns = fullnode_config
.vault_namespace
.as_ref()
.unwrap_or(&"".to_string()),
seed_peer_ip = fullnode_config.seed_peer_ip,
);
Some(serde_yaml::to_vec::<NodeConfig>(
&NodeConfig::parse(&config)
.map_err(|e| format_err!("Failed to parse config template : {}", e))?,
)?)
}
LSR(lsr_config) => {
let config = format!(
include_str!("configs/safetyrules.yaml"),
vault_addr = lsr_config.vault_addr.as_ref().unwrap_or(&"".to_string()),
vault_ns = lsr_config
.vault_namespace
.as_ref()
.unwrap_or(&"".to_string()),
);
Some(serde_yaml::to_vec::<SafetyRulesConfig>(
&SafetyRulesConfig::parse(&config)
.map_err(|e| format_err!("Failed to parse config template : {}", e))?,
)?)
}
Validator(validator_config) => Some(format!(
include_str!("configs/validator.yaml"),
vault_addr = validator_config
.vault_addr
.as_ref()
.unwrap_or(&"".to_string()),
vault_ns = validator_config
.vault_namespace
.as_ref()
.unwrap_or(&"".to_string()),
safety_rules_addr = validator_config
.safety_rules_addr
.as_ref()
.unwrap_or(&"".to_string()),
)),
Fullnode(fullnode_config) => Some(format!(
include_str!("configs/fullnode.yaml"),
vault_addr = fullnode_config
.vault_addr
.as_ref()
.unwrap_or(&"".to_string()),
vault_ns = fullnode_config
.vault_namespace
.as_ref()
.unwrap_or(&"".to_string()),
seed_peer_ip = fullnode_config.seed_peer_ip,
)),
LSR(lsr_config) => Some(format!(
include_str!("configs/safetyrules.yaml"),
vault_addr = lsr_config.vault_addr.as_ref().unwrap_or(&"".to_string()),
vault_ns = lsr_config
.vault_namespace
.as_ref()
.unwrap_or(&"".to_string()),
)),
_ => None,
};

if let Some(node_config) = node_config {
self.put_file(node, pod_name, "/opt/libra/etc/node.yaml", node_config)
.await?;
self.put_file(
node,
pod_name,
"/opt/libra/etc/node.yaml",
node_config.as_bytes(),
)
.await?;
}

Ok(())
Expand Down Expand Up @@ -790,18 +781,12 @@ impl ClusterSwarm for ClusterSwarmKube {
))
}

async fn put_file(
&self,
node: &str,
pod_name: &str,
path: &str,
content: Vec<u8>,
) -> Result<()> {
async fn put_file(&self, node: &str, pod_name: &str, path: &str, content: &[u8]) -> Result<()> {
let bucket = "toro-cluster-test-flamegraphs";
let run_id = env::var("RUN_ID").expect("RUN_ID is not set.");
libra_retrier::retry_async(k8s_retry_strategy(), || {
let run_id = &run_id;
let content = content.clone();
let content = content.to_vec();
Box::pin(async move {
self.s3_client
.put_object(PutObjectRequest {
Expand Down
8 changes: 1 addition & 7 deletions testsuite/cluster-test/src/cluster_swarm/mod.rs
Expand Up @@ -20,11 +20,5 @@ pub trait ClusterSwarm: Send + Sync {

async fn get_grafana_baseurl(&self) -> Result<String>;

async fn put_file(
&self,
node: &str,
pod_name: &str,
path: &str,
content: Vec<u8>,
) -> Result<()>;
async fn put_file(&self, node: &str, pod_name: &str, path: &str, content: &[u8]) -> Result<()>;
}

0 comments on commit 39fca8b

Please sign in to comment.