summaryrefslogtreecommitdiff
path: root/watcher_tempest_plugin/tests/api/admin/test_audit.py
diff options
context:
space:
mode:
Diffstat (limited to 'watcher_tempest_plugin/tests/api/admin/test_audit.py')
-rw-r--r--watcher_tempest_plugin/tests/api/admin/test_audit.py221
1 files changed, 0 insertions, 221 deletions
diff --git a/watcher_tempest_plugin/tests/api/admin/test_audit.py b/watcher_tempest_plugin/tests/api/admin/test_audit.py
deleted file mode 100644
index 13a187e..0000000
--- a/watcher_tempest_plugin/tests/api/admin/test_audit.py
+++ /dev/null
@@ -1,221 +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
19import functools
20
21from tempest.lib.common.utils import test_utils
22from tempest.lib import decorators
23from tempest.lib import exceptions
24
25from watcher_tempest_plugin.tests.api.admin import base
26
27
28class TestCreateUpdateDeleteAudit(base.BaseInfraOptimTest):
29 """Tests for audit."""
30
31 audit_states = ['ONGOING', 'SUCCEEDED', 'FAILED',
32 'CANCELLED', 'DELETED', 'PENDING', 'SUSPENDED']
33
34 def assert_expected(self, expected, actual,
35 keys=('created_at', 'updated_at',
36 'deleted_at', 'state')):
37 super(TestCreateUpdateDeleteAudit, self).assert_expected(
38 expected, actual, keys)
39
40 @decorators.attr(type='smoke')
41 def test_create_audit_oneshot(self):
42 _, goal = self.client.show_goal("dummy")
43 _, audit_template = self.create_audit_template(goal['uuid'])
44
45 audit_params = dict(
46 audit_template_uuid=audit_template['uuid'],
47 audit_type='ONESHOT',
48 )
49
50 _, body = self.create_audit(**audit_params)
51 audit_params.pop('audit_template_uuid')
52 audit_params['goal_uuid'] = goal['uuid']
53 self.assert_expected(audit_params, body)
54
55 _, audit = self.client.show_audit(body['uuid'])
56 self.assert_expected(audit, body)
57
58 @decorators.attr(type='smoke')
59 def test_create_audit_continuous(self):
60 _, goal = self.client.show_goal("dummy")
61 _, audit_template = self.create_audit_template(goal['uuid'])
62
63 audit_params = dict(
64 audit_template_uuid=audit_template['uuid'],
65 audit_type='CONTINUOUS',
66 interval='7200',
67 )
68
69 _, body = self.create_audit(**audit_params)
70 audit_params.pop('audit_template_uuid')
71 audit_params['goal_uuid'] = goal['uuid']
72 self.assert_expected(audit_params, body)
73
74 _, audit = self.client.show_audit(body['uuid'])
75 self.assert_expected(audit, body)
76
77 @decorators.attr(type='smoke')
78 def test_create_audit_with_wrong_audit_template(self):
79 audit_params = dict(
80 audit_template_uuid='INVALID',
81 audit_type='ONESHOT',
82 )
83
84 self.assertRaises(
85 exceptions.BadRequest, self.create_audit, **audit_params)
86
87 @decorators.attr(type='smoke')
88 def test_create_audit_with_invalid_state(self):
89 _, goal = self.client.show_goal("dummy")
90 _, audit_template = self.create_audit_template(goal['uuid'])
91
92 audit_params = dict(
93 audit_template_uuid=audit_template['uuid'],
94 state='INVALID',
95 )
96
97 self.assertRaises(
98 exceptions.BadRequest, self.create_audit, **audit_params)
99
100 @decorators.attr(type='smoke')
101 def test_create_audit_with_no_state(self):
102 _, goal = self.client.show_goal("dummy")
103 _, audit_template = self.create_audit_template(goal['uuid'])
104
105 audit_params = dict(
106 audit_template_uuid=audit_template['uuid'],
107 state='',
108 )
109
110 _, body = self.create_audit(**audit_params)
111 audit_params.pop('audit_template_uuid')
112 audit_params['goal_uuid'] = goal['uuid']
113 self.assert_expected(audit_params, body)
114
115 _, audit = self.client.show_audit(body['uuid'])
116
117 initial_audit_state = audit.pop('state')
118 self.assertIn(initial_audit_state, self.audit_states)
119
120 self.assert_expected(audit, body)
121
122 @decorators.attr(type='smoke')
123 def test_delete_audit(self):
124 _, goal = self.client.show_goal("dummy")
125 _, audit_template = self.create_audit_template(goal['uuid'])
126 _, body = self.create_audit(audit_template['uuid'])
127 audit_uuid = body['uuid']
128
129 test_utils.call_until_true(
130 func=functools.partial(
131 self.is_audit_idle, audit_uuid),
132 duration=10,
133 sleep_for=.5
134 )
135
136 def is_audit_deleted(uuid):
137 try:
138 return not bool(self.client.show_audit(uuid))
139 except exceptions.NotFound:
140 return True
141
142 self.delete_audit(audit_uuid)
143
144 test_utils.call_until_true(
145 func=functools.partial(is_audit_deleted, audit_uuid),
146 duration=5,
147 sleep_for=1
148 )
149
150 self.assertTrue(is_audit_deleted(audit_uuid))
151
152
153class TestShowListAudit(base.BaseInfraOptimTest):
154 """Tests for audit."""
155
156 audit_states = ['ONGOING', 'SUCCEEDED', 'FAILED',
157 'CANCELLED', 'DELETED', 'PENDING', 'SUSPENDED']
158
159 @classmethod
160 def resource_setup(cls):
161 super(TestShowListAudit, cls).resource_setup()
162 _, cls.goal = cls.client.show_goal("dummy")
163 _, cls.audit_template = cls.create_audit_template(cls.goal['uuid'])
164 _, cls.audit = cls.create_audit(cls.audit_template['uuid'])
165
166 def assert_expected(self, expected, actual,
167 keys=('created_at', 'updated_at',
168 'deleted_at', 'state')):
169 super(TestShowListAudit, self).assert_expected(
170 expected, actual, keys)
171
172 @decorators.attr(type='smoke')
173 def test_show_audit(self):
174 _, audit = self.client.show_audit(
175 self.audit['uuid'])
176
177 initial_audit = self.audit.copy()
178 del initial_audit['state']
179 audit_state = audit['state']
180 actual_audit = audit.copy()
181 del actual_audit['state']
182
183 self.assertIn(audit_state, self.audit_states)
184 self.assert_expected(initial_audit, actual_audit)
185
186 @decorators.attr(type='smoke')
187 def test_show_audit_with_links(self):
188 _, audit = self.client.show_audit(
189 self.audit['uuid'])
190 self.assertIn('links', audit.keys())
191 self.assertEqual(2, len(audit['links']))
192 self.assertIn(audit['uuid'],
193 audit['links'][0]['href'])
194
195 @decorators.attr(type="smoke")
196 def test_list_audits(self):
197 _, body = self.client.list_audits()
198 self.assertIn(self.audit['uuid'],
199 [i['uuid'] for i in body['audits']])
200 # Verify self links.
201 for audit in body['audits']:
202 self.validate_self_link('audits', audit['uuid'],
203 audit['links'][0]['href'])
204
205 @decorators.attr(type='smoke')
206 def test_list_with_limit(self):
207 # We create 3 extra audits to exceed the limit we fix
208 for _ in range(3):
209 self.create_audit(self.audit_template['uuid'])
210
211 _, body = self.client.list_audits(limit=3)
212
213 next_marker = body['audits'][-1]['uuid']
214 self.assertEqual(3, len(body['audits']))
215 self.assertIn(next_marker, body['next'])
216
217 @decorators.attr(type='smoke')
218 def test_list_audits_related_to_given_audit_template(self):
219 _, body = self.client.list_audits(
220 goal=self.goal['uuid'])
221 self.assertIn(self.audit['uuid'], [n['uuid'] for n in body['audits']])