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)
30 self.connection = ssh.SSH.from_node(host, defaults={"user": "root"})
31 self.connection.wait(timeout=600)
32 LOG.debug("ssh host success!")
34 self.key = self._config['key']
35 self.resultchecker_key = self._config['checker_key']
36 self.type = self._config['checker_type']
37 self.condition = self._config['condition']
38 self.expectedResult = self._config['expectedValue']
39 self.actualResult = object()
41 self.key = self._config['key']
42 if "parameter" in self._config:
43 parameter = self._config['parameter']
44 str = buildshellparams(parameter)
45 l = list(item for item in parameter.values())
46 self.shell_cmd = str.format(*l)
48 self.resultchecker_cfgs = BaseResultChecker.resultchecker_cfgs.get(
49 self.resultchecker_key)
50 self.verify_script = self.get_script_fullpath(
51 self.resultchecker_cfgs['verify_script'])
54 if "parameter" in self._config:
55 with open(self.verify_script, "r") as stdin_file:
56 exit_status, stdout, stderr = self.connection.execute(
59 LOG.debug("action script of the operation is: %s",
61 LOG.debug("action parameter the of operation is: %s",
64 with open(self.verify_script, "r") as stdin_file:
65 exit_status, stdout, stderr = self.connection.execute(
68 LOG.debug("action script of the operation is: %s",
71 LOG.debug("exit_status ,stdout : %s ,%s", exit_status, stdout)
72 if exit_status == 0 and stdout:
73 self.actualResult = stdout
74 LOG.debug("verifying resultchecker: %s", self.key)
75 LOG.debug("verifying resultchecker,expected: %s",
77 LOG.debug("verifying resultchecker,actual: %s", self.actualResult)
78 LOG.debug("verifying resultchecker,condition: %s", self.condition)
79 if (type(self.expectedResult) is int):
80 self.actualResult = int(self.actualResult)
81 if self.condition == Condition.EQUAL:
82 self.success = self.actualResult == self.expectedResult
83 elif self.condition == Condition.GREATERTHAN:
84 self.success = self.actualResult > self.expectedResult
85 elif self.condition == Condition.GREATERTHANEQUAL:
86 self.success = self.actualResult >= self.expectedResult
87 elif self.condition == Condition.LESSTHANEQUAL:
88 self.success = self.actualResult <= self.expectedResult
89 elif self.condition == Condition.LESSTHAN:
90 self.success = self.actualResult < self.expectedResult
91 elif self.condition == Condition.IN:
92 self.success = self.expectedResult in self.actualResult
96 "error happened when resultchecker: %s Invalid condition",
101 "error happened when resultchecker: %s verifying the result",
106 "verifying resultchecker: %s,the result is : %s", self.key,