Skip to content

Commit

Permalink
Update PointDNSException so it inherits from the base ProviderError c…
Browse files Browse the repository at this point in the history
…lass and

update constructori signature so it matches the parent class one.
  • Loading branch information
Kami committed Oct 3, 2015
1 parent e8f9ba3 commit 0855665
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 49 deletions.
84 changes: 49 additions & 35 deletions libcloud/dns/drivers/pointdns.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import json

from libcloud.utils.py3 import httplib
from libcloud.common.types import ProviderError
from libcloud.common.types import MalformedResponseError
from libcloud.common.pointdns import PointDNSConnection
from libcloud.common.exceptions import BaseHTTPError
Expand All @@ -40,18 +41,13 @@
from libcloud.dns.base import DNSDriver, Zone, Record


class PointDNSException(Exception):
class PointDNSException(ProviderError):

def __init__(self, code, message):
self.code = code
self.message = message
self.args = (code, message)

def __str__(self):
return "%s %s" % (self.code, self.message)

def __repr__(self):
return "PointDNSException %s %s" % (self.code, self.message)
def __init__(self, value, http_code, driver=None):
super(PointDNSException, self).__init__(value=value,
http_code=http_code,
driver=driver)
self.args = (http_code, value)


class Redirect(object):
Expand Down Expand Up @@ -266,7 +262,8 @@ def create_zone(self, domain, ttl=None, extra=None):
data=r_data)
except BaseHTTPError:
e = sys.exc_info()[1]
raise PointDNSException(e.code, e.message)
raise PointDNSException(value=e.message, http_code=e.code,
driver=self)
zone = self._to_zone(response.object)
return zone

Expand Down Expand Up @@ -303,7 +300,8 @@ def create_record(self, name, zone, type, data, extra=None):
method='POST', data=r_data)
except BaseHTTPError:
e = sys.exc_info()[1]
raise PointDNSException(e.code, e.message)
raise PointDNSException(value=e.message, http_code=e.code,
driver=self)
record = self._to_record(response.object, zone=zone)
return record

Expand Down Expand Up @@ -338,7 +336,8 @@ def update_zone(self, zone, domain, ttl=None, extra=None):
raise ZoneDoesNotExistError(value="Zone doesn't exists",
driver=self,
zone_id=zone.id)
raise PointDNSException(e.code, e.message)
raise PointDNSException(value=e.message, http_code=e.code,
driver=self)
zone = self._to_zone(response.object)
return zone

Expand Down Expand Up @@ -381,7 +380,8 @@ def update_record(self, record, name, type, data, extra=None):
raise RecordDoesNotExistError(value="Record doesn't exists",
driver=self,
record_id=record.id)
raise PointDNSException(e.code, e.message)
raise PointDNSException(value=e.message, http_code=e.code,
driver=self)
record = self._to_record(response.object, zone=zone)
return record

Expand Down Expand Up @@ -491,7 +491,8 @@ def ex_create_redirect(self, redirect_to, name, type, zone, iframe=None,
method='POST', data=r_data)
except (BaseHTTPError, MalformedResponseError):
e = sys.exc_info()[1]
raise PointDNSException(e.code, e.message)
raise PointDNSException(value=e.message, http_code=e.code,
driver=self)
redirect = self._to_redirect(response.object, zone=zone)
return redirect

Expand All @@ -516,7 +517,8 @@ def ex_create_mail_redirect(self, destination, source, zone):
data=r_data)
except (BaseHTTPError, MalformedResponseError):
e = sys.exc_info()[1]
raise PointDNSException(e.code, e.message)
raise PointDNSException(value=e.message, http_code=e.code,
driver=self)
mail_redirect = self._to_mail_redirect(response.object, zone=zone)
return mail_redirect

Expand All @@ -536,9 +538,11 @@ def ex_get_redirect(self, zone_id, redirect_id):
except (BaseHTTPError, MalformedResponseError):
e = sys.exc_info()[1]
if isinstance(e, MalformedResponseError) and e.body == 'Not found':
raise PointDNSException(httplib.NOT_FOUND,
"Couldn't found redirect")
raise PointDNSException(e.code, e.message)
raise PointDNSException(value='Couldn\'t found redirect',
http_code=httplib.NOT_FOUND,
driver=self)
raise PointDNSException(value=e.message, http_code=e.code,
driver=self)
redirect = self._to_redirect(response.object, zone_id=zone_id)
return redirect

