Beispiel #1
0
def func_for_mock_tmgr_test(mq_hostname, port, pending_queue, completed_queue):

    mq_connection = pika.BlockingConnection(pika.ConnectionParameters(
                                                   host=mq_hostname, port=port))
    mq_channel = mq_connection.channel()

    tasks = list()
    for _ in range(16):
        task = Task()
        task.state      = states.SCHEDULING
        task.executable = '/bin/echo'
        tasks.append(task.to_dict())

    tasks_as_json = json.dumps(tasks)
    mq_channel.basic_publish(exchange='',
                             routing_key=pending_queue,
                             body=tasks_as_json)
    cnt = 0
    while cnt < 15:

        method_frame, props, body = mq_channel.basic_get(queue=completed_queue)

        if not body:
            continue

        task = Task()
        task.from_dict(json.loads(body))

        if task.state == states.DONE:
            cnt += 1

        mq_channel.basic_ack(delivery_tag=method_frame.delivery_tag)

    mq_connection.close()
def func_for_mock_tmgr_test(mq_hostname, port, pending_queue, completed_queue):

    mq_connection = pika.BlockingConnection(pika.ConnectionParameters(host=mq_hostname, port=port))
    mq_channel = mq_connection.channel()

    tasks = list()
    for _ in range(16):
        t = Task()
        t.state = states.SCHEDULING
        t.executable = '/bin/echo'
        tasks.append(t.to_dict())

    tasks_as_json = json.dumps(tasks)
    mq_channel.basic_publish(exchange='',
                             routing_key=pending_queue,
                             body=tasks_as_json)

    cnt = 0
    while cnt < 15:

        method_frame, props, body = mq_channel.basic_get(queue=completed_queue)
        if body:
            task = Task()
            task.from_dict(json.loads(body))
            if task.state == states.DONE:
                cnt += 1
            mq_channel.basic_ack(delivery_tag=method_frame.delivery_tag)

    mq_connection.close()
def test_issue_271():

    d = {   'uid': 're.Task.0000',
            'name': 't1',
            'state': states.DONE,
            'state_history': [states.INITIAL, states.DONE],
            'pre_exec': [],
            'executable': 'sleep',
            'arguments': [],
            'post_exec': [],
            'cpu_reqs': { 'processes': 1,
                        'process_type': None,
                        'threads_per_process': 1,
                        'thread_type': None
                        },
            'gpu_reqs': { 'processes': 0,
                        'process_type': None,
                        'threads_per_process': 0,
                        'thread_type': None
                        },
            'lfs_per_process': 1024,
            'upload_input_data': [],
            'copy_input_data': [],
            'link_input_data': [],
            'move_input_data': [],
            'copy_output_data': [],
            'move_output_data': [],
            'download_output_data': [],
            'stdout': 'out',
            'stderr': 'err',
            'exit_code': 555,
            'path': 'here/it/is',
            'tag': 'task.0010',
            'parent_stage': {'uid': 's1', 'name': 'stage1'},
            'parent_pipeline': {'uid': 'p1', 'name': 'pipe1'}}

    t = Task()
    t.from_dict(d)

    d['executable'] = 'sleep'

    t = Task()
    t.from_dict(d)
