-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new image with generated block logs for use in testing
- Loading branch information
Lucius
committed
Oct 7, 2024
1 parent
b53a736
commit 7b7ad10
Showing
5 changed files
with
187 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#! /bin/bash | ||
|
||
set -euo pipefail | ||
|
||
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" | ||
|
||
# shellcheck source=./docker_image_utils.sh | ||
source "$SCRIPTPATH/docker_image_utils.sh" | ||
|
||
submodule_path=$CI_PROJECT_DIR | ||
REGISTRY=$CI_REGISTRY_IMAGE | ||
REGISTRY_USER=$REGISTRY_USER | ||
REGISTRY_PASSWORD=$REGISTRY_PASS | ||
IMGNAME=/testing-block-logs | ||
|
||
echo "Attempting to get commit for: $submodule_path" | ||
|
||
CHANGES=(tests/python/functional/util/testing_block_logs/generate_testing_block_logs.py) | ||
commit=$("$SCRIPTPATH/retrieve_last_commit.sh" "${submodule_path}" "${CHANGES[@]}") | ||
echo "commit with last source code changes is $commit" | ||
|
||
pushd "${submodule_path}" | ||
short_commit=$(git -c core.abbrev=8 rev-parse --short "$commit") | ||
popd | ||
|
||
prefix_tag="testing-block-log" | ||
tag=$prefix_tag-$short_commit | ||
|
||
img=$( build_image_name $IMGNAME "$tag" "$REGISTRY" ) | ||
img_path=$( build_image_registry_path $IMGNAME "$tag" "$REGISTRY" ) | ||
img_tag=$( build_image_registry_tag $IMGNAME "$tag" "$REGISTRY" ) | ||
|
||
echo "$REGISTRY_PASSWORD" | docker login -u "$REGISTRY_USER" "$REGISTRY" --password-stdin | ||
|
||
image_exists=0 | ||
docker_image_exists $IMGNAME "$tag" "$REGISTRY" image_exists | ||
|
||
if [ "$image_exists" -eq 1 ]; | ||
then | ||
echo "Testing block log image is up to date. Skipping generation..." | ||
else | ||
echo "${img} image is missing. Starting generation of testing block logs..." | ||
echo "Save block logs to directory: $TESTING_BLOCK_LOGS_DIR" | ||
cd tests/python/functional/util/testing_block_logs | ||
python3 generate_testing_block_logs.py --output-block-log-directory="$TESTING_BLOCK_LOGS_DIR/block_logs_for_testing" | ||
echo "Block logs saved in: $TESTING_BLOCK_LOGS_DIR" | ||
|
||
checksum=$(find $TESTING_BLOCK_LOGS_DIR -type f | sort | xargs cat | md5sum |cut -d ' ' -f 1) | ||
echo "Checksum of the generated testing block logs: $checksum" | ||
|
||
echo "Build a Dockerfile" | ||
|
||
pwd | ||
cd $TESTING_BLOCK_LOGS_DIR | ||
pwd | ||
|
||
cat <<EOF > Dockerfile | ||
FROM scratch | ||
LABEL testing_block_logs_checksum=${checksum} | ||
COPY block_logs_for_testing /testing_block_logs | ||
EOF | ||
cat Dockerfile | ||
echo "Build docker image containing testing_block_logs" | ||
docker build -t $img . | ||
docker push $img | ||
echo "Created and push docker image with testing block logs: $img" | ||
fi | ||
|
||
echo "TESTING_BLOCK_LOG_LATEST_VERSION_IMAGE=$img" > $CI_PROJECT_DIR/testing_block_log_latest_version.env | ||
echo "TESTING_BLOCK_LOG_LATEST_COMMIT_SHORT_SHA=$short_commit" > $CI_PROJECT_DIR/testing_block_log_latest_commit_short_sha.env |
Empty file.
54 changes: 54 additions & 0 deletions
54
tests/python/functional/util/testing_block_logs/generate_testing_block_logs.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from __future__ import annotations | ||
|
||
import argparse | ||
from pathlib import Path | ||
|
||
from loguru import logger | ||
|
||
import test_tools as tt | ||
|
||
|
||
def generate_and_copy_empty_log( | ||
split_value: int, | ||
block_count: int, | ||
target_dir: Path, | ||
) -> None: | ||
node = tt.InitNode() | ||
node.config.block_log_split = split_value | ||
|
||
node.run(time_control=tt.SpeedUpRateTimeControl(speed_up_rate=10)) | ||
tt.logger.info(f"Waiting for block {block_count}...") | ||
node.wait_for_block_with_number(block_count) | ||
|
||
node.close() | ||
node.block_log.copy_to(target_dir / f"_{block_count}", artifacts="required") | ||
|
||
|
||
def prepare_empty_logs( | ||
output_block_log_directory: Path, | ||
) -> None: | ||
""" | ||
This script generates block logs (both split and monlithic) of different length with empty blocks only | ||
""" | ||
logger.disable("helpy") | ||
logger.disable("test_tools") | ||
|
||
# Initial 30 blocks are needed to have at least 10 irreversible ones. | ||
block_log_directory_30 = output_block_log_directory / "empty_30" | ||
block_log_directory_30.mkdir(parents=True, exist_ok=True) | ||
generate_and_copy_empty_log(9999, 30, block_log_directory_30) | ||
generate_and_copy_empty_log(-1, 30, block_log_directory_30) | ||
|
||
# 430 blocks is enough for the split block log to be in 2 parts. | ||
block_log_directory_430 = output_block_log_directory / "empty_430" | ||
block_log_directory_430.mkdir(parents=True, exist_ok=True) | ||
generate_and_copy_empty_log(9999, 430, block_log_directory_430) | ||
generate_and_copy_empty_log(-1, 430, block_log_directory_430) | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--output-block-log-directory", type=Path, default=Path(__file__).parent) | ||
args = parser.parse_args() | ||
prepare_empty_logs(args.output_block_log_directory) | ||
# TODO: Add generation of other logs here. |
Submodule test-tools
updated
2 files
+14 −30 | tests/functional_tests/block_log_tests/test_block_log_util_tools.py | |
+26 −0 | tests/functional_tests/conftest.py |