From c2e118b3673286b5a545a11e0ceccbeadd29e3fb Mon Sep 17 00:00:00 2001 From: Kun Huang Date: Thu, 29 Oct 2015 10:55:59 +0800 Subject: [PATCH] add lock for task update Change-Id: I53aa58d7d8ae75f9e229fe2c5d7d75b3b9afbed1 --- requirements.txt | 1 + scripts/agent.py | 22 ++++++++++++++++------ tests/ci/scalpels-ci.sh | 4 ++++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/requirements.txt b/requirements.txt index 19ab49d..20a40e2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,4 @@ oslo.db python-novaclient sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2 psutil>=1.1.1,<2.0.0 +tooz>=1.19.0 # Apache-2.0 diff --git a/scripts/agent.py b/scripts/agent.py index 0a69eed..1a088aa 100755 --- a/scripts/agent.py +++ b/scripts/agent.py @@ -8,6 +8,8 @@ import sys from scalpels.db import api as db_api from copy import deepcopy as copy import signal +from tooz import coordination +import time """ python /agent.py mysql @@ -37,9 +39,17 @@ if __name__ == "__main__": # this kill is to script process worker_p = psutil.Process(worker.pid) worker_p.send_signal(signal.SIGINT) - task = db_api.task_get(task_uuid) - results = copy(task.results) - ret = db_api.result_create(out) - results.append(ret.uuid) - # TODO set this behaviour concurrable - db_api.task_update(task_uuid, results=results) + + # TODO file lock is okay in localhost, here need redis for distributed + # lock istead + co = coordination.get_coordinator("file:///tmp", b"localhost") + co.start() + lock = co.get_lock("task_update_lock") + with lock: + task = db_api.task_get(task_uuid) + results = copy(task.results) + ret = db_api.result_create(out) + results.append(ret.uuid) + db_api.task_update(task_uuid, results=results) + time.sleep(2) + co.stop() diff --git a/tests/ci/scalpels-ci.sh b/tests/ci/scalpels-ci.sh index 8ea7178..751c493 100755 --- a/tests/ci/scalpels-ci.sh +++ b/tests/ci/scalpels-ci.sh @@ -16,10 +16,14 @@ sca start -a rpc -a rabbit -a traffic echo "running load" source /opt/stack/new/devstack/openrc admin admin sca load --storm +sleep 10 echo stop those agents sca stop +echo waiting agent write data into db before report +sleep 20 + echo report data sca report