summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docker/Dockerfile3
-rw-r--r--restful_server/db.py11
-rw-r--r--restful_server/qtip_server.py10
-rw-r--r--tests/driver_test.py23
-rw-r--r--tests/qtip_server_test.py21
5 files changed, 56 insertions, 12 deletions
diff --git a/docker/Dockerfile b/docker/Dockerfile
index fc0e57c5..7c4b18fb 100644
--- a/docker/Dockerfile
+++ b/docker/Dockerfile
@@ -12,6 +12,7 @@ LABEL version="0.1" description="OPNFV QTIP Docker container"
ENV REPOS_DIR /home/opnfv/repos
ENV QTIP_DIR /home/opnfv/repos/qtip
+ENV PYTHONPATH /home/opnfv/repos/qtip
WORKDIR /home/opnfv
@@ -57,4 +58,4 @@ RUN git clone https://gerrit.opnfv.org/gerrit/releng $REPOS_DIR/releng
RUN pip install -r $REPOS_DIR/qtip/requirements.txt
-
+CMD cd $REPOS_DIR/qtip && python restful_server/qtip_server.py>/var/log/qtip/run.log
diff --git a/restful_server/db.py b/restful_server/db.py
index 916fc031..cf6ebfbb 100644
--- a/restful_server/db.py
+++ b/restful_server/db.py
@@ -7,6 +7,7 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
from datetime import datetime
+from operator import add
import uuid
jobs = {}
@@ -28,7 +29,8 @@ def create_job(args):
'end_time': None,
'state': 'processing',
'state_detail': [],
- 'result': []}
+ 'result': None,
+ 'result_detail': []}
jobs[job['job_id']] = job
return job['job_id']
@@ -54,6 +56,8 @@ def get_job_info(job_id):
def finish_job(job_id):
jobs[job_id]['end_time'] = str(datetime.now())
jobs[job_id]['state'] = 'finished'
+ jobs[job_id]['result'] = reduce(add, map(lambda x: x['result'],
+ jobs[job_id]['result_detail']))
del threads[job_id]
@@ -61,8 +65,9 @@ def update_job_state_detail(job_id, state_detail):
jobs[job_id]['state_detail'] = state_detail
-def update_job_result(job_id, result):
- jobs[job_id]['result'] = result
+def update_job_result_detail(job_id, benchmark, result):
+ result['benchmark'] = benchmark
+ jobs[job_id]['result_detail'].append(result)
def is_job_timeout(job_id):
diff --git a/restful_server/qtip_server.py b/restful_server/qtip_server.py
index b03c8f16..734a471c 100644
--- a/restful_server/qtip_server.py
+++ b/restful_server/qtip_server.py
@@ -163,8 +163,12 @@ default is 'compute'
if db.is_job_timeout(job_id) or stop_event.is_set():
break
db.update_benmark_state_in_state_detail(job_id, benchmark, 'processing')
- args_handler.prepare_and_run_benchmark(installer_type, '/home',
- args_handler.get_benchmark_path(pod_name, suite_name, benchmark))
+ result = args_handler.prepare_and_run_benchmark(installer_type,
+ '/home',
+ args_handler.get_benchmark_path(pod_name,
+ suite_name,
+ benchmark))
+ db.update_job_result_detail(job_id, benchmark, copy(result))
db.update_benmark_state_in_state_detail(job_id, benchmark, 'finished')
db.finish_job(job_id)
@@ -173,4 +177,4 @@ api.add_resource(JobList, '/api/v1.0/jobs')
api.add_resource(Job, '/api/v1.0/jobs/<string:id>')
if __name__ == "__main__":
- app.run()
+ app.run(host='0.0.0.0')
diff --git a/tests/driver_test.py b/tests/driver_test.py
index 9162ca16..5ea5dac4 100644
--- a/tests/driver_test.py
+++ b/tests/driver_test.py
@@ -63,13 +63,30 @@ class TestClass:
"role": "2-host"}])
])
@mock.patch('func.driver.AnsibleApi.execute_playbook')
- def test_driver_success(self, mock_ansible, test_input, expected):
+ @mock.patch('func.driver.AnsibleApi.get_detail_playbook_stats')
+ def test_driver_success(self, mock_stats, mock_ansible, test_input, expected):
mock_ansible.return_value = True
+ mock_stats.return_value = [(u'10.20.6.14', {'unreachable': 0,
+ 'skipped': 13,
+ 'ok': 27,
+ 'changed': 26,
+ 'failures': 0}),
+ ('localhost', {'unreachable': 0,
+ 'skipped': 0,
+ 'ok': 6,
+ 'changed': 6,
+ 'failures': 0}),
+ (u'10.20.6.13', {'unreachable': 0,
+ 'skipped': 13,
+ 'ok': 27,
+ 'changed': 26,
+ 'failures': 0})]
dri = Driver()
- dri.drive_bench(test_input[0], test_input[1], test_input[2], test_input[3],
- test_input[4], test_input[5], test_input[6], test_input[7])
+ result = dri.drive_bench(test_input[0], test_input[1], test_input[2], test_input[3],
+ test_input[4], test_input[5], test_input[6], test_input[7])
call_list = mock_ansible.call_args_list
for call in call_list:
call_args, call_kwargs = call
real_call = call_args[3]
assert real_call == expected[call_list.index(call)]
+ assert result['result'] == 0
diff --git a/tests/qtip_server_test.py b/tests/qtip_server_test.py
index 3f70a1f6..511d209a 100644
--- a/tests/qtip_server_test.py
+++ b/tests/qtip_server_test.py
@@ -41,7 +41,7 @@ class TestClass:
{'state': 'finished', 'benchmark': 'ramspeed_bm.yaml'},
{'state': 'finished', 'benchmark': 'dpi_bm.yaml'},
{'state': 'finished', 'benchmark': 'ssl_bm.yaml'}],
- 'result': []}),
+ 'result': 0}),
({'installer_type': 'fuel',
'installer_ip': '10.20.0.2',
'pod_name': 'zte-pod1',
@@ -61,10 +61,27 @@ class TestClass:
{u'state': u'finished', u'benchmark': u'ramspeed_vm.yaml'},
{u'state': u'finished', u'benchmark': u'dpi_vm.yaml'},
{u'state': u'finished', u'benchmark': u'ssl_vm.yaml'}],
- 'result': []})
+ 'result': 0})
])
@mock.patch('restful_server.qtip_server.args_handler.prepare_and_run_benchmark')
def test_post_get_delete_job_successful(self, mock_args_handler, app_client, body, expected):
+ mock_args_handler.return_value = {'result': 0,
+ 'detail': {'host': [(u'10.20.6.14', {'unreachable': 0,
+ 'skipped': 13,
+ 'ok': 27,
+ 'changed': 26,
+ 'failures': 0}),
+ ('localhost', {'unreachable': 0,
+ 'skipped': 0,
+ 'ok': 6,
+ 'changed': 6,
+ 'failures': 0}),
+ (u'10.20.6.13', {'unreachable': 0,
+ 'skipped': 13,
+ 'ok': 27,
+ 'changed': 26,
+ 'failures': 0})]}}
+
reply = app_client.post("/api/v1.0/jobs", data=body)
print(reply.data)
id = json.loads(reply.data)['job_id']