cloudstack-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seb...@apache.org
Subject [23/50] [abbrv] cloudstack-gcestack git commit: Add varning when no items found for zone
Date Tue, 05 May 2015 11:18:57 GMT
Add varning when no items found for zone


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

Branch: refs/heads/master
Commit: f3f68cd146ac3e0691241c8067b2c63094bb35c2
Parents: 4ffa677
Author: BroganD1993 <darrenbrogan@hotmail.com>
Authored: Fri Jun 20 20:24:06 2014 +0100
Committer: BroganD1993 <darrenbrogan@hotmail.com>
Committed: Fri Jun 20 20:24:06 2014 +0100

----------------------------------------------------------------------
 gstack/controllers/__init__.py  |  6 ++++--
 gstack/controllers/errors.py    |  7 +------
 gstack/controllers/instances.py | 20 +++-----------------
 tests/__init__.py               |  5 +++++
 tests/instances_tests.py        | 27 ---------------------------
 tests/utils.py                  |  3 +++
 6 files changed, 16 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack-gcestack/blob/f3f68cd1/gstack/controllers/__init__.py
----------------------------------------------------------------------
diff --git a/gstack/controllers/__init__.py b/gstack/controllers/__init__.py
index 966f540..97f7847 100644
--- a/gstack/controllers/__init__.py
+++ b/gstack/controllers/__init__.py
@@ -122,9 +122,11 @@ def describe_items_aggregated(authorization, args, type, gce_type, to_cloudstack
     for zone in zone_list:
         kwargs['zone'] = zone
         zone_items = _get_requested_items(authorization, args, type, to_cloudstack, **kwargs)
-
         items['zone/' + zone] = {}
-        items['zone/' + zone][gce_type] = zone_items
+        if zone_items:
+            items['zone/' + zone][gce_type] = zone_items
+        else:
+            items['zone/' + zone] = errors.no_results_found(zone)
 
     return items
 

http://git-wip-us.apache.org/repos/asf/cloudstack-gcestack/blob/f3f68cd1/gstack/controllers/errors.py
----------------------------------------------------------------------
diff --git a/gstack/controllers/errors.py b/gstack/controllers/errors.py
index 1381297..9805ca9 100644
--- a/gstack/controllers/errors.py
+++ b/gstack/controllers/errors.py
@@ -23,11 +23,6 @@ from gstack import helpers
 from flask import Response
 
 
-@app.errorhandler(404)
-def not_found(e):
-    return Response('Not Found', status=404, mimetype='text/html')
-
-
 @app.errorhandler(401)
 def unauthorized(e):
     res = {
@@ -71,7 +66,7 @@ def no_results_found(scope):
     return ({
         "warning": {
             "code": "NO_RESULTS_ON_PAGE",
-            "message": "There are no results for scope" + scope + " on this page.",
+            "message": "There are no results for scope " + scope + " on this page.",
             "data": [{
                 "key": "scope",
                 "value": scope

http://git-wip-us.apache.org/repos/asf/cloudstack-gcestack/blob/f3f68cd1/gstack/controllers/instances.py
----------------------------------------------------------------------
diff --git a/gstack/controllers/instances.py b/gstack/controllers/instances.py
index 08d7ae8..1eb0e6a 100755
--- a/gstack/controllers/instances.py
+++ b/gstack/controllers/instances.py
@@ -167,20 +167,9 @@ def addinstance(authorization, projectid, zone):
     deployment_result = _deploy_virtual_machine(authorization, args, projectid)
 
     if 'errortext' in deployment_result['deployvirtualmachineresponse']:
-        populated_response = {
-            'kind': 'compute#operation',
-            'operationType': 'insert',
-            'targetLink': '',
-            'status': 'DONE',
-            'progress': 100,
-            'error': {
-                'errors': [{
-                    'code': 'RESOURCE_ALREADY_EXISTS',
-                    'message': 'the resource \'projects/\'' + projectid +
-                               '/zones/' + zone + '/instances/' + args['name']
-                }]
-            }
-        }
+        func_route = url_for('addinstance', projectid=projectid, zone=zone)
+        return errors.resource_not_found(func_route)
+
     else:
         populated_response = operations.create_response(
             projectid=projectid,
@@ -196,9 +185,6 @@ def addinstance(authorization, projectid, zone):
 def deleteinstance(projectid, authorization, zone, instance):
     args = {'command': 'listVirtualMachines'}
     virtual_machine = controllers.get_item_with_name(authorization, instance, args, 'virtualmachine')
-    if virtual_machine is None:
-        func_route = url_for('deleteinstance', projectid=projectid, zone=zone, instance=instance)
-        return errors.resource_not_found(func_route)
 
     virtual_machine_id = virtual_machine['id']
     args = {'id': virtual_machine_id}

http://git-wip-us.apache.org/repos/asf/cloudstack-gcestack/blob/f3f68cd1/tests/__init__.py
----------------------------------------------------------------------
diff --git a/tests/__init__.py b/tests/__init__.py
index 01c4810..6308895 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -22,6 +22,10 @@ class GStackAppTestCase(FlaskTestCaseMixin, GStackTestCase):
     def _configure_app(self):
         configure_app(settings=settings)
 
+    def _unauthed_user(self):
+        response = self.get('/compute/v1/projects/exampleproject/global/images')
+        self.assert_unauthorized(response)
+
 
     def _auth_example_user(self):
         data = {}
@@ -53,6 +57,7 @@ class GStackAppTestCase(FlaskTestCaseMixin, GStackTestCase):
         self.app_context = self.app.app_context()
         self.app_context.push()
         db.create_all()
+        self._unauthed_user()
         self._auth_example_user()
 
 

http://git-wip-us.apache.org/repos/asf/cloudstack-gcestack/blob/f3f68cd1/tests/instances_tests.py
----------------------------------------------------------------------
diff --git a/tests/instances_tests.py b/tests/instances_tests.py
index 4278caa..6f548ae 100644
--- a/tests/instances_tests.py
+++ b/tests/instances_tests.py
@@ -123,33 +123,6 @@ class InstancesTestCase(GStackAppTestCase):
 
         self.assert_ok(response)
 
-    def test_delete_instance_instance_not_found(self):
-        get = mock.Mock()
-        get.return_value.text = read_file('tests/data/valid_async_destroy_vm.json')
-        get.return_value.status_code = 200
-
-        get_instance = mock.Mock()
-        get_instance.return_value = None
-
-        get_async_result = mock.Mock()
-        get_async_result.return_value = json.loads(read_file('tests/data/valid_run_instance.json'))
-
-        publickey_storage['admin'] = 'testkey'
-
-        with mock.patch('requests.get', get):
-            with mock.patch(
-                    'gstack.controllers.get_item_with_name',
-                    get_instance
-                ):
-                with mock.patch(
-                    'gstack.controllers.operations._get_async_result',
-                    get_async_result
-                ):
-                    headers = {'authorization': 'Bearer ' + str(GStackAppTestCase.access_token)}
-                    response = self.delete('/compute/v1/projects/admin/zones/examplezone/instances/instancename',
headers=headers)
-
-        self.assert_not_found(response)
-
     def test_add_instance(self):
         data = {
              'kind':  'compte#instance',

http://git-wip-us.apache.org/repos/asf/cloudstack-gcestack/blob/f3f68cd1/tests/utils.py
----------------------------------------------------------------------
diff --git a/tests/utils.py b/tests/utils.py
index 60f57b1..c442322 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -55,3 +55,6 @@ class FlaskTestCaseMixin(object):
     def assert_not_found(self, response):
         return self.assert_status_code(response, 404)
 
+    def assert_unauthorized(self, response):
+        return self.assert_status_code(response, 401)
+


Mime
View raw message