Exemplo n.º 1
0
 def to_flyte_idl(self):
     """
     :rtype: flyteidl.admin.launch_plan_pb2.Auth
     """
     return _launch_plan.Auth(
         assumable_iam_role=self.assumable_iam_role
         if self.assumable_iam_role else None,
         kubernetes_service_account=self.kubernetes_service_account
         if self.kubernetes_service_account else None,
     )
Exemplo n.º 2
0
def test_old_style_role():
    identifier_model = identifier.Identifier(identifier.ResourceType.TASK,
                                             "project", "domain", "name",
                                             "version")

    s = schedule.Schedule("asdf", "1 3 4 5 6 7")
    launch_plan_metadata_model = launch_plan.LaunchPlanMetadata(
        schedule=s, notifications=[])

    v = interface.Variable(types.LiteralType(simple=types.SimpleType.BOOLEAN),
                           "asdf asdf asdf")
    p = interface.Parameter(var=v)
    parameter_map = interface.ParameterMap({"ppp": p})

    fixed_inputs = literals.LiteralMap({
        "a":
        literals.Literal(scalar=literals.Scalar(primitive=literals.Primitive(
            integer=1)))
    })

    labels_model = common.Labels({})
    annotations_model = common.Annotations({"my": "annotation"})

    raw_data_output_config = common.RawOutputDataConfig("s3://bucket")

    old_role = _launch_plan_idl.Auth(
        kubernetes_service_account="my:service:account")

    old_style_spec = _launch_plan_idl.LaunchPlanSpec(
        workflow_id=identifier_model.to_flyte_idl(),
        entity_metadata=launch_plan_metadata_model.to_flyte_idl(),
        default_inputs=parameter_map.to_flyte_idl(),
        fixed_inputs=fixed_inputs.to_flyte_idl(),
        labels=labels_model.to_flyte_idl(),
        annotations=annotations_model.to_flyte_idl(),
        raw_output_data_config=raw_data_output_config.to_flyte_idl(),
        auth=old_role,
    )

    lp_spec = launch_plan.LaunchPlanSpec.from_flyte_idl(old_style_spec)

    assert lp_spec.auth_role.assumable_iam_role == "my:service:account"
