pbs_two_mom_hooks_resources_used.py 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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.functional import *
  37. class TestAcctlogRescUsedWithTwoMomHooks(TestFunctional):
  38. """
  39. This test suite tests the accounting logs to have non-zero resources_used
  40. in the scenario where we have execjob_begin and execjob_end hooks.
  41. """
  42. def setUp(self):
  43. TestFunctional.setUp(self)
  44. if len(self.moms) != 2:
  45. self.skipTest('Test requires two MoMs as input, '
  46. 'use -p moms=<mom1>:<mom2>')
  47. hook_body = "import time\n"
  48. a = {'event': 'execjob_begin', 'enabled': 'True'}
  49. rv = self.server.create_import_hook("test", a, hook_body)
  50. self.assertTrue(rv)
  51. a = {'event': 'execjob_end', 'enabled': 'True'}
  52. rv = self.server.create_import_hook("test2", a, hook_body)
  53. self.assertTrue(rv)
  54. a = {ATTR_nodefailrq: 5}
  55. rc = self.server.manager(MGR_CMD_SET, SERVER, a)
  56. self.assertEqual(rc, 0)
  57. a = {'job_history_enable': 'True'}
  58. rc = self.server.manager(MGR_CMD_SET, SERVER, a)
  59. self.assertEqual(rc, 0)
  60. self.momA = self.moms.values()[0]
  61. self.momB = self.moms.values()[1]
  62. self.momA.delete_vnode_defs()
  63. self.momB.delete_vnode_defs()
  64. self.hostA = self.momA.shortname
  65. self.hostB = self.momB.shortname
  66. rc = self.server.manager(MGR_CMD_DELETE, NODE, None, "")
  67. self.assertEqual(rc, 0)
  68. rc = self.server.manager(MGR_CMD_CREATE, NODE, id=self.hostA)
  69. self.assertEqual(rc, 0)
  70. rc = self.server.manager(MGR_CMD_CREATE, NODE, id=self.hostB)
  71. self.assertEqual(rc, 0)
  72. def test_Rrecord(self):
  73. """
  74. This test case runs a job on two nodes. Kills the mom process on
  75. MS, waits for the job to be requeued and tests for the
  76. resources_used value to be present in the 'R' record.
  77. """
  78. test = []
  79. test += ['#PBS -N NodeFailRequeueTest\n']
  80. test += ['echo Starting test at `date`\n']
  81. test += ['sleep 5\n']
  82. select = "vnode=" + self.hostA + "+vnode=" + self.hostB
  83. j1 = Job(TEST_USER, attrs={
  84. 'Resource_List.select': select})
  85. j1.create_script(body=test)
  86. jid1 = self.server.submit(j1)
  87. # Wait for the job to start running.
  88. self.server.expect(JOB, {ATTR_state: 'R'}, jid1)
  89. # Kill the MoM process on the MS.
  90. self.momA.signal('-KILL')
  91. # Wait for the job to be requeued.
  92. self.server.expect(JOB, {'job_state': 'Q'}, id=jid1)
  93. # Check for resources_used value in the 'R' record.
  94. msg = '.*R;' + str(jid1) + '.*resources_used.ncpus=2.*'
  95. self.server.accounting_match(msg, tail=True, regexp=True)
  96. def test_Erecord(self):
  97. """
  98. This test case runs a job on two nodes. Waits for the job to complete.
  99. After that, tests for the E record to have non-zero values in
  100. resources_used.
  101. """
  102. test = []
  103. test += ['#PBS -N JobEndTest\n']
  104. test += ['echo Starting test at `date`\n']
  105. test += ['sleep 1\n']
  106. select = "vnode=" + self.hostA + "+vnode=" + self.hostB
  107. j1 = Job(TEST_USER, attrs={
  108. 'Resource_List.select': select})
  109. j1.create_script(body=test)
  110. jid1 = self.server.submit(j1)
  111. # Wait for the job to start running.
  112. self.server.expect(JOB, {ATTR_state: 'R'}, jid1)
  113. # Wait for the job to finish running.
  114. self.server.expect(JOB, {'job_state': 'F'}, id=jid1, extend='x')
  115. rv = 0
  116. # Check if resources_used.walltime is zero or not.
  117. try:
  118. rv = self.server.expect(JOB, {'resources_used.walltime': '0'},
  119. id=jid1, max_attempts=2, extend='x')
  120. except PtlExpectError, e:
  121. # resources_used.walltime is non-zero.
  122. self.assertFalse(rv)
  123. else:
  124. # resources_used.walltime is zero, test case fails.
  125. self.logger.info("resources_used.walltime reported to be zero")
  126. self.assertFalse(True)
  127. # Check for the E record to NOT have zero walltime.
  128. msg = '.*E;' + str(jid1) + '.*resources_used.walltime=\"00:00:00.*'
  129. self.server.accounting_match(msg, tail=True, regexp=True,
  130. existence=False)
  131. # Check for the E record to have non-zero ncpus.
  132. msg = '.*E;' + str(jid1) + '.*resources_used.ncpus=2.*'
  133. self.server.accounting_match(msg, tail=True, regexp=True)