libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r1454658 - in /libcloud/trunk/libcloud: compute/drivers/ test/ test/compute/ test/compute/fixtures/digitalocean/
Date Sat, 09 Mar 2013 05:08:37 GMT
Author: tomaz
Date: Sat Mar  9 05:08:36 2013
New Revision: 1454658

URL: http://svn.apache.org/r1454658
Log:
Fix some Digital Ocean stuff and add preliminary tests.

Added:
    libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/
    libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/create_node.json
    libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/destroy_node.json
    libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/error.txt
    libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/ex_create_ssh_key.json
    libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/ex_destroy_ssh_key.json
    libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/ex_list_ssh_keys.json
    libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/list_images.json
    libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/list_locations.json
    libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/list_nodes.json
    libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/list_nodes_empty.json
    libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/list_sizes.json
    libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/reboot_node.json
    libcloud/trunk/libcloud/test/compute/test_digitalocean.py
Modified:
    libcloud/trunk/libcloud/compute/drivers/digitalocean.py
    libcloud/trunk/libcloud/test/secrets.py-dist

Modified: libcloud/trunk/libcloud/compute/drivers/digitalocean.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/compute/drivers/digitalocean.py?rev=1454658&r1=1454657&r2=1454658&view=diff
==============================================================================
--- libcloud/trunk/libcloud/compute/drivers/digitalocean.py (original)
+++ libcloud/trunk/libcloud/compute/drivers/digitalocean.py Sat Mar  9 05:08:36 2013
@@ -19,13 +19,16 @@ Digital Ocean Driver
 from libcloud.utils.py3 import httplib
 
 from libcloud.common.base import ConnectionUserAndKey, JsonResponse
-from libcloud.compute.types import Provider, NodeState
+from libcloud.compute.types import Provider, NodeState, InvalidCredsError
 from libcloud.compute.base import NodeDriver
 from libcloud.compute.base import Node, NodeImage, NodeSize, NodeLocation
 
 
 class DigitalOceanResponse(JsonResponse):
-    pass
+    def parse_error(self):
+        if self.status == httplib.FOUND and '/api/error' in self.body:
+            # Hacky, but DigitalOcean error responses are awful
+            raise InvalidCredsError(self.body)
 
 
 class SSHKey(object):
@@ -126,12 +129,12 @@ class DigitalOceanNodeDriver(NodeDriver)
 
     def _to_node(self, data):
         extra_keys = ['backups_active', 'region_id']
-        if 'staus' in data:
+        if 'status' in data:
             state = self.NODE_STATE_MAP.get(data['status'], NodeState.UNKNOWN)
         else:
             state = NodeState.UNKNOWN
 
-        if 'ip_address' in data:
+        if 'ip_address' in data and data['ip_address'] is not None:
             public_ips = [data['ip_address']]
         else:
             public_ips = []

Added: libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/create_node.json
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/create_node.json?rev=1454658&view=auto
==============================================================================
--- libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/create_node.json (added)
+++ libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/create_node.json Sat Mar  9
05:08:36 2013
@@ -0,0 +1 @@
+{"status":"OK","droplet":{"id":119461,"name":"test-2","image_id":1601,"size_id":66,"event_id":919341}}

Added: libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/destroy_node.json
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/destroy_node.json?rev=1454658&view=auto
==============================================================================
--- libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/destroy_node.json (added)
+++ libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/destroy_node.json Sat Mar 
9 05:08:36 2013
@@ -0,0 +1 @@
+{"status":"OK","event_id":918910}

Added: libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/error.txt
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/error.txt?rev=1454658&view=auto
==============================================================================
--- libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/error.txt (added)
+++ libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/error.txt Sat Mar  9 05:08:36
2013
@@ -0,0 +1 @@
+<html><body>You are being <a href="https://www.digitalocean.com/api/error">redirected</a>.</body></html>

Added: libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/ex_create_ssh_key.json
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/ex_create_ssh_key.json?rev=1454658&view=auto
==============================================================================
--- libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/ex_create_ssh_key.json (added)
+++ libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/ex_create_ssh_key.json Sat
Mar  9 05:08:36 2013
@@ -0,0 +1 @@
+{"status":"OK","ssh_key":{"id":7717,"name":"test1","ssh_pub_key":"aaq"}}

