From 8145c924e0e3cd450114fbe342232197cf3ebcdb Mon Sep 17 00:00:00 2001 From: James Page Date: Thu, 27 Feb 2020 17:00:52 +0000 Subject: [PATCH] Baseline of charm --- .gitignore | 6 + LICENSE | 202 ++++++++ requirements.txt | 4 + src/README.md | 23 + src/config.yaml | 9 + src/copyright | 16 + src/icon.svg | 450 ++++++++++++++++++ src/layer.yaml | 5 + src/lib/charm/openstack/__init__.py | 0 src/lib/charm/openstack/trilio_wlm.py | 117 +++++ src/metadata.yaml | 10 + src/reactive/trilio_wlm_handlers.py | 55 +++ src/templates/api-paste.ini | 49 ++ src/templates/workloadmgr.conf | 78 +++ src/test-requirements.txt | 20 + src/tox.ini | 53 +++ test-generate-requirements.txt | 5 + test-requirements.txt | 7 + tox.ini | 71 +++ unit_tests/__init__.py | 46 ++ ...est_lib_charm_openstack_openvswitch_odl.py | 47 ++ unit_tests/test_openvswitch_odl_handlers.py | 43 ++ 22 files changed, 1316 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 requirements.txt create mode 100644 src/README.md create mode 100644 src/config.yaml create mode 100644 src/copyright create mode 100644 src/icon.svg create mode 100644 src/layer.yaml create mode 100644 src/lib/charm/openstack/__init__.py create mode 100644 src/lib/charm/openstack/trilio_wlm.py create mode 100644 src/metadata.yaml create mode 100644 src/reactive/trilio_wlm_handlers.py create mode 100644 src/templates/api-paste.ini create mode 100644 src/templates/workloadmgr.conf create mode 100644 src/test-requirements.txt create mode 100644 src/tox.ini create mode 100644 test-generate-requirements.txt create mode 100644 test-requirements.txt create mode 100644 tox.ini create mode 100644 unit_tests/__init__.py create mode 100644 unit_tests/test_lib_charm_openstack_openvswitch_odl.py create mode 100644 unit_tests/test_openvswitch_odl_handlers.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..452c6f1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +build/ +.local/ +.testrepository/ +.tox/ +func-results.json +test-charm/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..7a4a3ea --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + + 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. \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..cb6c9d4 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +# Requirements to build the charm +charm-tools +simplejson +flake8 \ No newline at end of file diff --git a/src/README.md b/src/README.md new file mode 100644 index 0000000..20d8b94 --- /dev/null +++ b/src/README.md @@ -0,0 +1,23 @@ +# Overview + +This subordinate charm provides ... + + +# Usage + +With the OpenStack nova-compute and neutron-gateway charms: + + juju deploy ... + juju deploy neutron-gateway + juju add-relation nova-compute ... + juju add-relation neutron-gateway ... + +# Configuration Options + +This charm will optionally configure the local ip address of the OVS instance to something other than the 'private-address' provided by Juju: + + juju set ... os-data-network=10.20.3.0/21 + + +# Restrictions + diff --git a/src/config.yaml b/src/config.yaml new file mode 100644 index 0000000..99a3e7a --- /dev/null +++ b/src/config.yaml @@ -0,0 +1,9 @@ +options: + triliovault-pkg-source: + type: string + default: "deb [trusted=yes] https://apt.fury.io/triliovault-python3/ /" + description: Repository address of triliovault packages + trilio-user-id: + type: string + default: + description: Unique TrilioVault User ID diff --git a/src/copyright b/src/copyright new file mode 100644 index 0000000..6f8a25f --- /dev/null +++ b/src/copyright @@ -0,0 +1,16 @@ +Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0 + +Files: * +Copyright: 2015, 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. \ No newline at end of file diff --git a/src/icon.svg b/src/icon.svg new file mode 100644 index 0000000..c90ecfc --- /dev/null +++ b/src/icon.svg @@ -0,0 +1,450 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/layer.yaml b/src/layer.yaml new file mode 100644 index 0000000..7777bf1 --- /dev/null +++ b/src/layer.yaml @@ -0,0 +1,5 @@ +includes: ['layer:openstack-api'] +options: + basic: + use_venv: True + include_system_packages: True diff --git a/src/lib/charm/openstack/__init__.py b/src/lib/charm/openstack/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/lib/charm/openstack/trilio_wlm.py b/src/lib/charm/openstack/trilio_wlm.py new file mode 100644 index 0000000..c4f8e01 --- /dev/null +++ b/src/lib/charm/openstack/trilio_wlm.py @@ -0,0 +1,117 @@ +import collections +import socket +import subprocess + +import charmhelpers.core.hookenv as hookenv +import charmhelpers.fetch as fetch +import charms_openstack.charm +import charms_openstack.ip as os_ip + + +class TrilioWLMCharm(charms_openstack.charm.HAOpenStackCharm): + + # Internal name of charm + service_name = name = 'trilio-wlm' + + # First release supported + release = 'stein' + + # List of packages to install for this charm + packages = ['workloadmgr', 'python-apt'] + + api_ports = { + 'workloadmgr-api': { + os_ip.PUBLIC: 8780, + os_ip.ADMIN: 8780, + os_ip.INTERNAL: 8780, + } + } + + service_type = 'workloadmgr' + default_service = 'workloadmgr-api' + services = [ + 'wlm-api', 'wlm-scheduler', 'wlm-workloads', + ] + + required_relations = [ + 'shared-db', + 'amqp', + 'identity-service' + ] + + restart_map = { + '/etc/workloadmgr/workloadmgr.conf': services, + '/etc/workloadmgr/api-paste.ini': ['wlm-api'], + } + + ha_resources = [ + 'vips', + 'haproxy' + ] + + release_pkg = 'workloadmgr' + + package_codenames = { + 'workloadmgr': collections.OrderedDict([ + ('3', 'stein'), + ]), + } + + + sync_cmd = ['true'] + + user = 'root' + group = 'nova' + + def __init__(self, release=None, **kwargs): + super().__init__(release='stein', **kwargs) + + + def get_amqp_credentials(self): + return ('triliowlm', 'triliowlm') + + def get_database_setup(self): + return [{ + 'database': 'workloadmgr', + 'username': 'workloadmgr', + 'hostname': hookenv.network_get_primary_address('shared-db'), + }] + + def configure_source(self): + with open ('/etc/apt/sources.list.d/trilio-wlm.list', + 'w') as tsources: + tsources.write(hookenv.config('triliovault-pkg-source')) + super().configure_source() + + @property + def public_url(self): + """Return the public endpoint URL for the default service as specified + in the self.default_service attribute + """ + return "{}:{}/v1/$(tenant_id)s".format( + os_ip.canonical_url(os_ip.PUBLIC), + self.api_port(self.default_service, + os_ip.PUBLIC) + ) + + @property + def admin_url(self): + """Return the admin endpoint URL for the default service as specificed + in the self.default_service attribute + """ + return "{}:{}/v1/$(tenant_id)s".format( + os_ip.canonical_url(os_ip.ADMIN), + self.api_port(self.default_service, + os_ip.ADMIN) + ) + + @property + def internal_url(self): + """Return the internal internal endpoint URL for the default service as + specificated in the self.default_service attribtue + """ + return "{}:{}/v1/$(tenant_id)s".format( + os_ip.canonical_url(os_ip.INTERNAL), + self.api_port(self.default_service, + os_ip.INTERNAL) + ) diff --git a/src/metadata.yaml b/src/metadata.yaml new file mode 100644 index 0000000..b00e0e9 --- /dev/null +++ b/src/metadata.yaml @@ -0,0 +1,10 @@ +name: trilio-wlm +display-name: TrilioVault Workload Manager +maintainer: OpenStack Charmers +summary: TrilioVault Workload Manager Service +description: | + TrilioVault Workload Manager Service +tags: + - openstack +series: + - bionic diff --git a/src/reactive/trilio_wlm_handlers.py b/src/reactive/trilio_wlm_handlers.py new file mode 100644 index 0000000..a5059af --- /dev/null +++ b/src/reactive/trilio_wlm_handlers.py @@ -0,0 +1,55 @@ +# 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 charms_openstack.charm as charm +import charms.reactive as reactive + +# This charm's library contains all of the handler code associated with +# sdn_charm +import charm.openstack.trilio_wlm as trilio_wlm # noqa + +charm.use_defaults( + 'charm.installed', + 'amqp.connected', + 'shared-db.connected', + 'identity-service.connected', + 'identity-service.available', # enables SSL support + 'config.changed', + 'update-status') + +@reactive.when('shared-db.available') +@reactive.when('identity-service.available') +@reactive.when('amqp.available') +def render_config(*args): + """Render the configuration for charm when all the interfaces are + available. + """ + with charm.provide_charm_instance() as charm_class: + charm_class.upgrade_if_available(args) + charm_class.render_with_interfaces(args) + charm_class.assess_status() + reactive.set_state('config.rendered') + +# db_sync checks if sync has been done so rerunning is a noop +@reactive.when('config.rendered') +def init_db(): + with charm.provide_charm_instance() as charm_class: + charm_class.db_sync() + +@reactive.when('ha.connected') +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() \ No newline at end of file diff --git a/src/templates/api-paste.ini b/src/templates/api-paste.ini new file mode 100644 index 0000000..ce0c41f --- /dev/null +++ b/src/templates/api-paste.ini @@ -0,0 +1,49 @@ +# This file is managed by Juju - changes will be overwritten +[composite:osapi_workloads] +use = call:workloadmgr.api:root_app_factory +/: apiversions +/v1: openstack_workloads_api_v1 + +[composite:openstack_workloads_api_v1] +use = call:workloadmgr.api.middleware.auth:pipeline_factory +noauth = faultwrap sizelimit noauth apiv1 +keystone = faultwrap sizelimit authtoken keystonecontext apiv1 +keystone_nolimit = faultwrap sizelimit authtoken keystonecontext apiv1 + +[filter:faultwrap] +paste.filter_factory = workloadmgr.api.middleware.fault:FaultWrapper.factory + +[filter:noauth] +paste.filter_factory = workloadmgr.api.middleware.auth:NoAuthMiddleware.factory + +[filter:sizelimit] +paste.filter_factory = oslo_middleware.sizelimit:RequestBodySizeLimiter.factory + +[app:apiv1] +paste.app_factory = workloadmgr.api.v1.router:APIRouter.factory + +[pipeline:apiversions] +pipeline = faultwrap osworkloadsversionapp + +[app:osworkloadsversionapp] +paste.app_factory = workloadmgr.api.versions:Versions.factory + +########## +# Shared # +########## + +[filter:keystonecontext] +paste.filter_factory = workloadmgr.api.middleware.auth:WorkloadMgrKeystoneContext.factory + +[filter:authtoken] +paste.filter_factory = keystonemiddleware.auth_token:filter_factory +{% if identity_service.auth_host -%} +auth_host = {{ identity_service.auth_host }} +auth_port = {{ identity_service.auth_port }} +auth_protocol = {{ identity_service.auth_protocol }} +admin_tenant_name = services +project_name = services +admin_user = {{ identity_service.service_username }} +admin_password = {{ identity_service.service_password }} +signing_dir = /var/cache/workloadmgr +{% endif -%} diff --git a/src/templates/workloadmgr.conf b/src/templates/workloadmgr.conf new file mode 100644 index 0000000..5894808 --- /dev/null +++ b/src/templates/workloadmgr.conf @@ -0,0 +1,78 @@ +# This file is managed by Juju - changes will be overwritten +[DEFAULT] +log_dir = /var/log/workloadmgr +use_syslog = False +use_stderr = False + +# TODO +triliovault_hostnames = + +config_status = configured + +{% if amqp.transport_url -%} +transport_url = {{ amqp.transport_url }} +{% endif -%} + +{% if shared_db.host -%} +sql_connection = {{ shared_db.uri }} +{% endif -%} + +compute_driver = libvirt.LibvirtDriver +state_path = /var/lib/workloadmgr +rootwrap_config = /etc/workloadmgr/rootwrap.conf +api_paste_config = /etc/workloadmgr/api-paste.ini +osapi_workloads_listen_port = {{ options.service_listen_info.workloadmgr_api.port }} + +verbose = {{ options.verbose }} +debug = {{ options.debug }} + +# TODO +glance_production_host = +glance_production_api_servers = +cinder_production_endpoint_template = +nova_production_endpoint_template = +neutron_production_url = +trustee_role = + +global_job_scheduler_override = False + +cloud_unique_id = {{ options.trilio_user_id }} +region_name_for_services = {{ options.region }} + +{% if identity_service.auth_host -%} + +nova_admin_auth_url = {{ identity_service.auth_protocol }}://{{ identity_service.auth_host }}:{{ identity_service.auth_port }} +neutron_admin_auth_url = {{ identity_service.auth_protocol }}://{{ identity_service.auth_host }}:{{ identity_service.auth_port }} +keystone_endpoint_url = {{ identity_service.auth_protocol }}://{{ identity_service.auth_host }}:{{ identity_service.auth_port }} + +{% if identity_service.service_domain -%} +domain_name = {{ identity_service.service_domain }} +triliovault_user_domain_id = {{ identity_service.service_domain }} + +cloud_admin_user_id = {{ identity_service.service_username }} +cloud_admin_domain = {{ identity_service.service_domain }} +cloud_admin_project_id = services +cloud_admin_role = Admin +{% endif -%} + +{% endif -%} + +keystone_auth_version = 3 +glance_api_version = 2 + +vault_data_directory = /var/triliovault-mounts +vault_data_directory_old = /var/triliovault +vault_storage_das_device = none + +# TODO +vault_storage_type = nfs +vault_storage_nfs_export = + +vault_storage_nfs_options = nolock,soft,timeo=180,intr,lookupcache=none + +{% include "parts/section-keystone-authtoken" %} + +[clients] +endpoint_type = +insecure = True +cafile = /etc/workloadmgr/ca-chain.pem diff --git a/src/test-requirements.txt b/src/test-requirements.txt new file mode 100644 index 0000000..7d907c4 --- /dev/null +++ b/src/test-requirements.txt @@ -0,0 +1,20 @@ +# charm-proof +charm-tools>=2.0.0 +# amulet deployment helpers +bzr+lp:charm-helpers#egg=charmhelpers +# 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-designateclient>=1.5,<2.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 \ No newline at end of file diff --git a/src/tox.ini b/src/tox.ini new file mode 100644 index 0000000..879671c --- /dev/null +++ b/src/tox.ini @@ -0,0 +1,53 @@ +# Source charm: ./src/tox.ini +# This file is managed centrally by release-tools and should not be modified +# within individual charm repos. +[tox] +envlist = pep8 +skipsdist = True + +[testenv] +setenv = VIRTUAL_ENV={envdir} + PYTHONHASHSEED=0 + AMULET_SETUP_TIMEOUT=2700 +whitelist_externals = juju +passenv = HOME TERM AMULET_* +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] +# 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] +# 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] +# 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] +# 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} \ No newline at end of file diff --git a/test-generate-requirements.txt b/test-generate-requirements.txt new file mode 100644 index 0000000..e602803 --- /dev/null +++ b/test-generate-requirements.txt @@ -0,0 +1,5 @@ +# Requirements for generating a charm +charm-tools +simple-json +jinja2 +git+https://github.com/openstack-charmers/charm-templates-openstack.git \ No newline at end of file diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000..16bcf0b --- /dev/null +++ b/test-requirements.txt @@ -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 \ No newline at end of file diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..ee7e92e --- /dev/null +++ b/tox.ini @@ -0,0 +1,71 @@ +# Source charm: ./tox.ini +# This file is managed centrally by release-tools and should not be modified +# within individual charm repos. +[tox] +skipsdist = True +envlist = pep8,py34,py35,py27 +skip_missing_interpreters = True + +[bundleenv] +setenv = VIRTUAL_ENV={envdir} + PYTHONHASHSEED=0 + TERM=linux + LAYER_PATH={toxinidir}/layers + INTERFACE_PATH={toxinidir}/interfaces + JUJU_REPOSITORY={toxinidir}/build +install_command = + pip install {opts} {packages} +deps = + -r{toxinidir}/requirements.txt + +[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 CHARM_TEMPLATE_LOCAL_BRANCH +install_command = + pip install {opts} {packages} +deps = + -r{toxinidir}/requirements.txt + +[testenv:build] +basepython = python2.7 +commands = + charm-build --log-level DEBUG -o {toxinidir}/build src {posargs} + +[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} + +[testenv:pep8] +basepython = python2.7 +deps = -r{toxinidir}/test-requirements.txt +commands = flake8 {posargs} src unit_tests + +[testenv:test_create] +# This tox target is used for template generation testing and can be removed +# from a generated source charm or built charm +basepython = python2.7 +deps = -r{toxinidir}/test-generate-requirements.txt +setenv = + CHARM_TEMPLATE_ALT_REPO = {toxinidir} +commands = + charm-create -t openstack-api -a congress test-charm + /bin/cp test-artifacts/congress.conf.sample {toxinidir}/test-charm/congress/src/templates/congress.conf +# charm-build --log-level DEBUG -o {toxinidir}/test-charm/congress/build {toxinidir}/test-charm/congress/src {posargs} + +[testenv:venv] +commands = {posargs} + +[flake8] +# E402 ignore necessary for path append before sys module import in actions +ignore = E402 \ No newline at end of file diff --git a/unit_tests/__init__.py b/unit_tests/__init__.py new file mode 100644 index 0000000..1ca5eb6 --- /dev/null +++ b/unit_tests/__init__.py @@ -0,0 +1,46 @@ +# 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 +import mock + +sys.path.append('src') +sys.path.append('src/lib') + +# Mock out charmhelpers so that we can test without it. +# also stops sideeffects from occuring. +charmhelpers = mock.MagicMock() +apt_pkg = mock.MagicMock() +sys.modules['apt_pkg'] = apt_pkg +sys.modules['charmhelpers'] = charmhelpers +sys.modules['charmhelpers.core'] = charmhelpers.core +sys.modules['charmhelpers.core.decorators'] = charmhelpers.core.decorators +sys.modules['charmhelpers.core.hookenv'] = charmhelpers.core.hookenv +sys.modules['charmhelpers.core.host'] = charmhelpers.core.host +sys.modules['charmhelpers.core.unitdata'] = charmhelpers.core.unitdata +sys.modules['charmhelpers.core.templating'] = charmhelpers.core.templating +sys.modules['charmhelpers.contrib'] = charmhelpers.contrib +sys.modules['charmhelpers.contrib.openstack'] = charmhelpers.contrib.openstack +sys.modules['charmhelpers.contrib.openstack.utils'] = ( + charmhelpers.contrib.openstack.utils) +sys.modules['charmhelpers.contrib.openstack.templating'] = ( + charmhelpers.contrib.openstack.templating) +sys.modules['charmhelpers.contrib.network'] = charmhelpers.contrib.network +sys.modules['charmhelpers.contrib.network.ip'] = ( + charmhelpers.contrib.network.ip) +sys.modules['charmhelpers.fetch'] = charmhelpers.fetch +sys.modules['charmhelpers.cli'] = charmhelpers.cli +sys.modules['charmhelpers.contrib.hahelpers'] = charmhelpers.contrib.hahelpers +sys.modules['charmhelpers.contrib.hahelpers.cluster'] = ( + charmhelpers.contrib.hahelpers.cluster) \ No newline at end of file diff --git a/unit_tests/test_lib_charm_openstack_openvswitch_odl.py b/unit_tests/test_lib_charm_openstack_openvswitch_odl.py new file mode 100644 index 0000000..7c4385b --- /dev/null +++ b/unit_tests/test_lib_charm_openstack_openvswitch_odl.py @@ -0,0 +1,47 @@ +# 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. + +from __future__ import absolute_import +from __future__ import print_function + +import unittest + +import mock + +import charm.openstack.sdn_charm as sdn_charm + + +class Helper(unittest.TestCase): + + def setUp(self): + self._patches = {} + self._patches_start = {} + + def tearDown(self): + for k, v in self._patches.items(): + v.stop() + setattr(self, k, None) + self._patches = None + self._patches_start = None + + def patch(self, obj, attr, return_value=None, **kwargs): + mocked = mock.patch.object(obj, attr, **kwargs) + self._patches[attr] = mocked + started = mocked.start() + started.return_value = return_value + self._patches_start[attr] = started + setattr(self, attr, started) + + +class TestSDNCharm(Helper): \ No newline at end of file diff --git a/unit_tests/test_openvswitch_odl_handlers.py b/unit_tests/test_openvswitch_odl_handlers.py new file mode 100644 index 0000000..f107ee6 --- /dev/null +++ b/unit_tests/test_openvswitch_odl_handlers.py @@ -0,0 +1,43 @@ +# 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. + +from __future__ import absolute_import +from __future__ import print_function + +import mock + +import reactive.sdn_charm_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'] + hook_set = { + 'when': { + }, + 'when_not': { + } + } + # test that the hooks were registered via the + # reactive.barbican_handlers + self.registered_hooks_test_helper(handlers, hook_set, defaults) + + +class TestSDNCharmHandles(test_utils.PatchHelper): \ No newline at end of file