def notification_criteria(job_id, criteria, state, health, old_health): if "dependency_query" in criteria: # Makes sure that all the jobs from dependency list also satisfy the # criteria for sending notification. dependency_jobs = Query.get_queryset( ContentType.objects.get_for_model(TestJob), Query.parse_conditions(TestJob._meta.model_name, criteria["dependency_query"]), ).exclude(pk=job_id) if criteria["status"] == "finished": if dependency_jobs.filter(~Q( state=TestJob.STATE_FINISHED)).count(): return False if criteria["status"] == "running": if dependency_jobs.filter(~Q(state=TestJob.STATE_RUNNING)).count(): return False if criteria["status"] == "complete": if dependency_jobs.filter(~Q( health=TestJob.HEALTH_COMPLETE)).count(): return False elif criteria["status"] == "incomplete": if dependency_jobs.filter(~Q( health=TestJob.HEALTH_INCOMPLETE)).count(): return False elif criteria["status"] == "canceled": if dependency_jobs.filter(~Q( health=TestJob.HEALTH_CANCELED)).count(): return False # support special status of finished, otherwise skip to normal if criteria["status"] == "finished": return state == TestJob.STATE_FINISHED if criteria["status"] == "running": return state == TestJob.STATE_RUNNING if criteria["status"] == "complete": const = TestJob.HEALTH_COMPLETE elif criteria["status"] == "incomplete": const = TestJob.HEALTH_INCOMPLETE else: const = TestJob.HEALTH_CANCELED # use normal notification support if health == const: if "type" in criteria: if criteria["type"] == "regression": if (old_health == TestJob.HEALTH_COMPLETE and health == TestJob.HEALTH_INCOMPLETE): return True if criteria["type"] == "progression": if (old_health == TestJob.HEALTH_INCOMPLETE and health == TestJob.HEALTH_COMPLETE): return True else: return True return False
def query_export_custom(request): """ Create and serve the CSV file. """ try: content_type = Query.get_content_type(request.GET.get("entity")) except ContentType.DoesNotExist: raise InvalidContentTypeError( "Wrong table name in entity param. Please refer to query docs.") if content_type.model_class() not in QueryCondition.RELATION_MAP: raise InvalidContentTypeError( "Wrong table name in entity param. Please refer to query docs.") conditions = Query.parse_conditions( content_type, request.GET.get("conditions")) filename = "query_%s_export" % (content_type) try: results = Query.get_queryset(content_type, conditions).visible_by_user( request.user) except FieldError: raise InvalidConditionsError("Conditions URL incorrect: Field does " "not exist. Please refer to query docs.") return _export_query(results, content_type, filename)
def query_export_custom(request): """ Create and serve the CSV file. """ try: content_type = Query.get_content_type(request.GET.get("entity")) except InvalidContentTypeError as e: messages.error(request, e) raise Http404() if content_type.model_class() not in QueryCondition.RELATION_MAP: messages.error( request, "Wrong table name in entity param. Please refer to query docs.") raise Http404() try: conditions = Query.parse_conditions(content_type, request.GET.get("conditions")) except InvalidConditionsError as e: messages.error(request, e) raise Http404() filename = "query_%s_export" % (content_type) try: results = Query.get_queryset(content_type, conditions).visible_by_user(request.user) except (FieldDoesNotExist, FieldError) as e: messages.error(request, e) raise Http404() return _export_query(results, content_type, filename)
def query_export_custom(request): """ Create and serve the CSV file. """ try: content_type = Query.get_content_type(request.GET.get("entity")) except InvalidContentTypeError as e: messages.error(request, e) raise Http404() if content_type.model_class() not in QueryCondition.RELATION_MAP: messages.error( request, "Wrong table name in entity param. Please refer to query docs.") raise Http404() try: conditions = Query.parse_conditions( content_type, request.GET.get("conditions")) except InvalidConditionsError as e: messages.error(request, e) raise Http404() filename = "query_%s_export" % (content_type) try: results = Query.get_queryset(content_type, conditions).visible_by_user( request.user) except (FieldDoesNotExist, FieldError) as e: messages.error(request, e) raise Http404() return _export_query(results, content_type, filename)
def query_export_custom(request): """ Create and serve the CSV file. """ try: content_type = Query.get_content_type(request.GET.get("entity")) except ContentType.DoesNotExist: raise InvalidContentTypeError( "Wrong table name in entity param. Please refer to query docs.") if content_type.model_class() not in QueryCondition.RELATION_MAP: raise InvalidContentTypeError( "Wrong table name in entity param. Please refer to query docs.") conditions = Query.parse_conditions(content_type, request.GET.get("conditions")) filename = "query_%s_export" % (content_type) try: results = Query.get_queryset(content_type, conditions).visible_by_user(request.user) except FieldError: raise InvalidConditionsError("Conditions URL incorrect: Field does " "not exist. Please refer to query docs.") return _export_query(results, content_type, filename)
def get_query_results(notification): if notification.query_name: query = Query.objects.get(name=notification.query_name, owner=notification.query_owner) # We use query_owner as user here since we show only status. return query.get_results( notification.query_owner)[:notification.QUERY_LIMIT] else: return Query.get_queryset( notification.entity, Query.parse_conditions(notification.entity, notification.conditions), notification.QUERY_LIMIT)
def make_custom_query(self, entity, conditions, limit=200): """ Name ---- `make_custom_query` (`entity`, `conditions`, `limit`) Description ----------- Construct and run a custom query and return the results. Arguments --------- `entity`: string The entity you want to query `conditions`: string The conditions of the query `limit`: integer Add a limit to the number of results returned. Defaults to 200. Return value ------------ A list of dictionaries containing the query results. The user should be authenticated with a username and token. Example ------- # Get all test jobs submitted by the user 'kernel-ci', and which ended # as 'Incomplete': server.results.make_custom_query("testjob", "testjob__submitter__exact__kernel-ci," "testjob__health__exact__Incomplete") [{ jobXX }, { jobXY }, ...] # Get all test cases in a test suite named 'custom-tests', that failed, # and for whom the job ended after '2017-04-26 00:00:00'. server.results.make_custom_query("testcase", "testsuite__name__exact__1_custom-tests," "testcase__result__exact__Test failed," "testjob__end_time__gt__2017-04-26 00:00:00") [{ testcaseXX }, { testcaseXY }, ...] """ self._authenticate() try: content_type = Query.get_content_type(entity) except InvalidContentTypeError: raise xmlrpc.client.Fault( 400, "Wrong table name in entity parameter. " "Please refer to query docs.") if content_type.model_class() not in QueryCondition.RELATION_MAP: raise xmlrpc.client.Fault( 400, "Wrong table name in entity parameter. " "Please refer to query docs.") conditions = Query.parse_conditions(content_type, conditions) try: results = Query.get_queryset(content_type, conditions).visible_by_user(self.user) except FieldDoesNotExist: raise xmlrpc.client.Fault( 400, "Conditions URL incorrect: Field does not exist. " "Please refer to query docs.") return list(results[:limit])
def get_queryset(self): return Query.get_queryset( self.content_type, self.conditions).visible_by_user( self.request.user)
def get_queryset(self): return Query.get_queryset(self.content_type, self.conditions).visible_by_user( self.request.user)
def make_custom_query(self, entity, conditions, limit=200): """ Name ---- `make_custom_query` (`entity`, `conditions`, `limit`) Description ----------- Construct and run a custom query and return the results. Arguments --------- `entity`: string The entity you want to query `conditions`: string The conditions of the query `limit`: integer Add a limit to the number of results returned. Defaults to 200. Return value ------------ A list of dictionaries containing the query results. The user should be authenticated with a username and token. Example ------- # Get all test jobs submitted by the user 'kernel-ci', and which ended # as 'Incomplete': server.results.make_custom_query("testjob", "testjob__submitter__exact__kernel-ci," "testjob__health__exact__Incomplete") [{ jobXX }, { jobXY }, ...] # Get all test cases in a test suite named 'custom-tests', that failed, # and for whom the job ended after '2017-04-26 00:00:00'. server.results.make_custom_query("testcase", "testsuite__name__exact__1_custom-tests," "testcase__result__exact__Test failed," "testjob__end_time__gt__2017-04-26 00:00:00") [{ testcaseXX }, { testcaseXY }, ...] """ self._authenticate() try: content_type = Query.get_content_type(entity) except InvalidContentTypeError: raise xmlrpclib.Fault( 400, "Wrong table name in entity parameter. " "Please refer to query docs.") if content_type.model_class() not in QueryCondition.RELATION_MAP: raise xmlrpclib.Fault( 400, "Wrong table name in entity parameter. " "Please refer to query docs.") conditions = Query.parse_conditions(content_type, conditions) try: results = Query.get_queryset(content_type, conditions).visible_by_user(self.user) except FieldDoesNotExist: raise xmlrpclib.Fault(400, "Conditions URL incorrect: Field does not exist. " "Please refer to query docs.") return list(results[:limit])