示例#1
0
def copy_file_to(context, source, destination):
    source = source.format(context=context)
    destination = prepend_installroot(context, destination)
    ensure_directory_exists(os.path.dirname(destination))
    # If we dont specify destination with name keep the name of source file
    if (os.path.isdir(destination)):
        destination = os.path.join(destination, os.path.basename(source))
    copy_file(source, destination)
示例#2
0
def file_does_not_contain(context, filepath):
    regexp_lines = context.text.split('\n')
    full_path = prepend_installroot(context, filepath)
    ensure_directory_exists(os.path.dirname(full_path))
    read_str = read_file_contents(full_path)
    for line in regexp_lines:
        if re.search(line, read_str):
            print("line: " + line + " found")
            raise AssertionError("File %s contains: \n%s" % (filepath, read_str))
    return
示例#3
0
def step_configure_new_repository_in(context, repo, path):
    """
    Creates a new repository config at `path` with the default values overriden
    with what is in the context table.
    """
    check_context_table(context, ["key", "value"])
    path = path.format(context=context)
    ensure_directory_exists(path)

    write_repo_config(context, repo, repo_config(repo, dict(context.table)),
                      path)
示例#4
0
def write_config(context):
    config_dir = os.path.join(context.dnf.installroot, "etc/dnf")
    ensure_directory_exists(config_dir)

    conf_text = ""
    # sort and put [main] first
    for section, values in \
            sorted(list(context.dnf.config.items()), key=lambda i: "" if i[0] == "[main]" else i[0]):
        conf_text += "%s\n" % section
        for k, v in values.items():
            if v != "":
                conf_text += "%s=%s\n" % (k, v.format(context=context))

    create_file_with_contents(os.path.join(config_dir, "dnf.conf"), conf_text)
示例#5
0
    def __init__(self, userdata, force_installroot=False, no_installroot=False):
        self._scenario_data = {}

        self.repos = {}
        self.ports = {}

        self.tempdir = tempfile.mkdtemp(prefix="dnf_ci_tempdir_")
        # some tests need to be run inside the installroot, it can be forced
        # per scenario by using @force_installroot decorator
        if no_installroot:
            self.installroot = "/"
            # never delete root
            self.delete_installroot = False
        elif "installroot" in userdata and not force_installroot:
            self.installroot = userdata["installroot"]
            # never delete user defined installroot - this allows running tests on /
            self.delete_installroot = False
        else:
            self.installroot = tempfile.mkdtemp(prefix="dnf_ci_installroot_")
            # if we're creating installroot, ensure /etc/yum.repos.d exists,
            # otherwise dnf picks repo configs from the host
            ensure_directory_exists(os.path.join(self.installroot, "etc/yum.repos.d"))
            self.delete_installroot = True

        self.dnf_command = userdata.get("dnf_command", DEFAULT_DNF_COMMAND)
        self.config = userdata.get("config", DEFAULT_CONFIG)
        self.releasever = userdata.get("releasever", DEFAULT_RELEASEVER)
        self.module_platform_id = userdata.get("module_platform_id", DEFAULT_PLATFORM_ID)
        self.fixturesdir = FIXTURES_DIR
        self.disable_plugins = True
        self.disable_repos_option = "--disablerepo='*'"
        self.assumeyes_option = "-y"

        self.preserve_temporary_dirs = "none"
        preserve = userdata.get("preserve", "no")
        if preserve in ("yes", "y", "1", "true"):
            self.preserve_temporary_dirs = "all"
        elif preserve in ("failed", "fail", "f"):
            self.preserve_temporary_dirs = "failed"

        self.scenario_failed = False
示例#6
0
    def __init__(self,
                 userdata,
                 force_installroot=False,
                 no_installroot=False):
        self._scenario_data = {}

        self.repos = {}
        self.ports = {}
        self.config = {
            "[main]": {
                "gpgcheck": "1",
                "installonly_limit": "3",
                "clean_requirements_on_remove": "True",
                "best": "True"
            }
        }

        # Since protected_packages don't work in installroot override host configuration
        if not no_installroot:
            self.config["[main]"]["protected_packages"] = ","

        self.tempdir = tempfile.mkdtemp(prefix="dnf_ci_tempdir_")
        # some tests need to be run inside the installroot, it can be forced
        # per scenario by using @force_installroot decorator
        if no_installroot:
            self.installroot = "/"

            # move the following original system setup files to a backup location,
            # so that they don't interfere and the tests start with a clean state
            for path in ("/etc/dnf/dnf.conf", "/etc/yum.repos.d",
                         "/var/lib/dnf/modulefailsafe"):
                backup_path = path + ".backup"
                if os.path.exists(backup_path):
                    raise AssertionError(
                        'System backup path "%s" already exists. '
                        'Rerunning a no_installroot test in an unclean environment?'
                        % backup_path)
                try:
                    shutil.move(path, backup_path)
                except FileNotFoundError:
                    pass

            # never delete root
            self.delete_installroot = False
        elif "installroot" in userdata and not force_installroot:
            self.installroot = userdata["installroot"]
            # never delete user defined installroot - this allows running tests on /
            self.delete_installroot = False
        else:
            self.installroot = tempfile.mkdtemp(prefix="dnf_ci_installroot_")
            self.delete_installroot = True

        ensure_directory_exists(
            os.path.join(self.installroot, "etc/yum.repos.d"))

        self.dnf_command = userdata.get("dnf_command", DEFAULT_DNF_COMMAND)
        self.releasever = userdata.get("releasever", DEFAULT_RELEASEVER)
        self.module_platform_id = userdata.get("module_platform_id",
                                               DEFAULT_PLATFORM_ID)
        self.fixturesdir = consts.FIXTURES_DIR
        self.disable_plugins = True
        self.disable_repos_option = "--disablerepo='*'"
        self.assumeyes_option = "-y"

        self.preserve_temporary_dirs = "none"
        preserve = userdata.get("preserve", "no")
        if preserve in ("yes", "y", "1", "true"):
            self.preserve_temporary_dirs = "all"
        elif preserve in ("failed", "fail", "f"):
            self.preserve_temporary_dirs = "failed"

        self.scenario_failed = False
示例#7
0
def step_impl(context, dst, src):
    dst = prepend_installroot(context, dst)
    src = prepend_installroot(context, src)
    ensure_directory_exists(os.path.dirname(dst))
    os.symlink(src, dst)
示例#8
0
def step_impl(context, filepath):
    full_path = prepend_installroot(context, filepath)
    ensure_directory_exists(os.path.dirname(full_path))
    create_file_with_contents(full_path, context.text.format(context=context))
示例#9
0
def step_impl(context, dirpath):
    full_path = prepend_installroot(context, dirpath)
    ensure_directory_exists(full_path)
示例#10
0
def step_impl(context, source, destination):
    source = source.format(context=context)
    destination = prepend_installroot(context, destination)
    ensure_directory_exists(os.path.dirname(destination))
    copy_tree(source, destination)