diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f515728354853..962c6103a109a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -177,7 +177,7 @@ variables: # To use images from test-infra-definitions dev branches, set the SUFFIX variable to -dev # and check the job creating the image to make sure you have the right SHA prefix TEST_INFRA_DEFINITIONS_BUILDIMAGES_SUFFIX: "" - TEST_INFRA_DEFINITIONS_BUILDIMAGES: a60850d5606e + TEST_INFRA_DEFINITIONS_BUILDIMAGES: 40b046c22010 DATADOG_AGENT_BUILDERS: v22276738-b36b132 DATADOG_AGENT_EMBEDDED_PATH: /opt/datadog-agent/embedded diff --git a/.gitlab/junit_upload/functional_test_junit_upload_system_probe.yml b/.gitlab/junit_upload/functional_test_junit_upload_system_probe.yml index d362441aab6e5..c151297b07e80 100644 --- a/.gitlab/junit_upload/functional_test_junit_upload_system_probe.yml +++ b/.gitlab/junit_upload/functional_test_junit_upload_system_probe.yml @@ -23,17 +23,12 @@ functional_test_junit_upload_system_probe: - set -x - ss=0; for f in $DD_AGENT_TESTING_DIR/kitchen-junit-*.tar.gz; do [[ -e "$f" ]] || continue; inv -e junit-upload --tgz-path $f || ((ss++)); done; exit $ss -functional_test_junit_upload_system_probe_kmt: +.functional_test_junit_upload_system_probe_kmt: stage: functional_test_junit_upload image: 486234852809.dkr.ecr.us-east-1.amazonaws.com/ci/datadog-agent-buildimages/datadog-ci-uploader$DATADOG_AGENT_BUILDIMAGES_SUFFIX:$DATADOG_AGENT_BUILDIMAGES tags: ["arch:amd64"] allow_failure: true when: always - needs: - - job: kernel_matrix_testing_run_tests_x64 - optional: true - - job: kernel_matrix_testing_run_tests_arm64 - optional: true variables: DD_ENV: ci script: @@ -42,3 +37,19 @@ functional_test_junit_upload_system_probe_kmt: - export JIRA_TOKEN=$(aws ssm get-parameter --region us-east-1 --name ci.datadog-agent.jira_read_api_token --with-decryption --query "Parameter.Value" --out text) - set -x - ss=0; for f in $DD_AGENT_TESTING_DIR/junit-*.tar.gz; do [[ -e "$f" ]] || continue; inv -e junit-upload --tgz-path $f || ((ss++)); done; exit $ss + +# junit upload jobs are separted because of gitlab limit on the number of jobs +# a single job can 'need'. +functional_test_junit_upload_system_probe_kmt_x64: + extends: + - .functional_test_junit_upload_system_probe_kmt + needs: + - job: kernel_matrix_testing_run_tests_x64 + optional: true + +functional_test_junit_upload_system_probe_kmt_arm64: + extends: + - .functional_test_junit_upload_system_probe_kmt + needs: + - job: kernel_matrix_testing_run_tests_arm64 + optional: true diff --git a/.gitlab/kernel_version_testing/system_probe.yml b/.gitlab/kernel_version_testing/system_probe.yml index b5005039c0f12..c7745d7a56d64 100644 --- a/.gitlab/kernel_version_testing/system_probe.yml +++ b/.gitlab/kernel_version_testing/system_probe.yml @@ -154,6 +154,7 @@ upload_dependencies_arm64: - cp -R $KITCHEN_TESTS $SYSTEM_PROBE_TESTS - pushd $CI_PROJECT_DIR/test/new-e2e/system-probe/test-runner && go build -o $DEPENDENCIES/test-runner && popd - pushd $CI_PROJECT_DIR/test/new-e2e/system-probe/test-json-review && go build -o $DEPENDENCIES/test-json-review && popd + - cp $CI_PROJECT_DIR/test/new-e2e/system-probe/test-runner/files/*.json $DEPENDENCIES/ - popd # package all the dependencies - ls -la $DEPENDENCIES @@ -291,6 +292,8 @@ upload_minimized_btfs_arm64: RESOURCE_TAGS: "instance-type:${INSTANCE_TYPE},arch:${ARCH}" KUBERNETES_MEMORY_REQUEST: "12Gi" KUBERNETES_MEMORY_LIMIT: "16Gi" + VMCONFIG_FILE: "${CI_PROJECT_DIR}/vmconfig-${CI_PIPELINE_ID}-${ARCH}.json" + TEST_SETS: "no_tracersuite,only_tracersuite" before_script: - set +x - export DD_API_KEY=$(aws ssm get-parameter --region us-east-1 --name ci.datadog-agent.datadog_api_key_org2 --with-decryption --query "Parameter.Value" --out text) @@ -301,7 +304,8 @@ upload_minimized_btfs_arm64: script: - echo "s3://dd-pulumi-state?region=us-east-1&awssdk=v2&profile=$AWS_PROFILE" > $STACK_DIR - pulumi login $(cat $STACK_DIR | tr -d '\n') - - inv -e system-probe.start-microvms --provision --vmconfig=$VMCONFIG_PATH $INSTANCE_TYPE_ARG $AMI_ID_ARG --ssh-key-name=$AWS_EC2_SSH_KEY_NAME --ssh-key-path=$AWS_EC2_SSH_KEY_FILE --infra-env=$INFRA_ENV --stack-name=kernel-matrix-testing-$ARCH-$CI_PIPELINE_ID --run-agent + - inv -e kmt.gen-config --ci --arch=$ARCH --output-file=$VMCONFIG_FILE --sets=$TEST_SETS + - inv -e system-probe.start-microvms --provision --vmconfig=$VMCONFIG_FILE $INSTANCE_TYPE_ARG $AMI_ID_ARG --ssh-key-name=$AWS_EC2_SSH_KEY_NAME --ssh-key-path=$AWS_EC2_SSH_KEY_FILE --infra-env=$INFRA_ENV --stack-name=kernel-matrix-testing-$ARCH-$CI_PIPELINE_ID --run-agent - cat $CI_PROJECT_DIR/stack.output - pulumi logout after_script: @@ -317,6 +321,7 @@ upload_minimized_btfs_arm64: paths: - $CI_PROJECT_DIR/stack.output - $CI_PROJECT_DIR/libvirt + - $VMCONFIG_FILE kernel_matrix_testing_setup_env_arm64: extends: @@ -327,7 +332,6 @@ kernel_matrix_testing_setup_env_arm64: ARCH: arm64 AMI_ID_ARG: "--arm-ami-id=$KERNEL_MATRIX_TESTING_ARM_AMI_ID" LibvirtSSHKey: $CI_PROJECT_DIR/libvirt_rsa-arm - VMCONFIG_PATH: $CI_PROJECT_DIR/test/new-e2e/system-probe/config/vmconfig-arm64.json kernel_matrix_testing_setup_env_x64: extends: @@ -338,7 +342,6 @@ kernel_matrix_testing_setup_env_x64: ARCH: x86_64 AMI_ID_ARG: "--x86-ami-id=$KERNEL_MATRIX_TESTING_X86_AMI_ID" LibvirtSSHKey: $CI_PROJECT_DIR/libvirt_rsa-x86 - VMCONFIG_PATH: $CI_PROJECT_DIR/test/new-e2e/system-probe/config/vmconfig-x64.json .kernel_matrix_testing_run_tests: stage: kernel_matrix_testing @@ -348,6 +351,7 @@ kernel_matrix_testing_setup_env_x64: variables: AWS_EC2_SSH_KEY_FILE: $CI_PROJECT_DIR/ssh_key RETRY: 2 + MICROVM_GREP_PATTERN: "$ARCH-$TAG-.*$TEST_SET.*-ddvm" before_script: - set +x - export DD_API_KEY=$(aws ssm get-parameter --region us-east-1 --name ci.datadog-agent.datadog_api_key_org2 --with-decryption --query "Parameter.Value" --out text) @@ -367,28 +371,28 @@ kernel_matrix_testing_setup_env_x64: echo "These jobs do not permit retries. The go tests are retried a user-specified number of times automatically. In order to re-run the tests, you must trigger the pipeline again" 'false' fi - - MICRO_VM_IP=$(cat $CI_PROJECT_DIR/stack.output | grep $ARCH-$TAG | cut -d ' ' -f 2) - - MICRO_VM_NAME=$(cat $CI_PROJECT_DIR/stack.output | grep $ARCH-$TAG | cut -d ' ' -f 1) + - MICRO_VM_IP=$(cat $CI_PROJECT_DIR/stack.output | grep $MICROVM_GREP_PATTERN | cut -d ' ' -f 2) + - MICRO_VM_NAME=$(cat $CI_PROJECT_DIR/stack.output | grep $MICROVM_GREP_PATTERN | cut -d ' ' -f 1) - GO_VERSION=$(inv go-version) - !reference [.setup_ssh_config] # ssh into each micro-vm and run initialization script. This script will also run the tests. - - scp "$DD_AGENT_TESTING_DIR/job_env.txt" "metal_instance:/home/ubuntu/job_env-${ARCH}-${TAG}.txt" - - ssh metal_instance "scp /home/ubuntu/job_env-${ARCH}-${TAG}.txt ${MICRO_VM_IP}:/job_env.txt" - - NESTED_VM_CMD="/home/ubuntu/connector -host ${MICRO_VM_IP} -user root -ssh-file /home/kernel-version-testing/ddvm_rsa -vm-cmd 'bash /root/fetch_dependencies.sh ${ARCH} && /micro-vm-init.sh ${RETRY}'" + - scp "$DD_AGENT_TESTING_DIR/job_env.txt" "metal_instance:/home/ubuntu/job_env-${ARCH}-${TAG}-${TEST_SET}.txt" + - ssh metal_instance "scp /home/ubuntu/job_env-${ARCH}-${TAG}-${TEST_SET}.txt ${MICRO_VM_IP}:/job_env.txt" + - NESTED_VM_CMD="/home/ubuntu/connector -host ${MICRO_VM_IP} -user root -ssh-file /home/kernel-version-testing/ddvm_rsa -vm-cmd 'bash /root/fetch_dependencies.sh ${ARCH} && /micro-vm-init.sh ${RETRY} /${TEST_SET}.json'" - $CI_PROJECT_DIR/connector-$ARCH -host $INSTANCE_IP -user ubuntu -ssh-file $AWS_EC2_SSH_KEY_FILE -vm-cmd "${NESTED_VM_CMD}" - ssh metal_instance "ssh ${MICRO_VM_IP} '/test-json-review'" after_script: - - MICRO_VM_IP=$(cat $CI_PROJECT_DIR/stack.output | grep $ARCH-$TAG | cut -d ' ' -f 2) - - ssh metal_instance "scp ${MICRO_VM_IP}:/ci-visibility/junit.tar.gz /home/ubuntu/junit-${ARCH}-${TAG}.tar.gz" - - scp "metal_instance:/home/ubuntu/junit-${ARCH}-${TAG}.tar.gz" $DD_AGENT_TESTING_DIR/ - - ssh metal_instance "scp ${MICRO_VM_IP}:/ci-visibility/testjson.tar.gz /home/ubuntu/testjson-${ARCH}-${TAG}.tar.gz" - - scp "metal_instance:/home/ubuntu/testjson-${ARCH}-${TAG}.tar.gz" $DD_AGENT_TESTING_DIR/ + - MICRO_VM_IP=$(cat $CI_PROJECT_DIR/stack.output | grep $MICROVM_GREP_PATTERN | cut -d ' ' -f 2) + - ssh metal_instance "scp ${MICRO_VM_IP}:/ci-visibility/junit.tar.gz /home/ubuntu/junit-${ARCH}-${TAG}-${TEST_SET}.tar.gz" + - scp "metal_instance:/home/ubuntu/junit-${ARCH}-${TAG}-${TEST_SET}.tar.gz" $DD_AGENT_TESTING_DIR/ + - ssh metal_instance "scp ${MICRO_VM_IP}:/ci-visibility/testjson.tar.gz /home/ubuntu/testjson-${ARCH}-${TAG}-${TEST_SET}.tar.gz" + - scp "metal_instance:/home/ubuntu/testjson-${ARCH}-${TAG}-${TEST_SET}.tar.gz" $DD_AGENT_TESTING_DIR/ artifacts: expire_in: 2 weeks when: always paths: - - $DD_AGENT_TESTING_DIR/junit-$ARCH-$TAG.tar.gz - - $DD_AGENT_TESTING_DIR/testjson-$ARCH-$TAG.tar.gz + - $DD_AGENT_TESTING_DIR/junit-$ARCH-$TAG-$TEST_SET.tar.gz + - $DD_AGENT_TESTING_DIR/testjson-$ARCH-$TAG-$TEST_SET.tar.gz kernel_matrix_testing_run_tests_x64: extends: @@ -402,6 +406,7 @@ kernel_matrix_testing_run_tests_x64: parallel: matrix: - TAG: ["ubuntu_16.04", "ubuntu_18.04", "ubuntu_20.04", "ubuntu_22.04", "ubuntu_23.10", "amzn_4.14", "amzn_5.4", "amzn_5.10", "fedora_37", "fedora_38", "debian_10", "debian_11", "debian_12", "centos_79", "centos_8"] + TEST_SET: ["no_tracersuite", "only_tracersuite"] kernel_matrix_testing_run_tests_arm64: extends: @@ -415,6 +420,7 @@ kernel_matrix_testing_run_tests_arm64: parallel: matrix: - TAG: ["ubuntu_18.04", "ubuntu_20.04", "ubuntu_22.04", "ubuntu_23.10", "amzn_4.14", "amzn_5.4", "amzn_5.10", "fedora_37", "fedora_38", "debian_10", "debian_11", "debian_12", "centos_79", "centos_8"] + TEST_SET: ["no_tracersuite", "only_tracersuite"] .kernel_matrix_testing_cleanup: stage: kernel_matrix_testing diff --git a/tasks/kernel_matrix_testing/vmconfig.py b/tasks/kernel_matrix_testing/vmconfig.py index c827374529147..3a8a25dff47f7 100644 --- a/tasks/kernel_matrix_testing/vmconfig.py +++ b/tasks/kernel_matrix_testing/vmconfig.py @@ -1,14 +1,18 @@ +import copy import itertools import json import math import os import platform +from urllib.parse import urlparse -from .download import archs_mapping, karch_mapping, url_base -from .init_kmt import KMT_STACKS_DIR, VMCONFIG, check_and_get_stack -from .stacks import ARM_INSTANCE_TYPE, X86_INSTANCE_TYPE, create_stack, stack_exists +from .init_kmt import KMT_ROOTFS_DIR, KMT_STACKS_DIR, VMCONFIG, check_and_get_stack +from .stacks import create_stack, stack_exists from .tool import Exit, ask, info, warn +local_arch = "local" +vmconfig_file = "test/new-e2e/system-probe/config/vmconfig.json" + try: from thefuzz import fuzz, process except ImportError: @@ -55,80 +59,42 @@ "4.20", ] distributions = { - "ubuntu_18": "bionic", - "ubuntu_20": "focal", - "ubuntu_22": "jammy", - "jammy": "jammy", - "focal": "focal", - "bionic": "bionic", + # Ubuntu mappings + "ubuntu_16": "ubuntu_16.04", + "ubuntu_18": "ubuntu_18.04", + "ubuntu_20": "ubuntu_20.04", + "ubuntu_22": "ubuntu_22.04", + "ubuntu_23": "ubuntu_23.10", + "xenial": "ubuntu_16.04", + "bionic": "ubuntu_18.04", + "focal": "ubuntu_20.04", + "jammy": "ubuntu_22.04", + "mantic": "ubuntu_23.10", + # Amazon Linux mappings "amazon_4.14": "amzn_4.14", "amazon_5.4": "amzn_5.4", "amazon_5.10": "amzn_5.10", - "amazon_5.15": "amzn_5.15", "amzn_4.14": "amzn_4.14", "amzn_5.4": "amzn_5.4", "amzn_5.10": "amzn_5.10", - "amzn_5.15": "amzn_5.15", - "fedora_35": "fedora_35", - "fedora_36": "fedora_36", + # Fedora mappings "fedora_37": "fedora_37", "fedora_38": "fedora_38", + # Debian mappings "debian_10": "debian_10", "debian_11": "debian_11", -} -distro_arch_mapping = {"x86_64": "amd64", "arm64": "arm64"} -images_path_local = { - "bionic": "file:///home/kernel-version-testing/rootfs/bionic-server-cloudimg-{arch}.qcow2", - "focal": "file:///home/kernel-version-testing/rootfs/focal-server-cloudimg-{arch}.qcow2", - "jammy": "file:///home/kernel-version-testing/rootfs/jammy-server-cloudimg-{arch}.qcow2", - "bullseye": "file:///home/kernel-version-testing/rootfs/custom-bullseye.{arch}.qcow2", - "buster": "file:///home/kernel-version-testing/rootfs/custom-buster.{arch}.qcow2", - "amzn_4.14": "file:///home/kernel-version-testing/rootfs/amzn2-kvm-2.0-{arch}-4.14.qcow2", - "amzn_5.4": "file:///home/kernel-version-testing/rootfs/amzn2-kvm-2.0-{arch}-5.4.qcow2", - "amzn_5.10": "file:///home/kernel-version-testing/rootfs/amzn2-kvm-2.0-{arch}-5.10.qcow2", - "amzn_5.15": "file:///home/kernel-version-testing/rootfs/amzn2-kvm-2.0-{arch}-5.15.qcow2", - "fedora_35": "file:///home/kernel-version-testing/rootfs/Fedora-Cloud-Base-35.{arch}.qcow2", - "fedora_36": "file:///home/kernel-version-testing/rootfs/Fedora-Cloud-Base-36.{arch}.qcow2", - "fedora_37": "file:///home/kernel-version-testing/rootfs/Fedora-Cloud-Base-37.{arch}.qcow2", - "fedora_38": "file:///home/kernel-version-testing/rootfs/Fedora-Cloud-Base-38.{arch}.qcow2", - "debian_10": "file:///home/kernel-version-testing/rootfs/debian-10-generic-{arch}.qcow2", - "debian_11": "file:///home/kernel-version-testing/rootfs/debian-11-generic-{arch}.qcow2", + "debian_12": "debian_12", + # CentOS mappings + "centos_79": "centos_79", } -images_path_s3 = { - "bionic": "{url_base}bionic-server-cloudimg-{arch}.qcow2", - "focal": "{url_base}focal-server-cloudimg-{arch}.qcow2", - "jammy": "{url_base}jammy-server-cloudimg-{arch}.qcow2", - "bullseye": "{url_base}custom-bullseye.{arch}.qcow2", - "buster": "{url_base}custom-buster.{arch}.qcow2", - "amzn_4.14": "{url_base}amzn2-kvm-2.0-{arch}-4.14.qcow2", - "amzn_5.4": "{url_base}amzn2-kvm-2.0-{arch}-5.4.qcow2", - "amzn_5.10": "{url_base}amzn2-kvm-2.0-{arch}-5.10.qcow2", - "amzn_5.15": "{url_base}amzn2-kvm-2.0-{arch}-5.15.qcow2", - "fedora_35": "{url_base}Fedora-Cloud-Base-35.{arch}.qcow2", - "fedora_36": "{url_base}Fedora-Cloud-Base-36.{arch}.qcow2", - "fedora_37": "{url_base}Fedora-Cloud-Base-37.{arch}.qcow2", - "fedora_38": "{url_base}Fedora-Cloud-Base-38.{arch}.qcow2", - "debian_10": "{url_base}debian-10-generic-{arch}.qcow2", - "debian_11": "{url_base}debian-11-generic-{arch}.qcow2", -} - -images_name = { - "bionic": "bionic-server-cloudimg-{arch}.qcow2", - "focal": "focal-server-cloudimg-{arch}.qcow2", - "jammy": "jammy-server-cloudimg-{arch}.qcow2", - "bullseye": "custom-bullseye.{arch}.qcow2", - "buster": "custom-buster.{arch}.qcow2", - "amzn_4.14": "amzn2-kvm-2.0-{arch}-4.14.qcow2", - "amzn_5.4": "amzn2-kvm-2.0-{arch}-5.4.qcow2", - "amzn_5.10": "amzn2-kvm-2.0-{arch}-5.10.qcow2", - "amzn_5.15": "amzn2-kvm-2.0-{arch}-5.15.qcow2", - "fedora_35": "Fedora-Cloud-Base-35.{arch}.qcow2", - "fedora_36": "Fedora-Cloud-Base-36.{arch}.qcow2", - "fedora_37": "Fedora-Cloud-Base-37.{arch}.qcow2", - "fedora_38": "Fedora-Cloud-Base-38.{arch}.qcow2", - "debian_10": "debian-10-generic-{arch}.qcow2", - "debian_11": "debian-11-generic-{arch}.qcow2", +arch_mapping = { + "amd64": "x86_64", + "x86": "x86_64", + "x86_64": "x86_64", + "arm64": "arm64", + "arm": "arm64", + "aarch64": "arm64", } TICK = "\u2713" @@ -150,14 +116,10 @@ ["debian 11 - v5.10.0", TICK, TICK], ] -consoles = {"x86_64": "ttyS0", "arm64": "ttyAMA0"} - -def get_image_path(img, arch, local): - if local: - return images_path_local[img].format(arch=arch) - - return images_path_s3[img].format(arch=arch, url_base=url_base) +def lte_414(version): + major, minor = version.split('.') + return (int(major) <= 4) and (int(minor) <= 14) def get_image_list(distro, custom): @@ -207,7 +169,8 @@ def empty_config(file_path): def list_possible(): distros = list(distributions.keys()) - archs = list(archs_mapping.keys()) + archs = list(arch_mapping.keys()) + archs.append(local_arch) result = list() possible = list(itertools.product(["custom"], kernels, archs)) + list(itertools.product(["distro"], distros, archs)) @@ -229,216 +192,293 @@ def normalize_vm_def(possible, vm): vm_def, _ = process.extractOne(vm, possible, scorer=fuzz.token_sort_ratio) recipe, version, arch = vm_def.split('-') - arch = archs_mapping[arch] + if arch != local_arch: + arch = arch_mapping[arch] + if recipe == "distro": version = distributions[version] return recipe, version, arch -def vmset_name_from_id(set_id): - recipe, arch, id_tag = set_id - - return f"{recipe}_{id_tag}_{arch}" +def get_custom_kernel_config(version, arch): + if arch == local_arch: + arch = arch_mapping[platform.machine()] + if arch == "x86_64": + console = "ttyS0" + else: + console = "ttyAMA0" -# Set id uniquely categorizes each requested -# VM into particular sets. -# Each set id will contain 1 or more of the VMs requested -# by the user. -def vmset_id(recipe, version, arch): - if recipe == "custom": - if lte_414(version): - return (recipe, arch, "lte_414") - else: - return (recipe, arch, "gt_414") + if lte_414(version): + extra_params = {"console": console, "systemd.unified_cgroup_hierarchy": "0"} else: - return recipe, arch, "distro" + extra_params = { + "console": console, + } + + return { + "dir": f"kernel-{version}.{arch}.pkg", + "tag": version, + "extra_params": extra_params, + } # This function derives the configuration for each # unique kernel or distribution from the normalized vm-def. # For more details on the generated configuration element, refer # to the micro-vms scenario in test-infra-definitions -def get_kernel_config(recipe, version, arch): +def get_kernel_config(template, recipe, version, arch): if recipe == "custom": return get_custom_kernel_config(version, arch) - elif recipe == "distro": - return get_distro_image_config(version, arch) - raise Exit(f"Invalid recipe {recipe}") + if arch == "local": + arch = arch_mapping[platform.machine()] + setname = f"{recipe}_{arch}" -def lte_414(version): - major, minor = version.split('.') - return (int(major) <= 4) and (int(minor) <= 14) + for vmset in template["vmsets"]: + if setname not in vmset["tags"]: + continue + for kernel in vmset["kernels"]: + if kernel["tag"] == version: + return copy.deepcopy(kernel) -def get_custom_kernel_config(version, arch): - if arch == "local": - arch = archs_mapping[platform.machine()] + raise Exit(f"No kernel {version} in set {setname}") - kernel = { - "dir": f"kernel-v{version}.{karch_mapping[arch]}.pkg", - "tag": version, - "extra_params": {"console": consoles[arch]}, + +def vmset_exists(vm_config, tags): + vmsets = vm_config["vmsets"] + + for vmset in vmsets: + if set(vmset["tags"]) == tags: + return True + + return False + + +def kernel_in_vmset(vmset, kernel): + vmset_kernels = vmset["kernels"] + for k in vmset_kernels: + if k["tag"] == kernel["tag"]: + return True + + return False + + +def vmset_name(arch, recipe): + return f"{recipe}_{arch}" + + +def add_custom_vmset(vmset, vm_config): + arch = vmset.arch + if arch == local_arch: + arch = arch_mapping[platform.machine()] + + lte = False + for vm in vmset.vms: + if lte_414(vm.version): + lte = True + break + + image_path = f"custom-bullseye.{arch}.qcow2" + if lte: + image_path = f"custom-buster.{arch}.qcow2" + + if vmset_exists(vm_config, vmset.tags): + return + + new_set = { + "tags": list(vmset.tags), + "recipe": f"{vmset.recipe}-{vmset.arch}", + "arch": vmset.arch, + "kernels": list(), + "image": { + "image_path": image_path, + "image_source": f"https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/{image_path}", + }, } - if lte_414(version): - kernel["extra_params"]["systemd.unified_cgroup_hierarchy"] = "0" + vm_config["vmsets"].append(new_set) - return kernel +def add_vmset(vmset, vm_config): + if vmset_exists(vm_config, vmset.tags): + return -def get_distro_image_config(version, arch): - local = False - if arch == "local": - local = True - arch = archs_mapping[platform.machine()] + if vmset.recipe == "custom": + return add_custom_vmset(vmset, vm_config) - return { - "dir": images_name[version].format(arch=distro_arch_mapping[arch]), - "tag": version, - "image_source": get_image_path(version, distro_arch_mapping[arch], local), + new_set = { + "tags": list(vmset.tags), + "recipe": f"{vmset.recipe}-{vmset.arch}", + "arch": vmset.arch, + "kernels": list(), } + vm_config["vmsets"].append(new_set) -# This function generates new VMSets. Refer to the documentation -# of the micro-vm scenario in test-infra-definitions to see what -# a VMSet is. -def build_new_vmset(set_id, kernels): - recipe, arch, version = set_id - vmset = dict() - local = False - if arch == "local": - local = True - platform_arch = archs_mapping[platform.machine()] - else: - platform_arch = arch +def add_kernel(vm_config, kernel, tags): + for vmset in vm_config["vmsets"]: + if set(vmset["tags"]) != tags: + continue - if recipe == "custom": - vmset = {"name": vmset_name_from_id(set_id), "recipe": f"custom-{arch}", "arch": arch, "kernels": kernels} - if version == "lte_414": - vmset["image"] = { - "image_path": f"custom-buster.{distro_arch_mapping[platform_arch]}.qcow2", - "image_source": get_image_path("buster", distro_arch_mapping[platform_arch], local), - } - else: - vmset["image"] = { - "image_path": f"custom-bullseye.{distro_arch_mapping[platform_arch]}.qcow2", - "image_source": get_image_path("bullseye", distro_arch_mapping[platform_arch], local), - } - elif recipe == "distro": - vmset = {"name": vmset_name_from_id(set_id), "recipe": f"distro-{arch}", "arch": arch, "kernels": kernels} + if not kernel_in_vmset(vmset, kernel): + vmset["kernels"].append(kernel) + return + + raise Exit(f"Unable to find vmset with tags {tags}") + + +def add_vcpu(vmset, vcpu): + vmset["vcpu"] = vcpu + + +def add_memory(vmset, memory): + vmset["memory"] = memory + + +def template_name(arch, recipe): + if arch == local_arch: + arch = arch_mapping[platform.machine()] + + recipe_without_arch = recipe.split("-")[0] + return f"{recipe_without_arch}_{arch}" + + +def add_disks(vmconfig_template, vmset): + tname = template_name(vmset["arch"], vmset["recipe"]) + + for template in vmconfig_template["vmsets"]: + if tname in template["tags"]: + vmset["disks"] = copy.deepcopy(template["disks"]) + + +def add_console(vmset): + vmset["console_type"] = "file" + + +def url_to_fspath(url): + source = urlparse(url) + if os.path.basename(source.path).endswith(".xz"): + filename = os.path.basename(source.path)[: -len(".xz")] else: - raise Exit(f"Invalid recipe {recipe}") + filename = os.path.basename(source.path) - if arch == "arm64": - vmset["machine"] = "virt" + return f"file://{os.path.join(KMT_ROOTFS_DIR,filename)}" - return vmset +def image_source_to_path(vmset): + if vmset["recipe"] == f"custom-{vmset['arch']}": + vmset["image"]["image_source"] = url_to_fspath(vmset["image"]["image_source"]) + return -def vmset_exists(vm_config, set_name): - vmsets = vm_config["vmsets"] + for kernel in vmset["kernels"]: + kernel["image_source"] = url_to_fspath(kernel["image_source"]) - for vmset in vmsets: - if vmset["name"] == set_name: - return True + if "disks" in vmset: + for disk in vmset["disks"]: + disk["source"] = url_to_fspath(disk["source"]) - return False +class VM: + def __init__(self, version): + self.version = version -def kernel_in_vmset(vmset, kernel): - vmset_kernels = vmset["kernels"] - for k in vmset_kernels: - if k["tag"] == kernel["tag"]: - return True - return False +class VMSet: + def __init__(self, arch, recipe, tags): + self.arch = arch + self.recipe = recipe + self.tags = tags + self.vms = list() + def __eq__(self, other): + for tag in self.tags: + if tag not in other.tags: + return False + return True -def add_kernels_to_vmset(vmset, set_name, kernels): - for k in kernels: - if kernel_in_vmset(vmset, k): - continue - if vmset["name"] == set_name: - vmset["kernels"].append(k) + def __hash__(self): + return hash('-'.join(self.tags)) + def __repr__(self): + vm_str = list() + for vm in self.vms: + vm_str.append(vm.version) + return f" tags={'-'.join(self.tags)} arch={self.arch} vms={','.join(vm_str)}" -# Each vmset is uniquely identified by its name, which -# can be derived from the set_id. If a vmset exists, -# and we have data to add, this function modifies the appropriate -# vmset. -def modify_existing_vmsets(vm_config, set_id, kernels): - set_name = vmset_name_from_id(set_id) + def add_vm_if_belongs(self, recipe, version, arch): + if recipe == "custom": + expected_tag = custom_version_prefix(version) + found = False + for tag in self.tags: + if tag == expected_tag: + found = True - if not vmset_exists(vm_config, set_name): - return False + if not found: + return - vmsets = vm_config["vmsets"] - for vmset in vmsets: - add_kernels_to_vmset(vmset, set_name, kernels) + if self.recipe == recipe and self.arch == arch: + self.vms.append(VM(version)) - return True +def custom_version_prefix(version): + return "lte_414" if lte_414(version) else "gt_414" -def generate_vm_config(vm_config, vms, vcpu, memory): - # get all possible (recipe, version, arch) combinations we can support. - possible = list_possible() - kernels = dict() - for vm in vms: - normalized_vm_def = normalize_vm_def(possible, vm) - set_id = vmset_id(*normalized_vm_def) - # generate kernel configuration for each vm-def - if set_id not in kernels: - kernels[set_id] = [get_kernel_config(*normalized_vm_def)] - else: - kernels[set_id].append(get_kernel_config(*normalized_vm_def)) +def generate_vmconfig(vm_config, normalized_vm_defs, vcpu, memory, sets, ci): + with open(vmconfig_file) as f: + vmconfig_template = json.load(f) - keys_to_remove = list() - # detect if the requested VM falls in an already existing vmset - for set_id in kernels: - if modify_existing_vmsets(vm_config, set_id, kernels[set_id]): - keys_to_remove.append(set_id) + # generate all vmsets + vmsets = set() + for recipe, version, arch in normalized_vm_defs: + if recipe == "custom": + sets.append(custom_version_prefix(version)) - # delete kernels already added - for key in keys_to_remove: - del kernels[key] + # duplicate vm if multiple sets provided by user + for s in sets: + vmsets.add(VMSet(arch, recipe, {vmset_name(arch, recipe), s})) - # this loop generates vmsets which do not already exist - for set_id in kernels: - vm_config["vmsets"].append(build_new_vmset(set_id, kernels[set_id])) + if len(sets) == 0: + vmsets.add(VMSet(arch, recipe, {vmset_name(arch, recipe)})) - # Modify the vcpu and memory configuration of all sets. - for vmset in vm_config["vmsets"]: - vmset["vcpu"] = vcpu - vmset["memory"] = memory + # map vms to vmsets + for recipe, version, arch in normalized_vm_defs: + for vmset in vmsets: + vmset.add_vm_if_belongs(recipe, version, arch) + + # add new vmsets to new vm_config + for vmset in vmsets: + add_vmset(vmset, vm_config) + + # add vm configurations to vmsets. + for vmset in vmsets: + for vm in vmset.vms: + add_kernel( + vm_config, + get_kernel_config(vmconfig_template, vmset.recipe, vm.version, vmset.arch), + vmset.tags, + ) - local_cnt = 0 - remote_cnt = 0 - amd64_ec2 = False - arm64_ec2 = False for vmset in vm_config["vmsets"]: - if vmset["arch"] == "local": - local_cnt += len(vmset["kernels"]) - if vmset["arch"] != "local": - remote_cnt += len(vmset["kernels"]) - if vmset["arch"] == "x86_64": - amd64_ec2 = True - if vmset["arch"] == "arm64": - arm64_ec2 = True + add_vcpu(vmset, vcpu) + add_memory(vmset, memory) - print() - warn("[!] Please review configuration") - if arm64_ec2: - info(f"[*] Configuration will launch 1 arm64 {ARM_INSTANCE_TYPE} EC2 instance") - if amd64_ec2: - info(f"[*] Configuration will launch 1 x86_64 {X86_INSTANCE_TYPE} EC2 instance") + if vmset["recipe"] != "custom": + add_disks(vmconfig_template, vmset) - info(f"[*] Configuration launches {local_cnt} VMs locally, and {remote_cnt} VMs on remote instances") + # For local VMs we want to read images from the filesystem + if vmset["arch"] == local_arch: + image_source_to_path(vmset) + + if ci: + add_console(vmset) + + return vm_config def ls_to_int(ls): @@ -449,7 +489,7 @@ def ls_to_int(ls): return int_ls -def gen_config(ctx, stack=None, vms="", init_stack=False, vcpu="4", memory="8192", new=False): +def gen_config_for_stack(ctx, stack, vms, sets, init_stack, vcpu, memory, new, ci): stack = check_and_get_stack(stack) if not stack_exists(stack) and not init_stack: raise Exit( @@ -461,18 +501,18 @@ def gen_config(ctx, stack=None, vms="", init_stack=False, vcpu="4", memory="8192 info(f"[+] Select stack {stack}") + # get normalized vm definitions vm_types = vms.split(',') if len(vm_types) == 0: raise Exit("No VMs to boot provided") - vcpu_ls = vcpu.split(',') - memory_ls = memory.split(',') - - check_memory_and_vcpus(memory_ls, vcpu_ls) - mem_to_pow_of_2(memory_ls) + ## get all possible (recipe, version, arch) combinations we can support. + possible = list_possible() + normalized_vms = list() + for vm in vm_types: + normalized_vms.append(normalize_vm_def(possible, vm)) vmconfig_file = f"{KMT_STACKS_DIR}/{stack}/{VMCONFIG}" - # vmconfig_file = "/tmp/vm-config.json" if new or not os.path.exists(vmconfig_file): empty_config(vmconfig_file) @@ -480,7 +520,7 @@ def gen_config(ctx, stack=None, vms="", init_stack=False, vcpu="4", memory="8192 orig_vm_config = f.read() vm_config = json.loads(orig_vm_config) - generate_vm_config(vm_config, vm_types, ls_to_int(vcpu_ls), ls_to_int(memory_ls)) + vm_config = generate_vmconfig(vm_config, normalized_vms, vcpu, memory, sets, ci) vm_config_str = json.dumps(vm_config, indent=4) tmpfile = "/tmp/vm.json" @@ -501,3 +541,50 @@ def gen_config(ctx, stack=None, vms="", init_stack=False, vcpu="4", memory="8192 f.write(vm_config_str) info(f"[+] vmconfig @ {vmconfig_file}") + + +def list_all_distro_normalized_vms(archs): + with open(vmconfig_file) as f: + vmconfig = json.load(f) + + vms = list() + for arch in archs: + distributions = list() + for vmset in vmconfig["vmsets"]: + if vmset["arch"] not in arch: + continue + + for kernel in vmset["kernels"]: + distributions.append(kernel["tag"]) + + for distro_version in distributions: + vms.append(("distro", distro_version, arch)) + + return vms + + +def gen_config(ctx, stack, vms, sets, init_stack, vcpu, memory, new, ci, arch, output_file): + vcpu_ls = vcpu.split(',') + memory_ls = memory.split(',') + + check_memory_and_vcpus(memory_ls, vcpu_ls) + mem_to_pow_of_2(memory_ls) + set_ls = list() + if sets != "": + set_ls = sets.split(",") + + if not ci: + return gen_config_for_stack( + ctx, stack, vms, set_ls, init_stack, ls_to_int(vcpu_ls), ls_to_int(memory_ls), new, ci + ) + + arch_ls = ["x86_64", "arm64"] + if arch != "": + arch_ls = [arch_mapping[arch]] + + vms_to_generate = list_all_distro_normalized_vms(arch_ls) + + vm_config = generate_vmconfig({"vmsets": []}, vms_to_generate, ls_to_int(vcpu_ls), ls_to_int(memory_ls), set_ls, ci) + + with open(output_file, "w") as f: + f.write(json.dumps(vm_config, indent=4)) diff --git a/tasks/kmt.py b/tasks/kmt.py index a3d5aed1369e5..626f5c87619bd 100644 --- a/tasks/kmt.py +++ b/tasks/kmt.py @@ -45,8 +45,20 @@ def create_stack(ctx, stack=None): "init-stack": "Automatically initialize stack if not present. Equivalent to calling 'inv -e kmt.create-stack [--stack=]'", } ) -def gen_config(ctx, stack=None, vms="", init_stack=False, vcpu="4", memory="8192", new=False): - vmconfig.gen_config(ctx, stack, vms, init_stack, vcpu, memory, new) +def gen_config( + ctx, + stack=None, + vms="", + sets="", + init_stack=False, + vcpu="4", + memory="8192", + new=False, + ci=False, + arch="", + output_file="vmconfig.json", +): + vmconfig.gen_config(ctx, stack, vms, sets, init_stack, vcpu, memory, new, ci, arch, output_file) @task diff --git a/test/new-e2e/go.mod b/test/new-e2e/go.mod index f7ec0801f565b..00742efa25ee7 100644 --- a/test/new-e2e/go.mod +++ b/test/new-e2e/go.mod @@ -22,7 +22,7 @@ require ( // `TEST_INFRA_DEFINITIONS_BUILDIMAGES` matches the commit sha in the module version // Example: github.com/DataDog/test-infra-definitions v0.0.0-YYYYMMDDHHmmSS-0123456789AB // => TEST_INFRA_DEFINITIONS_BUILDIMAGES: 0123456789AB - github.com/DataDog/test-infra-definitions v0.0.0-20231129092443-a60850d5606e + github.com/DataDog/test-infra-definitions v0.0.0-20231129185556-40b046c22010 github.com/aws/aws-sdk-go-v2 v1.22.1 github.com/aws/aws-sdk-go-v2/config v1.18.40 github.com/aws/aws-sdk-go-v2/service/ec2 v1.130.0 diff --git a/test/new-e2e/go.sum b/test/new-e2e/go.sum index c5f52da5f7155..230f4082ffc85 100644 --- a/test/new-e2e/go.sum +++ b/test/new-e2e/go.sum @@ -12,8 +12,8 @@ github.com/DataDog/datadog-api-client-go/v2 v2.15.0 h1:5UVON1xs6Lul4d6R5TmLDqqSJ github.com/DataDog/datadog-api-client-go/v2 v2.15.0/go.mod h1:ZG8wS+y2rUmkRDJZQq7Og7EAPFPage+7vXcmuah2I9o= github.com/DataDog/mmh3 v0.0.0-20200805151601-30884ca2197a h1:m9REhmyaWD5YJ0P53ygRHxKKo+KM+nw+zz0hEdKztMo= github.com/DataDog/mmh3 v0.0.0-20200805151601-30884ca2197a/go.mod h1:SvsjzyJlSg0rKsqYgdcFxeEVflx3ZNAyFfkUHP0TxXg= -github.com/DataDog/test-infra-definitions v0.0.0-20231129092443-a60850d5606e h1:yVjfUFnwtxqppiAnlQbQcGt6wQ9hqaRoI72+HP690OE= -github.com/DataDog/test-infra-definitions v0.0.0-20231129092443-a60850d5606e/go.mod h1:P6FDz6Iyki8kX1WoDln5U+3kVLC+QzRi7FIzauuZ6jM= +github.com/DataDog/test-infra-definitions v0.0.0-20231129185556-40b046c22010 h1:v8ChDpXZVMYEUEyyfYsS3rzDqqkRm2BeR0FlUeaWEXs= +github.com/DataDog/test-infra-definitions v0.0.0-20231129185556-40b046c22010/go.mod h1:P6FDz6Iyki8kX1WoDln5U+3kVLC+QzRi7FIzauuZ6jM= github.com/DataDog/zstd v1.5.2 h1:vUG4lAyuPCXO0TLbXvPv7EB7cNK1QV/luu55UHLrrn8= github.com/DataDog/zstd v1.5.2/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw= github.com/DataDog/zstd_0 v0.0.0-20210310093942-586c1286621f h1:5Vuo4niPKFkfwW55jV4vY0ih3VQ9RaQqeqY67fvRn8A= diff --git a/test/new-e2e/system-probe/config/vmconfig-arm64.json b/test/new-e2e/system-probe/config/vmconfig-arm64.json deleted file mode 100644 index 045a20eda7380..0000000000000 --- a/test/new-e2e/system-probe/config/vmconfig-arm64.json +++ /dev/null @@ -1,97 +0,0 @@ -{ - "vmsets": [ - { - "name": "distro_arm64", - "recipe": "distro-arm64", - "arch": "arm64", - "console_type": "file", - "kernels": [ - { - "dir": "bionic-server-cloudimg-arm64.qcow2", - "tag": "ubuntu_18.04", - "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/bionic-server-cloudimg-arm64.qcow2.xz" - }, - { - "dir": "focal-server-cloudimg-arm64.qcow2", - "tag": "ubuntu_20.04", - "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/focal-server-cloudimg-arm64.qcow2.xz" - }, - { - "dir": "jammy-server-cloudimg-arm64.qcow2", - "tag": "ubuntu_22.04", - "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/jammy-server-cloudimg-arm64.qcow2.xz" - }, - { - "dir": "mantic-server-cloudimg-arm64.qcow2", - "tag": "ubuntu_23.10", - "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/mantic-server-cloudimg-arm64.qcow2.xz" - }, - { - "dir": "amzn2-kvm-2.0-arm64-4.14.qcow2", - "tag": "amzn_4.14", - "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/amzn2-kvm-2.0-arm64-4.14.qcow2.xz" - }, - { - "dir": "amzn2-kvm-2.0-arm64-5.4.qcow2", - "tag": "amzn_5.4", - "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/amzn2-kvm-2.0-arm64-5.4.qcow2.xz" - }, - { - "dir": "amzn2-kvm-2.0-arm64-5.10.qcow2", - "tag": "amzn_5.10", - "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/amzn2-kvm-2.0-arm64-5.10.qcow2.xz" - }, - { - "dir": "Fedora-Cloud-Base-37.arm64.qcow2", - "tag": "fedora_37", - "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/Fedora-Cloud-Base-37.arm64.qcow2.xz" - }, - { - "dir": "Fedora-Cloud-Base-38.arm64.qcow2", - "tag": "fedora_38", - "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/Fedora-Cloud-Base-38.arm64.qcow2.xz" - }, - { - "dir": "debian-10-generic-arm64.qcow2", - "tag": "debian_10", - "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/debian-10-generic-arm64.qcow2.xz-test-only" - }, - { - "dir": "debian-11-generic-arm64.qcow2", - "tag": "debian_11", - "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/debian-11-generic-arm64.qcow2.xz-test-only" - }, - { - "dir": "debian-12-generic-arm64.qcow2", - "tag": "debian_12", - "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/debian-12-generic-arm64.qcow2.xz" - }, - { - "dir": "centos-7.9-arm64.qcow2", - "tag": "centos_79", - "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/centos-7.9-arm64.qcow2.xz" - }, - { - "dir": "centos-8-arm64.qcow2", - "tag": "centos_8", - "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/centos-8-arm64.qcow2.xz" - } - ], - "machine": "virt", - "vcpu": [ - 4 - ], - "memory": [ - 8192 - ], - "disks": [ - { - "mount_point": "/mnt/docker", - "source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/docker-arm64.qcow2", - "target": "/home/kernel-version-testing/docker-arm64.qcow2", - "type": "default" - } - ] - } - ] -} diff --git a/test/new-e2e/system-probe/config/vmconfig-x64.json b/test/new-e2e/system-probe/config/vmconfig-x64.json deleted file mode 100644 index 39ac353d57072..0000000000000 --- a/test/new-e2e/system-probe/config/vmconfig-x64.json +++ /dev/null @@ -1,101 +0,0 @@ -{ - "vmsets": [ - { - "name": "distro_x86_64", - "recipe": "distro-x86_64", - "arch": "x86_64", - "console_type": "file", - "kernels": [ - { - "dir": "xenial-server-cloudimg-amd64.qcow2", - "tag": "ubuntu_16.04", - "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/xenial-server-cloudimg-amd64.qcow2.xz" - }, - { - "dir": "bionic-server-cloudimg-amd64.qcow2", - "tag": "ubuntu_18.04", - "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/bionic-server-cloudimg-amd64.qcow2.xz" - }, - { - "dir": "focal-server-cloudimg-amd64.qcow2", - "tag": "ubuntu_20.04", - "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/focal-server-cloudimg-amd64.qcow2.xz" - }, - { - "dir": "jammy-server-cloudimg-amd64.qcow2", - "tag": "ubuntu_22.04", - "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/jammy-server-cloudimg-amd64.qcow2.xz" - }, - { - "dir": "mantic-server-cloudimg-amd64.qcow2", - "tag": "ubuntu_23.10", - "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/mantic-server-cloudimg-amd64.qcow2.xz" - }, - { - "dir": "amzn2-kvm-2.0-amd64-4.14.qcow2", - "tag": "amzn_4.14", - "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/amzn2-kvm-2.0-amd64-4.14.qcow2.xz" - }, - { - "dir": "amzn2-kvm-2.0-amd64-5.4.qcow2", - "tag": "amzn_5.4", - "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/amzn2-kvm-2.0-amd64-5.4.qcow2.xz" - }, - { - "dir": "amzn2-kvm-2.0-amd64-5.10.qcow2", - "tag": "amzn_5.10", - "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/amzn2-kvm-2.0-amd64-5.10.qcow2.xz" - }, - { - "dir": "Fedora-Cloud-Base-37.amd64.qcow2", - "tag": "fedora_37", - "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/Fedora-Cloud-Base-37.amd64.qcow2.xz" - }, - { - "dir": "Fedora-Cloud-Base-38.amd64.qcow2", - "tag": "fedora_38", - "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/Fedora-Cloud-Base-38.amd64.qcow2.xz" - }, - { - "dir": "debian-10-generic-amd64.qcow2", - "tag": "debian_10", - "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/debian-10-generic-amd64.qcow2.xz" - }, - { - "dir": "debian-11-generic-amd64.qcow2", - "tag": "debian_11", - "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/debian-11-generic-amd64.qcow2.xz" - }, - { - "dir": "debian-12-generic-amd64.qcow2", - "tag": "debian_12", - "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/debian-12-generic-amd64.qcow2.xz" - }, - { - "dir": "centos-7.9-x86_64.qcow2", - "tag": "centos_79", - "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/centos-7.9-x86_64.qcow2.xz" - }, - { - "dir": "centos-8-x86_64.qcow2", - "tag": "centos_8", - "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/centos-8-x86_64.qcow2.xz" - } - ], - "vcpu": [ - 4 - ], - "memory": [ - 8192 - ], - "disks": [ - { - "mount_point": "/mnt/docker", - "source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/docker-amd64.qcow2", - "target": "/home/kernel-version-testing/docker-amd64.qcow2", - "type": "default" - } - ] - } - ] -} diff --git a/test/new-e2e/system-probe/config/vmconfig.json b/test/new-e2e/system-probe/config/vmconfig.json new file mode 100644 index 0000000000000..df4644b78f283 --- /dev/null +++ b/test/new-e2e/system-probe/config/vmconfig.json @@ -0,0 +1,198 @@ +{ + "vmsets": [ + { + "tags": [ + "distro_x86_64" + ], + "recipe": "distro-x86_64", + "arch": "x86_64", + "console_type": "file", + "kernels": [ + { + "dir": "xenial-server-cloudimg-x86_64.qcow2", + "tag": "ubuntu_16.04", + "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/xenial-server-cloudimg-x86_64.qcow2.xz" + }, + { + "dir": "bionic-server-cloudimg-x86_64.qcow2", + "tag": "ubuntu_18.04", + "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/bionic-server-cloudimg-x86_64.qcow2.xz" + }, + { + "dir": "focal-server-cloudimg-x86_64.qcow2", + "tag": "ubuntu_20.04", + "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/focal-server-cloudimg-x86_64.qcow2.xz" + }, + { + "dir": "jammy-server-cloudimg-x86_64.qcow2", + "tag": "ubuntu_22.04", + "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/jammy-server-cloudimg-x86_64.qcow2.xz" + }, + { + "dir": "mantic-server-cloudimg-x86_64.qcow2", + "tag": "ubuntu_23.10", + "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/mantic-server-cloudimg-x86_64.qcow2.xz" + }, + { + "dir": "amzn2-kvm-2.0-x86_64-4.14.qcow2", + "tag": "amzn_4.14", + "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/amzn2-kvm-2.0-x86_64-4.14.qcow2.xz" + }, + { + "dir": "amzn2-kvm-2.0-x86_64-5.4.qcow2", + "tag": "amzn_5.4", + "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/amzn2-kvm-2.0-x86_64-5.4.qcow2.xz" + }, + { + "dir": "amzn2-kvm-2.0-x86_64-5.10.qcow2", + "tag": "amzn_5.10", + "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/amzn2-kvm-2.0-x86_64-5.10.qcow2.xz" + }, + { + "dir": "Fedora-Cloud-Base-37.x86_64.qcow2", + "tag": "fedora_37", + "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/Fedora-Cloud-Base-37.x86_64.qcow2.xz" + }, + { + "dir": "Fedora-Cloud-Base-38.x86_64.qcow2", + "tag": "fedora_38", + "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/Fedora-Cloud-Base-38.x86_64.qcow2.xz" + }, + { + "dir": "debian-10-generic-x86_64.qcow2", + "tag": "debian_10", + "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/debian-10-generic-x86_64.qcow2.xz" + }, + { + "dir": "debian-11-generic-x86_64.qcow2", + "tag": "debian_11", + "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/debian-11-generic-x86_64.qcow2.xz" + }, + { + "dir": "debian-12-generic-x86_64.qcow2", + "tag": "debian_12", + "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/debian-12-generic-x86_64.qcow2.xz" + }, + { + "dir": "centos-7.9-x86_64.qcow2", + "tag": "centos_79", + "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/centos-7.9-x86_64.qcow2.xz" + }, + { + "dir": "centos-8-x86_64.qcow2", + "tag": "centos_8", + "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/centos-8-x86_64.qcow2.xz" + } + ], + "vcpu": [ + 4 + ], + "memory": [ + 8192 + ], + "disks": [ + { + "mount_point": "/mnt/docker", + "source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/docker-x86_64.qcow2", + "target": "/home/kernel-version-testing/docker-x86_64.qcow2", + "type": "default" + } + ] + }, + { + "tags": [ + "distro_arm64" + ], + "recipe": "distro-arm64", + "arch": "arm64", + "console_type": "file", + "kernels": [ + { + "dir": "bionic-server-cloudimg-arm64.qcow2", + "tag": "ubuntu_18.04", + "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/bionic-server-cloudimg-arm64.qcow2.xz" + }, + { + "dir": "focal-server-cloudimg-arm64.qcow2", + "tag": "ubuntu_20.04", + "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/focal-server-cloudimg-arm64.qcow2.xz" + }, + { + "dir": "jammy-server-cloudimg-arm64.qcow2", + "tag": "ubuntu_22.04", + "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/jammy-server-cloudimg-arm64.qcow2.xz" + }, + { + "dir": "mantic-server-cloudimg-arm64.qcow2", + "tag": "ubuntu_23.10", + "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/mantic-server-cloudimg-arm64.qcow2.xz" + }, + { + "dir": "amzn2-kvm-2.0-arm64-4.14.qcow2", + "tag": "amzn_4.14", + "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/amzn2-kvm-2.0-arm64-4.14.qcow2.xz" + }, + { + "dir": "amzn2-kvm-2.0-arm64-5.4.qcow2", + "tag": "amzn_5.4", + "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/amzn2-kvm-2.0-arm64-5.4.qcow2.xz" + }, + { + "dir": "amzn2-kvm-2.0-arm64-5.10.qcow2", + "tag": "amzn_5.10", + "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/amzn2-kvm-2.0-arm64-5.10.qcow2.xz" + }, + { + "dir": "Fedora-Cloud-Base-37.arm64.qcow2", + "tag": "fedora_37", + "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/Fedora-Cloud-Base-37.arm64.qcow2.xz" + }, + { + "dir": "Fedora-Cloud-Base-38.arm64.qcow2", + "tag": "fedora_38", + "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/Fedora-Cloud-Base-38.arm64.qcow2.xz" + }, + { + "dir": "debian-10-generic-arm64.qcow2", + "tag": "debian_10", + "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/debian-10-generic-arm64.qcow2.xz-test-only" + }, + { + "dir": "debian-11-generic-arm64.qcow2", + "tag": "debian_11", + "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/debian-11-generic-arm64.qcow2.xz-test-only" + }, + { + "dir": "debian-12-generic-arm64.qcow2", + "tag": "debian_12", + "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/debian-12-generic-arm64.qcow2.xz" + }, + { + "dir": "centos-7.9-arm64.qcow2", + "tag": "centos_79", + "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/centos-7.9-arm64.qcow2.xz" + }, + { + "dir": "centos-8-arm64.qcow2", + "tag": "centos_8", + "image_source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/centos-8-arm64.qcow2.xz" + } + ], + "machine": "virt", + "vcpu": [ + 4 + ], + "memory": [ + 8192 + ], + "disks": [ + { + "mount_point": "/mnt/docker", + "source": "https://dd-agent-omnibus.s3.amazonaws.com/kernel-version-testing/rootfs/master/docker-arm64.qcow2", + "target": "/home/kernel-version-testing/docker-arm64.qcow2", + "type": "default" + } + ] + } + ] +} diff --git a/test/new-e2e/system-probe/test-runner/files/no_tracersuite.json b/test/new-e2e/system-probe/test-runner/files/no_tracersuite.json new file mode 100644 index 0000000000000..fad878e4e0a2a --- /dev/null +++ b/test/new-e2e/system-probe/test-runner/files/no_tracersuite.json @@ -0,0 +1,8 @@ +{ + "pkg/network/tracer": { + "run-only": ["^TestUSMSuite$"] + }, + "*": { + "exclude": false + } +} diff --git a/test/new-e2e/system-probe/test-runner/files/only_tracersuite.json b/test/new-e2e/system-probe/test-runner/files/only_tracersuite.json new file mode 100644 index 0000000000000..13e10a3ce5eb3 --- /dev/null +++ b/test/new-e2e/system-probe/test-runner/files/only_tracersuite.json @@ -0,0 +1,5 @@ +{ + "pkg/network/tracer": { + "skip": ["^TestUSMSuite$"] + } +} diff --git a/test/new-e2e/system-probe/test-runner/main.go b/test/new-e2e/system-probe/test-runner/main.go index 3fb45e420dc6b..3479f10f79dac 100644 --- a/test/new-e2e/system-probe/test-runner/main.go +++ b/test/new-e2e/system-probe/test-runner/main.go @@ -10,6 +10,7 @@ package main import ( "bufio" "bytes" + "encoding/json" "flag" "fmt" "io" @@ -26,15 +27,21 @@ import ( "golang.org/x/sys/unix" ) +const matchAllPackages = "*" + func init() { color.NoColor = false } +type packageRunConfiguration struct { + RunOnly []string `json:"run-only"` + Skip []string + Exclude bool +} + type testConfig struct { - retryCount int - includePackages []string - excludePackages []string - runTests string + retryCount int + packagesRunConfig map[string]packageRunConfiguration } const ( @@ -106,7 +113,7 @@ func pathToPackage(path string) string { func buildCommandArgs(pkg string, xmlpath string, jsonpath string, file string, testConfig *testConfig) []string { args := []string{ - "--format", "dots", + "--format", "testname", "--junitfile", xmlpath, "--jsonfile", jsonpath, fmt.Sprintf("--rerun-fails=%d", testConfig.retryCount), @@ -115,8 +122,12 @@ func buildCommandArgs(pkg string, xmlpath string, jsonpath string, file string, "/go/bin/test2json", "-t", "-p", pkg, file, "-test.v", "-test.count=1", "-test.timeout=" + getTimeout(pkg).String(), } - if testConfig.runTests != "" { - args = append(args, "-test.run", testConfig.runTests) + packagesRunConfig := testConfig.packagesRunConfig + if config, ok := packagesRunConfig[pkg]; ok && config.RunOnly != nil { + args = append(args, "-test.run", strings.Join(config.RunOnly, "|")) + } + if config, ok := packagesRunConfig[pkg]; ok && config.Skip != nil { + args = append(args, "-test.skip", strings.Join(config.Skip, "|")) } return args @@ -161,20 +172,16 @@ func createDir(d string) error { func testPass(testConfig *testConfig, props map[string]string) error { testsuites, err := glob(testDirRoot, "testsuite", func(path string) bool { dir := pathToPackage(path) - for _, p := range testConfig.excludePackages { - if dir == p { - return false - } + + if config, ok := testConfig.packagesRunConfig[dir]; ok { + return !config.Exclude } - if len(testConfig.includePackages) != 0 { - for _, p := range testConfig.includePackages { - if dir == p { - return true - } - } - return false + + if config, ok := testConfig.packagesRunConfig[matchAllPackages]; ok { + return !config.Exclude } - return true + + return false }) if err != nil { return fmt.Errorf("test glob: %s", err) @@ -234,30 +241,31 @@ func fixAssetPermissions() error { return nil } -func buildTestConfiguration() *testConfig { +func buildTestConfiguration() (*testConfig, error) { retryPtr := flag.Int("retry", 2, "number of times to retry testing pass") - packagesPtr := flag.String("include-packages", "", "Comma separated list of packages to test") - excludePackagesPtr := flag.String("exclude-packages", "", "Comma separated list of packages to exclude") - runTestsPtr := flag.String("run-tests", "", "Regex for running specific tests") + packageRunConfigPtr := flag.String("packages-run-config", "", "Configuration for controlling which tests run in a package") flag.Parse() - var packagesLs []string - var excludeLs []string + breakdown := make(map[string]packageRunConfiguration) + if *packageRunConfigPtr != "" { + configData, err := os.ReadFile(*packageRunConfigPtr) + if err != nil { + return nil, fmt.Errorf("failed to read config file: %w", err) + } + fmt.Printf("Runner under configuration: %s\n", configData) - if *packagesPtr != "" { - packagesLs = strings.Split(*packagesPtr, ",") - } - if *excludePackagesPtr != "" { - excludeLs = strings.Split(*excludePackagesPtr, ",") + dec := json.NewDecoder(bytes.NewReader(configData)) + dec.DisallowUnknownFields() + if err := dec.Decode(&breakdown); err != nil { + return nil, err + } } return &testConfig{ - retryCount: *retryPtr, - includePackages: packagesLs, - excludePackages: excludeLs, - runTests: *runTestsPtr, - } + retryCount: *retryPtr, + packagesRunConfig: breakdown, + }, nil } func readOSRelease() (map[string]string, error) { @@ -309,7 +317,11 @@ func run() error { return fmt.Errorf("props: %s", err) } - testConfig := buildTestConfiguration() + testConfig, err := buildTestConfiguration() + if err != nil { + return fmt.Errorf("failed to build test configuration: %w", err) + } + if err := fixAssetPermissions(); err != nil { return fmt.Errorf("asset perms: %s", err) } diff --git a/test/new-e2e/system-probe/test/micro-vm-init.sh b/test/new-e2e/system-probe/test/micro-vm-init.sh index 5f92459eb6fd0..5d5ce55807987 100755 --- a/test/new-e2e/system-probe/test/micro-vm-init.sh +++ b/test/new-e2e/system-probe/test/micro-vm-init.sh @@ -1,7 +1,8 @@ #!/bin/bash set -eEuxo pipefail -retry_count=$1; shift +retry_count=$1 +pkgs_run_config_file=$2 docker_dir=/kmt-docker # Add provisioning steps here ! @@ -15,7 +16,7 @@ fi # Start tests code=0 -/test-runner -retry "${retry_count}" "${@}" || code=$? +/test-runner -retry "${retry_count}" -packages-run-config "${pkgs_run_config_file}" || code=$? cp /job_env.txt /ci-visibility/junit/ tar -C /ci-visibility/testjson -czvf /ci-visibility/testjson.tar.gz .