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 import buildshellparams
19 LOG = logging.getLogger(__name__)
22 class GeneralOperaion(BaseOperation):
24 __operation__type__ = "general-operation"
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.operation_key = self._config['operation_key']
37 if "action_parameter" in self._config:
38 actionParameter = self._config['action_parameter']
39 str = buildshellparams(actionParameter)
40 l = list(item for item in actionParameter.values())
41 self.action_param = str.format(*l)
43 if "rollback_parameter" in self._config:
44 rollbackParameter = self._config['rollback_parameter']
45 str = buildshellparams(rollbackParameter)
46 l = list(item for item in rollbackParameter.values())
47 self.rollback_param = str.format(*l)
49 self.operation_cfgs = BaseOperation.operation_cfgs.get(
51 self.action_script = self.get_script_fullpath(
52 self.operation_cfgs['action_script'])
53 self.rollback_script = self.get_script_fullpath(
54 self.operation_cfgs['rollback_script'])
57 if "action_parameter" in self._config:
58 with open(self.action_script, "r") as stdin_file:
59 exit_status, stdout, stderr = self.connection.execute(
63 with open(self.action_script, "r") as stdin_file:
64 exit_status, stdout, stderr = self.connection.execute(
69 LOG.debug("success,the operation's output is: {0}".format(stdout))
72 "the operation's error, stdout:%s, stderr:%s",
76 if "rollback_parameter" in self._config:
77 with open(self.rollback_script, "r") as stdin_file:
78 exit_status, stdout, stderr = self.connection.execute(
82 with open(self.rollback_script, "r") as stdin_file:
83 exit_status, stdout, stderr = self.connection.execute(