Merge "New scenario test case for TLD + re-factoring"

This commit is contained in:
Zuul 2022-05-11 15:36:24 +00:00 committed by Gerrit Code Review
commit 402767b78c
6 changed files with 139 additions and 73 deletions

View File

@ -51,8 +51,10 @@ DnsGroup = [
help="The timeout on a single dns query to a nameserver"),
cfg.StrOpt('zone_id',
help="The target zone to test the dns recordsets "
"If it is not specified, a new zone will be created ")
"If it is not specified, a new zone will be created "),
cfg.StrOpt('tld_suffix',
default='com',
help="TLD suffix that used in all tests (if not overridden)")
]
dns_feature_group = cfg.OptGroup(name='dns_feature_enabled',

View File

@ -35,7 +35,7 @@ def rand_ipv6():
return an.format(netaddr.ipv6_compact)
def rand_zone_name(name='', prefix='rand', suffix='.com.'):
def rand_zone_name(name='', prefix='rand', suffix=None):
"""Generate a random zone name
:param str name: The name that you want to include
:param prefix: the exact text to start the string. Defaults to "rand"
@ -43,6 +43,8 @@ def rand_zone_name(name='', prefix='rand', suffix='.com.'):
:return: a random zone name e.g. example.org.
:rtype: string
"""
if suffix is None:
suffix = '.{}.'.format(CONF.dns.tld_suffix)
name = data_utils.rand_name(name=name, prefix=prefix)
return name + suffix
@ -67,7 +69,6 @@ def rand_ttl(start=1, end=86400):
def rand_zonefile_data(name=None, ttl=None):
"""Generate random zone data, with optional overrides
:return: A ZoneModel
"""
zone_base = ('$ORIGIN &\n& # IN SOA ns.& nsadmin.& # # # # #\n'
@ -105,11 +106,11 @@ def rand_quotas(zones=None, zone_records=None, zone_recordsets=None,
def rand_zone_data(name=None, email=None, ttl=None, description=None):
"""Generate random zone data, with optional overrides
:return: A ZoneModel
"""
if name is None:
name = rand_zone_name(prefix='testdomain', suffix='.com.')
name = rand_zone_name(
prefix='testdomain', suffix='.{}.'.format(CONF.dns.tld_suffix))
if email is None:
email = ("admin@" + name).strip('.')
if description is None:
@ -126,7 +127,6 @@ def rand_zone_data(name=None, email=None, ttl=None, description=None):
def rand_recordset_data(record_type, zone_name, name=None, records=None,
ttl=None):
"""Generate random recordset data, with optional overrides
:return: A RecordsetModel
"""
if name is None:
@ -202,7 +202,7 @@ def rand_txt_recordset(zone_name, data=None, **kwargs):
def wildcard_ns_recordset(zone_name):
name = "*.{0}".format(zone_name)
records = ["ns.example.com."]
records = ["ns.example.{}.".format(CONF.dns.tld_suffix)]
return rand_recordset_data('NS', zone_name, name, records)
@ -225,7 +225,6 @@ def rand_tld():
def rand_transfer_request_data(description=None, target_project_id=None):
"""Generate random transfer request data, with optional overrides
:return: A TransferRequest data
"""
@ -255,7 +254,6 @@ def make_rand_recordset(zone_name, record_type):
"""Create a rand recordset by type
This essentially just dispatches to the relevant random recordset
creation functions.
:param str zone_name: The zone name the recordset applies to
:param str record_type: The type of recordset (ie A, MX, NS, etc...)
"""
@ -266,7 +264,6 @@ def make_rand_recordset(zone_name, record_type):
def rand_string(size):
"""Create random string of ASCII chars by size
:param int size - length os the string to be create
:return - random creates string of ASCII lover characters
"""
@ -275,7 +272,6 @@ def rand_string(size):
def rand_domain_name(tld=None):
"""Create random valid domain name
:param tld (optional) - TLD that will be used to random domain name
:return - valid domain name, for example: paka.zbabun.iuh
"""

View File

@ -38,7 +38,7 @@ class BaseRecordsetsTest(base.BaseDnsV2Test):
# All the recordset tests need a zone, create one to share
LOG.info('Create a zone')
_, cls.zone = cls.zone_client.create_zone()
cls.zone = cls.zone_client.create_zone()[1]
@classmethod
def resource_cleanup(cls):
@ -127,16 +127,18 @@ class RecordsetsTest(BaseRecordsetsTest):
@decorators.idempotent_id('6c22a3f9-3f4d-4b32-bdf2-5237851ed25e')
def test_create_recordset_type_SRV_TCP(self):
self._test_create_recordset_type(
"_sip._tcp", "SRV", ["10 60 5060 server1.example.com.",
"20 60 5060 server2.example.com.",
"20 30 5060 server3.example.com."])
"_sip._tcp", "SRV", [
"10 60 5060 server1.example.{}.".format(self.tld_suffix),
"20 60 5060 server2.example.{}.".format(self.tld_suffix),
"20 30 5060 server3.example.{}.".format(self.tld_suffix)])
@decorators.idempotent_id('59c1aa42-278e-4f7b-a6a1-4320d5daf1fd')
def test_create_recordset_type_SRV_UDP(self):
self._test_create_recordset_type(
"_sip._udp", "SRV", ["10 60 5060 server1.example.com.",
"10 60 5060 server2.example.com.",
"20 30 5060 server3.example.com."])
"_sip._udp", "SRV", [
"10 60 5060 server1.example.{}.".format(self.tld_suffix),
"10 60 5060 server2.example.{}.".format(self.tld_suffix),
"20 30 5060 server3.example.{}.".format(self.tld_suffix)])
@decorators.idempotent_id('1ac46f94-f03a-4f85-b84f-826a2660b927')
def test_create_recordset_type_CNAME(self):
@ -201,7 +203,7 @@ class RecordsetsTest(BaseRecordsetsTest):
self.zone['id'], body['id'])
LOG.info('List zone recordsets')
_, body = self.client.list_recordset(self.zone['id'])
body = self.client.list_recordset(self.zone['id'])[1]
self.assertGreater(len(body), 0)
@ -218,7 +220,7 @@ class RecordsetsTest(BaseRecordsetsTest):
self.zone['id'], body['id'])
LOG.info('Re-Fetch the Recordset')
_, record = self.client.show_recordset(self.zone['id'], body['id'])
record = self.client.show_recordset(self.zone['id'], body['id'])[1]
LOG.info('Ensure the fetched response matches the expected one')
self.assertExpected(body, record, self.excluded_keys)
@ -229,14 +231,14 @@ class RecordsetsTest(BaseRecordsetsTest):
record_type='A', zone_name=self.zone['name'])
LOG.info('Create a Recordset')
_, record = self.client.create_recordset(
self.zone['id'], recordset_data)
record = self.client.create_recordset(
self.zone['id'], recordset_data)[1]
self.addCleanup(
self.wait_recordset_delete, self.client,
self.zone['id'], record['id'])
LOG.info('Delete a Recordset')
_, body = self.client.delete_recordset(self.zone['id'], record['id'])
self.client.delete_recordset(self.zone['id'], record['id'])
LOG.info('Ensure successful deletion of Recordset')
self.assertRaises(lib_exc.NotFound,
@ -248,8 +250,8 @@ class RecordsetsTest(BaseRecordsetsTest):
record_type='A', zone_name=self.zone['name'])
LOG.info('Create a recordset')
_, record = self.client.create_recordset(
self.zone['id'], recordset_data)
record = self.client.create_recordset(
self.zone['id'], recordset_data)[1]
self.addCleanup(
self.wait_recordset_delete, self.client,
self.zone['id'], record['id'])
@ -258,8 +260,8 @@ class RecordsetsTest(BaseRecordsetsTest):
record_type='A', zone_name=self.zone['name'], name=record['name'])
LOG.info('Update the recordset')
_, update = self.client.update_recordset(self.zone['id'],
record['id'], recordset_data)
update = self.client.update_recordset(self.zone['id'],
record['id'], recordset_data)[1]
self.assertEqual(record['name'], update['name'])
self.assertNotEqual(record['records'], update['records'])
@ -270,8 +272,8 @@ class RecordsetsTest(BaseRecordsetsTest):
record_type='A', zone_name=self.zone['name'])
LOG.info('Create a recordset')
_, record = self.client.create_recordset(
self.zone['id'], recordset_data)
record = self.client.create_recordset(
self.zone['id'], recordset_data)[1]
self.addCleanup(
self.wait_recordset_delete, self.client,
self.zone['id'], record['id'])
@ -281,8 +283,8 @@ class RecordsetsTest(BaseRecordsetsTest):
}
LOG.info('Update the recordset')
_, update = self.client.update_recordset(self.zone['id'],
record['id'], recordset_data)
update = self.client.update_recordset(self.zone['id'],
record['id'], recordset_data)[1]
self.assertEqual(record['name'], update['name'])
self.assertEqual(record['records'], update['records'])
@ -442,7 +444,7 @@ class RecordsetsNegativeTest(BaseRecordsetsTest):
@decorators.idempotent_id('b6dad57e-5ce9-4fa5-8d66-aebbcd23b4ad')
def test_get_nonexistent_recordset(self):
LOG.info('Create a zone')
_, zone = self.zone_client.create_zone()
zone = self.zone_client.create_zone()[1]
self.addCleanup(self.wait_zone_delete, self.zone_client, zone['id'])
LOG.info('Attempt to get an invalid Recordset')
@ -453,7 +455,7 @@ class RecordsetsNegativeTest(BaseRecordsetsTest):
@decorators.idempotent_id('93d744a8-0dfd-4650-bcef-1e6ad632ad72')
def test_get_nonexistent_recordset_invalid_id(self):
LOG.info('Create a zone')
_, zone = self.zone_client.create_zone()
zone = self.zone_client.create_zone()[1]
self.addCleanup(self.wait_zone_delete, self.zone_client, zone['id'])
LOG.info('Attempt to get an invalid Recordset')
@ -463,7 +465,7 @@ class RecordsetsNegativeTest(BaseRecordsetsTest):
@decorators.idempotent_id('da08f19a-7f10-47cc-8b41-994507190812')
def test_update_nonexistent_recordset(self):
LOG.info('Create a zone')
_, zone = self.zone_client.create_zone()
zone = self.zone_client.create_zone()[1]
self.addCleanup(self.wait_zone_delete, self.zone_client, zone['id'])
recordset_data = data_utils.rand_recordset_data('A', zone['name'])
@ -477,7 +479,7 @@ class RecordsetsNegativeTest(BaseRecordsetsTest):
@decorators.idempotent_id('158340a1-3f69-4aaa-9968-956190563768')
def test_update_nonexistent_recordset_invalid_id(self):
LOG.info('Create a zone')
_, zone = self.zone_client.create_zone()
zone = self.zone_client.create_zone()[1]
self.addCleanup(self.wait_zone_delete, self.zone_client, zone['id'])
recordset_data = data_utils.rand_recordset_data('A', zone['name'])
@ -490,7 +492,7 @@ class RecordsetsNegativeTest(BaseRecordsetsTest):
@decorators.idempotent_id('64bd94d4-54bd-4bee-b6fd-92ede063234e')
def test_delete_nonexistent_recordset(self):
LOG.info('Create a zone')
_, zone = self.zone_client.create_zone()
zone = self.zone_client.create_zone()[1]
self.addCleanup(self.wait_zone_delete, self.zone_client, zone['id'])
LOG.info('Attempt to delete an invalid Recordset')
@ -502,7 +504,7 @@ class RecordsetsNegativeTest(BaseRecordsetsTest):
@decorators.idempotent_id('5948b599-a332-4dcb-840b-afc825075ba3')
def test_delete_nonexistent_recordset_invalid_id(self):
LOG.info('Create a zone')
_, zone = self.zone_client.create_zone()
zone = self.zone_client.create_zone()[1]
self.addCleanup(self.wait_zone_delete, self.zone_client, zone['id'])
LOG.info('Attempt to get an invalid Recordset')
@ -578,7 +580,7 @@ class RootRecordsetsTests(BaseRecordsetsTest):
@decorators.idempotent_id('48a081b9-4474-4da0-9b1a-6359a80456ce')
def test_list_zones_recordsets(self):
LOG.info('List recordsets')
_, body = self.client.list_zones_recordsets()
body = self.client.list_zones_recordsets()[1]
self.assertGreater(len(body['recordsets']), 0)
@ -609,7 +611,7 @@ class RootRecordsetsTests(BaseRecordsetsTest):
self.zone['id'], zone_recordset['id'])
LOG.info('Create another zone')
_, zone2 = self.zone_client.create_zone()
zone2 = self.zone_client.create_zone()[1]
self.addCleanup(self.wait_zone_delete, self.zone_client, zone2['id'])
LOG.info('Create another Recordset')
@ -623,7 +625,7 @@ class RootRecordsetsTests(BaseRecordsetsTest):
self.zone['id'], zone_recordset2['id'])
LOG.info('List recordsets')
_, body = self.client.list_zones_recordsets(params={"data": "10.0.*"})
body = self.client.list_zones_recordsets(params={"data": "10.0.*"})[1]
recordsets = body['recordsets']
@ -641,11 +643,11 @@ class RootRecordsetsTests(BaseRecordsetsTest):
@decorators.idempotent_id('7f4970bf-9aeb-4a3c-9afd-02f5a7178d35')
def test_list_zones_recordsets_zone_names(self):
LOG.info('Create another zone')
_, zone2 = self.zone_client.create_zone()
zone2 = self.zone_client.create_zone()[1]
self.addCleanup(self.wait_zone_delete, self.zone_client, zone2['id'])
LOG.info('List recordsets')
_, body = self.client.list_zones_recordsets()
body = self.client.list_zones_recordsets()[1]
recordsets = body['recordsets']
zone_names = set()
@ -763,7 +765,7 @@ class RecordsetOwnershipTest(BaseRecordsetsTest):
zone_name = data_utils.rand_zone_name()
LOG.info('Create a zone as a default user')
_, zone = self.zone_client.create_zone(name='a.b.' + zone_name)
zone = self.zone_client.create_zone(name='a.b.' + zone_name)[1]
self.addCleanup(self.wait_zone_delete, self.zone_client, zone['id'])
rrset_data = data_utils.rand_recordset_data(
@ -777,8 +779,8 @@ class RecordsetOwnershipTest(BaseRecordsetsTest):
@decorators.idempotent_id('3dbe244d-fa85-4afc-869b-0306388d8746')
def test_no_create_recordset_via_alt_domain(self):
_, zone = self.zone_client.create_zone()
_, alt_zone = self.alt_zone_client.create_zone()
zone = self.zone_client.create_zone()[1]
alt_zone = self.alt_zone_client.create_zone()[1]
self.addCleanup(self.wait_zone_delete,
self.zone_client,
zone['id'])

View File

@ -51,7 +51,7 @@ class TldAdminTest(BaseTldTest):
def resource_setup(cls):
super(TldAdminTest, cls).resource_setup()
cls.tld = cls.admin_client.create_tld(
tld_name='com', ignore_errors=lib_exc.Conflict
tld_name=cls.tld_suffix, ignore_errors=lib_exc.Conflict
)
@classmethod
@ -66,8 +66,8 @@ class TldAdminTest(BaseTldTest):
"description": "sample tld"}
LOG.info('Create a tld')
_, tld = self.admin_client.create_tld(tld_data['name'],
tld_data['description'])
tld = self.admin_client.create_tld(tld_data['name'],
tld_data['description'])[1]
self.addCleanup(self.admin_client.delete_tld, tld['id'])
self.assertEqual(tld_data["name"], tld['name'])
@ -116,21 +116,6 @@ class TldAdminTest(BaseTldTest):
lib_exc.BadRequest, self.admin_client.create_tld,
tld_name='org', description='test_create_invalid_tld' * 1000)
@decorators.idempotent_id('06deced8-d4de-11eb-b8ee-74e5f9e2a801')
def test_create_zone_for_not_existing_tld(self):
LOG.info('Create an "org" TLD')
tld_data = {"name": "org",
"description": "test_create_zone_for_not_existing_tld"}
tld = self.admin_client.create_tld(
tld_data['name'], tld_data['description'])[1]
self.addCleanup(self.admin_client.delete_tld, tld['id'])
self.assertEqual(tld_data["name"], tld['name'])
LOG.info('Try to create a Primary zone with "zzz" (not existing) TLD.')
self.assertRaises(
lib_exc.BadRequest, self.primary_zone_client.create_zone,
name='example.zzz.')
@decorators.idempotent_id('757019c0-d4e2-11eb-b8ee-74e5f9e2a801')
def test_create_tld_as_primary_user(self):
tld_data = {
@ -147,12 +132,12 @@ class TldAdminTest(BaseTldTest):
"description": "sample tld"}
LOG.info('Create a tld')
_, tld = self.admin_client.create_tld(tld_data['name'],
tld_data['description'])
tld = self.admin_client.create_tld(tld_data['name'],
tld_data['description'])[1]
self.addCleanup(self.admin_client.delete_tld, tld['id'])
LOG.info('Fetch the tld')
_, body = self.admin_client.show_tld(tld['id'])
body = self.admin_client.show_tld(tld['id'])[1]
LOG.info('Ensure the fetched response matches the created tld')
self.assertExpected(tld, body, self.excluded_keys)
@ -160,12 +145,12 @@ class TldAdminTest(BaseTldTest):
@decorators.idempotent_id('26708cb8-7126-48a7-9424-1c225e56e609')
def test_delete_tld(self):
LOG.info('Create a tld')
_, tld = self.admin_client.create_tld()
tld = self.admin_client.create_tld()[1]
self.addCleanup(self.admin_client.delete_tld, tld['id'],
ignore_errors=lib_exc.NotFound)
LOG.info('Delete the tld')
_, body = self.admin_client.delete_tld(tld['id'])
self.admin_client.delete_tld(tld['id'])
self.assertRaises(lib_exc.NotFound,
lambda: self.admin_client.show_tld(tld['id']))
@ -173,13 +158,13 @@ class TldAdminTest(BaseTldTest):
@decorators.idempotent_id('95b13759-c85c-4791-829b-9591ca15779d')
def test_list_tlds(self):
LOG.info('List tlds')
_, body = self.admin_client.list_tlds()
body = self.admin_client.list_tlds()[1]
self.assertGreater(len(body['tlds']), 0)
@decorators.idempotent_id('1a233812-48d9-4d15-af5e-9961744286ff')
def test_update_tld(self):
_, tld = self.admin_client.create_tld()
tld = self.admin_client.create_tld()[1]
self.addCleanup(self.admin_client.delete_tld, tld['id'])
tld_data = {
@ -188,8 +173,8 @@ class TldAdminTest(BaseTldTest):
}
LOG.info('Update the tld')
_, patch_tld = self.admin_client.update_tld(tld['id'],
tld_data['name'], tld_data['description'])
patch_tld = self.admin_client.update_tld(tld['id'],
tld_data['name'], tld_data['description'])[1]
self.assertEqual(tld_data["name"], patch_tld["name"])
self.assertEqual(tld_data["description"], patch_tld["description"])

