Merge "Remove ARQInvalidState exception"

This commit is contained in:
Zuul 2021-03-12 01:53:36 +00:00 committed by Gerrit Code Review
commit f9835cff9c
7 changed files with 16 additions and 20 deletions

View File

@ -181,9 +181,9 @@ class ARQsController(base.CyborgController):
arqs = [extarq.arq for extarq in extarqs]
# TODO(Sundar): Optimize by doing the filtering in the db layer
# Apply instance filter before state filter.
if bind_state:
if bind_state != 'resolved':
raise exception.ARQInvalidState(state=bind_state)
if bind_state and bind_state != 'resolved':
raise exception.ARQBadState(
state=bind_state, uuid=None, expected=['resolved'])
if instance:
new_arqs = [arq for arq in arqs
if arq['instance_uuid'] == instance]

View File

@ -83,14 +83,8 @@ class Forbidden(CyborgException):
code = HTTPStatus.FORBIDDEN
# TODO(Sundar): Eliminate this after ARQBadState is merged.
class ARQInvalidState(CyborgException):
_msg_fmt = _("Accelerator Requests cannot be requested with "
"state %(state)s.")
class ARQBadState(CyborgException):
_msg_fmt = _('Bad state \"%(state)s\" for ARQ %(uuid)s. '
_msg_fmt = _('Bad state: %(state)s for ARQ: %(uuid)s. '
'Expected state(s): %(expected)s')

View File

@ -137,7 +137,8 @@ class ExtARQ(base.CyborgObject, object_base.VersionedObjectDictCompat,
msg = ("Failed to change ARQ state from %s to %s, the current "
"state is %s" % (old, state, current))
LOG.error(msg)
raise exception.ARQInvalidState(msg)
raise exception.ARQBadState(
state=current, uuid=self.arq.uuid, expected=list(state))
return True
def destroy(self, context):

View File

@ -58,9 +58,10 @@ class ExtARQJobMixin(object):
def start_bind_job(self, context, valid_fields):
"""Check and start bind jobs for ARQ."""
# Check can ARC be bound.
if (self.arq.state not in
ARQ_STATES_TRANSFORM_MATRIX[constants.ARQ_BIND_STARTED]):
raise exception.ARQInvalidState(state=self.arq.state)
expected = ARQ_STATES_TRANSFORM_MATRIX[constants.ARQ_BIND_STARTED]
if self.arq.state not in expected:
raise exception.ARQBadState(
state=self.arq.state, uuid=self.arq.uuid, expected=expected)
hostname = valid_fields[self.arq.uuid]['hostname']
devrp_uuid = valid_fields[self.arq.uuid]['device_rp_uuid']

View File

@ -157,8 +157,8 @@ class TestARQsController(v2_test.APITestV2):
# TODO(all) Cyborg does not have fake HTTPRequest Object now, so just
# use assertIn here, improve this case with assertRaises later.
self.assertIn(
"Accelerator Requests cannot be requested with "
"state started.", exc.args[0])
"Bad state: started for ARQ: None. Expected state(s): "
"[\\\'resolved\\\']", exc.args[0])
url = '%s?bind_state=started' % (self.ARQ_URL)
exc = None
@ -169,8 +169,8 @@ class TestARQsController(v2_test.APITestV2):
# TODO(all) Cyborg does not have fake HTTPRequest Object now, so just
# use assertIn here, improve this case with assertRaises later.
self.assertIn(
"Accelerator Requests cannot be requested with "
"state started.", exc.args[0])
"Bad state: started for ARQ: None. Expected state(s): "
"[\\\'resolved\\\']", exc.args[0])
@mock.patch('cyborg.objects.ExtARQ.list')
def test_get_all_with_invalid_arq_state(self, mock_extarqs):

View File

@ -108,7 +108,7 @@ class TestExtARQJobMixin(base.DbTestCase):
}
self.assertRaises(
exception.ARQInvalidState, obj_extarq.start_bind_job,
exception.ARQBadState, obj_extarq.start_bind_job,
self.context, valid_fields)
@mock.patch('cyborg.objects.extarq.ext_arq_job.ExtARQJobMixin._bind_job')

View File

@ -104,7 +104,7 @@ class TestExtARQObject(base.DbTestCase):
obj_extarq.arq.state = state
mock_get.return_value = obj_extarq
self.assertRaises(
exception.ARQInvalidState, objects.ExtARQ.apply_patch,
exception.ARQBadState, objects.ExtARQ.apply_patch,
self.context, patch_list, valid_fields)
mock_notify_bind.assert_not_called()