Ejemplo n.º 1
0
def configure_taskdesc_for_run(config, job, taskdesc, worker_implementation):
    """
    Run the appropriate function for this job against the given task
    description.

    This will raise an appropriate error if no function exists, or if the job's
    run is not valid according to the schema.
    """
    run_using = job["run"]["using"]
    if run_using not in registry:
        raise Exception(f"no functions for run.using {run_using!r}")

    if worker_implementation not in registry[run_using]:
        raise Exception("no functions for run.using {!r} on {!r}".format(
            run_using, worker_implementation))

    func, schema, defaults = registry[run_using][worker_implementation]
    for k, v in defaults.items():
        job["run"].setdefault(k, v)

    if schema:
        validate_schema(
            schema,
            job["run"],
            "In job.run using {!r}/{!r} for job {!r}:".format(
                job["run"]["using"], worker_implementation, job["label"]),
        )
    func(config, job, taskdesc)
Ejemplo n.º 2
0
def test_worker_caches(task, transform):
    config, job, taskdesc, impl = transform(task)
    add_cache(job, taskdesc, "cache1", "/cache1")
    add_cache(job, taskdesc, "cache2", "/cache2", skip_untrusted=True)

    if impl not in ("docker-worker", "generic-worker"):
        pytest.xfail(f"caches not implemented for '{impl}'")

    key = "caches" if impl == "docker-worker" else "mounts"
    assert key in taskdesc["worker"]
    assert len(taskdesc["worker"][key]) == 2

    # Create a new schema object with just the part relevant to caches.
    partial_schema = Schema(payload_builders[impl].schema.schema[key])
    validate_schema(partial_schema, taskdesc["worker"][key],
                    "validation error")
Ejemplo n.º 3
0
 def check(self):
     schema = (base_schema if self.strict else base_schema.extend(
         {}, extra=ALLOW_EXTRA))
     validate_schema(schema, self.copy(), "Invalid parameters:")
Ejemplo n.º 4
0
 def test_invalid(self):
     try:
         validate_schema(schema, {"x": "not-int"}, "pfx")
         self.fail("no exception raised")
     except Exception as e:
         self.assertTrue(str(e).startswith("pfx\n"))
Ejemplo n.º 5
0
 def test_valid(self):
     validate_schema(schema, {"x": 10, "y": "foo"}, "pfx")