| OLD | NEW |
| 1 """ | 1 """ |
| 2 Library to perform pre/post test setup for KVM autotest. | 2 Library to perform pre/post test setup for KVM autotest. |
| 3 """ | 3 """ |
| 4 import os, shutil, tempfile, re, ConfigParser, glob, inspect | 4 import os, shutil, tempfile, re, ConfigParser, glob, inspect |
| 5 import logging, time | 5 import logging, time |
| 6 from autotest_lib.client.common_lib import error | 6 from autotest_lib.client.common_lib import error |
| 7 from autotest_lib.client.bin import utils | 7 from autotest_lib.client.bin import utils |
| 8 | 8 |
| 9 | 9 |
| 10 @error.context_aware | 10 @error.context_aware |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 """ | 61 """ |
| 62 def __init__(self): | 62 def __init__(self): |
| 63 self.path = None | 63 self.path = None |
| 64 | 64 |
| 65 | 65 |
| 66 def setup_answer_file(self, filename, contents): | 66 def setup_answer_file(self, filename, contents): |
| 67 utils.open_write_close(os.path.join(self.mount, filename), contents) | 67 utils.open_write_close(os.path.join(self.mount, filename), contents) |
| 68 | 68 |
| 69 | 69 |
| 70 def copy_to(self, src): | 70 def copy_to(self, src): |
| 71 logging.debug("Copying %s to disk image mount", src) |
| 71 dst = os.path.join(self.mount, os.path.basename(src)) | 72 dst = os.path.join(self.mount, os.path.basename(src)) |
| 72 if os.path.isdir(src): | 73 if os.path.isdir(src): |
| 73 shutil.copytree(src, dst) | 74 shutil.copytree(src, dst) |
| 74 elif os.path.isfile(src): | 75 elif os.path.isfile(src): |
| 75 shutil.copyfile(src, dst) | 76 shutil.copyfile(src, dst) |
| 76 | 77 |
| 77 | 78 |
| 78 def close(self): | 79 def close(self): |
| 79 os.chmod(self.path, 0755) | 80 os.chmod(self.path, 0755) |
| 80 cleanup(self.mount) | 81 cleanup(self.mount) |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 """ | 221 """ |
| 221 root_dir = test.bindir | 222 root_dir = test.bindir |
| 222 images_dir = os.path.join(root_dir, 'images') | 223 images_dir = os.path.join(root_dir, 'images') |
| 223 self.deps_dir = os.path.join(root_dir, 'deps') | 224 self.deps_dir = os.path.join(root_dir, 'deps') |
| 224 self.unattended_dir = os.path.join(root_dir, 'unattended') | 225 self.unattended_dir = os.path.join(root_dir, 'unattended') |
| 225 | 226 |
| 226 attributes = ['kernel_args', 'finish_program', 'cdrom_cd1', | 227 attributes = ['kernel_args', 'finish_program', 'cdrom_cd1', |
| 227 'unattended_file', 'medium', 'url', 'kernel', 'initrd', | 228 'unattended_file', 'medium', 'url', 'kernel', 'initrd', |
| 228 'nfs_server', 'nfs_dir', 'install_virtio', 'floppy', | 229 'nfs_server', 'nfs_dir', 'install_virtio', 'floppy', |
| 229 'cdrom_unattended', 'boot_path', 'extra_params', | 230 'cdrom_unattended', 'boot_path', 'extra_params', |
| 230 'qemu_img_binary', 'cdkey', 'virtio_storage_path', | 231 'qemu_img_binary', 'cdkey', 'finish_program'] |
| 231 'virtio_network_path', 'virtio_network_installer_path'] | |
| 232 | 232 |
| 233 for a in attributes: | 233 for a in attributes: |
| 234 setattr(self, a, params.get(a, '')) | 234 setattr(self, a, params.get(a, '')) |
| 235 | 235 |
| 236 if self.install_virtio == 'yes': | 236 if self.install_virtio == 'yes': |
| 237 v_attributes = ['virtio_floppy', 'virtio_storage_path', | 237 v_attributes = ['virtio_floppy', 'virtio_storage_path', |
| 238 'virtio_network_path', 'virtio_oemsetup_id', | 238 'virtio_network_path', 'virtio_oemsetup_id', |
| 239 'virtio_network_installer'] | 239 'virtio_network_installer'] |
| 240 for va in v_attributes: | 240 for va in v_attributes: |
| 241 setattr(self, va, params.get(va, '')) | 241 setattr(self, va, params.get(va, '')) |
| 242 | 242 |
| 243 self.tmpdir = test.tmpdir | 243 self.tmpdir = test.tmpdir |
| 244 | 244 |
| 245 if getattr(self, 'unattended_file'): | 245 if getattr(self, 'unattended_file'): |
| 246 self.unattended_file = os.path.join(root_dir, self.unattended_file) | 246 self.unattended_file = os.path.join(root_dir, self.unattended_file) |
| 247 | 247 |
| 248 if getattr(self, 'finish_program'): |
| 249 self.finish_program = os.path.join(root_dir, self.finish_program) |
| 250 |
| 248 if getattr(self, 'qemu_img_binary'): | 251 if getattr(self, 'qemu_img_binary'): |
| 249 if not os.path.isfile(getattr(self, 'qemu_img_binary')): | 252 if not os.path.isfile(getattr(self, 'qemu_img_binary')): |
| 250 self.qemu_img_binary = os.path.join(root_dir, | 253 self.qemu_img_binary = os.path.join(root_dir, |
| 251 self.qemu_img_binary) | 254 self.qemu_img_binary) |
| 252 | 255 |
| 253 if getattr(self, 'cdrom_cd1'): | 256 if getattr(self, 'cdrom_cd1'): |
| 254 self.cdrom_cd1 = os.path.join(root_dir, self.cdrom_cd1) | 257 self.cdrom_cd1 = os.path.join(root_dir, self.cdrom_cd1) |
| 255 self.cdrom_cd1_mount = tempfile.mkdtemp(prefix='cdrom_cd1_', | 258 self.cdrom_cd1_mount = tempfile.mkdtemp(prefix='cdrom_cd1_', |
| 256 dir=self.tmpdir) | 259 dir=self.tmpdir) |
| 257 if self.medium == 'nfs': | 260 if self.medium == 'nfs': |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 l_result = utils.run('losetup -a') | 691 l_result = utils.run('losetup -a') |
| 689 if self.loopback and (self.loopback in l_result.stdout): | 692 if self.loopback and (self.loopback in l_result.stdout): |
| 690 try: | 693 try: |
| 691 utils.run("losetup -d %s" % self.loopback) | 694 utils.run("losetup -d %s" % self.loopback) |
| 692 except error.CmdError: | 695 except error.CmdError: |
| 693 logging.error("Failed to liberate loopback %s", self.loopback) | 696 logging.error("Failed to liberate loopback %s", self.loopback) |
| 694 if os.path.islink(self.qcow_file_path): | 697 if os.path.islink(self.qcow_file_path): |
| 695 os.remove(self.qcow_file_path) | 698 os.remove(self.qcow_file_path) |
| 696 if os.path.isfile(self.raw_file_path): | 699 if os.path.isfile(self.raw_file_path): |
| 697 os.remove(self.raw_file_path) | 700 os.remove(self.raw_file_path) |
| OLD | NEW |