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
This commit is contained in:
Luigi Toscano 2020-07-30 12:22:37 +02:00
parent a75d5e5e25
commit f1432e10e1
2 changed files with 30 additions and 7 deletions

View File

@ -0,0 +1,22 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from tempest.lib import exceptions
class ConsistencyGroupException(exceptions.TempestException):
message = "Consistency group %(cg_id)s failed and is in ERROR status"
class ConsistencyGroupSnapshotException(exceptions.TempestException):
message = ("Consistency group snapshot %(cgsnapshot_id)s failed and is "
"in ERROR status")

View File

@ -18,10 +18,11 @@ import time
from oslo_serialization import jsonutils as json
from six.moves import http_client
from tempest import exceptions
from tempest.lib.common import rest_client
from tempest.lib import exceptions as lib_exc
from cinder_tempest_plugin import exceptions as volume_exc
class ConsistencyGroupsClient(rest_client.RestClient):
"""Client class to send CRUD Volume ConsistencyGroup API requests"""
@ -137,14 +138,14 @@ class ConsistencyGroupsClient(rest_client.RestClient):
body = self.show_consistencygroup(cg_id)['consistencygroup']
cg_status = body['status']
if cg_status == 'error':
raise exceptions.ConsistencyGroupException(cg_id=cg_id)
raise volume_exc.ConsistencyGroupException(cg_id=cg_id)
if int(time.time()) - start >= self.build_timeout:
message = ('Consistency group %s failed to reach %s status '
'(current %s) within the required time (%s s).' %
(cg_id, status, cg_status,
self.build_timeout))
raise exceptions.TimeoutException(message)
raise lib_exc.TimeoutException(message)
def wait_for_consistencygroup_deletion(self, cg_id):
"""Waits for consistency group deletion"""
@ -155,7 +156,7 @@ class ConsistencyGroupsClient(rest_client.RestClient):
except lib_exc.NotFound:
return
if int(time.time()) - start_time >= self.build_timeout:
raise exceptions.TimeoutException
raise lib_exc.TimeoutException
time.sleep(self.build_interval)
def wait_for_cgsnapshot_status(self, cgsnapshot_id, status):
@ -169,7 +170,7 @@ class ConsistencyGroupsClient(rest_client.RestClient):
body = self.show_cgsnapshot(cgsnapshot_id)['cgsnapshot']
cgsnapshot_status = body['status']
if cgsnapshot_status == 'error':
raise exceptions.ConsistencyGroupSnapshotException(
raise volume_exc.ConsistencyGroupSnapshotException(
cgsnapshot_id=cgsnapshot_id)
if int(time.time()) - start >= self.build_timeout:
@ -178,7 +179,7 @@ class ConsistencyGroupsClient(rest_client.RestClient):
'(%s s).' %
(cgsnapshot_id, status, cgsnapshot_status,
self.build_timeout))
raise exceptions.TimeoutException(message)
raise lib_exc.TimeoutException(message)
def wait_for_cgsnapshot_deletion(self, cgsnapshot_id):
"""Waits for consistency group snapshot deletion"""
@ -189,5 +190,5 @@ class ConsistencyGroupsClient(rest_client.RestClient):
except lib_exc.NotFound:
return
if int(time.time()) - start_time >= self.build_timeout:
raise exceptions.TimeoutException
raise lib_exc.TimeoutException
time.sleep(self.build_interval)