Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the kubernetes test #3101

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion luigi/contrib/kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
Written and maintained by Marco Capuccini (@mcapuccini).
"""
import logging
import os
import time
import uuid
from datetime import datetime
Expand All @@ -54,7 +55,7 @@ class kubernetes(luigi.Config):
default="kubeconfig",
description="Authorization method to access the cluster")
kubeconfig_path = luigi.Parameter(
default="~/.kube/config",
default=os.getenv("KUBECONFIG", "~/.kube/config"),
description="Path to kubeconfig file for cluster authentication")
max_retrials = luigi.IntParameter(
default=0,
Expand Down
10 changes: 7 additions & 3 deletions test/contrib/kubernetes_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_success_job(self):

def test_fail_job(self):
fail = FailJob()
self.assertRaises(RuntimeError, fail.run)
self.assertRaises(AssertionError, fail.run)
# Check for retrials
kube_api = HTTPClient(KubeConfig.from_file("~/.kube/config")) # assumes minikube
jobs = Job.objects(kube_api).filter(selector="luigi_task_id="
Expand All @@ -94,18 +94,22 @@ def test_fail_job(self):
job = Job(kube_api, jobs.response["items"][0])
self.assertTrue("failed" in job.obj["status"])
self.assertTrue(job.obj["status"]["failed"] > fail.max_retrials)
self.assertTrue(job.obj['spec']['template']['metadata']['labels'] == fail.labels())
self.assertTrue(job.obj['spec']['template']['metadata']['labels'].items() >= fail.labels.items())

@mock.patch.object(KubernetesJobTask, "_KubernetesJobTask__verify_job_has_started")
@mock.patch.object(KubernetesJobTask, "_KubernetesJobTask__get_job_status")
@mock.patch.object(KubernetesJobTask, "signal_complete")
def test_output(self, mock_signal, mock_job_status):
def test_output(self, mock_signal, mock_job_status, mock_verify_job):
# mock that the job has started
mock_verify_job.return_value = True
# mock that the job succeeded
mock_job_status.return_value = "succeeded"
# create a kubernetes job
kubernetes_job = KubernetesJobTask()
# set logger and uu_name due to logging in __track_job()
kubernetes_job._KubernetesJobTask__logger = logger
kubernetes_job.uu_name = "test"
kubernetes_job._KubernetesJobTask__print_kubectl_hints = mock.Mock()
# track the job (bc included in run method)
kubernetes_job._KubernetesJobTask__track_job()
# Make sure successful job signals
Expand Down