OLD | NEW |
1 # | 1 # |
2 # Copyright 2008 Google Inc. Released under the GPL v2 | 2 # Copyright 2008 Google Inc. Released under the GPL v2 |
3 | 3 |
4 import os, pickle, random, re, resource, select, shutil, signal, StringIO | 4 import os, pickle, random, re, resource, select, shutil, signal, StringIO |
5 import socket, struct, subprocess, sys, time, textwrap, urlparse | 5 import socket, struct, subprocess, sys, time, textwrap, urlparse, platform |
6 import warnings, smtplib, logging, urllib2 | 6 import warnings, smtplib, logging, urllib2 |
7 from threading import Thread, Event | 7 from threading import Thread, Event |
8 try: | 8 try: |
9 import hashlib | 9 import hashlib |
10 except ImportError: | 10 except ImportError: |
11 import md5, sha | 11 import md5, sha |
12 from autotest_lib.client.common_lib import error, logging_manager | 12 from autotest_lib.client.common_lib import error, logging_manager |
13 | 13 |
14 def deprecated(func): | 14 def deprecated(func): |
15 """This is a decorator which can be used to mark functions as deprecated. | 15 """This is a decorator which can be used to mark functions as deprecated. |
(...skipping 1685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1701 s.close() | 1701 s.close() |
1702 | 1702 |
1703 # On the 2.6 kernel, calling try_bind() on UDP socket returns the | 1703 # On the 2.6 kernel, calling try_bind() on UDP socket returns the |
1704 # same port over and over. So always try TCP first. | 1704 # same port over and over. So always try TCP first. |
1705 while True: | 1705 while True: |
1706 # Ask the OS for an unused port. | 1706 # Ask the OS for an unused port. |
1707 port = try_bind(0, socket.SOCK_STREAM, socket.IPPROTO_TCP) | 1707 port = try_bind(0, socket.SOCK_STREAM, socket.IPPROTO_TCP) |
1708 # Check if this port is unused on the other protocol. | 1708 # Check if this port is unused on the other protocol. |
1709 if port and try_bind(port, socket.SOCK_DGRAM, socket.IPPROTO_UDP): | 1709 if port and try_bind(port, socket.SOCK_DGRAM, socket.IPPROTO_UDP): |
1710 return port | 1710 return port |
| 1711 |
| 1712 |
| 1713 def save_vm_state(checkpoint): |
| 1714 """Saves the current state of the virtual machine |
| 1715 |
| 1716 This function is a NOOP if the test is not running under a virtual machine |
| 1717 with the USB serial port redirected. |
| 1718 |
| 1719 Arguments: |
| 1720 checkpoint - Name used to identify this state |
| 1721 |
| 1722 Returns: |
| 1723 None |
| 1724 """ |
| 1725 # The QEMU monitor has been redirected to the guest serial port located at |
| 1726 # /dev/ttyUSB0. To save the state of the VM, we just send the 'savevm' |
| 1727 # command to the serial port. |
| 1728 proc = platform.processor() |
| 1729 if proc.find('QEMU') >= 0 and os.path.exists('/dev/ttyUSB0'): |
| 1730 logging.info('Saving VM state "%s"' % checkpoint) |
| 1731 serial = open('/dev/ttyUSB0', 'w') |
| 1732 serial.write("savevm %s\r\n" % checkpoint) |
| 1733 logging.info('Done saving VM state "%s"' % checkpoint) |
OLD | NEW |