Skip to content

Commit 7795001

Browse files
committed
feat: update the way test artifacts are downloaded and used
The old setup used `build/img` as the base directory for artifacts pulled from S3. In S3 the artifacts directory contains 1 subdirectory per architecture (x86_64 and aarch64). This was causing final local artifacts path to be `build/img/x86_64` or `build/img/aarch64`. This commit changes the structure a to have a separate `build/artifacts` directory with subdirectories containing different versions of artifacts. The path to currently used artifacts will be placed in `build/current_artifacts` file. This make is easy to switch between multiple versions of artifacts without a need to delete/download them. This also opens a door for A/B testing of artifacts. Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
1 parent 5ed2f21 commit 7795001

File tree

6 files changed

+46
-23
lines changed

6 files changed

+46
-23
lines changed

tests/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,9 +452,9 @@ there. `pytest` will bring them into scope for all your tests.
452452
453453
`Q4:` *I want to use more/other microvm test images, but I don't want to add
454454
them to the common s3 bucket.*\
455-
`A4:` Add your custom images to the `build/img` subdirectory in the Firecracker
456-
source tree. This directory is bind-mounted in the container and used as a local
457-
image cache.
455+
`A4:` Add your custom images to the `build/artifacts` subdirectory in the
456+
Firecracker source tree. This directory is bind-mounted in the container and
457+
used as a local image cache.
458458
459459
`Q5:` *How can I get live logger output from the tests?*\
460460
`A5:` Accessing **pytest.ini** will allow you to modify logger settings.

tests/conftest.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import inspect
2323
import json
2424
import os
25-
import platform
2625
import shutil
2726
import sys
2827
import tempfile
@@ -346,9 +345,13 @@ def get(self, _netns_id):
346345
for netns in netns_fcty._all:
347346
netns._cleanup_orig()
348347

348+
@pytest.fixture(scope="session")
349+
def current_artifacts_path():
350+
with open("/firecracker/build/current_artifacts", "r", encoding="utf-8") as ca:
351+
yield ca.read().strip()
349352

350353
@pytest.fixture()
351-
def microvm_factory(request, record_property, results_dir, netns_factory):
354+
def microvm_factory(request, record_property, results_dir, netns_factory, current_artifacts_path):
352355
"""Fixture to create microvms simply."""
353356

354357
binary_dir = request.config.getoption("--binary-dir") or DEFAULT_BINARY_DIR
@@ -399,7 +402,7 @@ def microvm_factory(request, record_property, results_dir, netns_factory):
399402
uvm_data.joinpath("host-dmesg.log").write_text(
400403
utils.run_cmd(["dmesg", "-dPx"]).stdout
401404
)
402-
shutil.copy(f"/firecracker/build/img/{platform.machine()}/id_rsa", uvm_data)
405+
shutil.copy(f"{current_artifacts_path}/id_rsa", uvm_data)
403406
if Path(uvm.screen_log).exists():
404407
shutil.copy(uvm.screen_log, uvm_data)
405408

tests/framework/defs.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,13 @@
3232

3333
SUPPORTED_HOST_KERNELS = ["5.10", "6.1"]
3434

35-
IMG_DIR = Path(DEFAULT_TEST_SESSION_ROOT_PATH) / "img"
35+
ARTIFACT_DIR = Path(DEFAULT_TEST_SESSION_ROOT_PATH) / "current_artifacts"
3636

3737
# fall-back to the local directory
38-
if not IMG_DIR.exists():
39-
IMG_DIR = LOCAL_BUILD_PATH / "img"
40-
41-
ARTIFACT_DIR = IMG_DIR / platform.machine()
38+
if not ARTIFACT_DIR.exists():
39+
current_artifacts_dir = (
40+
open(Path(LOCAL_BUILD_PATH) / "current_artifacts", "r", encoding="utf-8")
41+
.read()
42+
.strip()
43+
)
44+
ARTIFACT_DIR = LOCAL_BUILD_PATH / current_artifacts_dir

tools/devtool

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,11 @@ CTR_TEST_RESULTS_DIR="${CTR_FC_ROOT_DIR}/test_results"
116116
CTR_CARGO_TARGET_DIR="$CTR_FC_BUILD_DIR/cargo_target"
117117

