Paul Glass 374970cd10 Flesh out zone-related test cases
Change-Id: I387179b0c8f80e87436be0dc841a47f0b0aed598
2015-10-12 21:08:39 +00:00

81 lines
2.8 KiB
Python

"""
Copyright 2015 Rackspace
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 fixtures
from tempest_lib.exceptions import CommandFailed
from designateclient.functionaltests.client import DesignateCLI
class BaseFixture(fixtures.Fixture):
def __init__(self, user='default', *args, **kwargs):
"""args/kwargs are forwarded to a create method on DesignateCLI"""
super(BaseFixture, self).__init__()
self.args = args
self.kwargs = kwargs
self.client = DesignateCLI.as_user(user)
class ZoneFixture(BaseFixture):
"""See DesignateCLI.zone_create for __init__ args"""
def _setUp(self):
super(ZoneFixture, self)._setUp()
self.zone = self.client.zone_create(*self.args, **self.kwargs)
self.addCleanup(self.cleanup_zone, self.client, self.zone.id)
@classmethod
def cleanup_zone(cls, client, zone_id):
try:
client.zone_delete(zone_id)
except CommandFailed:
pass
class TransferRequestFixture(BaseFixture):
"""See DesignateCLI.zone_transfer_request_create for __init__ args"""
def __init__(self, zone, user='default', target_user='alt', *args,
**kwargs):
super(TransferRequestFixture, self).__init__(user, *args, **kwargs)
self.zone = zone
self.target_client = DesignateCLI.as_user(target_user)
# the client has a bug such that it requires --target-project-id.
# when this bug is fixed, please remove this
self.kwargs['target_project_id'] = self.target_client.project_id
def _setUp(self):
super(TransferRequestFixture, self)._setUp()
self.transfer_request = self.client.zone_transfer_request_create(
zone_id=self.zone.id,
*self.args, **self.kwargs
)
self.addCleanup(self.cleanup_transfer_request, self.client,
self.transfer_request.id)
self.addCleanup(ZoneFixture.cleanup_zone, self.client, self.zone.id)
self.addCleanup(ZoneFixture.cleanup_zone, self.target_client,
self.zone.id)
@classmethod
def cleanup_transfer_request(cls, client, transfer_request_id):
try:
client.zone_transfer_request_delete(transfer_request_id)
except CommandFailed:
pass