1 ##############################################################################
2 # Copyright (c) 2016 Juan Qiu and others
3 # juan_ qiu@tongji.edu.cn
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
11 from baseresultchecker import BaseResultChecker
12 from yardstick.benchmark.scenarios.availability import Condition
13 import yardstick.ssh as ssh
14 from yardstick.benchmark.scenarios.availability.util import buildshellparams
16 LOG = logging.getLogger(__name__)
19 class GeneralResultChecker(BaseResultChecker):
21 __result_checker__type__ = "general-result-checker"
24 LOG.debug("config:%s context:%s" % (self._config, self._context))
25 host = self._context.get(self._config['host'], None)
26 ip = host.get("ip", None)
27 user = host.get("user", "root")
28 key_filename = host.get("key_filename", "~/.ssh/id_rsa")
30 self.connection = ssh.SSH(user, ip, key_filename=key_filename)
31 self.connection.wait(timeout=600)
32 LOG.debug("ssh host success!")
34 self.key = self._config['key']
35 self.type = self._config['checker_type']
36 self.condition = self._config['condition']
37 self.expectedResult = self._config['expectedValue']
38 self.actualResult = object()
40 self.key = self._config['key']
41 if "parameter" in self._config:
42 parameter = self._config['parameter']
43 str = buildshellparams(parameter)
44 l = list(item for item in parameter.values())
45 self.shell_cmd = str.format(*l)
47 self.resultchecker_cfgs = BaseResultChecker.resultchecker_cfgs.get(
49 self.verify_script = self.get_script_fullpath(
50 self.resultchecker_cfgs['verify_script'])
53 if "parameter" in self._config:
54 exit_status, stdout, stderr = self.connection.execute(
56 stdin=open(self.verify_script, "r"))
57 LOG.debug("action script of the operation is: {0}"
58 .format(self.verify_script))
59 LOG.debug("action parameter the of operation is: {0}"
60 .format(self.shell_cmd))
62 exit_status, stdout, stderr = self.connection.execute(
64 stdin=open(self.verify_script, "r"))
65 LOG.debug("action script of the operation is: {0}"
66 .format(self.verify_script))
68 LOG.debug("exit_status ,stdout : {0} ,{1}".format(exit_status, stdout))
69 if exit_status == 0 and stdout:
70 self.actualResult = stdout
71 LOG.debug("verifying resultchecker: {0}".format(self.key))
72 LOG.debug("verifying resultchecker,expected: {0}"
73 .format(self.expectedResult))
74 LOG.debug("verifying resultchecker,actual: {0}"
75 .format(self.actualResult))
76 LOG.debug("verifying resultchecker,condition: {0}"
77 .format(self.condition))
78 if (type(self.expectedResult) is int):
79 self.actualResult = int(self.actualResult)
80 if self.condition == Condition.EQUAL:
81 self.success = self.actualResult == self.expectedResult
82 elif self.condition == Condition.GREATERTHAN:
83 self.success = self.actualResult > self.expectedResult
84 elif self.condition == Condition.GREATERTHANEQUAL:
85 self.success = self.actualResult >= self.expectedResult
86 elif self.condition == Condition.LESSTHANEQUAL:
87 self.success = self.actualResult <= self.expectedResult
88 elif self.condition == Condition.LESSTHAN:
89 self.success = self.actualResult < self.expectedResult
90 elif self.condition == Condition.IN:
91 self.success = self.expectedResult in self.actualResult
95 "error happened when resultchecker: {0} Invalid condition"
100 "error happened when resultchecker: {0} verifying the result"
105 "verifying resultchecker: {0},the result is : {1}"
106 .format(self.key, self.success))