def get_dataset(self):
        '''Returns a Filesystem for test purposes. If the ZFS dataset already
        exists, the test is aborted, to prevent accidental destruction of data.
        If a dataset is given, it is stored and destroyed (as well as any
        descendants) after test execution'''
        if not _PERMISSIONS:
            raise SkipTest("Insufficient permissions to run ZFS test")

        test_ids = (self.id()).split(".")

        # Use name of the test case as the name of the function.
        # name of test case is found in the last field of the test id.
        ds_name = _ZFS_TEST_DS % test_ids[-1] + "_%s"

        tried = []
        # try to look for a unique name for the ZFS dataset to be used
        # for the tests.  If can not find a unique name within 15 tries,
        # notify the user, so, they can do some cleanup of their test datasets.
        for x in xrange(15):
            dataset = Filesystem(ds_name % x)
            tried.append(dataset.name)
            if not dataset.exists:
                break
        else:
            raise SkipTest("Could not generate unique ZFS dataset to safely"
                           " test. Tried: %s" % tried)

        dataset.create(dry_run=False)
        self.__dataset = dataset
        return dataset
    def get_dataset(self):
        '''Returns a Filesystem for test purposes. If the ZFS dataset already
        exists, the test is aborted, to prevent accidental destruction of data.
        If a dataset is given, it is stored and destroyed (as well as any
        descendants) after test execution'''
        if not _PERMISSIONS:
            raise SkipTest("Insufficient permissions to run ZFS test")
        
        test_ids = (self.id()).split(".")

        # Use name of the test case as the name of the function.
        # name of test case is found in the last field of the test id.
        ds_name = _ZFS_TEST_DS % test_ids[-1] + "_%s"
      
        tried = []
        # try to look for a unique name for the ZFS dataset to be used
        # for the tests.  If can not find a unique name within 15 tries, 
        # notify the user, so, they can do some cleanup of their test datasets.
        for x in xrange(15):
            dataset = Filesystem(ds_name % x)
            tried.append(dataset.name)
            if not dataset.exists:
                break
        else:
            raise SkipTest("Could not generate unique ZFS dataset to safely"
                           " test. Tried: %s" % tried)
        
        dataset.create(dry_run=False)
        self.__dataset = dataset
        return dataset
示例#3
0
def setup_build_dataset(zpool, fs, resume_checkpoint=None):
    """ Setup the build datasets for use by DC. This includes setting up:
    - top level build dataset
    - a child dataset named 'build_data'
    - a child dataset named 'media'
    - a child dataset named 'logs'
    - a snapshot of the empty build_data dataset - build_data@empty
    """
    eng = InstallEngine.get_instance()
    doc = eng.data_object_cache

    build_data = eng.dataset
    empty_snap = Filesystem(
        os.path.join(zpool.name, fs.name, "build_data@empty"))
    logs = Filesystem(os.path.join(zpool.name, fs.name, "logs"))
    media = Filesystem(os.path.join(zpool.name, fs.name, "media"))

    if fs.action == "create":
        # recursively destroy the Filesystem dataset before creating it
        fs.destroy(dry_run=False, recursive=True)

    fs.create()
    build_data.create()
    logs.create()
    media.create()

    if fs.action == "preserve":
        # check to see if base_dataset/build_data@empty exists.
        if resume_checkpoint is None and empty_snap.exists:
            # rollback the dataset only if DC is not resuming from a specific
            # checkpoint
            build_data.rollback("empty", recursive=True)

    if not empty_snap.exists:
        build_data.snapshot("empty")

    # Now that the base dataset is created, store the mountpoint ZFS calculated
    base_dataset_mp = fs.get("mountpoint")

    # check for the existence of a lock file, bail out if one exists.
    if os.path.exists(base_dataset_mp):
        if os.path.exists(os.path.join(base_dataset_mp, DC_LOCKFILE)):
            raise RuntimeError("distro_const: An instance of distro_const "
                               "is already running in %s" % base_dataset_mp)

    DC_LOGGER.info("Build datasets successfully setup")
    return (base_dataset_mp, build_data.get("mountpoint"),
            logs.get("mountpoint"), media.get("mountpoint"))