Skip to content
Permalink
Browse files
Add varning when no items found for zone
  • Loading branch information
brogand93 committed Jun 20, 2014
1 parent 4ffa677 commit f3f68cd146ac3e0691241c8067b2c63094bb35c2
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 52 deletions.
@@ -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

@@ -23,11 +23,6 @@
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
@@ -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}
@@ -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 @@ def setUp(self):
self.app_context = self.app.app_context()
self.app_context.push()
db.create_all()
self._unauthed_user()
self._auth_example_user()


@@ -123,33 +123,6 @@ def test_delete_instance(self):

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',
@@ -55,3 +55,6 @@ def assert_bad_request(self, response):
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)

0 comments on commit f3f68cd

Please sign in to comment.