summaryrefslogtreecommitdiffstats
path: root/api/actions/result.py
diff options
context:
space:
mode:
authorJing Lu <lvjing5@huawei.com>2016-11-30 04:57:55 +0000
committerGerrit Code Review <gerrit@opnfv.org>2016-11-30 04:57:55 +0000
commited89d5d7372b598a3b849f7753e8d29a39282d53 (patch)
tree058c9694d125be16e900dde8c3e002694d5b3688 /api/actions/result.py
parent59aff2e16b819df0731ac8d2cf47cab112df9178 (diff)
parent053759a87b1d479b8083e352944baff3d12ff097 (diff)
Merge "Bugfix: the API to get result do not work due to can't parse $"
Diffstat (limited to 'api/actions/result.py')
-rw-r--r--api/actions/result.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/api/actions/result.py b/api/actions/result.py
index 9f606d2cb..10112ac68 100644
--- a/api/actions/result.py
+++ b/api/actions/result.py
@@ -7,6 +7,8 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
import logging
+import uuid
+import re
from api.utils import influx as influx_utils
from api.utils import common as common_utils
@@ -19,23 +21,27 @@ def getResult(args):
try:
measurement = args['measurement']
task_id = args['task_id']
+
+ if re.search("[^a-zA-Z0-9_-]", measurement):
+ raise ValueError('invalid measurement parameter')
+
+ uuid.UUID(task_id)
except KeyError:
- message = 'measurement and task_id must be needed'
+ message = 'measurement and task_id must be provided'
return common_utils.error_handler(message)
measurement = conf.TEST_CASE_PRE + measurement
- query_sql = "select * from $table where task_id='$task_id'"
- param = {'table': 'tasklist', 'task_id': task_id}
- data = common_utils.translate_to_str(influx_utils.query(query_sql, param))
+ query_template = "select * from %s where task_id='%s'"
+ query_sql = query_template % ('tasklist', task_id)
+ data = common_utils.translate_to_str(influx_utils.query(query_sql))
def _unfinished():
return common_utils.result_handler(0, [])
def _finished():
- param = {'table': measurement, 'task_id': task_id}
- data = common_utils.translate_to_str(influx_utils.query(query_sql,
- param))
+ query_sql = query_template % (measurement, task_id)
+ data = common_utils.translate_to_str(influx_utils.query(query_sql))
return common_utils.result_handler(1, data)