OLD | NEW |
1 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2011 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 """Module containing implementation of an au_worker for virtual machines.""" | 5 """Module containing implementation of an au_worker for virtual machines.""" |
6 | 6 |
7 import os | 7 import os |
8 import threading | |
9 import unittest | 8 import unittest |
10 | 9 |
11 import cros_build_lib as cros_lib | 10 import cros_build_lib as cros_lib |
12 | 11 |
13 import au_worker | 12 import au_worker |
14 | 13 |
15 | 14 |
16 class VMAUWorker(au_worker.AUWorker): | 15 class VMAUWorker(au_worker.AUWorker): |
17 """Test harness for updating virtual machines.""" | 16 """Test harness for updating virtual machines.""" |
18 | 17 |
19 # Class variables used to acquire individual VM variables per test. | |
20 _vm_lock = threading.Lock() | |
21 _next_port = 9222 | |
22 | |
23 def __init__(self, options, test_results_root): | 18 def __init__(self, options, test_results_root): |
24 """Processes vm-specific options.""" | 19 """Processes vm-specific options.""" |
25 au_worker.AUWorker.__init__(self, options, test_results_root) | 20 au_worker.AUWorker.__init__(self, options, test_results_root) |
26 self.graphics_flag = '' | 21 self.graphics_flag = '' |
27 if options.no_graphics: self.graphics_flag = '--no_graphics' | 22 if options.no_graphics: self.graphics_flag = '--no_graphics' |
28 if not self.board: cros_lib.Die('Need board to convert base image to vm.') | 23 if not self.board: cros_lib.Die('Need board to convert base image to vm.') |
29 | 24 |
30 self._AcquireUniquePortAndPidFile() | |
31 self._KillExistingVM(self._kvm_pid_file) | |
32 | |
33 def _KillExistingVM(self, pid_file): | 25 def _KillExistingVM(self, pid_file): |
34 """Kills an existing VM specified by the pid_file.""" | 26 """Kills an existing VM specified by the pid_file.""" |
35 if os.path.exists(pid_file): | 27 if os.path.exists(pid_file): |
36 cros_lib.Warning('Existing %s found. Deleting and killing process' % | 28 cros_lib.Warning('Existing %s found. Deleting and killing process' % |
37 pid_file) | 29 pid_file) |
38 cros_lib.RunCommand(['./cros_stop_vm', '--kvm_pid=%s' % pid_file], | 30 cros_lib.RunCommand(['./cros_stop_vm', '--kvm_pid=%s' % pid_file], |
39 cwd=self.crosutilsbin) | 31 cwd=self.crosutilsbin) |
40 | 32 |
41 assert not os.path.exists(pid_file) | 33 assert not os.path.exists(pid_file) |
42 | 34 |
43 def _AcquireUniquePortAndPidFile(self): | |
44 """Acquires unique ssh port and pid file for VM.""" | |
45 with VMAUWorker._vm_lock: | |
46 self._ssh_port = VMAUWorker._next_port | |
47 self._kvm_pid_file = '/tmp/kvm.%d' % self._ssh_port | |
48 VMAUWorker._next_port += 1 | |
49 | |
50 def CleanUp(self): | 35 def CleanUp(self): |
51 """Stop the vm after a test.""" | 36 """Stop the vm after a test.""" |
52 self._KillExistingVM(self._kvm_pid_file) | 37 self._KillExistingVM(self._kvm_pid_file) |
53 | 38 |
54 def PrepareBase(self, image_path): | 39 def PrepareBase(self, image_path): |
55 """Creates an update-able VM based on base image.""" | 40 """Creates an update-able VM based on base image.""" |
56 self.PrepareVMBase(image_path) | 41 self.PrepareVMBase(image_path) |
57 | 42 |
58 def UpdateImage(self, image_path, src_image_path='', stateful_change='old', | 43 def UpdateImage(self, image_path, src_image_path='', stateful_change='old', |
59 proxy_port='', private_key_path=None): | 44 proxy_port='', private_key_path=None): |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 '--results_dir_root=%s' % log_directory_in_chroot, | 97 '--results_dir_root=%s' % log_directory_in_chroot, |
113 self.verify_suite, | 98 self.verify_suite, |
114 ] | 99 ] |
115 if self.graphics_flag: commandWithArgs.append(self.graphics_flag) | 100 if self.graphics_flag: commandWithArgs.append(self.graphics_flag) |
116 output = cros_lib.RunCommand(commandWithArgs, error_ok=True, | 101 output = cros_lib.RunCommand(commandWithArgs, error_ok=True, |
117 enter_chroot=False, redirect_stdout=True, | 102 enter_chroot=False, redirect_stdout=True, |
118 cwd=self.crosutilsbin) | 103 cwd=self.crosutilsbin) |
119 return self.AssertEnoughTestsPassed(unittest, output, | 104 return self.AssertEnoughTestsPassed(unittest, output, |
120 percent_required_to_pass) | 105 percent_required_to_pass) |
121 | 106 |
OLD | NEW |