From b87a699e00b1903731c12127ccc7e3a8a292239b Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Sun, 27 Oct 2013 23:40:47 +0100 Subject: [PATCH] added "dummy" service for debugging end testing --- linspector/services/dummy.py | 85 ++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 linspector/services/dummy.py diff --git a/linspector/services/dummy.py b/linspector/services/dummy.py new file mode 100644 index 0000000..5b41e15 --- /dev/null +++ b/linspector/services/dummy.py @@ -0,0 +1,85 @@ +""" +Dummy service for debugging and testing + +This should just return 0 on success and 1 on error. + +Example json service config for fail: + +{ + "class": "dummy", + "args": { "sleep": 3, "fail": 1 }, + "periods": ["fast"], + "threshold": 3 +} + +For Success: + +{ + "class": "dummy", + "args": { "sleep": 3, "fail": 0 }, + "periods": ["fast"], + "threshold": 3 +} + +Copyright (c) 2011-2013 by Johannes Findeisen and Rafael Timmerberg + +This file is part of Linspector (http://linspector.org). + +Linspector is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +""" + +import time + +from logging import getLogger + +from linspector.services.service import Service + +logger = getLogger(__name__) + + +class DummyService(Service): + def __init__(self, **kwargs): + super(DummyService, self).__init__(**kwargs) + + args = self.get_arguments() + + self.sleep = 1 + if "sleep" in args: + self.port = args["sleep"] + + self.fail = 0 + if "fail" in args: + self.fail = args["fail"] + + def needs_arguments(self): + return False + + def execute(self, jobInfo): + + time.sleep(self.sleep) + + if self.fail > 0: + jobInfo.set_errorcode(1) + jobInfo.set_message("[dummy: " + jobInfo.jobHex + "] Failed on host: " + jobInfo.get_host() + + " Sleep: " + str(self.sleep) + " Fail: " + str(self.fail)) + + if jobInfo.get_errorcode() == -1: + jobInfo.set_execution_successful(True) + jobInfo.set_errorcode(0) + jobInfo.set_message("[dummy: " + jobInfo.jobHex + "] Success on host: " + jobInfo.get_host() + + " Sleep: " + str(self.sleep) + " Fail: " + str(self.fail)) + + +def create(kwargs): + return DummyService(**kwargs) \ No newline at end of file