From 43f18cb215dea7b1dd1c2855ae87407c88c8a31c Mon Sep 17 00:00:00 2001 From: Ionut Balutoiu Date: Tue, 16 Mar 2021 10:54:48 +0200 Subject: [PATCH] Add charm code --- .gitignore | 5 + .stestr.conf | 3 + README.md | 3 +- requirements.txt | 26 ++++++ src/README.md | 17 ++++ src/layer.yaml | 17 ++++ src/lib/__init__.py | 0 src/lib/charm/__init__.py | 0 src/lib/charm/openstack/__init__.py | 0 src/lib/charm/openstack/manila_dashboard.py | 25 +++++ src/metadata.yaml | 17 ++++ src/reactive/__init__.py | 0 src/reactive/manila_dashboard_handlers.py | 40 ++++++++ src/test-requirements.txt | 15 +++ src/tests/bundles/bionic-train.yaml | 82 ++++++++++++++++ src/tests/bundles/bionic-ussuri.yaml | 82 ++++++++++++++++ src/tests/bundles/focal-ussuri.yaml | 98 ++++++++++++++++++++ src/tests/bundles/focal-victoria.yaml | 98 ++++++++++++++++++++ src/tests/bundles/groovy-victoria.yaml | 98 ++++++++++++++++++++ src/tests/tests.yaml | 26 ++++++ src/tox.ini | 61 ++++++++++++ src/wheelhouse.txt | 3 + test-requirements.txt | 47 ++++++++++ tox.ini | 97 +++++++++++++++++++ unit_tests/__init__.py | 22 +++++ unit_tests/test_manila_dashboard_handlers.py | 62 +++++++++++++ 26 files changed, 942 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 .stestr.conf mode change 100644 => 120000 README.md create mode 100644 requirements.txt create mode 100644 src/README.md create mode 100644 src/layer.yaml create mode 100644 src/lib/__init__.py create mode 100644 src/lib/charm/__init__.py create mode 100644 src/lib/charm/openstack/__init__.py create mode 100644 src/lib/charm/openstack/manila_dashboard.py create mode 100644 src/metadata.yaml create mode 100644 src/reactive/__init__.py create mode 100644 src/reactive/manila_dashboard_handlers.py create mode 100644 src/test-requirements.txt create mode 100644 src/tests/bundles/bionic-train.yaml create mode 100644 src/tests/bundles/bionic-ussuri.yaml create mode 100644 src/tests/bundles/focal-ussuri.yaml create mode 100644 src/tests/bundles/focal-victoria.yaml create mode 100644 src/tests/bundles/groovy-victoria.yaml create mode 100644 src/tests/tests.yaml create mode 100644 src/tox.ini create mode 100644 src/wheelhouse.txt create mode 100644 test-requirements.txt create mode 100644 tox.ini create mode 100644 unit_tests/__init__.py create mode 100644 unit_tests/test_manila_dashboard_handlers.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eb1cd65 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.tox +.stestr +*__pycache__* +*.pyc +build diff --git a/.stestr.conf b/.stestr.conf new file mode 100644 index 0000000..5fcccac --- /dev/null +++ b/.stestr.conf @@ -0,0 +1,3 @@ +[DEFAULT] +test_path=./unit_tests +top_dir=./ diff --git a/README.md b/README.md deleted file mode 100644 index 04ef01f..0000000 --- a/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# charm-manila-dashboard -Juju charm for the Manila dashboard plugin diff --git a/README.md b/README.md new file mode 120000 index 0000000..351df1d --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +src/README.md \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..a4d3eff --- /dev/null +++ b/requirements.txt @@ -0,0 +1,26 @@ +# 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 +# +# NOTE(lourot): This might look like a duplication of test-requirements.txt but +# some tox targets use only test-requirements.txt whereas charm-build uses only +# requirements.txt +setuptools<50.0.0 # https://github.com/pypa/setuptools/commit/04e3df22df840c6bb244e9b27bc56750c44b7c85 + +# Build requirements +charm-tools>=2.4.4 + +# Workaround until https://github.com/juju/charm-tools/pull/589 gets +# published +keyring<21 + +simplejson + +# Newer versions use keywords that didn't exist in python 3.5 yet (e.g. +# "ModuleNotFoundError") +# NOTE(lourot): This might look like a duplication of test-requirements.txt but +# some tox targets use only test-requirements.txt whereas charm-build uses only +# requirements.txt +importlib-metadata<3.0.0; python_version < '3.6' +importlib-resources<3.0.0; python_version < '3.6' diff --git a/src/README.md b/src/README.md new file mode 100644 index 0000000..79e0937 --- /dev/null +++ b/src/README.md @@ -0,0 +1,17 @@ +# Overview + +This subordinate charm provides the Manila Dashboard plugin for use with the OpenStack Dashboard. + +# Usage + +Example minimal deploy: + + juju deploy cs:openstack-dashboard --config openstack-origin=cloud:bionic-train + juju deploy cs:manila-dashboard + juju add-relation openstack-dashboard:dashboard-plugin manila-dashboard:dashboard + +# Bugs + +Please report bugs on [Launchpad](https://bugs.launchpad.net/charm-manila-dashboard/+filebug). + +For general questions please refer to the OpenStack [Charm Guide](https://docs.openstack.org/charm-guide/latest/). diff --git a/src/layer.yaml b/src/layer.yaml new file mode 100644 index 0000000..23c2109 --- /dev/null +++ b/src/layer.yaml @@ -0,0 +1,17 @@ +includes: + - layer:openstack + - interface:dashboard-plugin +options: + basic: + use_venv: True + include_system_packages: False +repo: https://github.com/openstack/charm-manila-dashboard +config: + deletes: + - debug + - verbose + - use-internal-endpoints + - use-syslog + - ssl_ca + - ssl_cert + - ssl_key diff --git a/src/lib/__init__.py b/src/lib/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/lib/charm/__init__.py b/src/lib/charm/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/lib/charm/openstack/__init__.py b/src/lib/charm/openstack/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/lib/charm/openstack/manila_dashboard.py b/src/lib/charm/openstack/manila_dashboard.py new file mode 100644 index 0000000..0de51c6 --- /dev/null +++ b/src/lib/charm/openstack/manila_dashboard.py @@ -0,0 +1,25 @@ +# Copyright 2021 Canonical Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import charms_openstack.adapters +import charms_openstack.charm + + +class ManilaDashboardCharm(charms_openstack.charm.OpenStackCharm): + release = 'stein' + name = 'manila-dashboard' + packages = ['python3-manila-ui'] + python_version = 3 + adapters_class = charms_openstack.adapters.OpenStackRelationAdapters + required_relations = ['dashboard'] diff --git a/src/metadata.yaml b/src/metadata.yaml new file mode 100644 index 0000000..593d2a9 --- /dev/null +++ b/src/metadata.yaml @@ -0,0 +1,17 @@ +name: manila-dashboard +summary: Openstack Manila Dashboard +maintainer: OpenStack Charmers +description: | + This is the dashboard plugin for the OpenStack shared file system + service, Manila. +tags: +- openstack +series: +- bionic +- focal +- groovy +subordinate: true +requires: + dashboard: + interface: dashboard-plugin + scope: container diff --git a/src/reactive/__init__.py b/src/reactive/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/reactive/manila_dashboard_handlers.py b/src/reactive/manila_dashboard_handlers.py new file mode 100644 index 0000000..08ed74c --- /dev/null +++ b/src/reactive/manila_dashboard_handlers.py @@ -0,0 +1,40 @@ +# Copyright 2021 Canonical Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import charms.reactive as reactive + +import charms_openstack.bus +import charms_openstack.charm as charm + +charms_openstack.bus.discover() + +# Use the charms.openstack defaults for common states and hooks +charm.use_defaults( + 'charm.installed', + 'config.changed', + 'update-status', + 'upgrade-charm') + + +@reactive.when('dashboard.available') +def dashboard_available(): + """Relation to OpenStack Dashboard principal charm complete. + """ + with charm.provide_charm_instance() as manila_dashboard_charm: + dashboard_relation = reactive.endpoint_from_flag('dashboard.available') + dashboard_relation.publish_plugin_info( + "", None, + conflicting_packages=manila_dashboard_charm.purge_packages, + install_packages=manila_dashboard_charm.packages) + manila_dashboard_charm.assess_status() diff --git a/src/test-requirements.txt b/src/test-requirements.txt new file mode 100644 index 0000000..520681e --- /dev/null +++ b/src/test-requirements.txt @@ -0,0 +1,15 @@ +# 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 +# +# pep8 requirements +charm-tools>=2.4.4 + +# Workaround until https://github.com/juju/charm-tools/pull/589 gets +# published +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 diff --git a/src/tests/bundles/bionic-train.yaml b/src/tests/bundles/bionic-train.yaml new file mode 100644 index 0000000..8791635 --- /dev/null +++ b/src/tests/bundles/bionic-train.yaml @@ -0,0 +1,82 @@ +variables: + openstack-origin: &openstack-origin cloud:bionic-train + +series: bionic + +comment: +- 'machines section to decide order of deployment. database sooner = faster' +machines: + '0': + constraints: mem=3072M + '1': + '2': + '3': + '4': + +applications: + + percona-cluster: + charm: cs:~openstack-charmers-next/percona-cluster + num_units: 1 + options: + source: *openstack-origin + max-connections: 1000 + innodb-buffer-pool-size: 256M + to: + - '0' + + rabbitmq-server: + charm: cs:~openstack-charmers-next/rabbitmq-server + num_units: 1 + to: + - '1' + + keystone: + charm: cs:~openstack-charmers-next/keystone + num_units: 1 + options: + openstack-origin: *openstack-origin + to: + - '2' + + manila: + charm: cs:~openstack-charmers-next/manila + num_units: 1 + options: + openstack-origin: *openstack-origin + to: + - '3' + + openstack-dashboard: + charm: cs:~openstack-charmers-next/openstack-dashboard + num_units: 1 + options: + openstack-origin: *openstack-origin + to: + - '4' + + manila-dashboard: + charm: ../../../manila-dashboard + +relations: + + - - 'keystone:shared-db' + - 'percona-cluster:shared-db' + + - - 'manila:shared-db' + - 'percona-cluster:shared-db' + + - - 'manila:amqp' + - 'rabbitmq-server:amqp' + + - - 'manila:identity-service' + - 'keystone:identity-service' + + - - 'openstack-dashboard:shared-db' + - 'percona-cluster:shared-db' + + - - 'openstack-dashboard:identity-service' + - 'keystone:identity-service' + + - - 'openstack-dashboard:dashboard-plugin' + - 'manila-dashboard:dashboard' diff --git a/src/tests/bundles/bionic-ussuri.yaml b/src/tests/bundles/bionic-ussuri.yaml new file mode 100644 index 0000000..832d527 --- /dev/null +++ b/src/tests/bundles/bionic-ussuri.yaml @@ -0,0 +1,82 @@ +variables: + openstack-origin: &openstack-origin cloud:bionic-ussuri + +series: bionic + +comment: +- 'machines section to decide order of deployment. database sooner = faster' +machines: + '0': + constraints: mem=3072M + '1': + '2': + '3': + '4': + +applications: + + percona-cluster: + charm: cs:~openstack-charmers-next/percona-cluster + num_units: 1 + options: + source: *openstack-origin + max-connections: 1000 + innodb-buffer-pool-size: 256M + to: + - '0' + + rabbitmq-server: + charm: cs:~openstack-charmers-next/rabbitmq-server + num_units: 1 + to: + - '1' + + keystone: + charm: cs:~openstack-charmers-next/keystone + num_units: 1 + options: + openstack-origin: *openstack-origin + to: + - '2' + + manila: + charm: cs:~openstack-charmers-next/manila + num_units: 1 + options: + openstack-origin: *openstack-origin + to: + - '3' + + openstack-dashboard: + charm: cs:~openstack-charmers-next/openstack-dashboard + num_units: 1 + options: + openstack-origin: *openstack-origin + to: + - '4' + + manila-dashboard: + charm: ../../../manila-dashboard + +relations: + + - - 'keystone:shared-db' + - 'percona-cluster:shared-db' + + - - 'manila:shared-db' + - 'percona-cluster:shared-db' + + - - 'manila:amqp' + - 'rabbitmq-server:amqp' + + - - 'manila:identity-service' + - 'keystone:identity-service' + + - - 'openstack-dashboard:shared-db' + - 'percona-cluster:shared-db' + + - - 'openstack-dashboard:identity-service' + - 'keystone:identity-service' + + - - 'openstack-dashboard:dashboard-plugin' + - 'manila-dashboard:dashboard' diff --git a/src/tests/bundles/focal-ussuri.yaml b/src/tests/bundles/focal-ussuri.yaml new file mode 100644 index 0000000..39dfdd0 --- /dev/null +++ b/src/tests/bundles/focal-ussuri.yaml @@ -0,0 +1,98 @@ +variables: + openstack-origin: &openstack-origin distro + +series: focal + +comment: +- 'machines section to decide order of deployment. database sooner = faster' +machines: + '0': + constraints: mem=3072M + '1': + constraints: mem=3072M + '2': + constraints: mem=3072M + '3': + '4': + '5': + '6': + +applications: + keystone-mysql-router: + charm: cs:~openstack-charmers-next/mysql-router + manila-mysql-router: + charm: cs:~openstack-charmers-next/mysql-router + openstack-dashboard-mysql-router: + charm: cs:~openstack-charmers-next/mysql-router + + mysql-innodb-cluster: + charm: cs:~openstack-charmers-next/mysql-innodb-cluster + num_units: 3 + options: + source: *openstack-origin + to: + - '0' + - '1' + - '2' + + rabbitmq-server: + charm: cs:~openstack-charmers-next/rabbitmq-server + num_units: 1 + to: + - '3' + + keystone: + charm: cs:~openstack-charmers-next/keystone + num_units: 1 + options: + openstack-origin: *openstack-origin + to: + - '4' + + manila: + charm: cs:~openstack-charmers-next/manila + num_units: 1 + options: + openstack-origin: *openstack-origin + to: + - '5' + + openstack-dashboard: + charm: cs:~openstack-charmers-next/openstack-dashboard + num_units: 1 + options: + openstack-origin: *openstack-origin + to: + - '6' + + manila-dashboard: + charm: ../../../manila-dashboard + +relations: + + - - 'keystone:shared-db' + - 'keystone-mysql-router:shared-db' + - - 'keystone-mysql-router:db-router' + - 'mysql-innodb-cluster:db-router' + + - - 'manila:shared-db' + - 'manila-mysql-router:shared-db' + - - 'manila-mysql-router:db-router' + - 'mysql-innodb-cluster:db-router' + + - - 'manila:amqp' + - 'rabbitmq-server:amqp' + + - - 'manila:identity-service' + - 'keystone:identity-service' + + - - 'openstack-dashboard:shared-db' + - 'openstack-dashboard-mysql-router:shared-db' + - - 'openstack-dashboard-mysql-router:db-router' + - 'mysql-innodb-cluster:db-router' + + - - 'openstack-dashboard:identity-service' + - 'keystone:identity-service' + + - - 'openstack-dashboard:dashboard-plugin' + - 'manila-dashboard:dashboard' diff --git a/src/tests/bundles/focal-victoria.yaml b/src/tests/bundles/focal-victoria.yaml new file mode 100644 index 0000000..b47248c --- /dev/null +++ b/src/tests/bundles/focal-victoria.yaml @@ -0,0 +1,98 @@ +variables: + openstack-origin: &openstack-origin cloud:focal-victoria + +series: focal + +comment: +- 'machines section to decide order of deployment. database sooner = faster' +machines: + '0': + constraints: mem=3072M + '1': + constraints: mem=3072M + '2': + constraints: mem=3072M + '3': + '4': + '5': + '6': + +applications: + keystone-mysql-router: + charm: cs:~openstack-charmers-next/mysql-router + manila-mysql-router: + charm: cs:~openstack-charmers-next/mysql-router + openstack-dashboard-mysql-router: + charm: cs:~openstack-charmers-next/mysql-router + + mysql-innodb-cluster: + charm: cs:~openstack-charmers-next/mysql-innodb-cluster + num_units: 3 + options: + source: *openstack-origin + to: + - '0' + - '1' + - '2' + + rabbitmq-server: + charm: cs:~openstack-charmers-next/rabbitmq-server + num_units: 1 + to: + - '3' + + keystone: + charm: cs:~openstack-charmers-next/keystone + num_units: 1 + options: + openstack-origin: *openstack-origin + to: + - '4' + + manila: + charm: cs:~openstack-charmers-next/manila + num_units: 1 + options: + openstack-origin: *openstack-origin + to: + - '5' + + openstack-dashboard: + charm: cs:~openstack-charmers-next/openstack-dashboard + num_units: 1 + options: + openstack-origin: *openstack-origin + to: + - '6' + + manila-dashboard: + charm: ../../../manila-dashboard + +relations: + + - - 'keystone:shared-db' + - 'keystone-mysql-router:shared-db' + - - 'keystone-mysql-router:db-router' + - 'mysql-innodb-cluster:db-router' + + - - 'manila:shared-db' + - 'manila-mysql-router:shared-db' + - - 'manila-mysql-router:db-router' + - 'mysql-innodb-cluster:db-router' + + - - 'manila:amqp' + - 'rabbitmq-server:amqp' + + - - 'manila:identity-service' + - 'keystone:identity-service' + + - - 'openstack-dashboard:shared-db' + - 'openstack-dashboard-mysql-router:shared-db' + - - 'openstack-dashboard-mysql-router:db-router' + - 'mysql-innodb-cluster:db-router' + + - - 'openstack-dashboard:identity-service' + - 'keystone:identity-service' + + - - 'openstack-dashboard:dashboard-plugin' + - 'manila-dashboard:dashboard' diff --git a/src/tests/bundles/groovy-victoria.yaml b/src/tests/bundles/groovy-victoria.yaml new file mode 100644 index 0000000..554f117 --- /dev/null +++ b/src/tests/bundles/groovy-victoria.yaml @@ -0,0 +1,98 @@ +variables: + openstack-origin: &openstack-origin distro + +series: groovy + +comment: +- 'machines section to decide order of deployment. database sooner = faster' +machines: + '0': + constraints: mem=3072M + '1': + constraints: mem=3072M + '2': + constraints: mem=3072M + '3': + '4': + '5': + '6': + +applications: + keystone-mysql-router: + charm: cs:~openstack-charmers-next/mysql-router + manila-mysql-router: + charm: cs:~openstack-charmers-next/mysql-router + openstack-dashboard-mysql-router: + charm: cs:~openstack-charmers-next/mysql-router + + mysql-innodb-cluster: + charm: cs:~openstack-charmers-next/mysql-innodb-cluster + num_units: 3 + options: + source: *openstack-origin + to: + - '0' + - '1' + - '2' + + rabbitmq-server: + charm: cs:~openstack-charmers-next/rabbitmq-server + num_units: 1 + to: + - '3' + + keystone: + charm: cs:~openstack-charmers-next/keystone + num_units: 1 + options: + openstack-origin: *openstack-origin + to: + - '4' + + manila: + charm: cs:~openstack-charmers-next/manila + num_units: 1 + options: + openstack-origin: *openstack-origin + to: + - '5' + + openstack-dashboard: + charm: cs:~openstack-charmers-next/openstack-dashboard + num_units: 1 + options: + openstack-origin: *openstack-origin + to: + - '6' + + manila-dashboard: + charm: ../../../manila-dashboard + +relations: + + - - 'keystone:shared-db' + - 'keystone-mysql-router:shared-db' + - - 'keystone-mysql-router:db-router' + - 'mysql-innodb-cluster:db-router' + + - - 'manila:shared-db' + - 'manila-mysql-router:shared-db' + - - 'manila-mysql-router:db-router' + - 'mysql-innodb-cluster:db-router' + + - - 'manila:amqp' + - 'rabbitmq-server:amqp' + + - - 'manila:identity-service' + - 'keystone:identity-service' + + - - 'openstack-dashboard:shared-db' + - 'openstack-dashboard-mysql-router:shared-db' + - - 'openstack-dashboard-mysql-router:db-router' + - 'mysql-innodb-cluster:db-router' + + - - 'openstack-dashboard:identity-service' + - 'keystone:identity-service' + + - - 'openstack-dashboard:dashboard-plugin' + - 'manila-dashboard:dashboard' diff --git a/src/tests/tests.yaml b/src/tests/tests.yaml new file mode 100644 index 0000000..1c832f5 --- /dev/null +++ b/src/tests/tests.yaml @@ -0,0 +1,26 @@ +charm_name: manila-dashboard + +smoke_bundles: +- bionic-ussuri + +gate_bundles: +- bionic-train +- bionic-ussuri +- focal-ussuri +- focal-victoria +- groovy-victoria + +target_deploy_status: + manila: + workload-status: blocked + workload-status-message: No share backends configured + +configure: +- zaza.charm_tests.noop.setup.basic_setup + +tests: +- zaza.charm_tests.noop.tests.NoopTest + +tests_options: + force_deploy: + - groovy-victoria diff --git a/src/tox.ini b/src/tox.ini new file mode 100644 index 0000000..e763047 --- /dev/null +++ b/src/tox.ini @@ -0,0 +1,61 @@ +# 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 +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 +requires = pip < 20.3 + virtualenv < 20.0 +# NOTE: https://wiki.canonical.com/engineering/OpenStack/InstallLatestToxOnOsci +minversion = 3.2.0 + +[testenv] +setenv = VIRTUAL_ENV={envdir} + PYTHONHASHSEED=0 +whitelist_externals = juju +passenv = HOME TERM CS_* OS_* TEST_* +deps = -r{toxinidir}/test-requirements.txt +install_command = + pip install {opts} {packages} + +[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/src/wheelhouse.txt b/src/wheelhouse.txt new file mode 100644 index 0000000..44c8187 --- /dev/null +++ b/src/wheelhouse.txt @@ -0,0 +1,3 @@ +git+https://opendev.org/openstack/charms.openstack.git#egg=charms.openstack + +git+https://github.com/juju/charm-helpers.git#egg=charmhelpers diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000..3f08524 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,47 @@ +# 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 +# +setuptools<50.0.0 # https://github.com/pypa/setuptools/commit/04e3df22df840c6bb244e9b27bc56750c44b7c85 +# Lint and unit test requirements +flake8>=2.2.4 + +stestr>=2.2.0 + +# Dependency of stestr. Workaround for +# https://github.com/mtreinish/stestr/issues/145 +cliff<3.0.0 + +# Dependencies of stestr. Newer versions use keywords that didn't exist in +# python 3.5 yet (e.g. "ModuleNotFoundError") +importlib-metadata<3.0.0; python_version < '3.6' +importlib-resources<3.0.0; python_version < '3.6' + +# Some Zuul nodes sometimes pull newer versions of these dependencies which +# dropped support for python 3.5: +osprofiler<2.7.0;python_version<'3.6' +stevedore<1.31.0;python_version<'3.6' +debtcollector<1.22.0;python_version<'3.6' +oslo.utils<=3.41.0;python_version<'3.6' + +requests>=2.18.4 +charms.reactive + +# Newer mock seems to have some syntax which is newer than python3.5 (e.g. +# f'{something}' +mock>=1.2,<4.0.0; python_version < '3.6' +mock>=1.2; python_version >= '3.6' + +nose>=1.3.7 +coverage>=3.6 +git+https://github.com/openstack/charms.openstack.git#egg=charms.openstack +# +# Revisit for removal / mock improvement: +netifaces # vault +psycopg2-binary # vault +tenacity # vault +pbr # vault +cryptography # vault, keystone-saml-mellon +lxml # keystone-saml-mellon +hvac # vault, barbican-vault diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..c91922e --- /dev/null +++ b/tox.ini @@ -0,0 +1,97 @@ +# 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] +skipsdist = True +envlist = pep8,py3 +# 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] +setenv = VIRTUAL_ENV={envdir} + PYTHONHASHSEED=0 + TERM=linux + LAYER_PATH={toxinidir}/layers + INTERFACE_PATH={toxinidir}/interfaces + JUJU_REPOSITORY={toxinidir}/build +passenv = http_proxy https_proxy INTERFACE_PATH LAYER_PATH JUJU_REPOSITORY +install_command = + pip install {opts} {packages} +deps = + -r{toxinidir}/requirements.txt + +[testenv:build] +basepython = python3 +commands = + charm-build --log-level DEBUG -o {toxinidir}/build src {posargs} + +[testenv:py3] +basepython = python3 +deps = -r{toxinidir}/test-requirements.txt +commands = stestr run --slowest {posargs} + +[testenv:py35] +basepython = python3.5 +deps = -r{toxinidir}/test-requirements.txt +commands = stestr run --slowest {posargs} + +[testenv:py36] +basepython = python3.6 +deps = -r{toxinidir}/test-requirements.txt +commands = stestr run --slowest {posargs} + +[testenv:py37] +basepython = python3.7 +deps = -r{toxinidir}/test-requirements.txt +commands = stestr run --slowest {posargs} + +[testenv:py38] +basepython = python3.8 +deps = -r{toxinidir}/test-requirements.txt +commands = stestr run --slowest {posargs} + +[testenv:pep8] +basepython = python3 +deps = -r{toxinidir}/test-requirements.txt +commands = flake8 {posargs} src unit_tests + +[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 +setenv = + {[testenv]setenv} + PYTHON=coverage run +commands = + coverage erase + stestr run --slowest {posargs} + coverage combine + coverage html -d cover + coverage xml -o cover/coverage.xml + coverage report + +[coverage:run] +branch = True +concurrency = multiprocessing +parallel = True +source = + . +omit = + .tox/* + */charmhelpers/* + unit_tests/* + +[testenv:venv] +basepython = python3 +commands = {posargs} + +[flake8] +# E402 ignore necessary for path append before sys module import in actions +ignore = E402,W503,W504 diff --git a/unit_tests/__init__.py b/unit_tests/__init__.py new file mode 100644 index 0000000..b23b405 --- /dev/null +++ b/unit_tests/__init__.py @@ -0,0 +1,22 @@ +# Copyright 2021 Canonical Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys + +sys.path.append('src') +sys.path.append('src/lib') + +# Mock out charmhelpers so that we can test without it. +import charms_openstack.test_mocks # noqa +charms_openstack.test_mocks.mock_charmhelpers() diff --git a/unit_tests/test_manila_dashboard_handlers.py b/unit_tests/test_manila_dashboard_handlers.py new file mode 100644 index 0000000..7707662 --- /dev/null +++ b/unit_tests/test_manila_dashboard_handlers.py @@ -0,0 +1,62 @@ +# Copyright 2021 Canonical Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import mock + +import reactive.manila_dashboard_handlers as handlers + +import charms_openstack.test_utils as test_utils + + +class TestRegisteredHooks(test_utils.TestRegisteredHooks): + + def test_hooks(self): + defaults = [ + 'charm.installed', + 'config.changed', + 'update-status', + 'upgrade-charm'] + hook_set = { + 'when': { + 'dashboard_available': ( + 'dashboard.available',), + }, + } + # test that the hooks were registered via the + # reactive.barbican_handlers + self.registered_hooks_test_helper(handlers, hook_set, defaults) + + +class TestManilaDashboardHandlers(test_utils.PatchHelper): + + def setUp(self): + super().setUp() + self.manila_dashboard_charm = mock.MagicMock() + self.patch_object(handlers.charm, 'provide_charm_instance', + new=mock.MagicMock()) + self.provide_charm_instance().__enter__.return_value = \ + self.manila_dashboard_charm + self.provide_charm_instance().__exit__.return_value = None + self.patch('charms.reactive.endpoint_from_flag') + + def test_dashboard_available(self): + mock_flag = mock.Mock() + self.endpoint_from_flag.return_value = mock_flag + self.manila_dashboard_charm.purge_packages = ['n1'] + self.manila_dashboard_charm.packages = ['p1', 'p2'] + handlers.dashboard_available() + mock_flag.publish_plugin_info.assert_called_once_with( + "", None, conflicting_packages=['n1'], + install_packages=['p1', 'p2']) + self.manila_dashboard_charm.assess_status.assert_called_once_with()