Fix charm for tox4 compatibility

Also remove python 3.5 targets as this is long not supported.

And add the mocking for charmhelpers - see
https://review.opendev.org/c/openstack/charm-heat/+/899195 for example

Related-Bug: 2002788
Change-Id: Ic70092a45d595d337ea26505139c2f6515cb1d38
This commit is contained in:
Samuel Walladge 2023-10-26 10:19:02 +10:30
parent 6549101baa
commit bf30af291e
5 changed files with 29 additions and 37 deletions

View File

@ -1,7 +0,0 @@
# NOTES(lourot):
# * We don't install charmcraft via pip anymore because it anyway spins up a
# container and scp the system's charmcraft snap inside it. So the charmcraft
# snap is necessary on the system anyway.
# * `tox -e build` successfully validated with charmcraft 1.2.1
cffi==1.14.6; python_version < '3.6' # cffi 1.15.0 drops support for py35.

View File

@ -15,7 +15,7 @@
needs_charm_build: true
charm_build_name: ceph-iscsi
build_type: charmcraft
charmcraft_channel: 2.0/stable
charmcraft_channel: 2.2/stable
- job:
name: ceph-iscsi-focal-quincy
parent: func-target

View File

@ -8,9 +8,6 @@ flake8>=2.2.4,<=2.4.1
stestr>=2.2.0
requests>=2.18.4
psutil
# oslo.i18n dropped py35 support
oslo.i18n<4.0.0
git+https://github.com/openstack-charmers/zaza.git#egg=zaza
git+https://github.com/openstack-charmers/zaza-openstack-tests.git#egg=zaza.openstack
pytz # workaround for 14.04 pip/tox
pyudev # for ceph-* charm unit tests (not mocked?)

42
tox.ini
View File

@ -7,44 +7,30 @@ skipsdist = True
sitepackages = False
# NOTE: Avoid false positives by not skipping missing interpreters.
skip_missing_interpreters = False
# NOTES:
# * We avoid the new dependency resolver by pinning pip < 20.3, see
# https://github.com/pypa/pip/issues/9187
# * Pinning dependencies requires tox >= 3.2.0, see
# https://tox.readthedocs.io/en/latest/config.html#conf-requires
# * It is also necessary to pin virtualenv as a newer virtualenv would still
# lead to fetching the latest pip in the func* tox targets, see
# https://stackoverflow.com/a/38133283
# * It is necessary to declare setuptools as a dependency otherwise tox will
# fail very early at not being able to load it. The version pinning is in
# line with `pip.sh`.
requires = pip < 20.3
virtualenv < 20.0
setuptools < 50.0.0
# NOTE: https://wiki.canonical.com/engineering/OpenStack/InstallLatestToxOnOsci
minversion = 3.2.0
[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
CHARM_DIR={envdir}
install_command =
pip install {opts} {packages}
commands = stestr run --slowest {posargs}
allowlist_externals =
git
add-to-archive.py
bash
charmcraft
rename.sh
passenv = HOME TERM CS_* OS_* TEST_*
{toxinidir}/rename.sh
passenv =
HOME
TERM
CS_*
OS_*
TEST_*
deps = -r{toxinidir}/test-requirements.txt
[testenv:py35]
basepython = python3.5
# python3.5 is irrelevant on a focal+ charm.
commands = /bin/true
[testenv:py36]
basepython = python3.6
deps = -r{toxinidir}/requirements.txt
@ -70,6 +56,11 @@ basepython = python3.10
deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
[testenv:py311]
basepython = python3.11
deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
[testenv:py3]
basepython = python3
deps = -r{toxinidir}/requirements.txt
@ -115,7 +106,6 @@ commands = {posargs}
[testenv:build]
basepython = python3
deps = -r{toxinidir}/build-requirements.txt
commands =
charmcraft clean
charmcraft -v pack

View File

@ -17,3 +17,15 @@ import mock
# Mock out secrets to make py35 happy.
sys.modules['secrets'] = mock.MagicMock()
# 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.
mock.patch(
'charmhelpers.osplatform.get_platform', return_value='ubuntu'
).start()
mock.patch(
'charmhelpers.core.host.lsb_release',
return_value={
'DISTRIB_CODENAME': 'jammy'
}).start()