Merge "Add support for restarting a service"
[yardstick.git] / yardstick / benchmark / scenarios / compute / qemu_migrate_benchmark.bash
1 #!/bin/bash
2
3 #############################################################################
4 #Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
11
12 set -e
13
14 # Commandline arguments
15
16 src=$2
17 dst=$3
18 dst_ip=$4
19 migrate_to_port=$5
20 max_down_time=$6
21
22 OUTPUT_FILE=/tmp/output-qemu.log
23
24 do_migrate()
25 {
26         echo "Execution of Live Migration"
27
28         echo "info status" | nc -U $src
29         # with no speed limit
30         echo "migrate_set_speed 0" | nc -U $src
31         # set the expected max downtime
32         echo "migrate_set_downtime ${max_down_time}" | nc -U $src
33         # start live migration
34         echo "migrate -d tcp:${dst_ip}:${migrate_to_port}" | nc -U $src
35         # wait until live migration completed
36         status=""
37         while [  "${status}" == ""  ]
38         do
39                 status=`echo "info migrate" | nc -U $src |grep completed | cut -d: -f2`
40                 echo ${status}
41                 sleep 1;
42         done
43
44         echo "End of Live Migration"
45
46 } > /dev/null
47
48 output_qemu()
49 {
50         echo "Checking status of Migration"
51         # print detail information
52         echo "info migrate" | nc -U $src
53         echo "quit" | nc -U $src
54         echo "quit" | nc -U $dst
55         sleep 5
56         echo "Migration executed successfully"
57
58 } > $OUTPUT_FILE
59
60 output_json()
61 {
62 totaltime=$(grep "total time" $OUTPUT_FILE | cut -d' ' -f3)
63 downtime=$(grep "downtime" $OUTPUT_FILE | cut -d' ' -f2)
64 setuptime=$(grep "setup" $OUTPUT_FILE | cut -d' ' -f2)
65 echo -e "{ \
66         \"totaltime\":\"$totaltime\", \
67         \"downtime\":\"$downtime\", \
68         \"setuptime\":\"$setuptime\" \
69          }"
70 }
71
72 # main entry
73 main()
74 {
75     # Perform LiveMigration
76     do_migrate
77
78     # LiveMigration Status
79     output_qemu
80
81     # LiveMigration JSON output
82     output_json
83 }
84
85 main