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)
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.operation_key = self._config['operation_key']
42 if "action_parameter" in self._config:
43 actionParameter = self._config['action_parameter']
44 str = buildshellparams(actionParameter)
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(rollbackParameter)
51 l = list(item for item in rollbackParameter.values())
52 self.rollback_param = str.format(*l)
54 self.operation_cfgs = BaseOperation.operation_cfgs.get(
56 self.action_script = self.get_script_fullpath(
57 self.operation_cfgs['action_script'])
58 self.rollback_script = self.get_script_fullpath(
59 self.operation_cfgs['rollback_script'])
62 if "action_parameter" in self._config:
63 with open(self.action_script, "r") as stdin_file:
64 exit_status, stdout, stderr = self.connection.execute(
68 with open(self.action_script, "r") as stdin_file:
69 exit_status, stdout, stderr = self.connection.execute(
74 LOG.debug("success,the operation's output is: %s", stdout)
77 "the operation's error, stdout:%s, stderr:%s",
81 if "rollback_parameter" in self._config:
82 with open(self.rollback_script, "r") as stdin_file:
83 exit_status, stdout, stderr = self.connection.execute(
87 with open(self.rollback_script, "r") as stdin_file:
88 exit_status, stdout, stderr = self.connection.execute(