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):
20 __result_checker__type__ = "general-result-checker"
23 LOG.debug("config:%s context:%s", self._config, self._context)
24 host = self._context.get(self._config['host'], None)
25 ip = host.get("ip", None)
26 user = host.get("user", "root")
27 ssh_port = host.get("ssh_port", ssh.DEFAULT_PORT)
28 key_filename = host.get("key_filename", "~/.ssh/id_rsa")
30 self.connection = ssh.SSH(user, ip, key_filename=key_filename,
32 self.connection.wait(timeout=600)
33 LOG.debug("ssh host success!")
35 self.key = self._config['key']
36 self.resultchecker_key = self._config['checker_key']
37 self.type = self._config['checker_type']
38 self.condition = self._config['condition']
39 self.expectedResult = self._config['expectedValue']
40 self.actualResult = object()
42 self.key = self._config['key']
43 if "parameter" in self._config:
44 parameter = self._config['parameter']
45 str = buildshellparams(parameter)
46 l = list(item for item in parameter.values())
47 self.shell_cmd = str.format(*l)
49 self.resultchecker_cfgs = BaseResultChecker.resultchecker_cfgs.get(
50 self.resultchecker_key)
51 self.verify_script = self.get_script_fullpath(
52 self.resultchecker_cfgs['verify_script'])
55 if "parameter" in self._config:
56 with open(self.verify_script, "r") as stdin_file:
57 exit_status, stdout, stderr = self.connection.execute(
60 LOG.debug("action script of the operation is: {0}"
61 .format(self.verify_script))
62 LOG.debug("action parameter the of operation is: {0}"
63 .format(self.shell_cmd))
65 with open(self.verify_script, "r") as stdin_file:
66 exit_status, stdout, stderr = self.connection.execute(
69 LOG.debug("action script of the operation is: {0}"
70 .format(self.verify_script))
72 LOG.debug("exit_status ,stdout : %s ,%s", exit_status, stdout)
73 if exit_status == 0 and stdout:
74 self.actualResult = stdout
75 LOG.debug("verifying resultchecker: {0}".format(self.key))
76 LOG.debug("verifying resultchecker,expected: {0}"
77 .format(self.expectedResult))
78 LOG.debug("verifying resultchecker,actual: {0}"
79 .format(self.actualResult))
80 LOG.debug("verifying resultchecker,condition: {0}"
81 .format(self.condition))
82 if (type(self.expectedResult) is int):
83 self.actualResult = int(self.actualResult)
84 if self.condition == Condition.EQUAL:
85 self.success = self.actualResult == self.expectedResult
86 elif self.condition == Condition.GREATERTHAN:
87 self.success = self.actualResult > self.expectedResult
88 elif self.condition == Condition.GREATERTHANEQUAL:
89 self.success = self.actualResult >= self.expectedResult
90 elif self.condition == Condition.LESSTHANEQUAL:
91 self.success = self.actualResult <= self.expectedResult
92 elif self.condition == Condition.LESSTHAN:
93 self.success = self.actualResult < self.expectedResult
94 elif self.condition == Condition.IN:
95 self.success = self.expectedResult in self.actualResult
99 "error happened when resultchecker: {0} Invalid condition"
104 "error happened when resultchecker: {0} verifying the result"
109 "verifying resultchecker: %s,the result is : %s", self.key,