Ejemplo n.º 1
0
def test_mount_v3io():
    cases = [
        {
            "mount_path":
            "/custom-mount-path",
            "volume_mounts":
            [mlrun.VolumeMount("/volume-mount-path", "volume-sub-path")],
            "expect_failure":
            True,
        },
        {
            "mount_path":
            "/custom-mount-path",
            "volume_mounts":
            [mlrun.VolumeMount("/volume-mount-path", "volume-sub-path")],
            "remote":
            "~/custom-remote",
            "expect_failure":
            True,
        },
        {
            "mount_path": "/custom-mount-path",
            "remote": "~/custom-remote",
            "set_user": True,
        },
        {
            "mount_path": "/custom-mount-path",
            "set_user": True
        },
        {
            "remote": "~/custom-remote",
            "set_user": True
        },
        {
            "remote":
            "~/custom-remote",
            "volume_mounts":
            [mlrun.VolumeMount("/volume-mount-path", "volume-sub-path")],
            "set_user":
            True,
        },
        {
            "volume_mounts":
            [mlrun.VolumeMount("/volume-mount-path", "volume-sub-path")],
            "set_user":
            True,
        },
        {
            "set_user": True
        },
    ]
    for case in cases:
        username = "******"
        tested_function = mlrun.new_function(
            "tested-function-name",
            "function-project",
            kind=mlrun.runtimes.RuntimeKinds.job,
        )
        expectation_function = mlrun.new_function(
            "expectation-function-name",
            "function-project",
            kind=mlrun.runtimes.RuntimeKinds.job,
        )
        if case.get("set_user"):
            os.environ["V3IO_USERNAME"] = username
            os.environ["V3IO_ACCESS_KEY"] = "access-key"
        else:
            os.environ.pop("V3IO_USERNAME", None)
            os.environ.pop("V3IO_ACCESS_KEY", None)
        mount_v3io_kwargs = {
            "remote": case.get("remote"),
            "mount_path": case.get("mount_path"),
            "volume_mounts": case.get("volume_mounts"),
        }
        mount_v3io_kwargs = {k: v for k, v in mount_v3io_kwargs.items() if v}
        if case.get("expect_failure"):
            with pytest.raises(mlrun.errors.MLRunInvalidArgumentError):
                tested_function.apply(mlrun.mount_v3io(**mount_v3io_kwargs))
Ejemplo n.º 2
0
def test_mount_v3io_extended():
    username = "******"
    access_key = "access-key"
    cases = [
        {
            "set_user":
            True,
            "expected_volume": {
                "flexVolume": {
                    "driver": "v3io/fuse",
                    "options": {
                        "accessKey": access_key
                    },
                },
                "name": "v3io",
            },
            "expected_volume_mounts": [
                {
                    "mountPath": "/User",
                    "name": "v3io",
                    "subPath": f"users/{username}"
                },
                {
                    "mountPath": "/v3io",
                    "name": "v3io",
                    "subPath": ""
                },
            ],
        },
        {
            "remote": "~/custom-remote",
            "expect_failure": True
        },
        {
            "mounts":
            [mlrun.VolumeMount("/volume-mount-path", "volume-sub-path")],
            "remote": "~/custom-remote",
            "expect_failure": True,
        },
        {
            "mounts": [
                mlrun.VolumeMount("/volume-mount-path", "volume-sub-path"),
                mlrun.VolumeMount("/volume-mount-path-2", "volume-sub-path-2"),
            ],
            "remote":
            "~/custom-remote",
            "set_user":
            True,
            "expected_volume": {
                "flexVolume": {
                    "driver": "v3io/fuse",
                    "options": {
                        "accessKey": access_key,
                        "container": "users",
                        "subPath": f"/{username}/custom-remote",
                    },
                },
                "name": "v3io",
            },
            "expected_volume_mounts": [
                {
                    "mountPath": "/volume-mount-path",
                    "name": "v3io",
                    "subPath": "volume-sub-path",
                },
                {
                    "mountPath": "/volume-mount-path-2",
                    "name": "v3io",
                    "subPath": "volume-sub-path-2",
                },
            ],
        },
        {
            "mounts": [
                mlrun.VolumeMount("/volume-mount-path", "volume-sub-path"),
                mlrun.VolumeMount("/volume-mount-path-2", "volume-sub-path-2"),
            ],
            "set_user":
            True,
            "expected_volume": {
                "flexVolume": {
                    "driver": "v3io/fuse",
                    "options": {
                        "accessKey": access_key
                    },
                },
                "name": "v3io",
            },
            "expected_volume_mounts": [
                {
                    "mountPath": "/volume-mount-path",
                    "name": "v3io",
                    "subPath": "volume-sub-path",
                },
                {
                    "mountPath": "/volume-mount-path-2",
                    "name": "v3io",
                    "subPath": "volume-sub-path-2",
                },
            ],
        },
    ]
    for case in cases:
        if case.get("set_user"):
            os.environ["V3IO_USERNAME"] = username
            os.environ["V3IO_ACCESS_KEY"] = access_key
        else:
            os.environ.pop("V3IO_USERNAME", None)
            os.environ.pop("V3IO_ACCESS_KEY", None)

        function = mlrun.new_function("function-name",
                                      "function-project",
                                      kind=mlrun.runtimes.RuntimeKinds.job)
        mount_v3io_extended_kwargs = {
            "remote": case.get("remote"),
            "mounts": case.get("mounts"),
        }
        mount_v3io_extended_kwargs = {
            k: v
            for k, v in mount_v3io_extended_kwargs.items() if v
        }

        if case.get("expect_failure"):
            with pytest.raises(mlrun.errors.MLRunInvalidArgumentError):
                function.apply(
                    mlrun.mount_v3io_extended(**mount_v3io_extended_kwargs))
Ejemplo n.º 3
0
         "remote": case.get("remote"),
         "mount_path": case.get("mount_path"),
     }
 else:
     expectation_modifier = mlrun.mount_v3io_extended
     expectation_modifier_kwargs = {
         "remote": case.get("remote"),
         "mounts": case.get("volume_mounts"),
     }
 expectation_modifier_kwargs = {
     k: v
     for k, v in expectation_modifier_kwargs.items() if v
 }
 if list(mount_v3io_kwargs.keys()) == ["mount_path"]:
     expectation_modifier_kwargs["mounts"] = [
         mlrun.VolumeMount(path="/v3io", sub_path=""),
         mlrun.VolumeMount(
             path=mount_v3io_kwargs["mount_path"],
             sub_path="users/" + username,
         ),
     ]
 expectation_function.apply(
     expectation_modifier(**expectation_modifier_kwargs))
 assert (deepdiff.DeepDiff(
     expectation_function.spec.volumes,
     tested_function.spec.volumes,
     ignore_order=True,
 ) == {})
 assert (deepdiff.DeepDiff(
     expectation_function.spec.volume_mounts,
     tested_function.spec.volume_mounts,