libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [1/2] libcloud git commit: Fix HostVirtual list_records method when no records exist yet
Date Sun, 22 Feb 2015 11:51:43 GMT
Repository: libcloud
Updated Branches:
  refs/heads/trunk 0fafc7d38 -> 968425c62


Fix HostVirtual list_records method when no records exist yet

Closes #460

Signed-off-by: Tomaz Muraus <tomaz@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/fe0ad781
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/fe0ad781
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/fe0ad781

Branch: refs/heads/trunk
Commit: fe0ad781f4bce00ac93379c168b708d8a9858d04
Parents: 0fafc7d
Author: Vanč Levstik <vanc.levstik@gmail.com>
Authored: Tue Feb 17 13:49:30 2015 +0100
Committer: Tomaz Muraus <tomaz@apache.org>
Committed: Sun Feb 22 12:49:19 2015 +0100

----------------------------------------------------------------------
 CHANGES.rst                                      |  8 ++++++++
 libcloud/dns/drivers/hostvirtual.py              | 19 +++++++++++++------
 .../fixtures/hostvirtual/list_records_none.json  |  6 ++++++
 libcloud/test/dns/test_hostvirtual.py            | 13 +++++++++++++
 4 files changed, 40 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/fe0ad781/CHANGES.rst
----------------------------------------------------------------------
diff --git a/CHANGES.rst b/CHANGES.rst
index 7ef3a75..d5ff01e 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -38,6 +38,14 @@ Compute
   (LIBCLOUD-663, GITHUB-450)
   [Allard Hoeve]
 
+DNS
+~~~
+
+- Fix a bug when a ZoneDoesntExist exception was thrown when listing records
+  for a zone which has no records in the HostVirtual driver.
+  (GITHUB-460)
+  [Vanč Levstik]
+
 Changes with Apache Libcloud 0.17.0
 -----------------------------------
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/fe0ad781/libcloud/dns/drivers/hostvirtual.py
----------------------------------------------------------------------
diff --git a/libcloud/dns/drivers/hostvirtual.py b/libcloud/dns/drivers/hostvirtual.py
index 1d9eec2..400844c 100644
--- a/libcloud/dns/drivers/hostvirtual.py
+++ b/libcloud/dns/drivers/hostvirtual.py
@@ -40,11 +40,13 @@ class HostVirtualDNSResponse(HostVirtualResponse):
 
         if status == httplib.NOT_FOUND:
             if context['resource'] == 'zone':
-                raise ZoneDoesNotExistError(value='', driver=self,
-                                            zone_id=context['id'])
+                raise ZoneDoesNotExistError(
+                    value=self.parse_body()['error']['message'],
+                    driver=self,zone_id=context['id'])
             elif context['resource'] == 'record':
-                raise RecordDoesNotExistError(value='', driver=self,
-                                              record_id=context['id'])
+                raise RecordDoesNotExistError(
+                    value=self.parse_body()['error']['message'],
+                    driver=self, record_id=context['id'])
 
         super(HostVirtualDNSResponse, self).parse_error()
         return self.body
@@ -115,8 +117,13 @@ class HostVirtualDNSDriver(DNSDriver):
     def list_records(self, zone):
         params = {'id': zone.id}
         self.connection.set_context({'resource': 'zone', 'id': zone.id})
-        result = self.connection.request(
-            API_ROOT + '/dns/records/', params=params).object
+        try:
+            result = self.connection.request(
+                API_ROOT + '/dns/records/', params=params).object
+        except ZoneDoesNotExistError as e:
+            if e.value == u'Not Found: No Records Found':
+                return []
+            raise e
         records = self._to_records(items=result, zone=zone)
         return records
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/fe0ad781/libcloud/test/dns/fixtures/hostvirtual/list_records_none.json
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/fixtures/hostvirtual/list_records_none.json b/libcloud/test/dns/fixtures/hostvirtual/list_records_none.json
new file mode 100644
index 0000000..cca4133
--- /dev/null
+++ b/libcloud/test/dns/fixtures/hostvirtual/list_records_none.json
@@ -0,0 +1,6 @@
+{
+    "error": {
+        "code": 404,
+        "message": "Not Found: No Records Found"
+    }
+}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/fe0ad781/libcloud/test/dns/test_hostvirtual.py
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/test_hostvirtual.py b/libcloud/test/dns/test_hostvirtual.py
index f74571b..26c00f8 100644
--- a/libcloud/test/dns/test_hostvirtual.py
+++ b/libcloud/test/dns/test_hostvirtual.py
@@ -59,6 +59,14 @@ class HostVirtualTests(unittest.TestCase):
         self.assertEqual(record.type, RecordType.A)
         self.assertEqual(record.data, '208.111.35.173')
 
+    def test_list_records_none(self):
+
+        zone = self.driver.list_zones()[0]
+
+        HostVirtualMockHttp.type = 'NO_RECORDS'
+        records = self.driver.list_records(zone=zone)
+        self.assertEqual(len(records), 0)
+
     def test_get_zone(self):
         zone = self.driver.get_zone(zone_id='47234')
         self.assertEqual(zone.id, '47234')
@@ -247,6 +255,11 @@ class HostVirtualMockHttp(MockHttp):
         return (httplib.NOT_FOUND, body,
                 {}, httplib.responses[httplib.NOT_FOUND])
 
+    def _dns_records_NO_RECORDS(self, method, url, body, headers):
+        body = self.fixtures.load('list_records_none.json')
+        return (httplib.NOT_FOUND, body,
+                {}, httplib.responses[httplib.NOT_FOUND])
+
     def _dns_zones_RECORD_DOES_NOT_EXIST(self, method,
                                          url, body, headers):
         body = self.fixtures.load('zone_does_not_exist.json')


Mime
View raw message