| 1 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 |
# not use this file except in compliance with the License. You may obtain |
| 3 |
# a copy of the License at |
| 4 |
# |
| 5 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 |
# |
| 7 |
# Unless required by applicable law or agreed to in writing, software |
| 8 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 |
# License for the specific language governing permissions and limitations |
| 11 |
# under the License. |
| 12 |
|
| 13 |
import abc |
| 14 |
from urllib import parse |
| 15 |
|
| 16 |
from tempest.lib.common import rest_client |
| 17 |
|
| 18 |
from magnum_tempest_plugin.common import config |
| 19 |
|
| 20 |
|
| 21 |
class MagnumClient(rest_client.RestClient, metaclass=abc.ABCMeta): |
| 22 |
"""Abstract class responsible for setting up auth provider""" |
| 23 |
|
| 24 |
def __init__(self, auth_provider, **kwargs): |
| 25 |
service = kwargs.pop( |
| 26 |
"service" |
| 27 |
) if "service" in kwargs else 'container-infra' |
| 28 |
region = kwargs.pop( |
| 29 |
"region" |
| 30 |
) if "region" in kwargs else config.Config.region |
| 31 |
disable_validation = kwargs.pop( |
| 32 |
"disable_ssl_certificate_validation" |
| 33 |
) if "disable_ssl_certificate_validation" in kwargs else True |
| 34 |
super(MagnumClient, self).__init__( |
| 35 |
auth_provider=auth_provider, |
| 36 |
service=service, |
| 37 |
region=region, |
| 38 |
disable_ssl_certificate_validation=disable_validation, |
| 39 |
**kwargs |
| 40 |
) |
| 41 |
|
| 42 |
@classmethod |
| 43 |
def deserialize(cls, resp, body, model_type): |
| 44 |
return resp, model_type.from_json(body) |
| 45 |
|
| 46 |
@property |
| 47 |
def tenant_id(self): |
| 48 |
return self.client.tenant_id |
| 49 |
|
| 50 |
@classmethod |
| 51 |
def add_filters(cls, url, filters): |
| 52 |
"""add_filters adds dict values (filters) to url as query parameters |
| 53 |
|
| 54 |
:param url: base URL for the request |
| 55 |
:param filters: dict with var:val pairs to add as parameters to URL |
| 56 |
:returns: url string |
| 57 |
""" |
| 58 |
return url + "?" + parse(filters) |