Martin Betak has uploaded a new change for review. Change subject: response: Add support for specific error checking in is_error ......................................................................
response: Add support for specific error checking in is_error response.is_error can now take an optional 'err' argument to check if given response is of that particular error type. E.g. to check if given response if an instance of 'migrateLimit' error: response.is_error(result, 'migrateLimit') This will return false for successful response as well for all error codes other than that of 'migrateLimit'. Change-Id: I00d8d2914983f75293ece5ce05894ca3821b7b24 Signed-off-by: Martin Betak <mbe...@redhat.com> --- M lib/vdsm/response.py M tests/responseTests.py 2 files changed, 9 insertions(+), 2 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/36/54036/1 diff --git a/lib/vdsm/response.py b/lib/vdsm/response.py index 160898f..559c753 100644 --- a/lib/vdsm/response.py +++ b/lib/vdsm/response.py @@ -75,10 +75,13 @@ } -def is_error(res): +def is_error(res, err=None): try: code = res["status"]["code"] except KeyError: raise MalformedResponse(res) else: - return code != doneCode["code"] + if err: + return code == errCode[err]["status"]["code"] + else: + return code != doneCode["code"] diff --git a/tests/responseTests.py b/tests/responseTests.py index 569fce3..427bf48 100644 --- a/tests/responseTests.py +++ b/tests/responseTests.py @@ -75,8 +75,12 @@ def test_is_error(self): NAME = 'noVM' # no special meaning, any error is fine + NAME2 = 'hookError' self.assertTrue(response.is_error(response.error(NAME))) + self.assertTrue(response.is_error(response.error(NAME), err=NAME)) + self.assertFalse(response.is_error(response.error(NAME), err=NAME2)) + def test_malformed_empty(self): self.assertRaises(response.MalformedResponse, response.is_error, -- To view, visit https://gerrit.ovirt.org/54036 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I00d8d2914983f75293ece5ce05894ca3821b7b24 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Martin Betak <mbe...@redhat.com> _______________________________________________ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches