From 2a92e223322f4c37daec79f11c091344ab97531f Mon Sep 17 00:00:00 2001 From: Brad Warren Date: Thu, 6 Mar 2025 14:13:26 -0800 Subject: [PATCH] make integration tests crossplatform (#10217) i wanted this for testing https://github.com/certbot/certbot/issues/10190 alex started working on this in https://github.com/certbot/certbot/pull/9207 years ago, but pebble didn't end up doing a release containing his work while he was still regularly contributing to certbot. this has now changed though before this PR, our integration tests only worked on amd64 linux systems. with this PR, i've successfully run our integration tests on all combinations of the architectures amd64 and arm64 and the OSes linux and macos --------- Co-authored-by: ohemorange --- .../utils/pebble_artifacts.py | 25 ++++++++++++++++--- certbot/docs/contributing.rst | 4 --- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/certbot-ci/certbot_integration_tests/utils/pebble_artifacts.py b/certbot-ci/certbot_integration_tests/utils/pebble_artifacts.py index ebd5bd1c7..21fbb4077 100644 --- a/certbot-ci/certbot_integration_tests/utils/pebble_artifacts.py +++ b/certbot-ci/certbot_integration_tests/utils/pebble_artifacts.py @@ -4,6 +4,7 @@ import importlib.resources import io import json import os +import platform import stat import zipfile from contextlib import ExitStack @@ -14,7 +15,7 @@ import requests from certbot_integration_tests.utils.constants import DEFAULT_HTTP_01_PORT from certbot_integration_tests.utils.constants import MOCK_OCSP_SERVER_PORT -PEBBLE_VERSION = 'v2.5.1' +PEBBLE_VERSION = 'v2.7.0' def fetch(workspace: str, http_01_port: int = DEFAULT_HTTP_01_PORT) -> Tuple[str, str, str]: @@ -32,11 +33,11 @@ def fetch(workspace: str, http_01_port: int = DEFAULT_HTTP_01_PORT) -> Tuple[str def _fetch_asset(asset: str, assets_path: str) -> str: - platform = 'linux-amd64' base_url = 'https://github.com/letsencrypt/pebble/releases/download' - asset_path = os.path.join(assets_path, f'{asset}_{PEBBLE_VERSION}_{platform}') + os_type, architecture = _get_validated_os_and_architecture() + asset_path = os.path.join(assets_path, f'{asset}_{PEBBLE_VERSION}_{os_type}_{architecture}') if not os.path.exists(asset_path): - asset_url = f'{base_url}/{PEBBLE_VERSION}/{asset}-{platform}.zip' + asset_url = f'{base_url}/{PEBBLE_VERSION}/{asset}-{os_type}-{architecture}.zip' response = requests.get(asset_url, timeout=30) response.raise_for_status() asset_data = _unzip_asset(response.content, asset) @@ -49,6 +50,22 @@ def _fetch_asset(asset: str, assets_path: str) -> str: return asset_path +def _get_validated_os_and_architecture() -> tuple[str, str]: + os_type = platform.system().lower() + if os_type not in ('darwin', 'linux'): + raise ValueError(f'this code has not been tested on {os_type} systems') + + architecture = platform.machine() + if architecture in ('amd64', 'x86_64'): + architecture = 'amd64' + elif architecture in ('aarch64' 'arm64'): + architecture = 'arm64' + else: + raise ValueError(f'this code has not been tested on {architecture} systems') + + return os_type, architecture + + def _unzip_asset(zipped_data: bytes, asset_name: str) -> Optional[bytes]: with zipfile.ZipFile(io.BytesIO(zipped_data)) as zip_file: for entry in zip_file.filelist: diff --git a/certbot/docs/contributing.rst b/certbot/docs/contributing.rst index 18b47f565..6734c9eff 100644 --- a/certbot/docs/contributing.rst +++ b/certbot/docs/contributing.rst @@ -125,10 +125,6 @@ You can test your code in several ways: - running the `automated integration`_ tests - running an *ad hoc* `manual integration`_ test -.. note:: Running integration tests does not currently work on macOS. See - https://github.com/certbot/certbot/issues/6959. In the meantime, we - recommend developers on macOS open a PR to run integration tests. - .. _automated unit: Running automated unit tests