Skip to content

Commit

Permalink
Outsource duplicated code of test single jobs to helper script
Browse files Browse the repository at this point in the history
CMK-20920

Change-Id: I20fdf1421ee3508d663a719616e46ed9bec3711e
  • Loading branch information
JonasScharpf committed Jan 16, 2025
1 parent 14fde02 commit 9fb3639
Show file tree
Hide file tree
Showing 5 changed files with 220 additions and 359 deletions.
132 changes: 28 additions & 104 deletions buildscripts/scripts/test-composition-single-f12less.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -14,69 +14,26 @@ def main() {
"OTEL_EXPORTER_OTLP_ENDPOINT",
]);

def versioning = load("${checkout_dir}/buildscripts/scripts/utils/versioning.groovy");
def single_tests = load("${checkout_dir}/buildscripts/scripts/utils/single_tests.groovy");
def test_jenkins_helper = load("${checkout_dir}/buildscripts/scripts/utils/test_helper.groovy");

// TODO: we should always use USE_CASE directly from the job parameters
def use_case = (USE_CASE == "fips") ? USE_CASE : "daily_tests"
test_jenkins_helper.assert_fips_testing(use_case, NODE_LABELS);
def distro = params.DISTRO;

def safe_branch_name = versioning.safe_branch_name(scm);
def branch_version = versioning.get_branch_version(checkout_dir);
// When building from a git tag (VERSION != "daily"), we cannot get the branch name from the scm so used defines.make instead.
// this is save on master as there are no tags/versions built other than daily
def branch_name = safe_branch_name;
def cmk_version_rc_aware = versioning.get_cmk_version(safe_branch_name, branch_version, "daily");
def cmk_version = versioning.strip_rc_number_from_version(cmk_version_rc_aware);
def docker_tag = versioning.select_docker_tag(
"", // 'build tag'
safe_branch_name, // 'branch' returns '<BRANCH>-latest'
);

def edition = params.EDITION;

def make_target = "test-composition-docker";
// TODO: we should always use USE_CASE directly from the job parameters
def use_case = (params.USE_CASE == "fips") ? params.USE_CASE : "daily_tests"
test_jenkins_helper.assert_fips_testing(use_case, NODE_LABELS);

// Use the directory also used by tests/testlib/containers.py to have it find
// the downloaded package.
def download_dir = "package_download";
def make_target = "test-composition-docker";

currentBuild.description += (
"""
|Run composition tests for packages<br>
|safe_branch_name: ${safe_branch_name}<br>
|branch_version: ${branch_version}<br>
|cmk_version: ${cmk_version}<br>
|docker_tag: ${docker_tag}<br>
|edition: ${edition}<br>
|distro: ${distro}<br>
|make_target: ${make_target}<br>
""".stripMargin());

print(
"""
|===== CONFIGURATION ===============================
|safe_branch_name:......... │${safe_branch_name}
|branch_name:.............. │${branch_name}
|cmk_version:.............. │${cmk_version}
|cmk_version_rc_aware:..... │${cmk_version_rc_aware}
|branch_version:........... │${branch_version}
|docker_tag:............... │${docker_tag}
|edition:.................. │${edition}
|distro:................... │${distro}
|make_target:.............. │${make_target}
|checkout_dir:............. │${checkout_dir}
|===================================================
""".stripMargin());
def setup_values = single_tests.common_prepare(version: "daily", make_target: make_target);

// this is a quick fix for FIPS based tests, see CMK-20851
def build_node = params.CIPARAM_OVERRIDE_BUILD_NODE;
if (build_node == "fips") {
// Do not start builds on FIPS node
println("Detected build node 'fips', switching this to 'fra'.");
build_node = "fra"
}
// todo: add upstream project to description
// todo: add error to description
// todo: build progress mins?

