Esempio n. 1
0
    def test_claim_connect_config(self):
        config_dict = {}
        with self.assertRaises(ValidationError):
            V1ClaimConnection.from_dict(config_dict)

        with self.assertRaises(ValidationError):
            validate_connection(V1ConnectionKind.VOLUME_CLAIM, config_dict)

        config_dict = {"volumeClaim": "foo"}
        with self.assertRaises(ValidationError):
            V1ClaimConnection.from_dict(config_dict)

        with self.assertRaises(ValidationError):
            validate_connection(V1ConnectionKind.VOLUME_CLAIM, config_dict)

        config_dict = {
            "volumeClaim": "foo",
            "mountPath": "foo",
            "readOnly": True
        }
        config = V1ClaimConnection.from_dict(config_dict)
        assert config.to_dict() == config_dict

        with self.assertRaises(ValidationError):
            validate_connection(V1ConnectionKind.S3, config_dict)

        with self.assertRaises(ValidationError):
            validate_connection(V1ConnectionKind.WASB, config_dict)

        validate_connection(V1ConnectionKind.VOLUME_CLAIM, config_dict)
Esempio n. 2
0
    def test_get_base_store_container_with_mount_store(self):
        claim_store = V1ConnectionType(
            name="test_claim",
            kind=V1ConnectionKind.VOLUME_CLAIM,
            schema=V1ClaimConnection(mount_path="/tmp",
                                     volume_claim="test",
                                     read_only=True),
        )

        container = get_base_store_container(
            container=k8s_schemas.V1Container(name="init"),
            container_name="init",
            polyaxon_init=V1PolyaxonInitContainer(image_tag=""),
            store=claim_store,
            env=None,
            env_from=None,
            volume_mounts=None,
            args=None,
        )
        assert container.name == "init"
        assert container.image == "polyaxon/polyaxon-init"
        assert container.image_pull_policy is None
        assert container.command == ["/bin/sh", "-c"]
        assert container.args is None
        assert container.env == get_connection_env_var(connection=claim_store,
                                                       secret=None)
        assert container.env_from == []
        assert container.resources is not None
        assert container.volume_mounts == [
            get_mount_from_store(store=claim_store)
        ]
Esempio n. 3
0
 def setUp(self):
     super().setUp()
     self.s3_store = V1ConnectionType(
         name="test",
         kind=V1ConnectionKind.S3,
         schema=V1BucketConnection(bucket="s3//:foo"),
     )
     self.gcs_store = V1ConnectionType(
         name="test",
         kind=V1ConnectionKind.GCS,
         schema=V1BucketConnection(bucket="gs//:foo"),
     )
     self.az_store = V1ConnectionType(
         name="test",
         kind=V1ConnectionKind.WASB,
         schema=V1BucketConnection(
             bucket="Conwasb://[email protected]"),
     )
     self.claim_store = V1ConnectionType(
         name="test",
         kind=V1ConnectionKind.VOLUME_CLAIM,
         schema=V1ClaimConnection(volume_claim="test",
                                  mount_path="/tmp",
                                  read_only=True),
     )
     self.host_path_store = V1ConnectionType(
         name="test",
         kind=V1ConnectionKind.HOST_PATH,
         schema=V1HostPathConnection(host_path="/tmp",
                                     mount_path="/tmp",
                                     read_only=True),
     )
Esempio n. 4
0
    def test_get_artifacts_path_container_with_managed_mount_store(self):
        store = V1ConnectionType(
            name="test_gcs",
            kind=V1ConnectionKind.VOLUME_CLAIM,
            schema=V1ClaimConnection(mount_path="/claim/path",
                                     volume_claim="claim"),
        )
        container = get_artifacts_path_container(
            polyaxon_init=V1PolyaxonInitContainer(
                image="init", image_pull_policy="IfNotPresent"),
            artifacts_store=store,
            run_path="run_uid",
            auto_resume=True,
        )

        init_args = init_artifact_context_args("run_uid")
        init_args.append(
            get_volume_args(
                store=store,
                mount_path=CONTEXT_MOUNT_ARTIFACTS,
                artifacts=V1ArtifactsType(dirs=["run_uid"]),
            ))

        assert container == get_base_store_container(
            container=k8s_schemas.V1Container(name="default"),
            container_name=INIT_ARTIFACTS_CONTAINER.format("default"),
            polyaxon_init=V1PolyaxonInitContainer(
                image="init", image_pull_policy="IfNotPresent"),
            store=store,
            env=[],
            env_from=[],
            volume_mounts=[get_artifacts_context_mount()],
            args=[" ".join(init_args)],
        )
