| 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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 """ | 220 """ |
| 221 root_dir = test.bindir | 221 root_dir = test.bindir |
| 222 images_dir = os.path.join(root_dir, 'images') | 222 images_dir = os.path.join(root_dir, 'images') |
| 223 self.deps_dir = os.path.join(root_dir, 'deps') | 223 self.deps_dir = os.path.join(root_dir, 'deps') |
| 224 self.unattended_dir = os.path.join(root_dir, 'unattended') | 224 self.unattended_dir = os.path.join(root_dir, 'unattended') |
| 225 | 225 |
| 226 attributes = ['kernel_args', 'finish_program', 'cdrom_cd1', | 226 attributes = ['kernel_args', 'finish_program', 'cdrom_cd1', |
| 227 'unattended_file', 'medium', 'url', 'kernel', 'initrd', | 227 'unattended_file', 'medium', 'url', 'kernel', 'initrd', |
| 228 'nfs_server', 'nfs_dir', 'install_virtio', 'floppy', | 228 'nfs_server', 'nfs_dir', 'install_virtio', 'floppy', |
| 229 'cdrom_unattended', 'boot_path', 'extra_params', | 229 'cdrom_unattended', 'boot_path', 'extra_params', |
| 230 'qemu_img_binary'] | 230 'qemu_img_binary', 'cdkey', 'virtio_storage_path', |
| 231 'virtio_network_path', 'virtio_network_installer_path'] |
| 231 | 232 |
| 232 for a in attributes: | 233 for a in attributes: |
| 233 setattr(self, a, params.get(a, '')) | 234 setattr(self, a, params.get(a, '')) |
| 234 | 235 |
| 235 if self.install_virtio == 'yes': | 236 if self.install_virtio == 'yes': |
| 236 v_attributes = ['virtio_floppy', 'virtio_storage_path', | 237 v_attributes = ['virtio_floppy', 'virtio_storage_path', |
| 237 'virtio_network_path', 'virtio_oemsetup_id', | 238 'virtio_network_path', 'virtio_oemsetup_id', |
| 238 'virtio_network_installer'] | 239 'virtio_network_installer'] |
| 239 for va in v_attributes: | 240 for va in v_attributes: |
| 240 setattr(self, va, params.get(va, '')) | 241 setattr(self, va, params.get(va, '')) |
| (...skipping 30 matching lines...) Expand all Loading... |
| 271 Replace KVM_TEST_CDKEY (in the unattended file) with the cdkey | 272 Replace KVM_TEST_CDKEY (in the unattended file) with the cdkey |
| 272 provided for this test and replace the KVM_TEST_MEDIUM with | 273 provided for this test and replace the KVM_TEST_MEDIUM with |
| 273 the tree url or nfs address provided for this test. | 274 the tree url or nfs address provided for this test. |
| 274 | 275 |
| 275 @return: Answer file contents | 276 @return: Answer file contents |
| 276 """ | 277 """ |
| 277 error.base_context('Rendering final answer file') | 278 error.base_context('Rendering final answer file') |
| 278 error.context('Reading answer file %s' % self.unattended_file) | 279 error.context('Reading answer file %s' % self.unattended_file) |
| 279 unattended_contents = open(self.unattended_file).read() | 280 unattended_contents = open(self.unattended_file).read() |
| 280 dummy_cdkey_re = r'\bKVM_TEST_CDKEY\b' | 281 dummy_cdkey_re = r'\bKVM_TEST_CDKEY\b' |
| 281 real_cdkey = os.environ.get('KVM_TEST_cdkey') | |
| 282 if re.search(dummy_cdkey_re, unattended_contents): | 282 if re.search(dummy_cdkey_re, unattended_contents): |
| 283 if real_cdkey: | 283 if self.cdkey: |
| 284 unattended_contents = re.sub(dummy_cdkey_re, real_cdkey, | 284 unattended_contents = re.sub(dummy_cdkey_re, self.cdkey, |
| 285 unattended_contents) | 285 unattended_contents) |
| 286 else: | 286 else: |
| 287 print ("WARNING: 'cdkey' required but not specified for " | 287 print ("WARNING: 'cdkey' required but not specified for " |
| 288 "this unattended installation") | 288 "this unattended installation") |
| 289 | 289 |
| 290 dummy_medium_re = r'\bKVM_TEST_MEDIUM\b' | 290 dummy_medium_re = r'\bKVM_TEST_MEDIUM\b' |
| 291 if self.medium == "cdrom": | 291 if self.medium == "cdrom": |
| 292 content = "cdrom" | 292 content = "cdrom" |
| 293 elif self.medium == "url": | 293 elif self.medium == "url": |
| 294 content = "url --url %s" % self.url | 294 content = "url --url %s" % self.url |
| 295 elif self.medium == "nfs": | 295 elif self.medium == "nfs": |
| 296 content = "nfs --server=%s --dir=%s" % (self.nfs_server, | 296 content = "nfs --server=%s --dir=%s" % (self.nfs_server, |
| 297 self.nfs_dir) | 297 self.nfs_dir) |
| 298 else: | 298 else: |
| 299 raise ValueError("Unexpected installation medium %s" % self.url) | 299 raise ValueError("Unexpected installation medium %s" % self.url) |
| 300 | 300 |
| 301 unattended_contents = re.sub(dummy_medium_re, content, | 301 unattended_contents = re.sub(dummy_medium_re, content, |
| 302 unattended_contents) | 302 unattended_contents) |
| 303 | 303 |
| 304 def replace_virtio_key(contents, dummy_re, env): | 304 def replace_virtio_key(contents, dummy_re, attribute_name): |
| 305 """ | 305 """ |
| 306 Replace a virtio dummy string with contents. | 306 Replace a virtio dummy string with contents. |
| 307 | 307 |
| 308 If install_virtio is not set, replace it with a dummy string. | 308 If install_virtio is not set, replace it with a dummy string. |
| 309 | 309 |
| 310 @param contents: Contents of the unattended file | 310 @param contents: Contents of the unattended file |
| 311 @param dummy_re: Regular expression used to search on the. | 311 @param dummy_re: Regular expression used to search on the. |
| 312 unattended file contents. | 312 unattended file contents. |
| 313 @param env: Name of the environment variable. | 313 @param env: Name of the environment variable. |
| 314 """ | 314 """ |
| 315 dummy_path = "C:" | 315 dummy_path = "C:" |
| 316 driver = os.environ.get(env, '') | 316 driver = getattr(self, attribute_name, '') |
| 317 | 317 |
| 318 if re.search(dummy_re, contents): | 318 if re.search(dummy_re, contents): |
| 319 if self.install_virtio == "yes": | 319 if self.install_virtio == "yes": |
| 320 if driver.endswith("msi"): | 320 if driver.endswith("msi"): |
| 321 driver = 'msiexec /passive /package ' + driver | 321 driver = 'msiexec /passive /package ' + driver |
| 322 else: | 322 else: |
| 323 try: | 323 try: |
| 324 # Let's escape windows style paths properly | 324 # Let's escape windows style paths properly |
| 325 drive, path = driver.split(":") | 325 drive, path = driver.split(":") |
| 326 driver = drive + ":" + re.escape(path) | 326 driver = drive + ":" + re.escape(path) |
| 327 except: | 327 except: |
| 328 pass | 328 pass |
| 329 contents = re.sub(dummy_re, driver, contents) | 329 contents = re.sub(dummy_re, driver, contents) |
| 330 else: | 330 else: |
| 331 contents = re.sub(dummy_re, dummy_path, contents) | 331 contents = re.sub(dummy_re, dummy_path, contents) |
| 332 return contents | 332 return contents |
| 333 | 333 |
| 334 vdict = {r'\bKVM_TEST_STORAGE_DRIVER_PATH\b': | 334 vdict = {r'\bKVM_TEST_STORAGE_DRIVER_PATH\b': |
| 335 'KVM_TEST_virtio_storage_path', | 335 'virtio_storage_path', |
| 336 r'\bKVM_TEST_NETWORK_DRIVER_PATH\b': | 336 r'\bKVM_TEST_NETWORK_DRIVER_PATH\b': |
| 337 'KVM_TEST_virtio_network_path', | 337 'virtio_network_path', |
| 338 r'\bKVM_TEST_VIRTIO_NETWORK_INSTALLER\b': | 338 r'\bKVM_TEST_VIRTIO_NETWORK_INSTALLER\b': |
| 339 'KVM_TEST_virtio_network_installer_path'} | 339 'virtio_network_installer_path'} |
| 340 | 340 |
| 341 for vkey in vdict: | 341 for vkey in vdict: |
| 342 unattended_contents = replace_virtio_key(unattended_contents, | 342 unattended_contents = replace_virtio_key( |
| 343 vkey, vdict[vkey]) | 343 contents=unattended_contents, |
| 344 dummy_re=vkey, |
| 345 attribute_name=vdict[vkey]) |
| 344 | 346 |
| 345 logging.debug("Unattended install contents:") | 347 logging.debug("Unattended install contents:") |
| 346 for line in unattended_contents.splitlines(): | 348 for line in unattended_contents.splitlines(): |
| 347 logging.debug(line) | 349 logging.debug(line) |
| 348 return unattended_contents | 350 return unattended_contents |
| 349 | 351 |
| 350 | 352 |
| 351 def setup_boot_disk(self): | 353 def setup_boot_disk(self): |
| 352 answer_contents = self.render_answer_file() | 354 answer_contents = self.render_answer_file() |
| 353 | 355 |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 l_result = utils.run('losetup -a') | 688 l_result = utils.run('losetup -a') |
| 687 if self.loopback and (self.loopback in l_result.stdout): | 689 if self.loopback and (self.loopback in l_result.stdout): |
| 688 try: | 690 try: |
| 689 utils.run("losetup -d %s" % self.loopback) | 691 utils.run("losetup -d %s" % self.loopback) |
| 690 except error.CmdError: | 692 except error.CmdError: |
| 691 logging.error("Failed to liberate loopback %s", self.loopback) | 693 logging.error("Failed to liberate loopback %s", self.loopback) |
| 692 if os.path.islink(self.qcow_file_path): | 694 if os.path.islink(self.qcow_file_path): |
| 693 os.remove(self.qcow_file_path) | 695 os.remove(self.qcow_file_path) |
| 694 if os.path.isfile(self.raw_file_path): | 696 if os.path.isfile(self.raw_file_path): |
| 695 os.remove(self.raw_file_path) | 697 os.remove(self.raw_file_path) |
| OLD | NEW |