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:
parent
c24ad6d386
commit
0089419c4f
@ -56,14 +56,18 @@ class Periodic_Task(object):
|
||||
task_interval = int(tasks[self.task])
|
||||
filters = {}
|
||||
filters['name'] = self.task
|
||||
lasttest = objects.Cpulse.list(context, filters=filters)[-1]
|
||||
lastime = lasttest['created_at']
|
||||
timenow = datetime.datetime.now(pytz.utc)
|
||||
timesincelast = (timenow - lastime).seconds
|
||||
if timesincelast >= task_interval:
|
||||
return True
|
||||
tests = objects.Cpulse.list(context, filters=filters)
|
||||
if tests:
|
||||
lasttest = objects.Cpulse.list(context, filters=filters)[-1]
|
||||
lastime = lasttest['created_at']
|
||||
timenow = datetime.datetime.now(pytz.utc)
|
||||
timesincelast = (timenow - lastime).seconds
|
||||
if timesincelast >= task_interval:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
else:
|
||||
return False
|
||||
return True
|
||||
|
||||
def run_task(self):
|
||||
importutils.import_module('keystonemiddleware.auth_token')
|
||||
|
@ -81,7 +81,7 @@ class ParsableErrorMiddleware(object):
|
||||
else:
|
||||
body = [json.dumps({'error_message': '\n'.join(app_iter)})]
|
||||
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:
|
||||
body = app_iter
|
||||
return body
|
||||
|
@ -330,6 +330,10 @@ class TestAlreadyExists(Conflict):
|
||||
message = _("A test with UUID %(uuid)s already exists.")
|
||||
|
||||
|
||||
class TestInvalid(Invalid):
|
||||
message = _("The test name %(test)s is invalid")
|
||||
|
||||
|
||||
class NotSupported(CloudpulseException):
|
||||
message = _("%(operation)s is not supported.")
|
||||
code = 400
|
||||
|
@ -15,11 +15,13 @@
|
||||
"""SQLAlchemy storage backend."""
|
||||
|
||||
from cloudpulse.common import exception
|
||||
from cloudpulse.common.plugin import discover
|
||||
from cloudpulse.common import utils
|
||||
from cloudpulse.db import api
|
||||
from cloudpulse.db.sqlalchemy import models
|
||||
from cloudpulse.openstack.common._i18n import _
|
||||
from cloudpulse.openstack.common import log
|
||||
from cloudpulse.scenario import base
|
||||
from oslo_config import cfg
|
||||
from oslo_db import exception as db_exc
|
||||
from oslo_db.sqlalchemy import session as db_session
|
||||
@ -132,6 +134,12 @@ class Connection(api.Connection):
|
||||
sort_key, sort_dir, query)
|
||||
|
||||
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
|
||||
if not values.get('uuid'):
|
||||
values['uuid'] = utils.generate_uuid()
|
||||
|
Loading…
x
Reference in New Issue
Block a user