Ejemplo n.º 1
0
def run_actions_parallel(
    actions: List[Action],
    state: defaultdict,
    test_name: str,
    hostnames: List[str],
    seconds_between_actions: float,
) -> ActionsData:
    """
    Runs each action in provided list on each of the provided hosts. For example, if two actions are provided and there
    are two hosts, each action will be run twice (once on each host)

    Args:
        actions: List of actions to run
        state: Initial state of test to provide to actions
        test_name: Name of test
        hostnames: List of host addresses
        seconds_between_actions: Seconds to wait on host before running the next action

    Returns:
        ActionsData generated by running actions in parallel
    """
    actions_task = (
        bag.from_sequence(hostnames)
        .map(
            lambda hostname: run_actions(
                actions, {**state}, hostname, seconds_between_actions
            )
        )
        .fold(combine_action_data, initial=state[test_name].get("actions", {}))
    )

    return actions_task.compute()
Ejemplo n.º 2
0
def test_run_actions_with_asserts_actual_override(get_action_sender_mock):
    get_action_sender_mock.return_value.__enter__.return_value.return_value = {
        "foo": ["fizz", "buzz"]
    }

    test_actions = [{
        "type":
        "POST",
        "name":
        "POST0",
        "params": {
            "foo": "bar"
        },
        "asserts": [{
            "name":
            "Assert0",
            "expected":
            2,
            "template":
            """
                        actual: {{ result['foo']|length }}
                    """,
        }],
    }]

    actions_data = actions.run_actions(test_actions, {}, "", 0)

    assert actions_data["POST0"]["asserts"]["Assert0"][0]["passed"]
Ejemplo n.º 3
0
def test_run_actions(get_action_sender_mock):
    get_action_sender_mock.return_value.__enter__.return_value.return_value = {
        "foo": "bar"
    }

    test_actions = [
        {
            "type": "POST",
            "name": "POST0",
            "executionsPerCycle": 2,
            "params": {
                "foo": "bar"
            },
            "outputs": [{
                "name": "A",
                "value": "xyz"
            }],
        },
        {
            "name": "X",
            "params": {
                "fizz": "buzz"
            }
        },
    ]

    actions_data = actions.run_actions(test_actions, {}, "", 0)

    assert actions_data["POST0"]["results"] == [{"foo": "bar"}, {"foo": "bar"}]
    assert actions_data["POST0"]["outputs"]["A"] == "xyz"
    assert actions_data["X"]["results"] == [{"foo": "bar"}]
Ejemplo n.º 4
0
def test_run_actions_with_asserts(get_action_sender_mock):
    get_action_sender_mock.return_value.__enter__.return_value.return_value = {
        "foo": "bar",
        "fizz": "buzz",
    }

    test_actions = [{
        "type":
        "POST",
        "name":
        "POST0",
        "params": {
            "foo": "bar"
        },
        "asserts": [{
            "name": "Assert0",
            "expected": {
                "foo": "bar"
            }
        }],
    }]

    actions_data = actions.run_actions(test_actions, {}, "", 0)

    assert actions_data["POST0"]["results"] == [{"foo": "bar", "fizz": "buzz"}]
    assert actions_data["POST0"]["asserts"]["Assert0"][0]["passed"]
Ejemplo n.º 5
0
def test_run_actions_with_asserts_multiple_calls_versioned_keep_if_passed(
    get_action_sender_mock, ):
    get_action_sender_mock.return_value.__enter__.return_value.side_effect = [
        {
            "foo": "bar"
        },
        {
            "fizz": "buzz"
        },
    ]

    test_actions = [{
        "type":
        "POST",
        "name":
        "POST0",
        "params": {
            "foo": "bar"
        },
        "executionsPerCycle":
        2,
        "asserts": [
            {
                "name": "Assert0",
                "expected": {
                    "foo": "bar"
                },
                "storeVersions": True,
                "keepIfPassed": True,
            },
            {
                "name": "Assert1",
                "expected": {
                    "fizz": "buzz"
                },
                "storeVersions": True,
                "keepIfPassed": True,
            },
        ],
    }]

    actions_data = actions.run_actions(test_actions, {}, "", 0)

    assert actions_data["POST0"]["results"] == [{
        "foo": "bar"
    }, {
        "fizz": "buzz"
    }]

    # Assert0 passed, then fails
    # Assert1 fails, then passed
    assert actions_data["POST0"]["asserts"]["Assert0"][0]["passed"]
    assert actions_data["POST0"]["asserts"]["Assert1"][1]["passed"]

    assert not actions_data["POST0"]["asserts"]["Assert0"][1]["passed"]
    assert not actions_data["POST0"]["asserts"]["Assert1"][0]["passed"]
Ejemplo n.º 6
0
def run_actions_series(
    actions: List[Action],
    state: defaultdict,
    test_name: str,
    hostnames: List[str],
    seconds_between_actions: float,
) -> ActionsData:
    """
    Runs each action distributed into each host. For example, If there are two hosts and two actions, each action will
    be run once, one action per host

    Args:
        actions: List of actions to run
        state: Initial state of test to provide to actions
        test_name: Name of test
        hostnames: List of host addresses
        seconds_between_actions: Seconds to wait on host before running the next action

    Returns:
        ActionsData generated by running actions in series
    """
    hostname_actions_map: Dict[str, List[Action]] = {}

    for hostname_action in zip(cycle(hostnames), actions):
        hostname = hostname_action[0]
        action = hostname_action[1]

        if hostname not in hostname_actions_map:
            hostname_actions_map[hostname] = [action]
        else:
            hostname_actions_map[hostname] += [action]

    actions_task = (
        bag.from_sequence(hostname_actions_map)
        .map(
            lambda h_name: run_actions(
                hostname_actions_map[h_name], {**state}, h_name, seconds_between_actions
            )
        )
        .fold(combine_action_data, initial=state[test_name].get("actions", {}))
    )

    return actions_task.compute()