Esempio n. 5
0
    def test_get_sidecar_container_with_non_managed_mount_outputs_logs_store(
            self):
        env_vars = [
            get_env_var(name="key1", value="value1"),
            get_env_var(name="key2", value="value2"),
        ]
        mount_non_managed_store = V1ConnectionType(
            name="test_claim",
            kind=V1ConnectionKind.VOLUME_CLAIM,
            schema=V1ClaimConnection(volume_claim="test",
                                     mount_path="/tmp",
                                     read_only=True),
        )
        sidecar = get_sidecar_container(
            container_id=MAIN_JOB_CONTAINER,
            env=env_vars,
            polyaxon_sidecar=V1PolyaxonSidecarContainer(
                image="sidecar/sidecar",
                image_pull_policy="IfNotPresent",
                sleep_interval=213,
                sync_interval=-1,
            ),
            artifacts_store=mount_non_managed_store,
            contexts=PluginsContextsSpec.from_config(
                V1Plugins(collect_logs=False,
                          collect_artifacts=False,
                          auth=True)),
            run_path=None,
        )

        assert sidecar is None
Esempio n. 6
0
 def test_get_store_container_mount_stores(self):
     # Managed store
     store = V1ConnectionType(
         name="test_claim",
         kind=V1ConnectionKind.VOLUME_CLAIM,
         schema=V1ClaimConnection(
             mount_path="/tmp", volume_claim="test", read_only=True
         ),
     )
     container = get_store_container(
         polyaxon_init=V1PolyaxonInitContainer(
             image="foo/foo", image_tag="foo", image_pull_policy="IfNotPresent"
         ),
         connection=store,
         artifacts=None,
     )
     mount_path = CONTEXT_MOUNT_ARTIFACTS_FORMAT.format(store.name)
     assert container.name == INIT_ARTIFACTS_CONTAINER.format(store.name)
     assert container.image == "foo/foo:foo"
     assert container.image_pull_policy == "IfNotPresent"
     assert container.command == ["/bin/sh", "-c"]
     assert container.args == [
         get_volume_args(store=store, mount_path=mount_path, artifacts=None)
     ]
     assert container.env == get_connection_env_var(connection=store, secret=None)
     assert container.env_from == []
     assert container.resources is not None
     assert container.volume_mounts == [
         get_connections_context_mount(
             name=constants.CONTEXT_VOLUME_ARTIFACTS,
             mount_path=CONTEXT_MOUNT_ARTIFACTS_FORMAT.format(store.name),
         ),
         get_mount_from_store(store=store),
     ]
Esempio n. 7
0
 def test_get_base_container(self):
     store = V1ConnectionType(
         name="test_claim",
         kind=V1ConnectionKind.VOLUME_CLAIM,
         schema=V1ClaimConnection(mount_path="/tmp",
                                  volume_claim="test",
                                  read_only=True),
     )
     env = [get_env_var(name="key", value="value")]
     env_from = [k8s_schemas.V1EnvFromSource(secret_ref={"name": "ref"})]
     mounts = [k8s_schemas.V1VolumeMount(name="test", mount_path="/test")]
     container = get_base_store_container(
         container=k8s_schemas.V1Container(name="init"),
         container_name="init",
         polyaxon_init=V1PolyaxonInitContainer(
             image="foo/foo",
             image_tag="",
             image_pull_policy="IfNotPresent"),
         store=store,
         env=env,
         env_from=env_from,
         volume_mounts=mounts,
         args=["test"],
     )
     assert container.name == "init"
     assert container.image == "foo/foo"
     assert container.image_pull_policy == "IfNotPresent"
     assert container.command == ["/bin/sh", "-c"]
     assert container.args == ["test"]
     assert container.env == env
     assert container.env_from == env_from
     assert container.resources is not None
     assert container.volume_mounts == mounts + [
         get_mount_from_store(store=store)
     ]
