~chad.smith/curtin/docs-proposed

« back to all changes in this revision

Viewing changes to tests/vmtests/__init__.py

vmtests: add option to tar disk images after test run

vmtests may create a number of disk image files for use, these
are all sparse disks which report a size larger than the actual
space they occupy. In some cases someone copying files may
not be aware of the sparseness and expand the images instead.
Setting CURTIN_VMTEST_TAR_DISKS=1 will trigger vmtest to tar
sparsely the files and write out a .tar file in the same path.

This flag is disabled by default.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
CURTIN_VMTEST_IMAGE_SYNC = os.environ.get("CURTIN_VMTEST_IMAGE_SYNC", "1")
39
39
IMAGE_SYNCS = []
40
40
TARGET_IMAGE_FORMAT = "raw"
 
41
TAR_DISKS = bool(int(os.environ.get("CURTIN_VMTEST_TAR_DISKS", "0")))
41
42
 
42
43
 
43
44
DEFAULT_BRIDGE = os.environ.get("CURTIN_VMTEST_BRIDGE", "user")
938
939
        clean_working_dir(cls.td.tmpdir, success,
939
940
                          keep_pass=KEEP_DATA['pass'],
940
941
                          keep_fail=KEEP_DATA['fail'])
941
 
 
 
942
        if TAR_DISKS:
 
943
            tar_disks(cls.td.tmpdir)
942
944
        cls.cleanIscsiState(success,
943
945
                            keep_pass=KEEP_DATA['pass'],
944
946
                            keep_fail=KEEP_DATA['fail'])
1424
1426
    KEEP_DATA.update(data)
1425
1427
 
1426
1428
 
 
1429
def tar_disks(tmpdir, outfile="disks.tar", diskmatch=".img"):
 
1430
    """ Tar up files in ``tmpdir``/disks that ends with the pattern supplied"""
 
1431
 
 
1432
    disks_dir = os.path.join(tmpdir, "disks")
 
1433
    if os.path.exists(disks_dir):
 
1434
        outfile = os.path.join(disks_dir, outfile)
 
1435
        disks = [os.path.join(disks_dir, disk) for disk in
 
1436
                 os.listdir(disks_dir) if disk.endswith(diskmatch)]
 
1437
        cmd = ["tar", "--create", "--file=%s" % outfile,
 
1438
               "--verbose", "--remove-files", "--sparse"]
 
1439
        cmd.extend(disks)
 
1440
        logger.info('Taring %s disks sparsely to %s', len(disks), outfile)
 
1441
        util.subp(cmd, capture=True)
 
1442
    else:
 
1443
        logger.error('Failed to find "disks" dir under tmpdir: %s', tmpdir)
 
1444
 
 
1445
 
1427
1446
def boot_log_wrap(name, func, cmd, console_log, timeout, purpose):
1428
1447
    logger.debug("%s[%s]: booting with timeout=%s log=%s cmd: %s",
1429
1448
                 name, purpose, timeout, console_log, ' '.join(cmd))