def test_run_to_completion_check_other_K8_exception( self, mock_create_namespaced_job): """ Checking if the an exception is raised when ApiException status is other than 409 """ for executor in self.data['executors']: jobname = executor['metadata']['name'] job = Job(executor, jobname, taskmaster.args.namespace) with self.assertRaises(ApiException): job.run_to_completion(taskmaster.args.poll_interval, taskmaster.check_cancelled, taskmaster.args.pod_timeout)
def run_executor(executor, namespace, pvc=None): jobname = executor['metadata']['name'] spec = executor['spec']['template']['spec'] if os.environ.get('EXECUTOR_BACKOFF_LIMIT') is not None: executor['spec'].update( {'backoffLimit': int(os.environ['EXECUTOR_BACKOFF_LIMIT'])}) if pvc is not None: mounts = spec['containers'][0].setdefault('volumeMounts', []) mounts.extend(pvc.volume_mounts) volumes = spec.setdefault('volumes', []) volumes.extend([{ 'name': task_volume_basename, 'persistentVolumeClaim': { 'readonly': False, 'claimName': pvc.name } }]) logger.debug('Created job: ' + jobname) job = Job(executor, jobname, namespace) logger.debug('Job spec: ' + str(job.body)) global created_jobs created_jobs.append(job) status = job.run_to_completion(poll_interval, check_cancelled, args.pod_timeout) if status != 'Complete': if status == 'Error': job.delete() exit_cancelled('Got status ' + status)
def init_pvc(data, filer): task_name = data['executors'][0]['metadata']['labels']['taskmaster-name'] pvc_name = task_name + '-pvc' pvc_size = data['resources']['disk_gb'] pvc = PVC(pvc_name, pvc_size, args.namespace) mounts = generate_mounts(data, pvc) logging.debug(mounts) logging.debug(type(mounts)) pvc.set_volume_mounts(mounts) filer.add_volume_mount(pvc) pvc.create() # to global var for cleanup purposes global created_pvc created_pvc = pvc if os.environ.get('NETRC_SECRET_NAME') is not None: filer.add_netrc_mount(os.environ.get('NETRC_SECRET_NAME')) filerjob = Job(filer.get_spec('inputs', args.debug), task_name + '-inputs-filer', args.namespace) global created_jobs created_jobs.append(filerjob) # filerjob.run_to_completion(poll_interval) status = filerjob.run_to_completion(poll_interval, check_cancelled, args.pod_timeout) if status != 'Complete': exit_cancelled('Got status ' + status) return pvc
def run_task(data, filer_name, filer_version): task_name = data['executors'][0]['metadata']['labels']['taskmaster-name'] pvc = None if data['volumes'] or data['inputs'] or data['outputs']: filer = Filer(task_name + '-filer', data, filer_name, filer_version, args.pull_policy_always) if os.environ.get('TESK_FTP_USERNAME') is not None: filer.set_ftp(os.environ['TESK_FTP_USERNAME'], os.environ['TESK_FTP_PASSWORD']) pvc = init_pvc(data, filer) for executor in data['executors']: run_executor(executor, args.namespace, pvc) # run executors logging.debug("Finished running executors") # upload files and delete pvc if data['volumes'] or data['inputs'] or data['outputs']: filerjob = Job(filer.get_spec('outputs', args.debug), task_name + '-outputs-filer', args.namespace) global created_jobs created_jobs.append(filerjob) # filerjob.run_to_completion(poll_interval) status = filerjob.run_to_completion(poll_interval, check_cancelled, args.pod_timeout) if status != 'Complete': exit_cancelled('Got status ' + status) else: pvc.delete()
def test_run_to_completion_success(self, mock_get_status, mock_create_namespaced_job): """ Checking if the Job runs is completed successfully """ for executor in self.data['executors']: jobname = executor['metadata']['name'] job = Job(executor, jobname, taskmaster.args.namespace) status = job.run_to_completion(1, taskmaster.check_cancelled, taskmaster.args.pod_timeout) self.assertEqual(status, "Complete")
def test_run_to_completion_check_conflict_exception( self, mock_get_status, mock_read_namespaced_job, mock_check_cancelled, mock_create_namespaced_job): """ Checking if the Job status is complete when an ApiException of 409 is raised """ for executor in self.data['executors']: jobname = executor['metadata']['name'] job = Job(executor, jobname, taskmaster.args.namespace) status = job.run_to_completion(taskmaster.args.poll_interval, taskmaster.check_cancelled, taskmaster.args.pod_timeout) self.assertEqual(status, "Complete")
def test_run_to_completion_cancelled(self, mock_get_status, mock_create_namespaced_job, mock_check_cancelled, mock_job_delete): """ Checking if the Job is cancelled """ for executor in self.data['executors']: jobname = executor['metadata']['name'] job = Job(executor, jobname, taskmaster.args.namespace) status = job.run_to_completion(taskmaster.args.poll_interval, taskmaster.check_cancelled, taskmaster.args.pod_timeout) self.assertEqual(status, "Cancelled")
def test_run_to_completion_error(self, mock_create_namespaced_job, mock_check_cancelled, mock_job_delete, mock_read_namespaced_job, mock_list_namespaced_pod): """ Testing if the job state is 'error' when the status of the pod is in pending state and reason is ImagePullBackOff """ mock_list_namespaced_pod.return_value = list_namespaced_pod_error_ImagePullBackOff( 10) for executor in self.data['executors']: jobname = executor['metadata']['name'] job = Job(executor, jobname, taskmaster.args.namespace) status = job.run_to_completion(1, taskmaster.check_cancelled, 120) self.assertEqual(status, "Error")