| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# Copyright 2017 Objectif Libre |
| 3 |
# |
| 4 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 |
# not use this file except in compliance with the License. You may obtain |
| 6 |
# a copy of the License at |
| 7 |
# |
| 8 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
# |
| 10 |
# Unless required by applicable law or agreed to in writing, software |
| 11 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 |
# License for the specific language governing permissions and limitations |
| 14 |
# under the License. |
| 15 |
# |
| 16 |
|
| 17 |
from tempest import config |
| 18 |
from tempest.lib import exceptions |
| 19 |
import tempest.test |
| 20 |
|
| 21 |
from cloudkitty_tempest_plugin.services import client |
| 22 |
|
| 23 |
CONF = config.CONF |
| 24 |
|
| 25 |
|
| 26 |
def skipIf(flag, reason): |
| 27 |
def decorator(f): |
| 28 |
def wrapper(self, *args, **kwargs): |
| 29 |
if getattr(self, flag): |
| 30 |
self.skipTest(reason) |
| 31 |
else: |
| 32 |
f(self, *args, **kwargs) |
| 33 |
return wrapper |
| 34 |
return decorator |
| 35 |
|
| 36 |
|
| 37 |
class BaseRatingTest(tempest.test.BaseTestCase): |
| 38 |
"""Base test class for all Rating API tests.""" |
| 39 |
client_manager = client.Manager |
| 40 |
|
| 41 |
@classmethod |
| 42 |
def setup_clients(cls): |
| 43 |
super(BaseRatingTest, cls).setup_clients() |
| 44 |
os_var = 'os_{}'.format(cls.credentials[0]) |
| 45 |
cls.rating_client = getattr(cls, os_var).get_rating_client( |
| 46 |
getattr(cls, 'api_version')) |
| 47 |
|
| 48 |
@classmethod |
| 49 |
def setup_credentials(cls): |
| 50 |
super(BaseRatingTest, cls).setup_credentials() |
| 51 |
os_var = 'os_{}'.format(cls.credentials[0]) |
| 52 |
project_id = getattr(cls, os_var).credentials.project_id |
| 53 |
cls.skip_rating_tests = False |
| 54 |
try: |
| 55 |
cls.custom_identity_client = client.CustomIdentityClient() |
| 56 |
cls.custom_identity_client.enable_rating(project_id) |
| 57 |
except Exception: |
| 58 |
cls.skip_rating_tests = True |
| 59 |
|
| 60 |
@classmethod |
| 61 |
def resource_setup(cls): |
| 62 |
super(BaseRatingTest, cls).resource_setup() |
| 63 |
cls._created_resources = { |
| 64 |
'collector_mapping': list(), |
| 65 |
'hashmap_service': list(), |
| 66 |
'hashmap_field': list(), |
| 67 |
'hashmap_mapping': list(), |
| 68 |
'hashmap_group': list(), |
| 69 |
'hashmap_threshold': list(), |
| 70 |
'pyscript': list(), |
| 71 |
} |
| 72 |
|
| 73 |
@classmethod |
| 74 |
def resource_cleanup(cls): |
| 75 |
super(BaseRatingTest, cls).resource_cleanup() |
| 76 |
for method, item_ids in cls._created_resources.items(): |
| 77 |
delete_method = 'delete_' + method |
| 78 |
delete_method = getattr(cls.rating_client, delete_method) |
| 79 |
for item_id in item_ids: |
| 80 |
try: |
| 81 |
delete_method(item_id) |
| 82 |
except (exceptions.NotFound, |
| 83 |
exceptions.UnexpectedResponseCode): |
| 84 |
pass |