Skip to content

Commit

Permalink
Merge branch 'nikola-milosavljevic/REL-2373-add-support-for-unblessin…
Browse files Browse the repository at this point in the history
…g-ic-versions' into 'main'

Added retire automation command for blessed version retiring

Closes REL-2373

See merge request dfinity-lab/core/release!509
  • Loading branch information
Luka-DFINITY committed Jan 12, 2023
2 parents d9de649 + de44558 commit 3b95029
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 21 deletions.
4 changes: 0 additions & 4 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,3 @@ rustflags = [
"link-arg=-fuse-ld=mold",
] # Enable faster linker https://github.com/rui314/mold#how-to-use
linker = "clang"

[term]
# https://doc.rust-lang.org/cargo/reference/config.html#termquiet
quiet = true # quiet cargo output, available from Rust 1.59+
5 changes: 5 additions & 0 deletions rs/Cargo.lock

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

5 changes: 5 additions & 0 deletions rs/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ ic-nns-constants = { git = "https://github.com/dfinity/ic.git", rev = "36f4a1c29
ic-nns-governance = { git = "https://github.com/dfinity/ic.git", rev = "36f4a1c2903aed012b95b3b073e052c4036aef09" }
ic-canister-client = { git = "https://github.com/dfinity/ic.git", rev = "36f4a1c2903aed012b95b3b073e052c4036aef09" }
ic-sys = { git = "https://github.com/dfinity/ic.git", rev = "36f4a1c2903aed012b95b3b073e052c4036aef09" }
ic-registry-nns-data-provider = { git = "https://github.com/dfinity/ic.git", rev = "36f4a1c2903aed012b95b3b073e052c4036aef09" }
ic-registry-keys = { git = "https://github.com/dfinity/ic.git", rev = "36f4a1c2903aed012b95b3b073e052c4036aef09" }
ic-registry-transport = { git = "https://github.com/dfinity/ic.git", rev = "36f4a1c2903aed012b95b3b073e052c4036aef09" }
ic-protobuf = { git = "https://github.com/dfinity/ic.git", rev = "36f4a1c2903aed012b95b3b073e052c4036aef09" }
prost = "0.11.0"
tokio = { version = "1.14.0", features = ["full"] }
strum = { version = "0.24.1", features = ["derive"] }
strum_macros = "0.24.3"
Expand Down
11 changes: 11 additions & 0 deletions rs/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,16 @@ pub(crate) mod version {
pub enum Commands {
/// Bless replica version with release notes using the ic-admin CLI
Bless { version: String },

/// Retire replica versions
Retire {
/// Specify if the summary should be edited during the process
///
/// Default value of summary is:
/// Removing the obsolete IC replica versions from the registry, to
/// prevent unintended version in the future
#[clap(long)]
edit_summary: bool,
},
}
}
9 changes: 8 additions & 1 deletion rs/cli/src/clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use decentralization::SubnetChangeResponse;
use ic_base_types::PrincipalId;
use ic_management_types::{
requests::{MembershipReplaceRequest, SubnetExtendRequest},
Network, NetworkError, SubnetMembershipChangeProposal,
BlessedVersions, Network, NetworkError, SubnetMembershipChangeProposal,
};
use log::error;
use serde::de::DeserializeOwned;
Expand Down Expand Up @@ -72,6 +72,13 @@ impl DashboardBackendClient {
.rest_send()
.await
}

pub async fn get_retireable_versions(&self) -> anyhow::Result<BlessedVersions> {
reqwest::Client::new()
.get(self.url.join("nns/blessed-versions").map_err(|e| anyhow::anyhow!(e))?)
.rest_send()
.await
}
}

#[async_trait]
Expand Down
93 changes: 81 additions & 12 deletions rs/cli/src/ic_admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use ic_canister_client::{Agent, Sender};
use ic_nns_constants::GOVERNANCE_CANISTER_ID;
use ic_nns_governance::pb::v1::{ListNeurons, ListNeuronsResponse};
use ic_sys::utility_command::UtilityCommand;
use itertools::Itertools;
use keyring::{Entry, Error};
use log::{error, info, warn};
use regex::Regex;
Expand All @@ -27,6 +28,7 @@ use std::{path::Path, process::Command};
use strum::Display;

use crate::cli::Opts;
use crate::clients::DashboardBackendClient;
use crate::defaults;

#[derive(Clone)]
Expand Down Expand Up @@ -313,9 +315,9 @@ impl Cli {
exec(self)
}

