def test_resolver_default_service_ports(self): compiled_operation = V1CompiledOperation.read({ "version": 1.1, "kind": kinds.COMPILED_OPERATION, "plugins": { "auth": False, "shm": False, "collectLogs": False, "collectArtifacts": True, "collectResources": True, }, "run": { "kind": V1RunKind.SERVICE, "ports": [1212, 1234], "container": { "image": "test", "command": "{{ ports[0] }}" }, }, }) 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=None, connection_by_names={}, iteration=12, created_at=None, compiled_at=None, ) assert spec == { "globals": { "owner_name": "user", "project_name": "project", "project_unique_name": "user.project", "project_uuid": "uuid", "run_info": "user.project.runs.uuid", "name": "run", "uuid": "uuid", "context_path": "/plx-context", "artifacts_path": "/plx-context/artifacts", "run_artifacts_path": "/plx-context/artifacts/test", "run_outputs_path": "/plx-context/artifacts/test/outputs", "namespace": "test", "iteration": 12, "ports": [1212, 1234], "base_url": "/services/v1/test/user/project/runs/uuid", "created_at": None, "compiled_at": None, "cloning_kind": None, "original_uuid": None, }, "init": {}, "connections": {}, }
def test_resolver_default_contexts(self): context_root = container_contexts.CONTEXT_ROOT 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" } }, }) 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=None, connection_by_names={}, iteration=None, created_at=None, compiled_at=None, ) assert spec == { "globals": { "owner_name": "user", "project_unique_name": "user.project", "project_name": "project", "project_uuid": "uuid", "run_info": "user.project.runs.uuid", "context_path": context_root, "artifacts_path": "{}/artifacts".format(context_root), "name": "run", "uuid": "uuid", "namespace": "test", "iteration": None, "created_at": None, "compiled_at": None, "schedule_at": None, "started_at": None, "finished_at": None, "duration": None, "cloning_kind": None, "original_uuid": None, }, "init": {}, "connections": {}, }
def _apply_runtime_contexts(self): contexts = resolve_contexts( namespace=self.namespace, owner_name=self.owner_name, project_name=self.project_name, project_uuid=self.project_uuid, run_name=self.run_name, run_path=self.run_path, run_uuid=self.run_uuid, compiled_operation=self.compiled_operation, connection_by_names=self.connection_by_names, artifacts_store=self.artifacts_store, iteration=self.iteration, created_at=self.created_at, compiled_at=self.compiled_at, ) return CompiledOperationSpecification.apply_runtime_contexts( self.compiled_operation, contexts=contexts)
def _resolve_contexts(self): return resolve_contexts( namespace=self.namespace, owner_name=self.owner_name, project_name=self.project_name, project_uuid=self.project_uuid, run_name=self.run_name, run_path=self.run_path, run_uuid=self.run_uuid, compiled_operation=self.compiled_operation, connection_by_names=self.connection_by_names, artifacts_store=self.artifacts_store, iteration=self.iteration, created_at=self.created_at, compiled_at=self.compiled_at, cloning_kind=self.cloning_kind, original_uuid=self.original_uuid, )
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.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": "/plx-context", "artifacts_path": "/plx-context/artifacts", "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, "cloning_kind": V1CloningKind.COPY, "original_uuid": "uuid-copy", }, "init": { "test_claim": store.schema.to_dict() }, "connections": { "test_claim": store.schema.to_dict() }, }
def test_resolver_outputs_collections(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": True, "collectResources": True, }, "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, created_at=None, compiled_at=None, ) assert spec == { "globals": { "owner_name": "user", "project_name": "project", "project_unique_name": "user.project", "project_uuid": "uuid", "name": "run", "uuid": "uuid", "run_info": "user.project.runs.uuid", "context_path": context_root, "artifacts_path": "{}/artifacts".format(context_root), "run_artifacts_path": "{}/artifacts/test".format(context_root), "run_outputs_path": "{}/artifacts/test/outputs".format(context_root), "namespace": "test", "iteration": 12, "created_at": None, "compiled_at": None, "schedule_at": None, "started_at": None, "finished_at": None, "duration": None, "cloning_kind": None, "original_uuid": None, }, "init": { "test_claim": store.schema.to_dict() }, "connections": { "test_claim": store.schema.to_dict() }, }