pbs_acct_log_trunc.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 TestAcctlogTrunc(TestFunctional):
  38. """
  39. Test that the resources_used information doesn't get truncated
  40. in accounting log records
  41. """
  42. def setUp(self):
  43. TestFunctional.setUp(self)
  44. a = {'type': 'string', 'flag': 'h'}
  45. self.server.manager(MGR_CMD_CREATE, RSC, a, id='foo_str')
  46. def test_long_resource_end(self):
  47. """
  48. Test to see if a very long string resource is neither truncated
  49. in the job's resources_used attr or the accounting log at job end
  50. """
  51. self.server.manager(MGR_CMD_SET, SERVER,
  52. {'job_history_enable': 'True'})
  53. # Create a very long string - the truncation was 2048 characters
  54. # 4096 is plenty big to show it
  55. hstr = ""
  56. for i in range(4096):
  57. hstr += "1"
  58. hook_body = "import pbs\n"
  59. hook_body += "e = pbs.event()\n"
  60. hook_body += "hstr=\'" + hstr + "\'\n"
  61. hook_body += "e.job.resources_used[\"foo_str\"] = hstr\n"
  62. a = {'event': 'execjob_epilogue', 'enabled': 'True'}
  63. self.server.create_import_hook("ep", a, hook_body)
  64. J = Job()
  65. J.set_attributes({ATTR_m: 'e'})
  66. J.set_sleep_time(1)
  67. jid = self.server.submit(J)
  68. # Make sure the resources_used value hasn't been truncated
  69. self.server.expect(JOB, {'job_state': 'F'}, id=jid, extend='x')
  70. self.server.expect(
  71. JOB, {'resources_used.foo_str': hstr}, extend='x', max_attempts=1)
  72. # Make sure the accounting log hasn't been truncated
  73. log_match = 'resources_used.foo_str=' + hstr
  74. self.server.accounting_match(
  75. "E;%s;.*%s.*" % (jid, log_match), regexp=True)
  76. # Make sure the server log hasn't been truncated
  77. log_match = 'resources_used.foo_str=' + hstr
  78. self.server.log_match("%s;.*%s.*" % (jid, log_match), regexp=True)
  79. # Make sure emails are not truncated
  80. mailfile = os.environ['MAIL']
  81. if not os.path.isfile(mailfile):
  82. self.logger.info("Mail file does not exist or mail is not setup.\
  83. Hence this step would be skipped. Please check manually.")
  84. return 1
  85. mailpass = 0
  86. for x in range(1, 5):
  87. fo = open(mailfile, 'r')
  88. maillog = fo.readlines()[-10:]
  89. fo.close()
  90. if (log_match in str(maillog)):
  91. self.logger.info("Message found in " + mailfile)
  92. mailpass = 1
  93. break
  94. self.assertTrue(mailpass, "Message not found in " + mailfile)
  95. def test_long_resource_reque(self):
  96. """
  97. Test to see if a very long string value is truncated
  98. in the 'R' requeue accounting record
  99. """
  100. # Create a very long string - the truncation was 2048 characters
  101. # 4096 is plenty big to show it
  102. hstr = ""
  103. for i in range(4096):
  104. hstr += "1"
  105. hook_body = "import pbs\n"
  106. hook_body += "e = pbs.event()\n"
  107. hook_body += "hstr=\'" + hstr + "\'\n"
  108. hook_body += "e.job.resources_used[\"foo_str\"] = hstr\n"
  109. a = {'event': 'execjob_prologue', 'enabled': 'True'}
  110. self.server.create_import_hook("pr", a, hook_body)
  111. J = Job()
  112. jid = self.server.submit(J)
  113. self.server.expect(JOB, {'job_state': 'R', 'substate': 42}, id=jid)
  114. self.server.manager(MGR_CMD_SET, SERVER, {'scheduling': 'False'})
  115. self.server.rerunjob(jid)
  116. self.server.expect(JOB, {'job_state': 'Q'}, id=jid)
  117. # Make sure the accounting log hasn't been truncated
  118. acctlog_match = 'resources_used.foo_str=' + hstr
  119. self.server.accounting_match(
  120. "R;%s;.*%s.*" % (jid, acctlog_match), regexp=True)