コード例 #1
0
def mock_env(workflow, df_content: str, buildargs: Dict[str,
                                                        str]) -> PluginsRunner:
    env = MockEnv(workflow).for_plugin(AddBuildargsPlugin.key)
    (Path(workflow.source.path) / "Dockerfile").write_text(df_content)
    workflow.build_dir.init_build_dirs(["aarch64", "x86_64"], workflow.source)
    workflow.data.buildargs = buildargs
    return env.create_runner()
コード例 #2
0
def mock_env(dockerfile_path, docker_tasker,
             labels=(), flatpak=False, dockerfile_f=mock_dockerfile,
             isolated=None):
    """Mock test environment

    :param dockerfile_path: the path to the fake dockerfile to be created, not including the
        dockerfile filename.
    :type dockerfile_path: py.path.LocalPath
    :param docker_tasker: docker_tasker fixture from conftest. Passed to ``MockEnv.create_runner``
        directly to create a corresponding plugin runner instance.
    :param labels: an iterable labels set for testing operator bundle or appregistry build.
    :type labels: iterable[str]
    :param bool flatpak: a flag to indicate whether the test is for a flatpak build.
    :param callable dockerfile_f: a function to create fake dockerfile. Different test could pass a
        specific function for itself.
    :param bool isolated: a flag to indicated if build is isolated
    """
    if not flatpak:
        # flatpak build has no Dockefile
        dockerfile_f(dockerfile_path, labels)

    env = MockEnv().for_plugin('prebuild', CheckUserSettingsPlugin.key, {'flatpak': flatpak})
    env.workflow.source = FakeSource(dockerfile_path)

    if isolated is not None:
        env.set_isolated(isolated)

    dfp = df_parser(str(dockerfile_path))
    env.workflow.builder.set_df_path(str(dockerfile_path))
    env.workflow.builder.set_dockerfile_images([] if flatpak else dfp.parent_images)

    return env.create_runner(docker_tasker)
コード例 #3
0
def mock_env(
    workflow, df_content: str, args: Optional[Dict[str, str]] = None
) -> PluginsRunner:
    env = MockEnv(workflow).for_plugin("prebuild", AddDockerfilePlugin.key, args)

    (Path(workflow.source.path) / "Dockerfile").write_text(df_content)
    workflow.build_dir.init_build_dirs(["aarch64", "x86_64"], workflow.source)

    return env.create_runner()
コード例 #4
0
def mock_env(workflow,
             source_dir: Path,
             labels=None,
             flatpak=False,
             dockerfile_f=mock_dockerfile,
             isolated=None):
    """Mock test environment

    :param workflow: a DockerBuildWorkflow object for a specific test.
    :type workflow: DockerBuildWorkflow
    :param source_dir: path to the source directory holding the dockerfile to be created.
    :type source_dir: pathlib.Path
    :param labels: an iterable labels set for testing operator bundle or appregistry build.
    :type labels: iterable[str]
    :param bool flatpak: a flag to indicate whether the test is for a flatpak build.
    :param callable dockerfile_f: a function to create fake dockerfile. Different test could pass a
        specific function for itself.
    :param bool isolated: a flag to indicated if build is isolated
    """
    # Make sure the version label will be presented in labels
    if not labels:
        labels = ['version="1.0"']
    elif not any([label.startswith('version') for label in labels]):
        labels.append('version="1.0"')

    if not flatpak:
        # flatpak build has no Dockefile
        dockerfile_f(source_dir, labels)

    env = MockEnv(workflow).for_plugin(CheckUserSettingsPlugin.key,
                                       {'flatpak': flatpak})
    env.workflow.source = FakeSource(source_dir)
    env.workflow.build_dir.init_build_dirs(["aarch64", "x86_64"],
                                           env.workflow.source)

    if isolated is not None:
        env.set_isolated(isolated)

    dfp = env.workflow.build_dir.any_platform.dockerfile
    env.workflow.data.dockerfile_images = DockerfileImages(
        [] if flatpak else dfp.parent_images)

    flexmock(env.workflow.imageutil).should_receive(
        "base_image_inspect").and_return({})

    return env.create_runner()
コード例 #5
0
def mock_env(
    workflow,
    *,
    df_content: str,
    help_md: Optional[HelpMdFile] = None,
    plugin_args: Optional[Dict[str, str]] = None,
    mock_md2man: Callable[..., MockedPopen] = mock_md2man_success("man file content"),
) -> PluginsRunner:

    def get_build(pipeline_run_name):
        start_time_json = {'status': {'startTime': TIME}}
        return start_time_json

    flexmock(OSBS, get_build=get_build)
    config_kwargs = {
        'namespace': workflow.namespace,
        'verify_ssl': True,
        'openshift_url': 'http://example.com/',
        'use_auth': True,
        'conf_file': None,
    }
    (flexmock(osbs.conf.Configuration)
     .should_call("__init__")
     .with_args(**config_kwargs))

    openshift_map = {
        'url': 'http://example.com/',
        'insecure': False,
        'auth': {'enable': True},
    }

    rcm = {'version': 1, 'openshift': openshift_map}
    workflow.conf.conf = rcm

    env = MockEnv(workflow).for_plugin(AddHelpPlugin.key, plugin_args)
    source_dir = Path(workflow.source.path)

    (source_dir / "Dockerfile").write_text(df_content)
    if help_md:
        (source_dir / help_md.name).write_text(help_md.content)

    workflow.build_dir.init_build_dirs(["aarch64", "x86_64"], workflow.source)

    if help_md:
        def check_popen(*args, **kwargs):
            cmd = args[0]
            in_path, out_path = parse_md2man_args(cmd)

            assert in_path.name == help_md.name
            assert out_path.name == AddHelpPlugin.man_filename

            return mock_md2man(*args, **kwargs)

        (flexmock(subprocess)
         .should_receive("Popen")
         .once()
         .replace_with(check_popen))
    else:
        (flexmock(subprocess)
         .should_receive("Popen")
         .never())

    return env.create_runner()