diff --git a/setup.py b/setup.py index 8e963c1..fb39848 100644 --- a/setup.py +++ b/setup.py @@ -51,6 +51,7 @@ install_require = [ 'gnocchiclient>=7.0.5,<8.0.0', 'pika>=1.1.0,<2.0.0', 'python-barbicanclient>=4.0.1,<5.0.0', + 'python-cloudkittyclient', 'python-designateclient>=1.5,<3.0.0', 'python-heatclient<2.0.0', 'python-ironicclient', diff --git a/zaza/openstack/charm_tests/cloudkitty/__init__.py b/zaza/openstack/charm_tests/cloudkitty/__init__.py new file mode 100644 index 0000000..288ce37 --- /dev/null +++ b/zaza/openstack/charm_tests/cloudkitty/__init__.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python3 + +# Copyright 2019 Canonical Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# 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. + +"""Collection of code for setting up and testing cloudkitty.""" diff --git a/zaza/openstack/charm_tests/cloudkitty/setup.py b/zaza/openstack/charm_tests/cloudkitty/setup.py new file mode 100644 index 0000000..86e697f --- /dev/null +++ b/zaza/openstack/charm_tests/cloudkitty/setup.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 + +# Copyright 2019 Canonical Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# 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. + +"""Code for configuring Cloudkitty.""" + + +def basic_setup(): + """Run setup for testing Cloudkitty. + + Setup for testing Cloudkitty is currently part of functional + tests. + """ + pass diff --git a/zaza/openstack/charm_tests/cloudkitty/tests.py b/zaza/openstack/charm_tests/cloudkitty/tests.py new file mode 100644 index 0000000..8e16f67 --- /dev/null +++ b/zaza/openstack/charm_tests/cloudkitty/tests.py @@ -0,0 +1,117 @@ +#!/usr/bin/env python3 + +# Copyright 2019 Canonical Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# 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. + +"""Encapsulate Cloudkitty testing.""" + +import logging + +import zaza.openstack.charm_tests.test_utils as test_utils +import zaza.openstack.utilities.openstack as openstack_utils + +from cloudkittyclient import client + + +class CloudkittyTest(test_utils.OpenStackBaseTest): + """Encapsulate Cloudkitty tests.""" + + API_VERSION = '1' + + @classmethod + def setUpClass(cls): + """Run class setup for running Cloudkitty tests.""" + super(CloudkittyTest, cls).setUpClass() + cls.current_release = openstack_utils.get_os_release() + + logging.info('Instantiating cloudkitty client...') + cls.cloudkitty = client.Client( + CloudkittyTest.API_VERSION, + session=cls.keystone_session + ) + + def tearDown(self): + """Run teardown for test class.""" + rating = self.cloudkitty.rating + + if not rating.get_module(module_id='hashmap').get('enabled'): + rating.update_module(module_id='hashmap', enabled=True) + + hashmap = rating.hashmap + for service in hashmap.get_service().get('services'): + + service_id = service.get('service_id') + + fields = hashmap.get_field(service_id=service_id) + for field in fields.get('fields'): + hashmap.delete_field(field_id=field.get('field_id')) + + mappings = hashmap.get_mapping(service_id=service_id) + for mapping in mappings.get('mappings'): + hashmap.delete_mapping(mapping_id=mapping.get('mapping_id')) + + hashmap.delete_service(service_id=service_id) + + for group in hashmap.get_group().get('groups'): + hashmap.delete_group(group_id=group.get('group_id')) + + def test_400_api_connection(self): + """Simple api calls to check service is up and responding.""" + report = self.cloudkitty.report + tenants_list = report.get_tenants() + assert tenants_list == [] + + def test_401_module_enable_and_disable(self): + """Test enable and disable module via API.""" + rating = self.cloudkitty.rating + modules = rating.get_module() + + for module in modules.get('modules'): + module_id = module.get('module_id') + + # noop module can't be disabled + if module_id == 'noop': + continue + + logging.info('Enabling {} module'.format(module_id)) + rating.update_module(module_id=module_id, enabled=True) + module = rating.get_module(module_id=module_id) + assert module.get('enabled') + + logging.info('Disabling {} module'.format(module_id)) + rating.update_module(module_id=module_id, enabled=False) + module = rating.get_module(module_id=module_id) + assert not module.get('enabled') + + def test_402_create_mapping(self): + """Test mapping create via API.""" + rating = self.cloudkitty.rating + + if not rating.get_module(module_id='hashmap').get('enabled'): + rating.update_module(module_id='hashmap', enabled=True) + + hashmap = rating.hashmap + + service = hashmap.create_service(name='test-service') + service_id = service.get('service_id') + + field = hashmap.create_field(name='test-field', service_id=service_id) + field_id = field.get('field_id') + + group = hashmap.create_group(name='test-group') + group_id = group.get('group_id') + + hashmap.create_mapping( + type='flat', field_id=field_id, + group_id=group_id, value='test-value', cost=0.1)