Codebase list cinder-tempest-plugin / f1432e1
Consistency groups: fix the exceptions handling = Fix the imports of shared exceptions = Shared tempest exceptions (like TimeoutException) are defined in and exported by tempest.lib, so use them correctly. = Directly define the exceptions used by this tempest plugin = While those exceptions have been defined in tempest.lib through I62e0ba556b884c94f6e8796a2e6f6d8083277fa4, they really belongs to this plugin only, so define them here. Other tempest plugins followed the same pattern. Moreover, the current import would need to be fixed anyway, because it should import the exceptions from tempest.lib.exceptions instead of tempest.exceptions. Closes-Bug: #1858417 Closes-Bug: #1889537 Change-Id: Ie54c2a1dc25b647a0f0d10bcad6ba62023986741 Luigi Toscano 5 years ago
2 changed file(s) with 30 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
0 # Licensed under the Apache License, Version 2.0 (the "License"); you may
1 # not use this file except in compliance with the License. You may obtain
2 # a copy of the License at
3 #
4 # http://www.apache.org/licenses/LICENSE-2.0
5 #
6 # Unless required by applicable law or agreed to in writing, software
7 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
8 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
9 # License for the specific language governing permissions and limitations
10 # under the License.
11
12 from tempest.lib import exceptions
13
14
15 class ConsistencyGroupException(exceptions.TempestException):
16 message = "Consistency group %(cg_id)s failed and is in ERROR status"
17
18
19 class ConsistencyGroupSnapshotException(exceptions.TempestException):
20 message = ("Consistency group snapshot %(cgsnapshot_id)s failed and is "
21 "in ERROR status")
1717
1818 from oslo_serialization import jsonutils as json
1919 from six.moves import http_client
20 from tempest import exceptions
2120 from tempest.lib.common import rest_client
2221 from tempest.lib import exceptions as lib_exc
22
23 from cinder_tempest_plugin import exceptions as volume_exc
2324
2425
2526 class ConsistencyGroupsClient(rest_client.RestClient):
136137 body = self.show_consistencygroup(cg_id)['consistencygroup']
137138 cg_status = body['status']
138139 if cg_status == 'error':
139 raise exceptions.ConsistencyGroupException(cg_id=cg_id)
140 raise volume_exc.ConsistencyGroupException(cg_id=cg_id)
140141
141142 if int(time.time()) - start >= self.build_timeout:
142143 message = ('Consistency group %s failed to reach %s status '
143144 '(current %s) within the required time (%s s).' %
144145 (cg_id, status, cg_status,
145146 self.build_timeout))
146 raise exceptions.TimeoutException(message)
147 raise lib_exc.TimeoutException(message)
147148
148149 def wait_for_consistencygroup_deletion(self, cg_id):
149150 """Waits for consistency group deletion"""
154155 except lib_exc.NotFound:
155156 return
156157 if int(time.time()) - start_time >= self.build_timeout:
157 raise exceptions.TimeoutException
158 raise lib_exc.TimeoutException
158159 time.sleep(self.build_interval)
159160
160161 def wait_for_cgsnapshot_status(self, cgsnapshot_id, status):
168169 body = self.show_cgsnapshot(cgsnapshot_id)['cgsnapshot']
169170 cgsnapshot_status = body['status']
170171 if cgsnapshot_status == 'error':
171 raise exceptions.ConsistencyGroupSnapshotException(
172 raise volume_exc.ConsistencyGroupSnapshotException(
172173 cgsnapshot_id=cgsnapshot_id)
173174
174175 if int(time.time()) - start >= self.build_timeout:
177178 '(%s s).' %
178179 (cgsnapshot_id, status, cgsnapshot_status,
179180 self.build_timeout))
180 raise exceptions.TimeoutException(message)
181 raise lib_exc.TimeoutException(message)
181182
182183 def wait_for_cgsnapshot_deletion(self, cgsnapshot_id):
183184 """Waits for consistency group snapshot deletion"""
188189 except lib_exc.NotFound:
189190 return
190191 if int(time.time()) - start_time >= self.build_timeout:
191 raise exceptions.TimeoutException
192 raise lib_exc.TimeoutException
192193 time.sleep(self.build_interval)