Ejemplo n.º 1
0
def test_invoke_airflow_dag_errors(mock_info):
    act_resource = ActionsResource()
    dag_id = 'test_dag_id'
    action = 'test_action'
    web_server_url = CONF.base.web_server
    conf_value = {'action': action}
    responses.add(
        method='GET',
        url='{}admin/rest_api/api?api=trigger_dag&dag_id={}'
        '&conf={}'.format(web_server_url, dag_id,
                          act_resource.to_json(conf_value)),
        body=json.dumps({
            "error": "not found"
        }),
        status=404,
        content_type='application/json')

    with pytest.raises(ApiError) as expected_exc:
        act_resource.invoke_airflow_dag(dag_id, action, context)
    mock_info.assert_called_with('Response code from Airflow trigger_dag: %s',
                                 404)
    assert 'Unable to complete request to Airflow' in str(expected_exc)
    assert 'Airflow could not be contacted properly by Shipyard' in str(
        expected_exc)

    with mock.patch.object(actions_api, 'CONF') as mock_conf:
        mock_conf.base.web_server = 'Error'
        with pytest.raises(ApiError) as expected_exc:
            act_resource.invoke_airflow_dag(dag_id, action, context)
        assert 'Unable to invoke workflow' in str(expected_exc)
        assert ('Airflow URL not found by Shipyard. Shipyard configuration is '
                'missing web_server value') in str(expected_exc)
Ejemplo n.º 2
0
def test_invoke_airflow_dag_success(mock_info, mock_exhume_date):
    act_resource = ActionsResource()
    dag_id = 'test_dag_id'
    action = 'test_action'
    CONF = cfg.CONF
    web_server_url = CONF.base.web_server
    conf_value = {'action': action}
    log_string = 'Created <DagRun deploy_site @ 2017-09-22 22:16:14: man'
    responses.add(
        method='GET',
        url='{}admin/rest_api/api?api=trigger_dag&dag_id={}&conf={}'.format(
            web_server_url, dag_id, act_resource.to_json(conf_value)),
        body=json.dumps({'output': {
            'stdout': log_string
        }}),
        status=200,
        content_type='application/json')

    result = act_resource.invoke_airflow_dag(dag_id, action, context)
    mock_exhume_date.assert_called_with(dag_id, log_string)
    assert result == '2017-09-22T22:16:14'