def test_create_run_with_templated_service_spec(self):
     config_dict = get_fxt_service_with_inputs()
     spec = OperationSpecification.read(values=config_dict)
     run = compile_operation_run(
         project_id=self.project.id, user_id=self.user.id, op_spec=spec
     )
     assert run.kind == V1RunKind.SERVICE
     assert run.name == "foo"
     assert run.description == "a description"
     assert set(run.tags) == {"backend", "lab"}
     job_spec = CompiledOperationSpecification.read(run.content)
     assert job_spec.run.container.image == "{{ image }}"
     compiled_operation = CompiledOperationSpecification.read(run.content)
     compiled_operation = CompiledOperationSpecification.apply_params(
         compiled_operation, params=spec.params
     )
     compiled_operation = CompiledOperationSpecification.apply_operation_contexts(
         compiled_operation
     )
     CompiledOperationSpecification.apply_runtime_contexts(compiled_operation)
     run.content = compiled_operation.to_dict(dump=True)
     run.save(update_fields=["content"])
     job_spec = CompiledOperationSpecification.read(run.content)
     job_spec = CompiledOperationSpecification.apply_runtime_contexts(job_spec)
     assert job_spec.run.container.image == "foo/bar"
示例#2
0
 def setUp(self):
     super().setUp()
     self.object.delete()
     values = {
         "version": 1.1,
         "kind": "operation",
         "name": "foo",
         "description": "a description",
         "params": {"image": {"value": "foo/bar"}},
         "component": {
             "name": "build-template",
             "inputs": [{"name": "image", "type": "str"}],
             "tags": ["tag1", "tag2"],
             "run": {
                 "kind": V1RunKind.JOB,
                 "container": {"image": "{{ image }}"},
                 "init": [{"connection": "foo", "git": {"revision": "dev"}}],
             },
         },
     }
     op_spec = OperationSpecification.read(values=values)
     self.object = compile_operation_run(
         project_id=self.project.id, op_spec=op_spec, user_id=self.user.id
     )
     self.url = "/{}/{}/{}/runs/{}/".format(
         API_V1, self.user.username, self.project.name, self.object.uuid.hex
     )
示例#3
0
    def create(self, validated_data):
        is_managed = validated_data["is_managed"]
        content = validated_data.get("content")
        if content:
            is_managed = True if is_managed is None else is_managed

        if is_managed and not content:
            raise ValidationError(
                "Managed runs require a content with valid specification")

        user = validated_data.get("user")
        if is_managed:
            try:
                op_spec = OperationSpecification.read(content)
            except Exception as e:
                raise ValidationError(e)
            return compile_operation_run(
                project_id=validated_data["project"].id,
                user_id=user.id if user else None,
                op_spec=op_spec,
                name=validated_data.get("name"),
                description=validated_data.get("description"),
                tags=validated_data.get("tags"),
            )
        else:
            return create_run(
                project_id=validated_data["project"].id,
                user_id=user.id if user else None,
                name=validated_data.get("name"),
                description=validated_data.get("description"),
                tags=validated_data.get("tags"),
            )
示例#4
0
    def create(self, validated_data):
        is_managed = validated_data["is_managed"]
        content = validated_data.get("content")
        meta_info = validated_data.get("meta_info") or {}
        if content:
            is_managed = True if is_managed is None else is_managed

        if is_managed and not content:
            raise ValidationError(
                "Managed runs require a content with valid specification"
            )

        project_id = validated_data["project"].id
        user = validated_data.get("user")
        name = validated_data.get("name")
        description = validated_data.get("description")
        tags = validated_data.get("tags")
        pending = validated_data.get("pending")
        # Check the deprecated `is_approved` flag
        if pending is None:
            is_approved = validated_data.get("is_approved")
            if is_approved is False:
                pending = V1RunPending.UPLOAD

        if is_managed or content:
            try:
                op_spec = OperationSpecification.read(content)
            except Exception as e:
                raise ValidationError(e)
            if op_spec.is_template():
                raise ValidationError(
                    "Received a template polyaxonfile, "
                    "Please customize the specification or disable the template."
                )
            try:
                return compile_operation_run(
                    project_id=project_id,
                    user_id=user.id if user else None,
                    op_spec=op_spec,
                    name=name,
                    description=description,
                    tags=tags,
                    meta_info=meta_info,
                    is_managed=is_managed,
                    pending=pending,
                    supported_kinds=validated_data.get("supported_kinds"),
                    supported_owners=validated_data.get("supported_owners"),
                )
            except (MarshmallowValidationError, PolyaxonException, ValueError) as e:
                raise ValidationError(e)
        else:
            return create_run(
                project_id=project_id,
                user_id=user.id if user else None,
                name=name,
                description=description,
                tags=tags,
                meta_info=meta_info,
            )
