pbs_calendaring.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. import time
  37. from tests.functional import *
  38. class TestCalendaring(TestFunctional):
  39. """
  40. This test suite tests if PBS scheduler calendars events correctly
  41. """
  42. def test_topjob_start_time(self):
  43. """
  44. In this test we test that the top job which gets added to the
  45. calendar has estimated start time correctly set for future when
  46. job history is enabled and opt_backfill_fuzzy is turned off.
  47. """
  48. self.scheduler.set_sched_config({'strict_ordering': 'true all'})
  49. a = {'resources_available.ncpus': 1}
  50. self.server.manager(MGR_CMD_SET, NODE, a, self.mom.shortname)
  51. a = {'backfill_depth': '2', 'job_history_enable': 'True'}
  52. self.server.manager(MGR_CMD_SET, SERVER, a)
  53. # Turn opt_backfill_fuzzy off because we want to check if the job can
  54. # run after performing every end event in calendaring code instead
  55. # of rounding it off to next time boundary (default it 60 seconds)
  56. a = {'opt_backfill_fuzzy': 'off'}
  57. self.server.manager(MGR_CMD_SET, SCHED, a)
  58. res_req = {'Resource_List.select': '1:ncpus=1',
  59. 'Resource_List.walltime': 10,
  60. 'array_indices_submitted': '1-6'}
  61. j1 = Job(TEST_USER, attrs=res_req)
  62. j1.set_sleep_time(10)
  63. jid1 = self.server.submit(j1)
  64. j1_sub1 = j1.create_subjob_id(jid1, 1)
  65. j1_sub2 = j1.create_subjob_id(jid1, 2)
  66. res_req = {'Resource_List.select': '1:ncpus=1',
  67. 'Resource_List.walltime': 10}
  68. j2 = Job(TEST_USER, attrs=res_req)
  69. jid2 = self.server.submit(j2)
  70. self.server.expect(JOB, {'job_state': 'X'}, j1_sub1)
  71. self.server.expect(JOB, {'job_state': 'R'}, j1_sub2)
  72. self.server.expect(JOB, {'job_state': 'Q'}, jid2)
  73. job1 = self.server.status(JOB, id=jid1)
  74. job2 = self.server.status(JOB, id=jid2)
  75. time_now = int(time.time())
  76. # get estimated start time of both the jobs
  77. self.assertIn('estimated.start_time', job1[0])
  78. est_val1 = job1[0]['estimated.start_time']
  79. self.assertIn('estimated.start_time', job2[0])
  80. est_val2 = job2[0]['estimated.start_time']
  81. est1 = time.strptime(est_val1, "%a %b %d %H:%M:%S %Y")
  82. est2 = time.strptime(est_val2, "%a %b %d %H:%M:%S %Y")
  83. est_epoch1 = int(time.mktime(est1))
  84. est_epoch2 = int(time.mktime(est2))
  85. # since only one subjob of array parent can become topjob
  86. # second job must start 10 seconds after that because
  87. # walltime of array job is 10 seconds.
  88. self.assertEqual(est_epoch2, est_epoch1+10)
  89. # Also make sure that since second subjob from array is running
  90. # Third subjob should set estimated.start_time in future.
  91. self.assertGreater(est_epoch1, time_now)