blob: 8b18785b7ac289c3c73e25c2e98016a3cdb2fffc [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.
sonu.kumaraec952a2016-04-20 10:08:46 +090014
Kiall Mac Innes25fb29e2016-04-07 08:07:04 +010015from tempest.lib.common.utils import data_utils
16
17
sonu.kumaraec952a2016-04-20 10:08:46 +090018def rand_zone_name(name='', prefix=None, suffix='.com.'):
Kiall Mac Innes25fb29e2016-04-07 08:07:04 +010019 """Generate a random zone name
sonu.kumaraec952a2016-04-20 10:08:46 +090020 :param str name: The name that you want to include
21 :param prefix: the exact text to start the string. Defaults to "rand"
22 :param suffix: the exact text to end the string
Kiall Mac Innes25fb29e2016-04-07 08:07:04 +010023 :return: a random zone name e.g. example.org.
24 :rtype: string
25 """
sonu.kumaraec952a2016-04-20 10:08:46 +090026 name = data_utils.rand_name(name=name, prefix=prefix)
27 return name + suffix
Kiall Mac Innes25fb29e2016-04-07 08:07:04 +010028
29
30def rand_email(domain=None):
31 """Generate a random zone name
32 :return: a random zone name e.g. example.org.
33 :rtype: string
34 """
35 domain = domain or rand_zone_name()
36 return 'example@%s' % domain.rstrip('.')
37
38
39def rand_ttl(start=1, end=86400):
40 """Generate a random TTL value
41 :return: a random ttl e.g. 165
42 :rtype: string
43 """
44 return data_utils.rand_int_id(start, end)
sonu.kumaraec952a2016-04-20 10:08:46 +090045
46
47def rand_zonefile_data(name=None, ttl=None):
48 """Generate random zone data, with optional overrides
49
50 :return: A ZoneModel
51 """
52 zone_base = ('$ORIGIN &\n& # IN SOA ns.& nsadmin.& # # # # #\n'
53 '& # IN NS ns.&\n& # IN MX 10 mail.&\nns.& 360 IN A 1.0.0.1')
54 if name is None:
55 name = rand_zone_name()
56 if ttl is None:
57 ttl = str(rand_ttl(1200, 8400))
58
59 return zone_base.replace('&', name).replace('#', ttl)