View File

@ -163,6 +163,7 @@ class BaseDnsV2Test(BaseDnsTest):
"""Base class for DNS V2 API tests."""
all_projects_header = {'X-Auth-All-Projects': True}
tld_suffix = CONF.dns.tld_suffix
@classmethod
def skip_checks(cls):

View File

@ -0,0 +1,80 @@
# Copyright 2021 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 oslo_log import log as logging
from tempest import config
from tempest.lib import decorators
from tempest.lib import exceptions as lib_exc
from designate_tempest_plugin.common import constants as const
from designate_tempest_plugin.tests import base
from designate_tempest_plugin import data_utils as dns_data_utils
CONF = config.CONF
LOG = logging.getLogger(__name__)
class TldZoneTest(base.BaseDnsV2Test):
credentials = ["admin", "system_admin", "primary"]
@classmethod
def setup_credentials(cls):
# Do not create network resources for these test.
cls.set_network_resources()
super(TldZoneTest, cls).setup_credentials()
@classmethod
def setup_clients(cls):
super(TldZoneTest, cls).setup_clients()
if CONF.enforce_scope.designate:
cls.admin_tld_client = cls.os_system_admin.dns_v2.TldClient()
else:
cls.admin_tld_client = cls.os_admin.dns_v2.TldClient()
cls.primary_tld_client = cls.os_primary.dns_v2.TldClient()
cls.primary_zone_client = cls.os_primary.dns_v2.ZonesClient()
@classmethod
def resource_setup(cls):
super(TldZoneTest, cls).resource_setup()
cls.tld = cls.admin_tld_client.create_tld(
tld_name=cls.tld_suffix, ignore_errors=lib_exc.Conflict
)
@classmethod
def resource_cleanup(cls):
cls.admin_tld_client.delete_tld(cls.tld[1]['id'])
super(TldZoneTest, cls).resource_cleanup()
@decorators.idempotent_id('68b3e7cc-bf0e-11ec-b803-201e8823901f')
def test_create_zone_using_existing_tld(self):
LOG.info('Creates a zone using existing TLD:"{}"'.format(
self.tld_suffix))
zone_name = dns_data_utils.rand_zone_name(
name='existing_tld_zone', prefix='rand',
suffix='.{}.'.format(self.tld_suffix))
zone = self.primary_zone_client.create_zone(
name=zone_name, wait_until=const.ACTIVE)[1]
self.addCleanup(
self.wait_zone_delete, self.primary_zone_client, zone['id'])
@decorators.idempotent_id('06deced8-d4de-11eb-b8ee-74e5f9e2a801')
def test_create_zone_using_not_existing_tld(self):
LOG.info('Try to create a Zone using not existing TLD:"{}"'.format(
self.tld_suffix[::-1]))
zone_name = dns_data_utils.rand_zone_name(
name='not_existing_tld_zone', prefix='rand',
suffix='.{}.'.format(self.tld_suffix)[::-1])
self.assertRaises(
lib_exc.BadRequest, self.primary_zone_client.create_zone,
name=zone_name)