def test_attempt_job_launch_launches_job_correctly(self, mock_kube): job_processor.attempt_job_launch(valid_task_definition) mock_kube.create_namespaced_job.assert_called_once_with( namespace="", body=kubernetes.client.V1Job( metadata=kubernetes.client.V1ObjectMeta( name=job_processor.get_job_name(valid_task_definition["id"]), labels=job_processor.get_job_labels(valid_task_definition) ), spec=kubernetes.client.V1JobSpec( completions=1, parallelism=1, backoff_limit=1, active_deadline_seconds=600, template=kubernetes.client.V1PodTemplateSpec( metadata=kubernetes.client.V1ObjectMeta( annotations={"iam.amazonaws.com/role": ""}, labels=job_processor.get_job_labels(valid_task_definition) ), spec=kubernetes.client.V1PodSpec( containers=[ kubernetes.client.V1Container( name=job_processor.get_job_name(valid_task_definition["id"]), image=job_processor.get_image_name(), security_context=kubernetes.client.V1SecurityContext(privileged=True), volume_mounts=[ kubernetes.client.V1VolumeMount(name="dockersock", mount_path="/var/run/docker.sock"), kubernetes.client.V1VolumeMount(name="faas", mount_path="/etc/openfaas-secret", read_only=True), kubernetes.client.V1VolumeMount(name="secrets", mount_path="", read_only=True), ], command=["sh"], args=["entrypoints/contract_job.sh"], env=[ kubernetes.client.V1EnvVar(name="EVENT", value=valid_task_definition_string), kubernetes.client.V1EnvVar(name="SERVICE", value="contract-job"), ], env_from=[ kubernetes.client.V1EnvFromSource(config_map_ref=kubernetes.client.V1ConfigMapEnvSource(name="-configmap")) ], ) ], volumes=[ kubernetes.client.V1Volume( name="dockersock", host_path=kubernetes.client.V1HostPathVolumeSource(path="/var/run/docker.sock") ), kubernetes.client.V1Volume(name="faas", secret=kubernetes.client.V1SecretVolumeSource(secret_name="openfaas-auth")), kubernetes.client.V1Volume(name="secrets", secret=kubernetes.client.V1SecretVolumeSource(secret_name="d--secrets")), ], restart_policy="Never", ), ), ), ), )
def test_get_job_name(self): self.assertEqual(job_processor.get_job_name("my-id"), "contract-my-id")