summaryrefslogtreecommitdiff
path: root/watcher_tempest_plugin/tests/api/admin/test_audit_template.py
diff options
context:
space:
mode:
Diffstat (limited to 'watcher_tempest_plugin/tests/api/admin/test_audit_template.py')
-rw-r--r--watcher_tempest_plugin/tests/api/admin/test_audit_template.py226
1 files changed, 0 insertions, 226 deletions
diff --git a/watcher_tempest_plugin/tests/api/admin/test_audit_template.py b/watcher_tempest_plugin/tests/api/admin/test_audit_template.py
deleted file mode 100644
index 75ac80a..0000000
--- a/watcher_tempest_plugin/tests/api/admin/test_audit_template.py
+++ /dev/null
@@ -1,226 +0,0 @@
1# -*- encoding: utf-8 -*-
2# Copyright (c) 2016 b<>com
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13# implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17from __future__ import unicode_literals
18
19from oslo_utils import uuidutils
20
21from tempest.lib import decorators
22from tempest.lib import exceptions
23
24from watcher_tempest_plugin.tests.api.admin import base
25
26
27class TestCreateDeleteAuditTemplate(base.BaseInfraOptimTest):
28 """Tests on audit templates"""
29
30 @decorators.attr(type='smoke')
31 def test_create_audit_template(self):
32 goal_name = "dummy"
33 _, goal = self.client.show_goal(goal_name)
34
35 params = {
36 'name': 'my at name %s' % uuidutils.generate_uuid(),
37 'description': 'my at description',
38 'goal': goal['uuid']}
39 expected_data = {
40 'name': params['name'],
41 'description': params['description'],
42 'goal_uuid': params['goal'],
43 'goal_name': goal_name,
44 'strategy_uuid': None,
45 'strategy_name': None}
46
47 _, body = self.create_audit_template(**params)
48 self.assert_expected(expected_data, body)
49
50 _, audit_template = self.client.show_audit_template(body['uuid'])
51 self.assert_expected(audit_template, body)
52
53 @decorators.attr(type='smoke')
54 def test_create_audit_template_unicode_description(self):
55 goal_name = "dummy"
56 _, goal = self.client.show_goal(goal_name)
57 # Use a unicode string for testing:
58 params = {
59 'name': 'my at name %s' % uuidutils.generate_uuid(),
60 'description': 'my àt déscrïptïôn',
61 'goal': goal['uuid']}
62
63 expected_data = {
64 'name': params['name'],
65 'description': params['description'],
66 'goal_uuid': params['goal'],
67 'goal_name': goal_name,
68 'strategy_uuid': None,
69 'strategy_name': None}
70
71 _, body = self.create_audit_template(**params)
72 self.assert_expected(expected_data, body)
73
74 _, audit_template = self.client.show_audit_template(body['uuid'])
75 self.assert_expected(audit_template, body)
76
77 @decorators.attr(type='smoke')
78 def test_delete_audit_template(self):
79 _, goal = self.client.show_goal("dummy")
80 _, body = self.create_audit_template(goal=goal['uuid'])
81 audit_uuid = body['uuid']
82
83 self.delete_audit_template(audit_uuid)
84
85 self.assertRaises(exceptions.NotFound, self.client.show_audit_template,
86 audit_uuid)
87
88
89class TestAuditTemplate(base.BaseInfraOptimTest):
90 """Tests for audit_template."""
91
92 @classmethod
93 def resource_setup(cls):
94 super(TestAuditTemplate, cls).resource_setup()
95 _, cls.goal = cls.client.show_goal("dummy")
96 _, cls.strategy = cls.client.show_strategy("dummy")
97 _, cls.audit_template = cls.create_audit_template(
98 goal=cls.goal['uuid'], strategy=cls.strategy['uuid'])
99
100 @decorators.attr(type='smoke')
101 def test_show_audit_template(self):
102 _, audit_template = self.client.show_audit_template(
103 self.audit_template['uuid'])
104
105 self.assert_expected(self.audit_template, audit_template)
106
107 @decorators.attr(type='smoke')
108 def test_filter_audit_template_by_goal_uuid(self):
109 _, audit_templates = self.client.list_audit_templates(
110 goal=self.audit_template['goal_uuid'])
111
112 audit_template_uuids = [
113 at["uuid"] for at in audit_templates['audit_templates']]
114 self.assertIn(self.audit_template['uuid'], audit_template_uuids)
115
116 @decorators.attr(type='smoke')
117 def test_filter_audit_template_by_strategy_uuid(self):
118 _, audit_templates = self.client.list_audit_templates(
119 strategy=self.audit_template['strategy_uuid'])
120
121 audit_template_uuids = [
122 at["uuid"] for at in audit_templates['audit_templates']]
123 self.assertIn(self.audit_template['uuid'], audit_template_uuids)
124
125 @decorators.attr(type='smoke')
126 def test_show_audit_template_with_links(self):
127 _, audit_template = self.client.show_audit_template(
128 self.audit_template['uuid'])
129 self.assertIn('links', audit_template.keys())
130 self.assertEqual(2, len(audit_template['links']))
131 self.assertIn(audit_template['uuid'],
132 audit_template['links'][0]['href'])
133
134 @decorators.attr(type="smoke")
135 def test_list_audit_templates(self):
136 _, body = self.client.list_audit_templates()
137 self.assertIn(self.audit_template['uuid'],
138 [i['uuid'] for i in body['audit_templates']])
139 # Verify self links.
140 for audit_template in body['audit_templates']:
141 self.validate_self_link('audit_templates', audit_template['uuid'],
142 audit_template['links'][0]['href'])
143
144 @decorators.attr(type='smoke')
145 def test_list_with_limit(self):
146 # We create 3 extra audit templates to exceed the limit we fix
147 for _ in range(3):
148 self.create_audit_template(self.goal['uuid'])
149
150 _, body = self.client.list_audit_templates(limit=3)
151
152 next_marker = body['audit_templates'][-1]['uuid']
153 self.assertEqual(3, len(body['audit_templates']))
154 self.assertIn(next_marker, body['next'])
155
156 @decorators.attr(type='smoke')
157 def test_update_audit_template_replace(self):
158 _, new_goal = self.client.show_goal("server_consolidation")
159 _, new_strategy = self.client.show_strategy("basic")
160
161 params = {'name': 'my at name %s' % uuidutils.generate_uuid(),
162 'description': 'my at description',
163 'goal': self.goal['uuid']}
164
165 _, body = self.create_audit_template(**params)
166
167 new_name = 'my at new name %s' % uuidutils.generate_uuid()
168 new_description = 'my new at description'
169
170 patch = [{'path': '/name',
171 'op': 'replace',
172 'value': new_name},
173 {'path': '/description',
174 'op': 'replace',
175 'value': new_description},
176 {'path': '/goal',
177 'op': 'replace',
178 'value': new_goal['uuid']},
179 {'path': '/strategy',
180 'op': 'replace',
181 'value': new_strategy['uuid']}]
182
183 self.client.update_audit_template(body['uuid'], patch)
184
185 _, body = self.client.show_audit_template(body['uuid'])
186 self.assertEqual(new_name, body['name'])
187 self.assertEqual(new_description, body['description'])
188 self.assertEqual(new_goal['uuid'], body['goal_uuid'])
189 self.assertEqual(new_strategy['uuid'], body['strategy_uuid'])
190
191 @decorators.attr(type='smoke')
192 def test_update_audit_template_remove(self):
193 description = 'my at description'
194 name = 'my at name %s' % uuidutils.generate_uuid()
195 params = {'name': name,
196 'description': description,
197 'goal': self.goal['uuid']}
198
199 _, audit_template = self.create_audit_template(**params)
200
201 # Removing the description
202 self.client.update_audit_template(
203 audit_template['uuid'],
204 [{'path': '/description', 'op': 'remove'}])
205
206 _, body = self.client.show_audit_template(audit_template['uuid'])
207 self.assertIsNone(body.get('description'))
208
209 # Assert nothing else was changed
210 self.assertEqual(name, body['name'])
211 self.assertIsNone(body['description'])
212 self.assertEqual(self.goal['uuid'], body['goal_uuid'])
213
214 @decorators.attr(type='smoke')
215 def test_update_audit_template_add(self):
216 params = {'name': 'my at name %s' % uuidutils.generate_uuid(),
217 'goal': self.goal['uuid']}
218
219 _, body = self.create_audit_template(**params)
220
221 patch = [{'path': '/description', 'op': 'add', 'value': 'description'}]
222
223 self.client.update_audit_template(body['uuid'], patch)
224
225 _, body = self.client.show_audit_template(body['uuid'])
226 self.assertEqual('description', body['description'])