pbs_one_event_multiple_hooks.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 Test_single_event_multiple_hooks(TestFunctional):
  38. """
  39. Test if changes made to pbs objects by multiple hooks of same
  40. event type takes effect or not.
  41. """
  42. hook_string = """
  43. import pbs
  44. e = pbs.event()
  45. e.job.Resource_List["%s"]=%s
  46. %s
  47. """
  48. def create_hook_scr(self, accept, resource, value):
  49. """
  50. function to create a hook script.
  51. It accepts 3 arguments
  52. - accept If set to true, then hook will accept else reject
  53. - resource Resource whose value we want to change
  54. - value New value to be assigned
  55. """
  56. hook_action = "e.accept()"
  57. if not accept:
  58. hook_action = "e.reject()"
  59. final_hook = self.hook_string % (resource, value, hook_action)
  60. return final_hook
  61. def test_two_queuejob_hooks(self):
  62. """
  63. Submit two queue job hooks. One of the hook modifies resource ncpus
  64. and other hook modifies walltime. Check the result of modification.
  65. """
  66. hook_name = "h1"
  67. scr = self.create_hook_scr(True, "ncpus", "int(5)")
  68. attrs = {'event': "queuejob", 'order': '1'}
  69. rv = self.server.create_import_hook(
  70. hook_name,
  71. attrs,
  72. scr,
  73. overwrite=True)
  74. self.assertTrue(rv)
  75. hook_name = "h2"
  76. scr = self.create_hook_scr(True, "walltime", "600")
  77. attrs = {'event': "queuejob", 'order': '2'}
  78. rv = self.server.create_import_hook(
  79. hook_name,
  80. attrs,
  81. scr,
  82. overwrite=True)
  83. self.assertTrue(rv)
  84. a = {'Resource_List.ncpus': 1,
  85. 'Resource_List.walltime': 10}
  86. j = Job(TEST_USER)
  87. j.set_attributes(a)
  88. j.set_sleep_time("10")
  89. jid = self.server.submit(j)
  90. self.server.expect(JOB, {
  91. 'Resource_List.ncpus': 5,
  92. 'Resource_List.walltime': '00:10:00'},
  93. offset=2, id=jid)