Skip to content

Commit

Permalink
feat(dre): implementing a protection method for updating unassigned n…
Browse files Browse the repository at this point in the history
…odes (#151)

* implementing a protection method for updating unassigned nodes

* repinning
  • Loading branch information
NikolaMilosa committed Feb 5, 2024
1 parent 7e26ce4 commit c4205d2
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
11 changes: 11 additions & 0 deletions rs/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ pub(crate) enum Commands {
#[clap(allow_hyphen_values = true)]
args: Vec<String>,
},

/// Place a proposal for updating unassigned nodes config
UpdateUnassignedNodes {
/// NNS subnet id. By default 'tdb26-jop6k-aogll-7ltgs-eruif-6kk7m-qpktf-gdiqx-mxtrf-vb5e6-eqe'
#[clap(
long,
default_value = "tdb26-jop6k-aogll-7ltgs-eruif-6kk7m-qpktf-gdiqx-mxtrf-vb5e6-eqe"
)]
nns_subnet_id: String,
},

/// Manage replica/host-os versions blessing
#[clap(subcommand)]
Version(version::Cmd),
Expand Down
65 changes: 63 additions & 2 deletions rs/cli/src/ic_admin.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
use anyhow::{anyhow, Result};
use anyhow::{anyhow, Error, Result};
use cli::UpdateVersion;
use colored::Colorize;
use dialoguer::Confirm;
use flate2::read::GzDecoder;
use futures::stream::{self, StreamExt};
use futures::Future;
use ic_base_types::PrincipalId;
use ic_management_types::Artifact;
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 All @@ -15,6 +18,7 @@ use sha2::{Digest, Sha256};
use std::fs::File;
use std::io::Write;
use std::os::unix::fs::PermissionsExt;
use std::time::Duration;
use std::{path::Path, process::Command};
use strum::Display;

Expand Down Expand Up @@ -529,6 +533,56 @@ must be identical, and must match the SHA256 from the payload of the NNS proposa
})
}
}

pub async fn update_unassigned_nodes(
&self,
nns_subned_id: &String,
network: Network,
simulate: bool,
) -> Result<(), Error> {
let local_registry_path = local_registry_path(network.clone());
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_subned_id) {
Some((_, value)) => value,
None => return Err(anyhow::anyhow!("Couldn't find nns subnet with id '{}'", nns_subned_id)),
};

let registry_state = RegistryState::new(network, true).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::UpdateUnassignedNodes {
replica_version: unassigned_version,
};
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, simulate)
}
}

#[derive(Display, Clone)]
Expand Down Expand Up @@ -562,6 +616,9 @@ pub(crate) enum ProposeCommand {
node_ids: Vec<PrincipalId>,
replica_version: String,
},
UpdateUnassignedNodes {
replica_version: String,
},
}

impl ProposeCommand {
Expand All @@ -575,6 +632,7 @@ impl ProposeCommand {
release_artifact,
args: _,
} => format!("update-elected-{}-versions", release_artifact),
Self::UpdateUnassignedNodes { replica_version: _ } => "update-unassigned-nodes-config".to_string(),
_ => self.to_string(),
}
)
Expand Down Expand Up @@ -638,6 +696,9 @@ impl ProposeCommand {
}
args
}
Self::UpdateUnassignedNodes { replica_version } => {
vec!["--replica-version-id".to_string(), replica_version.clone()]
}
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions rs/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ async fn main() -> Result<(), anyhow::Error> {
ic_admin.run_passthrough_propose(args, simulate)
},

cli::Commands::UpdateUnassignedNodes { nns_subnet_id } => {
let ic_admin: IcAdminWrapper = cli::Cli::from_opts(&cli_opts, true).await?.into();
ic_admin.update_unassigned_nodes( nns_subnet_id, cli_opts.network, simulate).await
},

cli::Commands::Version(version_command) => {
match &version_command {
cli::version::Cmd::Update(update_command) => {
Expand Down

0 comments on commit c4205d2

Please sign in to comment.