def definition(self, job_id): """ Name ---- `scheduler.jobs.definition` (`job_id`) Description ----------- Return the job definition Arguments --------- `job_id`: string Job id Return value ------------ The job definition or and error. """ try: job = TestJob.get_by_job_number(job_id) except TestJob.DoesNotExist: raise xmlrpclib.Fault( 404, "Job '%s' was not found." % job_id) if not job.can_view(self.user): raise xmlrpclib.Fault( 403, "Job '%s' not available to user '%s'." % (job_id, self.user)) if job.is_multinode: return xmlrpclib.Binary(job.multinode_definition) else: return xmlrpclib.Binary(job.original_definition)
def definition(self, job_id): """ Name ---- `scheduler.jobs.definition` (`job_id`) Description ----------- Return the job definition Arguments --------- `job_id`: string Job id Return value ------------ The job definition or and error. Note: for MultiNode jobs, the original MultiNode definition is returned. """ try: job = TestJob.get_by_job_number(job_id) except TestJob.DoesNotExist: raise xmlrpc.client.Fault(404, "Job '%s' was not found." % job_id) if not job.can_view(self.user): raise xmlrpc.client.Fault( 403, "Job '%s' not available to user '%s'." % (job_id, self.user)) if job.is_multinode: return job.multinode_definition return job.original_definition
def get_testsuite_results_csv(self, job_id, suite_name, limit=None, offset=None): """ Name ---- `get_testsuite_results_csv` (`job_id`, `suite_name`, `limit=None`, `offset=None`) Description ----------- Get the suite results of given job id and suite name in CSV format. Arguments --------- `job_id`: string Job id for which the results are required. `suite_name`: string Name of the suite for which the results are required. `limit`: int Limit the number of test cases fetched. `offset`: int Start fetching test cases from a specific point. Return value ------------ This function returns an XML-RPC structures of suite results in CSV format, provided the user is authenticated with an username and token. """ self._authenticate() if not job_id: raise xmlrpc.client.Fault( 400, "Bad request: TestJob id was not specified.") try: job = TestJob.get_by_job_number(job_id) if not job.can_view(self.user): raise xmlrpc.client.Fault( 401, "Permission denied for user to job %s" % job_id) output = io.StringIO() writer = csv.DictWriter( output, quoting=csv.QUOTE_ALL, extrasaction="ignore", fieldnames=testcase_export_fields(), ) writer.writeheader() test_suite = job.testsuite_set.get(name=suite_name) for row in get_testcases_with_limit(test_suite, limit, offset): writer.writerow(export_testcase(row)) except TestJob.DoesNotExist: raise xmlrpc.client.Fault(404, "Specified job not found.") except TestSuite.DoesNotExist: raise xmlrpc.client.Fault(404, "Specified test suite not found.") return output.getvalue()
def get_testcase_results_csv(self, job_id, suite_name, case_name): """ Name ---- `get_testcase_results_csv` (`job_id`, `suite_name`, `case_name`) Description ----------- Get the test case results of given job id, suite and test case name in CSV format. Arguments --------- `job_id`: string Job id for which the results are required. `suite_name`: string Name of the suite for which the results are required. `case_name`: string Name of the test case for which the results are required. Return value ------------ This function returns an XML-RPC structures of test case results in CSV format, provided the user is authenticated with an username and token. """ self._authenticate() if not job_id: raise xmlrpclib.Fault( 400, "Bad request: TestJob id was not " "specified.") try: job = TestJob.get_by_job_number(job_id) if not job.can_view(self.user): raise xmlrpclib.Fault( 401, "Permission denied for user to job %s" % job_id) output = io.BytesIO() writer = csv.DictWriter(output, quoting=csv.QUOTE_ALL, extrasaction='ignore', fieldnames=testcase_export_fields()) writer.writeheader() test_suite = job.testsuite_set.get(name=suite_name) test_case = test_suite.testcase_set.get(name=case_name) writer.writerow(export_testcase(test_case)) except TestJob.DoesNotExist: raise xmlrpclib.Fault(404, "Specified job not found.") except TestSuite.DoesNotExist: raise xmlrpclib.Fault(404, "Specified test suite not found.") except TestCase.DoesNotExist: raise xmlrpclib.Fault(404, "Specified test case not found.") return output.getvalue()
def get_testcase_results_csv(self, job_id, suite_name, case_name): """ Name ---- `get_testcase_results_csv` (`job_id`, `suite_name`, `case_name`) Description ----------- Get the test case results of given job id, suite and test case name in CSV format. Arguments --------- `job_id`: string Job id for which the results are required. `suite_name`: string Name of the suite for which the results are required. `case_name`: string Name of the test case for which the results are required. Return value ------------ This function returns an XML-RPC structures of test case results in CSV format, provided the user is authenticated with an username and token. """ self._authenticate() if not job_id: raise xmlrpclib.Fault(400, "Bad request: TestJob id was not " "specified.") try: job = TestJob.get_by_job_number(job_id) if not job.can_view(self.user): raise xmlrpclib.Fault( 401, "Permission denied for user to job %s" % job_id) output = io.BytesIO() writer = csv.DictWriter( output, quoting=csv.QUOTE_ALL, extrasaction='ignore', fieldnames=testcase_export_fields()) writer.writeheader() test_suite = job.testsuite_set.get(name=suite_name) test_case = test_suite.testcase_set.get(name=case_name) writer.writerow(export_testcase(test_case)) except TestJob.DoesNotExist: raise xmlrpclib.Fault(404, "Specified job not found.") except TestSuite.DoesNotExist: raise xmlrpclib.Fault(404, "Specified test suite not found.") except TestCase.DoesNotExist: raise xmlrpclib.Fault(404, "Specified test case not found.") return output.getvalue()
def show(self, job_id): """ Name ---- `scheduler.jobs.show` (`job_id`) Description ----------- Show job details Arguments --------- `job_id`: string Job id Return value ------------ This function returns a dictionary of details abou the specified test job. """ try: job = TestJob.get_by_job_number(job_id) except TestJob.DoesNotExist: raise xmlrpc.client.Fault(404, "Job '%s' was not found." % job_id) if not job.can_view(self.user): raise xmlrpc.client.Fault( 403, "Job '%s' not available to user '%s'." % (job_id, self.user)) device_hostname = None if job.actual_device is not None: device_hostname = job.actual_device.hostname device_type = None if job.requested_device_type is not None: device_type = job.requested_device_type.name return { "id": job.display_id, "description": job.description, "device": device_hostname, "device_type": device_type, "health_check": job.health_check, "pipeline": True, "health": job.get_health_display(), "state": job.get_state_display(), "submitter": job.submitter.username, "submit_time": job.submit_time, "start_time": job.start_time, "end_time": job.end_time, "tags": [t.name for t in job.tags.all()], "visibility": job.get_visibility_display(), "failure_comment": job.failure_comment, }
def show(self, job_id): """ Name ---- `scheduler.jobs.show` (`job_id`) Description ----------- Show job details Arguments --------- `job_id`: string Job id Return value ------------ This function returns a dictionary of details abou the specified test job. """ try: job = TestJob.get_by_job_number(job_id) except TestJob.DoesNotExist: raise xmlrpclib.Fault( 404, "Job '%s' was not found." % job_id) if not job.can_view(self.user): raise xmlrpclib.Fault( 403, "Job '%s' not available to user '%s'." % (job_id, self.user)) device_hostname = None if job.actual_device is not None: device_hostname = job.actual_device.hostname device_type = None if job.requested_device_type is not None: device_type = job.requested_device_type.name return {"id": job.display_id, "description": job.description, "device": device_hostname, "device_type": device_type, "health_check": job.health_check, "pipeline": True, "health": job.get_health_display(), "state": job.get_state_display(), "submitter": job.submitter.username, "submit_time": job.submit_time, "start_time": job.start_time, "end_time": job.end_time, "tags": [t.name for t in job.tags.all()], "visibility": job.get_visibility_display(), "failure_comment": job.failure_comment, }
def get_testsuite_results_yaml(self, job_id, suite_name, limit=None, offset=None): """ Name ---- `get_testsuite_results_yaml` (`job_id`, `suite_name`, `limit=None`, `offset=None`) Description ----------- Get the suite results of given job id and suite name in YAML format. Arguments --------- `job_id`: string Job id for which the results are required. `suite_name`: string Name of the suite for which the results are required. `limit`: int Limit the number of test cases fetched. `offset`: int Start fetching test cases from a specific point. Return value ------------ This function returns an XML-RPC structures of suite results in YAML format, provided the user is authenticated with an username and token. """ self._authenticate() if not job_id: raise xmlrpc.client.Fault( 400, "Bad request: TestJob id was not specified.") try: job = TestJob.get_by_job_number(job_id) if not job.can_view(self.user): raise xmlrpc.client.Fault( 401, "Permission denied for user to job %s" % job_id) yaml_list = [] test_suite = job.testsuite_set.get(name=suite_name) for test_case in get_testcases_with_limit(test_suite, limit, offset): yaml_list.append(export_testcase(test_case)) except TestJob.DoesNotExist: raise xmlrpc.client.Fault(404, "Specified job not found.") except TestSuite.DoesNotExist: raise xmlrpc.client.Fault(404, "Specified test suite not found.") return yaml.dump(yaml_list)
def get_testjob_metadata(self, job_id): """ Name ---- `get_testjob_metadata` (`job_id`) Description ----------- Get the job level metadata which includes entries created by LAVA as well as submitted in the test job definition Arguments --------- `job_id`: string Job id for which the results are required. Return value ------------ This function returns an XML-RPC structures of job results as a list of dictionaries, provided the user is authenticated with a username and token. [ {name: value}, {name: value}, ] For example: [ {'boot.0.hikey-oe.commands': 'fastboot'}, {'source': 'https://git.linaro.org/lava-team/refactoring.git'}, {'test.0.tlxc.definition.path': 'ubuntu/smoke-tests-basic.yaml'} ] """ self._authenticate() if not job_id: raise xmlrpclib.Fault(400, "Bad request: TestJob id was not " "specified.") try: job = TestJob.get_by_job_number(job_id) if not job.can_view(self.user): raise xmlrpclib.Fault( 401, "Permission denied for user to job %s" % job_id) except TestJob.DoesNotExist: raise xmlrpclib.Fault(404, "Specified job not found.") retval = [] data = TestData.objects.filter(testjob=job) for datum in data: for attribute in datum.attributes.all(): retval.append({attribute.name: attribute.value}) return retval
def get_testcase_results_yaml(self, job_id, suite_name, case_name): """ Name ---- `get_testcase_results_yaml` (`job_id`, `suite_name`, `case_name`) Description ----------- Get the test case results of given job id, suite and test case name in YAML format. Arguments --------- `job_id`: string Job id for which the results are required. `suite_name`: string Name of the suite for which the results are required. `case_name`: string Name of the test case for which the results are required. Return value ------------ This function returns an XML-RPC structures of test case results in YAML format, provided the user is authenticated with an username and token. """ self._authenticate() if not job_id: raise xmlrpc.client.Fault( 400, "Bad request: TestJob id was not specified.") try: job = TestJob.get_by_job_number(job_id) if not job.can_view(self.user): raise xmlrpc.client.Fault( 401, "Permission denied for user to job %s" % job_id) test_suite = job.testsuite_set.get(name=suite_name) test_cases = test_suite.testcase_set.filter(name=case_name) yaml_list = [ export_testcase(test_case) for test_case in test_cases ] except TestJob.DoesNotExist: raise xmlrpc.client.Fault(404, "Specified job not found.") except TestSuite.DoesNotExist: raise xmlrpc.client.Fault(404, "Specified test suite not found.") except TestCase.DoesNotExist: raise xmlrpc.client.Fault(404, "Specified test case not found.") return yaml.dump(yaml_list)
def get_testsuite_results_yaml(self, job_id, suite_name, limit=None, offset=None): """ Name ---- `get_testsuite_results_yaml` (`job_id`, `suite_name`, `limit=None`, `offset=None`) Description ----------- Get the suite results of given job id and suite name in YAML format. Arguments --------- `job_id`: string Job id for which the results are required. `suite_name`: string Name of the suite for which the results are required. `limit`: int Limit the number of test cases fetched. `offset`: int Start fetching test cases from a specific point. Return value ------------ This function returns an XML-RPC structures of suite results in YAML format, provided the user is authenticated with an username and token. """ self._authenticate() if not job_id: raise xmlrpclib.Fault(400, "Bad request: TestJob id was not " "specified.") try: job = TestJob.get_by_job_number(job_id) if not job.can_view(self.user): raise xmlrpclib.Fault( 401, "Permission denied for user to job %s" % job_id) yaml_list = [] test_suite = job.testsuite_set.get(name=suite_name) for test_case in get_testcases_with_limit(test_suite, limit, offset): yaml_list.append(export_testcase(test_case)) except TestJob.DoesNotExist: raise xmlrpclib.Fault(404, "Specified job not found.") except TestSuite.DoesNotExist: raise xmlrpclib.Fault(404, "Specified test suite not found.") return yaml.dump(yaml_list)
def configuration(self, job_id): """ Name ---- `scheduler.jobs.configuration` (`job_id`) Description ----------- Return the full job configuration Arguments --------- `job_id`: string Job id Return value ------------ Return an array with [job, device, dispatcher, env, env-dut] config. Any of these values might be None if the corresponding file hasn't been used by the job. If the job hasn't started yet, a 404 error will be returned. """ try: job = TestJob.get_by_job_number(job_id) except TestJob.DoesNotExist: raise xmlrpc.client.Fault(404, "Job '%s' was not found." % job_id) if not job.can_view(self.user): raise xmlrpc.client.Fault( 403, "Job '%s' not available to user '%s'." % (job_id, self.user)) if job.state not in [ TestJob.STATE_RUNNING, TestJob.STATE_CANCELING, TestJob.STATE_FINISHED, ]: raise xmlrpc.client.Fault(404, "Job '%s' has not started yet" % job_id) output_dir = job.output_dir definition = load_optional_file(os.path.join(output_dir, "job.yaml")) device = load_optional_file(os.path.join(output_dir, "device.yaml")) dispatcher = load_optional_file( os.path.join(output_dir, "dispatcher.yaml")) env = load_optional_file(os.path.join(output_dir, "env.yaml")) env_dut = load_optional_file(os.path.join(output_dir, "env-dut.yaml")) return [definition, device, dispatcher, env, env_dut]
def get_testcase_results_yaml(self, job_id, suite_name, case_name): """ Name ---- `get_testcase_results_yaml` (`job_id`, `suite_name`, `case_name`) Description ----------- Get the test case results of given job id, suite and test case name in YAML format. Arguments --------- `job_id`: string Job id for which the results are required. `suite_name`: string Name of the suite for which the results are required. `case_name`: string Name of the test case for which the results are required. Return value ------------ This function returns an XML-RPC structures of test case results in YAML format, provided the user is authenticated with an username and token. """ self._authenticate() if not job_id: raise xmlrpclib.Fault(400, "Bad request: TestJob id was not " "specified.") try: job = TestJob.get_by_job_number(job_id) if not job.can_view(self.user): raise xmlrpclib.Fault( 401, "Permission denied for user to job %s" % job_id) test_suite = job.testsuite_set.get(name=suite_name) test_cases = test_suite.testcase_set.filter(name=case_name) yaml_list = [export_testcase(test_case) for test_case in test_cases] except TestJob.DoesNotExist: raise xmlrpclib.Fault(404, "Specified job not found.") except TestSuite.DoesNotExist: raise xmlrpclib.Fault(404, "Specified test suite not found.") except TestCase.DoesNotExist: raise xmlrpclib.Fault(404, "Specified test case not found.") return yaml.dump(yaml_list)
def get_testjob_metadata(self, job_id): """ Name ---- `get_testjob_metadata` (`job_id`) Description ----------- Get the job level metadata which includes entries created by LAVA as well as submitted in the test job definition Arguments --------- `job_id`: string Job id for which the results are required. Return value ------------ This function returns an XML-RPC structures of job results as a list of dictionaries, provided the user is authenticated with a username and token. [ {name: value}, {name: value}, ] For example: [ {'boot.0.hikey-oe.commands': 'fastboot'}, {'source': 'https://git.linaro.org/lava-team/refactoring.git'}, {'test.0.tlxc.definition.path': 'ubuntu/smoke-tests-basic.yaml'} ] """ self._authenticate() if not job_id: raise xmlrpclib.Fault(400, "Bad request: TestJob id was not " "specified.") try: job = TestJob.get_by_job_number(job_id) if not job.can_view(self.user): raise xmlrpclib.Fault( 401, "Permission denied for user to job %s" % job_id) except TestJob.DoesNotExist: raise xmlrpclib.Fault(404, "Specified job not found.") return job.get_metadata_dict()
def get_testjob_suites_list_csv(self, job_id): """ Name ---- `get_testjob_suites_list_csv` (`job_id`) Description ----------- Get the test suites list from job results of given job id in CSV format. Arguments --------- `job_id`: string Job id for which the test suites are required. Return value ------------ This function returns an XML-RPC structures of test suites list from job results in CSV format, provided the user is authenticated with an username and token. """ self._authenticate() if not job_id: raise xmlrpc.client.Fault( 400, "Bad request: TestJob id was not specified.") try: job = TestJob.get_by_job_number(job_id) if not job.can_view(self.user): raise xmlrpc.client.Fault( 401, "Permission denied for user to job %s" % job_id) output = io.StringIO() writer = csv.DictWriter( output, quoting=csv.QUOTE_ALL, extrasaction="ignore", fieldnames=testsuite_export_fields(), ) writer.writeheader() for test_suite in job.testsuite_set.all(): writer.writerow(export_testsuite(test_suite)) except TestJob.DoesNotExist: raise xmlrpc.client.Fault(404, "Specified job not found.") return output.getvalue()
def job_details(self, job_id): """ Name ---- `job_details` (`job_id`) Description ----------- Get the details of given job id. Arguments --------- `job_id`: string Job id for which the output is required. Return value ------------ This function returns an XML-RPC structures of job details, provided the user is authenticated with an username and token. The elements available in XML-RPC structure include: _state, submitter_id, is_pipeline, id, failure_comment, multinode_definition, priority, _actual_device_cache, original_definition, status, health_check, description, start_time, target_group, pipeline_compatibility, submit_time, is_public, _old_status, actual_device_id, definition, sub_id, requested_device_type_id, end_time, absolute_url, submitter_username """ try: job = TestJob.get_by_job_number(job_id) except TestJob.DoesNotExist: raise xmlrpc.client.Fault(404, "Job '%s' was not found." % job_id) if not job.can_view(self.user): raise xmlrpc.client.Fault( 403, "Job '%s' not available to user '%s'." % (job_id, self.user)) job.status = job.get_legacy_status_display() job.state = job.get_state_display() job.health = job.get_health_display() job.submitter_username = job.submitter.username job.absolute_url = job.get_absolute_url() job.is_pipeline = True return job
def logs(self, job_id, line=0): """ Name ---- `scheduler.jobs.logs` (`job_id`, `line=0`) Description ----------- Return the logs for the given job Arguments --------- `job_id`: str Job id `line`: int Show only after the given line Return value ------------ This function returns a tuple made of (job_finished, data). job_finished is True if and only if the job is finished. """ try: job = TestJob.get_by_job_number(job_id) except TestJob.DoesNotExist: raise xmlrpclib.Fault(404, "Job '%s' was not found." % job_id) if not job.can_view(self.user): raise xmlrpclib.Fault( 403, "Job '%s' not available to user '%s'." % (job_id, self.user)) job_finished = (job.state == TestJob.STATE_FINISHED) try: with open(os.path.join(job.output_dir, "output.yaml"), "r") as f_in: count = 0 for _ in range(line): count += len(next(f_in)) f_in.seek(count) return (job_finished, xmlrpclib.Binary(f_in.read().encode("utf-8"))) except (IOError, StopIteration): return (job_finished, xmlrpclib.Binary("[]".encode("utf-8")))
def configuration(self, job_id): """ Name ---- `scheduler.jobs.configuration` (`job_id`) Description ----------- Return the full job configuration Arguments --------- `job_id`: string Job id Return value ------------ Return an array with [job, device, dispatcher, env, env-dut] config. Any of theses values might be None if the corresponding file hasn't been used by the job. If the job hasn't started yet, a 404 error will be returned. """ try: job = TestJob.get_by_job_number(job_id) except TestJob.DoesNotExist: raise xmlrpclib.Fault( 404, "Job '%s' was not found." % job_id) if not job.can_view(self.user): raise xmlrpclib.Fault( 403, "Job '%s' not available to user '%s'." % (job_id, self.user)) if job.state not in [TestJob.STATE_RUNNING, TestJob.STATE_CANCELING, TestJob.STATE_FINISHED]: raise xmlrpclib.Fault( 404, "Job '%s' has not started yet" % job_id) output_dir = job.output_dir definition = load_optional_file(os.path.join(output_dir, "job.yaml")) device = load_optional_file(os.path.join(output_dir, "device.yaml")) dispatcher = load_optional_file(os.path.join(output_dir, "dispatcher.yaml")) env = load_optional_file(os.path.join(output_dir, "env.yaml")) env_dut = load_optional_file(os.path.join(output_dir, "env.dut.yaml")) return [definition, device, dispatcher, env, env_dut]
def logs(self, job_id, line=0): """ Name ---- `scheduler.jobs.logs` (`job_id`, `line=0`) Description ----------- Return the logs for the given job Arguments --------- `job_id`: str Job id `line`: int Show only after the given line Return value ------------ This function returns a tuple made of (job_finished, data). job_finished is True if and only if the job is finished. """ try: job = TestJob.get_by_job_number(job_id) except TestJob.DoesNotExist: raise xmlrpclib.Fault( 404, "Job '%s' was not found." % job_id) if not job.can_view(self.user): raise xmlrpclib.Fault( 403, "Job '%s' not available to user '%s'." % (job_id, self.user)) job_finished = (job.state == TestJob.STATE_FINISHED) try: with open(os.path.join(job.output_dir, "output.yaml"), "r") as f_in: count = 0 for _ in range(line): count += len(next(f_in)) f_in.seek(count) return (job_finished, xmlrpclib.Binary(f_in.read().encode("utf-8"))) except (IOError, StopIteration): return (job_finished, xmlrpclib.Binary("[]".encode("utf-8")))
def job_output(self, job_id, offset=0): """ Name ---- `job_output` (`job_id`, `offset=0`) Description ----------- Get the output of given job id. Arguments --------- `job_id`: string Job id for which the output is required. `offset`: integer Offset from which to start reading the output file specified in bytes. It defaults to 0. Return value ------------ This function returns an XML-RPC binary data of output file, provided the user is authenticated with an username and token. """ try: job = TestJob.get_by_job_number(job_id) except TestJob.DoesNotExist: raise xmlrpc.client.Fault(404, "Job '%s' was not found." % job_id) if not job.can_view(self.user): raise xmlrpc.client.Fault( 403, "Job '%s' not available to user '%s'." % (job_id, self.user)) # Open the logs output_path = os.path.join(job.output_dir, "output.yaml") try: with open(output_path, encoding="utf-8", errors="replace") as f_logs: if f_logs: f_logs.seek(offset) return xmlrpc.client.Binary(f_logs.read().encode("UTF-8")) except OSError: raise xmlrpc.client.Fault(404, "Job output not found.")
def get_testsuite_results_count(self, job_id, suite_name): """ Name ---- `get_testsuite_results_count` (`job_id`, `suite_name`) Description ----------- Get the count of test cases in test suite. Arguments --------- `job_id`: string Job id for which the results are required. `suite_name`: string Name of the suite for which the test case count is required. Return value ------------ This function returns a count of test cases in particular test suite, provided the user is authenticated with an username and token. """ self._authenticate() if not job_id: raise xmlrpclib.Fault(400, "Bad request: TestJob id was not " "specified.") try: job = TestJob.get_by_job_number(job_id) if not job.can_view(self.user): raise xmlrpclib.Fault( 401, "Permission denied for user to job %s" % job_id) test_suite = job.testsuite_set.get(name=suite_name) test_case_count = test_suite.testcase_set.all().count() except TestJob.DoesNotExist: raise xmlrpclib.Fault(404, "Specified job not found.") except TestSuite.DoesNotExist: raise xmlrpclib.Fault(404, "Specified test suite not found.") return test_case_count
def get_testsuite_results_count(self, job_id, suite_name): """ Name ---- `get_testsuite_results_count` (`job_id`, `suite_name`) Description ----------- Get the count of test cases in test suite. Arguments --------- `job_id`: string Job id for which the results are required. `suite_name`: string Name of the suite for which the test case count is required. Return value ------------ This function returns a count of test cases in particular test suite, provided the user is authenticated with an username and token. """ self._authenticate() if not job_id: raise xmlrpc.client.Fault( 400, "Bad request: TestJob id was not specified.") try: job = TestJob.get_by_job_number(job_id) if not job.can_view(self.user): raise xmlrpc.client.Fault( 401, "Permission denied for user to job %s" % job_id) test_suite = job.testsuite_set.get(name=suite_name) test_case_count = test_suite.testcase_set.all().count() except TestJob.DoesNotExist: raise xmlrpc.client.Fault(404, "Specified job not found.") except TestSuite.DoesNotExist: raise xmlrpc.client.Fault(404, "Specified test suite not found.") return test_case_count
def logs(self, job_id, start=0, end=None): """ Name ---- `scheduler.jobs.logs` (`job_id`, `start=0`, `end=None`) Description ----------- Return the logs for the given job Arguments --------- `job_id`: str Job id `start`: int Show only after the given line `end`: int Do not return after the fiven line Return value ------------ This function returns a tuple made of (job_finished, data). job_finished is True if and only if the job is finished. """ try: job = TestJob.get_by_job_number(job_id) except TestJob.DoesNotExist: raise xmlrpc.client.Fault(404, "Job '%s' was not found." % job_id) if not job.can_view(self.user): raise xmlrpc.client.Fault( 403, "Job '%s' not available to user '%s'." % (job_id, self.user)) job_finished = job.state == TestJob.STATE_FINISHED try: data = logs_instance.read(job, start, end) return (job_finished, xmlrpc.client.Binary(data.encode("utf-8"))) except OSError: return (job_finished, xmlrpc.client.Binary("[]".encode("utf-8")))
def cancel_job(self, job_id): """ Name ---- `cancel_job` (`job_id`) Description ----------- Cancel the given job referred by its id. Arguments --------- `job_id`: string Job id which should be canceled. Return value ------------ None. The user should be authenticated with an username and token. """ self._authenticate() if not job_id: raise xmlrpc.client.Fault( 400, "Bad request: TestJob id was not specified.") with transaction.atomic(): try: job = TestJob.get_by_job_number(job_id) except TestJob.DoesNotExist: raise xmlrpc.client.Fault(404, "Job '%s' was not found." % job_id) if not job.can_view(self.user): raise xmlrpc.client.Fault( 403, "Job '%s' not available to user '%s'." % (job_id, self.user)) try: job.cancel(self.user) except PermissionDenied: raise xmlrpc.client.Fault(403, "Permission denied.") return True
def get_testjob_results_yaml(self, job_id): """ Name ---- `get_testjob_results_yaml` (`job_id`) Description ----------- Get the job results of given job id in the YAML format. Arguments --------- `job_id`: string Job id for which the results are required. Return value ------------ This function returns an XML-RPC structures of job results in YAML format, provided the user is authenticated with an username and token. """ self._authenticate() if not job_id: raise xmlrpclib.Fault( 400, "Bad request: TestJob id was not " "specified.") try: job = TestJob.get_by_job_number(job_id) if not job.can_view(self.user): raise xmlrpclib.Fault( 401, "Permission denied for user to job %s" % job_id) yaml_list = [] for test_suite in job.testsuite_set.all(): for test_case in test_suite.testcase_set.all(): yaml_list.append(export_testcase(test_case)) except TestJob.DoesNotExist: raise xmlrpclib.Fault(404, "Specified job not found.") return yaml.dump(yaml_list)
def job_health(self, job_id): """ Name ---- `job_health` (`job_id`) Description ----------- Get the health of given job id. Arguments --------- `job_id`: string Job id for which the output is required. Return value ------------ This function returns an XML-RPC structures of job health with the following fields. The user is authenticated with an username and token. `job_health`: string ['Unknown'|'Complete'|'Incomplete'|'Canceled'] """ try: job = TestJob.get_by_job_number(job_id) except TestJob.DoesNotExist: raise xmlrpc.client.Fault(404, "Job '%s' was not found." % job_id) if not job.can_view(self.user): raise xmlrpc.client.Fault( 403, "Job '%s' not available to user '%s'." % (job_id, self.user)) job_health = {"job_id": job.id, "job_health": job.get_health_display()} if job.is_multinode: job_health.update({"sub_id": job.sub_id}) return job_health
def job_state(self, job_id): """ Name ---- `job_state` (`job_id`) Description ----------- Get the state of given job id. Arguments --------- `job_id`: string Job id for which the output is required. Return value ------------ This function returns an XML-RPC structures of job state with the following fields. The user is authenticated with an username and token. `job_state`: string ['Submitted'|'Scheduling'|'Scheduled'|'Running'|'Canceling'|'Finished'] """ try: job = TestJob.get_by_job_number(job_id) except TestJob.DoesNotExist: raise xmlrpc.client.Fault(404, "Job '%s' was not found." % job_id) if not job.can_view(self.user): raise xmlrpc.client.Fault( 403, "Job '%s' not available to user '%s'." % (job_id, self.user)) job_state = {"job_id": job.id, "job_state": job.get_state_display()} if job.is_multinode: job_state.update({"sub_id": job.sub_id}) return job_state
def get_testjob_suites_list_yaml(self, job_id): """ Name ---- `get_testjob_suites_list_yaml` (`job_id`) Description ----------- Get the test suites list from job results of given job id in YAML format. Arguments --------- `job_id`: string Job id for which the test suites are required. Return value ------------ This function returns an XML-RPC structures of test suites list from job results in YAML format, provided the user is authenticated with an username and token. """ self._authenticate() if not job_id: raise xmlrpclib.Fault(400, "Bad request: TestJob id was not " "specified.") try: job = TestJob.get_by_job_number(job_id) if not job.can_view(self.user): raise xmlrpclib.Fault( 401, "Permission denied for user to job %s" % job_id) yaml_list = [] for test_suite in job.testsuite_set.all(): yaml_list.append(export_testsuite(test_suite)) except TestJob.DoesNotExist: raise xmlrpclib.Fault(404, "Specified job not found.") return yaml.dump(yaml_list)
def resubmit_job(self, job_id): """ Name ---- `resubmit_job` (`job_id`) Description ----------- Resubmit the given job referred by its id. Arguments --------- `job_id`: string The job's id which should be re-submitted. Return value ------------ This function returns an XML-RPC integer which is the newly created job's id, provided the user is authenticated with an username and token. """ self._authenticate() try: job = TestJob.get_by_job_number(job_id) except TestJob.DoesNotExist: raise xmlrpc.client.Fault(404, "Job '%s' was not found." % job_id) if not job.can_view(self.user): raise xmlrpc.client.Fault( 403, "Job '%s' not available to user '%s'." % (job_id, self.user)) if job.is_multinode: return self.submit_job(job.multinode_definition) else: return self.submit_job(job.definition)