From 517f461a9c7997ee626755537b1a92e7c78e887f Mon Sep 17 00:00:00 2001 From: Olga Naidjonoka Date: Thu, 17 Oct 2024 16:08:45 +0300 Subject: [PATCH] refactor --- .../scripts/agentbeat/setup_agentbeat.py | 70 +++++++++++-------- .../x-pack/pipeline.xpack.agentbeat.yml | 2 +- 2 files changed, 41 insertions(+), 31 deletions(-) diff --git a/.buildkite/scripts/agentbeat/setup_agentbeat.py b/.buildkite/scripts/agentbeat/setup_agentbeat.py index 35139ec2278..d32c62e7e04 100755 --- a/.buildkite/scripts/agentbeat/setup_agentbeat.py +++ b/.buildkite/scripts/agentbeat/setup_agentbeat.py @@ -6,6 +6,26 @@ import tarfile PATH = 'x-pack/agentbeat/build/distributions' +PLATFORMS = { + 'windows': { + 'x86_64': 'x86_64', + }, + 'linux': { + 'x86_64': 'x86_64', + 'arm64': 'arm64', + }, + 'darwin': { + 'x86_64': 'x86_64', + 'arm64': 'aarch64', + } + } + + +class Archive: + def __init__(self, os, arch, ext): + self.os = os + self.arch = arch + self.ext = ext def log(msg): @@ -18,38 +38,28 @@ def log_err(msg): sys.stderr.flush() -def get_os() -> str: - return platform.system().lower() +def get_archive_params() -> Archive: + system = platform.system().lower() + machine = platform.machine().lower() + arch = PLATFORMS.get(system, {}).get(machine) + ext = get_artifact_extension(system) + return Archive(system, arch, ext) -def get_arch() -> str: - arch = platform.machine().lower() - if arch == 'amd64': - return 'x86_64' - else: - if get_os() == 'darwin': - return 'aarch64' - else: - return arch - - -def get_artifact_extension(agent_os) -> str: - if agent_os == 'windows': +def get_artifact_extension(system) -> str: + if system == 'windows': return 'zip' else: return 'tar.gz' -def get_artifact_pattern() -> str: - agent_os = get_os() - agent_arch = get_arch() - extension = get_artifact_extension(agent_os) - print('Artifact params: ' + agent_os + ' ' + agent_arch + ' ' + extension) - return f'{PATH}/agentbeat-*-{agent_os}-{agent_arch}.{extension}' +def get_artifact_pattern(archive_obj) -> str: + return f'{PATH}/agentbeat-*-{archive_obj.os}-{archive_obj.arch}.{archive_obj.ext}' -def download_agentbeat(pattern, path) -> str: +def download_agentbeat(archive_obj) -> str: + pattern = get_artifact_pattern(archive_obj) try: subprocess.run( ['buildkite-agent', 'artifact', 'download', pattern, '.', @@ -59,16 +69,16 @@ def download_agentbeat(pattern, path) -> str: except subprocess.CalledProcessError: exit(1) - return get_filename(path) + return get_full_filename() -def get_filename(path) -> str: +def get_full_filename() -> str: try: out = subprocess.run( - ['ls', '-p', path], + ['ls', '-p', PATH], check=True, capture_output=True, text=True) - print("--- ls -p: " + out.stdout) - return out.stdout.strip() + filename = out.stdout.strip() + return filename except subprocess.CalledProcessError: exit(1) @@ -109,10 +119,10 @@ def get_path_to_executable(filepath) -> str: path = f'../../{match.group(1)}/agentbeat' return path else: - log_err("No agentbeat executable found") + log_err('No agentbeat executable found') exit(1) -artifact_pattern = get_artifact_pattern() -archive = download_agentbeat(artifact_pattern, PATH) +archive_params = get_archive_params() +archive = download_agentbeat(archive_params) extract_agentbeat(archive) log(get_path_to_executable(archive)) diff --git a/.buildkite/x-pack/pipeline.xpack.agentbeat.yml b/.buildkite/x-pack/pipeline.xpack.agentbeat.yml index a5375bd1e3d..c89ff5521d2 100644 --- a/.buildkite/x-pack/pipeline.xpack.agentbeat.yml +++ b/.buildkite/x-pack/pipeline.xpack.agentbeat.yml @@ -131,7 +131,7 @@ steps: provider: "orka" imagePrefix: "${IMAGE_MACOS_X86_64}" - - label: ":macos: Agentbeat/Integration tests macOS arm64" + - label: ":macos: x-pack/agentbeat: macOS arm64 Spec tests" key: "agentbeat-it-macos-arm64" depends_on: - agentbeat-package-linux