pbs_preemption.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 TestPreemption(TestFunctional):
  38. """
  39. Contains tests for scheduler's preemption functionality
  40. """
  41. def setUp(self):
  42. TestFunctional.setUp(self)
  43. a = {'resources_available.ncpus': 1}
  44. self.server.manager(MGR_CMD_SET, NODE, a, id=self.mom.shortname,
  45. expect=True)
  46. # create express queue
  47. a = {'queue_type': 'execution',
  48. 'started': 'True',
  49. 'enabled': 'True',
  50. 'Priority': 200}
  51. self.server.manager(MGR_CMD_CREATE, QUEUE, a, "expressq")
  52. def submit_and_preempt_jobs(self, preempt_order='R'):
  53. """
  54. This function will set the prempt order, submit jobs,
  55. preempt jobs and do log_match()
  56. """
  57. if preempt_order == 'R':
  58. job_state = 'Q'
  59. preempted_by = 'requeuing'
  60. elif preempt_order == 'C':
  61. job_state = 'Q'
  62. preempted_by = 'checkpointing'
  63. elif preempt_order == 'S':
  64. job_state = 'S'
  65. preempted_by = 'suspension'
  66. # set preempt order
  67. self.scheduler.set_sched_config({'preempt_order': preempt_order})
  68. attrs = {ATTR_l + '.select': '1:ncpus=1'}
  69. # submit a job to regular queue
  70. j1 = Job(TEST_USER, attrs)
  71. jid1 = self.server.submit(j1)
  72. self.server.expect(JOB, {'job_state': 'R'}, id=jid1)
  73. # submit a job to high priority queue
  74. attrs['queue'] = 'expressq'
  75. j2 = Job(TEST_USER, attrs)
  76. jid2 = self.server.submit(j2)
  77. self.server.expect(JOB, {'job_state': 'R'}, id=jid2)
  78. self.server.expect(JOB, {'job_state': job_state}, id=jid1)
  79. self.scheduler.log_match(jid1 + ";Job preempted by " + preempted_by)
  80. self.scheduler.log_match(
  81. jid1 + ";Job will never run", existence=False, max_attempts=5)
  82. def test_never_run_preempt_suspension(self):
  83. """
  84. Test that a job preempted by suspension is not
  85. marked as "Job will never run"
  86. """
  87. self.submit_and_preempt_jobs(preempt_order='S')
  88. def test_never_run_preempt_checkpoint(self):
  89. """
  90. Test that a preempted job with checkpoint is not
  91. marked as "Job will never run"
  92. """
  93. # Create checkpoint
  94. chk_script = """#!/bin/bash
  95. kill $1
  96. exit 0
  97. """
  98. self.chk_file = self.du.create_temp_file(body=chk_script)
  99. self.du.chmod(path=self.chk_file, mode=0755)
  100. self.du.chown(path=self.chk_file, uid=0, gid=0, sudo=True)
  101. c = {'$action': 'checkpoint_abort 30 !' + self.chk_file + ' %sid'}
  102. self.mom.add_config(c)
  103. self.attrs = {ATTR_l + '.select': '1:ncpus=1'}
  104. # preempt jobs and check logs
  105. self.submit_and_preempt_jobs(preempt_order='C')
  106. def test_never_run_preempt_requeue(self):
  107. """
  108. Test that a preempted job by requeueing is not
  109. marked as "Job will never run"
  110. """
  111. self.submit_and_preempt_jobs(preempt_order='R')