コード例 #1
0
 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
ファイル: converter.py プロジェクト: zhaohb/polyaxon
def convert(
    owner_name: str,
    project_name: str,
    run_name: str,
    run_uuid: str,
    content: str,
    default_auth: bool,
) -> Dict:
    polypod_config = PolypodConfig()
    compiled_operation = CompiledOperationSpecification.read(content)

    polypod_config.resolve(compiled_operation=compiled_operation)
    return converter.convert(
        compiled_operation=compiled_operation,
        owner_name=owner_name,
        project_name=project_name,
        run_name=run_name,
        run_uuid=run_uuid,
        namespace=polypod_config.namespace,
        polyaxon_init=polypod_config.polyaxon_init,
        polyaxon_sidecar=polypod_config.polyaxon_sidecar,
        run_path=run_uuid,
        artifacts_store=polypod_config.artifacts_store,
        connection_by_names=polypod_config.connection_by_names,
        secrets=polypod_config.secrets,
        config_maps=polypod_config.config_maps,
        default_sa=polypod_config.default_sa,
        converters=PLATFORM_CONVERTERS,
        default_auth=default_auth,
    )
コード例 #3
0
    def test_copy_run(self, auditor_record):
        run = copy_run(run=self.run)
        assert auditor_record.call_count == 1
        call_args, call_kwargs = auditor_record.call_args
        assert call_kwargs["event_type"] == run_events.RUN_CREATED
        assert run.user == self.run.user
        assert run.kind == self.run.kind
        assert run.project == self.run.project
        assert run.name == self.run.name
        assert run.description == self.run.description
        assert run.content != self.run.content
        config = CompiledOperationSpecification.read(run.content)
        original_config = CompiledOperationSpecification.read(self.run.content)
        assert len(config.run.init
                   or []) == len(original_config.run.init or []) + 1
        assert run.raw_content == self.run.raw_content
        assert run.readme == self.run.readme
        assert run.tags == self.run.tags
        assert run.cloning_kind == V1CloningKind.COPY
        assert run.original == self.run
        assert run.inputs == {"image": "foo/bar"}

        run = copy_run(
            run=self.run,
            user_id=self.user2.id,
            name="new-name",
            description="new-description",
            content={"trigger": "all_done"},
            readme="new-readme",
            tags=["tag1", "tag2"],
        )
        assert run.user != self.run.user
        assert run.user == self.user2
        assert run.project == self.project
        assert run.name == "new-name"
        assert run.description == "new-description"
        assert run.content != self.run.content
        assert run.raw_content == self.run.raw_content
        assert run.readme == "new-readme"
        assert set(run.tags) == {"tag1", "tag2"}
        assert run.inputs == {"image": "foo/bar"}
        assert run.cloning_kind == V1CloningKind.COPY
        assert run.original == self.run
コード例 #4
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"
コード例 #5
0
 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"
コード例 #6
0
    def test_copy_run(self, auditor_record):
        run = copy_run(run=self.run)
        assert auditor_record.call_count == 1
        call_args, call_kwargs = auditor_record.call_args
        assert call_kwargs["event_type"] == run_events.RUN_CREATED
        assert run.user == self.run.user
        assert run.kind == self.run.kind
        assert run.project == self.run.project
        assert run.name == self.run.name
        assert run.description == self.run.description
        assert run.content == self.run.content
        assert run.meta_info == {META_COPY_ARTIFACTS: {"dirs": [self.run.uuid.hex]}}
        config = CompiledOperationSpecification.read(run.content)
        original_config = CompiledOperationSpecification.read(self.run.content)
        assert len(config.run.init or []) == len(original_config.run.init or [])
        assert run.raw_content == self.run.raw_content
        assert run.readme == self.run.readme
        assert run.tags == self.run.tags
        assert run.cloning_kind == V1CloningKind.COPY
        assert run.original == self.run
        assert run.inputs == {"image": "foo/bar"}

        run = copy_run(
            run=self.run,
            user_id=self.user2.id,
            name="new-name",
            description="new-description",
            content={"trigger": "all_done"},
            readme="new-readme",
            tags=["tag1", "tag2"],
        )
        assert run.user != self.run.user
        assert run.user == self.user2
        assert run.project == self.project
        assert run.name == "new-name"
        assert run.description == "new-description"
        assert run.content != self.run.content
        assert run.raw_content == self.run.raw_content
        assert run.meta_info == {META_COPY_ARTIFACTS: {"dirs": [self.run.uuid.hex]}}
        assert run.readme == "new-readme"
        assert set(run.tags) == {"tag1", "tag2"}
        assert run.inputs == {"image": "foo/bar"}
        assert run.cloning_kind == V1CloningKind.COPY
        assert run.original == self.run

        # Copy with uploads
        self.run.meta_info[META_UPLOAD_ARTIFACTS] = "foo"
        self.run.save()
        run = copy_run(
            run=self.run,
            user_id=self.user2.id,
            name="new-name",
            description="new-description",
            content={"trigger": "all_done"},
            readme="new-readme",
            tags=["tag1", "tag2"],
        )
        assert run.user != self.run.user
        assert run.user == self.user2
        assert run.project == self.project
        assert run.name == "new-name"
        assert run.description == "new-description"
        assert run.content != self.run.content
        assert run.raw_content == self.run.raw_content
        assert run.meta_info == {
            META_UPLOAD_ARTIFACTS: "foo",
            META_COPY_ARTIFACTS: {"dirs": [self.run.uuid.hex]},
        }
        assert run.readme == "new-readme"
        assert set(run.tags) == {"tag1", "tag2"}
        assert run.inputs == {"image": "foo/bar"}
        assert run.cloning_kind == V1CloningKind.COPY
        assert run.original == self.run

        # Copy with uploads and specific fields
        self.run.meta_info[META_UPLOAD_ARTIFACTS] = "foo"
        self.run.save()
        run = copy_run(
            run=self.run,
            user_id=self.user2.id,
            name="new-name",
            description="new-description",
            content={"trigger": "all_done"},
            readme="new-readme",
            tags=["tag1", "tag2"],
            meta_info={
                META_COPY_ARTIFACTS: {
                    "dirs": ["{}/resources".format(self.run.uuid.hex)]
                }
            },
        )
        assert run.user != self.run.user
        assert run.user == self.user2
        assert run.project == self.project
        assert run.name == "new-name"
        assert run.description == "new-description"
        assert run.content != self.run.content
        assert run.raw_content == self.run.raw_content
        assert run.meta_info == {
            META_UPLOAD_ARTIFACTS: "foo",
            META_COPY_ARTIFACTS: {"dirs": ["{}/resources".format(self.run.uuid.hex)]},
        }
        assert run.readme == "new-readme"
        assert set(run.tags) == {"tag1", "tag2"}
        assert run.inputs == {"image": "foo/bar"}
        assert run.cloning_kind == V1CloningKind.COPY
        assert run.original == self.run