pbs_validate_job_qsub_attributes.py 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 TestQsubWithQueuejobHook(TestFunctional):
  38. """
  39. This test suite validates the job submitted through qsub
  40. when queuejob hook is enabled in the PBS complex.
  41. """
  42. hooks = {
  43. "queuejob_hook1":
  44. """
  45. import pbs
  46. pbs.logmsg(pbs.LOG_DEBUG, "submitted job with long select" )
  47. """,
  48. }
  49. def setUp(self):
  50. TestFunctional.setUp(self)
  51. def test_qsub_long_select_with_hook(self):
  52. """
  53. This test case validates that, when a long string of resource is
  54. requested in qsub through lselect. The requested resource should not
  55. get truncated by the server hook infra when there exists a queuejob
  56. hook.
  57. """
  58. hook_names = ["queuejob_hook1"]
  59. hook_attrib = {'event': 'queuejob', 'enabled': 'True'}
  60. for hook_name in hook_names:
  61. hook_script = self.hooks[hook_name]
  62. retval = self.server.create_import_hook(hook_name,
  63. hook_attrib,
  64. hook_script,
  65. overwrite=True)
  66. self.assertTrue(retval)
  67. # Create a long select statement for the job
  68. loop_str = "1:host=testnode"
  69. long_select = loop_str
  70. for loop_i in range(1, 5120, len(loop_str) + 1):
  71. long_select += "+" + loop_str
  72. select_len = len(long_select)
  73. long_select = "select=" + long_select
  74. job = Job(TEST_USER1, attrs={ATTR_l: long_select})
  75. jid = self.server.submit(job)
  76. job_status = self.server.status(JOB, id=jid)
  77. select_resource = job_status[0]['Resource_List.select']
  78. self.assertTrue(select_len == len(select_resource))
  79. def test_qsub_N_cmdline(self):
  80. """
  81. This test case validates, illlegal characters in job name,
  82. cause qsub to error out
  83. """
  84. J = Job(TEST_USER, attrs={ATTR_N: 'j&whoami&gt;/tmp/b&'})
  85. try:
  86. jid = self.server.submit(J)
  87. except PbsSubmitError as e:
  88. self.assertTrue("illegal -N value" in e.msg[0])
  89. self.logger.info('qsub: illegal -N value.Job not submitted')
  90. else:
  91. self.logger.info('Job created with illegal name: ' + jid)
  92. self.assertTrue(False, "Job shouldn't be accepted")
  93. def test_qsub_N_jobscript(self):
  94. """
  95. This test case validates, illlegal characters in job name
  96. passed from job script, cause qsub to error out
  97. """
  98. j = Job(TEST_USER)
  99. scrpt = []
  100. scrpt += ['#!/bin/bash']
  101. scrpt += ['#PBS -N "j&whoami&gt;/tmp/b&"\n']
  102. scrpt += ['#PBS -j oe\n']
  103. scrpt += ['#PBS -m n\n']
  104. scrpt += ['#PBS -l select=1:ncpus=1\n']
  105. scrpt += ['#PBS -l walltime=00:0:15\n']
  106. scrpt += ['#PBS -l place=scatter:excl\n']
  107. scrpt += ['date +%s']
  108. j.create_script(body=scrpt, hostname=self.server.client)
  109. try:
  110. jid = self.server.submit(j)
  111. except PbsSubmitError as e:
  112. self.assertTrue("illegal -N value" in e.msg[0])
  113. self.logger.info('qsub: illegal -N value.Job not submitted')
  114. else:
  115. self.logger.info('Job created with illegal name: ' + jid)
  116. self.assertTrue(False, "Job shouldn't be accepted")
  117. def test_qsub_N_job_array(self):
  118. """
  119. This test case validates, illlegal characters in job name
  120. for a job array, cause qsub to error out
  121. """
  122. J = Job(TEST_USER, attrs={ATTR_N: 'j&whoami&g;/tmp/b&', ATTR_J: '1-2'})
  123. try:
  124. jid = self.server.submit(J)
  125. except PbsSubmitError as e:
  126. self.assertTrue("illegal -N value" in e.msg[0])
  127. self.logger.info('qsub: illegal -N value.Job not submitted')
  128. else:
  129. self.logger.info('Job created with illegal name: ' + jid)
  130. self.assertTrue(False, "Job shouldn't be accepted")
  131. def test_qsub_N_validchar(self):
  132. """
  133. This test case validates whether character "."
  134. in job name passed via -N args in qsub works fine
  135. """
  136. j = Job(TEST_USER, {ATTR_N: 'job.scr'})
  137. try:
  138. jid = self.server.submit(j)
  139. except PbsSubmitError as e:
  140. self.assertNotIn('illegal -N value', e.msg[0],
  141. 'qsub: Not accepted "." in job name')
  142. else:
  143. self.server.expect(JOB, {'job_state': (MATCH_RE, '[RQ]')}, id=jid)
  144. self.logger.info('Job submitted successfully: ' + jid)