def test_simple_pb():

    for missing in ["id", "version", "type"]:
        with pytest.raises(ValueError, match="Workflow must"):
            workflow = dict(WORKFLOW)
            del workflow[missing]
            entity.ProcessingBlock("foo-bar", None, workflow)
    with pytest.raises(ValueError, match="Processing block ID"):
        entity.ProcessingBlock("asd_htb", None, WORKFLOW)
    with pytest.raises(ValueError, match="Processing block ID"):
        entity.ProcessingBlock("foo/bar", None, WORKFLOW)

    pblock = entity.ProcessingBlock("foo-bar", None, WORKFLOW)
    # pylint: disable=W0123
    assert pblock == eval("entity." + repr(pblock))
def test_simple_pb():

    for missing in ['id', 'version', 'type']:
        with pytest.raises(ValueError, match="Workflow must"):
            workflow = dict(WORKFLOW)
            del workflow[missing]
            entity.ProcessingBlock('foo-bar', None, workflow)
    with pytest.raises(ValueError, match="Processing block ID"):
        entity.ProcessingBlock('asd_htb', None, WORKFLOW)
    with pytest.raises(ValueError, match="Processing block ID"):
        entity.ProcessingBlock('foo/bar', None, WORKFLOW)

    pb = entity.ProcessingBlock('foo-bar', None, WORKFLOW)
    # pylint: disable=W0123,W0611
    from ska_sdp_config.entity import ProcessingBlock
    assert pb == eval(repr(pb))
def test_pb_state(cfg):

    pb_id = 'teststate-00000000-0000'
    state1 = {
        "state": "executing",
        "subarray": "ON",
        "obsState": "SCANNING",
        "receiveAddresses": {
            "1": {
                "1": ["0.0.0.0", 1024]
            }
        }
    }
    state2 = {
        "state": "failed",
        "subarray": "ON",
        "obsState": "SCANNING",
        "receiveAddresses": {
            "1": {
                "1": ["0.0.0.0", 1024]
            }
        }
    }

    # Create processing block
    for txn in cfg.txn():
        pb = entity.ProcessingBlock(pb_id, None, WORKFLOW)
        txn.create_processing_block(pb)

    # Check PB state is None
    for txn in cfg.txn():
        state_out = txn.get_processing_block_state(pb_id)
        assert state_out is None

    # Create PB state as state1
    for txn in cfg.txn():
        txn.create_processing_block_state(pb_id, state1)

    # Read PB state and check it matches state1
    for txn in cfg.txn():
        state_out = txn.get_processing_block_state(pb_id)
        assert state_out == state1

    # Try to create PB state again and check it raises a collision exception
    for txn in cfg.txn():
        with pytest.raises(backend.Collision):
            txn.create_processing_block_state(pb_id, state1)

    # Update PB state to state2
    for txn in cfg.txn():
        txn.update_processing_block_state(pb_id, state2)

    # Read PB state and check it now matches state2
    for txn in cfg.txn():
        state_out = txn.get_processing_block_state(pb_id)
        assert state_out == state2
def test_pblock_state(cfg):

    pblock_id = "teststate-00000000-0000"
    state1 = {
        "resources_available": True,
        "state": "RUNNING",
        "receive_addresses": {
            "1": {
                "1": ["0.0.0.0", 1024]
            }
        },
    }
    state2 = {
        "resources_available": True,
        "state": "FINISHED",
        "receive_addresses": {
            "1": {
                "1": ["0.0.0.0", 1024]
            }
        },
    }

    # Create processing block
    for txn in cfg.txn():
        pblock = entity.ProcessingBlock(pblock_id, None, WORKFLOW)
        txn.create_processing_block(pblock)

    # Check PBLOCK state is None
    for txn in cfg.txn():
        state_out = txn.get_processing_block_state(pblock_id)
        assert state_out is None

    # Create PBLOCK state as state1
    for txn in cfg.txn():
        txn.create_processing_block_state(pblock_id, state1)

    # Read PBLOCK state and check it matches state1
    for txn in cfg.txn():
        state_out = txn.get_processing_block_state(pblock_id)
        assert state_out == state1

    # Try to create PBLOCK state again and check it raises a collision exception
    for txn in cfg.txn():
        with pytest.raises(ConfigCollision):
            txn.create_processing_block_state(pblock_id, state1)

    # Update PBLOCK state to state2
    for txn in cfg.txn():
        txn.update_processing_block_state(pblock_id, state2)

    # Read PBLOCK state and check it now matches state2
    for txn in cfg.txn():
        state_out = txn.get_processing_block_state(pblock_id)
        assert state_out == state2
예제 #5
0
def cmd_create_pb(txn, workflow, parameters, _args):
    """Create a processing block."""
    # Parse parameters
    if parameters is not None:
        pars = yaml.safe_load(parameters)
    else:
        pars = {}

    # Create new processing block ID, create processing block
    pb_id = txn.new_processing_block_id(workflow['type'])
    txn.create_processing_block(entity.ProcessingBlock(
        pb_id, None, workflow, parameters=pars))
    return pb_id