示例#5
0
 def setUp(self):
     super().setUp()
     self.user = UserFactory()
     self.user2 = UserFactory()
     self.project = ProjectFactory()
     op_spec = OperationSpecification.read(values=get_fxt_job_with_inputs())
     self.run = compile_operation_run(project_id=self.project.id,
                                      op_spec=op_spec,
                                      user_id=self.user.id)
 def test_create_run_with_service_spec(self):
     config_dict = get_fxt_service()
     spec = OperationSpecification.read(values=config_dict)
     run = compile_operation_run(
         project_id=self.project.id, user_id=self.user.id, op_spec=spec
     )
     assert run.kind == V1RunKind.SERVICE
     assert run.name == "foo"
     assert run.description == "a description"
     assert set(run.tags) == {"backend", "lab", "tag1", "tag2"}
     service_spec = CompiledOperationSpecification.read(run.content)
     assert service_spec.run.container.image == "jupyter"
示例#7
0
    def create(self, validated_data):
        is_managed = validated_data["is_managed"]
        content = validated_data.get("content")
        if content:
            is_managed = True if is_managed is None else is_managed

        if is_managed and not content:
            raise ValidationError(
                "Managed runs require a content with valid specification"
            )

        project_id = validated_data["project"].id
        user = validated_data.get("user")
        name = validated_data.get("name")
        description = validated_data.get("description")
        tags = validated_data.get("tags")

        if is_managed or content:
            try:
                op_spec = OperationSpecification.read(content)
            except Exception as e:
                raise ValidationError(e)
            if op_spec.is_template():
                raise ValidationError(
                    "Received a template polyaxonfile, "
                    "Please customize the specification or disable the template."
                )
            try:
                return compile_operation_run(
                    project_id=project_id,
                    user_id=user.id if user else None,
                    op_spec=op_spec,
                    name=name,
                    description=description,
                    tags=tags,
                    is_managed=is_managed,
                    supported_kinds=validated_data.get("supported_kinds"),
                )
            except (PolyaxonException, ValueError) as e:
                raise ValidationError(e)
        else:
            return create_run(
                project_id=project_id,
                user_id=user.id if user else None,
                name=name,
                description=description,
                tags=tags,
            )
示例#8
0
 def test_create_run_with_job_spec(self):
     config_dict = get_fxt_job()
     spec = OperationSpecification.read(values=config_dict)
     run = compile_operation_run(project_id=self.project.id,
                                 user_id=self.user.id,
                                 op_spec=spec)
     assert run.kind == V1RunKind.JOB
     assert run.name == "foo"
     assert run.description == "a description"
     assert set(run.tags) == {"tag1", "tag2"}
     # Check compiled operation passes
     compiled_operation = CompiledOperationSpecification.read(run.content)
     compiled_operation = CompiledOperationSpecification.apply_params(
         compiled_operation)
     CompiledOperationSpecification.apply_run_contexts(compiled_operation, )
     # Check job
     job_spec = CompiledOperationSpecification.read(run.content)
     assert job_spec.run.container.image == "test"
     job_spec = CompiledOperationSpecification.apply_context(job_spec)
     assert job_spec.run.container.image == "test"