Added: libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/ex_destroy_ssh_key.json
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/ex_destroy_ssh_key.json?rev=1454658&view=auto
==============================================================================
--- libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/ex_destroy_ssh_key.json (added)
+++ libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/ex_destroy_ssh_key.json Sat
Mar  9 05:08:36 2013
@@ -0,0 +1 @@
+{"status":"OK"}

Added: libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/ex_list_ssh_keys.json
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/ex_list_ssh_keys.json?rev=1454658&view=auto
==============================================================================
--- libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/ex_list_ssh_keys.json (added)
+++ libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/ex_list_ssh_keys.json Sat Mar
 9 05:08:36 2013
@@ -0,0 +1 @@
+{"status":"OK","ssh_keys":[{"id":7717,"name":"test1"}]}

Added: libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/list_images.json
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/list_images.json?rev=1454658&view=auto
==============================================================================
--- libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/list_images.json (added)
+++ libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/list_images.json Sat Mar  9
05:08:36 2013
@@ -0,0 +1,145 @@
+{
+    "status": "OK",
+    "images": [
+        {
+            "id": 1601,
+            "name": "CentOS 5.8 x64",
+            "distribution": "CentOS"
+        },
+        {
+            "id": 1602,
+            "name": "CentOS 5.8 x32",
+            "distribution": "CentOS"
+        },
+        {
+            "id": 1605,
+            "name": "CentOS 6.0 x32",
+            "distribution": "CentOS"
+        },
+        {
+            "id": 1606,
+            "name": "Fedora 15 x64",
+            "distribution": "Fedora"
+        },
+        {
+            "id": 1609,
+            "name": "Ubuntu 11.10 x32 Server",
+            "distribution": "Ubuntu"
+        },
+        {
+            "id": 1611,
+            "name": "CentOS 6.2 x64",
+            "distribution": "CentOS"
+        },
+        {
+            "id": 1615,
+            "name": "Fedora 16 x64 Server",
+            "distribution": "Fedora"
+        },
+        {
+            "id": 1618,
+            "name": "Fedora 16 x64 Desktop",
+            "distribution": "Fedora"
+        },
+        {
+            "id": 2676,
+            "name": "Ubuntu 12.04 x64 Server",
+            "distribution": "Ubuntu"
+        },
+        {
+            "id": 12573,
+            "name": "Debian 6.0 x64",
+            "distribution": "Debian"
+        },
+        {
+            "id": 12574,
+            "name": "CentOS 6.3 x64",
+            "distribution": "CentOS"
+        },
+        {
+            "id": 12575,
+            "name": "Debian 6.0 x32",
+            "distribution": "Debian"
+        },
+        {
+            "id": 12578,
+            "name": "CentOS 6.3 x32",
+            "distribution": "CentOS"
+        },
+        {
+            "id": 14097,
+            "name": "Ubuntu 10.04 x64 Server",
+            "distribution": "Ubuntu"
+        },
+        {
+            "id": 14098,
+            "name": "Ubuntu 10.04 x32 Server",
+            "distribution": "Ubuntu"
+        },
+        {
+            "id": 14218,
+            "name": "Ubuntu 12.04 x64 Desktop",
+            "distribution": "Ubuntu"
+        },
+        {
+            "id": 25306,
+            "name": "Ubuntu 12.10 x32 Server",
+            "distribution": "Ubuntu"
+        },
+        {
+            "id": 25485,
+            "name": "Ubuntu 12.10 x32 Desktop",
+            "distribution": "Ubuntu"
+        },
+        {
+            "id": 25489,
+            "name": "Ubuntu 12.10 x64 Server",
+            "distribution": "Ubuntu"
+        },
+        {
+            "id": 25493,
+            "name": "Ubuntu 12.10 x64 Desktop",
+            "distribution": "Ubuntu"
+        },
+        {
+            "id": 32387,
+            "name": "Fedora 17 x32 Server",
+            "distribution": "Fedora"
+        },
+        {
+            "id": 32399,
+            "name": "Fedora 17 x32 Desktop",
+            "distribution": "Fedora"
+        },
+        {
+            "id": 32419,
+            "name": "Fedora 17 x64 Desktop",
+            "distribution": "Fedora"
+        },
+        {
+            "id": 32428,
+            "name": "Fedora 17 x64 Server",
+            "distribution": "Fedora"
+        },
+        {
+            "id": 42735,
+            "name": "Ubuntu 12.04 x32 Server",
+            "distribution": "Ubuntu"
+        },
+        {
+            "id": 43458,
+            "name": "Ubuntu 11.04x64 Server",
+            "distribution": "Ubuntu"
+        },
+        {
+            "id": 43462,
+            "name": "Ubuntu 11.04x32 Desktop",
+            "distribution": "Ubuntu"
+        },
+        {
+            "id": 46964,
+            "name": "LAMP on Ubuntu 12.04",
+            "distribution": "Ubuntu"
+        }
+    ]
+}

