Ejemplo n.º 1
0
def test_wait_for_compose_timeout(timeout):
    compose_url = '{}composes/{}'.format(ODCS_URL, COMPOSE_ID)

    responses.add(responses.GET,
                  compose_url,
                  body=compose_json(0, 'generating'))
    (flexmock(time).should_receive('time').and_return(
        2000, 1000)  # end time, start time
     .one_by_one())

    odcs_client = ODCSClient(ODCS_URL, timeout=timeout)
    expected_error = r'Timeout of waiting for compose \d+'
    with pytest.raises(WaitComposeToFinishTimeout, match=expected_error):
        odcs_client.wait_for_compose(COMPOSE_ID)
Ejemplo n.º 2
0
def odcs_client(tmpdir, request):
    insecure, token, cert = request.param

    mock_get_retry_session()

    odcs_client = ODCSClient(ODCS_URL, insecure=insecure, token=token, cert=cert)

    assert odcs_client.session.verify == (not insecure)
    assert odcs_client.session.cert == cert

    if token:
        expected_token_header = 'Bearer {}'.format(token)
        token_header = odcs_client.session.headers[ODCSClient.OIDC_TOKEN_HEADER]
        assert token_header == expected_token_header
    else:
        assert ODCSClient.OIDC_TOKEN_HEADER not in odcs_client.session.headers

    return odcs_client
Ejemplo n.º 3
0
def get_odcs_session(workflow, fallback):
    config = get_odcs(workflow, fallback)
    from atomic_reactor.utils.odcs import ODCSClient

    client_kwargs = {'insecure': config.get('insecure', False)}

    openidc_dir = config['auth'].get('openidc_dir')
    if openidc_dir:
        token_path = os.path.join(openidc_dir, 'token')
        with open(token_path, "r") as f:
            client_kwargs['token'] = f.read().strip()

    ssl_certs_dir = config['auth'].get('ssl_certs_dir')
    if ssl_certs_dir:
        cert_path = os.path.join(ssl_certs_dir, 'cert')
        if os.path.exists(cert_path):
            client_kwargs['cert'] = cert_path
        else:
            raise KeyError("ODCS ssl_certs_dir doesn't exist")

    return ODCSClient(config['api_url'], **client_kwargs)