From fb6ea187198aa040d9ed3778eeb3580f26ba5abb Mon Sep 17 00:00:00 2001 From: Liam Young Date: Wed, 18 Jan 2023 10:20:38 +0000 Subject: [PATCH] Fix charm for tox4 compatibility Related-Bug: 2002788 Change-Id: I64f071d8175235abf8748c1cc82943291a18bb40 --- build-requirements.txt | 7 -- osci.yaml | 2 +- pip.sh | 18 ----- src/test-requirements.txt | 9 +++ src/tox.ini | 55 +++++++++++++++ test-requirements.txt | 2 + tox.ini | 143 ++++++++++++++------------------------ 7 files changed, 121 insertions(+), 115 deletions(-) delete mode 100644 build-requirements.txt delete mode 100755 pip.sh create mode 100644 src/test-requirements.txt create mode 100644 src/tox.ini diff --git a/build-requirements.txt b/build-requirements.txt deleted file mode 100644 index 0eb4905..0000000 --- a/build-requirements.txt +++ /dev/null @@ -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' # diff --git a/osci.yaml b/osci.yaml index dbe37fc..a908f8c 100644 --- a/osci.yaml +++ b/osci.yaml @@ -7,4 +7,4 @@ needs_charm_build: true charm_build_name: cinder-nimblestorage build_type: charmcraft - charmcraft_channel: 2.0/stable + charmcraft_channel: 2.1/stable diff --git a/pip.sh b/pip.sh deleted file mode 100755 index 9a7e6b0..0000000 --- a/pip.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash -# -# This file is managed centrally by release-tools and should not be modified -# within individual charm repos. See the 'global' dir contents for available -# choices of tox.ini for OpenStack Charms: -# https://github.com/openstack-charmers/release-tools -# -# setuptools 58.0 dropped the support for use_2to3=true which is needed to -# install blessings (an indirect dependency of charm-tools). -# -# More details on the beahvior of tox and virtualenv creation can be found at -# https://github.com/tox-dev/tox/issues/448 -# -# This script is wrapper to force the use of the pinned versions early in the -# process when the virtualenv was created and upgraded before installing the -# depedencies declared in the target. -pip install 'pip<20.3' 'setuptools<50.0.0' -pip "$@" diff --git a/src/test-requirements.txt b/src/test-requirements.txt new file mode 100644 index 0000000..e771023 --- /dev/null +++ b/src/test-requirements.txt @@ -0,0 +1,9 @@ +# This file is managed centrally by release-tools and should not be modified +# within individual charm repos. See the 'global' dir contents for available +# choices of *requirements.txt files for OpenStack Charms: +# https://github.com/openstack-charmers/release-tools +# + +# Functional Test Requirements (let Zaza's dependencies solve all dependencies here!) +git+https://github.com/openstack-charmers/zaza.git#egg=zaza +git+https://github.com/openstack-charmers/zaza-openstack-tests.git#egg=zaza.openstack diff --git a/src/tox.ini b/src/tox.ini new file mode 100644 index 0000000..8ffff0f --- /dev/null +++ b/src/tox.ini @@ -0,0 +1,55 @@ +# Source charm (with zaza): ./src/tox.ini +# This file is managed centrally by release-tools and should not be modified +# within individual charm repos. See the 'global' dir contents for available +# choices of tox.ini for OpenStack Charms: +# https://github.com/openstack-charmers/release-tools + +[tox] +envlist = pep8 +# NOTE: Avoid build/test env pollution by not enabling sitepackages. +sitepackages = False +# NOTE: Avoid false positives by not skipping missing interpreters. +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 +allowlist_externals = juju +passenv = + HOME + TERM + CS_* + OS_* + TEST_* +deps = -r{toxinidir}/test-requirements.txt + +[testenv:pep8] +basepython = python3 +commands = charm-proof + +[testenv:func-noop] +basepython = python3 +commands = + functest-run-suite --help + +[testenv:func] +basepython = python3 +commands = + functest-run-suite --keep-model + +[testenv:func-smoke] +basepython = python3 +commands = + functest-run-suite --keep-model --smoke + +[testenv:func-target] +basepython = python3 +commands = + functest-run-suite --keep-model --bundle {posargs} + +[testenv:venv] +commands = {posargs} diff --git a/test-requirements.txt b/test-requirements.txt index 170df5e..1ab98d6 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -14,3 +14,5 @@ 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?) +ops +git+https://opendev.org/openstack/charm-ops-openstack#egg=ops_openstack diff --git a/tox.ini b/tox.ini index 4822c9e..854d8be 100644 --- a/tox.ini +++ b/tox.ini @@ -1,76 +1,79 @@ -# Operator charm (with zaza): tox.ini +# Source charm: ./tox.ini +# This file is managed centrally by release-tools and should not be modified +# within individual charm repos. See the 'global' dir contents for available +# choices of tox.ini for OpenStack Charms: +# https://github.com/openstack-charmers/release-tools [tox] envlist = pep8,py3 -skipsdist = True # NOTE: Avoid build/test env pollution by not enabling sitepackages. 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 [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} -whitelist_externals = - git - bash + TERM=linux + CHARM_LAYERS_DIR={toxinidir}/layers + CHARM_INTERFACES_DIR={toxinidir}/interfaces + JUJU_REPOSITORY={toxinidir}/build +passenv = + no_proxy + http_proxy + https_proxy + CHARM_INTERFACES_DIR + CHARM_LAYERS_DIR + JUJU_REPOSITORY +allowlist_externals = charmcraft + bash + tox rename.sh -passenv = HOME TERM CS_* OS_* TEST_* -deps = -r{toxinidir}/test-requirements.txt +deps = + -r{toxinidir}/requirements.txt + +[testenv:build] +basepython = python3 +# charmcraft clean is done to ensure that +# `tox -e build` always performs a clean, repeatable build. +# For faster rebuilds during development, +# directly run `charmcraft -v pack && ./rename.sh`. +commands = + charmcraft clean + charmcraft -v pack + {toxinidir}/rename.sh + charmcraft clean + +[testenv:build-reactive] +basepython = python3 +commands = + charm-build --log-level DEBUG --use-lock-file-branches -o {toxinidir}/build/builds src {posargs} + +[testenv:add-build-lock-file] +basepython = python3 +commands = + charm-build --log-level DEBUG --write-lock-file -o {toxinidir}/build/builds src {posargs} [testenv:py3] basepython = python3 -deps = -r{toxinidir}/requirements.txt - -r{toxinidir}/test-requirements.txt - -[testenv:py36] -basepython = python3.6 -deps = -r{toxinidir}/requirements.txt - -r{toxinidir}/test-requirements.txt -commands = stestr run --slowest {posargs} - -[testenv:py38] -basepython = python3.8 -deps = -r{toxinidir}/requirements.txt - -r{toxinidir}/test-requirements.txt -commands = stestr run --slowest {posargs} - -[testenv:py39] -basepython = python3.9 -deps = -r{toxinidir}/requirements.txt - -r{toxinidir}/test-requirements.txt +deps = -r{toxinidir}/test-requirements.txt commands = stestr run --slowest {posargs} [testenv:py310] basepython = python3.10 -deps = -r{toxinidir}/requirements.txt - -r{toxinidir}/test-requirements.txt +deps = -r{toxinidir}/test-requirements.txt commands = stestr run --slowest {posargs} [testenv:pep8] basepython = python3 -deps = -r{toxinidir}/requirements.txt - -r{toxinidir}/test-requirements.txt -commands = flake8 {posargs} src unit_tests tests +deps = flake8==3.9.2 + git+https://github.com/juju/charm-tools.git +commands = flake8 {posargs} src unit_tests [testenv:cover] # Technique based heavily upon @@ -104,44 +107,6 @@ omit = basepython = python3 commands = {posargs} -[testenv:build] -basepython = python3 -deps = -r{toxinidir}/build-requirements.txt -# NOTE(lourot): charmcraft 1.0.0 used to generate -# cinder-nimblestorage.charm, which is the behaviour expected by OSCI. -# However charmcraft 1.2.1 now generates -# cinder-nimblestorage_ubuntu-20.04-amd64.charm instead. In order to keep -# the old behaviour we rename the file at the en -commands = - charmcraft clean - charmcraft -v pack - {toxinidir}/rename.sh - -[testenv:func-noop] -basepython = python3 -commands = - functest-run-suite --help - -[testenv:func] -basepython = python3 -commands = - functest-run-suite --keep-model - -[testenv:func-smoke] -basepython = python3 -commands = - functest-run-suite --keep-model --smoke - -[testenv:func-dev] -basepython = python3 -commands = - functest-run-suite --keep-model --dev - -[testenv:func-target] -basepython = python3 -commands = - functest-run-suite --keep-model --bundle {posargs} - [flake8] -# Ignore E902 because the unit_tests directory is missing in the built charm. -ignore = E402,E226,W503,W504,E902 +# E402 ignore necessary for path append before sys module import in actions +ignore = E402,W503,W504