stage("Prepare workspace") {
inside_container(
Expand All @@ -88,69 +45,36 @@ def main() {
mount_credentials: true,
priviliged: true,
) {
dir("${checkout_dir}") {
// Cleanup test results directory before starting the test to prevent previous
// runs somehow affecting the current run.
sh("rm -rf ${WORKSPACE}/test-results");

/// remove downloaded packages since they consume dozens of MiB
sh("""rm -rf "${checkout_dir}/${download_dir}" """);

// Initialize our virtual environment before parallelization
sh("make .venv");
single_tests.prepare_workspace(
cleanup: [
"${WORKSPACE}/test-results",
"${checkout_dir}/${download_dir}"
],
make_venv: true
);

dir("${checkout_dir}") {
stage("Fetch Checkmk package") {
upstream_build(
relative_job_name: "builders/build-cmk-distro-package",
build_params: [
/// currently CUSTOM_GIT_REF must match, but in the future
/// we should define dependency paths for build-cmk-distro-package
CUSTOM_GIT_REF: cmd_output("git rev-parse HEAD"),
EDITION: edition,
DISTRO: distro,
],
build_params_no_check: [
CIPARAM_OVERRIDE_BUILD_NODE: build_node,
],
dest: download_dir,
);
single_tests.fetch_package(edition: edition, distro: distro, download_dir: download_dir);
}
try {
stage("Run `make ${make_target}`") {
dir("${checkout_dir}/tests") {
docker.withRegistry(DOCKER_REGISTRY, "nexus") {
sh("""
RESULT_PATH='${WORKSPACE}/test-results/${distro}' \
EDITION='${edition}' \
DOCKER_TAG='${docker_tag}' \
VERSION='daily' \
DISTRO='${distro}' \
BRANCH='${branch_name}' \
OTEL_EXPORTER_OTLP_ENDPOINT='${env.OTEL_EXPORTER_OTLP_ENDPOINT}' \
CI_NODE_NAME='${env.NODE_NAME}' \
CI_WORKSPACE='${env.WORKSPACE}' \
CI_JOB_NAME='${env.JOB_NAME}' \
CI_BUILD_NUMBER='${env.BUILD_NUMBER}' \
CI_BUILD_URL='${env.BUILD_URL}' \
make ${make_target}
""");
}
single_tests.run_make_target(
result_path: "${WORKSPACE}/test-results/${distro}",
edition: edition,
docker_tag: setup_values.docker_tag,
version: "daily",
distro: distro,
branch_name: setup_values.safe_branch_name,
make_target: make_target,
);
}
}
} finally {
stage("Archive / process test reports") {
dir("${WORKSPACE}") {
show_duration("archiveArtifacts") {
archiveArtifacts(allowEmptyArchive: true, artifacts: "test-results/**");
}
xunit([Custom(
customXSL: "$JENKINS_HOME/userContent/xunit/JUnit/0.1/pytest-xunit.xsl",
deleteOutputFiles: true,
failIfNotNew: true,
pattern: "**/junit.xml",
skipNoTestFiles: false,
stopProcessingIfError: true
)]);
single_tests.archive_and_process_reports(test_results: "test-results/**");
}
}
}
Expand Down
98 changes: 21 additions & 77 deletions buildscripts/scripts/test-integration-single-f12less-redfish.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -14,45 +14,15 @@ def main() {
"DOCKER_REGISTRY",
]);

def versioning = load("${checkout_dir}/buildscripts/scripts/utils/versioning.groovy");
def single_tests = load("${checkout_dir}/buildscripts/scripts/utils/single_tests.groovy");

def safe_branch_name = versioning.safe_branch_name(scm);
def branch_version = versioning.get_branch_version(checkout_dir);
def cmk_version = versioning.get_cmk_version(safe_branch_name, branch_version, "daily");
def docker_tag = versioning.select_docker_tag(
"", // 'build tag'
safe_branch_name, // 'branch'
);
def distro = params.DISTRO;
def edition = params.EDITION;

def make_target = "test-integration-redfish-docker";
def download_dir = "package_download";

currentBuild.description += (
"""
|Run integration tests for redifsh<br>
|safe_branch_name: ${safe_branch_name}<br>
|branch_version: ${branch_version}<br>
|cmk_version: ${cmk_version}<br>
|docker_tag: ${docker_tag}<br>
|edition: ${edition}<br>
|distro: ${distro}<br>
|make_target: ${make_target}<br>
""".stripMargin());

print(
"""
|===== CONFIGURATION ===============================
|safe_branch_name:...... │${safe_branch_name}
|branch_version:........ │${branch_version}
|cmk_version:........... │${cmk_version}
|docker_tag:............ │${docker_tag}
|edition:............... │${edition}
|distro:................ │${distro}
|make_target:........... │${make_target}
|===================================================
""".stripMargin());
def setup_values = single_tests.common_prepare(version: "daily", make_target: make_target);

// todo: add upstream project to description
// todo: add error to description
Expand All @@ -68,62 +38,36 @@ def main() {
mount_credentials: true,
priviliged: true,
) {
dir("${checkout_dir}") {
// Cleanup test results directory before starting the test to prevent previous
// runs somehow affecting the current run.
sh("rm -rf ${WORKSPACE}/test-results");

/// remove downloaded packages since they consume dozens of MiB
sh("""rm -rf "${checkout_dir}/${download_dir}" """);

// Initialize our virtual environment before parallelization
sh("make .venv");
single_tests.prepare_workspace(
cleanup: [
"${WORKSPACE}/test-results",
"${checkout_dir}/${download_dir}"
],
make_venv: true
);

dir("${checkout_dir}") {
stage("Fetch Checkmk package") {
upstream_build(
relative_job_name: "builders/build-cmk-distro-package",
build_params: [
/// currently CUSTOM_GIT_REF must match, but in the future
/// we should define dependency paths for build-cmk-distro-package
CUSTOM_GIT_REF: cmd_output("git rev-parse HEAD"),
EDITION: edition,
DISTRO: distro,
],
build_params_no_check: [
CIPARAM_OVERRIDE_BUILD_NODE: params.CIPARAM_OVERRIDE_BUILD_NODE,
],
dest: download_dir,
);
single_tests.fetch_package(edition: edition, distro: distro, download_dir: download_dir);
}
try {
stage("Run `make ${make_target}`") {
dir("${checkout_dir}/tests") {
docker.withRegistry(DOCKER_REGISTRY, "nexus") {
sh("""
RESULT_PATH='${WORKSPACE}/test-results/${distro}' \
EDITION='${edition}' \
DOCKER_TAG='${docker_tag}' \
VERSION="daily" \
DISTRO='${distro}' \
make ${make_target}
""");
}
single_tests.run_make_target(
result_path: "${WORKSPACE}/test-results/${distro}",
edition: edition,
docker_tag: setup_values.docker_tag,
version: "daily",
distro: distro,
branch_name: setup_values.safe_branch_name,
make_target: make_target,
);
}
}
} finally {
stage("Archive / process test reports") {
dir("${WORKSPACE}") {
show_duration("archiveArtifacts") {
archiveArtifacts("test-results/**");
}
xunit([Custom(
customXSL: "$JENKINS_HOME/userContent/xunit/JUnit/0.1/pytest-xunit.xsl",
deleteOutputFiles: true,
failIfNotNew: true,
pattern: "**/junit.xml",
skipNoTestFiles: false,
stopProcessingIfError: true
)]);
single_tests.archive_and_process_reports(test_results: "test-results/**");
}
}
}
Expand Down
Loading

0 comments on commit 9fb3639

Please sign in to comment.