Skip to content

Commit

Permalink
fix: Switch DRE tests to newer env format (#3428)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bownairo and andrewbattat authored Feb 21, 2025
1 parent a9975c2 commit 732f889
Showing 1 changed file with 11 additions and 77 deletions.
88 changes: 11 additions & 77 deletions rs/tests/dre/utils/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,21 @@ use ic_system_test_driver::driver::{
node_software_version::NodeSoftwareVersion,
prometheus_vm::{HasPrometheus, PrometheusVm},
test_env::TestEnv,
test_env_api::{get_dependency_path, HasTopologySnapshot, NnsCustomizations},
test_env_api::{HasTopologySnapshot, NnsCustomizations},
};
use serde::Deserialize;
use slog::{info, Logger};
use slog::info;
use url::Url;

pub mod defs;
pub mod steps;

const IC_VERSION_FILE: &str = "ENV_DEPS__IC_VERSION_FILE";
const CUSTOM_REVISION: &str = "custom_revision";

const CUSTOM_DISK_IMG_TAR_URL: &str = "custom_disk_img_tar_url";
const DEV_DISK_IMG_TAR_ZST_CAS_URL: &str = "ENV_DEPS__DEV_DISK_IMG_TAR_ZST_CAS_URL";

const CUSTOM_DISK_IMG_SHA: &str = "custom_disk_img_sha";
const DEV_DISK_IMG_TAR_ZST_SHA256: &str = "ENV_DEPS__DEV_DISK_IMG_TAR_ZST_SHA256";

const CUSTOM_UPDATE_IMG_TAR_URL: &str = "custom_update_img_tar_url";
const DEV_UPDATE_IMG_TAR_ZST_CAS_URL: &str = "ENV_DEPS__DEV_UPDATE_IMG_TAR_ZST_CAS_URL";

const CUSTOM_UPDATE_IMG_SHA: &str = "custom_update_img_sha";
const DEV_UPDATE_IMG_TAR_ZST_SHA256: &str = "ENV_DEPS__DEV_UPDATE_IMG_TAR_ZST_SHA256";
const GUESTOS_DISK_IMG_URL: &str = "ENV_DEPS__GUESTOS_DISK_IMG_URL";
const GUESTOS_UPDATE_IMG_URL: &str = "ENV_DEPS__GUESTOS_UPDATE_IMG_URL";

pub const IC_CONFIG: &str = "IC_CONFIG";

const TAR_EXTENSION: &str = ".tar.zst";

pub fn setup(env: TestEnv, config: IcConfig) {
let mut ic = InternetComputer::new();
if let Some(v) = config.initial_version {
Expand All @@ -44,33 +31,20 @@ pub fn setup(env: TestEnv, config: IcConfig) {
orchestrator_url: Url::parse("https://unimportant.com").unwrap(),
orchestrator_hash: "".to_string(),
});
write_file_and_update_env_variable(
update_env_variables(
&env,
vec![
(
CUSTOM_REVISION,
v.to_string(),
IC_VERSION_FILE,
),
(
CUSTOM_DISK_IMG_TAR_URL,
format!("http://download.proxy-global.dfinity.network:8080/ic/{}/guest-os/disk-img/disk-img.tar.zst", v),
DEV_DISK_IMG_TAR_ZST_CAS_URL,
),
(
CUSTOM_DISK_IMG_SHA,
fetch_shasum_for_img(v.to_string(), "disk", env.logger()),
DEV_DISK_IMG_TAR_ZST_SHA256,
GUESTOS_DISK_IMG_URL,
),
(
CUSTOM_UPDATE_IMG_TAR_URL,
format!("http://download.proxy-global.dfinity.network:8080/ic/{}/guest-os/update-img/update-img.tar.zst", v),
DEV_UPDATE_IMG_TAR_ZST_CAS_URL,
),
(
CUSTOM_UPDATE_IMG_SHA,
fetch_shasum_for_img(v.to_string(), "update", env.logger()),
DEV_UPDATE_IMG_TAR_ZST_SHA256,
GUESTOS_UPDATE_IMG_URL,
),
],
);
Expand Down Expand Up @@ -122,54 +96,14 @@ pub fn setup(env: TestEnv, config: IcConfig) {
env.sync_with_prometheus();
}

fn write_file_and_update_env_variable(env: &TestEnv, pairs: Vec<(&str, String, &str)>) {
for (file_name, value_in_file, env_variable) in pairs {
let path = get_dependency_path(file_name);
std::fs::write(&path, value_in_file)
.unwrap_or_else(|_| panic!("Failed to write to path: {}", path.display()));
std::env::set_var(env_variable, file_name);
fn update_env_variables(env: &TestEnv, pairs: Vec<(String, &str)>) {
for (value, env_variable) in pairs {
std::env::set_var(env_variable, &value);
info!(
env.logger(),
"Overriden env variable `{}` to value: {}",
env_variable,
path.display()
)
}
}

fn fetch_shasum_for_img(version: String, image: &str, logger: Logger) -> String {
let url = format!(
"http://download.proxy-global.dfinity.network:8080/ic/{}/guest-os/{}-img/SHA256SUMS",
version, image
);
let response = reqwest::blocking::get(&url)
.unwrap_or_else(|e| panic!("Failed to fetch url `{}` with err: {:?}", &url, e));
if !response.status().is_success() {
panic!(
"Received non-success response status: {:?}",
response.status()
"Overriden env variable `{}` to value: {}", env_variable, value
)
}

let img = format!("{}-img{}", image, TAR_EXTENSION);
info!(logger, "Finding sha256 for {}", img);

let sha = String::from_utf8(
response
.bytes()
.expect("Failed to deserialize bytes")
.to_vec(),
)
.expect("Failed to convert to UTF8")
.lines()
.find(|l| l.ends_with(&img))
.unwrap_or_else(|| panic!("Failed to find a hash ending with `{}` from: {}", img, &url))
.split_whitespace()
.next()
.expect("The format of hash should contain whitespace")
.to_string();
info!(logger, "Found sha256 {}", sha);
sha
}

#[derive(Deserialize, Debug)]
Expand Down

0 comments on commit 732f889

Please sign in to comment.