Example #1
0
def _test_tracking(context, destination):
    """Test whether tracking information is stored in the destination.

    The "dnf" executable must be available.

    :param context: the context in which the function is called
    :type context: behave.runner.Context
    :param destination: the expected destination
    :type destination: unicode
    :raises exceptions.OSError: if DNF cannot be configured
    :raises shutil.Error: if DNF cannot be configured
    :raises exceptions.OSError: if the executable cannot be executed
    :raises subprocess.CalledProcessError: if the executable fails
    :raises exceptions.AssertionError: if the test fails

    """
    with dnf.Base() as base:
        releasever = context.releasever_option or dnf.rpm.detect_releasever(
            base.conf.installroot)
        persistdn = base.conf.persistdir
    guest_destination = 'in the guest'
    if destination not in {'locally', guest_destination}:
        raise NotImplementedError('destination not supported')
    backupdn = tempfile.mkdtemp()
    backuppersistdn = os.path.join(backupdn, 'persist')
    try:
        with _suppress_enoent():
            shutil.copytree(persistdn, backuppersistdn)
        with _suppress_enoent():
            shutil.rmtree(persistdn)
        environment.run_dnf(
            ['group', 'install', 'Books and Guides'], context.config_option,
            context.installroot_option, releasever, quiet=True, assumeyes=True)
        content = []
        with _suppress_enoent():
            content = os.listdir(persistdn)
        if destination == guest_destination:
            assert not content, 'something stored in the host'
        else:
            assert content, 'nothing stored in the host'
    finally:
        with _suppress_enoent():
            shutil.rmtree(persistdn)
        with _suppress_enoent():
            shutil.copytree(backuppersistdn, persistdn)
        shutil.rmtree(backupdn)
    if destination == guest_destination:
        if not context.installroot_option:
            raise ValueError('guest path not set')
        chrooteddn = os.path.join(
            context.installroot_option, persistdn.lstrip(os.path.sep))
        assert os.listdir(chrooteddn), 'nothing stored in the guest'
Example #2
0
def _run_repoquery(
        configfn=None, repo=None, root=None, releasever=None, quiet=False):
    """Run the DNF's repoquery plugin from command line.

    The "dnf" executable and its "repoquery" plugin must be available.

    :param configfn: a name of a configuration file
    :type configfn: unicode | None
    :param repo: a value of the --repo option
    :type repo: unicode | None
    :param root: a value of the --installroot option
    :type root: unicode | None
    :param releasever: a value of the --releasever option
    :type releasever: unicode | None
    :param quiet: set the --queit option
    :type quiet: bool
    :returns: the output of the command
    :rtype: str
    :raises exceptions.OSError: if the executable cannot be executed
    :raises subprocess.CalledProcessError: if executable or the plugin
       fails

    """
    args = ['repoquery']
    if repo:
        args.insert(1, repo)
        args.insert(1, '--repoid')
    return environment.run_dnf(args, configfn, root, releasever, quiet)
Example #3
0
def _run_dnf_remove(  # pylint: disable=too-many-arguments
        specs, configfn=None, root=None, releasever=None, quiet=False,
        assumeyes=False, disablerepo=None, enablerepo=None):
    """Run DNF's remove command from command line.

    The "dnf" executable must be available.

    :param specs: specifications of the packages to be removed
    :type specs: list[unicode]
    :param configfn: a name of a configuration file
    :type configfn: unicode | None
    :param root: a value of the --installroot option
    :type root: unicode | None
    :param releasever: a value of the --releasever option
    :type releasever: unicode | None
    :param quiet: set the --quiet option
    :type quiet: bool
    :param assumeyes: set the --assumeyes option
    :type assumeyes: bool
    :param disablerepo: a pattern matching the repositories to be
        disabled
    :type disablerepo: unicode | None
    :param enablerepo: a pattern matching the repositories to be
        enabled
    :type enablerepo: unicode | None
    :returns: the output of the command
    :rtype: str
    :raises exceptions.OSError: if the executable cannot be executed
    :raises subprocess.CalledProcessError: if the executable fails

    """
    return environment.run_dnf(
        ['remove'] + specs, configfn, root, releasever, quiet, assumeyes,
        disablerepo, enablerepo)
Example #4
0
def _test_caching(context, destination):
    """Test whether metadata is cached in the destination.

    The "dnf" executable must be available.

    :param context: the context in which the function is called
    :type context: behave.runner.Context
    :param destination: a description of the expected destination
    :type destination: unicode
    :raises exceptions.OSError: if DNF cannot be configured or if the
       executable cannot be executed
    :raises subprocess.CalledProcessError: if the executable fails
    :raises exceptions.AssertionError: if the test fails

    """
    with dnf.Base() as base:
        cachedir = chrooteddn = base.conf.cachedir
    if context.installroot_option:
        chrooteddn = os.path.join(
            context.installroot_option, cachedir.lstrip(os.path.sep))
        _prepare_installroot(
            context.installroot_option, context.releasever_option or '19')
    with _suppress_enoent():
        shutil.rmtree(cachedir)
    with _suppress_enoent():
        shutil.rmtree(chrooteddn)
    environment.run_dnf(
        ['makecache'], context.config_option, context.installroot_option,
        context.releasever_option, quiet=True, assumeyes=True)
    content = []
    with _suppress_enoent():
        content = os.listdir(cachedir)
    if destination == 'locally':
        assert content, 'nothing cached in the host'
    elif destination == 'in the guest':
        assert os.listdir(chrooteddn), 'nothing cached in the guest'
        assert not content, 'something cached in the host'
    else:
        raise NotImplementedError('destination not supported')