pbs_highreslog.py 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 TestHighResLogging(TestFunctional):
  38. """
  39. TestSuite for High resolution logging in PBS
  40. """
  41. tm_micro_re = re.compile(
  42. r'(\d{2,2}/\d{2,2}/\d{4,4}\s\d{2,2}:\d{2,2}:\d{2,2}.\d{6,6})')
  43. def validate_trace_job_lines(self, jid=None):
  44. """
  45. Validate that tracejob lines have high resolution time
  46. stamp
  47. """
  48. lines = self.server.log_lines(logtype='tracejob', id=jid, n='ALL')
  49. if len(lines) > 1:
  50. # Remove first line as it is not log line
  51. lines = lines[1:]
  52. for line in lines:
  53. m = self.tm_micro_re.match(line)
  54. if m is None:
  55. # If this is accounting log, ignore it as
  56. # Accounting log does not have high res logging
  57. line = line.split()
  58. _msg = 'Not Found high resolution time stamp in log'
  59. self.assertFalse(len(line) >= 3 and
  60. (line[2].strip() != 'A'), _msg)
  61. _msg = self.server.shortname + \
  62. ': High resolution time stamp found in log'
  63. self.logger.info(_msg)
  64. def validate_server_log_lines(self):
  65. """
  66. validates that the server_log lines have high resolution
  67. time stamp
  68. """
  69. lines = self.server.log_lines(logtype=self.server, n=20)
  70. for line in lines:
  71. m = self.tm_micro_re.match(line)
  72. _msg = 'Not Found high resolution time stamp in log'
  73. self.assertTrue(m, _msg)
  74. _msg = self.server.shortname + \
  75. ': High resolution time stamp found in log'
  76. self.logger.info(_msg)
  77. def test_disabled(self):
  78. """
  79. Default High resolution should be disabled (logfile version)
  80. """
  81. j = Job(TEST_USER)
  82. jid = self.server.submit(j)
  83. self.server.expect(JOB, {ATTR_state: 'R'}, id=jid)
  84. lines = self.server.log_lines(logtype=self.server,
  85. starttime=self.server.ctime)
  86. _msg = 'Found high resolution time stamp in log,' \
  87. ' it shouldn\'t be there'
  88. for line in lines:
  89. m = self.tm_micro_re.match(line)
  90. self.assertIsNone(m, _msg)
  91. _msg = self.server.shortname + \
  92. ': High resolution time stamp correctly not set in log'
  93. self.logger.info(_msg)
  94. def test_disabled_tracejob(self):
  95. """
  96. Default High resolution should be disabled (tracejob version)
  97. """
  98. j = Job(TEST_USER)
  99. jid = self.server.submit(j)
  100. self.server.expect(JOB, {ATTR_state: 'R'}, id=jid)
  101. lines = self.server.log_lines(logtype='tracejob', id=jid, n='ALL')
  102. if len(lines) > 1:
  103. # Remove first line as it is not log line
  104. lines = lines[1:]
  105. _msg = 'Found high resolution time stamp in tracejob, ' \
  106. 'it should not be there'
  107. for line in lines:
  108. m = self.tm_micro_re.match(line)
  109. self.assertIsNone(m, _msg)
  110. _msg = self.server.shortname + \
  111. ': High resolution time stamp correctly not set in ' \
  112. 'tracejob output'
  113. self.logger.info(_msg)
  114. def test_basic(self):
  115. """
  116. Enable High resolution logging, restart server
  117. and look for high resolution time stamp in server log
  118. """
  119. a = {'PBS_LOG_HIGHRES_TIMESTAMP': 1}
  120. self.du.set_pbs_config(confs=a, append=True)
  121. _msg = 'Failed to restart server: %s' % (self.server.shortname)
  122. self.assertTrue(self.server.restart(), _msg)
  123. j = Job(TEST_USER)
  124. jid = self.server.submit(j)
  125. self.server.expect(JOB, {ATTR_state: 'R'}, id=jid)
  126. self.validate_server_log_lines()
  127. def test_basic_tracejob(self):
  128. """
  129. Enable High resolution logging, restart PBS Daemons
  130. and look for high resolution time stamp in tracejob output
  131. """
  132. a = {'PBS_LOG_HIGHRES_TIMESTAMP': 1}
  133. self.du.set_pbs_config(confs=a, append=True)
  134. PBSInitServices().restart()
  135. self.assertTrue(self.server.isUp(), 'Failed to restart PBS Daemons')
  136. j = Job(TEST_USER)
  137. jid = self.server.submit(j)
  138. self.server.expect(JOB, {ATTR_state: 'R'}, id=jid)
  139. self.validate_trace_job_lines(jid=jid)
  140. def test_env_variable_overwrite(self):
  141. """
  142. Check env variable overwrites the pbs.conf value
  143. """
  144. a = {'PBS_LOG_HIGHRES_TIMESTAMP': 0}
  145. self.du.set_pbs_config(confs=a, append=True)
  146. conf_path = self.du.parse_pbs_config()
  147. pbs_init = os.path.join(os.sep, conf_path['PBS_EXEC'],
  148. 'libexec', 'pbs_init.d')
  149. cmd = ['sudo', 'PBS_LOG_HIGHRES_TIMESTAMP=1', pbs_init, 'restart']
  150. self.du.run_cmd(cmd=cmd, as_script=True, wait_on_script=True)
  151. j = Job(TEST_USER)
  152. jid = self.server.submit(j)
  153. self.server.expect(JOB, {ATTR_state: 'R'}, id=jid)
  154. self.validate_server_log_lines()
  155. self.validate_trace_job_lines(jid=jid)
  156. def tearDown(self):
  157. confs = self.du.parse_pbs_config()
  158. if 'PBS_LOG_HIGHRES_TIMESTAMP' in confs:
  159. del confs['PBS_LOG_HIGHRES_TIMESTAMP']
  160. self.du.set_pbs_config(confs=confs, append=False)
  161. PBSInitServices().restart()
  162. PBSTestSuite.tearDown(self)