Fixing issues with running cloudpulse

This fix addresses the following issues.
1.Throwing error when running an undefined test.
2.Show a 404 when doing cloudpulse show on a invalid test

Change-Id: Idd82cfdb43199bc223768000456ab3d26590edd0
This commit is contained in:
Anand Shanmugam 2015-09-21 17:52:16 -07:00
parent c24ad6d386
commit 0089419c4f
4 changed files with 24 additions and 8 deletions

View File

@ -56,14 +56,18 @@ class Periodic_Task(object):
task_interval = int(tasks[self.task]) task_interval = int(tasks[self.task])
filters = {} filters = {}
filters['name'] = self.task filters['name'] = self.task
lasttest = objects.Cpulse.list(context, filters=filters)[-1] tests = objects.Cpulse.list(context, filters=filters)
lastime = lasttest['created_at'] if tests:
timenow = datetime.datetime.now(pytz.utc) lasttest = objects.Cpulse.list(context, filters=filters)[-1]
timesincelast = (timenow - lastime).seconds lastime = lasttest['created_at']
if timesincelast >= task_interval: timenow = datetime.datetime.now(pytz.utc)
return True timesincelast = (timenow - lastime).seconds
if timesincelast >= task_interval:
return True
else:
return False
else: else:
return False return True
def run_task(self): def run_task(self):
importutils.import_module('keystonemiddleware.auth_token') importutils.import_module('keystonemiddleware.auth_token')

View File

@ -81,7 +81,7 @@ class ParsableErrorMiddleware(object):
else: else:
body = [json.dumps({'error_message': '\n'.join(app_iter)})] body = [json.dumps({'error_message': '\n'.join(app_iter)})]
state['headers'].append(('Content-Type', 'application/json')) state['headers'].append(('Content-Type', 'application/json'))
state['headers'].append(('Content-Length', len(body[0]))) state['headers'].append(('Content-Length', str(len(body[0]))))
else: else:
body = app_iter body = app_iter
return body return body

View File

@ -330,6 +330,10 @@ class TestAlreadyExists(Conflict):
message = _("A test with UUID %(uuid)s already exists.") message = _("A test with UUID %(uuid)s already exists.")
class TestInvalid(Invalid):
message = _("The test name %(test)s is invalid")
class NotSupported(CloudpulseException): class NotSupported(CloudpulseException):
message = _("%(operation)s is not supported.") message = _("%(operation)s is not supported.")
code = 400 code = 400

View File

@ -15,11 +15,13 @@
"""SQLAlchemy storage backend.""" """SQLAlchemy storage backend."""
from cloudpulse.common import exception from cloudpulse.common import exception
from cloudpulse.common.plugin import discover
from cloudpulse.common import utils from cloudpulse.common import utils
from cloudpulse.db import api from cloudpulse.db import api
from cloudpulse.db.sqlalchemy import models from cloudpulse.db.sqlalchemy import models
from cloudpulse.openstack.common._i18n import _ from cloudpulse.openstack.common._i18n import _
from cloudpulse.openstack.common import log from cloudpulse.openstack.common import log
from cloudpulse.scenario import base
from oslo_config import cfg from oslo_config import cfg
from oslo_db import exception as db_exc from oslo_db import exception as db_exc
from oslo_db.sqlalchemy import session as db_session from oslo_db.sqlalchemy import session as db_session
@ -132,6 +134,12 @@ class Connection(api.Connection):
sort_key, sort_dir, query) sort_key, sort_dir, query)
def create_test(self, values): def create_test(self, values):
# ensure that the test name is valid
discover.import_modules_from_package("cloudpulse.scenario.plugins")
plugins = discover.itersubclasses(base.Scenario)
if not any(values['name'] in dir(scenario) for scenario in plugins):
raise exception.TestInvalid(test=values['name'])
# ensure defaults are present for new tests # ensure defaults are present for new tests
if not values.get('uuid'): if not values.get('uuid'):
values['uuid'] = utils.generate_uuid() values['uuid'] = utils.generate_uuid()