Ejemplo n.º 1
0
def validate_job_spec_config(config, raise_for_rest: bool = False):
    try:
        spec = JobSpecification.read(config)
    except (MarshmallowValidationError, PolyaxonfileError,
            PolyaxonConfigurationError) as e:
        message_error = 'Received non valid job specification config. %s' % e
        if raise_for_rest:
            raise ValidationError(message_error)
        else:
            raise DjangoValidationError(message_error)

    return spec
Ejemplo n.º 2
0
    def test_get_with_environment(self):
        spec_content = """---
            version: 1

            kind: job

            environment:
              node_selector: 
                foo: bar
              tolerations:
                - key: "key"
                  operator: "Equal"
                  value: "value"
                  effect: "NoSchedule"
              affinity:
                foo: bar
              resources:
                gpu:
                  requests: 1
                  limits: 1
                gpu:
                  requests: 1
                  limits: 1

            build:
              image: my_image

            run:
              cmd: do_something
        """
        spec_parsed_content = JobSpecification.read(spec_content)

        project = ProjectFactory(user=self.auth_client.user)
        exp = self.factory_class(project=project, content=spec_parsed_content.raw_data)
        url = '/{}/{}/{}/jobs/{}/'.format(API_V1,
                                          project.user.username,
                                          project.name,
                                          exp.id)

        resp = self.auth_client.get(url)
        assert resp.status_code == status.HTTP_200_OK
        exp.refresh_from_db()
        assert resp.data == self.serializer_class(exp).data
Ejemplo n.º 3
0
    def test_create_job_with_valid_spec(self, spawner_mock):
        config = JobSpecification.read(job_spec_content)

        mock_instance = spawner_mock.return_value
        mock_instance.start_job.return_value = {'pod': 'pod_content'}
        mock_instance.spec = config

        with patch('scheduler.dockerizer_scheduler.create_build_job'
                   ) as mock_start:
            build = BuildJobFactory()
            BuildJobStatus.objects.create(status=JobLifeCycle.SUCCEEDED,
                                          job=build)
            mock_start.return_value = build, True, True
            job = JobFactory(content=config.raw_data)

        assert JobStatus.objects.filter(job=job).count() == 2
        assert list(
            JobStatus.objects.filter(job=job).values_list(
                'status',
                flat=True)) == [JobLifeCycle.CREATED, JobLifeCycle.SCHEDULED]
        job.refresh_from_db()
        assert job.last_status == JobLifeCycle.SCHEDULED
Ejemplo n.º 4
0
job_spec_content = """---
    version: 1

    kind: job
    
    tags: [fixtures]

    build:
      image: my_image
    
    run:
      cmd: test
"""

job_spec_parsed_content = JobSpecification.read(job_spec_content)
job_spec_parsed_content.parse_data()

job_spec_resources_content = """---
    version: 1

    kind: job
    
    tags: [fixtures]
    
    environment:
      resources:
        cpu:
          requests: 1
          limits: 1    
        memory:
Ejemplo n.º 5
0
 def create_job(self, config):
     config = JobSpecification.read(config)
     return JobFactory(content=config.raw_data, project=self.project)