1 from __future__ import absolute_import
2 from __future__ import print_function
11 from oslo_serialization import jsonutils
13 import yardstick.ssh as ssh
14 from yardstick.benchmark.scenarios import base
16 LOG = logging.getLogger(__name__)
17 LOG.setLevel(logging.DEBUG)
20 class QemuMigrate(base.Scenario):
22 Execute a live migration for two host using qemu
26 __scenario_type__ = "QemuMigrate"
28 TARGET_SCRIPT = "qemu_migrate_benchmark.bash"
29 WORKSPACE = "/root/workspace"
30 REBOOT_CMD_PATTERN = r";\s*reboot\b"
32 def __init__(self, scenario_cfg, context_cfg):
33 self.scenario_cfg = scenario_cfg
34 self.context_cfg = context_cfg
35 self.setup_done = False
37 def _connect_host(self):
38 host = self.context_cfg["host"]
39 self.host = ssh.SSH.from_node(host, defaults={"user": "root"})
40 self.host.wait(timeout=600)
42 def _put_files(self, client):
43 setup_options = self.scenario_cfg["setup_options"]
44 script_dir = setup_options["script_dir"]
45 LOG.debug("Send scripts from %s to workspace %s",
46 script_dir, self.WORKSPACE)
47 client.put(script_dir, self.WORKSPACE, recursive=True)
49 def _run_setup_cmd(self, client, cmd):
50 LOG.debug("Run cmd: %s", cmd)
51 status, stdout, stderr = client.execute(cmd)
53 if re.search(self.REBOOT_CMD_PATTERN, cmd):
54 LOG.debug("Error on reboot")
56 raise RuntimeError(stderr)
58 def _run_host_setup_scripts(self, scripts):
59 setup_options = self.scenario_cfg["setup_options"]
60 script_dir = os.path.basename(setup_options["script_dir"])
62 for script in scripts:
63 cmd = "cd %s/%s; export PATH=./:$PATH; %s" %\
64 (self.WORKSPACE, script_dir, script)
65 self._run_setup_cmd(self.host, cmd)
67 if re.search(self.REBOOT_CMD_PATTERN, cmd):
73 setup_options = self.scenario_cfg["setup_options"]
74 host_setup_seqs = setup_options["host_setup_seqs"]
77 self._put_files(self.host)
78 self._run_host_setup_scripts(host_setup_seqs)
81 self.target_script = pkg_resources.resource_filename(
82 "yardstick.benchmark.scenarios.compute",
83 QemuMigrate.TARGET_SCRIPT)
84 self.host.put_file(self.target_script, "~/qemu_migrate_benchmark.sh")
86 self.setup_done = True
88 def run(self, result):
89 """execute the benchmark"""
91 options = self.scenario_cfg["options"]
92 smp = options.get("smp", 2)
93 qmp_sock_src = options.get("qmp_src_path", "/tmp/qmp-sock-src")
94 qmp_sock_dst = options.get("qmp_dst_path", "/tmp/qmp-sock-dst")
95 incoming_ip = options.get("incoming_ip", 0)
96 migrate_to_port = options.get("migrate_to_port", 4444)
97 max_down_time = options.get("max_down_time", 0.10)
98 cmd_args = " %s %s %s %s %s %s" %\
99 (smp, qmp_sock_src, qmp_sock_dst, incoming_ip,
100 migrate_to_port, max_down_time)
101 cmd = "bash migrate_benchmark.sh %s" % (cmd_args)
102 LOG.debug("Executing command: %s", cmd)
103 status, stdout, stderr = self.host.execute(cmd)
105 raise RuntimeError(stderr)
107 result.update(jsonutils.loads(stdout))
109 if "sla" in self.scenario_cfg:
111 for t, timevalue in result.items():
112 if 'max_%s' % t not in self.scenario_cfg['sla']:
115 sla_time = int(self.scenario_cfg['sla'][
117 timevalue = int(timevalue)
118 if timevalue > sla_time:
119 sla_error += "%s timevalue %d > sla:max_%s(%d); " % \
120 (t, timevalue, t, sla_time)
121 assert sla_error == "", sla_error
124 def _test(): # pragma: no cover
125 """internal test function"""
126 key_filename = pkg_resources.resource_filename("yardstick.resources",
127 "files/yardstick_key")
130 "ip": "10.229.47.137",
132 "key_filename": key_filename
136 logger = logging.getLogger("yardstick")
137 logger.setLevel(logging.DEBUG)
140 "migrate_to_port": 4444,
142 "qmp_sock_src": "/tmp/qmp-sock-src",
143 "qmp_sock_dst": "/tmp/qmp-sock-dst",
144 "max_down_time": 0.10
150 migrate = QemuMigrate(args, ctx)
154 if __name__ == '__main__': # pragma: no cover