From f214d1770cab715b5bcc7d122f2d00b3add95fa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20Julia=CC=81n?= Date: Tue, 23 Jul 2024 10:38:19 +0200 Subject: [PATCH 1/6] Remove arch_ls argument --- tasks/kernel_matrix_testing/vmconfig.py | 7 +------ tasks/kmt.py | 7 ++----- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/tasks/kernel_matrix_testing/vmconfig.py b/tasks/kernel_matrix_testing/vmconfig.py index 68f266c1c8165..0951b8318b52c 100644 --- a/tasks/kernel_matrix_testing/vmconfig.py +++ b/tasks/kernel_matrix_testing/vmconfig.py @@ -716,7 +716,6 @@ def gen_config( memory: str, new: bool, ci: bool, - arch: str, output_file: PathOrStr, template: Component, yes: bool = False, @@ -734,11 +733,7 @@ def gen_config( ctx, stack, vms, set_ls, init_stack, ls_to_int(vcpu_ls), ls_to_int(memory_ls), new, ci, template, yes=yes ) - arch_ls: list[KMTArchName] = KMT_SUPPORTED_ARCHS - if arch != "": - arch_ls = [Arch.from_str(arch).kmt_arch] - - vms_to_generate = list_all_distro_normalized_vms(arch_ls, template) + vms_to_generate = list_all_distro_normalized_vms(KMT_SUPPORTED_ARCHS, template) vm_config = generate_vmconfig( {"vmsets": []}, vms_to_generate, ls_to_int(vcpu_ls), ls_to_int(memory_ls), set_ls, ci, template ) diff --git a/tasks/kmt.py b/tasks/kmt.py index d5b1c02ac1dec..cfc760f2299ef 100644 --- a/tasks/kmt.py +++ b/tasks/kmt.py @@ -123,7 +123,6 @@ def gen_config( memory: str | None = None, new=False, ci=False, - arch: str = "", output_file: str = "vmconfig.json", from_ci_pipeline: str | None = None, use_local_if_possible=False, @@ -143,7 +142,6 @@ def gen_config( memory=memory, new=new, ci=ci, - arch=arch, output_file=output_file, use_local_if_possible=use_local_if_possible, vmconfig_template=vmconfig_template, @@ -153,7 +151,7 @@ def gen_config( vcpu = DEFAULT_VCPU if vcpu is None else vcpu memory = DEFAULT_MEMORY if memory is None else memory vmconfig.gen_config( - ctx, stack, vms, sets, init_stack, vcpu, memory, new, ci, arch, output_file, vmconfig_template, yes=yes + ctx, stack, vms, sets, init_stack, vcpu, memory, new, ci, output_file, vmconfig_template, yes=yes ) @@ -167,7 +165,6 @@ def gen_config_from_ci_pipeline( new=False, ci=False, use_local_if_possible=False, - arch: str = "", output_file="vmconfig.json", vmconfig_template: Component = "system-probe", yes=False, @@ -213,7 +210,7 @@ def gen_config_from_ci_pipeline( vcpu = DEFAULT_VCPU if vcpu is None else vcpu memory = DEFAULT_MEMORY if memory is None else memory vmconfig.gen_config( - ctx, stack, ",".join(vms), "", init_stack, vcpu, memory, new, ci, arch, output_file, vmconfig_template, yes=yes + ctx, stack, ",".join(vms), "", init_stack, vcpu, memory, new, ci, output_file, vmconfig_template, yes=yes ) info("[+] You can run the following command to execute only packages with failed tests") print(f"inv kmt.test --packages=\"{' '.join(failed_packages)}\"") From e63ff638c850247866ba0bcb6fc23be01e0effc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20Julia=CC=81n?= Date: Tue, 23 Jul 2024 11:19:32 +0200 Subject: [PATCH 2/6] Do not allow remote stacks without SSH config --- tasks/kernel_matrix_testing/infra.py | 11 +---------- tasks/kernel_matrix_testing/stacks.py | 8 +++----- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/tasks/kernel_matrix_testing/infra.py b/tasks/kernel_matrix_testing/infra.py index 00dbd47ad3f57..88ed47cc2b7a4 100644 --- a/tasks/kernel_matrix_testing/infra.py +++ b/tasks/kernel_matrix_testing/infra.py @@ -10,7 +10,7 @@ from tasks.kernel_matrix_testing.config import ConfigManager from tasks.kernel_matrix_testing.kmt_os import get_kmt_os -from tasks.kernel_matrix_testing.tool import Exit, ask, error, info +from tasks.kernel_matrix_testing.tool import Exit, error, info if TYPE_CHECKING: from tasks.kernel_matrix_testing.types import KMTArchNameOrLocal, PathOrStr, SSHKey, StackOutput @@ -202,15 +202,6 @@ def build_infrastructure(stack: str, ssh_key_obj: SSHKey | None = None): return infra -def ask_for_ssh() -> bool: - return ( - ask( - "You may want to provide ssh key, since the given config launches a remote instance.\nContinue without a ssh key?[Y/n]" - ) - != "y" - ) - - def get_ssh_key_name(pubkey: Path) -> str | None: parts = pubkey.read_text().split() if len(parts) != 3: diff --git a/tasks/kernel_matrix_testing/stacks.py b/tasks/kernel_matrix_testing/stacks.py index fe2709719c503..e88621c913c52 100644 --- a/tasks/kernel_matrix_testing/stacks.py +++ b/tasks/kernel_matrix_testing/stacks.py @@ -9,7 +9,6 @@ from invoke.runners import Result from tasks.kernel_matrix_testing.infra import ( - ask_for_ssh, build_infrastructure, ensure_key_in_agent, ensure_key_in_ec2, @@ -199,12 +198,11 @@ def launch_stack( ssh_key_obj = try_get_ssh_key(ctx, ssh_key) if remote_vms_in_config(vm_config): - if ssh_key_obj is None and ask_for_ssh(): + if ssh_key_obj is None: raise Exit("No ssh key provided. Pass with '--ssh-key=' or configure it with kmt.config-ssh-key") - if ssh_key_obj is not None: - ensure_key_in_agent(ctx, ssh_key_obj) - ensure_key_in_ec2(ctx, ssh_key_obj) + ensure_key_in_agent(ctx, ssh_key_obj) + ensure_key_in_ec2(ctx, ssh_key_obj) env = [ "TEAM=ebpf-platform", From 5716c920182da71ac39a068e5e151ce643f6330d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20Julia=CC=81n?= Date: Tue, 23 Jul 2024 11:20:04 +0200 Subject: [PATCH 3/6] Improve log messages in --from-ci-pipeline --- tasks/kmt.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tasks/kmt.py b/tasks/kmt.py index cfc760f2299ef..013ef49e68d60 100644 --- a/tasks/kmt.py +++ b/tasks/kmt.py @@ -204,7 +204,12 @@ def gen_config_from_ci_pipeline( failed_tests = test_job.get_test_results() failed_packages.update({test.split(':')[0] for test in failed_tests.keys()}) - vms.add(f"{vm_arch}-{test_job.distro}-distro") + vm_name = f"{vm_arch}-{test_job.distro}-distro" + info(f"[+] Adding {vm_name} from failed job {test_job.name}") + vms.add(vm_name) + + if len(vms) == 0: + raise Exit(f"No failed jobs found in pipeline {pipeline}") info(f"[+] generating {output_file} file for VMs {vms}") vcpu = DEFAULT_VCPU if vcpu is None else vcpu From 301efc853d364791c943a3da2105b66137b13626 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20Julia=CC=81n?= Date: Tue, 23 Jul 2024 15:21:30 +0200 Subject: [PATCH 4/6] Revert "Remove arch_ls argument" This reverts commit f214d1770cab715b5bcc7d122f2d00b3add95fa5. --- tasks/kernel_matrix_testing/vmconfig.py | 7 ++++++- tasks/kmt.py | 7 +++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/tasks/kernel_matrix_testing/vmconfig.py b/tasks/kernel_matrix_testing/vmconfig.py index 0951b8318b52c..68f266c1c8165 100644 --- a/tasks/kernel_matrix_testing/vmconfig.py +++ b/tasks/kernel_matrix_testing/vmconfig.py @@ -716,6 +716,7 @@ def gen_config( memory: str, new: bool, ci: bool, + arch: str, output_file: PathOrStr, template: Component, yes: bool = False, @@ -733,7 +734,11 @@ def gen_config( ctx, stack, vms, set_ls, init_stack, ls_to_int(vcpu_ls), ls_to_int(memory_ls), new, ci, template, yes=yes ) - vms_to_generate = list_all_distro_normalized_vms(KMT_SUPPORTED_ARCHS, template) + arch_ls: list[KMTArchName] = KMT_SUPPORTED_ARCHS + if arch != "": + arch_ls = [Arch.from_str(arch).kmt_arch] + + vms_to_generate = list_all_distro_normalized_vms(arch_ls, template) vm_config = generate_vmconfig( {"vmsets": []}, vms_to_generate, ls_to_int(vcpu_ls), ls_to_int(memory_ls), set_ls, ci, template ) diff --git a/tasks/kmt.py b/tasks/kmt.py index 013ef49e68d60..705e6e0f27c7a 100644 --- a/tasks/kmt.py +++ b/tasks/kmt.py @@ -123,6 +123,7 @@ def gen_config( memory: str | None = None, new=False, ci=False, + arch: str = "", output_file: str = "vmconfig.json", from_ci_pipeline: str | None = None, use_local_if_possible=False, @@ -142,6 +143,7 @@ def gen_config( memory=memory, new=new, ci=ci, + arch=arch, output_file=output_file, use_local_if_possible=use_local_if_possible, vmconfig_template=vmconfig_template, @@ -151,7 +153,7 @@ def gen_config( vcpu = DEFAULT_VCPU if vcpu is None else vcpu memory = DEFAULT_MEMORY if memory is None else memory vmconfig.gen_config( - ctx, stack, vms, sets, init_stack, vcpu, memory, new, ci, output_file, vmconfig_template, yes=yes + ctx, stack, vms, sets, init_stack, vcpu, memory, new, ci, arch, output_file, vmconfig_template, yes=yes ) @@ -165,6 +167,7 @@ def gen_config_from_ci_pipeline( new=False, ci=False, use_local_if_possible=False, + arch: str = "", output_file="vmconfig.json", vmconfig_template: Component = "system-probe", yes=False, @@ -215,7 +218,7 @@ def gen_config_from_ci_pipeline( vcpu = DEFAULT_VCPU if vcpu is None else vcpu memory = DEFAULT_MEMORY if memory is None else memory vmconfig.gen_config( - ctx, stack, ",".join(vms), "", init_stack, vcpu, memory, new, ci, output_file, vmconfig_template, yes=yes + ctx, stack, ",".join(vms), "", init_stack, vcpu, memory, new, ci, arch, output_file, vmconfig_template, yes=yes ) info("[+] You can run the following command to execute only packages with failed tests") print(f"inv kmt.test --packages=\"{' '.join(failed_packages)}\"") From c808fb506055bfed9dce66d81e4694179ad87409 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20Julia=CC=81n?= Date: Tue, 23 Jul 2024 15:25:36 +0200 Subject: [PATCH 5/6] Notify when --arch is used without --ci --- tasks/kmt.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tasks/kmt.py b/tasks/kmt.py index 705e6e0f27c7a..e0f88b346f657 100644 --- a/tasks/kmt.py +++ b/tasks/kmt.py @@ -133,6 +133,12 @@ def gen_config( """ Generate a vmconfig.json file with the given VMs. """ + if not ci and arch != "": + raise Exit( + "Error: Architecture (--arch argument) can only be specified when generating from a CI pipeline (--ci argument). " + "To specify the architecture of the VMs, use the VM specifier (e.g., x64-ubuntu_22-distro or local-ubuntu_22-distro for local VMs)" + ) + if from_ci_pipeline is not None: return gen_config_from_ci_pipeline( ctx, From ebef81620ce56ea76da0ad239b0fcf4fb44c1860 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20Julia=CC=81n?= Date: Tue, 23 Jul 2024 15:27:38 +0200 Subject: [PATCH 6/6] docs --- tasks/kmt.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tasks/kmt.py b/tasks/kmt.py index e0f88b346f657..400062449e8d1 100644 --- a/tasks/kmt.py +++ b/tasks/kmt.py @@ -111,6 +111,8 @@ def create_stack(ctx, stack=None): "use-local-if-possible": "(Only when --from-ci-pipeline is used) If the VM is for the same architecture as the host, use the local VM instead of the remote one.", "vmconfig_template": "Template to use for the generated vmconfig.json file. Defaults to 'system-probe'. A file named 'vmconfig-.json' must exist in 'tasks/new-e2e/system-probe/config/'", "yes": "Do not ask for confirmation", + "ci": "Generate a vmconfig.json file for the KMT CI, that is, with all available VMs for the given architecture.", + "arch": "(Only when --ci is used) Architecture to select when generating the vmconfig for all posible VMs.", } ) def gen_config( @@ -134,6 +136,7 @@ def gen_config( Generate a vmconfig.json file with the given VMs. """ if not ci and arch != "": + # The argument is not used later on, so better notify the user early to avoid confusion raise Exit( "Error: Architecture (--arch argument) can only be specified when generating from a CI pipeline (--ci argument). " "To specify the architecture of the VMs, use the VM specifier (e.g., x64-ubuntu_22-distro or local-ubuntu_22-distro for local VMs)"