def test_server_register_raise_error_if_not_registering():
    reg_url = "http://doofus.com/is/comming/for/you.json"
    oas = OAServerFile("doofus", wdir)

    with requests_mock.Mocker() as m:
        m.post(reg_url, text="", status_code=500)
        assert_raises(UserWarning, lambda: oas.register(reg_url))
def test_server_register_correctly_locally():
    reg_file = pj(tmp_dir, "registration.json")
    oas = OAServerFile("doofus", wdir)
    oas.register(reg_file)

    assert exists(reg_file)
    reg = get_json(reg_file)
    for key in ('id', 'url', 'urlping', 'urldelete'):
        assert key in reg['args']
def test_server_register_correctly_remote():
    reg_url = "http://doofus.com/is/comming/for/you.json"
    oas = OAServerFile("doofus", wdir)

    def text_callback(request, context):
        reg = json.loads(request.text)
        for key in ('id', 'url', 'urlping', 'urldelete'):
            assert key in reg['args']

    with requests_mock.Mocker() as m:
        m.post(reg_url, text=text_callback)
        oas.register(reg_url)
def test_server_register_correctly_when_started_already():
    reg_file = pj(tmp_dir, "registration.json")
    oas = OAServerFile("doofus", wdir)
    oas.start()
    oas.register(reg_file)

    res = [exists(reg_file)]
    reg = get_json(reg_file)
    for key in ('id', 'url', 'urlping', 'urldelete'):
        res.append(key in reg['args'])

    oas.stop()
    assert all(res)
def test_server_ping():
    answer_file = pj(tmp_dir, "answer.json")

    oas = OAServerFile("doofus", wdir)
    oas.start()
    oas.register(answer_file)

    ping_pth = pj(wdir, get_json(answer_file)['args']['urlping'])
    remove(answer_file)

    post_json(ping_pth, dict(url=answer_file))

    ans = wait_for_content(answer_file, NB)
    res = [ans['state'] == 'waiting',
           ans['id'] == "doofus"]

    oas.stop()
    oas.join()

    assert all(res)
    assert not exists(ping_pth)
def test_server_delete():
    answer_file = pj(tmp_dir, "answer.json")

    oas = OAServerFile("doofus", wdir)
    oas.start()
    oas.register(answer_file)

    del_pth = pj(wdir, wait_for_content(answer_file, NB)['args']['urldelete'])

    post_json(del_pth, dict())

    oas.join()

    assert not exists(del_pth)
def test_server_do_not_react_to_unknown_files():
    answer_file = pj(tmp_dir, "answer.json")

    oas = OAServerFile("doofus", wdir)
    oas.start()
    oas.register(answer_file)

    post_json(pj(wdir, "takapouet.cmd"), dict(a=1))

    ping_pth = pj(wdir, get_json(answer_file)['args']['urlping'])
    remove(answer_file)

    post_json(ping_pth, dict(url=answer_file))

    ans = wait_for_content(answer_file, NB)
    res = [ans['state'] == 'waiting',
           ans['id'] == "doofus"]

    oas.stop()
    oas.join()

    assert all(res)
def test_server_compute():
    answer_file = pj(tmp_dir, "answer.json")

    oas = OAServerFile("doofus", wdir)
    oas.start()
    oas.register(answer_file)

    cpt_pth = pj(wdir, get_json(answer_file)['args']['url'])
    remove(answer_file)

    post_json(cpt_pth, dict(workflow="pycode:def main(a): return a",
                            urldata="a = 1",
                            urlreturn=answer_file))

    ans = wait_for_content(answer_file, NB)
    res = [ans['result'] == 1,
           ans['id'] == "doofus"]

    oas.stop()
    oas.join()

    assert all(res)
    assert not exists(cpt_pth)
def test_server_full_life():
    answer_file = pj(tmp_dir, "answer.json")

    oas = OAServerFile("doofus", wdir)
    oas.start()
    oas.register(answer_file)

    ans = wait_for_content(answer_file, NB)
    cpt_pth = pj(wdir, ans['args']['url'])
    ping_pth = pj(wdir, ans['args']['urlping'])
    del_pth = pj(wdir, ans['args']['urldelete'])

    res = []
    for a in (1, 2):
        post_json(cpt_pth, dict(workflow="pycode:" + pycode,
                                urldata="a = %d" % a,
                                urlreturn=answer_file))

        answer_ping = pj(tmp_dir, "answer_ping.json")
        post_json(ping_pth, dict(url=answer_ping))
        ans = wait_for_content(answer_ping, NB)
        res.append(ans['id'] == "doofus")
        res.append(ans['state'] in ('running', 'waiting'))

        ans = wait_for_content(answer_file, NB)
        res.append(ans['result'] == a)
        res.append(ans['id'] == "doofus")

        answer_ping = pj(tmp_dir, "answer_ping.json")
        post_json(ping_pth, dict(url=answer_ping))
        ans = wait_for_content(answer_ping, NB)
        res.append(ans['id'] == "doofus")
        res.append(ans['state'] == 'waiting')

    post_json(del_pth, dict())

    oas.join()
Esempio n. 10
0
from sys import argv

from oaserver.oa_server_file import OAServerFile
from oaserver.uos import ls, remove

from ip_list import dirac_com_dir as com_dir


if len(argv) == 1:
    sid = "doofus"
else:
    port = int(argv[1])
    sid = "doofus_%d" % port

local_com_dir = com_dir + "/" + sid
stdin = "dirac:%s/stdin" % local_com_dir
stdout = "dirac:%s/stdout" % local_com_dir

for name in ls(stdin):
    remove(stdin + "/" + name)

####################################################################
#
#   launch oaserver
#
####################################################################
oas = OAServerFile(sid, stdin)
oas.register(stdout + "/reg.json")
oas.start()
Esempio n. 11
0
from oaserver.oa_server_file import OAServerFile

from ip_list import sheldon_com_dir as com_dir


if len(argv) == 1:
    sid = "doofus"
else:
    port = int(argv[1])
    sid = "doofus_%d" % port

local_com_dir = pj(com_dir, sid)
stdin = pj(local_com_dir, "stdin")
stdout = pj(local_com_dir, "stdout")

if exists(local_com_dir):
    rmtree(local_com_dir, True)

for pth in (com_dir, local_com_dir, stdin, stdout):
    if not exists(pth):
        mkdir(pth)

####################################################################
#
#   launch oaserver
#
####################################################################
oas = OAServerFile(sid, stdin)
oas.register(pj(stdout, "reg.json"))
oas.start()