118118
# Path to the microVM images cache dir
119-
MICROVM_IMAGES_DIR="build/img"
119+
LOCAL_ARTIFACTS_DIR="build/artifacts"
120+
121+
# File with a single line specifing the name of the
122+
# currently used artifacts
123+
LOCAL_ARTIFACTS_CURRENT_DIR_FILE="build/current_artifacts"
120124

121125
# Full path to the public key mapping on the guest
122126
PUB_KEY_PATH=/root/.ssh/id_rsa.pub
@@ -138,6 +142,13 @@ DEFAULT_ARTIFACTS_S3_BUCKET=s3://spec.ccfc.min/firecracker-ci
138142
# Query default S3 bucket with artifacts and return the most recient path
139143
get_newest_s3_artifacts() {
140144
echo $(aws s3 ls $DEFAULT_ARTIFACTS_S3_BUCKET/ --no-sign-request | grep "PRE" | sort -k2 | tail -1 | awk -v bucket="$DEFAULT_ARTIFACTS_S3_BUCKET" '{print bucket "/" $2}')
145+
# echo "s3://spec.ccfc.min/firecracker-ci/v1.15"
146+
}
147+
# Function to return local path to artifacts. Accepts the url from function above
148+
# as an argument.
149+
get_local_artifacts_path() {
150+
local path=$1
151+
echo $LOCAL_ARTIFACTS_DIR/"${path//\//-}"
141152
}
142153

143154

@@ -567,7 +578,7 @@ cmd_distclean() {
567578

568579
cmd_download_ci_artifacts() {
569580
if [ "$1" = "--force" ]; then
570-
rm -rf $FC_BUILD_DIR/img
581+
rm -rf $ARTIFACTS_DIR
571582
fi
572583

573584
ensure_ci_artifacts
@@ -579,15 +590,21 @@ ensure_ci_artifacts() {
579590
fi
580591

581592
# Fetch all the artifacts so they are local
582-
S3_URL=$(get_newest_s3_artifacts)/$(uname -m)
583-
say "Fetching CI artifacts from S3: " $S3_URL
584-
ARTIFACTS=$MICROVM_IMAGES_DIR/$(uname -m)
585-
if [ ! -d "$ARTIFACTS" ]; then
586-
mkdir -pv $ARTIFACTS
587-
aws s3 sync --no-sign-request "$S3_URL" "$ARTIFACTS"
588-
ok_or_die "Failed to download CI artifacts using awscli!"
589-
cmd_sh "./tools/setup-ci-artifacts.sh"
593+
local artifacts_s3_url=$(get_newest_s3_artifacts)
594+
local artifacts_s3_url_arch=$artifacts_s3_url/$(uname -m)
595+
local artifacts_local_path=$(get_local_artifacts_path $artifacts_s3_url)/$(uname -m)
596+
597+
if [ ! -d "$artifacts_local_path" ]; then
598+
say "Fetching artifacts from S3: " $artifacts_s3_url_arch " into: " $artifacts_local_path
599+
mkdir -pv $artifacts_local_path
600+
aws s3 sync --no-sign-request "$artifacts_s3_url_arch" "$artifacts_local_path"
601+
ok_or_die "Failed to download artifacts using awscli!"
602+
cmd_sh "./tools/setup-ci-artifacts.sh" $artifacts_local_path
603+
else
604+
say "Found existing artifacts " $artifacts_s3_url_arch " at: " $artifacts_local_path
590605
fi
606+
607+
echo $artifacts_local_path > $LOCAL_ARTIFACTS_CURRENT_DIR_FILE
591608
}
592609

593610
apply_linux_61_tweaks() {

tools/setup-ci-artifacts.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ TOOLS_DIR=$(dirname $0)
99
source "$TOOLS_DIR/functions"
1010

1111
say "Setup CI artifacts"
12-
cd build/img/$(uname -m)
12+
cd $1
1313

1414
say "Fix executable permissions"
1515
find "firecracker" -type f |xargs chmod -c 755

tools/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ if [ -f $CGROUP/cgroup.controllers -a -e $CGROUP/cgroup.type ]; then
3232
fi
3333

3434
say "Copy CI artifacts to /srv, so hardlinks work"
35-
cp -ruvf build/img /srv
35+
cp -ruvfL $(cat build/current_artifacts) /srv/current_artifacts
3636

3737
cd tests
3838
export PYTEST_ADDOPTS="${PYTEST_ADDOPTS:-} --pdbcls=IPython.terminal.debugger:TerminalPdb"

0 commit comments

Comments
 (0)