pbs_multiple_execjob_launch_hook.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 TestExecJobHook(TestFunctional):
  38. hooks = {
  39. "execjob_hook1":
  40. """
  41. import pbs
  42. pbs.logmsg(pbs.LOG_DEBUG, "executing execjob_launch 1" )
  43. e=pbs.event()
  44. e.progname = "/usr/bin/echo"
  45. e.argv=[]
  46. e.argv.append("launch 1")
  47. pbs.logmsg(pbs.LOG_DEBUG, "environment var from execjob_hook1 is %s" % (e.env))
  48. """,
  49. "execjob_hook2":
  50. """
  51. import pbs
  52. pbs.logmsg(pbs.LOG_DEBUG, "executing execjob_launch 2" )
  53. e = pbs.event()
  54. if (e.progname != "/usr/bin/echo"):
  55. pbs.logmsg(pbs.LOG_DEBUG,
  56. "Modified progname value did not propagated from launch1 hook")
  57. e.reject("")
  58. else:
  59. pbs.logmsg(pbs.LOG_DEBUG,
  60. "Modified progname value got updated from launch1")
  61. pbs.logmsg(pbs.LOG_DEBUG, "environment var from execjob_hook2 is %s" % (e.env))
  62. """,
  63. }
  64. def setUp(self):
  65. TestFunctional.setUp(self)
  66. self.server.manager(MGR_CMD_SET, SERVER, {'log_events': 2047},
  67. expect=True)
  68. def test_multi_execjob_hook(self):
  69. """
  70. Unsetting ncpus, that is ['ncpus'] = None, in modifyjob hook
  71. """
  72. hook_names = ["execjob_hook1", "execjob_hook2"]
  73. hook_attrib = {'event': 'execjob_launch', 'enabled': 'True',
  74. 'order': ''}
  75. for hook_name in hook_names:
  76. hook_script = self.hooks[hook_name]
  77. hook_attrib['order'] = hook_names.index(hook_name) + 1
  78. retval = self.server.create_import_hook(hook_name,
  79. hook_attrib,
  80. hook_script,
  81. overwrite=True)
  82. self.assertTrue(retval)
  83. job = Job(TEST_USER1, attrs={ATTR_l: 'select=1:ncpus=1',
  84. ATTR_e: '/tmp/',
  85. ATTR_o: '/tmp/'})
  86. job.set_sleep_time(1)
  87. jid = self.server.submit(job)
  88. self.mom.log_match(
  89. "Modified progname value got updated from launch1",
  90. max_attempts=3, interval=3)
  91. hook1 = ["execjob_hook1", "execjob_hook2"]
  92. for hk in hook1:
  93. msg = "environment var from " + hk
  94. rv = self.mom.log_match(msg, starttime=self.server.ctime,
  95. max_attempts=10)
  96. val = rv[1] + ',' # appending comma at the end
  97. self.assertTrue("PBS_TASKNUM=1," in val,
  98. "Message not found for hook " + hk)