Add support for Designate client
This create a wrapper for: - getting Designate client - creating an Heat stack with a Designate Zone - get an existing Zone details Change-Id: I07d04259db9ef627570f1d5f0535599c66725fea
This commit is contained in:
parent
5ba93cff0d
commit
2efa8ec945
@ -17,6 +17,7 @@ pytest===6.2.5
|
||||
pytest-html==3.1.1
|
||||
pytest-xdist==2.2.0
|
||||
python-dateutil==2.8.0
|
||||
python-designateclient==4.4.0
|
||||
python-glanceclient==3.2.2
|
||||
python-heatclient==2.3.0
|
||||
python-ironicclient==4.6.1
|
||||
|
@ -14,6 +14,7 @@ paramiko>=2.7.2 # LGPLv2.1
|
||||
pbr>=5.5.1 # Apache-2.0
|
||||
psutil>=5.8.0 # BSD
|
||||
python-dateutil>=2.8.0 # Apache-2.0
|
||||
python-designateclient>=4.4.0 # Apache-2.0
|
||||
python-glanceclient>=3.2.2 # Apache-2.0
|
||||
python-heatclient>=2.3.0 # Apache-2.0
|
||||
python-ironicclient>=4.6.1 # Apache-2.0
|
||||
|
25
tobiko/openstack/designate/__init__.py
Normal file
25
tobiko/openstack/designate/__init__.py
Normal file
@ -0,0 +1,25 @@
|
||||
# Copyright 2022 Red Hat
|
||||
#
|
||||
# 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 tobiko.openstack.designate import _client
|
||||
from tobiko.openstack.designate import _zone
|
||||
|
||||
DesignateClientFixture = _client.DesignateClientFixture
|
||||
designate_client = _client.designate_client
|
||||
get_designate_client = _client.get_designate_client
|
||||
DESIGNATE_CLIENT_CLASSES = _client.DESIGNATE_CLIENT_CLASSES
|
||||
|
||||
designate_zone_id = _zone.designate_zone_id
|
||||
get_designate_zone = _zone.get_designate_zone
|
69
tobiko/openstack/designate/_client.py
Normal file
69
tobiko/openstack/designate/_client.py
Normal file
@ -0,0 +1,69 @@
|
||||
# Copyright 2019 Red Hat
|
||||
#
|
||||
# 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
|
||||
|
||||
import typing
|
||||
|
||||
from designateclient.v2 import client
|
||||
|
||||
import tobiko
|
||||
from tobiko.openstack import _client
|
||||
|
||||
|
||||
DESIGNATE_CLIENT_CLASSES = client.Client,
|
||||
|
||||
|
||||
class DesignateClientFixture(_client.OpenstackClientFixture):
|
||||
|
||||
def init_client(self, session) -> client.Client:
|
||||
return client.Client(session=session)
|
||||
|
||||
|
||||
class DesignateClientManager(_client.OpenstackClientManager):
|
||||
|
||||
def create_client(self, session) -> DesignateClientFixture:
|
||||
return DesignateClientFixture(session=session)
|
||||
|
||||
|
||||
CLIENTS = DesignateClientManager()
|
||||
|
||||
DesignateClientType = typing.Union[client.Client, DesignateClientFixture]
|
||||
|
||||
|
||||
def designate_client(obj: DesignateClientType = None):
|
||||
if obj is None:
|
||||
return get_designate_client()
|
||||
|
||||
if isinstance(obj, client.Client):
|
||||
return obj
|
||||
|
||||
fixture = tobiko.setup_fixture(obj)
|
||||
if isinstance(fixture, DesignateClientFixture):
|
||||
return fixture.client
|
||||
|
||||
message = "Object {!r} is not an OctaviaClientFixture".format(obj)
|
||||
raise TypeError(message)
|
||||
|
||||
|
||||
def get_designate_client(session=None,
|
||||
shared=True,
|
||||
init_client=None,
|
||||
manager: DesignateClientManager = None) \
|
||||
-> client.Client:
|
||||
manager = manager or CLIENTS
|
||||
fixture = manager.get_client(session=session,
|
||||
shared=shared,
|
||||
init_client=init_client)
|
||||
tobiko.setup_fixture(fixture)
|
||||
return fixture.client
|
38
tobiko/openstack/designate/_zone.py
Normal file
38
tobiko/openstack/designate/_zone.py
Normal file
@ -0,0 +1,38 @@
|
||||
# Copyright 2022 Red Hat
|
||||
#
|
||||
# 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 collections import abc
|
||||
import typing
|
||||
|
||||
from tobiko.openstack.designate import _client
|
||||
|
||||
DesignateZone = typing.Mapping[str, typing.Any]
|
||||
DesignateZoneType = typing.Union[str, typing.Mapping[str, typing.Any]]
|
||||
|
||||
|
||||
def designate_zone_id(zone: DesignateZoneType) -> str:
|
||||
if isinstance(zone, str):
|
||||
return zone
|
||||
elif isinstance(zone, abc.Mapping):
|
||||
return zone['id']
|
||||
else:
|
||||
raise TypeError(f'{zone} object is an invalid Designate zone type')
|
||||
|
||||
|
||||
def get_designate_zone(zone: str,
|
||||
client: _client.DesignateClientType = None) \
|
||||
-> DesignateZone:
|
||||
zone_id = designate_zone_id(zone)
|
||||
return _client.designate_client(client).zones.get(zone_id)
|
@ -17,6 +17,7 @@ from __future__ import absolute_import
|
||||
|
||||
from tobiko.openstack.stacks import _centos
|
||||
from tobiko.openstack.stacks import _cirros
|
||||
from tobiko.openstack.stacks import _designate
|
||||
from tobiko.openstack.stacks import _fedora
|
||||
from tobiko.openstack.stacks import _redhat
|
||||
from tobiko.openstack.stacks import _l3ha
|
||||
@ -47,6 +48,8 @@ EvacuableServerStackFixture = _cirros.EvacuableServerStackFixture
|
||||
ExtraDhcpOptsCirrosServerStackFixture = (
|
||||
_cirros.ExtraDhcpOptsCirrosServerStackFixture)
|
||||
|
||||
DesignateZoneStackFixture = _designate.DesignateZoneStackFixture
|
||||
|
||||
FedoraFlavorStackFixture = _fedora.FedoraFlavorStackFixture
|
||||
FedoraImageFixture = _fedora.FedoraImageFixture
|
||||
FedoraServerStackFixture = _fedora.FedoraServerStackFixture
|
||||
|
35
tobiko/openstack/stacks/_designate.py
Normal file
35
tobiko/openstack/stacks/_designate.py
Normal file
@ -0,0 +1,35 @@
|
||||
# Copyright (c) 2022 Red Hat, Inc.
|
||||
#
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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
|
||||
|
||||
import typing
|
||||
|
||||
import tobiko
|
||||
from tobiko.openstack import designate
|
||||
from tobiko.openstack import heat
|
||||
from tobiko.openstack.stacks import _hot
|
||||
|
||||
|
||||
class DesignateZoneStackFixture(heat.HeatStackFixture):
|
||||
template = _hot.heat_template_file('designate/zone.yaml')
|
||||
|
||||
@property
|
||||
def zone_name(self) -> str:
|
||||
return tobiko.get_fixture_name(self).lower() + '.'
|
||||
|
||||
@property
|
||||
def zone_details(self) -> typing.Mapping[str, typing.Any]:
|
||||
return designate.get_designate_zone(self.zone_id)
|
32
tobiko/openstack/stacks/designate/zone.yaml
Normal file
32
tobiko/openstack/stacks/designate/zone.yaml
Normal file
@ -0,0 +1,32 @@
|
||||
heat_template_version: newton
|
||||
|
||||
description: A Zone
|
||||
|
||||
parameters:
|
||||
zone_description:
|
||||
type: string
|
||||
default: Zone used by Tobiko test cases
|
||||
|
||||
zone_email:
|
||||
type: string
|
||||
description: The zone adimistrator e-mail
|
||||
default: info@tobiko.org
|
||||
|
||||
zone_name:
|
||||
type: string
|
||||
description: The zone domain name
|
||||
default: tobiko.org.
|
||||
|
||||
|
||||
resources:
|
||||
zone:
|
||||
type: OS::Designate::Zone
|
||||
properties:
|
||||
description: {get_param: zone_description}
|
||||
email: { get_param: zone_email }
|
||||
name: { get_param: zone_name }
|
||||
|
||||
outputs:
|
||||
zone_id:
|
||||
description: Zone ID
|
||||
value: { get_resource: zone }
|
49
tobiko/tests/functional/openstack/test_designate.py
Normal file
49
tobiko/tests/functional/openstack/test_designate.py
Normal file
@ -0,0 +1,49 @@
|
||||
# Copyright (c) 2019 Red Hat, Inc.
|
||||
#
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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 collections import abc
|
||||
|
||||
import testtools
|
||||
|
||||
import tobiko
|
||||
from tobiko.openstack import keystone
|
||||
from tobiko.openstack import designate
|
||||
from tobiko.openstack import stacks
|
||||
|
||||
|
||||
@keystone.skip_unless_has_keystone_credentials()
|
||||
@keystone.skip_if_missing_service(name='designate')
|
||||
class DesignateClientTest(testtools.TestCase):
|
||||
|
||||
stack = tobiko.required_fixture(stacks.DesignateZoneStackFixture)
|
||||
|
||||
def test_get_designate_client(self):
|
||||
client = designate.get_designate_client()
|
||||
self.assertIsInstance(client, designate.DESIGNATE_CLIENT_CLASSES)
|
||||
|
||||
def test_get_designate_zone(self):
|
||||
zone = designate.get_designate_zone(self.stack.zone_id)
|
||||
self.assertIsInstance(zone, abc.Mapping)
|
||||
self.assertEqual(zone['id'], self.stack.zone_id)
|
||||
self.assertEqual(zone['name'], self.stack.zone_name)
|
||||
self.assertEqual(zone, self.stack.zone_details)
|
||||
|
||||
def test_designate_zone_id(self):
|
||||
self.assertEqual('some-id',
|
||||
designate.designate_zone_id('some-id'))
|
||||
self.assertEqual('some-id',
|
||||
designate.designate_zone_id({'id': 'some-id'}))
|
Loading…
x
Reference in New Issue
Block a user