Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions bazel/workspace_status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ else
fi

# Used as farm metadata
test -n "${CI_JOB_NAME:-}" && echo "STABLE_FARM_JOB_NAME ${CI_JOB_NAME}"
if [[ -n "${USER:-}" ]]; then
echo "STABLE_FARM_USER ${USER}"
elif [[ -n "${HOSTUSER:-}" ]]; then
echo "STABLE_FARM_USER ${HOSTUSER}"
STABLE_FARM_METADATA="USER=${USER:-${HOSTUSER:-anonymous}}"
if [ -n "${CI_JOB_NAME:-}" ]; then
STABLE_FARM_METADATA="$STABLE_FARM_METADATA;JOB_NAME=$CI_JOB_NAME"
fi
echo "STABLE_FARM_METADATA $STABLE_FARM_METADATA"
8 changes: 7 additions & 1 deletion rs/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ load("@rules_distroless//apt:defs.bzl", "dpkg_status")
load("@rules_distroless//distroless:defs.bzl", "passwd")
load("@rules_oci//oci:defs.bzl", "oci_image")
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
load("//bazel:defs.bzl", "symlink_dir", "symlink_dir_test")
load("//bazel:defs.bzl", "symlink_dir", "symlink_dir_test", "write_info_file_var")
load(":system_tests.bzl", "oci_tar", "uvm_config_image")

package(default_visibility = ["//rs:system-tests-pkg"])
Expand Down Expand Up @@ -296,3 +296,9 @@ genrule(
outs = ["version-test.txt"],
cmd = "sed < $< 's/$$/-test/' > $@",
)

write_info_file_var(
name = "farm_metadata.txt",
varname = "STABLE_FARM_METADATA",
visibility = ["//visibility:public"],
)
37 changes: 14 additions & 23 deletions rs/tests/driver/src/driver/farm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
use crate::driver::ic::{AmountOfMemoryKiB, NrOfVCPUs, VmAllocationStrategy};
use crate::driver::log_events;
use crate::driver::test_env::{RequiredHostFeaturesFromCmdLine, TestEnvAttribute};
use crate::driver::test_env_api::{HasFarmUrl, read_dependency_to_string};
use crate::driver::test_env_api::HasFarmUrl;
use anyhow::Result;
use chrono::{DateTime, Utc};
use ic_crypto_sha2::Sha256;
Expand Down Expand Up @@ -450,25 +450,12 @@ pub struct GroupSpec {

impl GroupSpec {
pub fn add_meta(mut self, group_base_name: &str) -> Self {
// Acquire bazel's stable status containing key value pairs like user and job name:
let farm_metadata_path = std::env::var("FARM_METADATA_PATH")
.expect("Expected the environment variable FARM_METADATA_PATH to be defined!");
let farm_metadata = read_dependency_to_string(&farm_metadata_path)
.unwrap_or_else(|e| {
panic!("Couldn't read content of the status file {farm_metadata_path}: {e:?}")
})
.trim_end()
.to_string();
let runtime_args_map = parse_farm_metadata_file(farm_metadata);

// Read values from the runtime args and use sensible defaults if unset
let user = runtime_args_map
.get("STABLE_FARM_USER") // Always set by bazel
.cloned()
.unwrap_or("CI".to_string());
// Read injected farm metadata. We expect 'USER' and 'JOB_NAME' to be set and
// use sensible defaults if unset.
let mut runtime_args_map = parse_farm_metadata_env();
let user = runtime_args_map.remove("USER").unwrap_or("CI".to_string());
let job_schedule = runtime_args_map
.get("STABLE_FARM_JOB_NAME") // Injected by workspace status
.cloned()
.remove("JOB_NAME")
.unwrap_or("manual".to_string());
let metadata = GroupMetadata {
user,
Expand All @@ -490,11 +477,15 @@ pub struct GroupMetadata {
pub test_name: String,
}

fn parse_farm_metadata_file(input: String) -> HashMap<String, String> {
fn parse_farm_metadata_env() -> HashMap<String, String> {
// Read the FARM_METADATA environment variable containing ';' separated key pairs:
// 'FARM_METADATA=FOO=bar;BAZ=quux'
let farm_metadata = std::env::var("FARM_METADATA")
.expect("Expected the environment variable FARM_METADATA to be defined!");
let mut map = HashMap::new();
let lines = input.split('\n');
for line in lines {
if let Some((key, value)) = line.split_once(' ') {
let pairs = farm_metadata.split(';');
for pair in pairs {
if let Some((key, value)) = pair.split_once('=') {
map.insert(String::from(key), String::from(value));
}
}
Expand Down
6 changes: 2 additions & 4 deletions rs/tests/system_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ def _run_system_test(ctx):
if value.startswith("$"):
env[key] = ctx.expand_location(value, ctx.attr.runtime_deps)

# Used by the run script and by farm to read metadata
env["FARM_METADATA_PATH"] = ctx.info_file.short_path
data.append(ctx.info_file)

# We use the RUN_SCRIPT_ prefix for variables that are processed by the run
# script, and not passed directly to the test.

Expand Down Expand Up @@ -343,6 +339,8 @@ def system_test(
env["ENV_DEPS__HOSTOS_UPDATE_IMG_URL"] = icos_image_download_url(MAINNET_LATEST_HOSTOS["version"], "host-os", True) if guestos != "mainnet_latest_dev" else icos_dev_image_download_url(MAINNET_LATEST_HOSTOS["version"], "host-os", True)
env["ENV_DEPS__HOSTOS_UPDATE_IMG_HASH"] = MAINNET_LATEST_HOSTOS["hash" if guestos != "mainnet_latest_dev" else "dev_hash"]

env_var_files["FARM_METADATA"] = "//rs/tests:farm_metadata.txt"

deps = list(runtime_deps)
if logs:
env["VECTOR_VM_PATH"] = "$(rootpath //rs/tests:vector_with_log_fetcher_image)"
Expand Down
Loading