From 28f3d1ce17816d2cf17f2f31b07bb4172c156c40 Mon Sep 17 00:00:00 2001 From: Hemanth Nakkina Date: Tue, 26 Jul 2022 15:38:39 +0530 Subject: [PATCH] Sync global tox, requirement files Following changes are done as part of this patch: * Sync global tox, requirements.txt, test-requirements from release-tools project * Resolve flake errors * Restructure unit tests directory --- .stestr.conf | 4 +- CONTRIBUTING.md | 4 +- requirements.txt | 33 +++-- run_tests | 17 --- src/charm.py | 1 + test-requirements.txt | 27 ++-- {unit_tests => tests/unit}/__init__.py | 0 .../unit}/test_ovn_relay_charm.py | 5 - tox.ini | 134 +++++++----------- 9 files changed, 90 insertions(+), 135 deletions(-) delete mode 100755 run_tests rename {unit_tests => tests/unit}/__init__.py (100%) rename {unit_tests => tests/unit}/test_ovn_relay_charm.py (96%) diff --git a/.stestr.conf b/.stestr.conf index 5fcccac..e4750de 100644 --- a/.stestr.conf +++ b/.stestr.conf @@ -1,3 +1,3 @@ [DEFAULT] -test_path=./unit_tests -top_dir=./ +test_path=./tests/unit +top_dir=./tests diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 88bd2fa..18283b1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -32,9 +32,9 @@ TODO ## Testing The Python operator framework includes a very nice harness for testing -operator behaviour without full deployment. Just `run_tests`: +operator behaviour without full deployment. Run tests using command: - ./run_tests + tox -e py3 ## Deployment diff --git a/requirements.txt b/requirements.txt index 592fb03..f1f8957 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,14 +1,31 @@ -ops -jinja2 -# Get resources from github until cacerts issue is charmbuild image is fixed. -# git+https://opendev.org/openstack/charm-ops-openstack#egg=ops_openstack -# git+https://opendev.org/openstack/charm-ops-interface-tls-certificates#egg=interface_tls_certificates -git+https://github.com/openstack/charm-ops-interface-tls-certificates#egg=interface_tls_certificates +# 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 +# -git+https://github.com/openstack-charmers/advanced-sunbeam-openstack#egg=ops_sunbeam +# NOTE: newer versions of cryptography require a Rust compiler to build, +# see +# * https://github.com/openstack-charmers/zaza/issues/421 +# * https://mail.python.org/pipermail/cryptography-dev/2021-January/001003.html +# +cryptography<3.4 +jinja2 lightkube lightkube-models -cryptography < 3.4 +ops +git+https://github.com/openstack-charmers/advanced-sunbeam-openstack#egg=ops_sunbeam + +python-keystoneclient # keystone-k8s + +# Used for Traefik +# Note: Remove when traefik-k8s-operator v1 library is released +serialized_data_interface + +# Get resources from github until cacerts issue is charmbuild image is fixed. +git+https://github.com/openstack/charm-ops-interface-tls-certificates#egg=interface_tls_certificates + +# Note: Required for cinder-k8s, cinder-ceph-k8s, glance-k8s, nova-k8s git+https://github.com/openstack/charm-ops-interface-ceph-client#egg=interface_ceph_client # Charmhelpers is only present as interface_ceph_client uses it. git+https://github.com/juju/charm-helpers.git#egg=charmhelpers diff --git a/run_tests b/run_tests deleted file mode 100755 index c88bcc3..0000000 --- a/run_tests +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh -e -# Copyright 2022 Canonical Ltd. -# See LICENSE file for licensing details. - -if [ -z "$VIRTUAL_ENV" -a -d venv/ ]; then - . venv/bin/activate -fi - -if [ -z "$PYTHONPATH" ]; then - export PYTHONPATH="lib:src" -else - export PYTHONPATH="lib:src:$PYTHONPATH" -fi - -flake8 -coverage run --branch --source=src -m unittest -v "$@" -coverage report -m diff --git a/src/charm.py b/src/charm.py index 80fb8a1..e99a349 100755 --- a/src/charm.py +++ b/src/charm.py @@ -81,6 +81,7 @@ class OVNRelayXenaOperatorCharm(OVNRelayOperatorCharm): openstack_release = 'xena' + if __name__ == "__main__": # Note: use_juju_for_storage=True required per # https://github.com/canonical/operator/issues/506 diff --git a/test-requirements.txt b/test-requirements.txt index 8057d2c..35f58ad 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,17 +1,10 @@ -# This file is managed centrally. If you find the need to modify this as a -# one-off, please don't. Intead, consult #openstack-charms and ask about -# requirements management in charms via bot-control. Thank you. -charm-tools>=2.4.4 -coverage>=3.6 -mock>=1.2 -flake8>=2.2.4,<=2.4.1 -pyflakes==2.1.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?) +# 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 +# + +coverage +mock +flake8 +stestr diff --git a/unit_tests/__init__.py b/tests/unit/__init__.py similarity index 100% rename from unit_tests/__init__.py rename to tests/unit/__init__.py diff --git a/unit_tests/test_ovn_relay_charm.py b/tests/unit/test_ovn_relay_charm.py similarity index 96% rename from unit_tests/test_ovn_relay_charm.py rename to tests/unit/test_ovn_relay_charm.py index 23c8c12..a7c55c4 100644 --- a/unit_tests/test_ovn_relay_charm.py +++ b/tests/unit/test_ovn_relay_charm.py @@ -14,11 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import sys - -sys.path.append('lib') # noqa -sys.path.append('src') # noqa - import charm import ops_sunbeam.test_utils as test_utils diff --git a/tox.ini b/tox.ini index 5741249..7044cca 100644 --- a/tox.ini +++ b/tox.ini @@ -1,73 +1,76 @@ -# 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. +envlist = pep8,py3 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 -requires = pip < 20.3 - virtualenv < 20.0 -# NOTE: https://wiki.canonical.com/engineering/OpenStack/InstallLatestToxOnOsci minversion = 3.18.0 +[vars] +src_path = {toxinidir}/src/ +tst_path = {toxinidir}/tests/ +lib_path = {toxinidir}/lib/ + [testenv] -setenv = VIRTUAL_ENV={envdir} - PYTHONHASHSEED=0 - CHARM_DIR={envdir} +basepython = python3 +setenv = + PYTHONPATH = {toxinidir}:{[vars]lib_path}:{[vars]src_path} +passenv = + PYTHONPATH install_command = pip install {opts} {packages} commands = stestr run --slowest {posargs} -whitelist_externals = - git - add-to-archive.py - bash - charmcraft -passenv = HOME TERM CS_* OS_* TEST_* -deps = -r{toxinidir}/test-requirements.txt +allowlist_externals = + git + charmcraft + fetch-libs.sh +deps = + -r{toxinidir}/test-requirements.txt + +[testenv:build] +basepython = python3 +deps = +commands = + charmcraft clean + charmcraft -v pack [testenv:fetch] basepython = python3 deps = commands = - ./fetch-libs.sh - -[testenv:py3.8] -basepython = python3.8 -deps = -r{toxinidir}/requirements.txt - -r{toxinidir}/test-requirements.txt - -[testenv:py3.9] -basepython = python3.9 -deps = -r{toxinidir}/requirements.txt - -r{toxinidir}/test-requirements.txt + {toxinidir}/fetch-libs.sh [testenv:py3] basepython = python3 -deps = -r{toxinidir}/requirements.txt - -r{toxinidir}/test-requirements.txt +deps = + {[testenv]deps} + -r{toxinidir}/requirements.txt + +[testenv:py3.8] +basepython = python3.8 +deps = {[testenv:py3]deps} + +[testenv:py3.9] +basepython = python3.9 +deps = {[testenv:py3]deps} + +[testenv:py3.10] +basepython = python3.10 +deps = {[testenv:py3]deps} [testenv:pep8] basepython = python3 -deps = -r{toxinidir}/requirements.txt - -r{toxinidir}/test-requirements.txt -commands = flake8 {posargs} src unit_tests tests +deps = {[testenv]deps} +commands = flake8 {posargs} {[vars]src_path} {[vars]tst_path} [testenv:cover] -# Technique based heavily upon -# https://github.com/openstack/nova/blob/master/tox.ini basepython = python3 -deps = -r{toxinidir}/requirements.txt - -r{toxinidir}/test-requirements.txt +deps = {[testenv:py3]deps} setenv = {[testenv]setenv} PYTHON=coverage run @@ -87,45 +90,8 @@ source = . omit = .tox/* - */charmhelpers/* - unit_tests/* + tests/* src/templates/* -[testenv:venv] -basepython = python3 -commands = {posargs} - -[testenv:build] -basepython = python3 -deps = -r{toxinidir}/build-requirements.txt -commands = - charmcraft build - -[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,E902 +ignore=E226,W504