Chromium Code Reviews| 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 unittest | 8 import unittest |
| 9 | 9 |
| 10 import cros_build_lib as cros_lib | 10 import cros_build_lib as cros_lib |
| 11 | 11 |
| 12 import au_worker | 12 import au_worker |
| 13 | 13 |
| 14 | 14 |
| 15 class VMAUWorker(au_worker.AUWorker): | 15 class VMAUWorker(au_worker.AUWorker): |
| 16 """Test harness for updating virtual machines.""" | 16 """Test harness for updating virtual machines.""" |
| 17 | 17 |
| 18 def __init__(self, options, test_results_root): | 18 def __init__(self, options, test_results_root): |
| 19 """Processes vm-specific options.""" | 19 """Processes vm-specific options.""" |
| 20 au_worker.AUWorker.__init__(self, options, test_results_root) | 20 au_worker.AUWorker.__init__(self, options, test_results_root) |
| 21 self.graphics_flag = '' | 21 self.graphics_flag = '' |
| 22 if options.no_graphics: self.graphics_flag = '--no_graphics' | 22 if options.no_graphics: self.graphics_flag = '--no_graphics' |
| 23 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.') |
| 24 | 24 |
| 25 def _KillExistingVM(self, pid_file): | 25 def _KillExistingVM(self, pid_file): |
| 26 """Kills an existing VM specified by the pid_file.""" | 26 """Kills an existing VM specified by the pid_file.""" |
| 27 if os.path.exists(pid_file): | 27 if os.path.exists(pid_file): |
| 28 cros_lib.Warning('Existing %s found. Deleting and killing process' % | |
| 29 pid_file) | |
| 30 cros_lib.RunCommand(['./cros_stop_vm', '--kvm_pid=%s' % pid_file], | 28 cros_lib.RunCommand(['./cros_stop_vm', '--kvm_pid=%s' % pid_file], |
| 31 cwd=self.crosutilsbin) | 29 cwd=self.crosutilsbin, print_cmd=False) |
| 32 | 30 |
| 33 assert not os.path.exists(pid_file) | 31 assert not os.path.exists(pid_file) |
| 34 | 32 |
| 35 def CleanUp(self): | 33 def CleanUp(self): |
| 36 """Stop the vm after a test.""" | 34 """Stop the vm after a test.""" |
| 37 self._KillExistingVM(self._kvm_pid_file) | 35 self._KillExistingVM(self._kvm_pid_file) |
| 38 | 36 |
| 39 def PrepareBase(self, image_path): | 37 def PrepareBase(self, image_path): |
| 40 """Creates an update-able VM based on base image.""" | 38 """Creates an update-able VM based on base image.""" |
| 41 self.PrepareVMBase(image_path) | 39 self.PrepareVMBase(image_path) |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 54 '--update_log=%s' % os.path.join(log_directory, 'update_engine.log'), | 52 '--update_log=%s' % os.path.join(log_directory, 'update_engine.log'), |
| 55 '--snapshot', | 53 '--snapshot', |
| 56 self.graphics_flag, | 54 self.graphics_flag, |
| 57 '--persist', | 55 '--persist', |
| 58 '--kvm_pid=%s' % self._kvm_pid_file, | 56 '--kvm_pid=%s' % self._kvm_pid_file, |
| 59 '--ssh_port=%s' % self._ssh_port, | 57 '--ssh_port=%s' % self._ssh_port, |
| 60 stateful_change_flag, | 58 stateful_change_flag, |
| 61 ] | 59 ] |
| 62 self.AppendUpdateFlags(cmd, image_path, src_image_path, proxy_port, | 60 self.AppendUpdateFlags(cmd, image_path, src_image_path, proxy_port, |
| 63 private_key_path) | 61 private_key_path) |
| 62 self.TestInfo(self.GetUpdateMessage(image_path, src_image_path, True, | |
| 63 proxy_port)) | |
| 64 self.RunUpdateCmd(cmd, log_directory) | 64 self.RunUpdateCmd(cmd, log_directory) |
| 65 | 65 |
| 66 def UpdateUsingPayload(self, update_path, stateful_change='old', | 66 def UpdateUsingPayload(self, update_path, stateful_change='old', |
| 67 proxy_port=None): | 67 proxy_port=None): |
| 68 """Updates a vm image using cros_run_vm_update.""" | 68 """Updates a vm image using cros_run_vm_update.""" |
| 69 log_directory = self.GetNextResultsPath('update') | 69 log_directory = self.GetNextResultsPath('update') |
| 70 stateful_change_flag = self.GetStatefulChangeFlag(stateful_change) | 70 stateful_change_flag = self.GetStatefulChangeFlag(stateful_change) |
| 71 cmd = ['%s/cros_run_vm_update' % self.crosutilsbin, | 71 cmd = ['%s/cros_run_vm_update' % self.crosutilsbin, |
| 72 '--payload=%s' % update_path, | 72 '--payload=%s' % update_path, |
| 73 '--vm_image_path=%s' % self.vm_image_path, | 73 '--vm_image_path=%s' % self.vm_image_path, |
| 74 '--update_log=%s' % os.path.join(log_directory, 'update_engine.log'), | 74 '--update_log=%s' % os.path.join(log_directory, 'update_engine.log'), |
| 75 '--snapshot', | 75 '--snapshot', |
| 76 self.graphics_flag, | 76 self.graphics_flag, |
| 77 '--persist', | 77 '--persist', |
| 78 '--kvm_pid=%s' % self._kvm_pid_file, | 78 '--kvm_pid=%s' % self._kvm_pid_file, |
| 79 '--ssh_port=%s' % self._ssh_port, | 79 '--ssh_port=%s' % self._ssh_port, |
| 80 stateful_change_flag, | 80 stateful_change_flag, |
| 81 ] | 81 ] |
| 82 if proxy_port: cmd.append('--proxy_port=%s' % proxy_port) | 82 if proxy_port: cmd.append('--proxy_port=%s' % proxy_port) |
| 83 Info(self.GetUpdateMessage(image_path, src_image_path, True, proxy_port)) | |
|
dgarrett
2011/04/18 23:32:52
Should this be self.TestInfo instead?
| |
| 83 self.RunUpdateCmd(cmd, log_directory) | 84 self.RunUpdateCmd(cmd, log_directory) |
| 84 | 85 |
| 85 def VerifyImage(self, unittest, percent_required_to_pass=100): | 86 def VerifyImage(self, unittest, percent_required_to_pass=100): |
| 86 """Runs vm smoke suite to verify image.""" | 87 """Runs vm smoke suite to verify image.""" |
| 87 log_directory = self.GetNextResultsPath('verify') | 88 log_directory = self.GetNextResultsPath('verify') |
| 88 (_, _, log_directory_in_chroot) = log_directory.rpartition('chroot') | 89 (_, _, log_directory_in_chroot) = log_directory.rpartition('chroot') |
| 89 # image_to_live already verifies lsb-release matching. This is just | 90 # image_to_live already verifies lsb-release matching. This is just |
| 90 # for additional steps. | 91 # for additional steps. |
| 91 commandWithArgs = ['./cros_run_vm_test', | 92 commandWithArgs = ['./cros_run_vm_test', |
| 92 '--image_path=%s' % self.vm_image_path, | 93 '--image_path=%s' % self.vm_image_path, |
| 93 '--snapshot', | 94 '--snapshot', |
| 94 '--persist', | 95 '--persist', |
| 95 '--kvm_pid=%s' % self._kvm_pid_file, | 96 '--kvm_pid=%s' % self._kvm_pid_file, |
| 96 '--ssh_port=%s' % self._ssh_port, | 97 '--ssh_port=%s' % self._ssh_port, |
| 97 '--results_dir_root=%s' % log_directory_in_chroot, | 98 '--results_dir_root=%s' % log_directory_in_chroot, |
| 98 self.verify_suite, | 99 self.verify_suite, |
| 99 ] | 100 ] |
| 100 if self.graphics_flag: commandWithArgs.append(self.graphics_flag) | 101 if self.graphics_flag: commandWithArgs.append(self.graphics_flag) |
| 101 output = cros_lib.RunCommand(commandWithArgs, error_ok=True, | 102 self.TestInfo('Running smoke suite to verify image.') |
| 102 enter_chroot=False, redirect_stdout=True, | 103 output = cros_lib.RunCommand( |
| 103 cwd=self.crosutilsbin) | 104 commandWithArgs, error_ok=True, enter_chroot=False, |
| 105 redirect_stdout=True, redirect_stderr=True, cwd=self.crosutilsbin, | |
| 106 print_cmd=False, combine_stdout_stderr=True) | |
| 104 return self.AssertEnoughTestsPassed(unittest, output, | 107 return self.AssertEnoughTestsPassed(unittest, output, |
| 105 percent_required_to_pass) | 108 percent_required_to_pass) |
| 106 | 109 |
| OLD | NEW |