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
12 from yardstick.benchmark.scenarios.availability.operation.baseoperation \
16 import yardstick.ssh as ssh
17 from yardstick.benchmark.scenarios.availability.util \
18 import buildshellparams, execute_shell_command
20 LOG = logging.getLogger(__name__)
23 class GeneralOperaion(BaseOperation):
25 __operation__type__ = "general-operation"
28 LOG.debug("config:%s context:%s", self._config, self._context)
29 host = self._context.get(self._config.get('host', None), None)
31 self.connection = None
33 self.connection = ssh.SSH.from_node(
34 host, defaults={"user": "root"})
35 self.connection.wait(timeout=600)
36 LOG.debug("ssh host success!")
38 self.key = self._config['key']
39 self.operation_key = self._config['operation_key']
41 if "action_parameter" in self._config:
42 actionParameter = self._config['action_parameter']
43 str = buildshellparams(
44 actionParameter, True if self.connection else False)
45 l = list(item for item in actionParameter.values())
46 self.action_param = str.format(*l)
48 if "rollback_parameter" in self._config:
49 rollbackParameter = self._config['rollback_parameter']
50 str = buildshellparams(
51 rollbackParameter, True if self.connection else False)
52 l = list(item for item in rollbackParameter.values())
53 self.rollback_param = str.format(*l)
55 self.operation_cfgs = BaseOperation.operation_cfgs.get(
57 self.action_script = self.get_script_fullpath(
58 self.operation_cfgs['action_script'])
59 self.rollback_script = self.get_script_fullpath(
60 self.operation_cfgs['rollback_script'])
63 if "action_parameter" in self._config:
65 with open(self.action_script, "r") as stdin_file:
66 exit_status, stdout, stderr = self.connection.execute(
67 "sudo {}".format(self.action_param),
70 exit_status, stdout = \
71 execute_shell_command(
72 "/bin/bash {0} {1}".format(
73 self.action_script, self.action_param))
76 with open(self.action_script, "r") as stdin_file:
77 exit_status, stdout, stderr = self.connection.execute(
81 exit_status, stdout = execute_shell_command(
82 "/bin/bash {0}".format(self.action_script))
85 LOG.debug("success,the operation's output is: %s", stdout)
88 "the operation's error, stdout:%s, stderr:%s",
92 if "rollback_parameter" in self._config:
94 with open(self.rollback_script, "r") as stdin_file:
95 exit_status, stdout, stderr = self.connection.execute(
96 "sudo {}".format(self.rollback_param),
99 exit_status, stdout = \
100 execute_shell_command(
101 "/bin/bash {0} {1}".format(
102 self.rollback_script, self.rollback_param))
105 with open(self.rollback_script, "r") as stdin_file:
106 exit_status, stdout, stderr = self.connection.execute(
110 exit_status, stdout = execute_shell_command(
111 "/bin/bash {0}".format(self.rollback_script))