Add functional tests for tlds

The tld tests will create/remove tlds which would cause problems
when running zone tests in parallel. To solve this, a separate tld
is created for each zone.

Change-Id: I8957f6f294bc5624ce049e36bef4a948cef3e380
This commit is contained in:
Paul Glass 2015-09-28 15:44:46 +00:00
parent 83b9cad7eb
commit a98de81298
8 changed files with 154 additions and 3 deletions

@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
"""
from tempest_lib.cli import base
from tempest_lib.exceptions import CommandFailed
from designateclient.functionaltests import client
from designateclient.functionaltests import config
@ -24,3 +25,9 @@ class BaseDesignateTest(base.ClientTestBase):
def _get_clients(self):
config.read_config()
return client.DesignateCLI.as_user('default')
def ensure_tld_exists(self, tld):
try:
self.clients.as_user('admin').tld_create(tld)
except CommandFailed:
pass

@ -191,8 +191,39 @@ class RecordsetCommands(object):
return self.parsed_cmd(cmd, *args, **kwargs)
class TLDCommands(object):
def tld_list(self, *args, **kwargs):
return self.parsed_cmd('tld list', ListModel, *args, **kwargs)
def tld_show(self, id, *args, **kwargs):
return self.parsed_cmd('tld show {0}'.format(id), FieldValueModel,
*args, **kwargs)
def tld_delete(self, id, *args, **kwargs):
return self.parsed_cmd('tld delete {0}'.format(id), *args, **kwargs)
def tld_create(self, name, description=None, *args, **kwargs):
options_str = build_option_string({
'--name': name,
'--description': description,
})
cmd = 'tld create {0}'.format(options_str)
return self.parsed_cmd(cmd, FieldValueModel, *args, **kwargs)
def tld_set(self, id, name=None, description=None, no_description=False,
*args, **kwargs):
options_str = build_option_string({
'--name': name,
'--description': description,
})
flags_str = build_flags_string({'--no-description': no_description})
cmd = 'tld set {0} {1} {2}'.format(id, options_str, flags_str)
return self.parsed_cmd(cmd, FieldValueModel, *args, **kwargs)
class DesignateCLI(base.CLIClient, ZoneCommands, ZoneTransferCommands,
RecordsetCommands):
RecordsetCommands, TLDCommands):
# instantiate this once to minimize requests to keystone
_CLIENTS = None

@ -21,8 +21,12 @@ def random_digits(n=8):
return "".join([random.choice(string.digits) for _ in range(n)])
def random_zone_name(name='testdomain'):
return "{0}{1}.com.".format(name, random_digits())
def random_tld(name='testtld'):
return "{0}{1}".format(name, random_digits())
def random_zone_name(name='testdomain', tld='com'):
return "{0}{1}.{2}.".format(name, random_digits(), tld)
def random_a_recordset_name(zone_name, recordset_name='testrecord'):

@ -96,3 +96,22 @@ class RecordsetFixture(BaseFixture):
client.recordset_delete(zone_id, recordset_id)
except CommandFailed:
pass
class TLDFixture(BaseFixture):
"""See DesignateCLI.tld_create for __init__ args"""
def __init__(self, user='admin', *args, **kwargs):
super(TLDFixture, self).__init__(user=user, *args, **kwargs)
def _setUp(self):
super(TLDFixture, self)._setUp()
self.tld = self.client.tld_create(*self.args, **self.kwargs)
self.addCleanup(self.cleanup_tld, self.client, self.tld.id)
@classmethod
def cleanup_tld(cls, client, tld_id):
try:
client.tld_delete(tld_id)
except CommandFailed:
pass

@ -26,6 +26,7 @@ class TestRecordset(BaseDesignateTest):
def setUp(self):
super(TestRecordset, self).setUp()
self.ensure_tld_exists('com')
self.zone = self.useFixture(ZoneFixture(
name=random_zone_name(),
email='test@example.com',

@ -0,0 +1,82 @@
"""
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 tempest_lib.exceptions import CommandFailed
from designateclient.functionaltests.base import BaseDesignateTest
from designateclient.functionaltests.datagen import random_tld
from designateclient.functionaltests.v2.fixtures import TLDFixture
class TestTld(BaseDesignateTest):
def setUp(self):
super(TestTld, self).setUp()
tld_name = random_tld()
self.tld = self.useFixture(TLDFixture(
name=tld_name,
description='A random tld',
)).tld
self.assertEqual(self.tld.name, tld_name)
self.assertEqual(self.tld.description, 'A random tld')
def test_tld_list(self):
tlds = self.clients.as_user('admin').tld_list()
self.assertGreater(len(tlds), 0)
def test_tld_create_and_show(self):
tld = self.clients.as_user('admin').tld_show(self.tld.id)
self.assertEqual(tld.name, self.tld.name)
self.assertEqual(tld.created_at, self.tld.created_at)
self.assertEqual(tld.id, self.tld.id)
self.assertEqual(tld.name, self.tld.name)
self.assertEqual(tld.updated_at, self.tld.updated_at)
def test_tld_delete(self):
client = self.clients.as_user('admin')
client.tld_delete(self.tld.id)
self.assertRaises(CommandFailed, client.tld_show, self.tld.id)
def test_tld_set(self):
client = self.clients.as_user('admin')
updated_name = random_tld('updated')
tld = client.tld_set(self.tld.id, name=updated_name,
description='An updated tld')
self.assertEqual(tld.description, 'An updated tld')
self.assertEqual(tld.name, updated_name)
def test_tld_set_no_description(self):
client = self.clients.as_user('admin')
tld = client.tld_set(self.tld.id, no_description=True)
self.assertEqual(tld.description, 'None')
def test_no_set_tld_with_description_and_no_description(self):
client = self.clients.as_user('admin')
self.assertRaises(CommandFailed, client.tld_set, self.tld.id,
description='An updated tld',
no_description=True)
class TestTldNegative(BaseDesignateTest):
def test_tld_invalid_commmand(self):
client = self.clients.as_user('admin')
self.assertRaises(CommandFailed, client.openstack, 'tld notacommand')
def test_tld_create_invalid_flag(self):
client = self.clients.as_user('admin')
self.assertRaises(CommandFailed, client.openstack,
'tld create --notanoption "junk"')

@ -24,6 +24,7 @@ class TestZone(BaseDesignateTest):
def setUp(self):
super(TestZone, self).setUp()
self.ensure_tld_exists('com')
self.fixture = self.useFixture(ZoneFixture(
name=random_zone_name(),
email='test@example.com',
@ -80,6 +81,10 @@ class TestZone(BaseDesignateTest):
class TestsPassingZoneFlags(BaseDesignateTest):
def setUp(self):
super(TestsPassingZoneFlags, self).setUp()
self.ensure_tld_exists('com')
def test_zone_create_primary_with_all_args(self):
zone_name = random_zone_name()
fixture = self.useFixture(ZoneFixture(

@ -28,6 +28,7 @@ class TestZoneTransferRequest(BaseDesignateTest):
def setUp(self):
super(TestZoneTransferRequest, self).setUp()
self.ensure_tld_exists('com')
fixture = self.useFixture(ZoneFixture(
name=random_zone_name(),
email='test@example.com',
@ -92,6 +93,7 @@ class TestZoneTransferAccept(BaseDesignateTest):
def setUp(self):
super(TestZoneTransferAccept, self).setUp()
self.ensure_tld_exists('com')
fixture = self.useFixture(ZoneFixture(
name=random_zone_name(),
email='test@example.com',