Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Runner to use/not use dashboard backend #520

Merged
merged 12 commits into from
Jun 24, 2024
22 changes: 19 additions & 3 deletions Cargo.Bazel.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"checksum": "87e2c8f3dba5c353695777f770c5dd8e59ed40002ef4a441217e73677175c77b",
"checksum": "c3dcea9e1d5b4d6c8e5e6f9ece05a77fcd0901359c76444219a2d1904e54e8c2",
"crates": {
"actix-codec 0.5.2": {
"name": "actix-codec",
Expand Down Expand Up @@ -11213,6 +11213,10 @@
],
"deps": {
"common": [
{
"id": "actix-web 4.6.0",
"target": "actix_web"
},
{
"id": "anyhow 1.0.86",
"target": "anyhow"
Expand Down Expand Up @@ -11434,6 +11438,10 @@
},
"deps_dev": {
"common": [
{
"id": "actix-rt 2.9.0",
"target": "actix_rt"
},
{
"id": "wiremock 0.6.0",
"target": "wiremock"
Expand Down Expand Up @@ -28936,29 +28944,35 @@
],
"crate_features": {
"common": [
"elf",
"errno",
"general",
"ioctl",
"no_std"
],
"selects": {
"aarch64-unknown-linux-gnu": [
"elf",
"errno",
"prctl",
"std",
"system"
],
"arm-unknown-linux-gnueabi": [
"elf",
"errno",
"prctl",
"std",
"system"
],
"armv7-unknown-linux-gnueabi": [
"elf",
"errno",
"prctl",
"std",
"system"
],
"i686-unknown-linux-gnu": [
"elf",
"errno",
"prctl",
"std",
"system"
Expand All @@ -28974,6 +28988,8 @@
"system"
],
"x86_64-unknown-linux-gnu": [
"elf",
"errno",
"prctl",
"std",
"system"
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions rs/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ documentation.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
actix-web = { workspace = true }
anyhow = { workspace = true }
async-recursion = { workspace = true }
async-trait = { workspace = true }
Expand Down Expand Up @@ -72,6 +73,7 @@ url = { workspace = true }
humantime = { workspace = true }

[dev-dependencies]
actix-rt = { workspace = true }
wiremock = { workspace = true }

[build-dependencies]
Expand Down
81 changes: 27 additions & 54 deletions rs/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,20 @@ use dotenv::dotenv;
use dre::detect_neuron::Auth;
use dre::general::{filter_proposals, get_node_metrics_history, vote_on_proposals};
use dre::operations::hostos_rollout::{NodeGroupUpdate, NumberOfNodes};
use dre::{cli, ic_admin, local_unused_port, registry_dump, runner};
use dre::{cli, ic_admin, registry_dump, runner};
use ic_base_types::CanisterId;
use ic_canisters::governance::{governance_canister_version, GovernanceCanisterWrapper};
use ic_canisters::CanisterClient;
use ic_management_backend::endpoints;
use ic_management_types::requests::NodesRemoveRequest;
use ic_management_types::{Artifact, MinNakamotoCoefficients, NodeFeature};

use ic_nns_common::pb::v1::ProposalId;
use ic_nns_governance::pb::v1::ListProposalInfo;
use log::{info, warn};
use regex::Regex;
use serde_json::Value;
use std::collections::BTreeMap;
use std::str::FromStr;
use std::sync::mpsc;
use std::thread;
use tokio::runtime::Runtime;

const STAGING_NEURON_ID: u64 = 49;
Expand Down Expand Up @@ -70,35 +68,18 @@ async fn async_main() -> Result<(), anyhow::Error> {

let governance_canister_version = governance_canister_v.stringified_hash;

let (tx, rx) = mpsc::channel();

let backend_port = local_unused_port();
let target_network_backend = target_network.clone();
thread::spawn(move || {
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async move {
endpoints::run_backend(&target_network_backend, "127.0.0.1", backend_port, true, Some(tx))
.await
.expect("failed")
});
});

let srv = rx.recv().unwrap();

let r = ic_admin::with_ic_admin(governance_canister_version.into(), async {
ic_admin::with_ic_admin(governance_canister_version.into(), async {
let dry_run = cli_opts.dry_run;
let cli = dre::parsed_cli::ParsedCli::from_opts(&cli_opts)
.await
.expect("Failed to create authenticated CLI");
let ic_admin_wrapper = IcAdminWrapper::from_cli(cli);

let runner_instance = {
let cli = dre::parsed_cli::ParsedCli::from_opts(&cli_opts)
.await
.expect("Failed to create authenticated CLI");
let ic_admin_wrapper = IcAdminWrapper::from_cli(cli);
runner::Runner::new_with_network_and_backend_port(ic_admin_wrapper, &target_network, backend_port)
.await
.expect("Failed to create a runner")
};
let runner_instance = runner::Runner::new(ic_admin_wrapper, &target_network)
.await
.expect("Failed to create a runner");

match &cli_opts.subcommand {
let r = match &cli_opts.subcommand {
cli::Commands::DerToPrincipal { path } => {
let principal = ic_base_types::PrincipalId::new_self_authenticating(&std::fs::read(path)?);
println!("{}", principal);
Expand Down Expand Up @@ -268,26 +249,20 @@ async fn async_main() -> Result<(), anyhow::Error> {
cli::Commands::Propose { args } => runner_instance.ic_admin.run_passthrough_propose(args, dry_run).await,

cli::Commands::UpdateUnassignedNodes { nns_subnet_id } => {
let runner_instance = if target_network.is_mainnet() {
runner_instance.as_automation()
let ic_admin = if target_network.is_mainnet() {
runner_instance.ic_admin.clone().as_automation()
} else {
runner_instance
runner_instance.ic_admin.clone()
};
let nns_subnet_id = match nns_subnet_id {
Some(subnet_id) => subnet_id.to_owned(),
None => {
let res = runner_instance
.ic_admin
.run_passthrough_get(&["get-subnet-list".to_string()], true)
.await?;
let res = ic_admin.run_passthrough_get(&["get-subnet-list".to_string()], true).await?;
let subnet_list: Vec<String> = serde_json::from_str(&res)?;
subnet_list.first().ok_or_else(|| anyhow::anyhow!("No subnet found"))?.clone()
}
};
runner_instance
.ic_admin
.update_unassigned_nodes(&nns_subnet_id, &target_network, dry_run)
.await
ic_admin.update_unassigned_nodes(&nns_subnet_id, &target_network, dry_run).await
}

cli::Commands::Version(version_command) => match &version_command {
Expand Down Expand Up @@ -331,13 +306,11 @@ async fn async_main() -> Result<(), anyhow::Error> {
},

cli::Commands::Hostos(nodes) => {
let runner_instance = if target_network.is_mainnet() {
runner_instance.as_automation()
} else {
runner_instance
};
let as_automation = target_network.is_mainnet();
match &nodes.subcommand {
cli::hostos::Commands::Rollout { version, nodes } => runner_instance.hostos_rollout(nodes.clone(), version, dry_run, None).await,
cli::hostos::Commands::Rollout { version, nodes } => {
runner_instance.hostos_rollout(nodes.clone(), version, dry_run, None, as_automation).await
}
cli::hostos::Commands::RolloutFromNodeGroup {
version,
assignment,
Expand All @@ -347,7 +320,9 @@ async fn async_main() -> Result<(), anyhow::Error> {
} => {
let update_group = NodeGroupUpdate::new(*assignment, *owner, NumberOfNodes::from_str(nodes_in_group)?);
if let Some((nodes_to_update, summary)) = runner_instance.hostos_rollout_nodes(update_group, version, exclude).await? {
return runner_instance.hostos_rollout(nodes_to_update, version, dry_run, Some(summary)).await;
return runner_instance
.hostos_rollout(nodes_to_update, version, dry_run, Some(summary), as_automation)
.await;
}
Ok(())
}
Expand Down Expand Up @@ -550,13 +525,11 @@ async fn async_main() -> Result<(), anyhow::Error> {
Ok(())
}
},
}
};
let _ = runner_instance.stop_backend().await;
r
})
.await;

srv.stop(false).await;

r
.await
}

// Construct MinNakamotoCoefficients from an array (slice) of ["key=value"], and
Expand Down
Loading
Loading