libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [08/14] libcloud git commit: Add tests for the CloudFlare DNS diver.
Date Sun, 06 Dec 2015 06:32:46 GMT
Add tests for the CloudFlare DNS diver.


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

Branch: refs/heads/trunk
Commit: b85a9b6edda6428d98db7a018b937c1aedf507d7
Parents: de9e0da
Author: Tomaz Muraus <tomaz@tomaz.me>
Authored: Sun Dec 6 12:34:34 2015 +0800
Committer: Tomaz Muraus <tomaz@tomaz.me>
Committed: Sun Dec 6 13:32:52 2015 +0800

----------------------------------------------------------------------
 libcloud/dns/drivers/cloudflare.py              |  14 +-
 .../test/dns/fixtures/cloudflare/ip_lkup.json   |   7 +
 .../dns/fixtures/cloudflare/rec_delete.json     |  12 +
 .../test/dns/fixtures/cloudflare/rec_edit.json  |  48 ++
 .../dns/fixtures/cloudflare/rec_load_all.json   | 525 +++++++++++++++++++
 .../test/dns/fixtures/cloudflare/rec_new.json   |  47 ++
 .../test/dns/fixtures/cloudflare/stats.json     |  47 ++
 .../dns/fixtures/cloudflare/zone_check.json     |   9 +
 .../fixtures/cloudflare/zone_load_multi.json    |  62 +++
 .../dns/fixtures/cloudflare/zone_settings.json  |  44 ++
 libcloud/test/dns/test_cloudflare.py            | 214 ++++++++
 libcloud/test/secrets.py-dist                   |   1 +
 12 files changed, 1026 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/b85a9b6e/libcloud/dns/drivers/cloudflare.py
----------------------------------------------------------------------
diff --git a/libcloud/dns/drivers/cloudflare.py b/libcloud/dns/drivers/cloudflare.py
index cfa6fd4..f901d30 100644
--- a/libcloud/dns/drivers/cloudflare.py
+++ b/libcloud/dns/drivers/cloudflare.py
@@ -202,7 +202,7 @@ class CloudFlareDNSDriver(DNSDriver):
         params = {'z': zone.domain, 'interval': interval}
         self.connection.set_context({'zone_domain': zone.domain})
         resp = self.connection.request(action='stats', params=params)
-        result = resp.object['response']['result']['objs']
+        result = resp.object['response']['result']['objs'][0]
         return result
 
     def ex_zone_check(self, zones):
@@ -367,7 +367,7 @@ class CloudFlareDNSDriver(DNSDriver):
 
     def _to_zone(self, item):
         zone_type = item.get('zone_type', '').lower()
-        type = 'master' if zone_type == 'p' else 'slave'
+        type = 'master'
 
         extra = {}
         extra['props'] = item.get('props', {})
@@ -395,15 +395,21 @@ class CloudFlareDNSDriver(DNSDriver):
         type = item['type']
         data = item['content']
 
+        if item.get('ttl', None):
+            ttl = int(item['ttl'])
+        else:
+            ttl = None
+
         extra = {}
-        extra['ttl'] = item['ttl']
+        extra['ttl'] = ttl
         extra['props'] = item.get('props', {})
         for attribute in RECORD_EXTRA_ATTRIBUTES:
             value = item.get(attribute, None)
             extra[attribute] = value
 
         record = Record(id=str(item['rec_id']), name=name, type=type,
-                        data=data, zone=zone, driver=self, extra=extra)
+                        data=data, zone=zone, driver=self, ttl=ttl,
+                        extra=extra)
         return record
 
     def _get_record_name(self, item):

