Skip to content

Commit

Permalink
[EBPF] Fixes in kmt.gen-config (#27856)
Browse files Browse the repository at this point in the history
  • Loading branch information
gjulianm authored Jul 23, 2024
1 parent 69ec7b2 commit 386130a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
11 changes: 1 addition & 10 deletions tasks/kernel_matrix_testing/infra.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 3 additions & 5 deletions tasks/kernel_matrix_testing/stacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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=<key-name>' 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",
Expand Down
16 changes: 15 additions & 1 deletion tasks/kmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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-<vmconfig_template>.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(
Expand All @@ -133,6 +135,13 @@ 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)"
)

if from_ci_pipeline is not None:
return gen_config_from_ci_pipeline(
ctx,
Expand Down Expand Up @@ -207,7 +216,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
Expand Down

0 comments on commit 386130a

Please sign in to comment.