From f8ebb908d789da79c76293d59659a28a1c3c4e77 Mon Sep 17 00:00:00 2001 From: Alex Kavanagh Date: Tue, 24 Oct 2023 20:09:11 +0100 Subject: [PATCH] Improve platform mocking Patch out charmhelpers.osplatform.get_platform() and charmhelpers.core.host.lsb_release() globally in the unit tests to insulate the unit tests from the platform that the unit tests are being run on. Change-Id: Ifda8aa2675b4a756109254f62b9a600c42679cac --- osci.yaml | 9 --------- tests/tests.yaml | 4 ---- unit_tests/__init__.py | 13 +++++++++++++ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/osci.yaml b/osci.yaml index 88e9830..298ed06 100644 --- a/osci.yaml +++ b/osci.yaml @@ -7,8 +7,6 @@ - jammy-antelope-ec_cinder-ceph - jammy-bobcat-ec_cinder-ceph: voting: false - - lunar-antelope-ec_cinder-ceph: - voting: false - mantic-bobcat-ec_cinder-ceph: voting: false vars: @@ -34,13 +32,6 @@ - jammy-antelope-ec_cinder-ceph vars: tox_extra_args: '-- jammy-bobcat-ec' -- job: - name: lunar-antelope-ec_cinder-ceph - parent: func-target - dependencies: - - jammy-antelope-ec_cinder-ceph - vars: - tox_extra_args: '-- lunar-antelope-ec' - job: name: mantic-bobcat-ec_cinder-ceph parent: func-target diff --git a/tests/tests.yaml b/tests/tests.yaml index 1d96fae..5a9dbbd 100644 --- a/tests/tests.yaml +++ b/tests/tests.yaml @@ -14,9 +14,7 @@ gate_bundles: dev_bundles: - jammy-bobcat-ec - jammy-bobcat - - lunar-antelope-ec - mantic-bobcat-ec - - lunar-antelope - mantic-bobcat configure: @@ -42,7 +40,5 @@ tests_options: policyd: service: cinder force_deploy: - - lunar-antelope - mantic-bobcat - - lunar-antelope-ec - mantic-bobcat-ec diff --git a/unit_tests/__init__.py b/unit_tests/__init__.py index d8df6a5..6859a4a 100644 --- a/unit_tests/__init__.py +++ b/unit_tests/__init__.py @@ -14,6 +14,7 @@ import os import sys +from unittest.mock import patch _path = os.path.dirname(os.path.realpath(__file__)) _actions = os.path.abspath(os.path.join(_path, '../actions')) @@ -31,3 +32,15 @@ _add_path(_actions) _add_path(_hooks) _add_path(_charmhelpers) _add_path(_unit_tests) + +# Patch out lsb_release() and get_platform() as unit tests should be fully +# insulated from the underlying platform. Unit tests assume that the system is +# ubuntu jammy. +patch( + 'charmhelpers.osplatform.get_platform', return_value='ubuntu' +).start() +patch( + 'charmhelpers.core.host.lsb_release', + return_value={ + 'DISTRIB_CODENAME': 'jammy' + }).start()