Fix charm for tox4 compatibility

Also needed to switch charm to use _stored rather than
state inline with ops framework change.

Related-Bug: 2002788
Change-Id: I0bf8ece1f930157e6a4fad087d8c24ad5f5cfe6b
This commit is contained in:
Liam Young 2023-01-23 13:31:56 +00:00
parent f64d041ca2
commit 97ebbe3a8f
12 changed files with 125 additions and 108 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

@ -9,5 +9,5 @@
needs_charm_build: true
charm_build_name: manila-netapp
build_type: charmcraft
charmcraft_channel: 2.0/stable
charmcraft_channel: 2.1/stable

View File

@ -1,3 +1,3 @@
ops
git+https://github.com/openstack-charmers/ops-openstack#egg=ops_openstack
git+https://opendev.org/openstack/charm-ops-openstack#egg=ops_openstack
git+https://github.com/juju/charm-helpers.git#egg=charmhelpers

View File

@ -75,7 +75,7 @@ class ManilaNetappCharm(ops_openstack.core.OSBaseCharm):
context=self.adapters)
self.manila_plugin.send_backend_config(
self.options.share_backend_name, rendered_configs)
self.state.is_started = True
self._stored.is_started = True
self.update_status()
def custom_status_check(self):

View File

@ -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

55
src/tox.ini Normal file
View File

@ -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}

View File

@ -41,3 +41,6 @@ keyring<21
# 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
ops
git+https://opendev.org/openstack/charm-ops-openstack#egg=ops_openstack

View File

@ -117,8 +117,6 @@ applications:
rabbitmq-server:
charm: ch:rabbitmq-server
num_units: 1
options:
source: *openstack-origin
to:
- '8'
channel: latest/edge

View File

@ -117,8 +117,6 @@ applications:
rabbitmq-server:
charm: ch:rabbitmq-server
num_units: 1
options:
source: *openstack-origin
to:
- '8'
channel: latest/edge

View File

@ -117,8 +117,6 @@ applications:
rabbitmq-server:
charm: ch:rabbitmq-server
num_units: 1
options:
source: *openstack-origin
to:
- '8'
channel: latest/edge

141
tox.ini
View File

@ -1,79 +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
# 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}
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 =
git
bash
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
@ -107,43 +107,6 @@ omit =
basepython = python3
commands = {posargs}
[testenv:build]
basepython = python3
deps = -r{toxinidir}/build-requirements.txt
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
# NOTE(lourot): temporarily disabling Zaza in order to get a green gate as we
# don't have the necessary NetApp ONTAP cluster deployed yet in order to run
# these tests.
commands = /bin/true
#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
# E402 ignore necessary for path append before sys module import in actions
ignore = E402,W503,W504

View File

@ -60,7 +60,7 @@ class TestManilaNetappCharm(TestCase):
self.harness.add_relation_unit(rel_id, 'manila/0')
self.harness.begin_with_initial_hooks()
self.assertTrue(self.harness.charm.state.is_started)
self.assertTrue(self.harness.charm._stored.is_started)
_render.assert_called_once_with(
source='manila.conf',
template_loader='test-loader',
@ -93,7 +93,7 @@ class TestManilaNetappCharm(TestCase):
self.harness.begin_with_initial_hooks()
# Validate workflow with incomplete relation data
self.assertFalse(self.harness.charm.state.is_started)
self.assertFalse(self.harness.charm._stored.is_started)
_render.assert_not_called()
_get_loader.assert_not_called()
_send_backend_config.assert_not_called()
@ -111,7 +111,7 @@ class TestManilaNetappCharm(TestCase):
'data': 'test-manila-auth-data'
})
})
self.assertTrue(self.harness.charm.state.is_started)
self.assertTrue(self.harness.charm._stored.is_started)
_render.assert_called_once_with(
source='manila.conf',
template_loader='test-loader',