From f3a72cdc9f0ce99f130198528130cf39d18ffefd Mon Sep 17 00:00:00 2001 From: Samuel Walladge Date: Fri, 29 Sep 2023 07:36:44 +0930 Subject: [PATCH] Update jobs to fix the CI - remove old / deprecated zuul jobs - update to the latest rolling python3 jobs - update tox based on tox4 fixes - update tox python targets - add the platform mocking patch - copy from https://review.opendev.org/c/openstack/charm-nova-compute-nvidia-vgpu/+/899177/2/unit_tests/__init__.py Change-Id: If77436f4c27cf719907a2888d5b1e9e6c7eb3f7c --- .zuul.yaml | 3 +-- tox.ini | 23 ++++++++++------------- unit_tests/__init__.py | 12 ++++++++++++ unit_tests/test_ops.py | 5 +++-- unit_tests/test_requires.py | 2 +- 5 files changed, 27 insertions(+), 18 deletions(-) diff --git a/.zuul.yaml b/.zuul.yaml index b3037e9..fd20909 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -1,5 +1,4 @@ - project: templates: - - python35-charm-jobs - - openstack-python3-ussuri-jobs + - openstack-python3-charm-jobs - openstack-cover-jobs diff --git a/tox.ini b/tox.ini index a866ef1..53096e1 100644 --- a/tox.ini +++ b/tox.ini @@ -7,29 +7,26 @@ sitepackages = False skip_missing_interpreters = False [testenv] +# We use tox mainly for virtual environment management for test requirements +# and do not install the charm code as a Python package into that environment. +# Ref: https://tox.wiki/en/latest/config.html#skip_install +skip_install = True setenv = VIRTUAL_ENV={envdir} PYTHONHASHSEED=0 -install_command = - pip install {opts} {packages} commands = stestr run {posargs} -[testenv:py34] -basepython = python3.4 +[testenv:py38] +basepython = python3.8 deps = -r{toxinidir}/test-requirements.txt commands = stestr run {posargs} -[testenv:py35] -basepython = python3.5 +[testenv:py310] +basepython = python3.10 deps = -r{toxinidir}/test-requirements.txt commands = stestr run {posargs} -[testenv:py36] -basepython = python3.6 -deps = -r{toxinidir}/test-requirements.txt -commands = stestr run {posargs} - -[testenv:py37] -basepython = python3.7 +[testenv:py311] +basepython = python3.11 deps = -r{toxinidir}/test-requirements.txt commands = stestr run {posargs} diff --git a/unit_tests/__init__.py b/unit_tests/__init__.py index e69de29..0ce824d 100644 --- a/unit_tests/__init__.py +++ b/unit_tests/__init__.py @@ -0,0 +1,12 @@ +# 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. +from unittest.mock import patch +patch( + 'charmhelpers.osplatform.get_platform', return_value='ubuntu' +).start() +patch( + 'charmhelpers.core.host.lsb_release', + return_value={ + 'DISTRIB_CODENAME': 'jammy' + }).start() diff --git a/unit_tests/test_ops.py b/unit_tests/test_ops.py index 306968d..e4da092 100644 --- a/unit_tests/test_ops.py +++ b/unit_tests/test_ops.py @@ -123,8 +123,9 @@ requires: 'hacluster-b/1', {'veg': 'carrot'}) self.assertEqual( - self.harness.charm.ha.get_remote_all('fruit'), - ['orange', 'grape', 'banana']) + # sort for comparison because order is not guaranteed + sorted(self.harness.charm.ha.get_remote_all('fruit')), + ['banana', 'grape', 'orange']) def test_ha_ready(self): self.harness.begin() diff --git a/unit_tests/test_requires.py b/unit_tests/test_requires.py index adf189c..6cb3011 100644 --- a/unit_tests/test_requires.py +++ b/unit_tests/test_requires.py @@ -522,7 +522,7 @@ class TestHAClusterRequires(unittest.TestCase): ['value1']) # Check multiple values: self.assertEqual( - self.cr.get_remote_all('key2'), + sorted(self.cr.get_remote_all('key2')), ['value2', 'value3']) # Check missing key self.assertEqual(