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
Signed-off-by: Arkady Shtempler <ashtempl@redhat.com>
diff --git a/designate_tempest_plugin/data_utils.py b/designate_tempest_plugin/data_utils.py
index 4b5d24d..8389cfd 100644
--- a/designate_tempest_plugin/data_utils.py
+++ b/designate_tempest_plugin/data_utils.py
@@ -47,6 +47,27 @@
     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.
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 0000000..19d5d26
--- /dev/null
+++ b/designate_tempest_plugin/tests/scenario/v2/test_limits.py
@@ -0,0 +1,127 @@
+# 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):
+
+    credentials = ["primary", "admin"]
+
+    @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()
+        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()
+
+    @classmethod
+    def resource_setup(cls):
+        super(DesignateLimit, cls).resource_setup()
+        cls.project_limits = cls.limit_client.list_designate_limits()
+        cls.tld = cls.admin_tld_client.create_tld(
+            tld_name=dns_data_utils.rand_string(5))[1]
+
+    @classmethod
+    def resource_cleanup(cls):
+        cls.admin_tld_client.delete_tld(cls.tld['id'])
+        super(DesignateLimit, cls).resource_cleanup()
+
+    @decorators.idempotent_id('3d1b09a2-b8be-11ec-86fe-201e8823901f')
+    def test_max_zone_name_length(self):
+        allowed_limit = self.project_limits[
+            'max_zone_name_length'] - 1  # The final root null byte
+        LOG.info(
+            'Attempting to create a Zone of length:{}, expected: zone is'
+            ' successfully created'.format(allowed_limit))
+        zone_name = dns_data_utils.rand_dns_name_by_size(allowed_limit)
+        # Use class TLD at the end of generated Zone Name
+        zone_name = zone_name[:-(
+                len(self.tld['name']) + 2)] + '.' + self.tld['name'] + '.'
+        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(
+            'Attempting to create a Zone of length:{}, expected: zone is '
+            'failed to be created'.format(allowed_limit + 1))
+        zone_name = dns_data_utils.rand_dns_name_by_size(allowed_limit + 1)
+        self.assertRaisesDns(
+            lib_exc.BadRequest, 'invalid_object', 400,
+            self.zone_client.create_zone,
+            name=zone_name
+        )
+
+    @decorators.idempotent_id('86646744-b98a-11ec-b3a4-201e8823901f')
+    def test_max_recordset_name_length(self):
+        # The full recordset name is a combination of its short name
+        # and the zone name. e.g., "www" + "example.com." = "www.example.com."
+        # In this section, we'll set the lengths needed for testing.
+        allowed_recordset_limit = self.project_limits[
+            'max_recordset_name_length'] - 1  # The final root null byte
+        reserved_recordset_length = 10  # Reserved for recordset's host part.
+        zone_name_size = allowed_recordset_limit - reserved_recordset_length
+        zone_name = dns_data_utils.rand_dns_name_by_size(
+            name_size=zone_name_size)
+        # Use class TLD at the end of generated Zone Name
+        zone_name = zone_name[:-(
+                len(self.tld['name']) + 2)] + '.' + self.tld['name'] + '.'
+        max_valid_record_name_size = allowed_recordset_limit - len(zone_name)
+
+        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 name of length:{} is successfully '
+                 'created'.format(allowed_recordset_limit))
+        recordset_data = dns_data_utils.rand_recordset_data(
+            record_type='A',
+            zone_name=zone_name,
+            # Reserve 1 char for the dot between the record name and zone name.
+            name=dns_data_utils.rand_string(
+                max_valid_record_name_size - 1) + '.' + 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(
+            'Attempting to create a Recordset of length:{}, expected:'
+            ' Recordset is failed to be created'.format(
+                allowed_recordset_limit + 1))
+        recordset_data = dns_data_utils.rand_recordset_data(
+            record_type='A',
+            zone_name=zone_name,
+            name=dns_data_utils.rand_string(
+                max_valid_record_name_size) + '.' + zone_name)
+
+        self.assertRaisesDns(
+            lib_exc.BadRequest, 'invalid_object', 400,
+            self.recordset_client.create_recordset,
+            zone_uuid=zone['id'],
+            recordset_data=recordset_data)