summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-02-01 16:28:35 +0000
committerGerrit Code Review <review@openstack.org>2017-02-01 16:28:35 +0000
commit62677f8df1fb401148ad1ac7cc0fe2ef716ba12f (patch)
treef41b1a961e5d1d7a0cd03fe6091bcee9dc24e752
parent3416030a7b49ba551a54e92565ccbdc3ec76fe0d (diff)
parentdc715e1e350477cd0105f010a9b5d0d5451e7b6b (diff)
Merge "Migrate the recordset validation functional test"0.2.0
-rw-r--r--designate_tempest_plugin/common/waiters.py6
-rw-r--r--designate_tempest_plugin/data_utils.py13
-rw-r--r--designate_tempest_plugin/tests/api/v2/invalid_mx_dataset.json5
-rw-r--r--designate_tempest_plugin/tests/api/v2/invalid_sshfp_dataset.json6
-rw-r--r--designate_tempest_plugin/tests/api/v2/invalid_txt_dataset.json5
-rw-r--r--designate_tempest_plugin/tests/api/v2/test_recordset_validation.py175
-rw-r--r--designate_tempest_plugin/tests/api/v2/valid_txt_dataset.json5
7 files changed, 212 insertions, 3 deletions
diff --git a/designate_tempest_plugin/common/waiters.py b/designate_tempest_plugin/common/waiters.py
index d13465d..cd22541 100644
--- a/designate_tempest_plugin/common/waiters.py
+++ b/designate_tempest_plugin/common/waiters.py
@@ -149,17 +149,17 @@ def wait_for_zone_export_status(client, zone_export_id, status):
149 raise lib_exc.TimeoutException(message) 149 raise lib_exc.TimeoutException(message)
150 150
151 151
152def wait_for_recordset_status(client, recordset_id, status): 152def wait_for_recordset_status(client, zone_id, recordset_id, status):
153 """Waits for a recordset to reach the given status.""" 153 """Waits for a recordset to reach the given status."""
154 LOG.info('Waiting for recordset %s to reach %s', 154 LOG.info('Waiting for recordset %s to reach %s',
155 recordset_id, status) 155 recordset_id, status)
156 156
157 _, recordset = client.show_recordset(recordset_id) 157 _, recordset = client.show_recordset(zone_id, recordset_id)
158 start = int(time.time()) 158 start = int(time.time())
159 159
160 while recordset['status'] != status: 160 while recordset['status'] != status:
161 time.sleep(client.build_interval) 161 time.sleep(client.build_interval)
162 _, recordset = client.show_recordset(recordset_id) 162 _, recordset = client.show_recordset(zone_id, recordset_id)
163 status_curr = recordset['status'] 163 status_curr = recordset['status']
164 if status_curr == status: 164 if status_curr == status:
165 LOG.info('Recordset %s reached %s', recordset_id, status) 165 LOG.info('Recordset %s reached %s', recordset_id, status)
diff --git a/designate_tempest_plugin/data_utils.py b/designate_tempest_plugin/data_utils.py
index 7600542..46c8165 100644
--- a/designate_tempest_plugin/data_utils.py
+++ b/designate_tempest_plugin/data_utils.py
@@ -246,3 +246,16 @@ def rand_tsig_algorithm():
246def rand_tsig_scope(): 246def rand_tsig_scope():
247 scope = ["ZONE", "POOL"] 247 scope = ["ZONE", "POOL"]
248 return random.choice(scope) 248 return random.choice(scope)
249
250
251def make_rand_recordset(zone_name, record_type):
252 """Create a rand recordset by type
253 This essentially just dispatches to the relevant random recordset
254 creation functions.
255
256 :param str zone_name: The zone name the recordset applies to
257 :param str record_type: The type of recordset (ie A, MX, NS, etc...)
258 """
259
260 func = globals()["rand_{}_recordset".format(record_type.lower())]
261 return func(zone_name)
diff --git a/designate_tempest_plugin/tests/api/v2/invalid_mx_dataset.json b/designate_tempest_plugin/tests/api/v2/invalid_mx_dataset.json
new file mode 100644
index 0000000..100995a
--- /dev/null
+++ b/designate_tempest_plugin/tests/api/v2/invalid_mx_dataset.json
@@ -0,0 +1,5 @@
1{
2 "empty_preference": {"pref": ""},
3 "minus_zero_preference": {"pref": "-0"},
4 "minus_one_preference": {"pref": "-1"}
5}
diff --git a/designate_tempest_plugin/tests/api/v2/invalid_sshfp_dataset.json b/designate_tempest_plugin/tests/api/v2/invalid_sshfp_dataset.json
new file mode 100644
index 0000000..133b460
--- /dev/null
+++ b/designate_tempest_plugin/tests/api/v2/invalid_sshfp_dataset.json
@@ -0,0 +1,6 @@
1{
2 "minus_zero_algorithm": {"algo": "-0", "finger": null},
3 "minus_zero_fingerprint": {"algo": null, "finger": "-0"},
4 "minus_one_algorithm": {"algo": "-1", "finger": null},
5 "minus_one_fingerprint": {"algo": null, "finger": "-1"}
6}
diff --git a/designate_tempest_plugin/tests/api/v2/invalid_txt_dataset.json b/designate_tempest_plugin/tests/api/v2/invalid_txt_dataset.json
new file mode 100644
index 0000000..26633f3
--- /dev/null
+++ b/designate_tempest_plugin/tests/api/v2/invalid_txt_dataset.json
@@ -0,0 +1,5 @@
1{
2 "trailing_slash": {"data": "\\"},
3 "trailing_double_slash": {"data": "\\\\"},
4 "trailing_slash_after_text": {"data": "v=spf1 +all\\"}
5}
diff --git a/designate_tempest_plugin/tests/api/v2/test_recordset_validation.py b/designate_tempest_plugin/tests/api/v2/test_recordset_validation.py
new file mode 100644
index 0000000..48c05df
--- /dev/null
+++ b/designate_tempest_plugin/tests/api/v2/test_recordset_validation.py
@@ -0,0 +1,175 @@
1"""
2Copyright 2016 Rackspace
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15"""
16import ddt
17from tempest.lib import exceptions
18from tempest.lib import decorators
19
20from designate_tempest_plugin.tests import base
21from designate_tempest_plugin.common import waiters
22from designate_tempest_plugin import data_utils
23
24
25RECORDSETS_DATASET = [
26 'A',
27 'AAAA',
28 'CNAME',
29 'MX',
30 'SPF',
31 'SRV',
32 'SSHFP',
33 'TXT',
34]
35
36
37@ddt.ddt
38class RecordsetValidationTest(base.BaseDnsV2Test):
39
40 def setUp(self):
41 super(RecordsetValidationTest, self).setUp()
42 self._zone = None
43
44 @classmethod
45 def setup_clients(cls):
46 super(RecordsetValidationTest, cls).setup_clients()
47
48 cls.recordset_client = cls.os.recordset_client
49 cls.zones_client = cls.os.zones_client
50
51 @property
52 def zone(self):
53 if self._zone is None:
54 zone_data = data_utils.rand_zone_data()
55 resp, body = self.zones_client.create_zone(**zone_data)
56 self._zone = body
57 return self._zone
58
59 def create_recordset(self, data):
60 resp, body = self.recordset_client.create_recordset(
61 self.zone['id'], data)
62
63 return body
64
65 @decorators.idempotent_id('c5ef87e2-cb79-4758-b968-18eef2c251df')
66 @ddt.data(*RECORDSETS_DATASET)
67 def test_create_invalid(self, rtype):
68 data = ["b0rk"]
69
70 for i in data:
71 model = data_utils.make_rand_recordset(self.zone['name'], rtype)
72 model['data'] = i
73
74 self.assertRaisesDns(
75 exceptions.BadRequest, 'invalid_object', 400,
76 self.recordset_client.create_recordset,
77 self.zone['id'], model
78 )
79
80 @decorators.idempotent_id('1164c826-dceb-4557-9a22-7d65c4a4f5f4')
81 @ddt.data(*RECORDSETS_DATASET)
82 def test_update_invalid(self, rtype):
83 data = ["b0rk"]
84
85 post_model = data_utils.make_rand_recordset(self.zone['name'], rtype)
86 recordset = self.create_recordset(post_model)
87
88 for i in data:
89 model = data_utils.make_rand_recordset(self.zone['name'], rtype)
90 model['data'] = i
91 self.assertRaisesDns(
92 exceptions.BadRequest, 'invalid_object', 400,
93 self.recordset_client.update_recordset,
94 self.zone['id'], recordset['id'], model
95 )
96
97 @decorators.idempotent_id('61da1015-291f-43d1-a1a8-345cff12d201')
98 def test_cannot_create_wildcard_NS_recordset(self):
99 model = data_utils.wildcard_ns_recordset(self.zone['name'])
100 self.assertRaisesDns(
101 exceptions.BadRequest, 'invalid_object', 400,
102 self.recordset_client.create_recordset, self.zone['id'], model
103 )
104
105 @decorators.idempotent_id('92f681aa-d953-4d18-b12e-81a9149ccfd9')
106 def test_cname_recordsets_cannot_have_more_than_one_record(self):
107 post_model = data_utils.rand_cname_recordset(
108 zone_name=self.zone['name'])
109
110 post_model['records'] = [
111 "a.{0}".format(self.zone['name']),
112 "b.{0}".format(self.zone['name']),
113 ]
114
115 self.assertRaises(
116 exceptions.BadRequest,
117 self.recordset_client.create_recordset,
118 self.zone['id'], post_model
119 )
120
121 @decorators.idempotent_id('22a9544b-2382-4ed2-ba12-4dbaedb8e880')
122 @ddt.file_data("invalid_txt_dataset.json")
123 def test_cannot_create_TXT_with(self, data):
124 post_model = data_utils.rand_txt_recordset(self.zone['name'], data)
125 self.assertRaisesDns(
126 exceptions.BadRequest, 'invalid_object', 400,
127 self.recordset_client.create_recordset,
128 self.zone['id'], post_model,
129 )
130
131 @decorators.idempotent_id('03e4f811-0c37-4ce2-8b16-662c824f8f18')
132 @ddt.file_data("valid_txt_dataset.json")
133 def test_create_TXT_with(self, data):
134 post_model = data_utils.rand_txt_recordset(self.zone['name'], data)
135 recordset = self.create_recordset(post_model)
136
137 waiters.wait_for_recordset_status(
138 self.recordset_client, self.zone['id'], recordset['id'], 'ACTIVE')
139
140 @decorators.idempotent_id('775b3db5-ec60-4dd7-85d2-f05a9c544978')
141 @ddt.file_data("valid_txt_dataset.json")
142 def test_create_SPF_with(self, data):
143 post_model = data_utils.rand_spf_recordset(self.zone['name'], data)
144 recordset = self.create_recordset(post_model)
145
146 waiters.wait_for_recordset_status(
147 self.recordset_client, self.zone['id'], recordset['id'], 'ACTIVE')
148
149 @decorators.idempotent_id('7fa7783f-1624-4122-bfb2-6cfbf7a5b49b')
150 @ddt.file_data("invalid_mx_dataset.json")
151 def test_cannot_create_MX_with(self, pref):
152 post_model = data_utils.rand_mx_recordset(
153 self.zone['name'], pref=pref
154 )
155
156 self.assertRaisesDns(
157 exceptions.BadRequest, 'invalid_object', 400,
158 self.recordset_client.create_recordset,
159 self.zone['id'], post_model,
160 )
161
162 @decorators.idempotent_id('3016f998-4e4a-4712-b15a-4e8dfbc5a60b')
163 @ddt.data("invalid_sshfp_dataset.json")
164 def test_cannot_create_SSHFP_with(self, algo=None, finger=None):
165 post_model = data_utils.rand_sshfp_recordset(
166 zone_name=self.zone['name'],
167 algorithm_number=algo,
168 fingerprint_type=finger,
169 )
170
171 self.assertRaisesDns(
172 exceptions.BadRequest, 'invalid_object', 400,
173 self.recordset_client.create_recordset,
174 self.zone['id'], post_model,
175 )
diff --git a/designate_tempest_plugin/tests/api/v2/valid_txt_dataset.json b/designate_tempest_plugin/tests/api/v2/valid_txt_dataset.json
new file mode 100644
index 0000000..b54b1b3
--- /dev/null
+++ b/designate_tempest_plugin/tests/api/v2/valid_txt_dataset.json
@@ -0,0 +1,5 @@
1{
2 "slash_with_one_trailing_space": {"data": "\\ "},
3 "slash_with_many_trailing_space": {"data": "\\ "},
4 "text_with_slash_and_trailing_space": {"data": "the txts "}
5}