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 ##############################################################################
9 from __future__ import absolute_import
13 from yardstick.benchmark.scenarios.availability.result_checker \
14 .baseresultchecker import \
16 from yardstick.benchmark.scenarios.availability import Condition
17 import yardstick.ssh as ssh
18 from yardstick.benchmark.scenarios.availability.util import buildshellparams
20 LOG = logging.getLogger(__name__)
23 class GeneralResultChecker(BaseResultChecker):
24 __result_checker__type__ = "general-result-checker"
27 LOG.debug("config:%s context:%s", self._config, self._context)
28 host = self._context.get(self._config['host'], None)
29 ip = host.get("ip", None)
30 user = host.get("user", "root")
31 ssh_port = host.get("ssh_port", ssh.DEFAULT_PORT)
32 key_filename = host.get("key_filename", "~/.ssh/id_rsa")
34 self.connection = ssh.SSH(user, ip, key_filename=key_filename,
36 self.connection.wait(timeout=600)
37 LOG.debug("ssh host success!")
39 self.key = self._config['key']
40 self.resultchecker_key = self._config['checker_key']
41 self.type = self._config['checker_type']
42 self.condition = self._config['condition']
43 self.expectedResult = self._config['expectedValue']
44 self.actualResult = object()
46 self.key = self._config['key']
47 if "parameter" in self._config:
48 parameter = self._config['parameter']
49 str = buildshellparams(parameter)
50 l = list(item for item in parameter.values())
51 self.shell_cmd = str.format(*l)
53 self.resultchecker_cfgs = BaseResultChecker.resultchecker_cfgs.get(
54 self.resultchecker_key)
55 self.verify_script = self.get_script_fullpath(
56 self.resultchecker_cfgs['verify_script'])
59 if "parameter" in self._config:
60 with open(self.verify_script, "r") as stdin_file:
61 exit_status, stdout, stderr = self.connection.execute(
64 LOG.debug("action script of the operation is: %s",
66 LOG.debug("action parameter the of operation is: %s",
69 with open(self.verify_script, "r") as stdin_file:
70 exit_status, stdout, stderr = self.connection.execute(
73 LOG.debug("action script of the operation is: %s",
76 LOG.debug("exit_status ,stdout : %s ,%s", exit_status, stdout)
77 if exit_status == 0 and stdout:
78 self.actualResult = stdout
79 LOG.debug("verifying resultchecker: %s", self.key)
80 LOG.debug("verifying resultchecker,expected: %s",
82 LOG.debug("verifying resultchecker,actual: %s", self.actualResult)
83 LOG.debug("verifying resultchecker,condition: %s", self.condition)
84 if (type(self.expectedResult) is int):
85 self.actualResult = int(self.actualResult)
86 if self.condition == Condition.EQUAL:
87 self.success = self.actualResult == self.expectedResult
88 elif self.condition == Condition.GREATERTHAN:
89 self.success = self.actualResult > self.expectedResult
90 elif self.condition == Condition.GREATERTHANEQUAL:
91 self.success = self.actualResult >= self.expectedResult
92 elif self.condition == Condition.LESSTHANEQUAL:
93 self.success = self.actualResult <= self.expectedResult
94 elif self.condition == Condition.LESSTHAN:
95 self.success = self.actualResult < self.expectedResult
96 elif self.condition == Condition.IN:
97 self.success = self.expectedResult in self.actualResult
101 "error happened when resultchecker: %s Invalid condition",
106 "error happened when resultchecker: %s verifying the result",
111 "verifying resultchecker: %s,the result is : %s", self.key,