Added: libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/list_locations.json
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/list_locations.json?rev=1454658&view=auto
==============================================================================
--- libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/list_locations.json (added)
+++ libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/list_locations.json Sat Mar
 9 05:08:36 2013
@@ -0,0 +1 @@
+{"status":"OK","regions":[{"id":1,"name":"New York 1"},{"id":2,"name":"Amsterdam 1"}]}

Added: libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/list_nodes.json
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/list_nodes.json?rev=1454658&view=auto
==============================================================================
--- libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/list_nodes.json (added)
+++ libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/list_nodes.json Sat Mar  9
05:08:36 2013
@@ -0,0 +1 @@
+{"status":"OK","droplets":[{"id":119461,"name":"test-2","image_id":1601,"size_id":66,"region_id":1,"backups_active":null,"ip_address":null,"status":"new"}]}

Added: libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/list_nodes_empty.json
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/list_nodes_empty.json?rev=1454658&view=auto
==============================================================================
--- libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/list_nodes_empty.json (added)
+++ libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/list_nodes_empty.json Sat Mar
 9 05:08:36 2013
@@ -0,0 +1 @@
+{"status":"OK","droplets":[]}

Added: libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/list_sizes.json
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/list_sizes.json?rev=1454658&view=auto
==============================================================================
--- libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/list_sizes.json (added)
+++ libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/list_sizes.json Sat Mar  9
05:08:36 2013
@@ -0,0 +1 @@
+{"status":"OK","sizes":[{"id":66,"name":"512MB"},{"id":63,"name":"1GB"},{"id":62,"name":"2GB"},{"id":64,"name":"4GB"},{"id":65,"name":"8GB"},{"id":61,"name":"16GB"},{"id":60,"name":"32GB"},{"id":70,"name":"48GB"},{"id":69,"name":"64GB"},{"id":68,"name":"96GB"}]}

Added: libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/reboot_node.json
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/reboot_node.json?rev=1454658&view=auto
==============================================================================
--- libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/reboot_node.json (added)
+++ libcloud/trunk/libcloud/test/compute/fixtures/digitalocean/reboot_node.json Sat Mar  9
05:08:36 2013
@@ -0,0 +1 @@
+{"status":"OK","event_id":918910}