def test_create_pb(cfg):

    # Create 3 processing blocks
    for txn in cfg.txn():

        pb1_id = txn.new_processing_block_id(WORKFLOW['type'])
        pb1 = entity.ProcessingBlock(pb1_id, None, WORKFLOW)
        assert txn.get_processing_block(pb1_id) is None
        txn.create_processing_block(pb1)
        with pytest.raises(backend.Collision):
            txn.create_processing_block(pb1)
        assert txn.get_processing_block(pb1_id).pb_id == pb1_id

        pb2_id = txn.new_processing_block_id(WORKFLOW['type'])
        pb2 = entity.ProcessingBlock(pb2_id, None, WORKFLOW)
        txn.create_processing_block(pb2)

        pb_ids = txn.list_processing_blocks()
        assert(pb_ids == [pb1_id, pb2_id])

    # Make sure that it stuck
    for txn in cfg.txn():
        pb_ids = txn.list_processing_blocks()
        assert(pb_ids == [pb1_id, pb2_id])

    # Make sure we can update them
    for txn in cfg.txn():
        pb1.parameters['test'] = 'test'
        pb1.scan_parameters['12345'] = {
            'test_scan': 'asd'
        }
        txn.update_processing_block(pb1)

    # Check that update worked
    for txn in cfg.txn():
        pb1x = txn.get_processing_block(pb1.pb_id)
        assert pb1x.sbi_id is None
        assert pb1x.parameters == pb1.parameters
        assert pb1x.scan_parameters == pb1.scan_parameters
def test_create_pblock(cfg):

    # Create 3 processing blocks
    for txn in cfg.txn():

        pblock1_id = txn.new_processing_block_id("test")
        pblock1 = entity.ProcessingBlock(pblock1_id, None, WORKFLOW)
        assert txn.get_processing_block(pblock1_id) is None
        txn.create_processing_block(pblock1)
        with pytest.raises(ConfigCollision):
            txn.create_processing_block(pblock1)
        assert txn.get_processing_block(pblock1_id).id == pblock1_id

        pblock2_id = txn.new_processing_block_id("test")
        pblock2 = entity.ProcessingBlock(pblock2_id, None, WORKFLOW)
        txn.create_processing_block(pblock2)

        pblock_ids = txn.list_processing_blocks()
        assert pblock_ids == [pblock1_id, pblock2_id]

    # Make sure that it stuck
    for txn in cfg.txn():
        pblock_ids = txn.list_processing_blocks()
        assert pblock_ids == [pblock1_id, pblock2_id]

    # Make sure we can update them
    for txn in cfg.txn():
        pblock1.parameters["test"] = "test"
        pblock1.dependencies.append({"pblockId": pblock2_id, "type": []})
        txn.update_processing_block(pblock1)

    # Check that update worked
    for txn in cfg.txn():
        pblock1x = txn.get_processing_block(pblock1.id)
        assert pblock1x.sbi_id is None
        assert pblock1x.parameters == pblock1.parameters
        assert pblock1x.dependencies == pblock1.dependencies
def test_take_pb(cfg):

    workflow2 = dict(WORKFLOW)
    workflow2['id'] += "-take"

    # Create another processing block
    for txn in cfg.txn():

        pb_id = txn.new_processing_block_id(workflow2['type'])
        pb = entity.ProcessingBlock(pb_id, None, workflow2)
        txn.create_processing_block(pb)

    with cfg.lease() as lease:

        for txn in cfg.txn():
            txn.take_processing_block(pb_id, lease)

        for txn in cfg.txn():
            assert txn.get_processing_block_owner(pb_id) == cfg.owner
            assert txn.is_processing_block_owner(pb_id)

    for txn in cfg.txn():
        assert txn.get_processing_block_owner(pb_id) is None
        assert not txn.is_processing_block_owner(pb_id)

    # Check that asking for a non-existing workflow doesn't work
    for txn in cfg.txn():
        workflow3 = dict(WORKFLOW)
        workflow3['id'] += "-take-doesnt-exist"
        assert txn.take_processing_block_by_workflow(workflow3, lease) is None

    # Test that we can find the processing block by workflow
    with cfg.lease() as lease:
        for txn in cfg.txn():
            pb2 = txn.take_processing_block_by_workflow(workflow2, lease)
            assert pb2.pb_id == pb_id

    for txn in cfg.txn():
        assert txn.get_processing_block_owner(pb_id) is None
        assert not txn.is_processing_block_owner(pb_id)

    # Check that we can re-claim it using client lease
    for txn in cfg.txn():
        pb2 = txn.take_processing_block_by_workflow(workflow2,
                                                    cfg.client_lease)
        assert pb2.pb_id == pb_id
    for txn in cfg.txn():
        assert txn.get_processing_block_owner(pb_id) == cfg.owner
        assert txn.is_processing_block_owner(pb_id)
예제 #9
0
def cmd_create_pb(txn, workflow, parameters):
    """
    Create a processing block to run a workflow.

    :param txn: Config object transaction
    :param workflow: dict of workflow information: type, id, version
    :param parameters: dict of workflow parameters, it can be None

    :return pb_id: ID of the created processing block
    """
    # Parse parameters
    if parameters is not None:
        pars = yaml.safe_load(parameters)
    else:
        pars = {}

    # Create new processing block ID, create processing block
    pb_id = txn.new_processing_block_id("sdpcli")
    txn.create_processing_block(
        entity.ProcessingBlock(pb_id, None, workflow, parameters=pars))
    return pb_id
def test_take_pblock(cfg):

    workflow2 = dict(WORKFLOW)
    workflow2["id"] += "-take"

    # Create another processing block
    for txn in cfg.txn():

        pblock_id = txn.new_processing_block_id("test")
        pblock = entity.ProcessingBlock(pblock_id, None, workflow2)
        txn.create_processing_block(pblock)

    with cfg.lease() as lease:

        for txn in cfg.txn():
            txn.take_processing_block(pblock_id, lease)

        for txn in cfg.txn():
            assert txn.get_processing_block_owner(pblock_id) == cfg.owner
            assert txn.is_processing_block_owner(pblock_id)

    for txn in cfg.txn():
        assert txn.get_processing_block_owner(pblock_id) is None
        assert not txn.is_processing_block_owner(pblock_id)