Repository: libcloud Updated Branches: refs/heads/trunk d10676afa -> 047dd064d
Improve error parsing in the DigitalOcean driver. Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/047dd064 Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/047dd064 Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/047dd064 Branch: refs/heads/trunk Commit: 047dd064db66a57f4273293b1e5109f2a49e8d36 Parents: d10676a Author: Tomaz Muraus <[email protected]> Authored: Thu Feb 27 15:10:42 2014 +0100 Committer: Tomaz Muraus <[email protected]> Committed: Thu Feb 27 15:14:31 2014 +0100 ---------------------------------------------------------------------- CHANGES.rst | 5 +++++ docs/development.rst | 3 +++ libcloud/compute/drivers/digitalocean.py | 8 +++++++ .../digitalocean/error_invalid_image.json | 1 + libcloud/test/compute/test_digitalocean.py | 22 ++++++++++++++++++-- 5 files changed, 37 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/047dd064/CHANGES.rst ---------------------------------------------------------------------- diff --git a/CHANGES.rst b/CHANGES.rst index b24c39c..74ea79e 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -34,6 +34,11 @@ Compute (GITHUB-252) [Rahul Ranjan] +- Improve error parsing in the DigitalOcean driver. + + Reported by Deni Bertovic. + [Tomaz Muraus] + Changes with Apache Libcloud 0.14.1 ----------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/047dd064/docs/development.rst ---------------------------------------------------------------------- diff --git a/docs/development.rst b/docs/development.rst index 5d9b673..b3ef500 100644 --- a/docs/development.rst +++ b/docs/development.rst @@ -14,6 +14,9 @@ If you need help or get stuck at any point during this process, stop by on our IRC channel (:ref:`#libcloud on freenode <irc>`) and we will do our best to assist you. +Getting started with contributing to Libcloud +--------------------------------------------- + General contribution guidelines ------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/047dd064/libcloud/compute/drivers/digitalocean.py ---------------------------------------------------------------------- diff --git a/libcloud/compute/drivers/digitalocean.py b/libcloud/compute/drivers/digitalocean.py index 962862c..7dbed41 100644 --- a/libcloud/compute/drivers/digitalocean.py +++ b/libcloud/compute/drivers/digitalocean.py @@ -32,6 +32,14 @@ class DigitalOceanResponse(JsonResponse): elif self.status == httplib.UNAUTHORIZED: body = self.parse_body() raise InvalidCredsError(body['message']) + else: + body = self.parse_body() + + if 'error_message' in body: + error = '%s (code: %s)' % (body['error_message'], self.status) + else: + error = body + return error class SSHKey(object): http://git-wip-us.apache.org/repos/asf/libcloud/blob/047dd064/libcloud/test/compute/fixtures/digitalocean/error_invalid_image.json ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/fixtures/digitalocean/error_invalid_image.json b/libcloud/test/compute/fixtures/digitalocean/error_invalid_image.json new file mode 100644 index 0000000..e1ccb4f --- /dev/null +++ b/libcloud/test/compute/fixtures/digitalocean/error_invalid_image.json @@ -0,0 +1 @@ +{"status":"ERROR","error_message":"You specified an invalid image for Droplet creation.","message":"You specified an invalid image for Droplet creation."} http://git-wip-us.apache.org/repos/asf/libcloud/blob/047dd064/libcloud/test/compute/test_digitalocean.py ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/test_digitalocean.py b/libcloud/test/compute/test_digitalocean.py index 400b605..ee9ef55 100644 --- a/libcloud/test/compute/test_digitalocean.py +++ b/libcloud/test/compute/test_digitalocean.py @@ -23,15 +23,16 @@ except ImportError: from libcloud.utils.py3 import httplib from libcloud.common.types import InvalidCredsError +from libcloud.compute.base import NodeImage from libcloud.compute.drivers.digitalocean import DigitalOceanNodeDriver -from libcloud.test import MockHttpTestCase +from libcloud.test import LibcloudTestCase, MockHttpTestCase from libcloud.test.file_fixtures import ComputeFileFixtures from libcloud.test.secrets import DIGITAL_OCEAN_PARAMS # class DigitalOceanTests(unittest.TestCase, TestCaseMixin): -class DigitalOceanTests(unittest.TestCase): +class DigitalOceanTests(LibcloudTestCase): def setUp(self): DigitalOceanNodeDriver.connectionCls.conn_classes = \ @@ -79,6 +80,18 @@ class DigitalOceanTests(unittest.TestCase): self.assertEqual(nodes[0].name, 'test-2') self.assertEqual(nodes[0].public_ips, []) + def test_create_node_invalid_size(self): + image = NodeImage(id='invalid', name=None, driver=self.driver) + size = self.driver.list_sizes()[0] + location = self.driver.list_locations()[0] + + DigitalOceanMockHttp.type = 'INVALID_IMAGE' + expected_msg = r'You specified an invalid image for Droplet creation. \(code: 404\)' + self.assertRaisesRegexp(Exception, expected_msg, + self.driver.create_node, + name='test', size=size, image=image, + location=location) + def test_reboot_node_success(self): node = self.driver.list_nodes()[0] result = self.driver.reboot_node(node) @@ -127,6 +140,11 @@ class DigitalOceanMockHttp(MockHttpTestCase): body = self.fixtures.load('list_nodes.json') return (httplib.OK, body, {}, httplib.responses[httplib.OK]) + def _droplets_new_INVALID_IMAGE(self, method, url, body, headers): + # reboot_node + body = self.fixtures.load('error_invalid_image.json') + return (httplib.NOT_FOUND, body, {}, httplib.responses[httplib.NOT_FOUND]) + def _droplets_119461_reboot(self, method, url, body, headers): # reboot_node body = self.fixtures.load('reboot_node.json')
