From b919018b281a5c3212e23a5d5b9655e4b6933960 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Lehmann?= Date: Thu, 13 Mar 2025 16:50:45 +0100 Subject: [PATCH] test air gapped update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gaëtan Lehmann --- jobs.py | 9 +++++ tests/air_gapped/__init__.py | 0 tests/air_gapped/test_air_gapped_update.py | 44 ++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 tests/air_gapped/__init__.py create mode 100644 tests/air_gapped/test_air_gapped_update.py diff --git a/jobs.py b/jobs.py index c6ee4d713..2deeb403b 100755 --- a/jobs.py +++ b/jobs.py @@ -431,6 +431,15 @@ "params": {}, "paths": ["tests/fs_diff"], }, + "air-gapped": { + "description": "air gapped — without network — tests", + "requirements": [ + "A host with no access to the internet", + ], + "nb_pools": 1, + "params": {}, + "paths": ["tests/air_gapped"], + } } # List used by the 'check' action: tests listed here will not raise a check error diff --git a/tests/air_gapped/__init__.py b/tests/air_gapped/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/air_gapped/test_air_gapped_update.py b/tests/air_gapped/test_air_gapped_update.py new file mode 100644 index 000000000..b45cfa88b --- /dev/null +++ b/tests/air_gapped/test_air_gapped_update.py @@ -0,0 +1,44 @@ +import logging +import os +from urllib.request import urlretrieve + +from lib.host import Host + +# These tests are basic tests meant to check the update process in air-gapped environment. +# +# Requirements: +# - a host running XCP-ng 8.3. +# - with no access to internet +# - TODO: a snapshot to restore the host to a state without the offline repositories, to integrate when #226 +# will be merged + +REPOS = ['base', 'linstor', 'updates'] + + +def air_gapped_download(url: str, host: Host): + logging.debug(f"downloading {url}") + tmppath = f'/tmp/{os.path.basename(url)}' + urlretrieve(url, tmppath) + host.scp(tmppath, tmppath) + os.remove(tmppath) + + +def test_air_gapped_update(host: Host): + # get the required files and install the offline repositories + air_gapped_download( + 'https://raw.githubusercontent.com/xcp-ng/xcp/refs/heads/master/scripts/setup_offline_xcpng_repos', host + ) + host.ssh(['chmod', 'a+x', '/tmp/setup_offline_xcpng_repos']) + for repo in REPOS: + archive = f'xcpng-8_3-offline-{repo}-latest.tar' + air_gapped_download(f'https://repo.vates.tech/xcp-ng/offline/8/8.3/{archive}', host) + host.ssh(['/tmp/setup_offline_xcpng_repos', f'/tmp/{archive}']) + host.ssh(['rm', '-f', f'/tmp/{archive}']) + repolist = host.ssh(['yum', 'repolist', '-q']) + # ensure the repos are installed + for repo in REPOS: + assert f'xcp-ng-{repo}' in repolist + # run the actual update + host.ssh(['yum', '-y', 'update']) + # restart the XAPI toolstack + host.ssh(['xe-toolstack-restart'])