Пример #1
0
def test_no_branch():
    with NamedTemporaryFile(mode='w+') as f:
        f.write("""
[default]
openshift_url=https://172.0.0.1:8443/
registry_uri=127.0.0.1:5000
""")
        f.flush()
        f.seek(0)
        with pytest.raises(OsbsException):
            os_conf = Configuration(conf_file=f.name,
                                    conf_section="default")
            osbs = OSBS(os_conf)
            osbs.create_binary_container_pipeline_run(git_uri="https://example.com/example.git",
                                                      git_ref="master")
Пример #2
0
def cmd_build(args):
    if args.instance is None:
        conf_section = DEFAULT_CONF_BINARY_SECTION
    else:
        conf_section = args.instance
    os_conf = Configuration(conf_file=args.config,
                            conf_section=conf_section,
                            cli_args=args)
    osbs = OSBS(os_conf)

    build_kwargs = {
        'git_uri': osbs.os_conf.get_git_uri(),
        'git_ref': osbs.os_conf.get_git_ref(),
        'git_branch': osbs.os_conf.get_git_branch(),
        'user': osbs.os_conf.get_user(),
        'tag': osbs.os_conf.get_tag(),
        'target': osbs.os_conf.get_koji_target(),
        'yum_repourls': osbs.os_conf.get_yum_repourls(),
        'dependency_replacements': osbs.os_conf.get_dependency_replacements(),
        'scratch': args.scratch,
        'platforms': args.platforms,
        'release': args.release,
        'koji_parent_build': args.koji_parent_build,
        'isolated': args.isolated,
        'signing_intent': args.signing_intent,
        'compose_ids': args.compose_ids,
        'operator_csv_modifications_url': args.operator_csv_modifications_url,
    }
    if args.userdata:
        build_kwargs['userdata'] = json.loads(args.userdata)
    if osbs.os_conf.get_flatpak():
        build_kwargs['flatpak'] = True

    pipeline_run = osbs.create_binary_container_pipeline_run(**build_kwargs)

    print_output(pipeline_run, export_metadata_file=args.export_metadata_file)

    return_val = -1

    if pipeline_run.has_succeeded():
        return_val = 0
    cleanup_used_resources = osbs.os_conf.get_cleanup_used_resources()
    if cleanup_used_resources:
        try:
            logger.info("pipeline run removed: %s",
                        pipeline_run.remove_pipeline_run())
        except OsbsResponseException:
            logger.error("failed to remove pipeline run %s",
                         pipeline_run.pipeline_run_name)
            raise
    return return_val
Пример #3
0
    def test_create_binary_container_pipeline_run(self, koji_task_id, isolated,
                                                  scratch, release):
        rcm = 'rcm'
        rcm_scratch = 'rcm_scratch'
        with NamedTemporaryFile(mode="wt") as fp:
            fp.write("""
    [default_binary]
    openshift_url = /
    namespace = {namespace}
    use_auth = false
    pipeline_run_path = {pipeline_run_path}
    reactor_config_map = {rcm}
    reactor_config_map_scratch = {rcm_scratch}
    """.format(namespace=TEST_OCP_NAMESPACE,
               pipeline_run_path=TEST_PIPELINE_RUN_TEMPLATE,
               rcm=rcm,
               rcm_scratch=rcm_scratch))
            fp.flush()
            dummy_config = Configuration(fp.name,
                                         conf_section='default_binary')
            osbs = OSBS(dummy_config)

        random_postfix = 'sha-timestamp'
        (flexmock(utils).should_receive('generate_random_postfix').and_return(
            random_postfix))

        name = utils.make_name_from_git(TEST_GIT_URI, TEST_GIT_BRANCH)
        pipeline_run_name = utils.make_name_from_git(TEST_GIT_URI,
                                                     TEST_GIT_BRANCH)
        if isolated:
            pipeline_run_name = f'isolated-{random_postfix}'
        if scratch:
            pipeline_run_name = f'scratch-{random_postfix}'

        (flexmock(utils).should_receive('get_repo_info').with_args(
            TEST_GIT_URI, TEST_GIT_REF, git_branch=TEST_GIT_BRANCH,
            depth=None).and_return(self.mock_repo_info()))

        rand = '67890'
        timestr = '20170731111111'
        (flexmock(sys.modules['osbs.build.user_params']).should_receive(
            'utcnow').once().and_return(
                datetime.datetime.strptime(timestr, '%Y%m%d%H%M%S')))

        (flexmock(random).should_receive('randrange').with_args(
            10**(len(rand) - 1), 10**len(rand)).and_return(int(rand)))

        image_tag = f'{TEST_USER}/{TEST_COMPONENT}:{TEST_TARGET}-{rand}-{timestr}'

        self.mock_start_pipeline()
        signing_intent = 'signing_intent'
        pipeline_run = osbs.create_binary_container_pipeline_run(
            target=TEST_TARGET,
            signing_intent=signing_intent,
            koji_task_id=koji_task_id,
            isolated=isolated,
            scratch=scratch,
            release=release,
            **REQUIRED_BUILD_ARGS)
        assert isinstance(pipeline_run, PipelineRun)

        assert pipeline_run.input_data['metadata']['name'] == pipeline_run_name

        for ws in pipeline_run.input_data['spec']['workspaces']:
            if ws['name'] == PRUN_TEMPLATE_REACTOR_CONFIG_WS:
                if scratch:
                    assert ws['configmap']['name'] == rcm_scratch
                else:
                    assert ws['configmap']['name'] == rcm

            if ws['name'] in [
                    PRUN_TEMPLATE_BUILD_DIR_WS, PRUN_TEMPLATE_CONTEXT_DIR_WS
            ]:
                assert ws['volumeClaimTemplate']['metadata'][
                    'namespace'] == TEST_OCP_NAMESPACE

        for param in pipeline_run.input_data['spec']['params']:
            if param['name'] == PRUN_TEMPLATE_USER_PARAMS:
                assert param['value'] != {}

                up = json.loads(param['value'])

                expect_up = {}
                if scratch:
                    expect_up['reactor_config_map'] = rcm_scratch
                    expect_up['scratch'] = True
                else:
                    expect_up['reactor_config_map'] = rcm
                expect_up['base_image'] = MockDfParser.baseimage
                expect_up['component'] = TEST_COMPONENT
                expect_up['git_branch'] = TEST_GIT_BRANCH
                expect_up['git_ref'] = TEST_GIT_REF
                expect_up['git_uri'] = TEST_GIT_URI
                expect_up['kind'] = BuildUserParams.KIND
                if koji_task_id:
                    expect_up['koji_task_id'] = koji_task_id
                expect_up['name'] = name
                expect_up['koji_target'] = TEST_TARGET
                expect_up['user'] = TEST_USER
                expect_up['signing_intent'] = signing_intent
                if isolated:
                    expect_up['isolated'] = True
                if release:
                    expect_up['release'] = release
                expect_up['image_tag'] = image_tag

                assert up == expect_up