You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2015/02/22 12:51:43 UTC
[1/2] libcloud git commit: Fix HostVirtual list_records method when
no records exist yet
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 <to...@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 <va...@gmail.com>
Authored: Tue Feb 17 13:49:30 2015 +0100
Committer: Tomaz Muraus <to...@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')
[2/2] libcloud git commit: Fix lint and Pycon version compatibility
issues.
Posted by to...@apache.org.
Fix lint and Pycon version compatibility issues.
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/968425c6
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/968425c6
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/968425c6
Branch: refs/heads/trunk
Commit: 968425c62da91b271b04975c5fa5b062f88594f6
Parents: fe0ad78
Author: Tomaz Muraus <to...@apache.org>
Authored: Sun Feb 22 12:49:23 2015 +0100
Committer: Tomaz Muraus <to...@apache.org>
Committed: Sun Feb 22 12:49:23 2015 +0100
----------------------------------------------------------------------
libcloud/dns/drivers/hostvirtual.py | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/968425c6/libcloud/dns/drivers/hostvirtual.py
----------------------------------------------------------------------
diff --git a/libcloud/dns/drivers/hostvirtual.py b/libcloud/dns/drivers/hostvirtual.py
index 400844c..71973c9 100644
--- a/libcloud/dns/drivers/hostvirtual.py
+++ b/libcloud/dns/drivers/hostvirtual.py
@@ -16,6 +16,13 @@ __all__ = [
'HostVirtualDNSDriver'
]
+import sys
+
+try:
+ import simplejson as json
+except:
+ import json
+
from libcloud.utils.py3 import httplib
from libcloud.utils.misc import merge_valid_keys, get_new_obj
from libcloud.common.hostvirtual import HostVirtualResponse
@@ -25,11 +32,6 @@ from libcloud.dns.types import Provider, RecordType
from libcloud.dns.types import ZoneDoesNotExistError, RecordDoesNotExistError
from libcloud.dns.base import DNSDriver, Zone, Record
-try:
- import simplejson as json
-except:
- import json
-
VALID_RECORD_EXTRA_PARAMS = ['prio', 'ttl']
@@ -42,7 +44,7 @@ class HostVirtualDNSResponse(HostVirtualResponse):
if context['resource'] == 'zone':
raise ZoneDoesNotExistError(
value=self.parse_body()['error']['message'],
- driver=self,zone_id=context['id'])
+ driver=self, zone_id=context['id'])
elif context['resource'] == 'record':
raise RecordDoesNotExistError(
value=self.parse_body()['error']['message'],
@@ -120,8 +122,9 @@ class HostVirtualDNSDriver(DNSDriver):
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':
+ except ZoneDoesNotExistError:
+ e = sys.exc_info()[1]
+ if 'Not Found: No Records Found' in e.value:
return []
raise e
records = self._to_records(items=result, zone=zone)