pbs_resv_start_dur_end.py 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 TestReservationRequests(TestFunctional):
  38. """
  39. Various tests to verify behavoir of server
  40. in validating reservation requests
  41. """
  42. # Class variables
  43. bu = BatchUtils()
  44. fmt = "%a %b %d %H:%M:%S %Y"
  45. def test_duration_end_resv(self):
  46. """
  47. To test if reservations can be made by using
  48. duration and endtime, making the server calculate
  49. the starttime.
  50. """
  51. # create reservation to end in 5 seconds and lasts 1.
  52. now = int(time.time())
  53. a = {'Resource_List.select': '1:ncpus=1',
  54. 'reserve_end': now + 5,
  55. 'reserve_duration': 1}
  56. R = Reservation(TEST_USER, attrs=a)
  57. R.unset_attributes(['reserve_start'])
  58. rid = self.server.submit(R)
  59. a = {'reserve_start': self.bu.convert_seconds_to_datetime(
  60. now + 4, self.fmt)}
  61. self.server.expect(RESV, a, id=rid)
  62. def test_duration_end_resv_fail(self):
  63. """
  64. To test if reservations made by using
  65. duration and endtime, making the server calculate
  66. the starttime and rejects if the starttime is before now.
  67. """
  68. # create reservation to end in 5 seconds and lasts 10.
  69. a = {'Resource_List.select': '1:ncpus=1',
  70. 'reserve_end': int(time.time()) + 5,
  71. 'reserve_duration': 10}
  72. R = Reservation(TEST_USER, attrs=a)
  73. R.unset_attributes(['reserve_start'])
  74. rid = None
  75. try:
  76. rid = self.server.submit(R)
  77. except PbsSubmitError as e:
  78. self.assertTrue('Bad time specification(s)' in e.msg[0],
  79. 'Reservation Submit failed in an unexpected way')
  80. self.assertTrue(rid is None,
  81. 'Reservation Submit succeeded ' +
  82. 'when it should have failed')
  83. def test_start_dur_end_resv_fail(self):
  84. """
  85. Test to submit a job with a start, end, and duration
  86. where start + duration != end.
  87. """
  88. now = int(time.time())
  89. a = {'Resource_List.select': '1:ncpus=1',
  90. 'reserve_start': now + 10,
  91. 'reserve_end': now + 30,
  92. 'reserve_duration': 10}
  93. R = Reservation(TEST_USER, attrs=a)
  94. rid = None
  95. try:
  96. rid = self.server.submit(R)
  97. except PbsSubmitError as e:
  98. self.assertTrue('Bad time specification(s)' in e.msg[0],
  99. 'Reservation Submit failed in an unexpected way')
  100. self.assertTrue(rid is None,
  101. 'Reservation Submit succeeded' +
  102. 'when it should have failed')
  103. def test_start_dur_end_resv(self):
  104. """
  105. Test to submit a job with a start, end, and duration
  106. where start + duration = end.
  107. """
  108. now = int(time.time())
  109. a = {'Resource_List.select': '1:ncpus=1',
  110. 'reserve_start': now + 20,
  111. 'reserve_end': now + 30,
  112. 'reserve_duration': 10}
  113. R = Reservation(TEST_USER, attrs=a)
  114. rid = self.server.submit(R)
  115. a = {'reserve_state': (MATCH_RE, 'RESV_CONFIRMED|2')}
  116. self.server.expect(RESV, a, id=rid)
  117. def test_end_wall_resv(self):
  118. """
  119. Test to submit a job with end and walltime
  120. """
  121. now = int(time.time())
  122. a = {'Resource_List.select': '1:ncpus=1',
  123. 'Resource_List.walltime': '10',
  124. 'reserve_end': now + 30}
  125. R = Reservation(TEST_USER, attrs=a)
  126. R.unset_attributes(['reserve_start'])
  127. rid = self.server.submit(R)
  128. a = {'reserve_state': (MATCH_RE, 'RESV_CONFIRMED|2')}
  129. self.server.expect(RESV, a, id=rid)
  130. def test_rstat_longterm_resv(self):
  131. """
  132. Test to submit a reservation, where duration > INT_MAX.
  133. Check whether rstat displaying negative number.
  134. """
  135. now = int(time.time())
  136. a = {'Resource_List.select': '1:ncpus=1',
  137. 'reserve_start': now + 3600,
  138. 'reserve_end': now + 4294970895}
  139. r = Reservation(TEST_USER, attrs=a)
  140. rid = self.server.submit(r)
  141. a = {'reserve_state': (MATCH_RE, 'RESV_CONFIRMED|2')}
  142. self.server.expect(RESV, a, id=rid)
  143. out = self.server.status(RESV, 'reserve_duration', id=rid)[0][
  144. 'reserve_duration']
  145. dur = long(out)
  146. self.assertTrue(dur > 0, 'Duration ' + str(dur) + 'is negative.')