Kiall Mac Innes | 25fb29e | 2016-04-07 08:07:04 +0100 | [diff] [blame] | 1 | # Copyright 2016 Hewlett Packard Enterprise Development Company, L.P. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
Paul Glass | 89edc11 | 2016-04-21 17:06:33 +0000 | [diff] [blame] | 14 | from oslo_log import log as logging |
Kiall Mac Innes | 25fb29e | 2016-04-07 08:07:04 +0100 | [diff] [blame] | 15 | from tempest.lib.common.utils import data_utils |
| 16 | |
Paul Glass | 89edc11 | 2016-04-21 17:06:33 +0000 | [diff] [blame] | 17 | LOG = logging.getLogger(__name__) |
| 18 | |
Kiall Mac Innes | 25fb29e | 2016-04-07 08:07:04 +0100 | [diff] [blame] | 19 | |
sonu.kumar | aec952a | 2016-04-20 10:08:46 +0900 | [diff] [blame] | 20 | def rand_zone_name(name='', prefix=None, suffix='.com.'): |
Kiall Mac Innes | 25fb29e | 2016-04-07 08:07:04 +0100 | [diff] [blame] | 21 | """Generate a random zone name |
sonu.kumar | aec952a | 2016-04-20 10:08:46 +0900 | [diff] [blame] | 22 | :param str name: The name that you want to include |
| 23 | :param prefix: the exact text to start the string. Defaults to "rand" |
| 24 | :param suffix: the exact text to end the string |
Kiall Mac Innes | 25fb29e | 2016-04-07 08:07:04 +0100 | [diff] [blame] | 25 | :return: a random zone name e.g. example.org. |
| 26 | :rtype: string |
| 27 | """ |
sonu.kumar | aec952a | 2016-04-20 10:08:46 +0900 | [diff] [blame] | 28 | name = data_utils.rand_name(name=name, prefix=prefix) |
| 29 | return name + suffix |
Kiall Mac Innes | 25fb29e | 2016-04-07 08:07:04 +0100 | [diff] [blame] | 30 | |
| 31 | |
| 32 | def rand_email(domain=None): |
| 33 | """Generate a random zone name |
| 34 | :return: a random zone name e.g. example.org. |
| 35 | :rtype: string |
| 36 | """ |
| 37 | domain = domain or rand_zone_name() |
| 38 | return 'example@%s' % domain.rstrip('.') |
| 39 | |
| 40 | |
| 41 | def rand_ttl(start=1, end=86400): |
| 42 | """Generate a random TTL value |
| 43 | :return: a random ttl e.g. 165 |
| 44 | :rtype: string |
| 45 | """ |
| 46 | return data_utils.rand_int_id(start, end) |
sonu.kumar | aec952a | 2016-04-20 10:08:46 +0900 | [diff] [blame] | 47 | |
| 48 | |
| 49 | def rand_zonefile_data(name=None, ttl=None): |
| 50 | """Generate random zone data, with optional overrides |
| 51 | |
| 52 | :return: A ZoneModel |
| 53 | """ |
| 54 | zone_base = ('$ORIGIN &\n& # IN SOA ns.& nsadmin.& # # # # #\n' |
| 55 | '& # IN NS ns.&\n& # IN MX 10 mail.&\nns.& 360 IN A 1.0.0.1') |
| 56 | if name is None: |
| 57 | name = rand_zone_name() |
| 58 | if ttl is None: |
| 59 | ttl = str(rand_ttl(1200, 8400)) |
| 60 | |
| 61 | return zone_base.replace('&', name).replace('#', ttl) |
Paul Glass | 89edc11 | 2016-04-21 17:06:33 +0000 | [diff] [blame] | 62 | |
| 63 | |
| 64 | def rand_quotas(zones=None, zone_records=None, zone_recordsets=None, |
| 65 | recordset_records=None, api_export_size=None): |
| 66 | LOG.warn("Leaving `api_export_size` out of quota data due to: " |
| 67 | "https://bugs.launchpad.net/designate/+bug/1573141") |
| 68 | return { |
| 69 | 'quota': { |
| 70 | 'zones': |
| 71 | zones or data_utils.rand_int_id(100, 999999), |
| 72 | 'zone_records': |
| 73 | zone_records or data_utils.rand_int_id(100, 999999), |
| 74 | 'zone_recordsets': |
| 75 | zone_recordsets or data_utils.rand_int_id(100, 999999), |
| 76 | 'recordset_records': |
| 77 | recordset_records or data_utils.rand_int_id(100, 999999), |
| 78 | # https://bugs.launchpad.net/designate/+bug/1573141 |
| 79 | # 'api_export_size': |
| 80 | # api_export_size or data_utils.rand_int_id(100, 999999), |
| 81 | } |
| 82 | } |