Beispiel #4
0
def test_task_from_dict():
    """
    **Purpose**: Test if the 'from_dict' function of Task class converts a dictionary into a Task correctly with all
    the expected attributes
    """

    d = {
        'uid': 're.Task.0000',
        'name': 't1',
        'state': states.DONE,
        'state_history': [states.INITIAL, states.DONE],
        'pre_exec': [],
        'executable': [],
        'arguments': [],
        'post_exec': [],
        'cpu_reqs': {
            'processes': 1,
            'process_type': None,
            'threads_per_process': 1,
            'thread_type': None
        },
        'gpu_reqs': {
            'processes': 0,
            'process_type': None,
            'threads_per_process': 0,
            'thread_type': None
        },
        'lfs_per_process': 1024,
        'upload_input_data': [],
        'copy_input_data': [],
        'link_input_data': [],
        'move_input_data': [],
        'copy_output_data': [],
        'move_output_data': [],
        'download_output_data': [],
        'stdout': 'out',
        'stderr': 'err',
        'exit_code': 555,
        'path': 'here/it/is',
        'tag': 'task.0010',
        'parent_stage': {
            'uid': 's1',
            'name': 'stage1'
        },
        'parent_pipeline': {
            'uid': 'p1',
            'name': 'pipe1'
        }
    }

    t = Task()
    t.from_dict(d)

    assert t._uid == d['uid']
    assert t.name == d['name']
    assert t.state == d['state']
    assert t.state_history == d['state_history']
    assert t.pre_exec == d['pre_exec']
    assert t.executable == d['executable']
    assert t.arguments == d['arguments']
    assert t.post_exec == d['post_exec']
    assert t.cpu_reqs == d['cpu_reqs']
    assert t.gpu_reqs == d['gpu_reqs']
    assert t.lfs_per_process == d['lfs_per_process']
    assert t.upload_input_data == d['upload_input_data']
    assert t.copy_input_data == d['copy_input_data']
    assert t.link_input_data == d['link_input_data']
    assert t.move_input_data == d['move_input_data']
    assert t.copy_output_data == d['copy_output_data']
    assert t.move_output_data == d['move_output_data']
    assert t.download_output_data == d['download_output_data']
    assert t.stdout == d['stdout']
    assert t.stderr == d['stderr']
    assert t.exit_code == d['exit_code']
    assert t.path == d['path']
    assert t.tag == d['tag']
    assert t.parent_stage == d['parent_stage']
    assert t.parent_pipeline == d['parent_pipeline']
def test_task_from_dict():

    """
    **Purpose**: Test if the 'from_dict' function of Task class converts a dictionary into a Task correctly with all
    the expected attributes
    """

    d = {   'uid': 're.Task.0000',
            'name': 't1',
            'state': states.DONE,
            'state_history': [states.INITIAL, states.DONE],
            'pre_exec': [],
            'executable': '',
            'arguments': [],
            'post_exec': [],
            'cpu_reqs': { 'processes': 1,
                        'process_type': None,
                        'threads_per_process': 1,
                        'thread_type': None
                        },
            'gpu_reqs': { 'processes': 0,
                        'process_type': None,
                        'threads_per_process': 0,
                        'thread_type': None
                        },
            'lfs_per_process': 1024,
            'upload_input_data': [],
            'copy_input_data': [],
            'link_input_data': [],
            'move_input_data': [],
            'copy_output_data': [],
            'move_output_data': [],
            'download_output_data': [],
            'stdout': 'out',
            'stderr': 'err',
            'exit_code': 555,
            'path': 'here/it/is',
            'tag': 'task.0010',
            'parent_stage': {'uid': 's1', 'name': 'stage1'},
            'parent_pipeline': {'uid': 'p1', 'name': 'pipe1'}}

    t = Task()
    t.from_dict(d)

    assert t._uid                  == d['uid']
    assert t.name                  == d['name']
    assert t.state                 == d['state']
    assert t.state_history         == d['state_history']
    assert t.pre_exec              == d['pre_exec']
    assert t.executable            == d['executable']
    assert t.arguments             == d['arguments']
    assert t.post_exec             == d['post_exec']
    assert t.cpu_reqs              == d['cpu_reqs']
    assert t.gpu_reqs              == d['gpu_reqs']
    assert t.lfs_per_process       == d['lfs_per_process']
    assert t.upload_input_data     == d['upload_input_data']
    assert t.copy_input_data       == d['copy_input_data']
    assert t.link_input_data       == d['link_input_data']
    assert t.move_input_data       == d['move_input_data']
    assert t.copy_output_data      == d['copy_output_data']
    assert t.move_output_data      == d['move_output_data']
    assert t.download_output_data  == d['download_output_data']
    assert t.stdout                == d['stdout']
    assert t.stderr                == d['stderr']
    assert t.exit_code             == d['exit_code']
    assert t.path                  == d['path']
    assert t.tag                   == d['tag']
    assert t.parent_stage          == d['parent_stage']
    assert t.parent_pipeline       == d['parent_pipeline']


    d['executable'] = 'sleep'
    t = Task()
    t.from_dict(d)
    assert t.executable            == d['executable']