/jenkins_radiator/radiator/views.py

https://github.com/robertgreiner/jenkins-radiator · Python · 218 lines · 168 code · 48 blank · 2 comment · 73 complexity · c44d78555d976eecc0e064859153497c MD5 · raw file

  1. from django.shortcuts import render_to_response as render
  2. from django.conf import settings
  3. import models
  4. import re
  5. markup_constants = {"up_arrow": u"\u25B2",
  6. "down_arrow": u"\u25BC"}
  7. # Create your views here.
  8. def avg(lst):
  9. return sum(lst) / (1.0 * len(lst))
  10. def get_radiator(request, build_list):
  11. const = markup_constants
  12. buildCount = request.GET.get('builds', settings.HUDSON_BUILD_COUNT)
  13. build_types = [build_row.split(',') for build_row in build_list.split('|')]
  14. columnSize = 100 / len(build_types[0])
  15. return render('radiator/builds.html', locals())
  16. def get_builds(request, build_type):
  17. const = markup_constants
  18. count = int(request.GET.get('builds', settings.HUDSON_BUILD_COUNT))
  19. builds = models.get_recent_builds(build_type + settings.HUDSON_BUILD_NAME_PATTERN, count)
  20. buildDict = lookupTests(build_type, count, builds)
  21. if len(builds) > 1:
  22. avgTime = avg([build.totalElapsedTime for build in builds if build.overall_status != 'BUILDING'])
  23. for build in builds:
  24. if build.totalUnfinishedDuration > 0:
  25. build.estimatedRemaining = avgTime - build.totalUnfinishedDuration
  26. return render('radiator/builds_table.html', locals())
  27. def get_build_info(request, build_type, build_number):
  28. const = markup_constants
  29. build = models.get_specific_build(build_type + '_Build', build_number)
  30. buildDict = lookupTests(build_type, 20, [build])
  31. return render('radiator/build_detail.html', locals())
  32. def lookupTests(build_type, count, builds):
  33. project = models.Project(build_type)
  34. testProjects = models.get_test_projects(models.get_data(settings.HUDSON_URL + '/api/json?tree=jobs[name]'),
  35. build_type)
  36. testProjects = [proj for proj in testProjects if not settings.HUDSON_TEST_IGNORE_REGEX.findall(proj)]
  37. project.smokeProjects = [proj for proj in testProjects if settings.HUDSON_SMOKE_NAME_REGEX.findall(proj)]
  38. project.baselineProjects = [proj for proj in testProjects if settings.HUDSON_BASELINE_NAME_REGEX.findall(proj)]
  39. project.otherProjects = [proj for proj in testProjects if not settings.HUDSON_SMOKE_NAME_REGEX.findall(proj)]
  40. project.otherProjects = [proj for proj in project.otherProjects if
  41. not settings.HUDSON_BASELINE_NAME_REGEX.findall(proj)]
  42. project.perfProjects = models.get_performance_projects(
  43. models.get_data(settings.HUDSON_URL + '/api/json?tree=jobs[name]'), build_type)
  44. project.codeWatchProjects = models.get_code_watch_projects(
  45. models.get_data(settings.HUDSON_URL + '/api/json?tree=jobs[name]'), build_type)
  46. buildDict = dict((build.number, build) for build in builds)
  47. smokeBuilds = []
  48. for testName in project.smokeProjects:
  49. smokeBuilds.extend(models.get_recent_builds(testName, count))
  50. baselineBuilds = []
  51. for testName in project.baselineProjects:
  52. baselineBuilds.extend(models.get_recent_builds(testName, count))
  53. regressionBuilds = []
  54. for testName in project.otherProjects:
  55. regressionBuilds.extend(models.get_recent_builds(testName, count))
  56. perfBuilds = []
  57. for testName in project.perfProjects:
  58. perfBuilds.extend(models.get_recent_builds(testName, count))
  59. codeWatchBuilds = []
  60. for testName in project.codeWatchProjects:
  61. codeWatchBuilds.extend(models.get_recent_builds(testName, count))
  62. for test in smokeBuilds:
  63. parent = buildDict.get(test.parent)
  64. if parent is not None:
  65. if test.project not in parent.smokeTests or int(test.number) > int(parent.smokeTests[test.project].number):
  66. parent.smokeTests[test.project] = test
  67. for test in baselineBuilds:
  68. parent = buildDict.get(test.parent)
  69. if parent is not None:
  70. if test.project not in parent.baselineTests or int(test.number) > int(
  71. parent.baselineTests[test.project].number):
  72. parent.baselineTests[test.project] = test
  73. for test in regressionBuilds:
  74. parent = buildDict.get(test.parent)
  75. if parent is not None:
  76. if test.project not in parent.regressionTests or int(test.number) > int(
  77. parent.regressionTests[test.project].number):
  78. parent.regressionTests[test.project] = test
  79. for test in perfBuilds:
  80. parent = buildDict.get(test.parent)
  81. if parent is not None:
  82. if test.project not in parent.perfTests or int(test.number) > int(parent.perfTests[test.project].number):
  83. parent.perfTests[test.project] = test
  84. for test in codeWatchBuilds:
  85. parent = buildDict.get(test.parent)
  86. if parent is not None:
  87. if test.project not in parent.codeWatchTests or int(test.number) > int(
  88. parent.codeWatchTests[test.project].number):
  89. parent.codeWatchTests[test.project] = test
  90. for build in builds:
  91. for smoke in project.smokeProjects:
  92. if smoke not in build.smokeTests:
  93. build.smokeTests[smoke] = models.Build(projectName=smoke)
  94. for baseline in project.baselineProjects:
  95. if baseline not in build.baselineTests:
  96. build.baselineTests[smoke] = models.Build(projectName=baseline)
  97. for perf in project.perfProjects:
  98. if perf not in build.perfTests:
  99. build.perfTests[perf] = models.Build(projectName=perf)
  100. for watch in project.codeWatchProjects:
  101. if watch not in build.codeWatchTests:
  102. build.codeWatchTests[watch] = models.Build(projectName=watch)
  103. for other in project.otherProjects:
  104. if other not in build.regressionTests:
  105. build.regressionTests[other] = models.Build(projectName=other)
  106. # Find prior build with perf data
  107. for perfProject in project.perfProjects:
  108. lastSuccessfulBuild = None
  109. for build in reversed(builds):
  110. if build.perfTests.__contains__(perfProject) and build.perfTests[perfProject].result == "SUCCESS":
  111. build.perfTests[perfProject].prior = lastSuccessfulBuild
  112. lastSuccessfulBuild = build.perfTests[perfProject]
  113. for perfBuild in perfBuilds:
  114. perfBuild.pagePerfs = models.create_pagePerfs(perfBuild.url)
  115. for codeWatchBuild in codeWatchBuilds:
  116. codeWatchBuild.codeWatchStatus = models.get_codeWatchStatus(codeWatchBuild.url, codeWatchBuild.status)
  117. for perfBuild in perfBuilds:
  118. perfBuild.pagePerfDeltas = []
  119. for pageName, pagePerf in perfBuild.pagePerfs.iteritems():
  120. if perfBuild.prior:
  121. if perfBuild.prior.pagePerfs.has_key(pageName):
  122. priorPagePerf = perfBuild.prior.pagePerfs[pageName]
  123. perfBuild.pagePerfDeltas.append(models.PagePerformanceDelta(pagePerf, priorPagePerf))
  124. else:
  125. perfBuild.pagePerfDeltas.append(models.PagePerformanceDelta(pagePerf))
  126. return buildDict
  127. def get_project_report(request, build_type):
  128. count = int(request.GET.get('builds', settings.HUDSON_BUILD_COUNT))
  129. builds = models.get_recent_builds(build_type + settings.HUDSON_BUILD_NAME_PATTERN, count)
  130. buildDict = lookupTests(build_type, count, builds)
  131. caseDict = {}
  132. tests = []
  133. for build in sorted(buildDict.values(), key=lambda build: build.number, reverse=True):
  134. tests.append(build)
  135. compile_project_test_cases(build, caseDict)
  136. summary = summarize_test_cases(caseDict)
  137. return render('radiator/test_report.html', locals())
  138. def compile_project_test_cases( build, allCases ):
  139. for test in build.smokeTests.values() + build.baselineTests.values() + build.regressionTests.values():
  140. if test.testCases:
  141. for case in test.testCases:
  142. errorCount, casesByBuildNbr = allCases.get(case.name, (0, {}))
  143. casesByBuildNbr[build.number] = case
  144. if case.status in ['FAILED', 'REGRESSION']:
  145. errorCount = errorCount + 1
  146. allCases.update({case.name: (errorCount, casesByBuildNbr)})
  147. return allCases
  148. def get_test_report(request, test_name):
  149. count = int(request.GET.get('builds', settings.HUDSON_BUILD_COUNT))
  150. tests = models.get_recent_builds(test_name, count)
  151. caseDict = compile_test_cases(tests, test_name)
  152. summary = summarize_test_cases(caseDict)
  153. return render('radiator/test_report.html', locals())
  154. def compile_test_cases(tests, test_name):
  155. allCases = {}
  156. for test in tests:
  157. if test.testCases:
  158. for case in test.testCases:
  159. errorCount, casesByRun = allCases.get(case.name, (0, {}))
  160. casesByRun[case.runNumber] = case
  161. if case.status in ['FAILED', 'REGRESSION']:
  162. errorCount = errorCount + 1
  163. allCases.update({case.name: (errorCount, casesByRun)})
  164. return allCases
  165. def summarize_test_cases(caseDict):
  166. summary = []
  167. for k, v in caseDict.iteritems():
  168. triple = (k, v[0], v[1])
  169. summary.append(triple)
  170. return sorted(summary, key=lambda c: c[1], reverse=True)