df70e376ff
* Add sunbeam project template to run pep8, py3 tests * Add zuul.d/zuul.yaml to run pep8, py3, cover tests * Update charmcraft and requirements for each charm * Add global tox.ini to invoke fmt, pep8, py3, cover, build * Add gitreview file * Fix py3 test failures in ciner-ceph-k8s, glance-k8s, openstack-exporter * Add jobs for charm builds using files option so that job is invoked if files within the component are modified. Add charm builds to both check and gate pipeline. * Make function tests as part of global. Split the function tests into core, ceph, caas, misc mainly to accomodate function tests to run on 8GB. Add function tests as part of check pipeline. * Add zuul job to publish charms in promote pipeline Add charmhub token as secret that can be used to publish charms. Note: Charmhub token is generated with ttl of 90 days. * Run tox formatting * Make .gitignore, .jujuignore, .stestr.conf global and remove the files from all charms. * Make libs and templates global. Split libs to internal and external so that internal libs can adhere to sunbeam formatting styles. * Add script to copy common files necessary libs, config templates, stestr conf, jujuignore during py3 tests and charm builds. * Tests for keystone-ldap-k8s are commented due to intermittent bug LP#2045206 Change-Id: I804ca64182c109d16bd820ac00f129aa6dcf4496
145 lines
4.8 KiB
Python
145 lines
4.8 KiB
Python
#!/usr/bin/env python3
|
|
|
|
# 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.
|
|
|
|
"""Tests for gnocchi charm."""
|
|
|
|
import charm
|
|
import ops_sunbeam.test_utils as test_utils
|
|
from mock import (
|
|
patch,
|
|
)
|
|
|
|
|
|
class _GnocchiCephOperatorCharm(charm.GnocchiCephOperatorCharm):
|
|
def __init__(self, framework):
|
|
self.seen_events = []
|
|
super().__init__(framework)
|
|
|
|
def _log_event(self, event):
|
|
self.seen_events.append(type(event).__name__)
|
|
|
|
def configure_charm(self, event):
|
|
super().configure_charm(event)
|
|
self._log_event(event)
|
|
|
|
@property
|
|
def public_ingress_address(self):
|
|
return "gnocchi.juju"
|
|
|
|
|
|
class TestGnocchiCephOperatorCharm(test_utils.CharmTestCase):
|
|
"""Class for testing gnocchi charm."""
|
|
|
|
PATCHES = []
|
|
|
|
def setUp(self):
|
|
"""Run setup for unit tests."""
|
|
super().setUp(charm, self.PATCHES)
|
|
self.harness = test_utils.get_harness(
|
|
_GnocchiCephOperatorCharm, container_calls=self.container_calls
|
|
)
|
|
mock_get_platform = patch(
|
|
"charmhelpers.osplatform.get_platform", return_value="ubuntu"
|
|
)
|
|
mock_get_platform.start()
|
|
|
|
# clean up events that were dynamically defined,
|
|
# otherwise we get issues because they'll be redefined,
|
|
# which is not allowed.
|
|
from charms.data_platform_libs.v0.database_requires import (
|
|
DatabaseEvents,
|
|
)
|
|
|
|
for attr in (
|
|
"database_database_created",
|
|
"database_endpoints_changed",
|
|
"database_read_only_endpoints_changed",
|
|
):
|
|
try:
|
|
delattr(DatabaseEvents, attr)
|
|
except AttributeError:
|
|
pass
|
|
|
|
self.addCleanup(mock_get_platform.stop)
|
|
self.addCleanup(self.harness.cleanup)
|
|
test_utils.add_complete_ingress_relation(self.harness)
|
|
|
|
def test_pebble_ready_handler(self):
|
|
"""Test Pebble ready event is captured."""
|
|
self.harness.begin()
|
|
self.assertEqual(self.harness.charm.seen_events, [])
|
|
test_utils.set_all_pebbles_ready(self.harness)
|
|
self.assertEqual(len(self.harness.charm.seen_events), 2)
|
|
|
|
def test_all_relations(self):
|
|
"""Test all the charms relations."""
|
|
ceph_rel_id = self.harness.add_relation("ceph", "ceph-mon")
|
|
self.harness.begin_with_initial_hooks()
|
|
self.harness.add_relation_unit(ceph_rel_id, "ceph-mon/0")
|
|
self.harness.update_relation_data(
|
|
ceph_rel_id, "ceph-mon/0", {"ingress-address": "10.0.0.33"}
|
|
)
|
|
self.harness.add_relation("gnocchi-service", "ceilometer", app_data={})
|
|
test_utils.add_ceph_relation_credentials(self.harness, ceph_rel_id)
|
|
test_utils.add_db_relation_credentials(
|
|
self.harness, test_utils.add_base_db_relation(self.harness)
|
|
)
|
|
test_utils.add_identity_service_relation_response(
|
|
self.harness,
|
|
test_utils.add_base_identity_service_relation(self.harness),
|
|
)
|
|
|
|
self.harness.set_leader()
|
|
test_utils.set_all_pebbles_ready(self.harness)
|
|
ceph_install_cmds = [
|
|
[
|
|
"ceph-authtool",
|
|
"/etc/ceph/ceph.client.gnocchi-k8s.keyring",
|
|
"--create-keyring",
|
|
"--name=client.gnocchi-k8s",
|
|
"--add-key=AQBUfpVeNl7CHxAA8/f6WTcYFxW2dJ5VyvWmJg==",
|
|
],
|
|
[
|
|
"chown",
|
|
"gnocchi:gnocchi",
|
|
"/etc/ceph/ceph.client.gnocchi-k8s.keyring",
|
|
"/etc/ceph/rbdmap",
|
|
],
|
|
[
|
|
"chmod",
|
|
"640",
|
|
"/etc/ceph/ceph.client.gnocchi-k8s.keyring",
|
|
"/etc/ceph/rbdmap",
|
|
],
|
|
]
|
|
for cmd in ceph_install_cmds:
|
|
self.assertIn(cmd, self.container_calls.execute["gnocchi-api"])
|
|
|
|
app_setup_cmds = [
|
|
["a2dissite", "gnocchi-api"],
|
|
["a2ensite", "wsgi-gnocchi-api"],
|
|
["gnocchi-upgrade"],
|
|
]
|
|
for cmd in app_setup_cmds:
|
|
self.assertIn(cmd, self.container_calls.execute["gnocchi-api"])
|
|
|
|
for f in [
|
|
"/etc/gnocchi/gnocchi.conf",
|
|
"/etc/ceph/ceph.conf",
|
|
]:
|
|
self.check_file("gnocchi-api", f)
|
|
self.check_file("gnocchi-metricd", f)
|