Added: libcloud/trunk/libcloud/test/compute/test_digitalocean.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/test/compute/test_digitalocean.py?rev=1454658&view=auto
==============================================================================
--- libcloud/trunk/libcloud/test/compute/test_digitalocean.py (added)
+++ libcloud/trunk/libcloud/test/compute/test_digitalocean.py Sat Mar  9 05:08:36 2013
@@ -0,0 +1,153 @@
+# 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
+import unittest
+import base64
+
+try:
+    import simplejson as json
+except ImportError:
+    import json
+
+from libcloud.utils.py3 import httplib
+from libcloud.utils.py3 import b
+from libcloud.utils.py3 import u
+
+from libcloud.common.types import InvalidCredsError
+from libcloud.compute.drivers.digitalocean import DigitalOceanNodeDriver
+from libcloud.compute.types import NodeState
+
+from libcloud.test import MockHttp
+from libcloud.test.compute import TestCaseMixin
+from libcloud.test.file_fixtures import ComputeFileFixtures
+from libcloud.test.secrets import DIGITAL_OCEAN_PARAMS
+
+
+#class DigitalOceanTests(unittest.TestCase, TestCaseMixin):
+class DigitalOceanTests(unittest.TestCase):
+    def setUp(self):
+        DigitalOceanNodeDriver.connectionCls.conn_classes = \
+            (None, DigitalOceanMockHttp)
+        DigitalOceanMockHttp.type = None
+        self.driver = DigitalOceanNodeDriver(*DIGITAL_OCEAN_PARAMS)
+
+    def test_authentication(self):
+        DigitalOceanMockHttp.type = 'UNAUTHORIZED_CLIENT'
+        self.assertRaises(InvalidCredsError, self.driver.list_nodes)
+
+    def test_list_images_success(self):
+        images = self.driver.list_images()
+        self.assertTrue(len(images) >= 1)
+
+        image = images[0]
+        self.assertTrue(image.id is not None)
+        self.assertTrue(image.name is not None)
+
+    def test_list_sizes_success(self):
+        sizes = self.driver.list_sizes()
+        self.assertTrue(len(sizes) >= 1)
+
+        size = sizes[0]
+        self.assertTrue(size.id is not None)
+        self.assertEqual(size.name, '512MB')
+        self.assertEqual(size.ram, 512)
+
+        size = sizes[4]
+        self.assertTrue(size.id is not None)
+        self.assertEqual(size.name, '8GB')
+        self.assertEqual(size.ram, 8 * 1024)
+
+    def test_list_locations_success(self):
+        locations = self.driver.list_locations()
+        self.assertTrue(len(locations) >= 1)
+
+        location = locations[0]
+        self.assertEqual(location.id, '1')
+        self.assertEqual(location.name, 'New York 1')
+
+    def test_list_nodes_success(self):
+        nodes = self.driver.list_nodes()
+        self.assertEqual(len(nodes), 1)
+        self.assertEqual(nodes[0].name, 'test-2')
+        self.assertEqual(nodes[0].public_ips, [])
+
+    def test_reboot_node_success(self):
+        node = self.driver.list_nodes()[0]
+        result = self.driver.reboot_node(node)
+        self.assertTrue(result)
+
+    def test_destroy_node_success(self):
+        node = self.driver.list_nodes()[0]
+        result = self.driver.destroy_node(node)
+        self.assertTrue(result)
+
+    def test_ex_list_ssh_keys(self):
+        keys = self.driver.ex_list_ssh_keys()
+        self.assertEqual(len(keys), 1)
+
+        self.assertEqual(keys[0].id, 7717)
+        self.assertEqual(keys[0].name, 'test1')
+        self.assertEqual(keys[0].pub_key, None)
+
+    def test_ex_destroy_ssh_key(self):
+        key = self.driver.ex_list_ssh_keys()[0]
+        result = self.driver.ex_destroy_ssh_key(key.id)
+        self.assertTrue(result)
+
+
+class DigitalOceanMockHttp(MockHttp):
+    fixtures = ComputeFileFixtures('digitalocean')
+
+    def _regions(self, method, url, body, headers):
+        body = self.fixtures.load('list_locations.json')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+    def _images(self, method, url, body, headers):
+        body = self.fixtures.load('list_images.json')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+    def _sizes(self, method, url, body, headers):
+        body = self.fixtures.load('list_sizes.json')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+    def _droplets(self, method, url, body, headers):
+        body = self.fixtures.load('list_nodes.json')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+    def _droplets_119461_reboot(self, method, url, body, headers):
+        # reboot_node
+        body = self.fixtures.load('reboot_node.json')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+    def _droplets_119461_destroy(self, method, url, body, headers):
+        # destroy_node
+        body = self.fixtures.load('destroy_node.json')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+    def _ssh_keys(self, method, url, body, headers):
+        body = self.fixtures.load('ex_list_ssh_keys.json')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+    def _ssh_keys_7717_destroy(self, method, url, body, headers):
+        # destroy_ssh_key
+        body = self.fixtures.load('ex_destroy_ssh_key.json')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+    def _droplets_UNAUTHORIZED_CLIENT(self, method, url, body, headers):
+        body = self.fixtures.load('error.txt')
+        return (httplib.FOUND, body, {}, httplib.responses[httplib.FOUND])
+
+if __name__ == '__main__':
+    sys.exit(unittest.main())

Modified: libcloud/trunk/libcloud/test/secrets.py-dist
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/test/secrets.py-dist?rev=1454658&r1=1454657&r2=1454658&view=diff
==============================================================================
--- libcloud/trunk/libcloud/test/secrets.py-dist (original)
+++ libcloud/trunk/libcloud/test/secrets.py-dist Sat Mar  9 05:08:36 2013
@@ -39,6 +39,7 @@ JOYENT_PARAMS = ('user', 'key')
 VCL_PARAMS = ('user', 'pass', True, 'foo.bar.com')
 GRIDSPOT_PARAMS = ('key',)
 HOSTVIRTUAL_PARAMS = ('key',)
+DIGITAL_OCEAN_PARAMS = ('user', 'key')
 
 # Storage
 STORAGE_S3_PARAMS = ('key', 'secret')



Mime
View raw message