Exemplo n.º 3
0
def test_lp_each_parameter():
    @task
    def t1(a: int) -> typing.NamedTuple("OutputsBC", t1_int_output=int, c=str):
        a = a + 2
        return a, "world-" + str(a)

    @workflow
    def wf(a: int, c: str) -> (int, str):
        x, y = t1(a=a)
        return x, y

    # Fixed Inputs Parameter
    launch_plan.LaunchPlan.get_or_create(workflow=wf,
                                         name="get_or_create_fixed",
                                         fixed_inputs={
                                             "a": 1,
                                             "c": "4"
                                         })
    with pytest.raises(AssertionError):
        launch_plan.LaunchPlan.get_or_create(workflow=wf,
                                             name="get_or_create_fixed")

    # Schedule Parameter
    obj = CronSchedule("* * ? * * *", kickoff_time_input_arg="abc")
    schedule_lp = launch_plan.LaunchPlan.get_or_create(
        workflow=wf, name="get_or_create_schedule", schedule=obj)
    schedule_lp1 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf, name="get_or_create_schedule", schedule=obj)

    assert schedule_lp is schedule_lp1

    # Default Inputs Parameter
    launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_schedule_def_inputs",
        default_inputs={"a": 9})
    with pytest.raises(AssertionError):
        launch_plan.LaunchPlan.get_or_create(
            workflow=wf,
            name="get_or_create_schedule_def_inputs",
            default_inputs={"a": 19})

    # Notifications Parameter
    email_notif = notification.Email(
        phases=[_execution_model.WorkflowExecutionPhase.SUCCEEDED],
        recipients_email=["*****@*****.**"])
    notification_lp = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_notification",
        notifications=[email_notif])
    notification_lp1 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_notification",
        notifications=[email_notif])

    assert notification_lp is notification_lp1

    # Auth Parameter
    auth_role_model1 = AuthRole(assumable_iam_role="my:iam:role")
    auth_role_model2 = _launch_plan_idl.Auth(
        kubernetes_service_account="my:service:account")
    launch_plan.LaunchPlan.get_or_create(workflow=wf,
                                         name="get_or_create_auth",
                                         auth_role=auth_role_model1)
    with pytest.raises(AssertionError):
        launch_plan.LaunchPlan.get_or_create(workflow=wf,
                                             name="get_or_create_auth",
                                             auth_role=auth_role_model2)

    # Labels parameters
    labels_model1 = Labels({"label": "foo"})
    labels_model2 = Labels({"label": "foo"})
    labels_lp1 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf, name="get_or_create_labels", labels=labels_model1)
    labels_lp2 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf, name="get_or_create_labels", labels=labels_model2)
    assert labels_lp1 is labels_lp2

    # Annotations parameters
    annotations_model1 = Annotations({"anno": "bar"})
    annotations_model2 = Annotations({"anno": "bar"})
    annotations_lp1 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_annotations",
        annotations=annotations_model1)
    annotations_lp2 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_annotations",
        annotations=annotations_model2)
    assert annotations_lp1 is annotations_lp2

    # Raw output prefix parameters
    raw_output_data_config1 = RawOutputDataConfig("s3://foo/output")
    raw_output_data_config2 = RawOutputDataConfig("s3://foo/output")
    raw_output_data_config_lp1 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_raw_output_prefix",
        raw_output_data_config=raw_output_data_config1)
    raw_output_data_config_lp2 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_raw_output_prefix",
        raw_output_data_config=raw_output_data_config2)
    assert raw_output_data_config_lp1 is raw_output_data_config_lp2

    # Max parallelism
    max_parallelism = 100
    max_parallelism_lp1 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_max_parallelism",
        max_parallelism=max_parallelism,
    )
    max_parallelism_lp2 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_max_parallelism",
        max_parallelism=max_parallelism,
    )
    assert max_parallelism_lp1 is max_parallelism_lp2

    # Labels parameters
    labels_model1 = Labels({"label": "foo"})
    labels_model2 = Labels({"label": "foo"})
    labels_lp1 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf, name="get_or_create_labels", labels=labels_model1)
    labels_lp2 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf, name="get_or_create_labels", labels=labels_model2)
    assert labels_lp1 is labels_lp2

    # Annotations parameters
    annotations_model1 = Annotations({"anno": "bar"})
    annotations_model2 = Annotations({"anno": "bar"})
    annotations_lp1 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_annotations",
        annotations=annotations_model1)
    annotations_lp2 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_annotations",
        annotations=annotations_model2)
    assert annotations_lp1 is annotations_lp2

    # Raw output prefix parameters
    raw_output_data_config1 = RawOutputDataConfig("s3://foo/output")
    raw_output_data_config2 = RawOutputDataConfig("s3://foo/output")
    raw_output_data_config_lp1 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_raw_output_prefix",
        raw_output_data_config=raw_output_data_config1)
    raw_output_data_config_lp2 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_raw_output_prefix",
        raw_output_data_config=raw_output_data_config2)
    assert raw_output_data_config_lp1 is raw_output_data_config_lp2

    # Max parallelism
    max_parallelism = 100
    max_parallelism_lp1 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_max_parallelism",
        max_parallelism=max_parallelism,
    )
    max_parallelism_lp2 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_max_parallelism",
        max_parallelism=max_parallelism,
    )
    assert max_parallelism_lp1 is max_parallelism_lp2

    # Labels parameters
    labels_model1 = Labels({"label": "foo"})
    labels_model2 = Labels({"label": "foo"})
    labels_lp1 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf, name="get_or_create_labels", labels=labels_model1)
    labels_lp2 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf, name="get_or_create_labels", labels=labels_model2)
    assert labels_lp1 is labels_lp2

    # Annotations parameters
    annotations_model1 = Annotations({"anno": "bar"})
    annotations_model2 = Annotations({"anno": "bar"})
    annotations_lp1 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_annotations",
        annotations=annotations_model1)
    annotations_lp2 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_annotations",
        annotations=annotations_model2)
    assert annotations_lp1 is annotations_lp2

    # Raw output prefix parameters
    raw_output_data_config1 = RawOutputDataConfig("s3://foo/output")
    raw_output_data_config2 = RawOutputDataConfig("s3://foo/output")
    raw_output_data_config_lp1 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_raw_output_prefix",
        raw_output_data_config=raw_output_data_config1)
    raw_output_data_config_lp2 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_raw_output_prefix",
        raw_output_data_config=raw_output_data_config2)
    assert raw_output_data_config_lp1 is raw_output_data_config_lp2

    # Max parallelism
    max_parallelism = 100
    max_parallelism_lp1 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_max_parallelism",
        max_parallelism=max_parallelism,
    )
    max_parallelism_lp2 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_max_parallelism",
        max_parallelism=max_parallelism,
    )
    assert max_parallelism_lp1 is max_parallelism_lp2

    # Default LaunchPlan
    name_lp = launch_plan.LaunchPlan.get_or_create(workflow=wf)
    name_lp1 = launch_plan.LaunchPlan.get_or_create(workflow=wf)

    assert name_lp is name_lp1