http://git-wip-us.apache.org/repos/asf/libcloud/blob/b85a9b6e/libcloud/test/dns/fixtures/cloudflare/ip_lkup.json
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/fixtures/cloudflare/ip_lkup.json b/libcloud/test/dns/fixtures/cloudflare/ip_lkup.json
new file mode 100644
index 0000000..d0118a1
--- /dev/null
+++ b/libcloud/test/dns/fixtures/cloudflare/ip_lkup.json
@@ -0,0 +1,7 @@
+{
+  "response": {
+    "127.0.0.1": false
+  },
+  "result": "success",
+  "msg": null
+}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/b85a9b6e/libcloud/test/dns/fixtures/cloudflare/rec_delete.json
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/fixtures/cloudflare/rec_delete.json b/libcloud/test/dns/fixtures/cloudflare/rec_delete.json
new file mode 100644
index 0000000..0ffee1c
--- /dev/null
+++ b/libcloud/test/dns/fixtures/cloudflare/rec_delete.json
@@ -0,0 +1,12 @@
+{
+  "request": {
+    "act": "rec_delete",
+    "tkn": "maybeno",
+    "a": "rec_delete",
+    "z": "example.com",
+    "id": "412563484",
+    "email": "example@example.com"
+  },
+  "result": "success",
+  "msg": null
+}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/b85a9b6e/libcloud/test/dns/fixtures/cloudflare/rec_edit.json
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/fixtures/cloudflare/rec_edit.json b/libcloud/test/dns/fixtures/cloudflare/rec_edit.json
new file mode 100644
index 0000000..68128e8
--- /dev/null
+++ b/libcloud/test/dns/fixtures/cloudflare/rec_edit.json
@@ -0,0 +1,48 @@
+{
+  "request": {
+    "act": "rec_edit",
+    "a": "rec_edit",
+    "name": "test6",
+    "tkn": "maybeno",
+    "id": "412564825",
+    "content": "127.0.0.4",
+    "ttl": "120",
+    "z": "example.com",
+    "type": "A",
+    "email": "example@example.com"
+  },
+  "response": {
+    "rec": {
+      "obj": {
+        "rec_id": "412564825",
+        "rec_hash": "0cb296652af55023e5bf5ee6c9ad9974",
+        "zone_name": "example.com",
+        "name": "test6.example.com",
+        "display_name": "test6",
+        "type": "A",
+        "prio": null,
+        "content": "127.0.0.4",
+        "display_content": "127.0.0.4",
+        "ttl": "120",
+        "ttl_ceil": 86400,
+        "ssl_id": "2245194",
+        "ssl_status": "V",
+        "ssl_expires_on": null,
+        "auto_ttl": 0,
+        "service_mode": "0",
+        "props": {
+          "proxiable": 0,
+          "cloud_on": 0,
+          "cf_open": 1,
+          "vanity_lock": 0,
+          "ssl": 1,
+          "expired_ssl": 0,
+          "expiring_ssl": 0,
+          "pending_ssl": 0
+        }
+      }
+    }
+  },
+  "result": "success",
+  "msg": null
+}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/b85a9b6e/libcloud/test/dns/fixtures/cloudflare/rec_load_all.json
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/fixtures/cloudflare/rec_load_all.json b/libcloud/test/dns/fixtures/cloudflare/rec_load_all.json
new file mode 100644
index 0000000..dde804e
--- /dev/null
+++ b/libcloud/test/dns/fixtures/cloudflare/rec_load_all.json
@@ -0,0 +1,525 @@
+{
+  "request": {
+    "act": "rec_load_all",
+    "tkn": "maybeno",
+    "a": "rec_load_all",
+    "z": "example.com",
+    "email": "example@example.com"
+  },
+  "response": {
+    "recs": {
+      "has_more": false,
+      "count": 18,
+      "objs": [{
+        "rec_id": "364797364",
+        "rec_hash": "479a684c73e0e75c433675e86957660a",
+        "zone_name": "example.com",
+        "name": "example.com",
+        "display_name": "example.com",
+        "type": "A",
+        "prio": null,
+        "content": "192.30.252.153",
+        "display_content": "192.30.252.153",
+        "ttl": "1",
+        "ttl_ceil": 86400,
+        "ssl_id": "2245194",
+        "ssl_status": "V",
+        "ssl_expires_on": null,
+        "auto_ttl": 1,
+        "service_mode": "1",
+        "props": {
+          "proxiable": 1,
+          "cloud_on": 1,
+          "cf_open": 0,
+          "vanity_lock": 0,
+          "ssl": 1,
+          "expired_ssl": 0,
+          "expiring_ssl": 0,
+          "pending_ssl": 0
+        }
+      }, {
+        "rec_id": "364797367",
+        "rec_hash": "acaee7d8c6e256f7bcc5dab4410489cf",
+        "zone_name": "example.com",
+        "name": "example.com",
+        "display_name": "example.com",
+        "type": "A",
+        "prio": null,
+        "content": "192.30.252.154",
+        "display_content": "192.30.252.154",
+        "ttl": "1",
+        "ttl_ceil": 86400,
+        "ssl_id": "2245194",
+        "ssl_status": "V",
+        "ssl_expires_on": null,
+        "auto_ttl": 1,
+        "service_mode": "1",
+        "props": {
+          "proxiable": 1,
+          "cloud_on": 1,
+          "cf_open": 0,
+          "vanity_lock": 0,
+          "ssl": 1,
+          "expired_ssl": 0,
+          "expiring_ssl": 0,
+          "pending_ssl": 0
+        }
+      }, {
+        "rec_id": "403456915",
+        "rec_hash": "77cabc2ba4a75814eeda78daabce0859",
+        "zone_name": "example.com",
+        "name": "test2.example.com",
+        "display_name": "test2",
+        "type": "A",
+        "prio": null,
+        "content": "127.0.0.2",
+        "display_content": "127.0.0.2",
+        "ttl": "120",
+        "ttl_ceil": 86400,
+        "ssl_id": "2245194",
+        "ssl_status": "V",
+        "ssl_expires_on": null,
+        "auto_ttl": 0,
+        "service_mode": "0",
+        "props": {
+          "proxiable": 0,
+          "cloud_on": 0,
+          "cf_open": 1,
+          "vanity_lock": 0,
+          "ssl": 1,
+          "expired_ssl": 0,
+          "expiring_ssl": 0,
+          "pending_ssl": 0
+        }
+      }, {
+        "rec_id": "403456984",
+        "rec_hash": "edd95959936d20583e38352831d1978b",
+        "zone_name": "example.com",
+        "name": "test3.example.com",
+        "display_name": "test3",
+        "type": "A",
+        "prio": null,
+        "content": "127.0.0.1",
+        "display_content": "127.0.0.1",
+        "ttl": "120",
+        "ttl_ceil": 86400,
+        "ssl_id": "2245194",
+        "ssl_status": "V",
+        "ssl_expires_on": null,
+        "auto_ttl": 0,
+        "service_mode": "0",
+        "props": {
+          "proxiable": 0,
+          "cloud_on": 0,
+          "cf_open": 1,
+          "vanity_lock": 0,
+          "ssl": 1,
+          "expired_ssl": 0,
+          "expiring_ssl": 0,
+          "pending_ssl": 0
+        }
+      }, {
+        "rec_id": "364982413",
+        "rec_hash": "fa43ee2e176f9be7b8e464167bdff440",
+        "zone_name": "example.com",
+        "name": "yesyes.example.com",
+        "display_name": "yesyes",
+        "type": "CNAME",
+        "prio": null,
+        "content": "verify.bing.com",
+        "display_content": "verify.bing.com",
+        "ttl": "1",
+        "ttl_ceil": 86400,
+        "ssl_id": "2245194",
+        "ssl_status": "V",
+        "ssl_expires_on": null,
+        "auto_ttl": 1,
+        "service_mode": "0",
+        "props": {
+          "proxiable": 1,
+          "cloud_on": 0,
+          "cf_open": 1,
+          "vanity_lock": 0,
+          "ssl": 1,
+          "expired_ssl": 0,
+          "expiring_ssl": 0,
+          "pending_ssl": 0
+        }
+      }, {
+        "rec_id": "364982461",
+        "rec_hash": "4dfb7dd8d8a895174600fe9fb0f48380",
+        "zone_name": "example.com",
+        "name": "google.example.com",
+        "display_name": "google",
+        "type": "CNAME",
+        "prio": null,
+        "content": "google.com",
+        "display_content": "google.com",
+        "ttl": "1",
+        "ttl_ceil": 86400,
+        "ssl_id": "2245194",
+        "ssl_status": "V",
+        "ssl_expires_on": null,
+        "auto_ttl": 1,
+        "service_mode": "0",
+        "props": {
+          "proxiable": 1,
+          "cloud_on": 0,
+          "cf_open": 1,
+          "vanity_lock": 0,
+          "ssl": 1,
+          "expired_ssl": 0,
+          "expiring_ssl": 0,
+          "pending_ssl": 0
+        }
+      }, {
+        "rec_id": "364797370",
+        "rec_hash": "537311442890afedc06e5febf7171023",
+        "zone_name": "example.com",
+        "name": "www.example.com",
+        "display_name": "www",
+        "type": "CNAME",
+        "prio": null,
+        "content": "kami.github.io",
+        "display_content": "kami.github.io",
+        "ttl": "1",
+        "ttl_ceil": 86400,
+        "ssl_id": "2245194",
+        "ssl_status": "V",
+        "ssl_expires_on": null,
+        "auto_ttl": 1,
+        "service_mode": "1",
+        "props": {
+          "proxiable": 1,
+          "cloud_on": 1,
+          "cf_open": 0,
+          "vanity_lock": 0,
+          "ssl": 1,
+          "expired_ssl": 0,
+          "expiring_ssl": 0,
+          "pending_ssl": 0
+        }
+      }, {
+        "rec_id": "364797388",
+        "rec_hash": "a55e09423fa23c33906131aa678e86ba",
+        "zone_name": "example.com",
+        "name": "example.com",
+        "display_name": "example.com",
+        "type": "MX",
+        "prio": "20",
+        "content": "alt1.aspmx.l.google.com",
+        "display_content": "alt1.aspmx.l.google.com",
+        "ttl": "1",
+        "ttl_ceil": 86400,
+        "ssl_id": "2245194",
+        "ssl_status": "V",
+        "ssl_expires_on": null,
+        "auto_ttl": 1,
+        "service_mode": "0",
+        "props": {
+          "proxiable": 0,
+          "cloud_on": 0,
+          "cf_open": 1,
+          "vanity_lock": 0,
+          "ssl": 1,
+          "expired_ssl": 0,
+          "expiring_ssl": 0,
+          "pending_ssl": 0
+        },
+        "mx": {
+          "auto": false
+        }
+      }, {
+        "rec_id": "364797382",
+        "rec_hash": "c1bc38b678f1c07af3d506a0b4f57da4",
+        "zone_name": "example.com",
+        "name": "example.com",
+        "display_name": "example.com",
+        "type": "MX",
+        "prio": "20",
+        "content": "alt2.aspmx.l.google.com",
+        "display_content": "alt2.aspmx.l.google.com",
+        "ttl": "1",
+        "ttl_ceil": 86400,
+        "ssl_id": "2245194",
+        "ssl_status": "V",
+        "ssl_expires_on": null,
+        "auto_ttl": 1,
+        "service_mode": "0",
+        "props": {
+          "proxiable": 0,
+          "cloud_on": 0,
+          "cf_open": 1,
+          "vanity_lock": 0,
+          "ssl": 1,
+          "expired_ssl": 0,
+          "expiring_ssl": 0,
+          "pending_ssl": 0
+        },
+        "mx": {
+          "auto": false
+        }
+      }, {
+        "rec_id": "364797391",
+        "rec_hash": "90b3f10c8cbe2164b87302de99cf7760",
+        "zone_name": "example.com",
+        "name": "example.com",
+        "display_name": "example.com",
+        "type": "MX",
+        "prio": "30",
+        "content": "aspmx2.googlemail.com",
+        "display_content": "aspmx2.googlemail.com",
+        "ttl": "1",
+        "ttl_ceil": 86400,
+        "ssl_id": "2245194",
+        "ssl_status": "V",
+        "ssl_expires_on": null,
+        "auto_ttl": 1,
+        "service_mode": "0",
+        "props": {
+          "proxiable": 0,
+          "cloud_on": 0,
+          "cf_open": 1,
+          "vanity_lock": 0,
+          "ssl": 1,
+          "expired_ssl": 0,
+          "expiring_ssl": 0,
+          "pending_ssl": 0
+        },
+        "mx": {
+          "auto": false
+        }
+      }, {
+        "rec_id": "364797385",
+        "rec_hash": "99cad8b4ae97d559716c838276d1bf43",
+        "zone_name": "example.com",
+        "name": "example.com",
+        "display_name": "example.com",
+        "type": "MX",
+        "prio": "30",
+        "content": "aspmx3.googlemail.com",
+        "display_content": "aspmx3.googlemail.com",
+        "ttl": "1",
+        "ttl_ceil": 86400,
+        "ssl_id": "2245194",
+        "ssl_status": "V",
+        "ssl_expires_on": null,
+        "auto_ttl": 1,
+        "service_mode": "0",
+        "props": {
+          "proxiable": 0,
+          "cloud_on": 0,
+          "cf_open": 1,
+          "vanity_lock": 0,
+          "ssl": 1,
+          "expired_ssl": 0,
+          "expiring_ssl": 0,
+          "pending_ssl": 0
+        },
+        "mx": {
+          "auto": false
+        }
+      }, {
+        "rec_id": "364797379",
+        "rec_hash": "79e354b6d036b5eec0fe75974e0ffa98",
+        "zone_name": "example.com",
+        "name": "example.com",
+        "display_name": "example.com",
+        "type": "MX",
+        "prio": "30",
+        "content": "aspmx4.googlemail.com",
+        "display_content": "aspmx4.googlemail.com",
+        "ttl": "1",
+        "ttl_ceil": 86400,
+        "ssl_id": "2245194",
+        "ssl_status": "V",
+        "ssl_expires_on": null,
+        "auto_ttl": 1,
+        "service_mode": "0",
+        "props": {
+          "proxiable": 0,
+          "cloud_on": 0,
+          "cf_open": 1,
+          "vanity_lock": 0,
+          "ssl": 1,
+          "expired_ssl": 0,
+          "expiring_ssl": 0,
+          "pending_ssl": 0
+        },
+        "mx": {
+          "auto": false
+        }
+      }, {
+        "rec_id": "364797376",
+        "rec_hash": "ad08cc1813d4061763aecfe0d984bea3",
+        "zone_name": "example.com",
+        "name": "example.com",
+        "display_name": "example.com",
+        "type": "MX",
+        "prio": "30",
+        "content": "aspmx5.googlemail.com",
+        "display_content": "aspmx5.googlemail.com",
+        "ttl": "1",
+        "ttl_ceil": 86400,
+        "ssl_id": "2245194",
+        "ssl_status": "V",
+        "ssl_expires_on": null,
+        "auto_ttl": 1,
+        "service_mode": "0",
+        "props": {
+          "proxiable": 0,
+          "cloud_on": 0,
+          "cf_open": 1,
+          "vanity_lock": 0,
+          "ssl": 1,
+          "expired_ssl": 0,
+          "expiring_ssl": 0,
+          "pending_ssl": 0
+        },
+        "mx": {
+          "auto": false
+        }
+      }, {
+        "rec_id": "364797373",
+        "rec_hash": "b38ed0e1e250e12f2c1b3a4a163e5526",
+        "zone_name": "example.com",
+        "name": "example.com",
+        "display_name": "example.com",
+        "type": "MX",
+        "prio": "10",
+        "content": "aspmx.l.google.com",
+        "display_content": "aspmx.l.google.com",
+        "ttl": "1",
+        "ttl_ceil": 86400,
+        "ssl_id": "2245194",
+        "ssl_status": "V",
+        "ssl_expires_on": null,
+        "auto_ttl": 1,
+        "service_mode": "0",
+        "props": {
+          "proxiable": 0,
+          "cloud_on": 0,
+          "cf_open": 1,
+          "vanity_lock": 0,
+          "ssl": 1,
+          "expired_ssl": 0,
+          "expiring_ssl": 0,
+          "pending_ssl": 0
+        },
+        "mx": {
+          "auto": false
+        }
+      }, {
+        "rec_id": "364982359",
+        "rec_hash": "2f4037b298fb88b77a901725824287c0",
+        "zone_name": "example.com",
+        "name": "google._domainkey.example.com",
+        "display_name": "google._domainkey",
+        "type": "TXT",
+        "prio": null,
+        "content": "v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDNCHa8VeffMv+X\/fRkPgHC9MN2Eh5vQqMkWy4e\/YnFbWgF1JilL1Yn9nN54A5WV7lZpCTIvuOC2CrQrIcaBpfr+8SjYsjGO91dz8cwgqZkl7mAjKs7nz8U0PsstuI9i4V3LsHC4NVGOirAgnKA4HXVhxGRuyE94+tuNJ6XDLJoNQIDAQAB",
+        "display_content": "v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDNCHa8VeffMv+X\/fRkPgHC9MN2Eh5vQqMkWy4e\/YnFbWgF1JilL1Yn9nN54A5WV7lZpCTIvuOC2CrQrIcaBpfr+8SjYsjGO91dz8cwgqZkl7mAjKs7nz8U0PsstuI9i4V3LsHC4NVGOirAgnKA4HXVhxGRuyE94+tuNJ6XDLJoNQIDAQAB",
+        "ttl": "1",
+        "ttl_ceil": 86400,
+        "ssl_id": "2245194",
+        "ssl_status": "V",
+        "ssl_expires_on": null,
+        "auto_ttl": 1,
+        "service_mode": "0",
+        "props": {
+          "proxiable": 0,
+          "cloud_on": 0,
+          "cf_open": 1,
+          "vanity_lock": 0,
+          "ssl": 1,
+          "expired_ssl": 0,
+          "expiring_ssl": 0,
+          "pending_ssl": 0
+        }
+      }, {
+        "rec_id": "364797400",
+        "rec_hash": "75788bfdfe314c339e444bfc1c6cfd2e",
+        "zone_name": "example.com",
+        "name": "example.com",
+        "display_name": "example.com",
+        "type": "TXT",
+        "prio": null,
+        "content": "google-site-verification=Rgex8ShgIRWUlb9j0Ivw5uHllb0p9skEdJqkSMqvX_o",
+        "display_content": "google-site-verification=Rgex8ShgIRWUlb9j0Ivw5uHllb0p9skEdJqkSMqvX_o",
+        "ttl": "1",
+        "ttl_ceil": 86400,
+        "ssl_id": "2245194",
+        "ssl_status": "V",
+        "ssl_expires_on": null,
+        "auto_ttl": 1,
+        "service_mode": "0",
+        "props": {
+          "proxiable": 0,
+          "cloud_on": 0,
+          "cf_open": 1,
+          "vanity_lock": 0,
+          "ssl": 1,
+          "expired_ssl": 0,
+          "expiring_ssl": 0,
+          "pending_ssl": 0
+        }
+      }, {
+        "rec_id": "364797394",
+        "rec_hash": "c588426dbf098b57cfcee86815b482d0",
+        "zone_name": "example.com",
+        "name": "example.com",
+        "display_name": "example.com",
+        "type": "TXT",
+        "prio": null,
+        "content": "keybase-site-verification=L_shC4yrIjo-yM4qBDKmro9kOH8devqvHrlQtgFa2Us",
+        "display_content": "keybase-site-verification=L_shC4yrIjo-yM4qBDKmro9kOH8devqvHrlQtgFa2Us",
+        "ttl": "1",
+        "ttl_ceil": 86400,
+        "ssl_id": "2245194",
+        "ssl_status": "V",
+        "ssl_expires_on": null,
+        "auto_ttl": 1,
+        "service_mode": "0",
+        "props": {
+          "proxiable": 0,
+          "cloud_on": 0,
+          "cf_open": 1,
+          "vanity_lock": 0,
+          "ssl": 1,
+          "expired_ssl": 0,
+          "expiring_ssl": 0,
+          "pending_ssl": 0
+        }
+      }, {
+        "rec_id": "364797397",
+        "rec_hash": "e20556627e805701c5d0a383458201ae",
+        "zone_name": "example.com",
+        "name": "example.com",
+        "display_name": "example.com",
+        "type": "TXT",
+        "prio": null,
+        "content": "v=spf1 include:_spf.google.com ~all",
+        "display_content": "v=spf1 include:_spf.google.com ~all",
+        "ttl": "1",
+        "ttl_ceil": 86400,
+        "ssl_id": "2245194",
+        "ssl_status": "V",
+        "ssl_expires_on": null,
+        "auto_ttl": 1,
+        "service_mode": "0",
+        "props": {
+          "proxiable": 0,
+          "cloud_on": 0,
+          "cf_open": 1,
+          "vanity_lock": 0,
+          "ssl": 1,
+          "expired_ssl": 0,
+          "expiring_ssl": 0,
+          "pending_ssl": 0
+        }
+      }]
+    }
+  },
+  "result": "success",
+  "msg": null
+}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/b85a9b6e/libcloud/test/dns/fixtures/cloudflare/rec_new.json
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/fixtures/cloudflare/rec_new.json b/libcloud/test/dns/fixtures/cloudflare/rec_new.json
new file mode 100644
index 0000000..3ea4dfc
--- /dev/null
+++ b/libcloud/test/dns/fixtures/cloudflare/rec_new.json
@@ -0,0 +1,47 @@
+{
+  "request": {
+    "act": "rec_new",
+    "a": "rec_new",
+    "name": "test5",
+    "tkn": "maybeno",
+    "content": "127.0.0.3",
+    "ttl": "120",
+    "z": "example.com",
+    "type": "A",
+    "email": "example@example.com"
+  },
+  "response": {
+    "rec": {
+      "obj": {
+        "rec_id": "412561327",
+        "rec_hash": "ed23e38bca17007e026d2da517adf10a",
+        "zone_name": "example.com",
+        "name": "test5.example.com",
+        "display_name": "test5",
+        "type": "A",
+        "prio": null,
+        "content": "127.0.0.3",
+        "display_content": "127.0.0.3",
+        "ttl": "120",
+        "ttl_ceil": 86400,
+        "ssl_id": "2245194",
+        "ssl_status": "V",
+        "ssl_expires_on": null,
+        "auto_ttl": 0,
+        "service_mode": "0",
+        "props": {
+          "proxiable": 0,
+          "cloud_on": 0,
+          "cf_open": 1,
+          "vanity_lock": 0,
+          "ssl": 1,
+          "expired_ssl": 0,
+          "expiring_ssl": 0,
+          "pending_ssl": 0
+        }
+      }
+    }
+  },
+  "result": "success",
+  "msg": null
+}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/b85a9b6e/libcloud/test/dns/fixtures/cloudflare/stats.json
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/fixtures/cloudflare/stats.json b/libcloud/test/dns/fixtures/cloudflare/stats.json
new file mode 100644
index 0000000..b45884b
--- /dev/null
+++ b/libcloud/test/dns/fixtures/cloudflare/stats.json
@@ -0,0 +1,47 @@
+{
+  "response": {
+    "result": {
+      "timeZero": 1448773672000,
+      "timeEnd": 1449378472000,
+      "count": 1,
+      "has_more": false,
+      "objs": [{
+        "cachedServerTime": 1449378474000,
+        "cachedExpryTime": 1449379074000,
+        "trafficBreakdown": {
+          "pageviews": {
+            "regular": 1804,
+            "threat": 80,
+            "crawler": 438
+          },
+          "uniques": {
+            "regular": 1914,
+            "threat": 80,
+            "crawler": 438
+          }
+        },
+        "bandwidthServed": {
+          "cloudflare": 422053.22949219,
+          "user": 408767.30664062
+        },
+        "requestsServed": {
+          "cloudflare": 29333,
+          "user": 13367
+        },
+        "pro_zone": false,
+        "pageLoadTime": null,
+        "currentServerTime": 1449378474000,
+        "interval": 30,
+        "zoneCDate": 1373665252000,
+        "userSecuritySetting": "Medium",
+        "dev_mode": 0,
+        "ipv46": 3,
+        "ob": 1,
+        "cache_lvl": "agg",
+        "outboundLinks": "disabled"
+      }]
+    }
+  },
+  "result": "success",
+  "msg": null
+}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/b85a9b6e/libcloud/test/dns/fixtures/cloudflare/zone_check.json
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/fixtures/cloudflare/zone_check.json b/libcloud/test/dns/fixtures/cloudflare/zone_check.json
new file mode 100644
index 0000000..a6fdf34
--- /dev/null
+++ b/libcloud/test/dns/fixtures/cloudflare/zone_check.json
@@ -0,0 +1,9 @@
+{
+  "response": {
+    "zones": {
+      "example.com": 4025956
+    }
+  },
+  "result": "success",
+  "msg": null
+}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/b85a9b6e/libcloud/test/dns/fixtures/cloudflare/zone_load_multi.json
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/fixtures/cloudflare/zone_load_multi.json b/libcloud/test/dns/fixtures/cloudflare/zone_load_multi.json
new file mode 100644
index 0000000..8eb2ee5
--- /dev/null
+++ b/libcloud/test/dns/fixtures/cloudflare/zone_load_multi.json
@@ -0,0 +1,62 @@
+{
+  "request": {
+    "act": "zone_load_multi",
+    "tkn": "maybeno",
+    "a": "zone_load_multi",
+    "email": "example@example.com"
+  },
+  "response": {
+    "zones": {
+      "has_more": false,
+      "count": 1,
+      "objs": [{
+        "zone_id": "1234",
+        "user_id": "54321",
+        "zone_name": "example.com",
+        "display_name": "example.com",
+        "zone_status": "V",
+        "zone_mode": "1",
+        "host_id": null,
+        "zone_type": "F",
+        "host_pubname": null,
+        "host_website": null,
+        "vtxt": null,
+        "fqdns": ["kara.ns.cloudflare.com", "noah.ns.cloudflare.com"],
+        "step": "4",
+        "zone_status_class": "status-ac_api_json_html_zone_load_multitive",
+        "zone_status_desc": "CloudFlare powered, this website will be accelerated and protected
(<a class=\"modal-link-faq muted\" href=\"#\" onClick=\"cloudFlare.faq('en_US', ['CompleteActive']);return
false;\">info<\/a>)",
+        "ns_vanity_map": [],
+        "orig_registrar": "godaddy",
+        "orig_dnshost": null,
+        "orig_ns_names": "{dns1.stabletransit.com,dns2.stabletransit.com}",
+        "props": {
+          "dns_cname": 0,
+          "dns_partner": 0,
+          "dns_anon_partner": 0,
+          "plan": "FREE_ZONE",
+          "pro": 0,
+          "expired_pro": 0,
+          "pro_sub": 0,
+          "plan_sub": 0,
+          "ssl": 1,
+          "expired_ssl": 0,
+          "expired_rs_pro": 0,
+          "reseller_pro": 0,
+          "reseller_plans": [],
+          "force_interal": 0,
+          "ssl_needed": 0,
+          "alexa_rank": 1307220,
+          "has_vanity": 0
+        },
+        "confirm_code": {
+          "zone_delete": "maybeno",
+          "zone_deactivate": "maybeno",
+          "zone_dev_mode1": "maybeno"
+        },
+        "allow": ["analytics", "threat_control", "zone_delete", "cf_apps", "dns_editor",
"cf_settings", "page_rules", "zone_deactivate", "zone_dev_mode1"]
+      }]
+    }
+  },
+  "result": "success",
+  "msg": null
+}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/b85a9b6e/libcloud/test/dns/fixtures/cloudflare/zone_settings.json
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/fixtures/cloudflare/zone_settings.json b/libcloud/test/dns/fixtures/cloudflare/zone_settings.json
new file mode 100644
index 0000000..a6a4834
--- /dev/null
+++ b/libcloud/test/dns/fixtures/cloudflare/zone_settings.json
@@ -0,0 +1,44 @@
+{
+  "request": {
+    "act": "zone_settings",
+    "tkn": "maybeno",
+    "a": "zone_settings",
+    "z": "example.com",
+    "email": "example@example.com"
+  },
+  "response": {
+    "result": {
+      "objs": [{
+        "userSecuritySetting": "Medium",
+        "dev_mode": 0,
+        "ipv46": 3,
+        "ob": 1,
+        "cache_lvl": "agg",
+        "outboundLinks": "disabled",
+        "bic": "1",
+        "chl_ttl": "3600",
+        "comodo_vc": "a.b",
+        "dnssec": "",
+        "exp_ttl": "86400",
+        "fpurge_ts": "1448144070",
+        "minify": "7",
+        "preload": "0",
+        "sec_lvl": "med",
+        "secureheader_settings": "{\"*\":{\"strict_transport_security\":{\"enable\":1,\"max_age\":2592000},\"content_type_options\":\"nosniff\"}}",
+        "ssl": "1",
+        "outlink": "0",
+        "geoloc": "1",
+        "host_spf": "0",
+        "waf_profile": "off",
+        "email_filter": "1",
+        "sse": "1",
+        "cache_ttl": "14400",
+        "lazy": "0",
+        "async": "0",
+        "ddos": "Off"
+      }]
+    }
+  },
+  "result": "success",
+  "msg": null
+}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/b85a9b6e/libcloud/test/dns/test_cloudflare.py
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/test_cloudflare.py b/libcloud/test/dns/test_cloudflare.py
new file mode 100644
index 0000000..f1ebba5
--- /dev/null
+++ b/libcloud/test/dns/test_cloudflare.py
@@ -0,0 +1,214 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import sys
+
+from libcloud.test import unittest
+
+from libcloud.dns.drivers.cloudflare import CloudFlareDNSDriver
+from libcloud.dns.drivers.cloudflare import ZONE_EXTRA_ATTRIBUTES
+from libcloud.dns.drivers.cloudflare import RECORD_EXTRA_ATTRIBUTES
+from libcloud.dns.types import RecordType, ZoneDoesNotExistError
+from libcloud.utils.py3 import httplib
+from libcloud.test.secrets import DNS_PARAMS_CLOUDFLARE
+from libcloud.test.file_fixtures import DNSFileFixtures
+from libcloud.test import MockHttp
+
+
+class CloudFlareDNSDriverTestCase(unittest.TestCase):
+
+    def setUp(self):
+        CloudFlareDNSDriver.connectionCls.conn_classes = (
+            CloudFlareMockHttp, CloudFlareMockHttp)
+        CloudFlareMockHttp.type = None
+        CloudFlareMockHttp.use_param = 'a'
+        self.driver = CloudFlareDNSDriver(*DNS_PARAMS_CLOUDFLARE)
+
+    def test_list_record_types(self):
+        record_types = self.driver.list_record_types()
+        self.assertEqual(len(record_types), 9)
+        self.assertTrue(RecordType.A in record_types)
+
+    def test_list_zones(self):
+        zones = self.driver.list_zones()
+        self.assertEqual(len(zones), 1)
+
+        zone = zones[0]
+        self.assertEqual(zone.id, '1234')
+        self.assertEqual(zone.domain, 'example.com')
+        self.assertEqual(zone.type, 'master')
+
+        for attribute_name in ZONE_EXTRA_ATTRIBUTES:
+            self.assertTrue(attribute_name in zone.extra)
+
+    def test_list_records(self):
+        zone = self.driver.list_zones()[0]
+        records = self.driver.list_records(zone=zone)
+        self.assertEqual(len(records), 18)
+
+        record = records[0]
+        self.assertEqual(record.id, '364797364')
+        self.assertEqual(record.name, None)
+        self.assertEqual(record.type, 'A')
+        self.assertEqual(record.data, '192.30.252.153')
+
+        for attribute_name in RECORD_EXTRA_ATTRIBUTES:
+            self.assertTrue(attribute_name in record.extra)
+
+        record = records[4]
+        self.assertEqual(record.id, '364982413')
+        self.assertEqual(record.name, 'yesyes')
+        self.assertEqual(record.type, 'CNAME')
+        self.assertEqual(record.data, 'verify.bing.com')
+
+        for attribute_name in RECORD_EXTRA_ATTRIBUTES:
+            self.assertTrue(attribute_name in record.extra)
+
+    def test_create_record(self):
+        zone = self.driver.list_zones()[0]
+        record = self.driver.create_record(name='test5', zone=zone, type='A',
+                                           data='127.0.0.3')
+        self.assertEqual(record.id, '412561327')
+        self.assertEqual(record.name, 'test5')
+        self.assertEqual(record.type, 'A')
+        self.assertEqual(record.data, '127.0.0.3')
+
+    def test_update_records(self):
+        zone = self.driver.list_zones()[0]
+        record = zone.list_records()[0]
+        updated_record = self.driver.update_record(record=record,
+                                                   data='127.0.0.4')
+
+        self.assertEqual(updated_record.name, 'test6')
+        self.assertEqual(updated_record.type, 'A')
+        self.assertEqual(updated_record.data, '127.0.0.4')
+        self.assertEqual(updated_record.ttl, 120)
+
+    def test_delete_record(self):
+        zone = self.driver.list_zones()[0]
+        record = zone.list_records()[0]
+        result = self.driver.delete_record(record=record)
+        self.assertTrue(result)
+
+    def test_delete_zone(self):
+        zone = self.driver.list_zones()[0]
+        self.assertRaises(NotImplementedError, self.driver.delete_zone,
+                          zone=zone)
+
+    def test_ex_get_zone_stats(self):
+        zone = self.driver.list_zones()[0]
+        result = self.driver.ex_get_zone_stats(zone=zone)
+        self.assertTrue('trafficBreakdown' in result)
+        self.assertTrue('bandwidthServed' in result)
+        self.assertTrue('requestsServed' in result)
+        self.assertTrue('pro_zone' in result)
+        self.assertTrue('userSecuritySetting' in result)
+
+    def test_ex_zone_check(self):
+        zone = self.driver.list_zones()[0]
+        result = self.driver.ex_zone_check(zones=[zone])
+        self.assertEqual(result, {'example.com': 4025956})
+
+    def test_ex_get_ip_threat_score(self):
+        result = self.driver.ex_get_ip_threat_score(ip='127.0.0.1')
+        self.assertEqual(result, {'127.0.0.1': False})
+
+    def test_get_ex_zone_settings(self):
+        zone = self.driver.list_zones()[0]
+        result = self.driver.ex_get_zone_settings(zone=zone)
+        self.assertTrue('dnssec' in result)
+        self.assertTrue('ddos' in result)
+        self.assertTrue('email_filter' in result)
+        self.assertTrue('secureheader_settings' in result)
+
+
+class CloudFlareMockHttp(MockHttp):
+    fixtures = DNSFileFixtures('cloudflare')
+
+    def _api_json_html_zone_load_multi(
+            self, method, url, body, headers):
+        if method == 'GET':
+            body = self.fixtures.load('zone_load_multi.json')
+        else:
+            raise AssertionError('Unsupported method')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+    def _api_json_html_rec_load_all(
+            self, method, url, body, headers):
+        if method == 'GET':
+            body = self.fixtures.load('rec_load_all.json')
+        else:
+            raise AssertionError('Unsupported method')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+    def _api_json_html_rec_new(
+            self, method, url, body, headers):
+        if method == 'GET':
+            body = self.fixtures.load('rec_new.json')
+        else:
+            raise AssertionError('Unsupported method')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+    def _api_json_html_rec_delete(
+            self, method, url, body, headers):
+        if method == 'GET':
+            body = self.fixtures.load('rec_delete.json')
+        else:
+            raise AssertionError('Unsupported method')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+    def _api_json_html_rec_edit(
+            self, method, url, body, headers):
+        if method == 'GET':
+            body = self.fixtures.load('rec_edit.json')
+        else:
+            raise AssertionError('Unsupported method')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+    def _api_json_html_stats(
+            self, method, url, body, headers):
+        if method == 'GET':
+            body = self.fixtures.load('stats.json')
+        else:
+            raise AssertionError('Unsupported method')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+    def _api_json_html_zone_check(
+            self, method, url, body, headers):
+        if method == 'GET':
+            body = self.fixtures.load('zone_check.json')
+        else:
+            raise AssertionError('Unsupported method')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+    def _api_json_html_ip_lkup(
+            self, method, url, body, headers):
+        if method == 'GET':
+            body = self.fixtures.load('ip_lkup.json')
+        else:
+            raise AssertionError('Unsupported method')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+    def _api_json_html_zone_settings(
+            self, method, url, body, headers):
+        if method == 'GET':
+            body = self.fixtures.load('zone_settings.json')
+        else:
+            raise AssertionError('Unsupported method')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+
+if __name__ == '__main__':
+    sys.exit(unittest.main())

http://git-wip-us.apache.org/repos/asf/libcloud/blob/b85a9b6e/libcloud/test/secrets.py-dist
----------------------------------------------------------------------
diff --git a/libcloud/test/secrets.py-dist b/libcloud/test/secrets.py-dist
index 43531c9..99b2973 100644
--- a/libcloud/test/secrets.py-dist
+++ b/libcloud/test/secrets.py-dist
@@ -78,3 +78,4 @@ DNS_PARAMS_POINTDNS = ('user', 'key')
 DNS_PARAMS_LIQUIDWEB = ('user', 'key')
 DNS_PARAMS_ZONOMI = ('key')
 DNS_PARAMS_DURABLEDNS = ('api_user', 'api_key')
+DNS_PARAMS_CLOUDFLARE = ('user@example.com', 'key')


Mime
View raw message