256
262
self.url = pathlib.Path(self.base_dir).as_uri()
258
264
def get_image(self, release, arch, krel=None):
259
"""Return local path for root image, kernel and initrd, tarball."""
265
"""Return tuple of version info, and paths for root image,
266
kernel, initrd, tarball."""
269
ver_info, ftypes = get_images(
263
270
self.source_url, self.base_dir, release, arch, krel, self.sync)
264
271
root_image_path = ftypes['vmtest.root-image']
265
272
kernel_path = ftypes['boot-kernel']
266
273
initrd_path = ftypes['boot-initrd']
267
274
tarball = ftypes['vmtest.root-tgz']
268
return (root_image_path, kernel_path, initrd_path, tarball)
275
return ver_info, (root_image_path, kernel_path, initrd_path, tarball)
271
278
class TempDir(object):
328
335
# create output disk, mount ro
329
336
logger.debug('Creating output disk')
330
self.output_disk = os.path.join(self.boot, "output_disk.img")
337
self.output_disk = os.path.join(self.boot, OUTPUT_DISK_NAME)
331
338
subprocess.check_call(["qemu-img", "create", "-f", TARGET_IMAGE_FORMAT,
332
339
self.output_disk, "10M"],
333
340
stdout=DEVNULL, stderr=subprocess.STDOUT)
380
390
# Disable sync if env var is set.
381
391
image_store.sync = get_env_var_bool('CURTIN_VMTEST_IMAGE_SYNC', False)
382
392
logger.debug("Image sync = %s", image_store.sync)
383
(boot_img, boot_kernel, boot_initrd, tarball) = image_store.get_image(
384
cls.release, cls.arch, cls.krel)
393
img_verstr, (boot_img, boot_kernel, boot_initrd, tarball) = (
394
image_store.get_image(cls.release, cls.arch, cls.krel))
395
logger.debug("Image %s\n boot=%s\n kernel=%s\n initrd=%s\n"
396
" tarball=%s\n", img_verstr, boot_img, boot_kernel,
397
boot_initrd, tarball)
387
399
cls.td = TempDir(
388
400
name=cls.__name__,
389
401
user_data=generate_user_data(collect_scripts=cls.collect_scripts))
390
logger.info('Using tempdir: {}'.format(cls.td.tmpdir))
402
logger.info('Using tempdir: %s , Image: %s', cls.td.tmpdir,
392
404
cls.install_log = os.path.join(cls.td.logs, 'install-serial.log')
393
405
cls.boot_log = os.path.join(cls.td.logs, 'boot-serial.log')
394
406
logger.debug('Install console log: {}'.format(cls.install_log))
438
450
netdevs.extend(["--netdev=" + DEFAULT_BRIDGE])
440
452
# build disk arguments
441
# --disk source:size:driver:block_size
454
sc = util.load_file(cls.conf_file)
455
storage_config = yaml.load(sc).get('storage', {}).get('config', {})
456
cls.disk_wwns = ["wwn=%s" % x.get('wwn') for x in storage_config
458
cls.disk_serials = ["serial=%s" % x.get('serial')
459
for x in storage_config if 'serial' in x]
461
target_disk = "{}:{}:{}:{}:".format(cls.td.target_disk,
465
if len(cls.disk_wwns):
466
target_disk += cls.disk_wwns[0]
468
if len(cls.disk_serials):
469
target_disk += cls.disk_serials[0]
471
disks.extend(['--disk', target_disk])
473
# --disk source:size:driver:block_size:devopts
443
474
for (disk_no, disk_sz) in enumerate(cls.extra_disks):
444
475
dpath = os.path.join(cls.td.disks, 'extra_disk_%d.img' % disk_no)
446
['--disk', '{}:{}:{}:{}'.format(dpath, disk_sz, "",
447
cls.disk_block_size)])
476
extra_disk = '{}:{}:{}:{}:'.format(dpath, disk_sz,
479
if len(cls.disk_wwns):
480
w_index = disk_no + 1
481
if w_index < len(cls.disk_wwns):
482
extra_disk += cls.disk_wwns[w_index]
484
if len(cls.disk_serials):
485
w_index = disk_no + 1
486
if w_index < len(cls.disk_serials):
487
extra_disk += cls.disk_serials[w_index]
489
disks.extend(['--disk', extra_disk])
449
491
# build nvme disk args if needed
451
492
for (disk_no, disk_sz) in enumerate(cls.nvme_disks):
452
493
dpath = os.path.join(cls.td.disks, 'nvme_disk_%d.img' % disk_no)
454
['--disk', '{}:{}:nvme:{}'.format(dpath, disk_sz,
455
cls.disk_block_size)])
494
nvme_disk = '{}:{}:nvme:{}:{}'.format(dpath, disk_sz,
496
"serial=nvme-%d" % disk_no)
497
disks.extend(['--disk', nvme_disk])
458
500
configs = [cls.conf_file]
477
519
shutil.copy(OVMF_VARS, nvram)
478
520
cmd.extend(["--uefi", nvram])
480
# --disk source:size:driver:block_size
481
target_disk = "{}:{}:{}:{}".format(cls.td.target_disk, "", "",
483
cmd.extend(netdevs + ["--disk", target_disk] +
484
extra_disks + nvme_disks +
523
disks = disks * cls.multipath_num_paths
525
cmd.extend(netdevs + disks +
485
526
[boot_img, "--kernel=%s" % boot_kernel, "--initrd=%s" %
486
527
boot_initrd, "--", "curtin", "-vv", "install"] +
487
528
["--config=%s" % f for f in configs] +
527
568
cls.tearDownClass()
530
# drop the size parameter if present in extra_disks
531
extra_disks = [x if ":" not in x else x.split(':')[0]
532
for x in extra_disks]
533
571
# create --disk params for nvme disks
534
572
bsize_args = "logical_block_size={}".format(cls.disk_block_size)
535
573
bsize_args += ",physical_block_size={}".format(cls.disk_block_size)
536
574
bsize_args += ",min_io_size={}".format(cls.disk_block_size)
537
disk_driver = "virtio-blk"
539
576
target_disks = []
540
for (disk_no, disk) in enumerate([cls.td.target_disk,
541
cls.td.output_disk]):
542
d = '--disk={},driver={},format={},{}'.format(disk, disk_driver,
545
target_disks.extend([d])
577
for (disk_no, disk) in enumerate([cls.td.target_disk]):
578
disk = '--disk={},driver={},format={},{}'.format(
579
disk, cls.disk_driver, TARGET_IMAGE_FORMAT, bsize_args)
580
if len(cls.disk_wwns):
581
disk += ",%s" % cls.disk_wwns[0]
582
if len(cls.disk_serials):
583
disk += ",%s" % cls.disk_serials[0]
585
target_disks.extend([disk])
548
588
for (disk_no, disk_sz) in enumerate(cls.extra_disks):
549
589
dpath = os.path.join(cls.td.disks, 'extra_disk_%d.img' % disk_no)
550
d = '--disk={},driver={},format={},{}'.format(dpath, disk_driver,
553
extra_disks.extend([d])
590
disk = '--disk={},driver={},format={},{}'.format(
591
dpath, cls.disk_driver, TARGET_IMAGE_FORMAT, bsize_args)
592
if len(cls.disk_wwns):
593
w_index = disk_no + 1
594
if w_index < len(cls.disk_wwns):
595
disk += ",%s" % cls.disk_wwns[w_index]
597
if len(cls.disk_serials):
598
w_index = disk_no + 1
599
if w_index < len(cls.disk_serials):
600
disk += ",%s" % cls.disk_serials[w_index]
602
extra_disks.extend([disk])
556
605
disk_driver = 'nvme'
557
606
for (disk_no, disk_sz) in enumerate(cls.nvme_disks):
558
607
dpath = os.path.join(cls.td.disks, 'nvme_disk_%d.img' % disk_no)
559
d = '--disk={},driver={},format={},{}'.format(dpath, disk_driver,
562
nvme_disks.extend([d])
608
disk = '--disk={},driver={},format={},{}'.format(
609
dpath, disk_driver, TARGET_IMAGE_FORMAT, bsize_args)
610
nvme_disks.extend([disk])
613
target_disks = target_disks * cls.multipath_num_paths
614
extra_disks = extra_disks * cls.multipath_num_paths
615
nvme_disks = nvme_disks * cls.multipath_num_paths
617
# output disk is always virtio-blk, with serial of output_disk.img
618
output_disk = '--disk={},driver={},format={},{},{}'.format(
619
cls.td.output_disk, 'virtio-blk',
620
TARGET_IMAGE_FORMAT, bsize_args,
621
'serial=%s' % os.path.basename(cls.td.output_disk))
622
target_disks.extend([output_disk])
564
624
# create xkvm cmd
565
625
cmd = (["tools/xkvm", "-v", dowait] + netdevs +
788
848
self.base_dir = base_dir
790
850
def get_image(self, release, arch, krel=None):
791
"""Return local path for root image, kernel and initrd, tarball."""
851
"""Return tuple of version info, and paths for root image,
852
kernel, initrd, tarball."""
792
853
names = ['psuedo-root-image', 'psuedo-kernel', 'psuedo-initrd',
793
854
'psuedo-tarball']
794
return [os.path.join(self.base_dir, release, arch, f) for f in names]
856
"psuedo-%s %s/hwe-P 20160101" % (release, arch),
857
[os.path.join(self.base_dir, release, arch, f) for f in names])
797
860
class PsuedoVMBaseClass(VMBaseClass):
940
1003
'content': yaml.dump(base_cloudconfig, indent=1)},
941
1004
{'type': 'text/cloud-config', 'content': ssh_keys}]
1006
output_dir = '/mnt/output'
943
1007
output_dir_macro = 'OUTPUT_COLLECT_D'
944
output_dir = '/mnt/output'
945
output_device = '/dev/vdb'
1008
output_device = '/dev/disk/by-id/virtio-%s' % OUTPUT_DISK_NAME
947
1010
collect_prep = textwrap.dedent("mkdir -p " + output_dir)
948
1011
collect_post = textwrap.dedent(