Initialize repository
This adds the source files for the CloudKitty charm for queens and rocky releases. Change-Id: I7f497a8b72d16f4b40575e8b64278ec0da909891 story: 2004199
This commit is contained in:
parent
6cb7be7399
commit
6642a19fe9
11
.gitignore
vendored
Normal file
11
.gitignore
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
build
|
||||
layers
|
||||
.tox
|
||||
interfaces
|
||||
builds
|
||||
deps
|
||||
.testrepository
|
||||
__pycache__
|
||||
*.pyc
|
||||
.stestr
|
||||
/.vs
|
8
.testr.conf
Normal file
8
.testr.conf
Normal file
@ -0,0 +1,8 @@
|
||||
[DEFAULT]
|
||||
test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \
|
||||
OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \
|
||||
OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-60} \
|
||||
${PYTHON:-python} -m subunit.run discover -t ./ ./unit_tests $LISTOPT $IDOPTION
|
||||
|
||||
test_id_option=--load-list $IDFILE
|
||||
test_list_option=--list
|
201
LICENSE
Normal file
201
LICENSE
Normal file
@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright {yyyy} {name of copyright owner}
|
||||
|
||||
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.
|
4
requirements.txt
Normal file
4
requirements.txt
Normal file
@ -0,0 +1,4 @@
|
||||
# Requirements to build the charm
|
||||
charm-tools
|
||||
simplejson
|
||||
flake8
|
38
src/README.md
Normal file
38
src/README.md
Normal file
@ -0,0 +1,38 @@
|
||||
# Overview
|
||||
|
||||
CloudKitty is a Rating-as-a-Service project for OpenStack and more.
|
||||
The project aims at being a generic solution for the chargeback and rating
|
||||
of a cloud.
|
||||
|
||||
# Usage
|
||||
|
||||
This charm provides Cloudkitty (Rating as a Service) for an OpenStack Cloud,
|
||||
using Gnocchi as metrics collector:
|
||||
|
||||
juju deploy ./cloudkitty cloudkitty
|
||||
|
||||
At the moment only works with objectif ppa for install sources:
|
||||
|
||||
juju config cloudkitty install_sources="ppa:objectif-libre/cloudkitty-queens"
|
||||
|
||||
Set storage-backend, SQLalchemy is being the recommended one in cloudkitty docs
|
||||
|
||||
juju config cloudkitty storage-backend=sqlalchemy
|
||||
|
||||
Add the charm relations:
|
||||
|
||||
juju add-relation cloudkitty mysql
|
||||
juju add-relation cloudkitty keystone
|
||||
juju add-relation cloudkitty rabbitmq-server
|
||||
juju add-relation cloudkitty gnocchi
|
||||
|
||||
For Rocky deploy use:
|
||||
|
||||
juju config cloudkitty install_sources="ppa:objectif-libre/cloudkitty-rocky"
|
||||
juju config cloudkitty openstack-origin=cloud:bionic-rocky
|
||||
|
||||
For advanced metrics configuration is possible to use a charm resource to upload
|
||||
the yaml config file:
|
||||
|
||||
juju attach-resource cloudkitty custom_metrics=custom.yml
|
||||
juju config cloudkitty custom-metrics=true
|
24
src/config.yaml
Normal file
24
src/config.yaml
Normal file
@ -0,0 +1,24 @@
|
||||
options:
|
||||
collector-period:
|
||||
default: 3600
|
||||
type: int
|
||||
description: Period to collect metrics
|
||||
collector-wait-periods:
|
||||
default: 2
|
||||
type: int
|
||||
description: Number of periods before processing metrics
|
||||
storage-backend:
|
||||
default:
|
||||
type: string
|
||||
description: |
|
||||
Define the storage backend.
|
||||
.
|
||||
Supported values are 'sqlalchemy' and 'hybrid', for v1
|
||||
storage-backend-version:
|
||||
default: 1
|
||||
type: int
|
||||
description: Define the storage backend version, v2 is still in testing
|
||||
custom-metrics:
|
||||
default: false
|
||||
type: boolean
|
||||
description: If true use custom_metrics charm resource as metrics yaml
|
16
src/copyright
Normal file
16
src/copyright
Normal file
@ -0,0 +1,16 @@
|
||||
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0
|
||||
|
||||
Files: *
|
||||
Copyright: 2012, Canonical Ltd.
|
||||
License: Apache-2.0
|
||||
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.See the LICENSE file in the root directory.
|
13
src/layer.yaml
Normal file
13
src/layer.yaml
Normal file
@ -0,0 +1,13 @@
|
||||
includes:
|
||||
- layer:openstack-api
|
||||
- layer:apt
|
||||
- interface:mysql-shared
|
||||
- interface:rabbitmq
|
||||
- interface:gnocchi
|
||||
|
||||
includes: ['layer:openstack-api','layer:apt','interface:gnocchi']
|
||||
options:
|
||||
basic:
|
||||
use_venv: True
|
||||
include_system_packages: True
|
||||
repo: https://github.com/openstack/charm-cloudkitty.git
|
0
src/lib/charm/__init__.py
Normal file
0
src/lib/charm/__init__.py
Normal file
0
src/lib/charm/openstack/__init__.py
Normal file
0
src/lib/charm/openstack/__init__.py
Normal file
226
src/lib/charm/openstack/cloudkitty.py
Normal file
226
src/lib/charm/openstack/cloudkitty.py
Normal file
@ -0,0 +1,226 @@
|
||||
# Copyright 2019 Jalasoft
|
||||
#
|
||||
# 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 os
|
||||
import glob
|
||||
import collections
|
||||
import subprocess
|
||||
|
||||
import charmhelpers.core.host as host
|
||||
import charmhelpers.core.hookenv as hookenv
|
||||
|
||||
import charms_openstack.charm
|
||||
import charms_openstack.adapters as adapters
|
||||
import charms_openstack.ip as os_ip
|
||||
import charms.reactive as reactive
|
||||
|
||||
|
||||
CLOUDKITTY_DIR = '/etc/cloudkitty'
|
||||
CLOUDKITTY_CONF = os.path.join(CLOUDKITTY_DIR, 'cloudkitty.conf')
|
||||
CLOUDKITTY_METRICS = os.path.join(CLOUDKITTY_DIR, 'metrics.yml')
|
||||
CLOUDKITTY_CUSTOM_METRICS = os.path.join(CLOUDKITTY_DIR, 'custom_metrics.yml')
|
||||
CLOUDKITTY_WEBSERVER_SITE = 'cloudkitty-api'
|
||||
CLOUDKITTY_WSGI_CONF = '/etc/apache2/sites-available/{}.conf'.format(
|
||||
CLOUDKITTY_WEBSERVER_SITE)
|
||||
CLOUDKITTY_WWW_DIR = '/var/www/cloudkitty'
|
||||
CLOUDKITTY_WSGI_APP = os.path.join(CLOUDKITTY_WWW_DIR, 'app.wsgi')
|
||||
CLOUDKITTY_ROLES = ['rating']
|
||||
charms_openstack.charm.use_defaults('charm.default-select-package-type')
|
||||
charms_openstack.charm.use_defaults('charm.default-select-release')
|
||||
|
||||
|
||||
class MetricServiceRelationAdapter(adapters.OpenStackRelationAdapter):
|
||||
"""Adapter for the gnocchi metric relation interface."""
|
||||
|
||||
interface_type = "gnocchi"
|
||||
|
||||
@property
|
||||
def gnocchi_url(self):
|
||||
"""Gnocchi url."""
|
||||
return self.relation.gnocchi_url()
|
||||
|
||||
|
||||
class CloudkittyCharmRelationAdapters(adapters.OpenStackAPIRelationAdapters):
|
||||
"""Adapters class for the Cloudkitty charm."""
|
||||
|
||||
relation_adapters = {
|
||||
'shared_db': adapters.DatabaseRelationAdapter,
|
||||
'amqp': adapters.RabbitMQRelationAdapter,
|
||||
'cluster': adapters.PeerHARelationAdapter,
|
||||
'metric_service': MetricServiceRelationAdapter,
|
||||
}
|
||||
|
||||
|
||||
class CloudkittyCharmBase(charms_openstack.charm.HAOpenStackCharm):
|
||||
"""Base class for shared charm function."""
|
||||
|
||||
abstract_class = True
|
||||
service_name = name = 'cloudkitty'
|
||||
default_service = 'cloudkitty-api'
|
||||
service_type = 'cloudkitty'
|
||||
|
||||
api_ports = {
|
||||
'cloudkitty-api': {
|
||||
os_ip.PUBLIC: 8889,
|
||||
os_ip.ADMIN: 8889,
|
||||
os_ip.INTERNAL: 8889,
|
||||
}
|
||||
}
|
||||
|
||||
required_relations = ['shared-db',
|
||||
'amqp',
|
||||
'identity-service',
|
||||
'metric-service']
|
||||
|
||||
ha_resources = ['vips', 'haproxy', 'dnsha']
|
||||
|
||||
adapters_class = CloudkittyCharmRelationAdapters
|
||||
|
||||
def enable_webserver_site(self):
|
||||
"""Enable Cloudkitty Webserver sites if rendered or installed."""
|
||||
pass
|
||||
|
||||
def setup_storage(self):
|
||||
"""Perform the Cloudkitty storage setup."""
|
||||
subprocess.check_call(['cloudkitty-storage-init'])
|
||||
|
||||
def get_amqp_credentials(self):
|
||||
"""Configure the AMQP credentials for Cloudkitty."""
|
||||
return ('cloudkitty', 'cloudkitty')
|
||||
|
||||
def get_database_setup(self):
|
||||
"""Configure the database credentials for Cloudkitty."""
|
||||
return [{
|
||||
'database': 'cloudkitty',
|
||||
'username': 'cloudkitty',
|
||||
'hostname': hookenv.unit_private_ip()}, ]
|
||||
|
||||
def disable_services(self):
|
||||
"""Disable all services related to cloudkitty."""
|
||||
for svc in self.services:
|
||||
host.service_pause(svc)
|
||||
|
||||
def enable_services(self):
|
||||
"""Enable all services related to cloudkitty."""
|
||||
for svc in self.services:
|
||||
host.service_resume(svc)
|
||||
|
||||
def reload_services(self):
|
||||
"""Enable all services related to cloudkitty."""
|
||||
for svc in self.services:
|
||||
host.service_reload(svc)
|
||||
|
||||
@property
|
||||
def cloudkitty_user(self):
|
||||
"""Determine cloudkitty user.
|
||||
|
||||
Processes will run as:return string: user for cloudkitty processes
|
||||
"""
|
||||
return self.user
|
||||
|
||||
@property
|
||||
def cloudkitty_group(self):
|
||||
"""Determine cloudkitty group.
|
||||
|
||||
processes will run as:return string: group for cloudkitty processes
|
||||
"""
|
||||
return self.group
|
||||
|
||||
|
||||
class CloudkittyCharm(CloudkittyCharmBase):
|
||||
"""Charm for Juju deployment of Cloudkitty."""
|
||||
|
||||
# First release supported
|
||||
release = 'queens'
|
||||
# Deb package type
|
||||
package_type = 'deb'
|
||||
|
||||
# List of packages to install for this charm
|
||||
packages = ['cloudkitty-api',
|
||||
'cloudkitty-processor',
|
||||
'python-cloudkitty',
|
||||
'python-apt',
|
||||
'python-keystonemiddleware',
|
||||
'apache2',
|
||||
'libapache2-mod-wsgi']
|
||||
|
||||
services = ['cloudkitty-processor', 'apache2']
|
||||
|
||||
restart_map = {
|
||||
CLOUDKITTY_CONF: services,
|
||||
CLOUDKITTY_WSGI_CONF: ['apache2']
|
||||
}
|
||||
|
||||
release_pkg = 'cloudkitty-common'
|
||||
|
||||
package_codenames = {
|
||||
'cloudkitty-common': collections.OrderedDict([
|
||||
('2', 'mitaka'),
|
||||
('3', 'newton'),
|
||||
('4', 'ocata'),
|
||||
('5', 'pike'),
|
||||
('6', 'queens'),
|
||||
('7', 'rocky'),
|
||||
('8', 'stein'),
|
||||
]),
|
||||
}
|
||||
|
||||
sync_cmd = ['cloudkitty-dbsync',
|
||||
'--config-file',
|
||||
'/etc/cloudkitty/cloudkitty.conf',
|
||||
'upgrade']
|
||||
|
||||
# User and group for permissions management
|
||||
user = 'cloudkitty'
|
||||
group = 'cloudkitty'
|
||||
|
||||
def install(self):
|
||||
"""Install function."""
|
||||
super(CloudkittyCharm, self).install()
|
||||
host.service_pause('cloudkitty-api')
|
||||
|
||||
def enable_webserver_site(self):
|
||||
"""Enable Cloudkitty API apache2 site if rendered or installed."""
|
||||
if not os.path.isdir(CLOUDKITTY_WWW_DIR):
|
||||
host.mkdir(CLOUDKITTY_WWW_DIR)
|
||||
wsgi_search_path = '/var/lib/juju/*/unit-cloudkitty-*/*/*/app.wsgi'
|
||||
cloudkitty_wsgi_app_src = glob.glob(wsgi_search_path)[0]
|
||||
if os.path.exists(cloudkitty_wsgi_app_src):
|
||||
subprocess.call(
|
||||
['cp', cloudkitty_wsgi_app_src, CLOUDKITTY_WSGI_APP]
|
||||
)
|
||||
if (os.path.exists(CLOUDKITTY_WSGI_CONF)
|
||||
and os.path.exists(CLOUDKITTY_WSGI_APP)):
|
||||
check_enabled = subprocess.call(
|
||||
['a2query', '-s', CLOUDKITTY_WEBSERVER_SITE]
|
||||
)
|
||||
if check_enabled != 0:
|
||||
subprocess.check_call(['a2ensite',
|
||||
CLOUDKITTY_WEBSERVER_SITE])
|
||||
host.service_reload('apache2',
|
||||
restart_on_failure=True)
|
||||
|
||||
def enable_custom_metrics(self):
|
||||
"""Enable custom metrics if charm resource is available."""
|
||||
if not reactive.is_flag_set('config.default.custom-metrics'):
|
||||
custom_metrics_file = hookenv.resource_get('custom_metrics')
|
||||
hookenv.log('Retreived resource: {}'.format(custom_metrics_file))
|
||||
if custom_metrics_file:
|
||||
subprocess.call(
|
||||
['cp', custom_metrics_file, CLOUDKITTY_CUSTOM_METRICS]
|
||||
)
|
||||
host.chownr(CLOUDKITTY_CUSTOM_METRICS,
|
||||
self.user,
|
||||
self.group,
|
||||
chowntopdir=True)
|
33
src/metadata.yaml
Normal file
33
src/metadata.yaml
Normal file
@ -0,0 +1,33 @@
|
||||
name: cloudkitty
|
||||
summary: Cloudkitty provides rating services for OpenStack
|
||||
maintainer: jala <hugo.santacruz@jalasoft.com>
|
||||
description: |
|
||||
Cloudkitty is Rating as a Service for OpenStack.
|
||||
OpenStack Queens or later is required.
|
||||
tags:
|
||||
- openstack
|
||||
- rating
|
||||
series:
|
||||
- xenial
|
||||
- bionic
|
||||
- cosmic
|
||||
- disco
|
||||
subordinate: false
|
||||
requires:
|
||||
ha:
|
||||
interface: hacluster
|
||||
scope: container
|
||||
amqp:
|
||||
interface: rabbitmq
|
||||
identity-service:
|
||||
interface: keystone
|
||||
metric-service:
|
||||
interface: gnocchi
|
||||
peers:
|
||||
cluster:
|
||||
interface: openstack-ha
|
||||
resources:
|
||||
custom_metrics:
|
||||
type: file
|
||||
filename: custom_metrics.yml
|
||||
description: "Yaml file used for configure custom metrics"
|
97
src/reactive/cloudkitty_handlers.py
Normal file
97
src/reactive/cloudkitty_handlers.py
Normal file
@ -0,0 +1,97 @@
|
||||
# Copyright 2019 Jalasoft
|
||||
#
|
||||
# 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.charm as charm
|
||||
import charms.reactive as reactive
|
||||
import charm.openstack.cloudkitty as cloudkitty
|
||||
import charmhelpers.core.hookenv as hookenv
|
||||
|
||||
charm.use_defaults(
|
||||
'charm.installed',
|
||||
'shared-db.connected',
|
||||
'amqp.connected',
|
||||
'identity-service.available',
|
||||
'config.changed',
|
||||
'update-status',
|
||||
'upgrade-charm')
|
||||
|
||||
required_interfaces = ['shared-db.available',
|
||||
'identity-service.available',
|
||||
'amqp.available',
|
||||
'metric-service.available']
|
||||
|
||||
|
||||
@reactive.when_not_all(*required_interfaces)
|
||||
def disable_services():
|
||||
"""Disable services based on any of the required states not being set."""
|
||||
with charm.provide_charm_instance() as charm_class:
|
||||
charm_class.disable_services()
|
||||
|
||||
|
||||
@reactive.when('identity-service.connected')
|
||||
def setup_endpoint_connection(keystone):
|
||||
"""Register endpoint function for Cloudkitty.
|
||||
|
||||
Cloudkitty needs a rating role
|
||||
"""
|
||||
with charm.provide_charm_instance() as charm_class:
|
||||
roles = cloudkitty.CLOUDKITTY_ROLES
|
||||
keystone.register_endpoints(charm_class.service_type,
|
||||
charm_class.region,
|
||||
charm_class.public_url,
|
||||
charm_class.internal_url,
|
||||
charm_class.admin_url,
|
||||
requested_roles=roles)
|
||||
charm_class.assess_status()
|
||||
|
||||
|
||||
@reactive.when(*required_interfaces)
|
||||
def render_config(*args):
|
||||
"""Render the configuration.
|
||||
|
||||
Render the configuration for Cloudkitty charm when all the
|
||||
interfaces are available.
|
||||
"""
|
||||
with charm.provide_charm_instance() as charm_class:
|
||||
charm_class.upgrade_if_available(args)
|
||||
charm_class.configure_ssl()
|
||||
charm_class.enable_custom_metrics()
|
||||
charm_class.enable_services()
|
||||
charm_class.render_with_interfaces(args)
|
||||
charm_class.enable_webserver_site()
|
||||
charm_class.assess_status()
|
||||
hookenv.log("Configuration rendered", hookenv.DEBUG)
|
||||
reactive.set_state('config.rendered')
|
||||
|
||||
|
||||
# db_sync checks if sync has been done so rerunning is a noop
|
||||
@reactive.when('config.rendered')
|
||||
@reactive.when_not('db.synced')
|
||||
def init_db():
|
||||
"""Run initial DB migrations when config is rendered."""
|
||||
with charm.provide_charm_instance() as charm_class:
|
||||
charm_class.db_sync()
|
||||
charm_class.setup_storage()
|
||||
charm_class.reload_services()
|
||||
hookenv.log("Database synced", hookenv.DEBUG)
|
||||
reactive.set_state('db.synced')
|
||||
|
||||
|
||||
@reactive.when('ha.connected')
|
||||
@reactive.when_not('ha.available')
|
||||
def cluster_connected(hacluster):
|
||||
"""Configure HA resources in corosync."""
|
||||
with charm.provide_charm_instance() as charm_class:
|
||||
charm_class.configure_ha_resources(hacluster)
|
||||
charm_class.assess_status()
|
2
src/requirements.txt
Normal file
2
src/requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
flake8
|
||||
pytest
|
25
src/templates/cloudkitty-api.conf
Normal file
25
src/templates/cloudkitty-api.conf
Normal file
@ -0,0 +1,25 @@
|
||||
###############################################################################
|
||||
# [ WARNING ]
|
||||
# configuration file maintained by Juju
|
||||
# local changes will be overwritten.
|
||||
###############################################################################
|
||||
|
||||
Listen {{ options.service_listen_info.cloudkitty_api.public_port }}
|
||||
|
||||
<VirtualHost *:{{ options.service_listen_info.cloudkitty_api.public_port }}>
|
||||
WSGIDaemonProcess cloudkitty-api processes={{ options.wsgi_worker_context.processes }} threads=10 user=cloudkitty group=cloudkitty display-name=%{GROUP}
|
||||
WSGIProcessGroup cloudkitty-api
|
||||
WSGIScriptAlias / /var/www/cloudkitty/app.wsgi
|
||||
WSGIApplicationGroup %{GLOBAL}
|
||||
<Directory /var/www/cloudkitty>
|
||||
<IfVersion >= 2.4>
|
||||
Require all granted
|
||||
</IfVersion>
|
||||
<IfVersion < 2.4>
|
||||
Order allow,deny
|
||||
Allow from all
|
||||
</IfVersion>
|
||||
</Directory>
|
||||
ErrorLog /var/log/apache2/cloudkitty_error.log
|
||||
CustomLog /var/log/apache2/cloudkitty_access.log combined
|
||||
</VirtualHost>
|
63
src/templates/queens/cloudkitty.conf
Normal file
63
src/templates/queens/cloudkitty.conf
Normal file
@ -0,0 +1,63 @@
|
||||
###############################################################################
|
||||
# [ WARNING ]
|
||||
# configuration file maintained by Juju
|
||||
# local changes will be overwritten.
|
||||
###############################################################################
|
||||
|
||||
[DEFAULT]
|
||||
verbose = True
|
||||
debug = {{ options.debug }}
|
||||
auth_strategy = keystone
|
||||
{% include "parts/section-transport-url" %}
|
||||
|
||||
[ks_auth]
|
||||
auth_type = v3password
|
||||
auth_protocol = {{ identity_service.auth_protocol }}
|
||||
auth_url = {{ identity_service.service_protocol }}://{{ identity_service.service_host }}:{{ identity_service.service_port }}/v3
|
||||
identity_uri = {{ identity_service.auth_protocol }}://{{ identity_service.auth_host }}:{{ identity_service.auth_port }}/v3
|
||||
username = {{ identity_service.service_username }}
|
||||
password = {{ identity_service.service_password }}
|
||||
project_name = services
|
||||
user_domain_name = service_domain
|
||||
project_domain_name = service_domain
|
||||
debug = True
|
||||
|
||||
[keystone_authtoken]
|
||||
auth_section = ks_auth
|
||||
|
||||
{% if identity_service.signing_dir -%}
|
||||
signing_dir = {{ identity_service.signing_dir }}
|
||||
{% endif -%}
|
||||
{% if options.use_memcache == true -%}
|
||||
memcached_servers = {{ options.memcache_url }}
|
||||
{% endif -%}
|
||||
|
||||
|
||||
|
||||
[database]
|
||||
connection = {{ shared_db.type }}+pymysql://{{ shared_db.username }}:{{ shared_db.password }}@{{ shared_db.host }}/{{ shared_db.database }}{% if database_ssl_ca %}?ssl_ca={{ database_ssl_ca }}{% if database_ssl_cert %}&ssl_cert={{ database_ssl_cert }}&ssl_key={{ database_ssl_key }}{% endif %}{% endif %}
|
||||
|
||||
|
||||
[storage]
|
||||
backend = {{ options.storage_backend }}
|
||||
|
||||
[storage_gnocchi]
|
||||
auth_section = ks_auth
|
||||
|
||||
[collect]
|
||||
{%- if options.custom_metrics %}
|
||||
metrics_conf = /etc/cloudkitty/custom_metrics.yml
|
||||
{%- else %}
|
||||
metrics_conf = /etc/cloudkitty/metrics.yml
|
||||
{%- endif %}
|
||||
|
||||
|
||||
[gnocchi_collector]
|
||||
auth_section = ks_auth
|
||||
|
||||
[tenant_fetcher]
|
||||
backend = keystone
|
||||
|
||||
[keystone_fetcher]
|
||||
auth_section = ks_auth
|
||||
keystone_version = 3
|
70
src/templates/queens/metrics.yml
Normal file
70
src/templates/queens/metrics.yml
Normal file
@ -0,0 +1,70 @@
|
||||
- name: OpenStack
|
||||
|
||||
collector: gnocchi
|
||||
{% if options.collector_period %}
|
||||
period = {{ options.collector_period }}
|
||||
{% endif %}
|
||||
wait_periods: {{ options.collector_wait_periods }}
|
||||
window: 1800
|
||||
|
||||
services:
|
||||
- compute
|
||||
- volume
|
||||
- network.bw.in
|
||||
- network.bw.out
|
||||
- network.floating
|
||||
- image
|
||||
|
||||
services_objects:
|
||||
compute: instance
|
||||
volume: volume
|
||||
network.bw.out: instance_network_interface
|
||||
network.bw.in: instance_network_interface
|
||||
network.floating: network
|
||||
image: image
|
||||
|
||||
services_metrics:
|
||||
compute:
|
||||
- vcpus: max
|
||||
- memory: max
|
||||
- cpu: max
|
||||
- disk.root.size: max
|
||||
- disk.ephemeral.size: max
|
||||
volume:
|
||||
- volume.size: max
|
||||
network.bw.in:
|
||||
- network.incoming.bytes: max
|
||||
network.bw.out:
|
||||
- network.outgoing.bytes: max
|
||||
network.floating:
|
||||
- ip.floating: max
|
||||
image:
|
||||
- image.size: max
|
||||
- image.download: max
|
||||
- image.serve: max
|
||||
|
||||
metrics_units:
|
||||
compute:
|
||||
1:
|
||||
unit: instance
|
||||
volume:
|
||||
volume.size:
|
||||
unit: GiB
|
||||
network.bw.in:
|
||||
network.incoming.bytes:
|
||||
unit: MB
|
||||
factor: 1/1000000
|
||||
network.bw.out:
|
||||
network.outgoing.bytes:
|
||||
unit: MB
|
||||
factor: 1/1000000
|
||||
network.floating:
|
||||
1:
|
||||
unit: ip
|
||||
image:
|
||||
image.size:
|
||||
unit: MiB
|
||||
factor: 1/1048576
|
||||
default_unit:
|
||||
1:
|
||||
unit: unknown
|
66
src/templates/rocky/cloudkitty.conf
Normal file
66
src/templates/rocky/cloudkitty.conf
Normal file
@ -0,0 +1,66 @@
|
||||
###############################################################################
|
||||
# [ WARNING ]
|
||||
# configuration file maintained by Juju
|
||||
# local changes will be overwritten.
|
||||
###############################################################################
|
||||
|
||||
[DEFAULT]
|
||||
verbose = True
|
||||
debug = {{ options.debug }}
|
||||
auth_strategy = keystone
|
||||
{% include "parts/section-transport-url" %}
|
||||
|
||||
[ks_auth]
|
||||
auth_type = v3password
|
||||
auth_protocol = {{ identity_service.auth_protocol }}
|
||||
auth_url = {{ identity_service.service_protocol }}://{{ identity_service.service_host }}:{{ identity_service.service_port }}/v3
|
||||
identity_uri = {{ identity_service.auth_protocol }}://{{ identity_service.auth_host }}:{{ identity_service.auth_port }}/v3
|
||||
username = {{ identity_service.service_username }}
|
||||
password = {{ identity_service.service_password }}
|
||||
project_name = services
|
||||
user_domain_name = service_domain
|
||||
project_domain_name = service_domain
|
||||
debug = True
|
||||
|
||||
[keystone_authtoken]
|
||||
auth_section = ks_auth
|
||||
|
||||
{% if identity_service.signing_dir -%}
|
||||
signing_dir = {{ identity_service.signing_dir }}
|
||||
{% endif -%}
|
||||
{% if options.use_memcache == true -%}
|
||||
memcached_servers = {{ options.memcache_url }}
|
||||
{% endif -%}
|
||||
|
||||
|
||||
|
||||
[database]
|
||||
connection = {{ shared_db.type }}+pymysql://{{ shared_db.username }}:{{ shared_db.password }}@{{ shared_db.host }}/{{ shared_db.database }}{% if database_ssl_ca %}?ssl_ca={{ database_ssl_ca }}{% if database_ssl_cert %}&ssl_cert={{ database_ssl_cert }}&ssl_key={{ database_ssl_key }}{% endif %}{% endif %}
|
||||
|
||||
|
||||
[storage]
|
||||
backend = {{ options.storage_backend }}
|
||||
version = {{ options.storage_backend_version }}
|
||||
|
||||
[storage_gnocchi]
|
||||
auth_section = ks_auth
|
||||
|
||||
[collect]
|
||||
collector = gnocchi
|
||||
period = {{ options.collector_period }}
|
||||
wait_periods = {{ options.collector_wait_periods }}
|
||||
{%- if options.custom_metrics %}
|
||||
metrics_conf = /etc/cloudkitty/custom_metrics.yml
|
||||
{%- else %}
|
||||
metrics_conf = /etc/cloudkitty/metrics.yml
|
||||
{%- endif %}
|
||||
|
||||
[gnocchi_collector]
|
||||
auth_section = ks_auth
|
||||
|
||||
[tenant_fetcher]
|
||||
backend = keystone
|
||||
|
||||
[keystone_fetcher]
|
||||
auth_section = ks_auth
|
||||
keystone_version = 3
|
85
src/templates/rocky/metrics.yml
Normal file
85
src/templates/rocky/metrics.yml
Normal file
@ -0,0 +1,85 @@
|
||||
metrics:
|
||||
cpu:
|
||||
unit: instance
|
||||
alt_name: instance
|
||||
groupby:
|
||||
- id
|
||||
- project_id
|
||||
metadata:
|
||||
- flavor
|
||||
- flavor_id
|
||||
- vcpus
|
||||
mutate: NUMBOOL
|
||||
extra_args:
|
||||
aggregation_method: max
|
||||
resource_type: instance
|
||||
|
||||
image.size:
|
||||
unit: MiB
|
||||
factor: 1/1048576
|
||||
groupby:
|
||||
- id
|
||||
- project_id
|
||||
metadata:
|
||||
- container_format
|
||||
- disk_format
|
||||
extra_args:
|
||||
aggregation_method: max
|
||||
resource_type: image
|
||||
|
||||
volume.size:
|
||||
unit: GiB
|
||||
groupby:
|
||||
- id
|
||||
- project_id
|
||||
metadata:
|
||||
- volume_type
|
||||
extra_args:
|
||||
aggregation_method: max
|
||||
resource_type: volume
|
||||
|
||||
network.outgoing.bytes:
|
||||
unit: MB
|
||||
groupby:
|
||||
- id
|
||||
- project_id
|
||||
factor: 1/1000000
|
||||
metadata:
|
||||
- instance_id
|
||||
extra_args:
|
||||
aggregation_method: max
|
||||
resource_type: instance_network_interface
|
||||
|
||||
network.incoming.bytes:
|
||||
unit: MB
|
||||
groupby:
|
||||
- id
|
||||
- project_id
|
||||
factor: 1/1000000
|
||||
metadata:
|
||||
- instance_id
|
||||
extra_args:
|
||||
aggregation_method: max
|
||||
resource_type: instance_network_interface
|
||||
|
||||
ip.floating:
|
||||
unit: ip
|
||||
groupby:
|
||||
- id
|
||||
- project_id
|
||||
metadata:
|
||||
- state
|
||||
mutate: NUMBOOL
|
||||
extra_args:
|
||||
aggregation_method: max
|
||||
resource_type: network
|
||||
|
||||
radosgw.objects.size:
|
||||
unit: GiB
|
||||
groupby:
|
||||
- id
|
||||
- project_id
|
||||
factor: 1/1073741824
|
||||
extra_args:
|
||||
aggregation_method: max
|
||||
resource_type: ceph_account
|
20
src/test-requirements.txt
Normal file
20
src/test-requirements.txt
Normal file
@ -0,0 +1,20 @@
|
||||
# charm-proof
|
||||
charm-tools>=2.0.0
|
||||
# amulet deployment helpers
|
||||
git+https://github.com/juju/charm-helpers
|
||||
# BEGIN: Amulet OpenStack Charm Helper Requirements
|
||||
# Liberty client lower constraints
|
||||
amulet>=1.14.3,<2.0
|
||||
bundletester>=0.6.1,<1.0
|
||||
python-keystoneclient>=1.7.1,<2.0
|
||||
python-troveclient>=1.5,<=2.7.0
|
||||
python-cinderclient>=1.4.0,<2.0
|
||||
python-glanceclient>=1.1.0,<2.0
|
||||
python-heatclient>=0.8.0,<1.0
|
||||
python-neutronclient>=3.1.0,<4.0
|
||||
python-novaclient>=2.30.1,<3.0
|
||||
python-openstackclient>=1.7.0,<2.0
|
||||
python-swiftclient>=2.6.0,<3.0
|
||||
pika>=0.10.0,<1.0
|
||||
distro-info
|
||||
# END: Amulet OpenStack Charm Helper Requirements
|
9
src/tests/README.md
Normal file
9
src/tests/README.md
Normal file
@ -0,0 +1,9 @@
|
||||
# Overview
|
||||
|
||||
This directory provides Amulet tests to verify basic deployment functionality
|
||||
from the perspective of this charm, its requirements and its features, as
|
||||
exercised in a subset of the full OpenStack deployment test bundle topology.
|
||||
|
||||
For full details on functional testing of OpenStack charms please refer to
|
||||
the [functional testing](http://docs.openstack.org/developer/charm-guide/testing.html#functional-testing)
|
||||
section of the OpenStack Charm Guide.
|
54
src/tox.ini
Normal file
54
src/tox.ini
Normal file
@ -0,0 +1,54 @@
|
||||
[tox]
|
||||
envlist = pep8
|
||||
skipsdist = True
|
||||
|
||||
[testenv]
|
||||
envdir = .tox/py27
|
||||
setenv = VIRTUAL_ENV={envdir}
|
||||
PYTHONHASHSEED=0
|
||||
AMULET_SETUP_TIMEOUT=2700
|
||||
passenv = HOME TERM AMULET_HTTP_PROXY AMULET_OS_VIP
|
||||
deps = -r{toxinidir}/test-requirements.txt
|
||||
install_command =
|
||||
pip install --allow-unverified python-apt {opts} {packages}
|
||||
|
||||
[testenv:pep8]
|
||||
basepython = python2.7
|
||||
commands = charm-proof
|
||||
|
||||
[testenv:func27-noop]
|
||||
# DRY RUN - For Debug
|
||||
basepython = python2.7
|
||||
commands =
|
||||
bundletester -vl DEBUG -r json -o func-results.json --test-pattern "gate-*" -n --no-destroy
|
||||
|
||||
[testenv:func27]
|
||||
# Charm Functional Test
|
||||
# Run all gate tests which are +x (expected to always pass)
|
||||
basepython = python2.7
|
||||
commands =
|
||||
bundletester -vl DEBUG -r json -o func-results.json --test-pattern "gate-*" --no-destroy
|
||||
|
||||
[testenv:func27-smoke]
|
||||
# Charm Functional Test
|
||||
# Run a specific test as an Amulet smoke test (expected to always pass)
|
||||
basepython = python2.7
|
||||
commands =
|
||||
bundletester -vl DEBUG -r json -o func-results.json gate-basic-xenial-mitaka --no-destroy
|
||||
|
||||
[testenv:func27-dfs]
|
||||
# Charm Functional Test
|
||||
# Run all deploy-from-source tests which are +x (may not always pass!)
|
||||
basepython = python2.7
|
||||
commands =
|
||||
bundletester -vl DEBUG -r json -o func-results.json --test-pattern "dfs-*" --no-destroy
|
||||
|
||||
[testenv:func27-dev]
|
||||
# Charm Functional Test
|
||||
# Run all development test targets which are +x (may not always pass!)
|
||||
basepython = python2.7
|
||||
commands =
|
||||
bundletester -vl DEBUG -r json -o func-results.json --test-pattern "dev-*" --no-destroy
|
||||
|
||||
[testenv:venv]
|
||||
commands = {posargs}
|
24
src/wsgi_file/app.wsgi
Normal file
24
src/wsgi_file/app.wsgi
Normal file
@ -0,0 +1,24 @@
|
||||
# -*- mode: python -*-
|
||||
#
|
||||
# Copyright 2013 New Dream Network, LLC (DreamHost)
|
||||
#
|
||||
# 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.
|
||||
|
||||
"""Use this file for deploying the API under mod_wsgi.
|
||||
|
||||
See http://pecan.readthedocs.org/en/latest/deployment.html for details.
|
||||
"""
|
||||
|
||||
from cloudkitty.api import app
|
||||
|
||||
application = app.build_wsgi_app(argv=[])
|
7
test-requirements.txt
Normal file
7
test-requirements.txt
Normal file
@ -0,0 +1,7 @@
|
||||
# Unit test requirements
|
||||
flake8>=2.2.4,<=2.4.1
|
||||
os-testr>=0.4.1
|
||||
charms.reactive
|
||||
mock>=1.2
|
||||
coverage>=3.6
|
||||
git+https://github.com/openstack/charms.openstack#egg=charms.openstack
|
43
tox.ini
Normal file
43
tox.ini
Normal file
@ -0,0 +1,43 @@
|
||||
[tox]
|
||||
skipsdist = True
|
||||
envlist = pep8,py34,py35
|
||||
skip_missing_interpreters = True
|
||||
|
||||
[testenv]
|
||||
basepython = python2.7
|
||||
setenv = VIRTUAL_ENV={envdir}
|
||||
PYTHONHASHSEED=0
|
||||
TERM=linux
|
||||
INTERFACE_PATH={toxinidir}/interfaces
|
||||
LAYER_PATH={toxinidir}/layers
|
||||
JUJU_REPOSITORY={toxinidir}/build
|
||||
passenv = http_proxy https_proxy
|
||||
install_command =
|
||||
pip install {opts} {packages}
|
||||
deps =
|
||||
-r{toxinidir}/requirements.txt
|
||||
|
||||
[testenv:build]
|
||||
commands =
|
||||
charm-build --log-level DEBUG -o {toxinidir}/build src
|
||||
|
||||
[testenv:venv]
|
||||
commands = {posargs}
|
||||
|
||||
[testenv:pep8]
|
||||
commands = flake8 {posargs} src/reactive src/lib unit_tests
|
||||
|
||||
# Disable py27 tests as this is a reactive python 3 charm. Once project
|
||||
# config has been updated this tox target can be removed
|
||||
[testenv:py27]
|
||||
commands = /bin/true
|
||||
|
||||
[testenv:py34]
|
||||
basepython = python3.4
|
||||
deps = -r{toxinidir}/test-requirements.txt
|
||||
commands = ostestr {posargs}
|
||||
|
||||
[testenv:py35]
|
||||
basepython = python3.5
|
||||
deps = -r{toxinidir}/test-requirements.txt
|
||||
commands = ostestr {posargs}
|
42
unit_tests/__init__.py
Normal file
42
unit_tests/__init__.py
Normal file
@ -0,0 +1,42 @@
|
||||
# Copyright 2016 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()
|
||||
|
||||
|
||||
def mock_more_stuff():
|
||||
charmhelpers = charms_openstack.test_mocks.charmhelpers
|
||||
sys.modules['charmhelpers.core.hookenv.charm_dir'] = (
|
||||
charmhelpers.core.hookenv.charm_dir
|
||||
)
|
||||
charmhelpers.core.hookenv.charm_dir.return_value = "/tmp"
|
||||
sys.modules['charmhelpers.contrib.storage'] = (
|
||||
charmhelpers.contrib.storage
|
||||
)
|
||||
sys.modules['charmhelpers.contrib.storage.linux'] = (
|
||||
charmhelpers.contrib.storage.linux
|
||||
)
|
||||
sys.modules['charmhelpers.contrib.storage.linux.ceph'] = (
|
||||
charmhelpers.contrib.storage.linux.ceph
|
||||
)
|
||||
|
||||
|
||||
mock_more_stuff()
|
105
unit_tests/test_cloudkitty_handlers.py
Normal file
105
unit_tests/test_cloudkitty_handlers.py
Normal file
@ -0,0 +1,105 @@
|
||||
# Copyright 2019 Jalasoft
|
||||
#
|
||||
# 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 mock
|
||||
|
||||
import charms_openstack.test_utils as test_utils
|
||||
|
||||
import reactive.cloudkitty_handlers as handlers
|
||||
import charm.openstack.cloudkitty as cloudkitty
|
||||
|
||||
|
||||
class TestRegisteredHooks(test_utils.TestRegisteredHooks):
|
||||
|
||||
def test_hooks(self):
|
||||
defaults = [
|
||||
'charm.installed',
|
||||
'shared-db.connected',
|
||||
'amqp.connected',
|
||||
'identity-service.available',
|
||||
'config.changed',
|
||||
'update-status',
|
||||
'ha.connected',
|
||||
'upgrade-charm']
|
||||
hook_set = {
|
||||
'when': {
|
||||
'render_config': ('shared-db.available',
|
||||
'identity-service.available',
|
||||
'amqp.available',
|
||||
'metric-service.available',),
|
||||
'init_db': ('config.rendered',),
|
||||
'cluster_connected': ('ha.connected',),
|
||||
'setup_endpoint_connection': (
|
||||
'identity-service.connected',),
|
||||
},
|
||||
'when_not': {
|
||||
'disable_services': ('config.rendered',),
|
||||
'cluster_connected': ('ha.available',),
|
||||
'init_db': ('db.synced',),
|
||||
},
|
||||
}
|
||||
# test that the hooks were registered via the
|
||||
# reactive.cloudkitty_handlers
|
||||
self.registered_hooks_test_helper(handlers, hook_set, defaults)
|
||||
|
||||
|
||||
class TestCloudkittyHandlers(test_utils.PatchHelper):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.patch_release(cloudkitty.CloudkittyCharm.release)
|
||||
self.cloudkitty_charm = mock.MagicMock()
|
||||
self.patch_object(handlers.charm, 'provide_charm_instance',
|
||||
new=mock.MagicMock())
|
||||
self.provide_charm_instance().__enter__.return_value = \
|
||||
self.cloudkitty_charm
|
||||
self.provide_charm_instance().__exit__.return_value = None
|
||||
|
||||
def test_render_config(self):
|
||||
self.patch('charms.reactive.set_state', 'set_state')
|
||||
handlers.render_config('arg1', 'arg2')
|
||||
self.cloudkitty_charm.render_with_interfaces.assert_called_once_with(
|
||||
('arg1', 'arg2'))
|
||||
self.cloudkitty_charm.assess_status.assert_called_once_with()
|
||||
self.set_state.assert_called_once_with('config.rendered')
|
||||
|
||||
def test_init_db(self):
|
||||
self.patch('charms.reactive.set_state', 'set_state')
|
||||
handlers.init_db()
|
||||
self.cloudkitty_charm.db_sync.assert_called_once_with()
|
||||
self.cloudkitty_charm.restart_all.assert_called_once_with()
|
||||
self.set_state.assert_called_once_with('db.synced')
|
||||
self.cloudkitty_charm.assess_status.assert_called_once_with()
|
||||
|
||||
def test_cluster_connected(self):
|
||||
hacluster = mock.MagicMock()
|
||||
handlers.cluster_connected(hacluster)
|
||||
self.cloudkitty_charm.configure_ha_resources.assert_called_once_with(
|
||||
hacluster)
|
||||
self.octavia_charm.assess_status.assert_called_once_with()
|
||||
|
||||
def test_setup_endpoint_connection(self):
|
||||
keystone = mock.MagicMock()
|
||||
handlers.setup_endpoint_connection(keystone)
|
||||
keystone.register_endpoints.assert_called_once_with(
|
||||
self.cloudkitty_charm.service_type,
|
||||
self.cloudkitty_charm.region,
|
||||
self.cloudkitty_charm.public_url,
|
||||
self.cloudkitty_charm.internal_url,
|
||||
self.cloudkitty_charm.admin_url,
|
||||
requested_roles=cloudkitty.CLOUDKITTY_ROLES)
|
||||
self.cloudkitty_charm.assess_status.assert_called_once_with()
|
80
unit_tests/test_lib_charm_openstack_cloudkitty.py
Normal file
80
unit_tests/test_lib_charm_openstack_cloudkitty.py
Normal file
@ -0,0 +1,80 @@
|
||||
# Copyright 2019 Jalasoft
|
||||
#
|
||||
# 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 mock
|
||||
|
||||
import charms_openstack.test_utils as test_utils
|
||||
|
||||
import charm.openstack.cloudkitty as cloudkitty
|
||||
|
||||
|
||||
class Helper(test_utils.PatchHelper):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.patch_release(cloudkitty.CloudkittyCharm.release)
|
||||
|
||||
|
||||
class TestCloudkittyCharm(Helper):
|
||||
|
||||
def test_install(self):
|
||||
self.patch(cloudkitty.CloudkittyCharm, 'configure_source')
|
||||
self.patch(cloudkitty.CloudkittyCharm, 'update_api_ports')
|
||||
self.ch_config.side_effect = lambda: {'openstack-origin': 'distro'}
|
||||
c = cloudkitty.DesignateCharm(release='queens')
|
||||
c.install()
|
||||
self.configure_source.assert_called_with()
|
||||
|
||||
def test_get_amqp_credentials(self):
|
||||
c = cloudkitty.CloudkittyCharm()
|
||||
result = c.get_amqp_credentials()
|
||||
self.assertEqual(result, ('cloudkitty', 'cloudkitty'))
|
||||
|
||||
def test_get_database_setup(self):
|
||||
c = cloudkitty.CloudkittyCharm()
|
||||
result = c.get_database_setup()
|
||||
self.assertEqual(result, [{'database': 'cloudkitty',
|
||||
'username': 'cloudkitty'}])
|
||||
|
||||
def test_enable_webserver_site(self):
|
||||
self.patch('os.path.exists', 'exists')
|
||||
self.patch('subprocess.call', 'sp_call')
|
||||
self.patch('subprocess.check_call', 'sp_check_call')
|
||||
self.patch('charmhelpers.core.host.service_reload', 'service_reload')
|
||||
self.exists.return_value = True
|
||||
self.sp_call.return_value = True
|
||||
c = cloudkitty.CloudkittyCharm()
|
||||
c.enable_webserver_site()
|
||||
self.exists.assert_called_with(
|
||||
'/etc/apache2/sites-available/cloudkitty-api.conf')
|
||||
self.sp_call.assert_called_with(['a2query', '-s', 'cloudkitty-api'])
|
||||
self.sp_check_call.assert_called_with(['a2ensite', 'cloudkitty-api'])
|
||||
self.service_reload.assert_called_with(
|
||||
'apache2', restart_on_failure=True)
|
||||
|
||||
def test_local_address(self):
|
||||
c = cloudkitty.CloudkittyCharm()
|
||||
configuration_class = mock.MagicMock()
|
||||
c.configuration_class = configuration_class
|
||||
self.assertEqual(c.local_address, configuration_class().local_address)
|
||||
|
||||
def test_local_unit_name(self):
|
||||
c = cloudkitty.CloudkittyCharm()
|
||||
configuration_class = mock.MagicMock()
|
||||
c.configuration_class = configuration_class
|
||||
self.assertEqual(c.local_unit_name,
|
||||
configuration_class().local_unit_name)
|
Loading…
Reference in New Issue
Block a user