Esempio n. 8
0
    def test_get_mount_from_store(self):
        # Non bucket stores
        assert get_mount_from_store(store=None) is None
        store = V1ConnectionType(
            name="test",
            kind=V1ConnectionKind.S3,
            schema=V1BucketConnection(bucket="s3//:foo"),
        )
        assert get_mount_from_store(store=store) is None

        # Claim store
        store = V1ConnectionType(
            name="test",
            kind=V1ConnectionKind.VOLUME_CLAIM,
            schema=V1ClaimConnection(mount_path="/tmp",
                                     volume_claim="test",
                                     read_only=True),
        )
        mount = get_mount_from_store(store=store)
        assert mount.name == store.name
        assert mount.mount_path == store.schema.mount_path
        assert mount.read_only == store.schema.read_only

        # Host path
        store = V1ConnectionType(
            name="test",
            kind=V1ConnectionKind.HOST_PATH,
            schema=V1HostPathConnection(mount_path="/tmp",
                                        host_path="/tmp",
                                        read_only=True),
        )
        mount = get_mount_from_store(store=store)
        assert mount.name == store.name
        assert mount.mount_path == store.schema.mount_path
        assert mount.read_only == store.schema.read_only
Esempio n. 9
0
    def test_resolver_init_and_connections_contexts(self):
        store = V1ConnectionType(
            name="test_claim",
            kind=V1ConnectionKind.VOLUME_CLAIM,
            schema=V1ClaimConnection(
                mount_path="/claim/path", volume_claim="claim", read_only=True
            ),
        )

        compiled_operation = V1CompiledOperation.read(
            {
                "version": 1.05,
                "kind": kinds.COMPILED_OPERATION,
                "plugins": {
                    "auth": False,
                    "shm": False,
                    "collectLogs": False,
                    "collectArtifacts": False,
                    "collectResources": False,
                },
                "run": {
                    "kind": V1RunKind.JOB,
                    "container": {"image": "test"},
                    "connections": [store.name],
                    "init": [{"connection": store.name}],
                },
            }
        )
        spec = resolve_contexts(
            namespace="test",
            owner_name="user",
            project_name="project",
            project_uuid="uuid",
            run_uuid="uuid",
            run_name="run",
            run_path="test",
            compiled_operation=compiled_operation,
            artifacts_store=store,
            connection_by_names={store.name: store},
            iteration=12,
        )
        assert spec == {
            "globals": {
                "owner_name": "user",
                "project_unique_name": "user.project",
                "project_name": "project",
                "project_uuid": "uuid",
                "name": "run",
                "uuid": "uuid",
                "artifacts_path": "/claim/path/test",
                "namespace": "test",
                "iteration": 12,
                "run_info": "user.project.runs.uuid",
            },
            "init": {"test_claim": store.schema.to_dict()},
            "connections": {"test_claim": store.schema.to_dict()},
        }
Esempio n. 10
0
    def test_get_volume_args_claim(self):
        claim_store = V1ConnectionType(
            name="test_claim",
            kind=V1ConnectionKind.VOLUME_CLAIM,
            schema=V1ClaimConnection(mount_path="/tmp",
                                     volume_claim="test",
                                     read_only=True),
        )
        path_to = "/path/to/"
        path_from = os.path.join(claim_store.store_path, "")
        assert get_volume_args(claim_store, path_to, None) == "; ".join([
            get_or_create_args(path=path_to),
            cp_copy_args(path_from=path_from, path_to=path_to, is_file=False),
        ])

        claim_store = V1ConnectionType(
            name="test_claim",
            kind=V1ConnectionKind.VOLUME_CLAIM,
            schema=V1ClaimConnection(mount_path="/tmp",
                                     volume_claim="test",
                                     read_only=True),
        )
        base_path = "/path/to/"
        path_to1 = "/path/to/path1"
        path_to2 = "/path/to/path2"
        path_from1 = os.path.join(claim_store.store_path, "path1")
        path_from2 = os.path.join(claim_store.store_path, "path2")
        assert get_volume_args(
            claim_store,
            "/path/to",
            artifacts=V1ArtifactsType(files=["path1", "path2"])) == "; ".join([
                get_or_create_args(path=base_path),
                cp_copy_args(path_from=path_from1,
                             path_to=path_to1,
                             is_file=True),
                get_or_create_args(path=base_path),
                cp_copy_args(path_from=path_from2,
                             path_to=path_to2,
                             is_file=True),
            ])
Esempio n. 11
0
    def setUp(self):
        super().setUp()
        # Secrets
        self.resource1 = V1K8sResourceType(
            name="non_mount_test1",
            schema=V1K8sResourceSchema(name="ref", items=["item1", "item2"]),
            is_requested=False,
        )
        self.resource2 = V1K8sResourceType(
            name="non_mount_test2",
            schema=V1K8sResourceSchema(name="ref"),
            is_requested=False,
        )

        self.resource3 = V1K8sResourceType(
            name="non_mount_test1",
            schema=V1K8sResourceSchema(name="ref", items=["item1", "item2"]),
            is_requested=True,
        )
        self.resource4 = V1K8sResourceType(
            name="non_mount_test2",
            schema=V1K8sResourceSchema(name="ref"),
            is_requested=True,
        )

        self.resource5 = V1K8sResourceType(
            name="non_mount_test2",
            schema=V1K8sResourceSchema(name="ref"),
            is_requested=True,
        )

        self.resource6 = V1K8sResourceType(
            name="mount_test",
            schema=V1K8sResourceSchema(name="ref", mount_path="/test"),
            is_requested=True,
        )
        # Connections
        self.bucket_store = V1ConnectionType(
            name="test_s3",
            kind=V1ConnectionKind.S3,
            schema=V1BucketConnection(bucket="s3//:foo"),
            secret=self.resource3.schema,
        )
        self.mount_store = V1ConnectionType(
            name="test_claim",
            kind=V1ConnectionKind.VOLUME_CLAIM,
            schema=V1ClaimConnection(mount_path="/tmp",
                                     volume_claim="test",
                                     read_only=True),
        )
Esempio n. 12
0
    def test_get_main_container_with_logs_store_with_wrong_paths_raises(self):
        artifacts_store = V1ConnectionType(
            name="test_s3",
            kind=V1ConnectionKind.S3,
            schema=V1BucketConnection(bucket="s3//:foo"),
        )
        self.assert_artifacts_store_raises(store=artifacts_store)

        artifacts_store = V1ConnectionType(
            name="test_s3",
            kind=V1ConnectionKind.VOLUME_CLAIM,
            schema=V1ClaimConnection(volume_claim="foo", mount_path="/foo"),
        )
        self.assert_artifacts_store_raises(store=artifacts_store)
Esempio n. 13
0
    def setUp(self):
        super().setUp()
        self.s3_store = V1ConnectionType(
            name="test",
            kind=V1ConnectionKind.S3,
            tags=["test", "foo"],
            schema=V1BucketConnection(bucket="s3//:foo"),
        )
        self.gcs_store = V1ConnectionType(
            name="test",
            kind=V1ConnectionKind.GCS,
            tags=["test"],
            schema=V1BucketConnection(bucket="gs//:foo"),
        )
        self.az_store = V1ConnectionType(
            name="test",
            kind=V1ConnectionKind.WASB,
            schema=V1BucketConnection(
                bucket="Conwasb://[email protected]"),
        )
        self.claim_store = V1ConnectionType(
            name="test",
            kind=V1ConnectionKind.VOLUME_CLAIM,
            schema=V1ClaimConnection(volume_claim="test",
                                     mount_path="/tmp",
                                     read_only=True),
        )
        self.host_path_store = V1ConnectionType(
            name="test",
            kind=V1ConnectionKind.HOST_PATH,
            schema=V1HostPathConnection(host_path="/tmp",
                                        mount_path="/tmp",
                                        read_only=True),
        )

        self.custom_connection1 = V1ConnectionType(
            name="db",
            kind=V1ConnectionKind.POSTGRES,
        )

        self.custom_connection2 = V1ConnectionType(
            name="ssh",
            kind=V1ConnectionKind.SSH,
            schema=V1CustomConnection(key1="val1", key2="val2"),
        )
Esempio n. 14
0
    def test_get_volume_from_connection(self):
        # No store
        assert get_volume_from_connection(connection=None) is None

        # Bucket store
        store = V1ConnectionType(
            name="test",
            kind=V1ConnectionKind.S3,
            schema=V1BucketConnection(bucket="s3//:foo"),
        )
        assert get_volume_from_connection(connection=store) is None

        # Claim store
        store = V1ConnectionType(
            name="test",
            kind=V1ConnectionKind.VOLUME_CLAIM,
            schema=V1ClaimConnection(
                mount_path="/tmp", volume_claim="test", read_only=True
            ),
        )
        volume = get_volume_from_connection(connection=store)
        assert volume.name == store.name
        assert volume.persistent_volume_claim.claim_name == store.schema.volume_claim
        assert volume.persistent_volume_claim.read_only == store.schema.read_only

        # Host path
        store = V1ConnectionType(
            name="test",
            kind=V1ConnectionKind.HOST_PATH,
            schema=V1HostPathConnection(
                mount_path="/tmp", host_path="/tmp", read_only=True
            ),
        )
        volume = get_volume_from_connection(connection=store)
        assert volume.name == store.name
        assert volume.host_path == k8s_schemas.V1HostPathVolumeSource(
            path=store.schema.host_path
        )
Esempio n. 15
0
    def setUp(self):
        super().setUp()
        # Secrets
        self.resource1 = V1K8sResourceType(
            name="non_mount_test1",
            schema=V1K8sResourceSchema(name="non_mount_test1",
                                       items=["item1", "item2"]),
            is_requested=False,
        )
        self.resource2 = V1K8sResourceType(
            name="non_mount_test2",
            schema=V1K8sResourceSchema(name="non_mount_test2"),
            is_requested=False,
        )
        self.resource3 = V1K8sResourceType(
            name="non_mount_test3",
            schema=V1K8sResourceSchema(name="non_mount_test3",
                                       items=["item1", "item2"]),
            is_requested=True,
        )
        self.resource4 = V1K8sResourceType(
            name="non_mount_test4",
            schema=V1K8sResourceSchema(name="non_mount_test4"),
            is_requested=True,
        )
        self.resource5 = V1K8sResourceType(
            name="non_mount_test1",
            schema=V1K8sResourceSchema(name="non_mount_test1"),
            is_requested=True,
        )

        # Connections
        self.s3_store = V1ConnectionType(
            name="test_s3",
            kind=V1ConnectionKind.S3,
            schema=V1BucketConnection(bucket="s3//:foo"),
            secret=self.resource1.schema,
        )
        self.gcs_store = V1ConnectionType(
            name="test_gcs",
            kind=V1ConnectionKind.GCS,
            schema=V1BucketConnection(bucket="gcs//:foo"),
            secret=self.resource2.schema,
        )
        self.az_store = V1ConnectionType(
            name="test_az",
            kind=V1ConnectionKind.WASB,
            schema=V1BucketConnection(
                bucket="wasb://[email protected]"),
            secret=self.resource3.schema,
        )
        self.claim_store = V1ConnectionType(
            name="test_claim",
            kind=V1ConnectionKind.VOLUME_CLAIM,
            schema=V1ClaimConnection(mount_path="/tmp", volume_claim="test"),
        )
        self.host_path_store = V1ConnectionType(
            name="test_path",
            kind=V1ConnectionKind.HOST_PATH,
            schema=V1HostPathConnection(mount_path="/tmp",
                                        host_path="/tmp",
                                        read_only=True),
        )
