Example #1
0
def test_dci_agent_failure(monkeypatch, dci_context, job_id):
    def return_context(**a):
        return dci_context

    def raise_exception(*a, **b):
        raise Exception('booom')
    mock_run_commands = mock.Mock()
    mock_run_tests = raise_exception
    monkeypatch.setattr(agent, 'get_dci_context', return_context)
    monkeypatch.setattr(dciclient.v1.helper, 'run_command',
                        mock_run_commands)
    monkeypatch.setattr(tripleohelper.undercloud, 'Undercloud', mock.Mock())
    monkeypatch.setattr(dciclient.v1.tripleo_helper, 'run_tests',
                        mock_run_tests)
    with pytest.raises(SystemExit):
        agent.main(['--topic', 'topic_name', '--config',
                    os.path.dirname(__file__) + '/dci_agent.yaml'])

    js = dci_jobstate.list(dci_context).json()['jobstates']
    assert js[-1]['status'] == 'failure'
    assert js[-1]['comment'] == 'booom'

    # the where filter does not work yet:
    #   I1f0df01f813efae75f6e0e75a3861d2d4ba5694a
    files = dci_file.list(dci_context).json()['files']
    content = dci_file.content(dci_context, files[-1]['id'])
    assert 'most recent call last' in content.text
Example #2
0
def output(context, id):
    """output(context, id)

    Show a job output.

    >>> dcictl job-output [OPTIONS]

    :param string id: ID of the job to show [required]
    """

    colors = {
        'pre-run': '\x1b[6;30;44m',
        'running': '\x1b[6;30;42m',
        'post-run': '\x1b[6;30;44m',
        'failure': '\x1b[6;30;41m'}
    result = job.list_jobstates(context, id=id)
    jobstates = result.json()['jobstates']

    for js in jobstates:
        color = colors.get(js['status'], '')
        click.echo('%s[%s]\x1b[0m %s' % (
            color,
            js['status'],
            js['comment']))
        f_l = dci_file.list(
            context,
            where='jobstate_id:' + js['id'])
        for f in f_l.json()['files']:
            click.echo(dci_file.content(context, id=f['id']).text)
def test_run_command_shell(dci_context, jobstate_id):
    dci_helper.run_command(
        dci_context,
        'echo foo bar',
        shell=True)
    files = dci_file.list(dci_context).json()['files']
    assert files[-1]['name'] == 'echo foo bar'
    f = dci_file.content(dci_context, files[-1]['id'])
    assert f.content.decode(encoding='UTF-8') == 'foo bar\n'
Example #4
0
def show(context, id):
    """show(context, id)

    Show a file.

    >>> dcictl file-show [OPTIONS]

    :param string id: ID of the file to show [required]
    """
    content = file.content(context, id=id)
    click.echo(content.text)
Example #5
0
def output(context, args):
    result = job.list_jobstates(context, id=args.id, sort="created_at")
    jobstates = result.json()["jobstates"]

    res = []
    for js in jobstates:
        f_l = job.list_files(context,
                             id=args.id,
                             where="jobstate_id:" + js["id"],
                             sort="created_at")
        for f in f_l.json()["files"]:
            res.append(dci_file.content(context, id=f["id"]).text)
    return res
Example #6
0
def get_content_for_file(file_id):
    context = build_dci_context()
    r = dci_file.content(context, id=file_id)
    r.raise_for_status()
    return r.text
Example #7
0
def show(context, args):
    return file.content(context, id=args.id)