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 ##############################################################################
10 from baseoperation import BaseOperation
11 import yardstick.ssh as ssh
12 from yardstick.benchmark.scenarios.availability.util import buildshellparams
14 LOG = logging.getLogger(__name__)
17 class GeneralOperaion(BaseOperation):
19 __operation__type__ = "general-operation"
22 LOG.debug("config:%s context:%s" % (self._config, self._context))
23 host = self._context.get(self._config['host'], None)
24 ip = host.get("ip", None)
25 user = host.get("user", "root")
26 key_filename = host.get("key_filename", "~/.ssh/id_rsa")
28 self.connection = ssh.SSH(user, ip, key_filename=key_filename)
29 self.connection.wait(timeout=600)
30 LOG.debug("ssh host success!")
32 self.key = self._config['key']
33 self.operation_key = self._config['operation_key']
35 if "action_parameter" in self._config:
36 actionParameter = self._config['action_parameter']
37 str = buildshellparams(actionParameter)
38 l = list(item for item in actionParameter.values())
39 self.action_param = str.format(*l)
41 if "rollback_parameter" in self._config:
42 rollbackParameter = self._config['rollback_parameter']
43 str = buildshellparams(rollbackParameter)
44 l = list(item for item in rollbackParameter.values())
45 self.rollback_param = str.format(*l)
47 self.operation_cfgs = BaseOperation.operation_cfgs.get(
49 self.action_script = self.get_script_fullpath(
50 self.operation_cfgs['action_script'])
51 self.rollback_script = self.get_script_fullpath(
52 self.operation_cfgs['rollback_script'])
55 if "action_parameter" in self._config:
56 exit_status, stdout, stderr = self.connection.execute(
58 stdin=open(self.action_script, "r"))
60 exit_status, stdout, stderr = self.connection.execute(
62 stdin=open(self.action_script, "r"))
65 LOG.debug("success,the operation's output is: {0}".format(stdout))
68 "the operation's error, stdout:%s, stderr:%s" %
72 if "rollback_parameter" in self._config:
73 exit_status, stdout, stderr = self.connection.execute(
75 stdin=open(self.rollback_script, "r"))
77 exit_status, stdout, stderr = self.connection.execute(
79 stdin=open(self.rollback_script, "r"))