From 150643f8c35a5370d592f8e2d681420c86743049 Mon Sep 17 00:00:00 2001 From: Chris MacNaughton Date: Thu, 31 Oct 2019 14:32:30 +0100 Subject: [PATCH] start adding some ducs and unit testing frameworking --- .stestr.conf | 3 + src/README.ex | 65 -------- src/README.md | 151 ++++++++++++++++++ src/lib/charm/openstack/manila_ganesha.py | 7 +- src/local_tests/manila/__init__.py | 0 src/local_tests/manila_ganesha/setup.py | 4 - src/local_tests/manila_ganesha/tests.py | 8 +- src/reactive/manila_ganesha.py | 9 +- .../manila/setup.py => unit_tests/__init__.py | 14 +- unit_tests/test_manila_ganesha_handlers.py | 62 +++++++ 10 files changed, 233 insertions(+), 90 deletions(-) create mode 100644 .stestr.conf delete mode 100644 src/README.ex create mode 100644 src/README.md delete mode 100644 src/local_tests/manila/__init__.py rename src/local_tests/manila/setup.py => unit_tests/__init__.py (63%) create mode 100644 unit_tests/test_manila_ganesha_handlers.py 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/src/README.ex b/src/README.ex deleted file mode 100644 index b6816b2..0000000 --- a/src/README.ex +++ /dev/null @@ -1,65 +0,0 @@ -# Overview - -Describe the intended usage of this charm and anything unique about how this -charm relates to others here. - -This README will be displayed in the Charm Store, it should be either Markdown -or RST. Ideal READMEs include instructions on how to use the charm, expected -usage, and charm features that your audience might be interested in. For an -example of a well written README check out Hadoop: -http://jujucharms.com/charms/precise/hadoop - -Use this as a Markdown reference if you need help with the formatting of this -README: http://askubuntu.com/editing-help - -This charm provides [service][]. Add a description here of what the service -itself actually does. - -Also remember to check the [icon guidelines][] so that your charm looks good -in the Juju GUI. - -# Usage - -Step by step instructions on using the charm: - -juju deploy servicename - -and so on. If you're providing a web service or something that the end user -needs to go to, tell them here, especially if you're deploying a service that -might listen to a non-default port. - -You can then browse to http://ip-address to configure the service. - -## Scale out Usage - -If the charm has any recommendations for running at scale, outline them in -examples here. For example if you have a memcached relation that improves -performance, mention it here. - -## Known Limitations and Issues - -This not only helps users but gives people a place to start if they want to help -you add features to your charm. - -# Configuration - -The configuration options will be listed on the charm store, however If you're -making assumptions or opinionated decisions in the charm (like setting a default -administrator password), you should detail that here so the user knows how to -change it immediately, etc. - -# Contact Information - -Though this will be listed in the charm store itself don't assume a user will -know that, so include that information here: - -## Upstream Project Name - - - Upstream website - - Upstream bug tracker - - Upstream mailing list or contact information - - Feel free to add things if it's useful for users - - -[service]: http://example.com -[icon guidelines]: https://jujucharms.com/docs/stable/authors-charm-icon diff --git a/src/README.md b/src/README.md new file mode 100644 index 0000000..ed4cc14 --- /dev/null +++ b/src/README.md @@ -0,0 +1,151 @@ +# Manila Ganesha + +This charm provides Ganesha with CephFS as a storage backend for Manila, OpenStack's shared filesystem service. + +# Usage + +Manila (plus manila-ganesha) relies on services from the mysql/percona, +rabbitmq-server, keystone charms, and a storage backend charm. The following +yaml file will create a small, unconfigured, OpenStack system with the +necessary components to start testing with Manila. Note that these target the +'next' OpenStack charms which are essentially 'edge' charms. + +```yaml +# Juju 2.0 deploy bundle for development ('next') charms +# UOSCI relies on this for OS-on-OS deployment testing +series: bionic +automatically-retry-hooks: False +services: + ceph-mon: + charm: cs:~openstack-charmers-next/ceph-mon + num_units: 3 + options: + source: *source + ceph-osd: + charm: cs:~openstack-charmers-next/ceph-osd + num_units: 3 + options: + source: *source + osd-devices: /dev/sdb + ceph-fs: + charm: cs:~openstack-charmers-next/ceph-fs + num_units: 2 + options: + source: *source + mysql: + charm: cs:~openstack-charmers-next/percona-cluster + num_units: 1 + constraints: mem=1G + options: + dataset-size: 50% + root-password: mysql + rabbitmq-server: + charm: cs:~openstack-charmers-next/rabbitmq-server + num_units: 1 + constraints: mem=1G + keystone: + charm: cs:~openstack-charmers-next/keystone + num_units: 1 + constraints: mem=1G + options: + admin-password: openstack + admin-token: ubuntutesting + preferred-api-version: "2" + glance: + charm: cs:~openstack-charmers-next/glance + num_units: 1 + constraints: mem=1G + nova-cloud-controller: + charm: cs:~openstack-charmers-next/nova-cloud-controller + num_units: 1 + constraints: mem=1G + options: + network-manager: Neutron + nova-compute: + charm: cs:~openstack-charmers-next/nova-compute + num_units: 1 + constraints: mem=4G + neutron-gateway: + charm: cs:~openstack-charmers-next/neutron-gateway + num_units: 1 + constraints: mem=1G + options: + bridge-mappings: physnet1:br-ex + instance-mtu: 1300 + neutron-api: + charm: cs:~openstack-charmers-next/neutron-api + num_units: 1 + constraints: mem=1G + options: + neutron-security-groups: True + flat-network-providers: physnet1 + neutron-openvswitch: + charm: cs:~openstack-charmers-next/neutron-openvswitch + cinder: + charm: cs:~openstack-charmers-next/cinder + num_units: 1 + constraints: mem=1G + options: + block-device: vdb + glance-api-version: 2 + overwrite: 'true' + ephemeral-unmount: /mnt + manila: + charm: cs:~openstack-charmers-next/manila + num_units: 1 + options: + debug: True + manila-ganesha: + charm: cs:~openstack-charmers-next/manila-ganesha + options: + debug: True +relations: + - [ ceph-mon, ceph-osd ] + - [ ceph-mon, ceph-fs ] + - [ ceph-mon, manila-ganesha ] + - [ keystone, mysql ] + - [ manila, mysql ] + - [ manila, rabbitmq-server ] + - [ manila, keystone ] + - [ manila, manila-generic ] + - [ glance, keystone] + - [ glance, mysql ] + - [ glance, "cinder:image-service" ] + - [ nova-compute, "rabbitmq-server:amqp" ] + - [ nova-compute, glance ] + - [ nova-cloud-controller, rabbitmq-server ] + - [ nova-cloud-controller, mysql ] + - [ nova-cloud-controller, keystone ] + - [ nova-cloud-controller, glance ] + - [ nova-cloud-controller, nova-compute ] + - [ cinder, keystone ] + - [ cinder, mysql ] + - [ cinder, rabbitmq-server ] + - [ cinder, nova-cloud-controller ] + - [ "neutron-gateway:amqp", "rabbitmq-server:amqp" ] + - [ neutron-gateway, nova-cloud-controller ] + - [ neutron-api, mysql ] + - [ neutron-api, rabbitmq-server ] + - [ neutron-api, nova-cloud-controller ] + - [ neutron-api, neutron-openvswitch ] + - [ neutron-api, keystone ] + - [ neutron-api, neutron-gateway ] + - [ neutron-openvswitch, nova-compute ] + - [ neutron-openvswitch, rabbitmq-server ] + - [ neutron-openvswitch, manila ] +``` + +and then (with juju 2.x): + +```bash + juju deploy manila.yaml +``` + +Note that this OpenStack system will need to be configured (in terms of +networking, images, etc.) before testing can commence. + +# Bugs + +Please report bugs on [Launchpad](https://bugs.launchpad.net/charm-manila-ganesha/+filebug). + +For general questions please refer to the OpenStack [Charm Guide](https://github.com/openstack/charm-guide). diff --git a/src/lib/charm/openstack/manila_ganesha.py b/src/lib/charm/openstack/manila_ganesha.py index 97aa2b6..f608277 100644 --- a/src/lib/charm/openstack/manila_ganesha.py +++ b/src/lib/charm/openstack/manila_ganesha.py @@ -15,9 +15,6 @@ import collections import json -# import socket -import subprocess - # import charms.reactive as reactive import charms_openstack.charm @@ -27,7 +24,6 @@ from charms_openstack.ip import resolve_address from charmhelpers.core.hookenv import log from charmhelpers.contrib.storage.linux.ceph import ( CephBrokerRq, - is_request_complete, send_request_if_needed, ) # import charmhelpers.core as ch_core @@ -49,7 +45,6 @@ CEPH_CAPABILITIES = [ "allow command \"auth get-or-create\""] - @charms_openstack.adapters.config_property def access_ip(config): """Return the list of lines from the backends that need to go into the @@ -68,7 +63,7 @@ def use_memcache(config): class KeystoneCredentialAdapter( - charms_openstack.adapters.OpenStackRelationAdapter): + charms_openstack.adapters.OpenStackRelationAdapter): """Modifies the keystone-credentials interface to act like keystone.""" def __init__(self, relation): diff --git a/src/local_tests/manila/__init__.py b/src/local_tests/manila/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/local_tests/manila_ganesha/setup.py b/src/local_tests/manila_ganesha/setup.py index 878cf6e..66f1392 100644 --- a/src/local_tests/manila_ganesha/setup.py +++ b/src/local_tests/manila_ganesha/setup.py @@ -1,11 +1,7 @@ -import logging import zaza.openstack.utilities.openstack as openstack_utils from manilaclient import client as manilaclient -def noop(): - """Run setup.""" - logging.info('OK') def setup_ganesha_share_type(manila_client=None): if manila_client is None: diff --git a/src/local_tests/manila_ganesha/tests.py b/src/local_tests/manila_ganesha/tests.py index 8beb803..0a966f4 100644 --- a/src/local_tests/manila_ganesha/tests.py +++ b/src/local_tests/manila_ganesha/tests.py @@ -16,11 +16,8 @@ """Encapsulate Manila Ganesha testing.""" -import logging - from manilaclient import client as manilaclient -import zaza.model import zaza.openstack.charm_tests.glance.setup as glance_setup import zaza.openstack.charm_tests.neutron.tests as neutron_tests import zaza.openstack.charm_tests.nova.utils as nova_utils @@ -42,7 +39,6 @@ class ManilaGaneshaTests(test_utils.OpenStackBaseTest): cls.manila_client = manilaclient.Client( session=cls.keystone_session, client_version='2') - def test_manila_share(self): """Test that Manila + Ganesha shares can be accessed on two instances. @@ -104,7 +100,7 @@ class ManilaGaneshaTests(test_utils.OpenStackBaseTest): 'sudo apt install -yq nfs-common && ' 'sudo /bin/mkdir -p /mnt/ceph && ' 'sudo /bin/mount -t nfs -o nfsvers=4.1,proto=tcp {} /mnt/ceph' - .format(mount_path), + .format(mount_path), password=password, privkey=privkey, verify=verify_setup) def verify(stdin, stdout, stderr): @@ -122,5 +118,3 @@ class ManilaGaneshaTests(test_utils.OpenStackBaseTest): 'sudo cat /mnt/ceph/test'.format( mount_path), password=password, privkey=privkey, verify=verify) - - diff --git a/src/reactive/manila_ganesha.py b/src/reactive/manila_ganesha.py index 294c266..df34cdf 100644 --- a/src/reactive/manila_ganesha.py +++ b/src/reactive/manila_ganesha.py @@ -7,6 +7,7 @@ import charms_openstack.charm as charm import charms.reactive.relations as relations import charmhelpers.core as ch_core +from charmhelpers.core.hookenv import log charms_openstack.bus.discover() @@ -31,6 +32,7 @@ def ceph_connected(ceph): with charm.provide_charm_instance() as charm_instance: charm_instance.request_ceph_permissions(ceph) + @reactive.when('manila-plugin.available') def setup_manila(): manila_relation = relations.endpoint_from_flag('manila-plugin.available') @@ -39,6 +41,7 @@ def setup_manila(): 'complete': True, } + @reactive.when_not('identity-service.available') @reactive.when('identity-service.connected') def configure_ident_username(keystone): @@ -80,7 +83,7 @@ def render_things(*args): @reactive.when_all('config.rendered', 'ceph.pools.available') -@reactive.when_not('ganesha_pool_configured') +@reactive.when_not('ganesha-pool-configured') def configure_ganesha(*args): cmd = [ 'rados', '-p', 'manila-ganesha', '--id', 'manila-ganesha', @@ -88,6 +91,6 @@ def configure_ganesha(*args): ] try: subprocess.check_call(cmd) - reactive.set_flag('ganesha_pool_configured') + reactive.set_flag('ganesha-pool-configured') except subprocess.CalledProcessError: - log("Failed to setup ganesha index object") \ No newline at end of file + log("Failed to setup ganesha index object") diff --git a/src/local_tests/manila/setup.py b/unit_tests/__init__.py similarity index 63% rename from src/local_tests/manila/setup.py rename to unit_tests/__init__.py index 82cb11f..0df0b6a 100644 --- a/src/local_tests/manila/setup.py +++ b/unit_tests/__init__.py @@ -1,12 +1,10 @@ -#!/usr/bin/env python3 - -# Copyright 2019 Canonical Ltd. +# Copyright 2019 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 +# 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, @@ -14,5 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""Encapdulate manila setup tasks.""" +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_ganesha_handlers.py b/unit_tests/test_manila_ganesha_handlers.py new file mode 100644 index 0000000..abf0102 --- /dev/null +++ b/unit_tests/test_manila_ganesha_handlers.py @@ -0,0 +1,62 @@ +# Copyright 2018 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. + +from __future__ import absolute_import +from __future__ import print_function + +# import json +# import mock + +# import charm.openstack.manila_ganesha as manila_ganesha +import reactive.manila_ganesha as handlers + +import charms_openstack.test_utils as test_utils + + +class TestRegisteredHooks(test_utils.TestRegisteredHooks): + + def test_hooks(self): + defaults = [ + 'charm.installed', + 'amqp.connected', + 'shared-db.connected', + 'config.changed', + 'update-status', + 'upgrade-charm', + 'certificates.available', + ] + hook_set = { + 'when': { + 'ceph_connected': ('ceph.connected',), + 'setup_manila': ('manila-plugin.available',), + 'configure_ident_username': ('identity-service.connected',), + 'render_things': ('ceph.available', + 'amqp.available', + 'manila-plugin.available', + 'shared-db.available', + 'identity-service.available'), + }, + 'when_not': { + 'ceph_connected': ('ceph.available',), + 'configure_ident_username': ('identity-service.available',), + 'configure_ganesha': ('ganesha-pool-configured',), + }, + 'when_all': { + 'configure_ganesha': ('config.rendered', + 'ceph.pools.available',), + } + } + # test that the hooks were registered via the + # reactive.manila_ganesha_handlers + self.registered_hooks_test_helper(handlers, hook_set, defaults)