From a38133d936587568d75b7911fd59ab7f045c014a Mon Sep 17 00:00:00 2001 From: Gael Duperrey Date: Thu, 24 Aug 2023 14:32:29 +0200 Subject: [PATCH] Change test fsp for another repo and better teardown We changed the test for fsp to use repo on repo.vates.tech and to have a better teardown when the test failed. We con't want that the repo file stayed on the test server. Signed-off-by: Gael Duperrey --- lib/host.py | 6 ++++-- tests/storage/fsp/conftest.py | 22 ++++++++++++++-------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/host.py b/lib/host.py index d90a8e11a..5a5888d73 100644 --- a/lib/host.py +++ b/lib/host.py @@ -97,13 +97,15 @@ def create_file(self, filename, text): file.flush() self.scp(file.name, filename) - def add_xcpng_repo(self, name): + def add_xcpng_repo(self, name, base_repo='xcp-ng'): + assert base_repo in ['xcp-ng', 'vates'] + base_repo_url = 'http://mirrors.xcp-ng.org/' if base_repo == 'xcp-ng' else 'https://repo.vates.tech/xcp-ng/' major = self.xcp_version.major version = self.xcp_version_short self.create_file(f"/etc/yum.repos.d/xcp-ng-{name}.repo", ( f"[xcp-ng-{name}]\n" f"name=XCP-ng {name} Repository\n" - f"baseurl=http://mirrors.xcp-ng.org/{major}/{version}/{name}/x86_64/ http://updates.xcp-ng.org/{major}/{version}/{name}/x86_64/\n" # noqa + f"baseurl={base_repo_url}/{major}/{version}/{name}/x86_64/\n" "enabled=1\n" "gpgcheck=1\n" "repo_gpgcheck=1\n" diff --git a/tests/storage/fsp/conftest.py b/tests/storage/fsp/conftest.py index cd5501b3f..e9a3610ef 100644 --- a/tests/storage/fsp/conftest.py +++ b/tests/storage/fsp/conftest.py @@ -6,20 +6,26 @@ DIRECTORIES_PATH = 'directories' -def install_fsp(host): - host.add_xcpng_repo(FSP_REPO_NAME) +@pytest.fixture(scope='package') +def host_with_saved_yum_state(host): host.yum_save_state() - host.yum_install(FSP_PACKAGES) - -def uninstall_fsp(host): + yield host host.yum_restore_saved_state() + +@pytest.fixture(scope='package') +def host_with_runx_repo(host_with_saved_yum_state): + host = host_with_saved_yum_state + host.add_xcpng_repo(FSP_REPO_NAME, 'vates') + yield host + # teardown host.remove_xcpng_repo(FSP_REPO_NAME) @pytest.fixture(scope='package') -def host_with_fsp(host): - install_fsp(host) +def host_with_fsp(host_with_runx_repo): + host = host_with_runx_repo + host.yum_install(FSP_PACKAGES) yield host - uninstall_fsp(host) + # teardown: nothing to do, the teardown of host_with_saved_yum_state will revert the package installation @pytest.fixture(scope='package') def fsp_config(host_with_fsp):