| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 | 2 |
| 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 import optparse | 7 import optparse |
| 8 import os | 8 import os |
| 9 import sys | 9 import sys |
| 10 import unittest | 10 import unittest |
| 11 | 11 |
| 12 sys.path.append(os.path.join(os.path.dirname(__file__), '../lib')) | 12 sys.path.append(os.path.join(os.path.dirname(__file__), '../lib')) |
| 13 from cros_build_lib import RunCommand, Info, Warning | 13 from cros_build_lib import RunCommand, Info, Warning, ReinterpretPathForChroot |
| 14 | 14 |
| 15 _KVM_PID_FILE = '/tmp/harness_pid' | 15 _KVM_PID_FILE = '/tmp/harness_pid' |
| 16 _SCRIPTS_DIR = os.path.join(os.path.dirname(__file__), '..') | 16 _SCRIPTS_DIR = os.path.join(os.path.dirname(__file__), '..') |
| 17 _FULL_VDISK_SIZE = 6072 | 17 _FULL_VDISK_SIZE = 6072 |
| 18 _FULL_STATEFULFS_SIZE = 2048 | 18 _FULL_STATEFULFS_SIZE = 2048 |
| 19 | 19 |
| 20 global base_image_path | 20 global base_image_path |
| 21 global board |
| 21 global target_image_path | 22 global target_image_path |
| 22 | 23 |
| 23 _VERIFY_SUITE = 'suite_Smoke' | 24 _VERIFY_SUITE = 'suite_Smoke' |
| 24 | 25 |
| 25 class AUTest(object): | 26 class AUTest(object): |
| 26 """Abstract interface that defines an Auto Update test.""" | 27 """Abstract interface that defines an Auto Update test.""" |
| 27 | 28 |
| 28 def PrepareBase(self): | 29 def PrepareBase(self): |
| 29 """Prepares target with base_image_path.""" | 30 """Prepares target with base_image_path.""" |
| 30 pass | 31 pass |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 | 100 |
| 100 def PrepareBase(self): | 101 def PrepareBase(self): |
| 101 """Creates an update-able VM based on base image.""" | 102 """Creates an update-able VM based on base image.""" |
| 102 | 103 |
| 103 self.vm_image_path = ('%s/chromiumos_qemu_image.bin' % os.path.dirname( | 104 self.vm_image_path = ('%s/chromiumos_qemu_image.bin' % os.path.dirname( |
| 104 base_image_path)) | 105 base_image_path)) |
| 105 if not os.path.exists(self.vm_image_path): | 106 if not os.path.exists(self.vm_image_path): |
| 106 Info('Qemu image not found, creating one.') | 107 Info('Qemu image not found, creating one.') |
| 107 RunCommand(['%s/image_to_vm.sh' % _SCRIPTS_DIR, | 108 RunCommand(['%s/image_to_vm.sh' % _SCRIPTS_DIR, |
| 108 '--full', | 109 '--full', |
| 109 '--from %s' % os.path.dirname(base_image_path), | 110 '--from %s' % ReinterpretPathForChroot( |
| 111 os.path.dirname(base_image_path)), |
| 110 '--vdisk_size %s' % _FULL_VDISK_SIZE, | 112 '--vdisk_size %s' % _FULL_VDISK_SIZE, |
| 111 '--statefulfs_size %s' % _FULL_STATEFULFS_SIZE, | 113 '--statefulfs_size %s' % _FULL_STATEFULFS_SIZE, |
| 114 '--board %s' % board, |
| 112 '--test_image'], enter_chroot=True) | 115 '--test_image'], enter_chroot=True) |
| 113 else: | 116 else: |
| 114 Info('Using existing VM image') | 117 Info('Using existing VM image') |
| 115 | 118 |
| 116 self.assertTrue(os.path.exists(self.vm_image_path)) | 119 self.assertTrue(os.path.exists(self.vm_image_path)) |
| 117 | 120 |
| 118 def UpdateImage(self, image_path, stateful_change='old'): | 121 def UpdateImage(self, image_path, stateful_change='old'): |
| 119 """Updates VM image with image_path.""" | 122 """Updates VM image with image_path.""" |
| 120 | 123 |
| 121 stateful_change_flag = '' | 124 stateful_change_flag = '' |
| (...skipping 24 matching lines...) Expand all Loading... |
| 146 '--test_case=%s' % _VERIFY_SUITE, | 149 '--test_case=%s' % _VERIFY_SUITE, |
| 147 ], error_ok=True, enter_chroot=False) | 150 ], error_ok=True, enter_chroot=False) |
| 148 | 151 |
| 149 | 152 |
| 150 if __name__ == '__main__': | 153 if __name__ == '__main__': |
| 151 parser = optparse.OptionParser() | 154 parser = optparse.OptionParser() |
| 152 parser.add_option('-b', '--base_image', | 155 parser.add_option('-b', '--base_image', |
| 153 help='path to the base image.') | 156 help='path to the base image.') |
| 154 parser.add_option('-t', '--target_image', | 157 parser.add_option('-t', '--target_image', |
| 155 help='path to the target image') | 158 help='path to the target image') |
| 159 parser.add_option('-r', '--board', |
| 160 help='board for the images') |
| 156 # Set the usage to include flags. | 161 # Set the usage to include flags. |
| 157 parser.set_usage(parser.format_help()) | 162 parser.set_usage(parser.format_help()) |
| 158 # Parse existing sys.argv so we can pass rest to unittest.main. | 163 # Parse existing sys.argv so we can pass rest to unittest.main. |
| 159 (options, sys.argv) = parser.parse_args(sys.argv) | 164 (options, sys.argv) = parser.parse_args(sys.argv) |
| 160 | 165 |
| 161 base_image_path = options.base_image | 166 base_image_path = options.base_image |
| 162 target_image_path = options.target_image | 167 target_image_path = options.target_image |
| 168 board = options.board |
| 163 | 169 |
| 164 if not base_image_path: | 170 if not base_image_path: |
| 165 parser.error('Need path to base image for vm.') | 171 parser.error('Need path to base image for vm.') |
| 166 | 172 |
| 167 if not target_image_path: | 173 if not target_image_path: |
| 168 parser.error('Need path to target image to update with.') | 174 parser.error('Need path to target image to update with.') |
| 169 | 175 |
| 176 if not board: |
| 177 parser.error('Need board to convert base image to vm.') |
| 178 |
| 170 unittest.main() | 179 unittest.main() |
| OLD | NEW |