]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
With functionality test cases. Test it using 'python setup.py test'
authorBabu Shanmugam <anbu@enovance.com>
Fri, 7 Feb 2014 13:40:17 +0000 (19:10 +0530)
committerBabu Shanmugam <anbu@enovance.com>
Fri, 7 Feb 2014 13:40:17 +0000 (19:10 +0530)
server/ceph_brag.egg-info/SOURCES.txt
server/ceph_brag/controllers/root.py
server/ceph_brag/json.py
server/ceph_brag/model/db.py
server/ceph_brag/tests/test_functional.py
server/sample.json [new file with mode: 0644]

index 9c182f9a2704638f8a4a70cc6de2144dd3e2937e..fc3b81db98ef7e64c505fc25560b4f6ca06cce2d 100644 (file)
@@ -18,4 +18,4 @@ ceph_brag/model/db.py
 ceph_brag/tests/__init__.py
 ceph_brag/tests/config.py
 ceph_brag/tests/test_functional.py
-ceph_brag/tests/test_units.py
+ceph_brag/tests/test_units.py
\ No newline at end of file
index b83c460d880831b3e3b610cde9ec479c18a3e335..254ab86c09d34915c69b6093642eebe8fb4f2e80 100644 (file)
@@ -1,10 +1,14 @@
 from pecan import expose, request, abort, response
-from webob.exc import status_map
+from webob import exc
 from pecan.rest import RestController
 from ceph_brag.model import db
 import sys, traceback
 
 class RootController(RestController):
+    def fail(self, status_code=200, msg="OK"):
+        response.status = status_code
+        return msg
+
     @expose('json')
     def get(self, *args, **kwargs):
         if len(args) is 0:
@@ -12,58 +16,58 @@ class RootController(RestController):
             try:
                 result = db.get_uuids()
             except Exception as e:
-                traceback.print_exc()
-                abort(500, comment="Internal Server Error")
+                return self.fail(500, msg="Internal Server Error")
         elif len(args) is 1 or len(args) is 2 and args[1] == '':
             #/uuid
             try:
                 result = db.get_versions(args[0])
             except Exception as e:
-                traceback.print_exc()
-                abort(status_code=500, comment="Internal Server Error")
+                return self.fail(status_code=500, msg="Internal Server Error")
            
             if result is None:
-                abort(400, comment="Invalid UUID")
+                return self.fail(400, msg="Invalid UUID")
         elif len(args) is 2 or len(args) is 3 and args[2] == '':
             #/uuid/version_number
             try:
                 result = db.get_brag(args[0], args[1])
             except Exception as e:
-                traceback.print_exc()
-                abort(status_code=500, comment="Internal Server Error")
+                return self.fail(status_code=500, msg="Internal Server Error")
 
             if result is None:
-                abort(status_code=400, comment="Invalid UUID,version combination")
-        else: 
-            abort(status_code=400, comment="Invalid args")
-        
+                return self.fail(status_code=400, msg="Invalid UUID,version combination")
+        else:
+            return self.fail(status_code=400, msg="Invalid args")
+
         return result
 
     @expose(content_type='application/json')
     def put(self, *args, **kwargs):
         try:
             db.put_new_version(request.body)
+        except ValueError as ve:
+            return self.fail(status_code=422, msg="Improper payload")
+        except KeyError as ke:
+            msg = "Payload not as expected, some keys are missing"
+            return self.fail(status_code=422, msg=msg)
         except Exception as e:
-            traceback.print_exc()
-            abort(status_code=500, comment="Internal Server Error")
+            return self.fail(status_code=500, msg="Internal Server Error")
        
         response.status = 201
         return "CREATED"
     
     @expose()
     def delete(self, *args, **kwargs):
+        if 'uuid' not in kwargs:
+            return self.fail(status_code=400, msg="Required uuid parameter")
+        
         uuid = kwargs['uuid']
-        if uuid is None:
-            abort(status_code=400, comment="Required uuid parameter")
-
         try:
             status = db.delete_uuid(uuid)
         except Exception as e:
-            traceback.print_exc()
-            abort(status_code=500, comment="Internal Server Error")
+            return self.fail(status_code=500, msg="Internal Server Error")
         
         if status is not None:
-            abort(status_code=status['status'], comment=status['comment'])
+            return self.fail(status_code=status['status'], msg=status['msg'])
     
         response.status=200
         return "DELETED"
index 2f5128193f63c1bd4be4e7895356d293e7fd9e9d..5981e3c3497bff794ba80334577eb79e23b3972b 100644 (file)
@@ -17,6 +17,7 @@ def jsonify_cluster_info(ci):
               email=ci.contact_email,
               cluster_name=ci.cluster_name,
               cluster_creation_date=str(ci.cluster_creation_date),
+              num_versions=ci.num_versions
               )
 
 @jsonify.register(db.components_info)
index 09b5f5c94375df8d8e9c069d450916fa2871d073..acf3d5bd594f5dae7a0f52ed6d59c5a6348d0a28 100644 (file)
@@ -160,7 +160,7 @@ def put_new_version(data):
 def delete_uuid(uuid):
   ci = Session.query(cluster_info).filter_by(uuid=uuid).first()
   if ci is None:
-    return {'status':400, 'comment':'No information for this UUID'}
+    return {'status':400, 'msg':'No information for this UUID'}
 
   for v in Session.query(version_info).filter_by(cluster_id=ci.index).all():
     Session.query(components_info).filter_by(vid=v.index).delete()