Esempio n. 16
0
 def setUp(self):
     super().setUp()
     # Secrets and config maps
     self.non_mount_resource1 = V1K8sResourceType(
         name="non_mount_test1",
         schema=V1K8sResourceSchema(name="ref", items=["item1", "item2"]),
         is_requested=False,
     )
     self.non_mount_resource2 = V1K8sResourceType(
         name="non_mount_test2",
         schema=V1K8sResourceSchema(name="ref"),
         is_requested=False,
     )
     self.mount_resource1 = V1K8sResourceType(
         name="mount_test1",
         schema=V1K8sResourceSchema(name="ref",
                                    items=["item1", "item2"],
                                    mount_path="/tmp1"),
         is_requested=False,
     )
     self.mount_resource2 = V1K8sResourceType(
         name="mount_test2",
         schema=V1K8sResourceSchema(name="ref", mount_path="/tmp2"),
         is_requested=False,
     )
     # Volumes
     self.vol1 = get_volume(volume="vol1", claim_name="claim1")
     self.vol2 = get_volume(volume="vol2", host_path="/path2")
     self.vol3 = get_volume(volume="vol3")
     # connections
     self.s3_store = V1ConnectionType(
         name="test_s3",
         kind=V1ConnectionKind.S3,
         schema=V1BucketConnection(bucket="s3//:foo"),
         secret=self.mount_resource1.schema,
     )
     self.gcs_store = V1ConnectionType(
         name="test_gcs",
         kind=V1ConnectionKind.GCS,
         schema=V1BucketConnection(bucket="gs//:foo"),
         secret=self.mount_resource1.schema,
     )
     self.az_store = V1ConnectionType(
         name="test_az",
         kind=V1ConnectionKind.WASB,
         schema=V1BucketConnection(
             bucket="wasb://[email protected]"),
         secret=self.mount_resource1.schema,
     )
     self.claim_store = V1ConnectionType(
         name="test_claim",
         kind=V1ConnectionKind.VOLUME_CLAIM,
         schema=V1ClaimConnection(mount_path="/tmp",
                                  volume_claim="test",
                                  read_only=True),
     )
     self.host_path_store = V1ConnectionType(
         name="test_path",
         kind=V1ConnectionKind.HOST_PATH,
         schema=V1HostPathConnection(mount_path="/tmp",
                                     host_path="/tmp",
                                     read_only=True),
     )
    def test_get_init_containers_with_claim_outputs(self):
        store = V1ConnectionType(
            name="test_claim",
            kind=V1ConnectionKind.VOLUME_CLAIM,
            schema=V1ClaimConnection(mount_path="/claim/path",
                                     volume_claim="claim",
                                     read_only=True),
        )

        # No context to enable the outputs
        containers = self.converter.get_init_containers(
            contexts=None,
            artifacts_store=store.name,
            init_connections=None,
            connection_by_names={},
            init_containers=[],
            polyaxon_init=V1PolyaxonInitContainer(image="foo/foo"),
        )
        assert containers == []

        # Enable outputs
        containers = self.converter.get_init_containers(
            contexts=PluginsContextsSpec.from_config(
                V1Plugins(collect_artifacts=True, collect_logs=False)),
            artifacts_store=store,
            connection_by_names={},
            init_connections=None,
            init_containers=[],
            polyaxon_init=V1PolyaxonInitContainer(image="foo/foo"),
        )
        assert containers == [
            get_artifacts_path_container(
                polyaxon_init=V1PolyaxonInitContainer(image="foo/foo"),
                artifacts_store=store,
                run_path=self.converter.run_path,
                auto_resume=True,
            ),
        ]

        # Use store for init
        containers = self.converter.get_init_containers(
            contexts=None,
            artifacts_store=None,
            connection_by_names={store.name: store},
            init_connections=[V1Init(connection=store.name)],
            init_containers=[],
            polyaxon_init=V1PolyaxonInitContainer(image="foo/foo"),
        )
        assert containers == [
            get_store_container(
                polyaxon_init=V1PolyaxonInitContainer(image="foo/foo"),
                connection=store,
                artifacts=None,
                env=self.converter.get_init_service_env_vars(),
            )
        ]

        # Use store for init and outputs
        containers = self.converter.get_init_containers(
            contexts=PluginsContextsSpec.from_config(
                V1Plugins(collect_artifacts=True, collect_logs=False)),
            artifacts_store=store,
            init_connections=[V1Init(connection=store.name)],
            connection_by_names={store.name: store},
            init_containers=[],
            polyaxon_init=V1PolyaxonInitContainer(image="foo/foo"),
        )
        assert containers == [
            get_artifacts_path_container(
                polyaxon_init=V1PolyaxonInitContainer(image="foo/foo"),
                artifacts_store=store,
                run_path=self.converter.run_path,
                auto_resume=True,
            ),
            get_store_container(
                polyaxon_init=V1PolyaxonInitContainer(image="foo/foo"),
                connection=store,
                artifacts=None,
                env=self.converter.get_init_service_env_vars(),
            ),
        ]

        # Add Store
        store1 = V1ConnectionType(
            name="test_gcs",
            kind=V1ConnectionKind.S3,
            schema=V1BucketConnection(bucket="s3://foo"),
            secret=None,
        )

        containers = self.converter.get_init_containers(
            contexts=PluginsContextsSpec.from_config(
                V1Plugins(collect_artifacts=True,
                          collect_logs=False,
                          auth=True)),
            artifacts_store=store,
            init_connections=[
                V1Init(
                    connection=store.name,
                    artifacts=V1ArtifactsType(files=["/foo", "/bar"]),
                ),
                V1Init(
                    connection=store1.name,
                    artifacts=V1ArtifactsType(files=["/foo", "/bar"]),
                ),
            ],
            connection_by_names={
                store.name: store,
                store1.name: store1
            },
            init_containers=[],
            polyaxon_init=V1PolyaxonInitContainer(image="foo/foo"),
        )
        assert containers == [
            get_auth_context_container(
                polyaxon_init=V1PolyaxonInitContainer(image="foo/foo"),
                env=self.converter.get_auth_service_env_vars(),
            ),
            get_artifacts_path_container(
                polyaxon_init=V1PolyaxonInitContainer(image="foo/foo"),
                artifacts_store=store,
                run_path=self.converter.run_path,
                auto_resume=True,
            ),
            get_store_container(
                polyaxon_init=V1PolyaxonInitContainer(image="foo/foo"),
                connection=store,
                artifacts=V1ArtifactsType(files=["/foo", "/bar"]),
                env=self.converter.get_init_service_env_vars(),
            ),
            get_store_container(
                polyaxon_init=V1PolyaxonInitContainer(image="foo/foo"),
                connection=store1,
                artifacts=V1ArtifactsType(files=["/foo", "/bar"]),
                env=self.converter.get_init_service_env_vars(),
            ),
        ]
