summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dovetail/api/app/routes.py9
-rw-r--r--dovetail/api/app/server.py88
-rw-r--r--dovetail/tests/unit/utils/test_dovetail_utils.py2
3 files changed, 75 insertions, 24 deletions
diff --git a/dovetail/api/app/routes.py b/dovetail/api/app/routes.py
index b1557b67..e60f10a5 100644
--- a/dovetail/api/app/routes.py
+++ b/dovetail/api/app/routes.py
@@ -9,7 +9,7 @@ import uuid
from flask import Flask, jsonify, request
from flask_cors import CORS
-import server
+import app.server as server
app = Flask(__name__)
CORS(app)
@@ -51,9 +51,10 @@ def run_testcases():
os.pardir, os.pardir))
run_script = os.path.join(repo_dir, 'run.py')
- cmd = 'python {} {}'.format(run_script, input_str)
+ cmd = 'python3 {} {}'.format(run_script, input_str)
api_home = os.path.join(dovetail_home, str(requestId))
- subprocess.Popen(cmd, shell=True, env={'DOVETAIL_HOME': api_home})
+ subprocess.Popen(cmd, shell=True, env={'DOVETAIL_HOME': api_home,
+ 'LC_ALL': 'C.UTF-8', 'LANG': 'C.UTF-8'})
testcases_file = os.path.join(dovetail_home, str(requestId),
'results', 'testcases.json')
@@ -72,7 +73,7 @@ def run_testcases():
testsuite = data['testsuite']
result = server.get_execution_status(dovetail_home, testsuite,
- testcases, requestId)
+ testcases, testcases, requestId)
return jsonify({'result': result}), 200
diff --git a/dovetail/api/app/server.py b/dovetail/api/app/server.py
index e6b1df46..312657da 100644
--- a/dovetail/api/app/server.py
+++ b/dovetail/api/app/server.py
@@ -2,8 +2,8 @@ import json
import os
import shutil
-import constants
-import utils
+import app.constants as constants
+import app.utils as utils
from dovetail.testcase import Testsuite, Testcase
@@ -134,10 +134,30 @@ def get_execution_status(dovetail_home, testsuite, request_testcases,
'timestart': None, 'endTime': None}
results.append(res)
if tc.startswith('bottlenecks'):
- pass
+ status, result = get_bottlenecks_status(results_dir, tc)
+ res = {'testCaseName': tc, 'testSuiteName': testsuite,
+ 'scenario': 'nfvi', 'executionId': requestId,
+ 'results': result, 'status': status,
+ 'timestart': None, 'endTime': None}
+ results.append(res)
return results
+def get_status_from_total_file(total_file, testcase):
+ with open(total_file, 'r') as f:
+ for jsonfile in f:
+ try:
+ data = json.loads(jsonfile)
+ for item in data['testcases_list']:
+ if item['name'] == testcase:
+ return item['result'], item['sub_testcase']
+ except KeyError as e:
+ return 'FAILED', None
+ except ValueError:
+ continue
+ return 'FAILED', None
+
+
def get_functest_status(results_dir, testcase):
functest_file = os.path.join(results_dir, 'functest_results.txt')
total_file = os.path.join(results_dir, 'results.json')
@@ -152,21 +172,10 @@ def get_functest_status(results_dir, testcase):
# get criteria and sub_testcase from results.json when all tests completed
if os.path.isfile(total_file):
- with open(total_file, 'r') as f:
- for jsonfile in f:
- try:
- data = json.loads(jsonfile)
- for item in data['testcases_list']:
- if item['name'] == testcase:
- criteria = item['result']
- sub_testcase = item['sub_testcase']
- break
- else:
- return 'FAILED', None
- except KeyError:
- return 'FAILED', None
- except ValueError:
- continue
+ criteria, sub_testcase = get_status_from_total_file(total_file,
+ testcase)
+ if criteria == 'FAILED':
+ return 'FAILED', None
# get detailed results from functest_results.txt
with open(functest_file, 'r') as f:
@@ -200,11 +209,21 @@ def get_yardstick_status(results_dir, testcase):
if not os.path.isfile(total_file):
return 'IN_PROGRESS', None
return 'FAILED', None
+
+ criteria = None
+
+ # get criteria and sub_testcase from results.json when all tests completed
+ if os.path.isfile(total_file):
+ criteria, _ = get_status_from_total_file(total_file, testcase)
+ if criteria == 'FAILED':
+ return 'FAILED', None
+
with open(yardstick_file, 'r') as f:
for jsonfile in f:
data = json.loads(jsonfile)
try:
- criteria = data['result']['criteria']
+ if not criteria:
+ criteria = data['result']['criteria']
if criteria == 'PASS':
details = data['result']['testcases']
for key, value in details.items():
@@ -217,3 +236,34 @@ def get_yardstick_status(results_dir, testcase):
status = 'COMPLETED' if criteria == 'PASS' else 'FAILED'
results = {'criteria': criteria, 'timestart': None, 'timestop': None}
return status, results
+
+
+def get_bottlenecks_status(results_dir, testcase):
+ bottlenecks_file = os.path.join(results_dir, 'stress_logs',
+ '{}.out'.format(testcase))
+ total_file = os.path.join(results_dir, 'results.json')
+ if not os.path.isfile(bottlenecks_file):
+ if not os.path.isfile(total_file):
+ return 'IN_PROGRESS', None
+ return 'FAILED', None
+
+ criteria = None
+
+ # get criteria and sub_testcase from results.json when all tests completed
+ if os.path.isfile(total_file):
+ criteria, _ = get_status_from_total_file(total_file, testcase)
+ if criteria == 'FAILED':
+ return 'FAILED', None
+
+ with open(bottlenecks_file, 'r') as f:
+ for jsonfile in f:
+ data = json.loads(jsonfile)
+ try:
+ if not criteria:
+ criteria = data['data_body']['result']
+ except KeyError:
+ return 'FAILED', None
+
+ status = 'COMPLETED' if criteria == 'PASS' else 'FAILED'
+ results = {'criteria': criteria, 'timestart': None, 'timestop': None}
+ return status, results
diff --git a/dovetail/tests/unit/utils/test_dovetail_utils.py b/dovetail/tests/unit/utils/test_dovetail_utils.py
index 2d2cdb0d..7ec177d1 100644
--- a/dovetail/tests/unit/utils/test_dovetail_utils.py
+++ b/dovetail/tests/unit/utils/test_dovetail_utils.py
@@ -511,7 +511,7 @@ class DovetailUtilsTesting(unittest.TestCase):
hosts_obj.write.assert_called_once()
def test_get_obj_by_path(self):
- obj = {'name': 'name', 'validate': {'testcase': 'testcase'}}
+ obj = {'list': ['a', 'b'], 'name': 'name'}
dst_path = ('name',)
expected = 'name'