| OLD | NEW |
| 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 # | 4 # |
| 5 # Common vm functions for use in crosutils. | 5 # Common vm functions for use in crosutils. |
| 6 | 6 |
| 7 DEFINE_string kvm_pid "" \ | 7 DEFINE_string kvm_pid "" \ |
| 8 "Use this pid file. If it exists and is set, use the vm specified by pid." | 8 "Use this pid file. If it exists and is set, use the vm specified by pid." |
| 9 DEFINE_boolean no_graphics ${FLAGS_FALSE} "Runs the KVM instance silently." | 9 DEFINE_boolean no_graphics ${FLAGS_FALSE} "Runs the KVM instance silently." |
| 10 DEFINE_boolean persist "${FLAGS_FALSE}" "Persist vm." | 10 DEFINE_boolean persist "${FLAGS_FALSE}" "Persist vm." |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 else | 33 else |
| 34 # Let's be safe in case they specified a file that isn't a pid file. | 34 # Let's be safe in case they specified a file that isn't a pid file. |
| 35 echo "File ${KVM_PID_FILE} exists but specified pid doesn't." >&2 | 35 echo "File ${KVM_PID_FILE} exists but specified pid doesn't." >&2 |
| 36 exit 1 | 36 exit 1 |
| 37 fi | 37 fi |
| 38 else | 38 else |
| 39 # No pid specified by PID file. Let's create a VM instance in this case. | 39 # No pid specified by PID file. Let's create a VM instance in this case. |
| 40 echo "Starting a KVM instance" >&2 | 40 echo "Starting a KVM instance" >&2 |
| 41 local nographics="" | 41 local nographics="" |
| 42 local usesnapshot="" | 42 local usesnapshot="" |
| 43 local save_vm_state="" |
| 43 if [ ${FLAGS_no_graphics} -eq ${FLAGS_TRUE} ]; then | 44 if [ ${FLAGS_no_graphics} -eq ${FLAGS_TRUE} ]; then |
| 44 nographics="-nographic -serial none" | 45 nographics="-nographic -serial none" |
| 45 fi | 46 fi |
| 46 if [ -n "${FLAGS_vnc}" ]; then | 47 if [ -n "${FLAGS_vnc}" ]; then |
| 47 nographics="-vnc ${FLAGS_vnc}" | 48 nographics="-vnc ${FLAGS_vnc}" |
| 48 fi | 49 fi |
| 49 | 50 |
| 50 if [ ${FLAGS_snapshot} -eq ${FLAGS_TRUE} ]; then | 51 if [ ${FLAGS_snapshot} -eq ${FLAGS_TRUE} ]; then |
| 51 snapshot="-snapshot" | 52 snapshot="-snapshot" |
| 52 fi | 53 fi |
| 53 | 54 |
| 55 if [ ${FLAGS_save_vm_state} -eq ${FLAGS_TRUE} ]; then |
| 56 # Redirect the QEMU monitor to the guest usb serial port so tests |
| 57 # can trigger a "savevm" command. |
| 58 save_vm_state="-monitor telnet::4555,server,nowait |
| 59 -usbdevice serial::telnet:127.0.0.1:4555" |
| 60 fi |
| 61 |
| 54 sudo kvm -m 1024 \ | 62 sudo kvm -m 1024 \ |
| 55 -vga std \ | 63 -vga std \ |
| 56 -pidfile "${KVM_PID_FILE}" \ | 64 -pidfile "${KVM_PID_FILE}" \ |
| 57 -daemonize \ | 65 -daemonize \ |
| 58 -net nic,model=e1000 \ | 66 -net nic,model=e1000 \ |
| 59 ${nographics} \ | 67 ${nographics} \ |
| 60 ${snapshot} \ | 68 ${snapshot} \ |
| 69 ${save_vm_state} \ |
| 61 -net user,hostfwd=tcp::${FLAGS_ssh_port}-:22 \ | 70 -net user,hostfwd=tcp::${FLAGS_ssh_port}-:22 \ |
| 62 -hda "${1}" | 71 -hda "${1}" |
| 63 | 72 |
| 64 LIVE_VM_IMAGE="${1}" | 73 LIVE_VM_IMAGE="${1}" |
| 65 fi | 74 fi |
| 66 } | 75 } |
| 67 | 76 |
| 68 # Checks to see if we can access the target virtual machine with ssh. | 77 # Checks to see if we can access the target virtual machine with ssh. |
| 69 function ssh_ping() { | 78 function ssh_ping() { |
| 70 "$(dirname $0)"/../ssh_test.sh \ | 79 "$(dirname $0)"/../ssh_test.sh \ |
| (...skipping 28 matching lines...) Expand all Loading... |
| 99 if [ -n "${pid}" ]; then | 108 if [ -n "${pid}" ]; then |
| 100 echo "Killing ${pid}" >&2 | 109 echo "Killing ${pid}" >&2 |
| 101 sudo kill ${pid} | 110 sudo kill ${pid} |
| 102 sudo rm "${KVM_PID_FILE}" | 111 sudo rm "${KVM_PID_FILE}" |
| 103 else | 112 else |
| 104 echo "No kvm pid found to stop." >&2 | 113 echo "No kvm pid found to stop." >&2 |
| 105 return 1 | 114 return 1 |
| 106 fi | 115 fi |
| 107 fi | 116 fi |
| 108 } | 117 } |
| OLD | NEW |