start adding some ducs and unit testing frameworking

This commit is contained in:
Chris MacNaughton 2019-10-31 14:32:30 +01:00
parent f877c118dd
commit 150643f8c3
10 changed files with 233 additions and 90 deletions

3
.stestr.conf Normal file
View File

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

View File

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

151
src/README.md Normal file
View File

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

View File

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

View File

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

View File

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

View File

@ -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")
log("Failed to setup ganesha index object")

View File

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

View File

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