예제 #1
0
def test_constraints_all_not_match(fake_dict):
    assert not attributes_match_constraints(
        fake_dict,
        [
            Constraint(
                attribute='region',
                operator='==',
                value='another_fake_region_text',
            ),
            Constraint(
                attribute='pool',
                operator='==',
                value='fake_pool_text',
            ),
        ],
    )
    assert not attributes_match_constraints(
        fake_dict,
        [
            Constraint(
                attribute='region',
                operator='==',
                value='fake_region_text',
            ),
            Constraint(
                attribute='pool',
                operator='==',
                value='another_fake_pool_text',
            ),
        ],
    )
예제 #2
0
def test_constraints_LIKE_not_match(fake_dict):
    assert not attributes_match_constraints(
        fake_dict,
        [
            Constraint(
                attribute='region',
                operator='LIKE',
                value='another_fak.*t..t',
            ),
        ],
    )
    assert not attributes_match_constraints(
        fake_dict,
        [Constraint(attribute='region', operator='LIKE', value='fake_region')])
예제 #3
0
def test_constraints_EQUALS_not_match(fake_dict):
    assert not attributes_match_constraints(
        fake_dict,
        [
            Constraint(
                attribute='region',
                operator='EQUALS',
                value='another_fake_region_text',
            ),
        ],
    )
예제 #4
0
def test_constraints_ne_not_match(fake_dict):
    assert not attributes_match_constraints(
        fake_dict,
        [
            Constraint(
                attribute='region',
                operator='!=',
                value='fake_region_text',
            ),
        ],
    )
예제 #5
0
def test_constraints_ne_match(fake_dict):
    assert attributes_match_constraints(
        fake_dict,
        [
            Constraint(
                attribute='region',
                operator='!=',
                value='another_fake_region_text',
            ),
        ],
    )
    assert attributes_match_constraints(
        fake_dict,
        [
            Constraint(
                attribute='fake_attribute_name',
                operator='!=',
                value='random_text',
            ),
        ],
    )
예제 #6
0
def test_constraints_LIKE_match(fake_dict):
    assert attributes_match_constraints(
        fake_dict,
        [
            Constraint(
                attribute='region',
                operator='LIKE',
                value='fak.*t..t',
            ),
        ],
    )
    assert attributes_match_constraints(
        fake_dict,
        [
            Constraint(
                attribute='fake_attribute_name',
                operator='LIKE',
                value='random_text',
            ),
        ],
    )
def test_offer_matches_constraints_no_match(ef, fake_offer):
    attributes = {
        attribute.name: attribute.text.value for attribute in fake_offer.attributes}
    fake_task = MesosTaskConfig(
        image='fake_image',
        cmd='echo "fake"',
        constraints=[
            ['region', '==', 'another_fake_region_text'],
        ],
    )
    match = attributes_match_constraints(attributes, fake_task.constraints)
    assert not match
예제 #8
0
def get_tasks_for_offer(
    task_configs: List[MesosTaskConfig],
    offer_resources: ResourceSet,
    offer_attributes: dict,
    role: str,
) -> Tuple[List[MesosTaskConfig], List[MesosTaskConfig]]:

    tasks_to_launch, tasks_to_defer = [], []

    for task_config in task_configs:
        if (task_fits(task_config, offer_resources)
                and attributes_match_constraints(offer_attributes,
                                                 task_config.constraints)):
            prepared_task_config, offer_resources = allocate_task_resources(
                task_config,
                offer_resources,
            )
            tasks_to_launch.append(prepared_task_config)
        else:
            tasks_to_defer.append(task_config)

    return tasks_to_launch, tasks_to_defer
def test_offer_matches_constraints_no_constraints(ef, fake_task, fake_offer):
    attributes = {
        attribute.name: attribute.value for attribute in fake_offer.attributes}
    match = attributes_match_constraints(attributes, fake_task.constraints)
    assert match