index 126817ee5d1567f56fe1d31cdc05da6b69bdd16d..13285c41a506e904175bd5b6394beeb64d0a27a4 100644 (file)
@@ -1,22 +1,68 @@
 from unittest import TestCase
 from webtest import TestApp
 from ceph_brag.tests import FunctionalTest
-import sys
+import json, sys
 from pecan import request
 
 class TestRootController(FunctionalTest):
+    def test_1_get_invalid_url_format(self):
+        response = self.app.get('/1/2/3', expect_errors=True)
+        assert response.status_int == 400
 
-    def test_get(self):
-        response = self.app.get('/?k1=v1&k2=v2')
-        assert response.status_int == 200
-
-    def test_put(self):
-        #response = self.app.put('/', upload_files=[("uploadfield", "/tmp/sample.json")])
-        with open ("/tmp/sample.json", "r") as myfile:
+    def test_2_put(self):
+        with open ("sample.json", "r") as myfile:
             data=myfile.read().replace('\n', '')
         response = self.app.request('/', method='PUT', body=data)
-        assert response.status_int == 302
+        assert response.status_int == 201
+
+    def test_3_put_invalid_json(self):
+        response = self.app.request('/', method='PUT', body='{asdfg', expect_errors=True)
+        assert response.status_int == 422
+
+    def test_4_put_invalid_entries_1(self):
+        response = self.app.request('/', method='PUT', body='{}', expect_errors=True)
+        assert response.status_int == 422
+
+    def test_5_put_incomplete_json(self):
+        response = self.app.request('/', method='PUT', body='{\"uuid\":\"adfs-12312ad\"}', 
+                                    expect_errors=True)
+        assert response.status_int == 422
+
+    def test_6_get(self):
+        response = self.app.get('/')
+        js = json.loads(response.body)
+        for entry in js:
+            ci = entry
+            break
+
+        response = self.app.get('/'+ci['uuid']+'/'+str(ci['num_versions']))
+        assert response.status_int == 200
+
+    def test_7_get_invalid_uuid(self):
+        response = self.app.get('/xxxxxx', expect_errors=True)
+        assert response.status_int == 400
+
+    def test_8_get_invalid_version(self):
+        response = self.app.get('/')
+        js = json.loads(response.body)
+        for entry in js:
+            ci = entry
+            break
+
+        response = self.app.get('/'+ci['uuid']+'/'+str(0), expect_errors=True)
+        assert response.status_int == 400
+
+    def test_9_delete_invalid_parameters(self):
+        response = self.app.delete('/', expect_errors=True)
+        assert response.status_int == 400
+
+    def test_91_delete_wrong_uuid(self):
+        response = self.app.delete('/?uuid=xxxx', expect_errors=True)
+        assert response.status_int == 400
 
-    def test_get_not_found(self):
-        response = self.app.get('/a/bogus/url', expect_errors=True)
-        assert response.status_int == 404
+    def test_92_delete(self):
+        response = self.app.get('/')
+        js = json.loads(response.body)
+        for entry in js:
+            response = self.app.delete('/?uuid='+entry['uuid'])
+            assert response.status_int == 200
diff --git a/server/sample.json b/server/sample.json
new file mode 100644 (file)
index 0000000..d51fe59
--- /dev/null
@@ -0,0 +1,74 @@
+{
+      "cluster_creation_date": "2014-01-16 13:38:41.928551",
+      "uuid": "20679d0e-04b1-4004-8ee9-45ac271510e9",
+      "components_count": {
+        "bytes": {
+          "count": 0,
+          "scale": "bytes"
+        },
+        "osds": 1,
+        "objects": 0,
+        "pgs": 192,
+        "pools": 3,
+        "mdss": 1,
+        "mons": 1
+      },
+      "crush_types": [
+        "osd",
+        "host",
+        "chassis",
+        "rack",
+        "row",
+        "pdu",
+        "pod",
+        "room",
+        "datacenter",
+        "region",
+        "root"
+      ],
+      "ownership": {
+        "organization": "eNovance",
+        "description": "Use case1",
+        "email": "mail@enovance.com",
+        "name": "Cluster1"
+      },
+      "pool_metadata": [
+        {
+          "rep_size": 3,
+          "id": "0",
+          "name": "data"
+        },
+        {
+          "rep_size": 3,
+          "id": "1",
+          "name": "metadata"
+        },
+        {
+          "rep_size": 3,
+          "id": "2",
+          "name": "rbd"
+        }
+      ],
+      "sysinfo": [
+        {
+          "nw_info": {
+            "hostname": "ceph-brag",
+            "address": "127.0.0.1"
+          },
+          "hw_info": {
+            "swap_kb": 0,
+            "arch": "x86_64",
+            "cpu": "Intel Xeon E312xx (Sandy Bridge)",
+            "mem_kb": 2051648
+          },
+          "id": 0,
+          "os_info": {
+            "version": "3.2.0-23-virtual",
+            "os": "Linux",
+            "description": "#36-Ubuntu SMP Tue Apr 10 22:29:03 UTC 2012",
+            "distro": "Ubuntu 12.04 precise (Ubuntu 12.04 LTS)"
+          },
+          "ceph_version": "ceph version 0.75-229-g4050eae (4050eae32cd77a1c210ca11d0f12c74daecb1bd3)"
+        }
+      ]
+    }