| 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 | 8 import threading |
| 9 import unittest | 9 import unittest |
| 10 | 10 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 """Stop the vm after a test.""" | 51 """Stop the vm after a test.""" |
| 52 self._KillExistingVM(self._kvm_pid_file) | 52 self._KillExistingVM(self._kvm_pid_file) |
| 53 | 53 |
| 54 def PrepareBase(self, image_path): | 54 def PrepareBase(self, image_path): |
| 55 """Creates an update-able VM based on base image.""" | 55 """Creates an update-able VM based on base image.""" |
| 56 self.PrepareVMBase(image_path) | 56 self.PrepareVMBase(image_path) |
| 57 | 57 |
| 58 def UpdateImage(self, image_path, src_image_path='', stateful_change='old', | 58 def UpdateImage(self, image_path, src_image_path='', stateful_change='old', |
| 59 proxy_port='', private_key_path=None): | 59 proxy_port='', private_key_path=None): |
| 60 """Updates VM image with image_path.""" | 60 """Updates VM image with image_path.""" |
| 61 log_directory = self.GetNextResultsPath('update') |
| 61 stateful_change_flag = self.GetStatefulChangeFlag(stateful_change) | 62 stateful_change_flag = self.GetStatefulChangeFlag(stateful_change) |
| 62 if src_image_path and self._first_update: | 63 if src_image_path and self._first_update: |
| 63 src_image_path = self.vm_image_path | 64 src_image_path = self.vm_image_path |
| 64 self._first_update = False | 65 self._first_update = False |
| 65 | 66 |
| 66 cmd = ['%s/cros_run_vm_update' % self.crosutilsbin, | 67 cmd = ['%s/cros_run_vm_update' % self.crosutilsbin, |
| 67 '--vm_image_path=%s' % self.vm_image_path, | 68 '--vm_image_path=%s' % self.vm_image_path, |
| 69 '--update_log=%s' % os.path.join(log_directory, 'update_engine.log'), |
| 68 '--snapshot', | 70 '--snapshot', |
| 69 self.graphics_flag, | 71 self.graphics_flag, |
| 70 '--persist', | 72 '--persist', |
| 71 '--kvm_pid=%s' % self._kvm_pid_file, | 73 '--kvm_pid=%s' % self._kvm_pid_file, |
| 72 '--ssh_port=%s' % self._ssh_port, | 74 '--ssh_port=%s' % self._ssh_port, |
| 73 stateful_change_flag, | 75 stateful_change_flag, |
| 74 ] | 76 ] |
| 75 self.AppendUpdateFlags(cmd, image_path, src_image_path, proxy_port, | 77 self.AppendUpdateFlags(cmd, image_path, src_image_path, proxy_port, |
| 76 private_key_path) | 78 private_key_path) |
| 77 self.RunUpdateCmd(cmd) | 79 self.RunUpdateCmd(cmd, log_directory) |
| 78 | 80 |
| 79 def UpdateUsingPayload(self, update_path, stateful_change='old', | 81 def UpdateUsingPayload(self, update_path, stateful_change='old', |
| 80 proxy_port=None): | 82 proxy_port=None): |
| 81 """Updates a vm image using cros_run_vm_update.""" | 83 """Updates a vm image using cros_run_vm_update.""" |
| 84 log_directory = self.GetNextResultsPath('update') |
| 82 stateful_change_flag = self.GetStatefulChangeFlag(stateful_change) | 85 stateful_change_flag = self.GetStatefulChangeFlag(stateful_change) |
| 83 cmd = ['%s/cros_run_vm_update' % self.crosutilsbin, | 86 cmd = ['%s/cros_run_vm_update' % self.crosutilsbin, |
| 84 '--payload=%s' % update_path, | 87 '--payload=%s' % update_path, |
| 85 '--vm_image_path=%s' % self.vm_image_path, | 88 '--vm_image_path=%s' % self.vm_image_path, |
| 89 '--update_log=%s' % os.path.join(log_directory, 'update_engine.log'), |
| 86 '--snapshot', | 90 '--snapshot', |
| 87 self.graphics_flag, | 91 self.graphics_flag, |
| 88 '--persist', | 92 '--persist', |
| 89 '--kvm_pid=%s' % self._kvm_pid_file, | 93 '--kvm_pid=%s' % self._kvm_pid_file, |
| 90 '--ssh_port=%s' % self._ssh_port, | 94 '--ssh_port=%s' % self._ssh_port, |
| 91 stateful_change_flag, | 95 stateful_change_flag, |
| 92 ] | 96 ] |
| 93 if proxy_port: cmd.append('--proxy_port=%s' % proxy_port) | 97 if proxy_port: cmd.append('--proxy_port=%s' % proxy_port) |
| 94 self.RunUpdateCmd(cmd) | 98 self.RunUpdateCmd(cmd, log_directory) |
| 95 | 99 |
| 96 def VerifyImage(self, unittest, percent_required_to_pass=100): | 100 def VerifyImage(self, unittest, percent_required_to_pass=100): |
| 97 """Runs vm smoke suite to verify image.""" | 101 """Runs vm smoke suite to verify image.""" |
| 98 test_directory = self.GetNextResultsPath('verify') | 102 log_directory = self.GetNextResultsPath('verify') |
| 103 (_, _, log_directory_in_chroot) = log_directory.rpartition('chroot') |
| 99 # image_to_live already verifies lsb-release matching. This is just | 104 # image_to_live already verifies lsb-release matching. This is just |
| 100 # for additional steps. | 105 # for additional steps. |
| 101 commandWithArgs = ['%s/cros_run_vm_test' % self.crosutilsbin, | 106 commandWithArgs = ['%s/cros_run_vm_test' % self.crosutilsbin, |
| 102 '--image_path=%s' % self.vm_image_path, | 107 '--image_path=%s' % self.vm_image_path, |
| 103 '--snapshot', | 108 '--snapshot', |
| 104 '--persist', | 109 '--persist', |
| 105 '--kvm_pid=%s' % self._kvm_pid_file, | 110 '--kvm_pid=%s' % self._kvm_pid_file, |
| 106 '--ssh_port=%s' % self._ssh_port, | 111 '--ssh_port=%s' % self._ssh_port, |
| 107 '--results_dir_root=%s' % test_directory, | 112 '--results_dir_root=%s' % log_directory_in_chroot, |
| 108 self.verify_suite, | 113 self.verify_suite, |
| 109 ] | 114 ] |
| 110 if self.graphics_flag: commandWithArgs.append(self.graphics_flag) | 115 if self.graphics_flag: commandWithArgs.append(self.graphics_flag) |
| 111 output = cros_lib.RunCommand(commandWithArgs, error_ok=True, | 116 output = cros_lib.RunCommand(commandWithArgs, error_ok=True, |
| 112 enter_chroot=False, redirect_stdout=True) | 117 enter_chroot=False, redirect_stdout=True) |
| 113 return self.AssertEnoughTestsPassed(unittest, output, | 118 return self.AssertEnoughTestsPassed(unittest, output, |
| 114 percent_required_to_pass) | 119 percent_required_to_pass) |
| 115 | 120 |
| OLD | NEW |