Generate pod.yaml from current context
[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 "info status" | nc -U $src
27         # with no speed limit
28         echo "migrate_set_speed 0" |nc -U $src
29         # set the expected max downtime
30         echo "migrate_set_downtime ${max_down_time}" |nc -U $src
31         # start live migration
32         echo "migrate -d tcp:${dst_ip}:$migrate_to_port" |nc -U $src
33         # wait until live migration completed
34         status=""
35         while [  "${status}" == ""  ]
36         do
37                 status=`echo "info migrate" | nc -U $src |grep completed | cut -d: -f2`
38                 echo ${status}
39                 sleep 1;
40         done
41 } >/dev/null
42
43 output_qemu()
44 {
45         # print detail information
46         echo "info migrate" | nc -U $src
47         echo "quit" | nc -U $src
48         echo "quit" | nc -u $dst
49         sleep 5
50         echo "Migration executed successfully"
51
52 } > $OUTPUT_FILE
53
54 output_json()
55 {
56 totaltime=$(grep "total time" $OUTPUT_FILE | cut -d' ' -f3)
57 downtime=$(grep "downtime" $OUTPUT_FILE | cut -d' ' -f2)
58 setuptime=$(grep "setup" $OUTPUT_FILE | cut -d' ' -f2)
59 echo -e "{ \
60         \"totaltime\":\"$totaltime\", \
61         \"downtime\":\"$downtime\", \
62         \"setuptime\":\"$setuptime\" \
63          }"
64 }
65 # main entry
66 main()
67 {
68     do_migrate
69     output_qemu
70     output_json
71 }
72 main