libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject git commit: Fix Google DNS to use valid record split character
Date Mon, 12 May 2014 09:29:00 GMT
Repository: libcloud
Updated Branches:
  refs/heads/trunk 0a049c43f -> 08f6c2c45


Fix Google DNS to use valid record split character

Closes #290

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/08f6c2c4
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/08f6c2c4
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/08f6c2c4

Branch: refs/heads/trunk
Commit: 08f6c2c45e9e58e173d00662efcd5e06cd21d3cf
Parents: 0a049c4
Author: Eric Johnson <erjohnso@google.com>
Authored: Thu May 8 19:35:19 2014 +0000
Committer: Tomaz Muraus <tomaz@apache.org>
Committed: Mon May 12 11:28:30 2014 +0200

----------------------------------------------------------------------
 libcloud/dns/drivers/google.py                  | 10 ++--
 .../google/get_zone_does_not_exists.json        |  4 +-
 libcloud/test/dns/fixtures/google/zone.json     |  1 +
 libcloud/test/dns/test_google.py                | 50 ++++++++++----------
 4 files changed, 34 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/08f6c2c4/libcloud/dns/drivers/google.py
----------------------------------------------------------------------
diff --git a/libcloud/dns/drivers/google.py b/libcloud/dns/drivers/google.py
index aabc783..44a1231 100644
--- a/libcloud/dns/drivers/google.py
+++ b/libcloud/dns/drivers/google.py
@@ -124,7 +124,7 @@ class GoogleDNSDriver(DNSDriver):
 
         :rtype: :class:`Record`
         """
-        (record_name, record_type) = record_id.split('-')
+        (record_type, record_name) = record_id.split(':', 1)
 
         params = {
             'name': record_name,
@@ -142,7 +142,8 @@ class GoogleDNSDriver(DNSDriver):
                                         zone_id=zone_id)
 
         if len(response['rrsets']) > 0:
-            return self._to_record(response['rrsets'][0], zone_id)
+            zone = self.get_zone(zone_id)
+            return self._to_record(response['rrsets'][0], zone)
 
         raise RecordDoesNotExistError(value='', driver=self.connection.driver,
                                       record_id=record_id)
@@ -319,8 +320,9 @@ class GoogleDNSDriver(DNSDriver):
 
         extra['creationTime'] = r.get('creationTime')
         extra['nameServers'] = r.get('nameServers')
+        extra['id'] = r.get('id')
 
-        return Zone(id=r['id'], domain=r['dnsName'],
+        return Zone(id=r['name'], domain=r['dnsName'],
                     type='master', ttl=0, driver=self, extra=extra)
 
     def _to_records(self, response, zone):
@@ -330,7 +332,7 @@ class GoogleDNSDriver(DNSDriver):
         return records
 
     def _to_record(self, r, zone):
-        record_id = '%s-%s' % (r['name'], r['type'])
+        record_id = '%s:%s' % (r['type'], r['name'])
         return Record(id=record_id, name=r['name'],
                       type=r['type'], data=r, zone=zone,
                       driver=self, extra={})

http://git-wip-us.apache.org/repos/asf/libcloud/blob/08f6c2c4/libcloud/test/dns/fixtures/google/get_zone_does_not_exists.json
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/fixtures/google/get_zone_does_not_exists.json b/libcloud/test/dns/fixtures/google/get_zone_does_not_exists.json
index ddd959d..a38eb6a 100644
--- a/libcloud/test/dns/fixtures/google/get_zone_does_not_exists.json
+++ b/libcloud/test/dns/fixtures/google/get_zone_does_not_exists.json
@@ -4,10 +4,10 @@
    {
     "domain": "global",
     "reason": "notFound",
-    "message": "The 'parameters.managedZone' resource named '2' does not exist."
+    "message": "The 'parameters.managedZone' resource named 'example-com' does not exist."
    }
   ],
   "code": 404,
-  "message": "The 'parameters.managedZone' resource named '2' does not exist."
+  "message": "The 'parameters.managedZone' resource named 'example-com' does not exist."
  }
 }

http://git-wip-us.apache.org/repos/asf/libcloud/blob/08f6c2c4/libcloud/test/dns/fixtures/google/zone.json
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/fixtures/google/zone.json b/libcloud/test/dns/fixtures/google/zone.json
new file mode 100644
index 0000000..a380c6e
--- /dev/null
+++ b/libcloud/test/dns/fixtures/google/zone.json
@@ -0,0 +1 @@
+{"kind": "dns#managedZone", "name": "example-com", "nameServers": ["ns-cloud-e1.googledomains.com.",
"ns-cloud-e2.googledomains.com.", "ns-cloud-e3.googledomains.com.", "ns-cloud-e4.googledomains.com."],
"creationTime": "2014-03-29T22:45:47.618Z", "dnsName": "example.com.", "id": "1", "description":
""}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/08f6c2c4/libcloud/test/dns/test_google.py
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/test_google.py b/libcloud/test/dns/test_google.py
index 2a4b8c7..e6d0595 100644
--- a/libcloud/test/dns/test_google.py
+++ b/libcloud/test/dns/test_google.py
@@ -56,46 +56,48 @@ class GoogleTests(LibcloudTestCase):
         self.assertEqual(len(records), 3)
 
     def test_get_zone(self):
-        zone = self.driver.get_zone(1)
-        self.assertEqual(zone.id, '1')
+        zone = self.driver.get_zone('example-com')
+        self.assertEqual(zone.id, 'example-com')
         self.assertEqual(zone.domain, 'example.com.')
 
     def test_get_zone_does_not_exist(self):
         GoogleDNSMockHttp.type = 'ZONE_DOES_NOT_EXIST'
 
         try:
-            self.driver.get_zone(2)
+            self.driver.get_zone('example-com')
         except ZoneDoesNotExistError:
             e = sys.exc_info()[1]
-            self.assertEqual(e.zone_id, 2)
+            self.assertEqual(e.zone_id, 'example-com')
         else:
             self.fail('Exception not thrown')
 
     def test_get_record(self):
         GoogleDNSMockHttp.type = 'FILTER_ZONES'
         zone = self.driver.list_zones()[0]
-        record = self.driver.get_record(zone.id, "foo.example.com.-A")
+        record = self.driver.get_record(zone.id, "A:foo.example.com.")
+        self.assertEqual(record.id, 'A:foo.example.com.')
         self.assertEqual(record.name, 'foo.example.com.')
         self.assertEqual(record.type, 'A')
+        self.assertEqual(record.zone.id, 'example-com')
 
     def test_get_record_zone_does_not_exist(self):
         GoogleDNSMockHttp.type = 'ZONE_DOES_NOT_EXIST'
 
         try:
-            self.driver.get_record(2, 'a-a')
+            self.driver.get_record('example-com', 'a:a')
         except ZoneDoesNotExistError:
             e = sys.exc_info()[1]
-            self.assertEqual(e.zone_id, 2)
+            self.assertEqual(e.zone_id, 'example-com')
         else:
             self.fail('Exception not thrown')
 
     def test_get_record_record_does_not_exist(self):
         GoogleDNSMockHttp.type = 'RECORD_DOES_NOT_EXIST'
         try:
-            self.driver.get_record(1, "foo-A")
+            self.driver.get_record('example-com', "A:foo")
         except RecordDoesNotExistError:
             e = sys.exc_info()[1]
-            self.assertEqual(e.record_id, 'foo-A')
+            self.assertEqual(e.record_id, 'A:foo')
         else:
             self.fail('Exception not thrown')
 
@@ -107,7 +109,7 @@ class GoogleTests(LibcloudTestCase):
         self.assertEqual(len(zone.extra['nameServers']), 4)
 
     def test_delete_zone(self):
-        zone = self.driver.get_zone(1)
+        zone = self.driver.get_zone('example-com')
         res = self.driver.delete_zone(zone)
         self.assertTrue(res)
 
@@ -128,52 +130,50 @@ class GoogleDNSMockHttp(MockHttpTestCase):
         body = self.fixtures.load('zone_list.json')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
-    def _dns_v1beta1_projects_project_name_managedZones_1_rrsets_FILTER_ZONES(
+    def _dns_v1beta1_projects_project_name_managedZones_example_com_rrsets_FILTER_ZONES(
             self, method, url, body, headers):
         body = self.fixtures.load('record.json')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
-    def _dns_v1beta1_projects_project_name_managedZones_1_rrsets(
+    def _dns_v1beta1_projects_project_name_managedZones_example_com_rrsets(
             self, method, url, body, headers):
         body = self.fixtures.load('records_list.json')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
-    def _dns_v1beta1_projects_project_name_managedZones_1(self, method,
-                                                          url, body,
-                                                          headers):
+    def _dns_v1beta1_projects_project_name_managedZones_example_com(
+            self, method, url, body, headers):
         if method == 'GET':
             body = self.fixtures.load('managed_zones_1.json')
         elif method == 'DELETE':
             body = None
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
-    def _dns_v1beta1_projects_project_name_managedZones_2_ZONE_DOES_NOT_EXIST(
+    def _dns_v1beta1_projects_project_name_managedZones_example_com_ZONE_DOES_NOT_EXIST(
             self, method, url, body, headers):
         body = self.fixtures.load('get_zone_does_not_exists.json')
         return (httplib.NOT_FOUND, body, {},
                 httplib.responses[httplib.NOT_FOUND])
 
-    def _dns_v1beta1_projects_project_name_managedZones_3_ZONE_DOES_NOT_EXIST(
-            self, method, url, body, headers):
-        body = self.fixtures.load('get_zone_does_not_exists.json')
-        return (httplib.NOT_FOUND, body, {},
-                httplib.responses[httplib.NOT_FOUND])
-
-    def _dns_v1beta1_projects_project_name_managedZones_1_RECORD_DOES_NOT_EXIST(
+    def _dns_v1beta1_projects_project_name_managedZones_example_com_RECORD_DOES_NOT_EXIST(
             self, method, url, body, headers):
         body = self.fixtures.load('managed_zones_1.json')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
-    def _dns_v1beta1_projects_project_name_managedZones_1_rrsets_RECORD_DOES_NOT_EXIST(
+    def _dns_v1beta1_projects_project_name_managedZones_example_com_rrsets_RECORD_DOES_NOT_EXIST(
             self, method, url, body, headers):
         body = self.fixtures.load('no_record.json')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
-    def _dns_v1beta1_projects_project_name_managedZones_2_rrsets_ZONE_DOES_NOT_EXIST(
+    def _dns_v1beta1_projects_project_name_managedZones_example_com_rrsets_ZONE_DOES_NOT_EXIST(
             self, method, url, body, headers):
         body = self.fixtures.load('get_zone_does_not_exists.json')
         return (httplib.NOT_FOUND, body, {},
                 httplib.responses[httplib.NOT_FOUND])
 
+    def _dns_v1beta1_projects_project_name_managedZones_example_com_FILTER_ZONES(
+            self, method, url, body, headers):
+        body = self.fixtures.load('zone.json')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
 if __name__ == '__main__':
     sys.exit(unittest.main())


Mime
View raw message