Esempio n. 18
0
    def test_resolver_init_and_connections_contexts(self):
        context_root = container_contexts.CONTEXT_ROOT
        store = V1ConnectionType(
            name="test_claim",
            kind=V1ConnectionKind.VOLUME_CLAIM,
            schema=V1ClaimConnection(mount_path="/claim/path",
                                     volume_claim="claim",
                                     read_only=True),
        )

        compiled_operation = V1CompiledOperation.read({
            "version": 1.1,
            "kind": kinds.COMPILED_OPERATION,
            "plugins": {
                "auth": False,
                "shm": False,
                "collectLogs": False,
                "collectArtifacts": False,
                "collectResources": False,
            },
            "run": {
                "kind": V1RunKind.JOB,
                "container": {
                    "image": "test"
                },
                "connections": [store.name],
                "init": [{
                    "connection": store.name
                }],
            },
        })
        date_value = now()
        spec = resolve_contexts(
            namespace="test",
            owner_name="user",
            project_name="project",
            project_uuid="uuid",
            run_uuid="uuid",
            run_name="run",
            run_path="test",
            compiled_operation=compiled_operation,
            artifacts_store=store,
            connection_by_names={store.name: store},
            iteration=12,
            created_at=date_value,
            compiled_at=date_value,
            cloning_kind=V1CloningKind.COPY,
            original_uuid="uuid-copy",
        )
        assert spec == {
            "globals": {
                "owner_name": "user",
                "project_unique_name": "user.project",
                "project_name": "project",
                "project_uuid": "uuid",
                "name": "run",
                "uuid": "uuid",
                "context_path": context_root,
                "artifacts_path": "{}/artifacts".format(context_root),
                "run_artifacts_path": "/claim/path/test",
                "run_outputs_path": "/claim/path/test/outputs",
                "namespace": "test",
                "iteration": 12,
                "run_info": "user.project.runs.uuid",
                "created_at": date_value,
                "compiled_at": date_value,
                "schedule_at": None,
                "started_at": None,
                "finished_at": None,
                "duration": None,
                "cloning_kind": V1CloningKind.COPY,
                "original_uuid": "uuid-copy",
            },
            "init": {
                "test_claim": store.schema.to_dict()
            },
            "connections": {
                "test_claim": store.schema.to_dict()
            },
        }