bugfix: tc078 fails in some situations
[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 echo "To check the parameters:"
25 echo "SRC: $src"
26 echo "DST: $dst"
27 echo "DST_IP: $dst_ip"
28 echo "MIGRATE_PORT: $migrate_to_port"
29 echo "DOWN_TIME: $max_down_time"
30
31 do_migrate()
32 {
33         echo "Execution of Live Migration"
34
35         echo "info status" | nc -U $src
36         # with no speed limit
37         echo "migrate_set_speed 0" | nc -U $src
38         # set the expected max downtime
39         echo "migrate_set_downtime ${max_down_time}" | nc -U $src
40         # start live migration
41         echo "migrate -d tcp:${dst_ip}:${migrate_to_port}" | nc -U $src
42         # wait until live migration completed
43         status=""
44         while [  "${status}" == ""  ]
45         do
46                 status=`echo "info migrate" | nc -U $src |grep completed | cut -d: -f2`
47                 echo ${status}
48                 sleep 1;
49         done
50
51         echo "End of Live Migration"
52 }
53
54 output_qemu()
55 {
56         echo "Checking status of Migration"
57         # print detail information
58         echo "info migrate" | nc -U $src
59         echo "quit" | nc -U $src
60         echo "quit" | nc -U $dst
61         sleep 5
62         echo "Migration executed successfully"
63
64 } > $OUTPUT_FILE
65
66 output_json()
67 {
68 totaltime=$(grep "total time" $OUTPUT_FILE | cut -d' ' -f3)
69 downtime=$(grep "downtime" $OUTPUT_FILE | cut -d' ' -f2)
70 setuptime=$(grep "setup" $OUTPUT_FILE | cut -d' ' -f2)
71 echo -e "{ \
72         \"totaltime\":\"$totaltime\", \
73         \"downtime\":\"$downtime\", \
74         \"setuptime\":\"$setuptime\" \
75          }"
76 }
77 # main entry
78 main()
79 {
80     echo "Perform LiveMigration"
81     do_migrate
82     echo "LiveMigration Status"
83     output_qemu
84     echo "LiveMigration JSON output "
85     output_json
86 }
87 main