libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anthonys...@apache.org
Subject [03/16] libcloud git commit: continue integration test driver
Date Sun, 02 Apr 2017 11:38:45 GMT
continue integration test driver


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

Branch: refs/heads/trunk
Commit: b5702e25ea84289e881e04a1428f8265d5e5710f
Parents: e36c9b9
Author: Anthony Shaw <anthonyshaw@apache.org>
Authored: Mon Jan 9 17:06:44 2017 +1100
Committer: Anthony Shaw <anthonyshaw@apache.org>
Committed: Mon Jan 9 17:06:44 2017 +1100

----------------------------------------------------------------------
 integration/README.rst       | 20 +++++++++++
 integration/__main__.py      | 16 +++++++++
 integration/api/__main__.py  |  4 ++-
 integration/api/data.py      | 26 ++++++++++++++
 integration/api/routes.py    | 12 +++++--
 integration/driver/test.py   | 72 +++++++++++++++++++++++++++++++++++++++
 integration/requirements.txt |  1 +
 7 files changed, 147 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/b5702e25/integration/README.rst
----------------------------------------------------------------------
diff --git a/integration/README.rst b/integration/README.rst
new file mode 100644
index 0000000..ed61b5a
--- /dev/null
+++ b/integration/README.rst
@@ -0,0 +1,20 @@
+Integration Test Module
+=======================
+
+This test suite is for running a live API endpoint and testing the apache-libcloud functionality
as a full integration test
+
+Running the API service
+-----------------------
+
+.. code-block:: bash
+
+  pip install -r integration/requirements.txt
+  python -m integration.api
+
+Running the tests
+-----------------
+
+.. code-block:: bash
+
+   python -m integration
+   

http://git-wip-us.apache.org/repos/asf/libcloud/blob/b5702e25/integration/__main__.py
----------------------------------------------------------------------
diff --git a/integration/__main__.py b/integration/__main__.py
index e69de29..8f09ea9 100644
--- a/integration/__main__.py
+++ b/integration/__main__.py
@@ -0,0 +1,16 @@
+import unittest
+import sys
+
+from .driver.test import TestNodeDriver
+
+
+class IntegrationTest(unittest.TestCase):
+    def setUp(self):        
+        self.instance = TestNodeDriver('apache', 'libcloud', secure=False,
+                                       host='localhost', port=9898)
+
+    def test_nodes(self):
+        nodes = self.instance.list_nodes()
+
+if __name__ == '__main__':
+    sys.exit(unittest.main())

http://git-wip-us.apache.org/repos/asf/libcloud/blob/b5702e25/integration/api/__main__.py
----------------------------------------------------------------------
diff --git a/integration/api/__main__.py b/integration/api/__main__.py
index 7724165..2257687 100644
--- a/integration/api/__main__.py
+++ b/integration/api/__main__.py
@@ -13,6 +13,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from bottle import route, run, template
+from bottle import run
+
+from .routes import *
 
 run(host='localhost', port=9898)

http://git-wip-us.apache.org/repos/asf/libcloud/blob/b5702e25/integration/api/data.py
----------------------------------------------------------------------
diff --git a/integration/api/data.py b/integration/api/data.py
new file mode 100644
index 0000000..e49d515
--- /dev/null
+++ b/integration/api/data.py
@@ -0,0 +1,26 @@
+# 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.
+
+NODES = [
+    {'id': '1234a',
+     'name': 'test-1',
+     'state': 'RUNNING',
+     'public_ips': ['4.4.4.4', '8.8.8.8'],
+     'private_ips': ['10.0.0.1', '192.168.1.1'],
+     'size': 'test-size-1',
+     'created_at': '2017-01-09T05:25:12+00:00',
+     'image': 'test-image-1',
+     'extra': {'test-key': 'test-value'}}
+]
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/b5702e25/integration/api/routes.py
----------------------------------------------------------------------
diff --git a/integration/api/routes.py b/integration/api/routes.py
index 6e92298..7fdc3b1 100644
--- a/integration/api/routes.py
+++ b/integration/api/routes.py
@@ -13,6 +13,12 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-@route('/hello/<name>')
-def index(name):
-    return template('<b>Hello {{name}}</b>!', name=name)
+import json
+
+from bottle import route, template
+
+from .data import NODES
+
+@route('/compute/nodes', method='GET')
+def list_nodes():
+    return json.dumps(NODES)

http://git-wip-us.apache.org/repos/asf/libcloud/blob/b5702e25/integration/driver/test.py
----------------------------------------------------------------------
diff --git a/integration/driver/test.py b/integration/driver/test.py
new file mode 100644
index 0000000..886c98f
--- /dev/null
+++ b/integration/driver/test.py
@@ -0,0 +1,72 @@
+# 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 base64
+
+from libcloud.common.base import JsonResponse, ConnectionUserAndKey
+from libcloud.compute.base import NodeDriver
+
+from libcloud.utils.py3 import b
+
+
+class TestResponseType(JsonResponse):
+    pass
+
+
+class TestConnection(ConnectionUserAndKey):
+    host = 'localhost'
+    secure = True
+    responseCls = TestResponseType
+
+    allow_insecure = True
+
+    def __init__(self, user_id, key, secure=True, host=None, port=None,
+                 url=None, timeout=None, proxy_url=None,
+                 api_version=None, **conn_kwargs):
+        super(TestConnection, self).__init__(
+            user_id=user_id,
+            key=key,
+            secure=secure,
+            host=host, port=port,
+            url=url, timeout=timeout,
+            proxy_url=proxy_url)
+
+    def add_default_headers(self, headers):
+        user_b64 = base64.b64encode(b('%s:%s' % (self.user_id, self.key)))
+        headers['Authorization'] = 'Basic %s' % (user_b64)
+        return headers
+
+
+class TestNodeDriver(NodeDriver):
+    connectionCls = TestConnection
+    type = 'testing'
+    api_name = 'testing'
+    name = 'Test Compute Driver'
+    website = 'http://libcloud.apache.org'
+    features = {'create_node': ['ssh_key', 'password']}
+    
+    def __init__(self, key, secret=None, secure=True,
+                 host=None, port=None, **kwargs):
+        super(TestNodeDriver, self).__init__(key=key, secret=secret,
+                                             secure=secure, host=host,
+                                             port=port,
+                                             **kwargs)
+    
+    def list_nodes(self):
+        r = self.connection.request('/compute/nodes')
+        nodes = []
+        for node in r.object:
+            nodes.append(Node(**node))
+        return nodes

http://git-wip-us.apache.org/repos/asf/libcloud/blob/b5702e25/integration/requirements.txt
----------------------------------------------------------------------
diff --git a/integration/requirements.txt b/integration/requirements.txt
new file mode 100644
index 0000000..310dc0b
--- /dev/null
+++ b/integration/requirements.txt
@@ -0,0 +1 @@
+bottle


Mime
View raw message