def _test_logging(context, destination): """Test whether events are logged locally. 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 dnf.exceptions.DownloadError: if a testing root cannot be configured :raises exceptions.OSError: if DNF cannot be configured or if the executable cannot be executed :raises subprocess.CalledProcessError: if executable fails :raises exceptions.AssertionError: if the test fails """ def log_files(dirname): """Iter over the DNF log files in a directory. :param dirname: a name of the directory :type dirname: unicode :returns: names of the files :rtype: generator[unicode] """ basenames = [] with _suppress_enoent(): basenames = os.listdir(dirname) for basename in basenames: filename = os.path.join(dirname, basename) if basename.startswith('dnf') and os.path.isfile(filename): yield filename with dnf.Base() as base: logdn = chrooteddn = base.conf.logdir if context.installroot_option: chrooteddn = os.path.join( context.installroot_option, logdn.lstrip(os.path.sep)) _prepare_installroot( context.installroot_option, context.releasever_option or '19') for filename in log_files(logdn): os.remove(filename) for filename in log_files(chrooteddn): os.remove(filename) environment.run_dnf_clean_metadata( context.config_option, context.installroot_option, context.releasever_option, quiet=True, assumeyes=True) logged = any(log_files(logdn)) if destination == 'locally': assert logged, 'nothing logged in the host' elif destination == 'in the guest': assert any(log_files(chrooteddn)), 'nothing logged in the guest' assert not logged, 'something logged in the host' else: raise NotImplementedError('destination not supported')
def _test_plugins_conf(context, path): """Test whether the plugins configuration path is set correctly. The "dnf" executable must be available. :param context: the context in which the function is called :type context: behave.runner.Context :param path: the expected path :type path: unicode :raises exceptions.OSError: if DNF cannot be configured or if the executable cannot be executed :raises exceptions.IOError: if DNF cannot be configured :raises subprocess.CalledProcessError: if the executable fails :raises exceptions.AssertionError: if the test fails """ with dnf.Base() as base: plugindn = base.conf.pluginpath[0] confdn = base.conf.pluginconfpath[0] if path != "the host's default" and path.startswith("host's "): confdn = path[7:] with environment.TempResourceCopy('dnf-extra-tests.py', plugindn), \ environment.TempResourceCopy('dnf-extra-tests.conf', confdn): expected = b"dnf-extra-tests plugin's option is configured." output = environment.run_dnf_clean_metadata( context.config_option, context.installroot_option, context.releasever_option, quiet=True, assumeyes=True) assert expected in output, 'path not set'
def _test_plugins(context, path): """Test whether particular plugins are being loaded. The "dnf" executable must be available. :param context: the context in which the function is called :type context: behave.runner.Context :param path: a name of the plugins directory :type path: unicode :raises exceptions.OSError: if DNF cannot be configured or if the executable cannot be executed :raises exceptions.IOError: if DNF cannot be configured :raises subprocess.CalledProcessError: if the executable fails :raises exceptions.AssertionError: if the test fails """ with dnf.Base() as base: plugindn = base.conf.pluginpath[0] if path != "the host's default path" and path.startswith("host's "): plugindn = path[7:] with environment.TempResourceCopy('dnf-extra-tests.py', plugindn): expected = b'An output of the dnf-extra-tests plugin: This is unique.' output = environment.run_dnf_clean_metadata( context.config_option, context.installroot_option, context.releasever_option, quiet=True, assumeyes=True) assert expected in output, 'plugin not loaded'