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 2011/09/23 00:54:57 UTC
svn commit: r1174439 - in /libcloud/trunk/test: ./ dns/ dns/fixtures/
dns/fixtures/linode/
Author: tomaz
Date: Thu Sep 22 22:54:57 2011
New Revision: 1174439
URL: http://svn.apache.org/viewvc?rev=1174439&view=rev
Log:
Add tests and fixtures for Linode DNS driver. Still missing a few tests.
Added:
libcloud/trunk/test/dns/
libcloud/trunk/test/dns/__init__.py
libcloud/trunk/test/dns/fixtures/
libcloud/trunk/test/dns/fixtures/linode/
libcloud/trunk/test/dns/fixtures/linode/create_domain.json
libcloud/trunk/test/dns/fixtures/linode/create_domain_validation_error.json
libcloud/trunk/test/dns/fixtures/linode/domain_list.json
libcloud/trunk/test/dns/fixtures/linode/get_record.json
libcloud/trunk/test/dns/fixtures/linode/get_record_does_not_exist.json
libcloud/trunk/test/dns/fixtures/linode/get_zone.json
libcloud/trunk/test/dns/fixtures/linode/get_zone_does_not_exist.json
libcloud/trunk/test/dns/fixtures/linode/resource_list.json
libcloud/trunk/test/dns/test_linode.py
Modified:
libcloud/trunk/test/file_fixtures.py
Added: libcloud/trunk/test/dns/__init__.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/test/dns/__init__.py?rev=1174439&view=auto
==============================================================================
(empty)
Added: libcloud/trunk/test/dns/fixtures/linode/create_domain.json
URL: http://svn.apache.org/viewvc/libcloud/trunk/test/dns/fixtures/linode/create_domain.json?rev=1174439&view=auto
==============================================================================
--- libcloud/trunk/test/dns/fixtures/linode/create_domain.json (added)
+++ libcloud/trunk/test/dns/fixtures/linode/create_domain.json Thu Sep 22 22:54:57 2011
@@ -0,0 +1,7 @@
+{
+ "ERRORARRAY":[],
+ "ACTION":"domain.create",
+ "DATA":{
+ "DomainID":5123
+ }
+}
Added: libcloud/trunk/test/dns/fixtures/linode/create_domain_validation_error.json
URL: http://svn.apache.org/viewvc/libcloud/trunk/test/dns/fixtures/linode/create_domain_validation_error.json?rev=1174439&view=auto
==============================================================================
--- libcloud/trunk/test/dns/fixtures/linode/create_domain_validation_error.json (added)
+++ libcloud/trunk/test/dns/fixtures/linode/create_domain_validation_error.json Thu Sep 22 22:54:57 2011
@@ -0,0 +1 @@
+{"ERRORARRAY":[{"ERRORCODE":2,"ERRORMESSAGE":"The domain 'test.foo3455.net' already exists in our database. Please open a ticket if you think this is in error."},{"ERRORCODE":2,"ERRORMESSAGE":"Invalid domain type."}],"DATA":{},"ACTION":"domain.create"}
Added: libcloud/trunk/test/dns/fixtures/linode/domain_list.json
URL: http://svn.apache.org/viewvc/libcloud/trunk/test/dns/fixtures/linode/domain_list.json?rev=1174439&view=auto
==============================================================================
--- libcloud/trunk/test/dns/fixtures/linode/domain_list.json (added)
+++ libcloud/trunk/test/dns/fixtures/linode/domain_list.json Thu Sep 22 22:54:57 2011
@@ -0,0 +1,32 @@
+{
+ "ERRORARRAY":[],
+ "ACTION":"domain.list",
+ "DATA":[
+ {
+ "DOMAINID":5093,
+ "DESCRIPTION":"",
+ "TYPE":"master",
+ "STATUS":1,
+ "SOA_EMAIL":"dns@example.com",
+ "DOMAIN":"linode.com",
+ "RETRY_SEC":0,
+ "MASTER_IPS":"",
+ "EXPIRE_SEC":0,
+ "REFRESH_SEC":0,
+ "TTL_SEC":0
+ },
+ {
+ "DOMAINID":5125,
+ "DESCRIPTION":"",
+ "TYPE":"slave",
+ "STATUS":1,
+ "SOA_EMAIL":"",
+ "DOMAIN":"nodefs.com",
+ "RETRY_SEC":0,
+ "MASTER_IPS":"1.3.5.7;2.4.6.8;",
+ "EXPIRE_SEC":0,
+ "REFRESH_SEC":0,
+ "TTL_SEC":0
+ }
+ ]
+}
Added: libcloud/trunk/test/dns/fixtures/linode/get_record.json
URL: http://svn.apache.org/viewvc/libcloud/trunk/test/dns/fixtures/linode/get_record.json?rev=1174439&view=auto
==============================================================================
--- libcloud/trunk/test/dns/fixtures/linode/get_record.json (added)
+++ libcloud/trunk/test/dns/fixtures/linode/get_record.json Thu Sep 22 22:54:57 2011
@@ -0,0 +1,18 @@
+{
+ "ERRORARRAY":[],
+ "ACTION":"domain.resource.list",
+ "DATA":[
+ {
+ "PROTOCOL":"",
+ "TTL_SEC":0,
+ "PRIORITY":0,
+ "TYPE":"A",
+ "TARGET":"75.127.96.245",
+ "WEIGHT":0,
+ "RESOURCEID":28536,
+ "PORT":0,
+ "DOMAINID":5093,
+ "NAME":"www"
+ }
+ ]
+}
Added: libcloud/trunk/test/dns/fixtures/linode/get_record_does_not_exist.json
URL: http://svn.apache.org/viewvc/libcloud/trunk/test/dns/fixtures/linode/get_record_does_not_exist.json?rev=1174439&view=auto
==============================================================================
--- libcloud/trunk/test/dns/fixtures/linode/get_record_does_not_exist.json (added)
+++ libcloud/trunk/test/dns/fixtures/linode/get_record_does_not_exist.json Thu Sep 22 22:54:57 2011
@@ -0,0 +1,5 @@
+{
+ "ERRORARRAY":[],
+ "ACTION":"domain.resource.list",
+ "DATA":[]
+}
Added: libcloud/trunk/test/dns/fixtures/linode/get_zone.json
URL: http://svn.apache.org/viewvc/libcloud/trunk/test/dns/fixtures/linode/get_zone.json?rev=1174439&view=auto
==============================================================================
--- libcloud/trunk/test/dns/fixtures/linode/get_zone.json (added)
+++ libcloud/trunk/test/dns/fixtures/linode/get_zone.json Thu Sep 22 22:54:57 2011
@@ -0,0 +1,19 @@
+{
+ "ERRORARRAY":[],
+ "ACTION":"domain.list",
+ "DATA":[
+ {
+ "DOMAINID":5093,
+ "DESCRIPTION":"",
+ "TYPE":"master",
+ "STATUS":1,
+ "SOA_EMAIL":"dns@example.com",
+ "DOMAIN":"linode.com",
+ "RETRY_SEC":0,
+ "MASTER_IPS":"",
+ "EXPIRE_SEC":0,
+ "REFRESH_SEC":0,
+ "TTL_SEC":0
+ }
+ ]
+}
Added: libcloud/trunk/test/dns/fixtures/linode/get_zone_does_not_exist.json
URL: http://svn.apache.org/viewvc/libcloud/trunk/test/dns/fixtures/linode/get_zone_does_not_exist.json?rev=1174439&view=auto
==============================================================================
--- libcloud/trunk/test/dns/fixtures/linode/get_zone_does_not_exist.json (added)
+++ libcloud/trunk/test/dns/fixtures/linode/get_zone_does_not_exist.json Thu Sep 22 22:54:57 2011
@@ -0,0 +1,5 @@
+{
+ "ERRORARRAY":[],
+ "ACTION":"domain.list",
+ "DATA":[]
+}
Added: libcloud/trunk/test/dns/fixtures/linode/resource_list.json
URL: http://svn.apache.org/viewvc/libcloud/trunk/test/dns/fixtures/linode/resource_list.json?rev=1174439&view=auto
==============================================================================
--- libcloud/trunk/test/dns/fixtures/linode/resource_list.json (added)
+++ libcloud/trunk/test/dns/fixtures/linode/resource_list.json Thu Sep 22 22:54:57 2011
@@ -0,0 +1,30 @@
+{
+ "ERRORARRAY":[],
+ "ACTION":"domain.resource.list",
+ "DATA":[
+ {
+ "PROTOCOL":"",
+ "TTL_SEC":0,
+ "PRIORITY":0,
+ "TYPE":"A",
+ "TARGET":"75.127.96.245",
+ "WEIGHT":0,
+ "RESOURCEID":28536,
+ "PORT":0,
+ "DOMAINID":5093,
+ "NAME":"www"
+ },
+ {
+ "PROTOCOL":"",
+ "TTL_SEC":0,
+ "PRIORITY":0,
+ "TYPE":"A",
+ "TARGET":"75.127.96.245",
+ "WEIGHT":0,
+ "RESOURCEID":28537,
+ "PORT":0,
+ "DOMAINID":5093,
+ "NAME":"mail"
+ }
+ ]
+}
Added: libcloud/trunk/test/dns/test_linode.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/test/dns/test_linode.py?rev=1174439&view=auto
==============================================================================
--- libcloud/trunk/test/dns/test_linode.py (added)
+++ libcloud/trunk/test/dns/test_linode.py Thu Sep 22 22:54:57 2011
@@ -0,0 +1,210 @@
+# 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
+
+import sys
+import httplib
+import unittest
+
+from libcloud.common.linode import LinodeException
+from libcloud.dns.types import RecordType, ZoneDoesNotExistError
+from libcloud.dns.drivers.linode import LinodeDNSDriver
+
+from test import MockHttp # pylint: disable-msg=E0611
+from test.file_fixtures import DNSFileFixtures # pylint: disable-msg=E0611
+from test.secrets import DNS_PARAMS_LINODE
+
+DOES_NOT_EXIST_ERROR = '{"ERRORARRAY":[{"ERRORCODE":5,"ERRORMESSAGE":"Object not found"}],"DATA":{},"ACTION":"domain.resource.list"}'
+
+class LinodeTests(unittest.TestCase):
+ def setUp(self):
+ LinodeDNSDriver.connectionCls.conn_classes = (
+ None, LinodeMockHttp)
+ LinodeMockHttp.use_param = 'api_action'
+ LinodeMockHttp.type = None
+ self.driver = LinodeDNSDriver(*DNS_PARAMS_LINODE)
+
+ def assertHasKeys(self, dictionary, keys):
+ for key in keys:
+ self.assertTrue(key in dictionary, 'key "%s" not in dictionary' %
+ (key))
+
+ def test_list_zones_success(self):
+ zones = self.driver.list_zones()
+ self.assertEqual(len(zones), 2)
+
+ zone = zones[0]
+ self.assertEqual(zone.id, '5093')
+ self.assertEqual(zone.type, 'master')
+ self.assertEqual(zone.domain, 'linode.com')
+ self.assertEqual(zone.ttl, None)
+ self.assertHasKeys(zone.extra, ['description', 'soa_email', 'status'])
+
+ def test_list_records_success(self):
+ zone = self.driver.list_zones()[0]
+ records = self.driver.list_records(zone=zone)
+ self.assertEqual(len(records), 2)
+
+ record = records[0]
+ self.assertEqual(record.id, '28536')
+ self.assertEqual(record.name, 'www')
+ self.assertEqual(record.type, RecordType.A)
+ self.assertEqual(record.data, '75.127.96.245')
+ self.assertHasKeys(record.extra, ['protocol', 'ttl_sec', 'port', 'weight'])
+
+ def test_list_records_zone_does_not_exist(self):
+ zone = self.driver.list_zones()[0]
+
+ LinodeMockHttp.type = 'ZONE_DOES_NOT_EXIST'
+ try:
+ records = self.driver.list_records(zone=zone)
+ except ZoneDoesNotExistError, e:
+ self.assertEqual(e.zone_id, zone.id)
+ else:
+ self.fail('Exception was not thrown')
+
+ def test_get_zone_success(self):
+ LinodeMockHttp.type = 'GET_ZONE'
+
+ zone = self.driver.get_zone(zone_id='5093')
+ self.assertEqual(zone.id, '5093')
+ self.assertEqual(zone.type, 'master')
+ self.assertEqual(zone.domain, 'linode.com')
+ self.assertEqual(zone.ttl, None)
+ self.assertHasKeys(zone.extra, ['description', 'soa_email', 'status'])
+
+ def test_get_zone_does_not_exist(self):
+ LinodeMockHttp.type = 'GET_ZONE_DOES_NOT_EXIST'
+
+ try:
+ zone = self.driver.get_zone(zone_id='4444')
+ except ZoneDoesNotExistError, e:
+ self.assertEqual(e.zone_id, '4444')
+ else:
+ self.fail('Exception was not thrown')
+
+ def test_get_record_success(self):
+ LinodeMockHttp.type = 'GET_RECORD'
+ record = self.driver.get_record(zone_id='1234', record_id='28536')
+ self.assertEqual(record.id, '28536')
+ self.assertEqual(record.name, 'www')
+ self.assertEqual(record.type, RecordType.A)
+ self.assertEqual(record.data, '75.127.96.245')
+ self.assertHasKeys(record.extra, ['protocol', 'ttl_sec', 'port', 'weight'])
+
+ def test_get_record_zone_does_not_exist(self):
+ LinodeMockHttp.type = 'GET_RECORD_ZONE_DOES_NOT_EXIST'
+
+ try:
+ record = self.driver.get_record(zone_id='444', record_id='28536')
+ except ZoneDoesNotExistError:
+ self.assertEqual(e.zone_id, '4444')
+ else:
+ self.fail('Exception was not thrown')
+
+ def test_get_record_record_does_not_exist(self):
+ LinodeMockHttp.type = 'GET_RECORD_RECORD_DOES_NOT_EXIST'
+
+ try:
+ record = self.driver.get_record(zone_id='444', record_id='28536')
+ except ZoneDoesNotExistError:
+ self.assertEqual(e.zone_id, '4444')
+ else:
+ self.fail('Exception was not thrown')
+
+ def test_create_zone_success(self):
+ zone = self.driver.create_zone(domain='foo.bar.com', type='master',
+ ttl=None, extra=None)
+ self.assertEqual(zone.id, '5123')
+ self.assertEqual(zone.domain, 'foo.bar.com')
+
+ def test_create_zone_validaton_error(self):
+ LinodeMockHttp.type = 'VALIDATION_ERROR'
+
+ try:
+ zone = self.driver.create_zone(domain='foo.bar.com', type='master',
+ ttl=None, extra=None)
+ except LinodeException:
+ pass
+ else:
+ self.fail('Exception was not thrown')
+
+ def test_create_record_success(self):
+ pass
+
+ def test_update_record_success(self):
+ pass
+
+ def test_delete_record_success(self):
+ pass
+
+ def test_delete_record_does_not_exist(self):
+ pass
+
+ def test_delete_zone_success(self):
+ pass
+
+ def test_delete_zone_does_not_exist(self):
+ pass
+
+
+class LinodeMockHttp(MockHttp):
+ fixtures = DNSFileFixtures('linode')
+
+ def _domain_list(self, method, url, body, headers):
+ body = self.fixtures.load('domain_list.json')
+ return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+ def _domain_resource_list(self, method, url, body, headers):
+ body = self.fixtures.load('resource_list.json')
+ return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+ def _ZONE_DOES_NOT_EXIST_domain_resource_list(self, method, url, body, headers):
+ body = DOES_NOT_EXIST_ERROR
+ return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+ def _GET_ZONE_domain_list(self, method, url, body, headers):
+ body = self.fixtures.load('get_zone.json')
+ return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+ def _GET_ZONE_DOES_NOT_EXIST_domain_list(self, method, url, body, headers):
+ body = self.fixtures.load('get_zone_does_not_exist.json')
+ return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+ def _GET_RECORD_domain_list(self, method, url, body, headers):
+ body = self.fixtures.load('get_zone.json')
+ return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+ def _GET_RECORD_domain_resource_list(self, method, url, body, headers):
+ body = self.fixtures.load('get_record.json')
+ return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+ def _GET_RECORD_ZONE_DOES_NOT_EXIST_domain_list(self, method, url, body, headers):
+ body = self.fixtures.load('get_zone_does_not_exist.json')
+ return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+ def _GET_RECORD_RECORD_DOES_NOT_EXIST_domain_list(self, method, url, body, headers):
+ body = self.fixtures.load('get_record_does_not_exist.json')
+ return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+ def _domain_create(self, method, url, body, headers):
+ body = self.fixtures.load('create_domain.json')
+ return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+ def _VALIDATION_ERROR_domain_create(self, method, url, body, headers):
+ body = self.fixtures.load('create_domain_validation_error.json')
+ return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+
+if __name__ == '__main__':
+ sys.exit(unittest.main())
Modified: libcloud/trunk/test/file_fixtures.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/test/file_fixtures.py?rev=1174439&r1=1174438&r2=1174439&view=diff
==============================================================================
--- libcloud/trunk/test/file_fixtures.py (original)
+++ libcloud/trunk/test/file_fixtures.py Thu Sep 22 22:54:57 2011
@@ -22,6 +22,7 @@ FIXTURES_ROOT = {
'compute': 'compute/fixtures',
'storage': 'storage/fixtures',
'loadbalancer': 'loadbalancer/fixtures',
+ 'dns': 'dns/fixtures',
'openstack': 'openstack/fixtures',
}
@@ -55,6 +56,11 @@ class LoadBalancerFileFixtures(FileFixtu
super(LoadBalancerFileFixtures, self).__init__(fixtures_type='loadbalancer',
sub_dir=sub_dir)
+class DNSFileFixtures(FileFixtures):
+ def __init__(self, sub_dir=''):
+ super(DNSFileFixtures, self).__init__(fixtures_type='dns',
+ sub_dir=sub_dir)
+
class OpenStackFixtures(FileFixtures):
def __init__(self, sub_dir=''):
super(OpenStackFixtures, self).__init__(fixtures_type='openstack',