pub(crate) async fn prepare_args_to_propose_to_bless_new_replica_version(
pub(crate) async fn prepare_to_propose_to_bless_new_replica_version(
version: &String,
) -> anyhow::Result<Vec<String>> {
) -> anyhow::Result<(String, ProposeCommand)> {
let image_path = format!("ic/{}/guest-os/update-img", version);
let download_dir = format!("{}/tmp/{}", std::env::var("HOME").unwrap(), image_path);
let download_dir = Path::new(&download_dir);
Expand Down Expand Up @@ -362,17 +364,66 @@ impl Cli {
# Release Notes:"#
);
let edited = edit::edit(template)?.trim().replace("\r(\n)?", "\n");
let title = format!("Elect new replica binary revision (commit {version})");
Ok(vec![
"propose-to-bless-replica-version-flexible".to_string(),
"--proposal-title".to_string(),
title,
"--summary".to_string(),
Ok((
edited,
version.to_string(),
update_url,
stringified_hash,
])
ProposeCommand::BlessReplicaVersionFlexible {
version: version.to_string(),
update_url,
stringified_hash,
},
))
}

pub(crate) async fn get_replica_versions_to_retire(
&self,
edit_summary: bool,
client: DashboardBackendClient,
) -> anyhow::Result<(String, ProposeCommand)> {
let nns_versions = client.get_retireable_versions().await?;

info!("Provide the versions you would like to retire in the oppened window");
let template = "# In the below lines, uncomment the versions that you would like to retire".to_string();
let versions = edit::edit(format!(
"{}\n{}",
template,
nns_versions
.all
.iter()
.map(|f| if !nns_versions.obsolete.contains(f) {
format!("# {}", f)
} else {
f.to_string()
})
.join("\n")
))?
.trim()
.replace("\r(\n)?", "\n")
.split('\n')
.map(|s| s.trim().to_string())
.filter(|f| !f.is_empty() && !f.starts_with('#'))
.collect::<Vec<String>>();
for version in &versions {
if !nns_versions.all.contains(version) {
return Err(anyhow::anyhow!(
"Version \"{}\" is not present inside blessed replica versions",
version
));
}
}

if versions.is_empty() {
return Err(anyhow::anyhow!("Provided empty list of versions, aborting..."));
}

let mut template =
"Removing the obsolete IC replica versions from the registry, to prevent unintended version downgrades in the future"
.to_string();
if edit_summary {
info!("Edit summary");
template = edit::edit(template)?.trim().replace("\r(\n)?", "\n");
}

Ok((template, ProposeCommand::RetireReplicaVersion { versions }))
}
}

Expand All @@ -392,6 +443,14 @@ pub(crate) enum ProposeCommand {
command: String,
args: Vec<String>,
},
RetireReplicaVersion {
versions: Vec<String>,
},
BlessReplicaVersionFlexible {
version: String,
update_url: String,
stringified_hash: String,
},
}

impl ProposeCommand {
Expand Down Expand Up @@ -440,6 +499,16 @@ impl ProposeCommand {
vec![subnet.to_string(), version.clone()]
}
Self::Raw { command: _, args } => args.clone(),
Self::RetireReplicaVersion { versions } => versions.to_vec(),
Self::BlessReplicaVersionFlexible {
version,
update_url,
stringified_hash,
} => vec![
version.to_string(),
update_url.to_string(),
stringified_hash.to_string(),
],
}
}
}
Expand Down
17 changes: 13 additions & 4 deletions rs/cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use crate::cli::version::Commands::Bless;
use crate::cli::version::Commands::{Bless, Retire};
use clap::{CommandFactory, ErrorKind, Parser};
use clients::DashboardBackendClient;
use ic_management_types::{MinNakamotoCoefficients, NodeFeature};
use std::collections::BTreeMap;
use std::str::FromStr;

mod cli;
mod clients;
pub(crate) mod defaults;
Expand Down Expand Up @@ -130,9 +132,16 @@ async fn main() -> Result<(), anyhow::Error> {
match &cmd.subcommand {
Bless { version } => {
let ic_admin = ic_admin::Cli::from_opts(&cli_opts, true).await?;
let args = ic_admin::Cli::prepare_args_to_propose_to_bless_new_replica_version(version).await?;
ic_admin.run_passthrough_propose(&args)
}
let (summary, cmd) = ic_admin::Cli::prepare_to_propose_to_bless_new_replica_version(version).await?;
ic_admin.propose_run(cmd, ic_admin::ProposeOptions { title: Some(format!("Elect new replica binary revision (commit {version})")), summary: Some(summary), motivation: None })
},
Retire { edit_summary } => {
let ic_admin = ic_admin::Cli::from_opts(&cli_opts, true).await?;
let dashboard_client = DashboardBackendClient::new(cli_opts.network, cli_opts.dev);
let (summary, cmd ) = ic_admin.get_replica_versions_to_retire(*edit_summary, dashboard_client).await?;

ic_admin.propose_run(cmd, ic_admin::ProposeOptions { title: Some("Retire IC replica version".to_string()), summary: Some(summary), motivation: None })
},
}
},
}
Expand Down

0 comments on commit 3b95029

Please sign in to comment.