Exemple #1
0
def test_notification():
    phases = [
        _execution.WorkflowExecutionPhase.FAILED,
        _execution.WorkflowExecutionPhase.SUCCEEDED,
    ]
    recipients = ["a", "b", "c"]

    obj = _common.Notification(phases,
                               email=_common.EmailNotification(recipients))
    assert obj.phases == phases
    assert obj.email.recipients_email == recipients
    obj2 = _common.Notification.from_flyte_idl(obj.to_flyte_idl())
    assert obj == obj2
    assert obj2.phases == phases
    assert obj2.email.recipients_email == recipients

    obj = _common.Notification(
        phases, pager_duty=_common.PagerDutyNotification(recipients))
    assert obj.phases == phases
    assert obj.pager_duty.recipients_email == recipients
    obj2 = _common.Notification.from_flyte_idl(obj.to_flyte_idl())
    assert obj == obj2
    assert obj2.phases == phases
    assert obj2.pager_duty.recipients_email == recipients

    obj = _common.Notification(phases,
                               slack=_common.SlackNotification(recipients))
    assert obj.phases == phases
    assert obj.slack.recipients_email == recipients
    obj2 = _common.Notification.from_flyte_idl(obj.to_flyte_idl())
    assert obj == obj2
    assert obj2.phases == phases
    assert obj2.slack.recipients_email == recipients
Exemple #2
0
def test_execution_notification_soft_overrides(mock_client_factory):
    mock_client = MagicMock()
    mock_client.create_execution = MagicMock(
        return_value=identifier.WorkflowExecutionIdentifier('xp', 'xd', 'xn'))
    mock_client_factory.return_value = mock_client

    m = MagicMock()
    type(m).id = PropertyMock(return_value=identifier.Identifier(
        identifier.ResourceType.LAUNCH_PLAN, "project", "domain", "name",
        "version"))

    notification = _common_models.Notification(
        [0, 1, 2], email=_common_models.EmailNotification(["*****@*****.**"]))

    engine.FlyteLaunchPlan(m).execute('xp',
                                      'xd',
                                      'xn',
                                      literals.LiteralMap({}),
                                      notification_overrides=[notification])

    mock_client.create_execution.assert_called_once_with(
        'xp', 'xd', 'xn',
        _execution_models.ExecutionSpec(
            identifier.Identifier(identifier.ResourceType.LAUNCH_PLAN,
                                  "project", "domain", "name", "version"),
            literals.LiteralMap({}),
            _execution_models.ExecutionMetadata(
                _execution_models.ExecutionMetadata.ExecutionMode.MANUAL,
                'sdk', 0),
            notifications=_execution_models.NotificationList([notification]),
        ))
Exemple #3
0
def test_execution_spec(literal_value_pair):
    literal_value, _ = literal_value_pair

    obj = _execution.ExecutionSpec(
        _identifier.Identifier(_identifier.ResourceType.LAUNCH_PLAN, "project",
                               "domain", "name", "version"),
        _execution.ExecutionMetadata(
            _execution.ExecutionMetadata.ExecutionMode.MANUAL, "tester", 1),
        notifications=_execution.NotificationList([
            _common_models.Notification(
                [_core_exec.WorkflowExecutionPhase.ABORTED],
                pager_duty=_common_models.PagerDutyNotification(
                    recipients_email=["a", "b", "c"]),
            )
        ]),
    )
    assert obj.launch_plan.resource_type == _identifier.ResourceType.LAUNCH_PLAN
    assert obj.launch_plan.domain == "domain"
    assert obj.launch_plan.project == "project"
    assert obj.launch_plan.name == "name"
    assert obj.launch_plan.version == "version"
    assert obj.metadata.mode == _execution.ExecutionMetadata.ExecutionMode.MANUAL
    assert obj.metadata.nesting == 1
    assert obj.metadata.principal == "tester"
    assert obj.notifications.notifications[0].phases == [
        _core_exec.WorkflowExecutionPhase.ABORTED
    ]
    assert obj.notifications.notifications[0].pager_duty.recipients_email == [
        "a",
        "b",
        "c",
    ]
    assert obj.disable_all is None

    obj2 = _execution.ExecutionSpec.from_flyte_idl(obj.to_flyte_idl())
    assert obj == obj2
    assert obj2.launch_plan.resource_type == _identifier.ResourceType.LAUNCH_PLAN
    assert obj2.launch_plan.domain == "domain"
    assert obj2.launch_plan.project == "project"
    assert obj2.launch_plan.name == "name"
    assert obj2.launch_plan.version == "version"
    assert obj2.metadata.mode == _execution.ExecutionMetadata.ExecutionMode.MANUAL
    assert obj2.metadata.nesting == 1
    assert obj2.metadata.principal == "tester"
    assert obj2.notifications.notifications[0].phases == [
        _core_exec.WorkflowExecutionPhase.ABORTED
    ]
    assert obj2.notifications.notifications[0].pager_duty.recipients_email == [
        "a",
        "b",
        "c",
    ]
    assert obj2.disable_all is None

    obj = _execution.ExecutionSpec(
        _identifier.Identifier(_identifier.ResourceType.LAUNCH_PLAN, "project",
                               "domain", "name", "version"),
        _execution.ExecutionMetadata(
            _execution.ExecutionMetadata.ExecutionMode.MANUAL, "tester", 1),
        disable_all=True,
    )
    assert obj.launch_plan.resource_type == _identifier.ResourceType.LAUNCH_PLAN
    assert obj.launch_plan.domain == "domain"
    assert obj.launch_plan.project == "project"
    assert obj.launch_plan.name == "name"
    assert obj.launch_plan.version == "version"
    assert obj.metadata.mode == _execution.ExecutionMetadata.ExecutionMode.MANUAL
    assert obj.metadata.nesting == 1
    assert obj.metadata.principal == "tester"
    assert obj.notifications is None
    assert obj.disable_all is True

    obj2 = _execution.ExecutionSpec.from_flyte_idl(obj.to_flyte_idl())
    assert obj == obj2
    assert obj2.launch_plan.resource_type == _identifier.ResourceType.LAUNCH_PLAN
    assert obj2.launch_plan.domain == "domain"
    assert obj2.launch_plan.project == "project"
    assert obj2.launch_plan.name == "name"
    assert obj2.launch_plan.version == "version"
    assert obj2.metadata.mode == _execution.ExecutionMetadata.ExecutionMode.MANUAL
    assert obj2.metadata.nesting == 1
    assert obj2.metadata.principal == "tester"
    assert obj2.notifications is None
    assert obj2.disable_all is True