Skip to content

Commit

Permalink
fix(dre): update-unassigned-nodes logic in the wrong place (#805)
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaMilosa authored Aug 27, 2024
1 parent 9d32a90 commit 3e1445d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 52 deletions.
7 changes: 5 additions & 2 deletions rs/cli/src/commands/update_unassigned_nodes.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::str::FromStr;

use clap::Args;
use ic_canisters::registry::RegistryCanisterWrapper;
use ic_management_types::Network;
use ic_types::PrincipalId;

use crate::auth::Neuron;

Expand All @@ -22,7 +25,7 @@ impl ExecutableCommand for UpdateUnassignedNodes {
}

async fn execute(&self, ctx: crate::ctx::DreContext) -> anyhow::Result<()> {
let ic_admin = ctx.ic_admin();
let runner = ctx.runner().await;
let canister_agent = ctx.create_ic_agent_canister_client(None)?;

let nns_subnet_id = match &self.nns_subnet_id {
Expand All @@ -38,7 +41,7 @@ impl ExecutableCommand for UpdateUnassignedNodes {
}
};

ic_admin.update_unassigned_nodes(&nns_subnet_id, ctx.network()).await
runner.update_unassigned_nodes(&PrincipalId::from_str(&nns_subnet_id)?).await
}

fn validate(&self, _cmd: &mut clap::Command) {}
Expand Down
51 changes: 1 addition & 50 deletions rs/cli/src/ic_admin.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
use crate::auth::Neuron;
use anyhow::{anyhow, Error, Result};
use anyhow::{anyhow, Result};
use colored::Colorize;
use dialoguer::Confirm;
use flate2::read::GzDecoder;
use futures::stream::{self, StreamExt};
use ic_base_types::PrincipalId;
use ic_management_backend::registry::{local_registry_path, RegistryFamilyEntries, RegistryState};
use ic_management_types::{Artifact, Network};
use ic_protobuf::registry::subnet::v1::SubnetRecord;
use ic_registry_local_registry::LocalRegistry;
use itertools::Itertools;
use log::{error, info, warn};
use regex::Regex;
Expand Down Expand Up @@ -575,52 +572,6 @@ must be identical, and must match the SHA256 from the payload of the NNS proposa
})
}
}

pub async fn update_unassigned_nodes(&self, nns_subnet_id: &String, network: &Network) -> Result<(), Error> {
let local_registry_path = local_registry_path(network);
let local_registry = LocalRegistry::new(local_registry_path, Duration::from_secs(10))
.map_err(|e| anyhow::anyhow!("Error in creating local registry instance: {:?}", e))?;

local_registry
.sync_with_nns()
.await
.map_err(|e| anyhow::anyhow!("Error when syncing with NNS: {:?}", e))?;

let subnets = local_registry.get_family_entries::<SubnetRecord>()?;

let nns = match subnets.get_key_value(nns_subnet_id) {
Some((_, value)) => value,
None => return Err(anyhow::anyhow!("Couldn't find nns subnet with id '{}'", nns_subnet_id)),
};

let registry_state = RegistryState::new(network, true, None).await;
let unassigned_version = registry_state.get_unassigned_nodes_replica_version().await?;

if nns.replica_version_id.eq(&unassigned_version) {
info!(
"Unassigned nodes and nns are of the same version '{}', skipping proposal submition.",
unassigned_version
);
return Ok(());
}

info!(
"NNS version '{}' and Unassigned nodes '{}' differ",
nns.replica_version_id, unassigned_version
);

let command = ProposeCommand::DeployGuestosToAllUnassignedNodes {
replica_version: nns.replica_version_id.clone(),
};
let options = ProposeOptions {
summary: Some("Update the unassigned nodes to the latest rolled-out version".to_string()),
motivation: None,
title: Some("Update all unassigned nodes".to_string()),
};

self.propose_run(command, options).await?;
Ok(())
}
}

#[derive(Display, Clone)]
Expand Down
36 changes: 36 additions & 0 deletions rs/cli/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,42 @@ impl Runner {
.map_err(|e| anyhow::anyhow!(e))?;
Ok(())
}

pub async fn update_unassigned_nodes(&self, nns_subnet_id: &PrincipalId) -> anyhow::Result<()> {
let subnets = self.registry.subnets().await?;

let nns = match subnets.get_key_value(nns_subnet_id) {
Some((_, value)) => value,
None => return Err(anyhow::anyhow!("Couldn't find nns subnet with id '{}'", nns_subnet_id)),
};

let unassigned_version = self.registry.unassigned_nodes_replica_version()?;

if unassigned_version == nns.replica_version.clone().into() {
info!(
"Unassigned nodes and nns are of the same version '{}', skipping proposal submition.",
unassigned_version
);
return Ok(());
}

info!(
"NNS version '{}' and Unassigned nodes '{}' differ",
nns.replica_version, unassigned_version
);

let command = ProposeCommand::DeployGuestosToAllUnassignedNodes {
replica_version: nns.replica_version.clone(),
};
let options = ProposeOptions {
summary: Some("Update the unassigned nodes to the latest rolled-out version".to_string()),
motivation: None,
title: Some("Update all unassigned nodes".to_string()),
};

self.ic_admin.propose_run(command, options).await?;
Ok(())
}
}

pub fn replace_proposal_options(change: &SubnetChangeResponse) -> anyhow::Result<ic_admin::ProposeOptions> {
Expand Down

0 comments on commit 3e1445d

Please sign in to comment.