Add charm code

This commit is contained in:
Ionut Balutoiu 2021-03-16 10:54:48 +02:00
parent d32b17f685
commit 43f18cb215
26 changed files with 942 additions and 2 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
.tox
.stestr
*__pycache__*
*.pyc
build

3
.stestr.conf Normal file
View File

@ -0,0 +1,3 @@
[DEFAULT]
test_path=./unit_tests
top_dir=./

View File

@ -1,2 +0,0 @@
# charm-manila-dashboard
Juju charm for the Manila dashboard plugin

1
README.md Symbolic link
View File

@ -0,0 +1 @@
src/README.md

26
requirements.txt Normal file
View File

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

17
src/README.md Normal file
View File

@ -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/).

17
src/layer.yaml Normal file
View File

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

0
src/lib/__init__.py Normal file
View File

View File

View File

View File

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

17
src/metadata.yaml Normal file
View File

@ -0,0 +1,17 @@
name: manila-dashboard
summary: Openstack Manila Dashboard
maintainer: OpenStack Charmers <openstack-charmers@lists.ubuntu.com>
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

0
src/reactive/__init__.py Normal file
View File

View File

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

15
src/test-requirements.txt Normal file
View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

26
src/tests/tests.yaml Normal file
View File

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

61
src/tox.ini Normal file
View File

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

3
src/wheelhouse.txt Normal file
View File

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

47
test-requirements.txt Normal file
View File

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

97
tox.ini Normal file
View File

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

22
unit_tests/__init__.py Normal file
View File

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

View File

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