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,6 +56,8 @@ 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
|
||||||
|
tests = objects.Cpulse.list(context, filters=filters)
|
||||||
|
if tests:
|
||||||
lasttest = objects.Cpulse.list(context, filters=filters)[-1]
|
lasttest = objects.Cpulse.list(context, filters=filters)[-1]
|
||||||
lastime = lasttest['created_at']
|
lastime = lasttest['created_at']
|
||||||
timenow = datetime.datetime.now(pytz.utc)
|
timenow = datetime.datetime.now(pytz.utc)
|
||||||
@ -64,6 +66,8 @@ class Periodic_Task(object):
|
|||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
def run_task(self):
|
def run_task(self):
|
||||||
importutils.import_module('keystonemiddleware.auth_token')
|
importutils.import_module('keystonemiddleware.auth_token')
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user