Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
nmattia committed Nov 12, 2024
1 parent b2a1073 commit 4684870
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 16 deletions.
2 changes: 1 addition & 1 deletion rs/ic_os/metrics_tool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl Metric {
Self {
name: name.to_string(),
value,
annotation: "Custom metric".to_string(),
annotation: "Custom metric hahaho".to_string(),
labels: Vec::new(),
}
}
Expand Down
22 changes: 14 additions & 8 deletions rs/tests/driver/src/driver/test_env_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ const INFRA_GROUP_CREATED_EVENT_NAME: &str = "infra_group_name_created_event";
const KIBANA_URL_CREATED_EVENT_NAME: &str = "kibana_url_created_event";
pub type NodesInfo = HashMap<NodeId, Option<MaliciousBehaviour>>;

// TODO: necessary? why not used everywhere?
pub fn bail_if_sha256_invalid(sha256: &str, opt_name: &str) -> Result<()> {
let l = sha256.len();
if !(l == 64 && sha256.chars().all(|c| c.is_ascii_hexdigit())) {
Expand Down Expand Up @@ -1127,7 +1128,9 @@ pub fn get_elasticsearch_hosts() -> Result<Vec<String>> {
}

pub fn get_ic_os_img_url() -> Result<Url> {
let url = read_dependency_from_env_to_string("ENV_DEPS__DEV_DISK_IMG_TAR_ZST_CAS_URL")?;
//let url = read_dependency_from_env_to_string("ENV_DEPS__DEV_DISK_IMG_TAR_ZST_CAS_URL")?;
let sha256 = get_ic_os_img_sha256()?;
let url = format!("https://artifacts.zh1-idx1.dfinity.network/cas/{sha256}");
Ok(Url::parse(&url)?)
}

Expand All @@ -1138,8 +1141,8 @@ pub fn get_ic_os_img_sha256() -> Result<String> {
}

pub fn get_malicious_ic_os_img_url() -> Result<Url> {
let url =
read_dependency_from_env_to_string("ENV_DEPS__DEV_MALICIOUS_DISK_IMG_TAR_ZST_CAS_URL")?;
let sha256 = get_malicious_ic_os_img_sha256()?;
let url = format!("https://artifacts.zh1-idx1.dfinity.network/cas/{sha256}");
Ok(Url::parse(&url)?)
}

Expand All @@ -1151,7 +1154,9 @@ pub fn get_malicious_ic_os_img_sha256() -> Result<String> {
}

pub fn get_ic_os_update_img_url() -> Result<Url> {
let url = read_dependency_from_env_to_string("ENV_DEPS__DEV_UPDATE_IMG_TAR_ZST_CAS_URL")?;
//let url = read_dependency_from_env_to_string("ENV_DEPS__DEV_UPDATE_IMG_TAR_ZST_CAS_URL")?;
let sha256 = get_ic_os_update_img_sha256()?;
let url = format!("https://artifacts.zh1-idx1.dfinity.network/cas/{sha256}");
Ok(Url::parse(&url)?)
}

Expand All @@ -1174,8 +1179,8 @@ pub fn get_ic_os_update_img_test_sha256() -> Result<String> {
}

pub fn get_malicious_ic_os_update_img_url() -> Result<Url> {
let url =
read_dependency_from_env_to_string("ENV_DEPS__DEV_MALICIOUS_UPDATE_IMG_TAR_ZST_CAS_URL")?;
let sha256 = get_malicious_ic_os_update_img_sha256()?;
let url = format!("https://artifacts.zh1-idx1.dfinity.network/cas/{sha256}");
Ok(Url::parse(&url)?)
}

Expand Down Expand Up @@ -1212,8 +1217,9 @@ pub fn get_mainnet_ic_os_update_img_url() -> Result<Url> {
}

pub fn get_hostos_update_img_test_url() -> Result<Url> {
let url =
read_dependency_from_env_to_string("ENV_DEPS__DEV_HOSTOS_UPDATE_IMG_TEST_TAR_ZST_CAS_URL")?;
// TODO: look up from env (no need to repeat this every time)
let sha256 = get_hostos_update_img_test_sha256()?;
let url = format!("https://artifacts.zh1-idx1.dfinity.network/cas/{sha256}");
Ok(Url::parse(&url)?)
}

Expand Down
48 changes: 41 additions & 7 deletions rs/tests/system_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,30 @@ def _run_system_test(ctx):
is_executable = True,
content = """#!/bin/bash
set -eEuo pipefail
# TODO: explain
for image in $ICOS_IMAGES; do
echo found ic-os image "$image"
image_sha256=$(sha256sum "$image" | cut -d' ' -f1)
echo " sha256: '$image_sha256'"
url="https://artifacts.zh1-idx1.dfinity.network/cas/$image_sha256"
echo " image CAS URL is '$url'"
if ! curl --silent --fail --head "$url" >/dev/null; then
echo " image not uploaded yet, uploading"
curl --silent --fail "$url" --upload-file "$image"
else
echo " image already uploaded"
fi
done
# We export RUNFILES such that the from_location_specified_by_env_var() function in
# rs/rust_canisters/canister_test/src/canister.rs can find canisters
# relative to the $RUNFILES directory.
export RUNFILES="$PWD"
KUBECONFIG=$RUNFILES/${{KUBECONFIG:-}}
mkdir "$TEST_TMPDIR/root_env"
"$RUNFILES/{test_executable}" \
--working-dir "$TEST_TMPDIR" \
Expand All @@ -51,13 +70,21 @@ def _run_system_test(ctx):
env |= {
"VOLATILE_STATUS_FILE_PATH": ctx.version_file.short_path,
}

# TODO: explain
icos_images = ctx.files.icos_images
env |= {
"ICOS_IMAGES": " ".join([ image.short_path for image in icos_images ]),
}

if ctx.executable.colocated_test_bin != None:
env["COLOCATED_TEST_BIN"] = ctx.executable.colocated_test_bin.short_path

if k8s:
env["KUBECONFIG"] = ctx.file._k8sconfig.path

runtime_deps = [depset([ctx.file._k8sconfig])]
runtime_deps = [depset([ctx.file._k8sconfig] + icos_images)]

for target in ctx.attr.runtime_deps:
runtime_deps.append(target.files)

Expand Down Expand Up @@ -96,6 +123,7 @@ run_system_test = rule(
"_k8s": attr.label(default = "//rs/tests:k8s"),
"_k8sconfig": attr.label(allow_single_file = True, default = "@kubeconfig//:kubeconfig.yaml"),
"runtime_deps": attr.label_list(allow_files = True),
"icos_images": attr.label_list(allow_files = True),
"env_deps": attr.label_keyed_string_dict(allow_files = True),
"env_inherit": attr.string_list(doc = "Specifies additional environment variables to inherit from the external environment when the test is executed by bazel test."),
},
Expand Down Expand Up @@ -195,31 +223,35 @@ def system_test(
# NOTE: we use "ENV_DEPS__" as prefix for env variables, which are passed to system-tests via Bazel.
_env_deps[_guestos + "version.txt"] = "ENV_DEPS__IC_VERSION_FILE"

icos_images = []

if uses_guestos_dev:
_env_deps[_guestos + "disk-img.tar.zst.cas-url"] = "ENV_DEPS__DEV_DISK_IMG_TAR_ZST_CAS_URL"
icos_images.append(_guestos + "disk-img.tar.zst")
_env_deps[_guestos + "disk-img.tar.zst.sha256"] = "ENV_DEPS__DEV_DISK_IMG_TAR_ZST_SHA256"
_env_deps[_guestos + "update-img.tar.zst.cas-url"] = "ENV_DEPS__DEV_UPDATE_IMG_TAR_ZST_CAS_URL"

icos_images.append(_guestos + "update-img.tar.zst")
_env_deps[_guestos + "update-img.tar.zst.sha256"] = "ENV_DEPS__DEV_UPDATE_IMG_TAR_ZST_SHA256"

if uses_hostos_dev_test:
_env_deps[_hostos + "update-img-test.tar.zst.cas-url"] = "ENV_DEPS__DEV_HOSTOS_UPDATE_IMG_TEST_TAR_ZST_CAS_URL"
icos_images.append(_hostos + "update-img-test.tar.zst")
_env_deps[_hostos + "update-img-test.tar.zst.sha256"] = "ENV_DEPS__DEV_HOSTOS_UPDATE_IMG_TEST_TAR_ZST_SHA256"

# TODO: whole block unused?
if uses_setupos_dev:
_env_deps[_setupos + "disk-img.tar.zst"] = "ENV_DEPS__DEV_SETUPOS_IMG_TAR_ZST"
_env_deps["//rs/ic_os/dev_test_tools/setupos-disable-checks"] = "ENV_DEPS__SETUPOS_DISABLE_CHECKS"
_env_deps["//rs/ic_os/dev_test_tools/setupos-inject-configuration"] = "ENV_DEPS__SETUPOS_INJECT_CONFIGS"

if uses_guestos_dev_test:
_env_deps[_guestos + "update-img-test.tar.zst.cas-url"] = "ENV_DEPS__DEV_UPDATE_IMG_TEST_TAR_ZST_CAS_URL"
icos_images.append(_guestos + "update-img-test.tar.zst")
_env_deps[_guestos + "update-img-test.tar.zst.sha256"] = "ENV_DEPS__DEV_UPDATE_IMG_TEST_TAR_ZST_SHA256"

if malicious:
_guestos_malicous = "//ic-os/guestos/envs/dev-malicious:"

_env_deps[_guestos_malicous + "disk-img.tar.zst.cas-url"] = "ENV_DEPS__DEV_MALICIOUS_DISK_IMG_TAR_ZST_CAS_URL"
icos_images.append(_guestos_malicous + "disk-img.tar.zst")
_env_deps[_guestos_malicous + "disk-img.tar.zst.sha256"] = "ENV_DEPS__DEV_MALICIOUS_DISK_IMG_TAR_ZST_SHA256"
_env_deps[_guestos_malicous + "update-img.tar.zst.cas-url"] = "ENV_DEPS__DEV_MALICIOUS_UPDATE_IMG_TAR_ZST_CAS_URL"
icos_images.append(_guestos_malicous + "update-img.tar.zst")
_env_deps[_guestos_malicous + "update-img.tar.zst.sha256"] = "ENV_DEPS__DEV_MALICIOUS_UPDATE_IMG_TAR_ZST_SHA256"

run_system_test(
Expand All @@ -228,6 +260,7 @@ def system_test(
runtime_deps = runtime_deps,
env_deps = _env_deps,
env = env,
icos_images = icos_images,
env_inherit = env_inherit,
tags = tags + ["requires-network", "system_test"] +
(["manual"] if "experimental_system_test_colocation" in tags else []),
Expand Down Expand Up @@ -264,6 +297,7 @@ def system_test(
env_deps = _env_deps,
env_inherit = env_inherit,
env = env,
icos_images = icos_images,
tags = tags + ["requires-network", "system_test"] +
(["colocated"] if "experimental_system_test_colocation" in tags else ["manual"]) +
additional_colocate_tags,
Expand Down

0 comments on commit 4684870

Please sign in to comment.