def test_get_only_one_job_job_not_found(get_deployed_jobs_mock): """If we request a job with --job-name flag and it doesn't exist""" get_deployed_jobs_mock.return_value = ['k8s/job-asdf'] with catch_stdout() as output: with pytest.raises(SystemExit): get_only_one_job('not-a-job', '') output = output.getvalue().strip() assert output == "Job not-a-job not found.\nJobs to choose from are:\n" + \ 'k8s/job-asdf'
def test_get_only_one_job_many_jobs(get_deployed_jobs_mock): """if we want 1 job but get many returned we throw valueerror""" get_deployed_jobs_mock.return_value = ['k8s/job-asdf', 'k8s/job-jkl;'] with catch_stdout() as output: with pytest.raises(SystemExit): get_only_one_job(None, 'too many jobs, pick one') output = output.getvalue().strip() assert output == "too many jobs, pick one\nJobs to choose from are:\n" + \ "k8s/job-asdf\nk8s/job-jkl;"
def test_get_only_one_job_job_desired(get_deployed_jobs_mock): """If we have multiple jobs returned and only want 1, return that one""" get_deployed_jobs_mock.return_value = [ 'k8s/job-asdf-1234', 'k8s/job-jkl;-1234' ] job = get_only_one_job('k8s/job-asdf-1234', '') assert job == 'k8s/job-asdf'
def action(self): """ Display events for a job. If multiple jobs, specify with --job-name This method will check for `.push.json` and provides run-id to _get_event method to fetch events. """ job = files.get_only_one_job( job_desired=self.args["--job-name"], error_msg="Please use --job-name flag to query for job events.") self._get_events(job, self.config['namespace'])
def call_logs(config, args): """ This method will check for `.push.json` and provides run-id to _get_logs method to fetch logs. """ job = files.get_only_one_job( job_desired=args["--job-name"], error_msg="Please use --job-name flag to pick a job to tail.") namespace = config['namespace'] # check for pod readiness before fetching logs running = check_for_pods_readiness(namespace, job, args["--retries"]) if running: since = args["--since"] _get_logs(job, since, namespace) else: print("No logs found for this job.")
def test_get_only_one_job_no_job_desired(get_deployed_jobs_mock): """this is old behavior, return the only job in the list""" get_deployed_jobs_mock.return_value = ['k8s/job-asdf-1234'] job = get_only_one_job(None, '') assert job == 'k8s/job-asdf'