Ejemplo n.º 1
0
def test_start_should_not_update_existing_startfile(tmpdir):
    with open(str(tmpdir / 'started'), 'w') as f:
        print(u'old', file=f)
    req = Request(0, 1, path=str(tmpdir))
    req.execute()
    with open(os.path.join(req.path, 'started')) as f:
        assert u'old\n' == f.read()
Ejemplo n.º 2
0
def test_state_retrylimit(tmpdir):
    request = Request(0, 1, script='exit 75', path=str(tmpdir))
    request.save()
    with open(os.path.join(request.path, 'attempt'), 'w') as f:
        print(Request.MAX_TRIES, file=f)
    request.execute()
    assert request.state == Request.RETRYLIMIT
Ejemplo n.º 3
0
def test_execute_should_skip_execution_if_script_not_applicable(tmpdir):
    request = Request(0,
                      1,
                      script='echo >> did_something',
                      path=str(tmpdir),
                      applicable='/bin/false')
    request.execute()
    assert os.path.exists(os.path.join(request.path, 'did_something')) is False
Ejemplo n.º 4
0
def test_applicable_postpone(tmpdir):
    request = Request(0,
                      1,
                      script='true',
                      applicable='exit 69',
                      path=str(tmpdir))
    request.save()
    request.execute()
    assert request.state == Request.POSTPONE
Ejemplo n.º 5
0
def test_execute_should_write_stdout_stderr(tmpdir):
    request = Request(0,
                      1,
                      script='echo stdout; echo stderr >&2',
                      path=str(tmpdir))
    request.execute()
    with open(os.path.join(request.path, 'stdout')) as f:
        assert f.read() == 'stdout\n'
    with open(os.path.join(request.path, 'stderr')) as f:
        assert f.read() == 'stderr\n'
Ejemplo n.º 6
0
def test_applicable_error(tmpdir):
    request = Request(0,
                      1,
                      script='true',
                      applicable='exit 2',
                      path=str(tmpdir))
    request.save()
    request.execute()
    assert request.state == Request.ERROR
    assert request.exitcode == 2
Ejemplo n.º 7
0
def test_not_applicable_but_success(tmpdir):
    request = Request(0,
                      1,
                      script='true',
                      applicable='exit 1',
                      path=str(tmpdir))
    request.save()
    request.execute()
    assert request.state == Request.SUCCESS
    assert request.exitcode == 0
Ejemplo n.º 8
0
def test_execute_should_just_record_time_if_no_script(tmpdir):
    with freezegun.freeze_time('2011-07-27 07:35:00', tz_offset=0):
        request = Request(0, 1, path=str(tmpdir))
        request.save()
        request.execute()
        assert request.state == Request.SUCCESS
        assert request.started == datetime.datetime(2011,
                                                    7,
                                                    27,
                                                    7,
                                                    35,
                                                    tzinfo=pytz.utc)
        assert request.stopped == datetime.datetime(2011,
                                                    7,
                                                    27,
                                                    7,
                                                    35,
                                                    tzinfo=pytz.utc)
Ejemplo n.º 9
0
def test_execute_should_cd_to_requestpath(tmpdir):
    request = Request(0, 1, script='echo foo > localfile', path=str(tmpdir))
    request.execute()
    with open(os.path.join(request.path, 'localfile')) as f:
        assert f.read() == 'foo\n'
Ejemplo n.º 10
0
def test_execute_should_write_exitcode(tmpdir):
    request = Request(0, 1, script='exit 70', path=str(tmpdir))
    request.execute()
    with open(os.path.join(request.path, 'exitcode')) as f:
        assert f.read() == '70\n'
Ejemplo n.º 11
0
def test_state_error(tmpdir):
    request = Request(0, 1, script='exit 1', path=str(tmpdir))
    request.save()
    request.execute()
    assert request.state == Request.ERROR
Ejemplo n.º 12
0
def test_state_tempfail(tmpdir):
    request = Request(0, 1, script='exit 75', path=str(tmpdir))
    request.save()
    request.execute()
    assert request.state == Request.TEMPFAIL
Ejemplo n.º 13
0
def test_state_success(tmpdir):
    request = Request(0, 1, script='exit 0', path=str(tmpdir))
    request.save()
    request.execute()
    assert request.state == Request.SUCCESS