Exemplo n.º 4
0
def test_lp_each_parameter():
    @task
    def t1(a: int) -> typing.NamedTuple("OutputsBC", t1_int_output=int, c=str):
        a = a + 2
        return a, "world-" + str(a)

    @workflow
    def wf(a: int, c: str) -> (int, str):
        x, y = t1(a=a)
        return x, y

    # Fixed Inputs Parameter
    fixed_lp = launch_plan.LaunchPlan.get_or_create(workflow=wf,
                                                    name="get_or_create_fixed",
                                                    fixed_inputs={
                                                        "a": 1,
                                                        "c": "4"
                                                    })
    fixed_lp1 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf, name="get_or_create_fixed")

    with pytest.raises(AssertionError):
        assert fixed_lp is fixed_lp1

    # Schedule Parameter
    obj = CronSchedule("* * ? * * *", kickoff_time_input_arg="abc")
    schedule_lp = launch_plan.LaunchPlan.get_or_create(
        workflow=wf, name="get_or_create_schedule", schedule=obj)
    schedule_lp1 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf, name="get_or_create_schedule", schedule=obj)

    assert schedule_lp is schedule_lp1

    # Default Inputs Parameter
    default_lp = launch_plan.LaunchPlan.get_or_create(
        workflow=wf, name="get_or_create_schedule", default_inputs={"a": 9})
    default_lp1 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf, name="get_or_create_schedule", default_inputs={"a": 19})

    # Validates both schedule and default inputs owing to the same launch plan
    with pytest.raises(AssertionError):
        assert default_lp is default_lp1

    # Notifications Parameter
    email_notif = notification.Email(
        phases=[_execution_model.WorkflowExecutionPhase.SUCCEEDED],
        recipients_email=["*****@*****.**"])
    notification_lp = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_notification",
        notifications=email_notif)
    notification_lp1 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_notification",
        notifications=email_notif)

    assert notification_lp is notification_lp1

    # Auth Parameter
    auth_role_model1 = AuthRole(assumable_iam_role="my:iam:role")
    auth_role_model2 = _launch_plan_idl.Auth(
        kubernetes_service_account="my:service:account")
    auth_lp = launch_plan.LaunchPlan.get_or_create(workflow=wf,
                                                   name="get_or_create_auth",
                                                   auth_role=auth_role_model1)
    auth_lp1 = launch_plan.LaunchPlan.get_or_create(workflow=wf,
                                                    name="get_or_create_auth",
                                                    auth_role=auth_role_model2)

    with pytest.raises(AssertionError):
        assert auth_lp is auth_lp1

    # Default LaunchPlan
    name_lp = launch_plan.LaunchPlan.get_or_create(workflow=wf)
    name_lp1 = launch_plan.LaunchPlan.get_or_create(workflow=wf)

    assert name_lp is name_lp1