Commit 8a019a03 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

RAPI client: Include HTTP error code in GanetiApiError exception

Having the HTTP error code allows users of the class to act differently based
on the error code.
Signed-off-by: default avatarMichael Hanselmann <>
Reviewed-by: default avatarDavid Knowles <>
parent de4f53e6
......@@ -74,7 +74,9 @@ class GanetiApiError(Error):
"""Generic error raised from Ganeti API.
def __init__(self, msg, code=None):
Error.__init__(self, msg)
self.code = code
class InvalidReplacementMode(Error):
......@@ -414,7 +416,7 @@ class GanetiRapiClient(object):
msg = str(response_content)
raise GanetiApiError(msg)
raise GanetiApiError(msg, code=resp.code)
return response_content
......@@ -151,6 +151,15 @@ class GanetiRapiClientTests(testutils.GanetiTestCase):
def assertDryRun(self):
def testHttpError(self):
self.rapi.AddResponse(None, code=404)
except client.GanetiApiError, err:
self.assertEqual(err.code, 404)
else:"Didn't raise exception")
def testGetVersion(self):
self.client._version = None
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment