pbs_array_job_mail.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. import os
  38. class Test_array_job_email(TestFunctional):
  39. """
  40. This test suite is for testing arrayjob e-mailing (parent job and subjob)
  41. """
  42. def test_emails(self):
  43. """
  44. Run arrayjob with -m jabe and test if the e-mails are received
  45. """
  46. self.server.manager(MGR_CMD_SET, SERVER,
  47. {'job_history_enable': 'true'})
  48. self.server.manager(MGR_CMD_SET, NODE,
  49. {'resources_available.ncpus': 2},
  50. id=self.mom.shortname)
  51. mailfile = os.path.join("/var/mail", str(TEST_USER))
  52. if not os.path.isfile(mailfile):
  53. self.skip_test("Mail file '%s' does not exist or "
  54. "mail is not setup. "
  55. "Hence this step would be skipped. "
  56. "Please check manually." % mailfile)
  57. J = Job(TEST_USER, attrs={ATTR_m: 'jabe', ATTR_J: '1-2'})
  58. J.set_sleep_time(1)
  59. parent_jid = self.server.submit(J)
  60. self.server.expect(JOB, {'job_state': 'F'}, parent_jid,
  61. extend='x', max_attempts=15, interval=2)
  62. subjob_jid = parent_jid.replace("[]", "[1]")
  63. emails = [("PBS Job Id: " + parent_jid, "Begun execution"),
  64. ("PBS Job Id: " + parent_jid, "Execution terminated"),
  65. ("PBS Job Id: " + subjob_jid, "Begun execution"),
  66. ("PBS Job Id: " + subjob_jid, "Execution terminated")]
  67. self.logger.info("Wait 10s for saving the e-mails")
  68. time.sleep(10)
  69. ret = self.du.cat(filename=mailfile, sudo=True)
  70. maillog = [x.strip() for x in ret['out'][-600:]]
  71. for (jobid, msg) in emails:
  72. emailpass = 0
  73. for i in range(0, len(maillog)-2):
  74. if jobid == maillog[i] and msg == maillog[i+2]:
  75. emailpass = 1
  76. self.assertTrue(emailpass, "Message '" + jobid + " " + msg +
  77. "' not found in " + mailfile)
  78. def test_qsub_errors_j_mailpoint(self):
  79. """
  80. Try to submit 'qsub -m j' and test possible errors
  81. """
  82. J = Job(TEST_USER, attrs={ATTR_m: 'j'})
  83. error_msg = "mail option 'j' can not be used without array job"
  84. try:
  85. self.server.submit(J)
  86. except PbsSubmitError as e:
  87. self.assertTrue(error_msg in e.msg[0])
  88. J = Job(TEST_USER, attrs={ATTR_m: 'j', ATTR_J: '1-2'})
  89. error_msg = "illegal -m value"
  90. try:
  91. self.server.submit(J)
  92. except PbsSubmitError as e:
  93. self.assertTrue(error_msg in e.msg[0])