From d8caefd0ae4c0154b6de4189fb5e5b3f1e83d697 Mon Sep 17 00:00:00 2001 From: Arkady Shtempler Date: Sun, 10 Apr 2022 16:21:39 +0300 Subject: [PATCH] Adds boundary scenario tests for "Project limits" values 1) test_max_zone_name_length Get project's "max_zone_name" value and try to create a zones with the name lengths of: 1. "max_zone_name" --> Expected: PASS 2. "max_zone_name +1" --> Expected: FAILED 2) test_max_recordset_name_length Get project's "max_recordset_name_length" value and try to create a recordsets with the name lengths of: 1. "max_zone_name_length" --> Expected: PASS 2. "max_zone_name_length +1" --> Expected: FAILED Change-Id: I7e54759c50551fc09f468f874a16054c15316560 --- designate_tempest_plugin/data_utils.py | 23 +++++ .../tests/scenario/v2/test_limits.py | 93 +++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 designate_tempest_plugin/tests/scenario/v2/test_limits.py diff --git a/designate_tempest_plugin/data_utils.py b/designate_tempest_plugin/data_utils.py index 4b5d24dd..ec327ac4 100644 --- a/designate_tempest_plugin/data_utils.py +++ b/designate_tempest_plugin/data_utils.py @@ -47,6 +47,27 @@ def rand_zone_name(name='', prefix='rand', suffix='.com.'): return name + suffix +def rand_dns_name_by_size(name_size, label_size=63): + """Generates label based DNS name, by given characters size + :param name_size: size in characters + :param label_size: the max number of characters to be used + for label. Max value according the RFC is 63 + https://datatracker.ietf.org/doc/html/rfc1035# + section-2.3.4in + :return: DNS name + """ + template = '' + while len(template) < name_size: + remaining_length = name_size - len(template) + template += '{}.'.format(rand_string( + min(remaining_length - 1, label_size))) + if template.endswith('..'): + raise Exception("There is no way to generate a valid DNS name " + "using provided set of values:{},{}, consider " + "changing those values".format(name_size, label_size)) + return template + + def rand_email(domain=None): """Generate a random zone name :return: a random zone name e.g. example.org. @@ -281,3 +302,5 @@ def rand_domain_name(tld=None): """ domain_tld = tld or rand_string(3) return rand_string(4) + '.' + rand_string(6) + '.' + domain_tld + '.' + + diff --git a/designate_tempest_plugin/tests/scenario/v2/test_limits.py b/designate_tempest_plugin/tests/scenario/v2/test_limits.py new file mode 100644 index 00000000..6d2c51b7 --- /dev/null +++ b/designate_tempest_plugin/tests/scenario/v2/test_limits.py @@ -0,0 +1,93 @@ +# 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 import data_utils as dns_data_utils +from designate_tempest_plugin.tests import base + +CONF = config.CONF +LOG = logging.getLogger(__name__) + + +class DesignateLimit(base.BaseDnsV2Test): + + @classmethod + def setup_clients(cls): + super(DesignateLimit, cls).setup_clients() + cls.limit_client = cls.os_primary.dns_v2.DesignateLimitClient() + cls.zone_client = cls.os_primary.dns_v2.ZonesClient() + cls.recordset_client = cls.os_primary.dns_v2.RecordsetClient() + + @classmethod + def resource_setup(cls): + cls.project_limits = cls.limit_client.list_designate_limits() + + @decorators.idempotent_id('3d1b09a2-b8be-11ec-86fe-201e8823901f') + @decorators.skip_because(bug="1974143") + def test_max_zone_name_length(self): + allowed_limit = self.project_limits['max_zone_name_length'] + + LOG.info('Zone of length:{} is successfully created'.format( + allowed_limit)) + zone_name = dns_data_utils.rand_dns_name_by_size(allowed_limit) + zone = self.zone_client.create_zone(name=zone_name)[1] + self.addCleanup(self.wait_zone_delete, self.zone_client, zone['id']) + + LOG.info('Zone of length:{} is failed to be created'.format( + allowed_limit + 1)) + zone_name = dns_data_utils.rand_dns_name_by_size(allowed_limit) + self.assertRaisesDns( + lib_exc.BadRequest, 'invalid_object', 400, + self.zone_client.create_zone, + name=zone_name + ) + + @decorators.idempotent_id('86646744-b98a-11ec-b3a4-201e8823901f') + @decorators.skip_because(bug="1974143") + def test_max_recordset_name_length(self): + allowed_limit = self.project_limits['max_recordset_name_length'] + zone_name = dns_data_utils.rand_dns_name_by_size(allowed_limit - 5) + + LOG.info('Create a zone') + zone = self.zone_client.create_zone( + name=zone_name, wait_until=const.ACTIVE)[1] + self.addCleanup(self.wait_zone_delete, self.zone_client, zone['id']) + + LOG.info('Recordset of name length:{} is successfully ' + 'created'.format(allowed_limit)) + recordset_data = dns_data_utils.rand_recordset_data( + record_type='A', + name=dns_data_utils.rand_string(4) + '.' + zone_name, + zone_name=zone['name']) + + recordset = self.recordset_client.create_recordset( + zone['id'], recordset_data)[1] + self.addCleanup( + self.wait_recordset_delete, self.recordset_client, + zone['id'], recordset['id']) + + LOG.info('Recordset of name length:{} is failed ' + 'to be created'.format(allowed_limit + 1)) + recordset_data = dns_data_utils.rand_recordset_data( + record_type='A', + name=dns_data_utils.rand_string(4) + '.' + zone_name, + zone_name=zone['name']) + self.assertRaisesDns( + lib_exc.BadRequest, 'invalid_object', 400, + self.recordset_client.create_recordset, + zone_uuid=zone['id'], + recordset_data=recordset_data)