Skip to content

Commit

Permalink
Merge pull request #816 from DSD-DBS/fix-pipeline-job
Browse files Browse the repository at this point in the history
Fix pipeline job
  • Loading branch information
MoritzWeber0 authored Jul 3, 2023
2 parents dc2ca27 + c0d271f commit cfb62e6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
1 change: 1 addition & 0 deletions backend/capellacollab/sessions/operators/k8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ def _create_job(
image: str,
job_labels: dict[str, str],
environment: dict[str, str | None],
args: list[str] | None = None,
timeout=18000,
) -> client.V1Job:
job: client.V1Job = client.V1Job(
Expand Down
43 changes: 38 additions & 5 deletions backend/tests/sessions/test_session_operator_k8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import base64
import os

import kubernetes.config
import pytest

if not os.getenv("CI"):
from capellacollab.sessions.operators.k8s import (
KubernetesOperator,
lazy_b64decode,
)
from capellacollab.sessions.operators.k8s import (
KubernetesOperator,
lazy_b64decode,
)

hello = base64.b64encode(b"hello") # aGVsbG8=

Expand Down Expand Up @@ -61,3 +61,36 @@ def is_open(self):

def read_stdout(self, timeout=None):
return self._blocks.pop(0)


def test_create_job(monkeypatch):
monkeypatch.setattr(kubernetes.config, "load_config", lambda **_: None)
operator = KubernetesOperator()
monkeypatch.setattr(
operator.v1_batch, "create_namespaced_job", lambda namespace, job: None
)
result = operator.create_job(
image="fakeimage",
command="fakecmd",
labels={"key": "value"},
environment={"ENVVAR": "value"},
)

assert result


def test_create_cronjob(monkeypatch):
monkeypatch.setattr(kubernetes.config, "load_config", lambda **_: None)
operator = KubernetesOperator()
monkeypatch.setattr(
operator.v1_batch,
"create_namespaced_cron_job",
lambda namespace, job: None,
)
result = operator.create_cronjob(
image="fakeimage",
command="fakecmd",
environment={"ENVVAR": "value"},
)

assert result

0 comments on commit cfb62e6

Please sign in to comment.