From ecf5f1e1083b914dbd99976401156f9e3edf5194 Mon Sep 17 00:00:00 2001 From: hernandanielg Date: Mon, 26 Sep 2022 15:26:18 +0000 Subject: [PATCH 1/4] initial commit --- setup.py | 1 + .../charm_tests/cloudkitty/__init__.py | 17 +++++++ .../openstack/charm_tests/cloudkitty/setup.py | 26 ++++++++++ .../openstack/charm_tests/cloudkitty/tests.py | 47 +++++++++++++++++++ 4 files changed, 91 insertions(+) create mode 100644 zaza/openstack/charm_tests/cloudkitty/__init__.py create mode 100644 zaza/openstack/charm_tests/cloudkitty/setup.py create mode 100644 zaza/openstack/charm_tests/cloudkitty/tests.py diff --git a/setup.py b/setup.py index 6ae126b..9cf78b9 100644 --- a/setup.py +++ b/setup.py @@ -46,6 +46,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..7f14151 --- /dev/null +++ b/zaza/openstack/charm_tests/cloudkitty/tests.py @@ -0,0 +1,47 @@ +#!/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.""" + + CONF_FILE = '/etc/cloudkitty/cloudkitty.conf' + + @classmethod + def setUpClass(cls): + """Run class setup for running Cloudkitty tests.""" + super(CloudkittyTest, cls).setUpClass() + cls.current_release = openstack_utils.get_os_release() + + def test_400_api_connection(self): + """Simple api calls to check service is up and responding.""" + logging.info('Instantiating cloudkitty client...') + client_version = '1' + cloudkitty = client.Client( + client_version, + session=openstack_utils.get_overcloud_keystone_session() + ) + cloudkitty.report.get_summary() + pass From 627e2d82b1d1a8341e9b7962032bbbb720ffbee0 Mon Sep 17 00:00:00 2001 From: hernandanielg Date: Fri, 30 Sep 2022 00:36:29 +0000 Subject: [PATCH 2/4] added module_enable test --- .../openstack/charm_tests/cloudkitty/tests.py | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/zaza/openstack/charm_tests/cloudkitty/tests.py b/zaza/openstack/charm_tests/cloudkitty/tests.py index 7f14151..9dc29f6 100644 --- a/zaza/openstack/charm_tests/cloudkitty/tests.py +++ b/zaza/openstack/charm_tests/cloudkitty/tests.py @@ -28,6 +28,7 @@ class CloudkittyTest(test_utils.OpenStackBaseTest): """Encapsulate Cloudkitty tests.""" CONF_FILE = '/etc/cloudkitty/cloudkitty.conf' + API_VERSION = '1' @classmethod def setUpClass(cls): @@ -35,13 +36,21 @@ class CloudkittyTest(test_utils.OpenStackBaseTest): 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 test_400_api_connection(self): """Simple api calls to check service is up and responding.""" - logging.info('Instantiating cloudkitty client...') - client_version = '1' - cloudkitty = client.Client( - client_version, - session=openstack_utils.get_overcloud_keystone_session() - ) - cloudkitty.report.get_summary() - pass + tenants_list = self.cloudkitty.report.get_tenants() + assert tenants_list == [] + + def test_401_module_enable(self): + """Test enabling hashmap module via API.""" + logging.info('Enabling hashmap module') + self.cloudkitty.rating.update_module(module_id='hashmap', enabled=True) + + hashmap = self.cloudkitty.rating.get_module(module_id='hashmap') + assert hashmap.get('enabled') From 84c58b44a42b761555a3e87243326194efcaba2d Mon Sep 17 00:00:00 2001 From: hernandanielg Date: Fri, 30 Sep 2022 06:05:37 +0000 Subject: [PATCH 3/4] added services field and mapping tests --- .../openstack/charm_tests/cloudkitty/tests.py | 44 ++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/zaza/openstack/charm_tests/cloudkitty/tests.py b/zaza/openstack/charm_tests/cloudkitty/tests.py index 9dc29f6..ae22d00 100644 --- a/zaza/openstack/charm_tests/cloudkitty/tests.py +++ b/zaza/openstack/charm_tests/cloudkitty/tests.py @@ -50,7 +50,47 @@ class CloudkittyTest(test_utils.OpenStackBaseTest): def test_401_module_enable(self): """Test enabling hashmap module via API.""" logging.info('Enabling hashmap module') - self.cloudkitty.rating.update_module(module_id='hashmap', enabled=True) + rating = self.cloudkitty.rating + rating.update_module(module_id='hashmap', enabled=True) - hashmap = self.cloudkitty.rating.get_module(module_id='hashmap') + hashmap = rating.get_module(module_id='hashmap') assert hashmap.get('enabled') + + def test_402_service_create_and_delete(self): + """Test service create and delete via API.""" + hashmap = self.cloudkitty.rating.hashmap + service = hashmap.create_service(name='test') + + assert service['name'] == 'test' + + service_id = service['service_id'] + hashmap.delete_service(service_id=service_id) + + def test_403_field_create_and_delete(self): + """Test field create and delete via API.""" + hashmap = self.cloudkitty.rating.hashmap + service = hashmap.create_service(name='test') + + service_id = service['service_id'] + field = hashmap.create_field(name='test', service_id=service_id) + + field_id = field['field_id'] + hashmap.delete_field(field_id=field_id) + hashmap.delete_service(service_id=service_id) + + def test_404_mapping_create_and_delete(self): + """Test mapping create and delete via API.""" + hashmap = self.cloudkitty.rating.hashmap + service = hashmap.create_service(name='test') + + service_id = service['service_id'] + field = hashmap.create_field(name='test', service_id=service_id) + + field_id = field['field_id'] + mapping = hashmap.create_mapping( + type='flat', field_id=field_id, value='test', cost=0.1) + + mapping_id = mapping['mapping_id'] + hashmap.delete_mapping(mapping_id=mapping_id) + hashmap.delete_field(field_id=field_id) + hashmap.delete_service(service_id=service_id) From ace6e6d70bb7ca1569b4440310b9d7a861e6409a Mon Sep 17 00:00:00 2001 From: hernandanielg Date: Fri, 30 Sep 2022 07:20:58 +0000 Subject: [PATCH 4/4] added group create and delete test --- .../openstack/charm_tests/cloudkitty/tests.py | 95 +++++++++++-------- 1 file changed, 58 insertions(+), 37 deletions(-) diff --git a/zaza/openstack/charm_tests/cloudkitty/tests.py b/zaza/openstack/charm_tests/cloudkitty/tests.py index ae22d00..8e16f67 100644 --- a/zaza/openstack/charm_tests/cloudkitty/tests.py +++ b/zaza/openstack/charm_tests/cloudkitty/tests.py @@ -27,7 +27,6 @@ from cloudkittyclient import client class CloudkittyTest(test_utils.OpenStackBaseTest): """Encapsulate Cloudkitty tests.""" - CONF_FILE = '/etc/cloudkitty/cloudkitty.conf' API_VERSION = '1' @classmethod @@ -42,55 +41,77 @@ class CloudkittyTest(test_utils.OpenStackBaseTest): 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.""" - tenants_list = self.cloudkitty.report.get_tenants() + report = self.cloudkitty.report + tenants_list = report.get_tenants() assert tenants_list == [] - def test_401_module_enable(self): - """Test enabling hashmap module via API.""" - logging.info('Enabling hashmap module') + def test_401_module_enable_and_disable(self): + """Test enable and disable module via API.""" rating = self.cloudkitty.rating - rating.update_module(module_id='hashmap', enabled=True) + modules = rating.get_module() - hashmap = rating.get_module(module_id='hashmap') - assert hashmap.get('enabled') + for module in modules.get('modules'): + module_id = module.get('module_id') - def test_402_service_create_and_delete(self): - """Test service create and delete via API.""" - hashmap = self.cloudkitty.rating.hashmap - service = hashmap.create_service(name='test') + # noop module can't be disabled + if module_id == 'noop': + continue - assert service['name'] == 'test' + 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') - service_id = service['service_id'] - hashmap.delete_service(service_id=service_id) + 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_403_field_create_and_delete(self): - """Test field create and delete via API.""" - hashmap = self.cloudkitty.rating.hashmap - service = hashmap.create_service(name='test') + def test_402_create_mapping(self): + """Test mapping create via API.""" + rating = self.cloudkitty.rating - service_id = service['service_id'] - field = hashmap.create_field(name='test', service_id=service_id) + if not rating.get_module(module_id='hashmap').get('enabled'): + rating.update_module(module_id='hashmap', enabled=True) - field_id = field['field_id'] - hashmap.delete_field(field_id=field_id) - hashmap.delete_service(service_id=service_id) + hashmap = rating.hashmap - def test_404_mapping_create_and_delete(self): - """Test mapping create and delete via API.""" - hashmap = self.cloudkitty.rating.hashmap - service = hashmap.create_service(name='test') + service = hashmap.create_service(name='test-service') + service_id = service.get('service_id') - service_id = service['service_id'] - field = hashmap.create_field(name='test', service_id=service_id) + field = hashmap.create_field(name='test-field', service_id=service_id) + field_id = field.get('field_id') - field_id = field['field_id'] - mapping = hashmap.create_mapping( - type='flat', field_id=field_id, value='test', cost=0.1) + group = hashmap.create_group(name='test-group') + group_id = group.get('group_id') - mapping_id = mapping['mapping_id'] - hashmap.delete_mapping(mapping_id=mapping_id) - hashmap.delete_field(field_id=field_id) - hashmap.delete_service(service_id=service_id) + hashmap.create_mapping( + type='flat', field_id=field_id, + group_id=group_id, value='test-value', cost=0.1)