Expand All @@ -558,9 +562,11 @@ def ex_get_mail_redirects(self, zone_id, mail_r_id):
except (BaseHTTPError, MalformedResponseError):
e = sys.exc_info()[1]
if isinstance(e, MalformedResponseError) and e.body == 'Not found':
raise PointDNSException(httplib.NOT_FOUND,
"Couldn't found mail redirect")
raise PointDNSException(e.code, e.message)
raise PointDNSException(value='Couldn\'t found mail redirect',
http_code=httplib.NOT_FOUND,
driver=self)
raise PointDNSException(value=e.message, http_code=e.code,
driver=self)
mail_redirect = self._to_mail_redirect(response.object,
zone_id=zone_id)
return mail_redirect
Expand Down Expand Up @@ -610,9 +616,11 @@ def ex_update_redirect(self, redirect, redirect_to=None, name=None,
except (BaseHTTPError, MalformedResponseError):
e = sys.exc_info()[1]
if isinstance(e, MalformedResponseError) and e.body == 'Not found':
raise PointDNSException(httplib.NOT_FOUND,
"Couldn't found redirect")
raise PointDNSException(e.code, e.message)
raise PointDNSException(value='Couldn\'t found redirect',
http_code=httplib.NOT_FOUND,
driver=self)
raise PointDNSException(value=e.message, http_code=e.code,
driver=self)
redirect = self._to_redirect(response.object, zone=redirect.zone)
return redirect

Expand Down Expand Up @@ -641,9 +649,11 @@ def ex_update_mail_redirect(self, mail_r, destination, source=None):
except (BaseHTTPError, MalformedResponseError):
e = sys.exc_info()[1]
if isinstance(e, MalformedResponseError) and e.body == 'Not found':
raise PointDNSException(httplib.NOT_FOUND,
"Couldn't found mail redirect")
raise PointDNSException(e.code, e.message)
raise PointDNSException(value='Couldn\'t found mail redirect',
http_code=httplib.NOT_FOUND,
driver=self)
raise PointDNSException(value=e.message, http_code=e.code,
driver=self)
mail_redirect = self._to_mail_redirect(response.object,
zone=mail_r.zone)
return mail_redirect
Expand All @@ -663,9 +673,11 @@ def ex_delete_redirect(self, redirect):
except (BaseHTTPError, MalformedResponseError):
e = sys.exc_info()[1]
if isinstance(e, MalformedResponseError) and e.body == 'Not found':
raise PointDNSException(httplib.NOT_FOUND,
"Couldn't found redirect")
raise PointDNSException(e.code, e.message)
raise PointDNSException(value='Couldn\'t found redirect',
http_code=httplib.NOT_FOUND,
driver=self)
raise PointDNSException(value=e.message, http_code=e.code,
driver=self)
return True

def ex_delete_mail_redirect(self, mail_r):
Expand All @@ -683,9 +695,11 @@ def ex_delete_mail_redirect(self, mail_r):
except (BaseHTTPError, MalformedResponseError):
e = sys.exc_info()[1]
if isinstance(e, MalformedResponseError) and e.body == 'Not found':
raise PointDNSException(httplib.NOT_FOUND,
"Couldn't found mail redirect")
raise PointDNSException(e.code, e.message)
raise PointDNSException(value='Couldn\'t found mail redirect',
http_code=httplib.NOT_FOUND,
driver=self)
raise PointDNSException(value=e.message, http_code=e.code,
driver=self)
return True

def _to_zones(self, data):
Expand Down
28 changes: 14 additions & 14 deletions libcloud/test/dns/test_pointdns.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def test_ex_create_redirect_with_error(self):
e = sys.exc_info()[1]
# The API actually responds with httplib.UNPROCESSABLE_ENTITY code,
# but httplib.responses doesn't have it.
self.assertEqual(e.code, httplib.METHOD_NOT_ALLOWED)
self.assertEqual(e.http_code, httplib.METHOD_NOT_ALLOWED)
else:
self.fail('Exception was not thrown')

Expand All @@ -366,7 +366,7 @@ def test_ex_create_mail_redirect_with_error(self):
e = sys.exc_info()[1]
# The API actually responds with httplib.UNPROCESSABLE_ENTITY code,
# but httplib.responses doesn't have it.
self.assertEqual(e.code, httplib.METHOD_NOT_ALLOWED)
self.assertEqual(e.http_code, httplib.METHOD_NOT_ALLOWED)
else:
self.fail('Exception was not thrown')

Expand All @@ -392,7 +392,7 @@ def test_ex_get_redirect_with_error(self):
e = sys.exc_info()[1]
# The API actually responds with httplib.UNPROCESSABLE_ENTITY code,
# but httplib.responses doesn't have it.
self.assertEqual(e.code, httplib.METHOD_NOT_ALLOWED)
self.assertEqual(e.http_code, httplib.METHOD_NOT_ALLOWED)
else:
self.fail('Exception was not thrown')

Expand All @@ -404,8 +404,8 @@ def test_ex_get_redirect_not_found(self):
self.driver.ex_get_redirect(zone.id, '36843229')
except PointDNSException:
e = sys.exc_info()[1]
self.assertEqual(e.code, httplib.NOT_FOUND)
self.assertEqual(e.message, "Couldn't found redirect")
self.assertEqual(e.http_code, httplib.NOT_FOUND)
self.assertEqual(e.value, "Couldn't found redirect")
else:
self.fail('Exception was not thrown')

Expand All @@ -428,7 +428,7 @@ def test_ex_get_mail_redirects_with_error(self):
e = sys.exc_info()[1]
# The API actually responds with httplib.UNPROCESSABLE_ENTITY code,
# but httplib.responses doesn't have it.
self.assertEqual(e.code, httplib.METHOD_NOT_ALLOWED)
self.assertEqual(e.http_code, httplib.METHOD_NOT_ALLOWED)
else:
self.fail('Exception was not thrown')

Expand Down Expand Up @@ -459,7 +459,7 @@ def test_ex_update_redirect_with_error(self):
e = sys.exc_info()[1]
# The API actually responds with httplib.UNPROCESSABLE_ENTITY code,
# but httplib.responses doesn't have it.
self.assertEqual(e.code, httplib.METHOD_NOT_ALLOWED)
self.assertEqual(e.http_code, httplib.METHOD_NOT_ALLOWED)
else:
self.fail('Exception was not thrown')

Expand Down Expand Up @@ -488,7 +488,7 @@ def test_ex_update_mail_redirect_with_error(self):
e = sys.exc_info()[1]
# The API actually responds with httplib.UNPROCESSABLE_ENTITY code,
# but httplib.responses doesn't have it.
self.assertEqual(e.code, httplib.METHOD_NOT_ALLOWED)
self.assertEqual(e.http_code, httplib.METHOD_NOT_ALLOWED)
else:
self.fail('Exception was not thrown')

Expand All @@ -511,7 +511,7 @@ def test_ex_delete_redirect_with_error(self):
e = sys.exc_info()[1]
# The API actually responds with httplib.UNPROCESSABLE_ENTITY code,
# but httplib.responses doesn't have it.
self.assertEqual(e.code, httplib.METHOD_NOT_ALLOWED)
self.assertEqual(e.http_code, httplib.METHOD_NOT_ALLOWED)
else:
self.fail('Exception was not thrown')

Expand All @@ -524,8 +524,8 @@ def test_ex_delete_redirect_not_found(self):
self.driver.ex_delete_redirect(redirect)
except PointDNSException:
e = sys.exc_info()[1]
self.assertEqual(e.code, httplib.NOT_FOUND)
self.assertEqual(e.message, "Couldn't found redirect")
self.assertEqual(e.http_code, httplib.NOT_FOUND)
self.assertEqual(e.value, "Couldn't found redirect")
else:
self.fail('Exception was not thrown')

Expand All @@ -548,7 +548,7 @@ def test_ex_delete_mail_redirect_with_error(self):
e = sys.exc_info()[1]
# The API actually responds with httplib.UNPROCESSABLE_ENTITY code,
# but httplib.responses doesn't have it.
self.assertEqual(e.code, httplib.METHOD_NOT_ALLOWED)
self.assertEqual(e.http_code, httplib.METHOD_NOT_ALLOWED)
else:
self.fail('Exception was not thrown')

Expand All @@ -561,8 +561,8 @@ def test_ex_delete_mail_redirect_not_found(self):
self.driver.ex_delete_mail_redirect(mailredirect)
except PointDNSException:
e = sys.exc_info()[1]
self.assertEqual(e.code, httplib.NOT_FOUND)
self.assertEqual(e.message, "Couldn't found mail redirect")
self.assertEqual(e.http_code, httplib.NOT_FOUND)
self.assertEqual(e.value, "Couldn't found mail redirect")
else:
self.fail('Exception was not thrown')

Expand Down

0 comments on commit 0855665

Please sign in to comment.