pbs_json_test_report.py 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. # coding: utf-8
  2. # Copyright (C) 1994-2018 Altair Engineering, Inc.
  3. # For more information, contact Altair at www.altair.com.
  4. #
  5. # This file is part of the PBS Professional ("PBS Pro") software.
  6. #
  7. # Open Source License Information:
  8. #
  9. # PBS Pro is free software. You can redistribute it and/or modify it under the
  10. # terms of the GNU Affero General Public License as published by the Free
  11. # Software Foundation, either version 3 of the License, or (at your option) any
  12. # later version.
  13. #
  14. # PBS Pro is distributed in the hope that it will be useful, but WITHOUT ANY
  15. # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  16. # FOR A PARTICULAR PURPOSE.
  17. # See the GNU Affero General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU Affero General Public License
  20. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. #
  22. # Commercial License Information:
  23. #
  24. # For a copy of the commercial license terms and conditions,
  25. # go to: (http://www.pbspro.com/UserArea/agreement.html)
  26. # or contact the Altair Legal Department.
  27. #
  28. # Altair’s dual-license business model allows companies, individuals, and
  29. # organizations to create proprietary derivative works of PBS Pro and
  30. # distribute them - whether embedded or bundled with other software -
  31. # under a commercial license agreement.
  32. #
  33. # Use of Altair’s trademarks, including but not limited to "PBS™",
  34. # "PBS Professional®", and "PBS Pro™" and Altair’s logos is subject to Altair's
  35. # trademark licensing policies.
  36. from tests.selftest import *
  37. from ptl.utils.plugins.ptl_report_json import PTLJsonData
  38. class TestJSONReport(TestSelf):
  39. """
  40. Tests to test JSON test report
  41. """
  42. def test_json_fields(self):
  43. """
  44. Test to verify fields of JSON test report
  45. """
  46. test_data = {
  47. 'status': 'PASS',
  48. 'start_time': datetime.datetime(2018, 10, 4, 0, 18, 8, 509426),
  49. 'hostname': self.server.hostname,
  50. 'status_data': '',
  51. 'pbs_version': '19.2.0.20180903140741',
  52. 'testcase': 'test_select',
  53. 'end_time': datetime.datetime(2018, 10, 4, 0, 18, 11, 153022),
  54. 'testdoc': '\n Test to qselect\n ',
  55. 'duration': datetime.timedelta(0, 2, 643596),
  56. 'suite': 'SmokeTest',
  57. 'testparam': 'ABC=DEF,x=100',
  58. 'machinfo': {
  59. self.server.hostname: {
  60. 'platform': 'Linux centos7alpha3.10.0-862.11.6.el7.x86_64',
  61. 'pbs_install_type': 'server',
  62. 'os_info': 'Linux-3.10.0-862.11.6.el7.x86_64-x86_64'
  63. }
  64. },
  65. 'suitedoc': '\n This test suite contains smoke tests of PBS\n',
  66. 'tags': ['smoke'],
  67. 'file': 'tests/pbs_smoketest.py',
  68. 'module': 'tests.pbs_smoketest'
  69. }
  70. verify_data = {
  71. 'test_keys': ["command", "user", "product_version", "run_id",
  72. "test_conf", "machine_info", "testsuites",
  73. "test_summary", "additional_data"],
  74. 'test_summary_keys': ["result_summary", "test_start_time",
  75. "test_end_time", "tests_with_failures",
  76. "test_suites_with_failures"],
  77. 'test_machine_info': ["platform", "os_info", "pbs_install_type"],
  78. 'test_results': ["run", "succeeded", "failed", "errors", "skipped",
  79. "timedout"],
  80. 'test_suites_info': ["testcases", "docstring", "module", "file"],
  81. 'test_cases_info': ["docstring", "tags", "requirements",
  82. "results"],
  83. 'test_results_info': ["duration", "status", "status_data",
  84. "start_time", "end_time", "measurements"]
  85. }
  86. field_values = {
  87. 'machine_info_name': test_data['machinfo'].keys()[0],
  88. 'testresult_status': test_data['status']
  89. }
  90. faulty_fields = []
  91. faulty_values = []
  92. test_cmd = "pbs_benchpress -t SmokeTest.test_submit_job"
  93. jsontest = PTLJsonData(command=test_cmd)
  94. jdata = jsontest.get_json(data=test_data, prev_data=None)
  95. for k in verify_data['test_keys']:
  96. if k not in jdata:
  97. faulty_fields.append(k)
  98. for l in verify_data['test_summary_keys']:
  99. if l not in jdata['test_summary']:
  100. faulty_fields.append(l)
  101. for o in verify_data['test_results']:
  102. if o not in jdata['test_summary']['result_summary']:
  103. faulty_fields.append(o)
  104. for node in jdata['machine_info']:
  105. for m in verify_data['test_machine_info']:
  106. if m not in jdata['machine_info'][node]:
  107. faulty_fields.append(m)
  108. for q in jdata['testsuites']:
  109. for p in verify_data['test_suites_info']:
  110. if p not in jdata['testsuites'][q]:
  111. faulty_fields.append(p)
  112. for s in jdata['testsuites']:
  113. for t in jdata['testsuites'][s]:
  114. for u in jdata['testsuites'][s]['testcases']:
  115. for r in verify_data['test_cases_info']:
  116. if r not in jdata['testsuites'][s]['testcases'][u]:
  117. faulty_fields.append(r)
  118. for s in jdata['testsuites']:
  119. for t in jdata['testsuites'][s]['testcases']:
  120. for v in verify_data['test_results_info']:
  121. testcase = jdata['testsuites'][s]['testcases'][t]
  122. if v not in testcase['results']:
  123. faulty_fields.append(v)
  124. for k, v in field_values.items():
  125. if k == 'machine_info_name':
  126. if jdata['machine_info'].keys()[0] != v:
  127. faulty_values.append(k)
  128. if k == 'testresult_status':
  129. tsname = test_data['suite']
  130. tcname = test_data['testcase']
  131. vdata = jdata['testsuites'][tsname]['testcases'][tcname]
  132. if vdata['results']['status'] != v:
  133. faulty_values.append(k)
  134. if (faulty_fields or faulty_values):
  135. raise AssertionError("Faulty fields or values",
  136. (faulty_fields, faulty_values))