blob: c77c4b19a487845926c234c9228c4af84460e343 [file] [log] [blame]
Kiall Mac Innes25fb29e2016-04-07 08:07:04 +01001# 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 Glass89edc112016-04-21 17:06:33 +000014from oslo_log import log as logging
Kiall Mac Innes25fb29e2016-04-07 08:07:04 +010015from tempest.lib.common.utils import data_utils
16
Paul Glass89edc112016-04-21 17:06:33 +000017LOG = logging.getLogger(__name__)
18
Kiall Mac Innes25fb29e2016-04-07 08:07:04 +010019
sonu.kumaraec952a2016-04-20 10:08:46 +090020def rand_zone_name(name='', prefix=None, suffix='.com.'):
Kiall Mac Innes25fb29e2016-04-07 08:07:04 +010021 """Generate a random zone name
sonu.kumaraec952a2016-04-20 10:08:46 +090022 :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 Innes25fb29e2016-04-07 08:07:04 +010025 :return: a random zone name e.g. example.org.
26 :rtype: string
27 """
sonu.kumaraec952a2016-04-20 10:08:46 +090028 name = data_utils.rand_name(name=name, prefix=prefix)
29 return name + suffix
Kiall Mac Innes25fb29e2016-04-07 08:07:04 +010030
31
32def 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
41def 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.kumaraec952a2016-04-20 10:08:46 +090047
48
49def 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 Glass89edc112016-04-21 17:06:33 +000062
63
64def 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 }