pbs_verify_log_output.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 sys
  38. import socket
  39. import fcntl
  40. import struct
  41. import array
  42. class TestVerifyLogOutput(TestFunctional):
  43. """
  44. Test that hostname and interface information
  45. is added to all logs at log open
  46. """
  47. def setUp(self):
  48. TestFunctional.setUp(self)
  49. def all_interfaces(self):
  50. """
  51. Miscellaneous function to return all interface names
  52. that should also be added to logs
  53. """
  54. is_64bits = sys.maxsize > 2**32
  55. struct_size = 40 if is_64bits else 32
  56. s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  57. max_possible = 8
  58. while True:
  59. bytes = max_possible * struct_size
  60. names = array.array('B', '\0' * bytes)
  61. outbytes = struct.unpack('iL', fcntl.ioctl(
  62. s.fileno(),
  63. 0x8912,
  64. struct.pack('iL', bytes, names.buffer_info()[0])
  65. ))[0]
  66. if outbytes == bytes:
  67. max_possible *= 2
  68. else:
  69. break
  70. namestr = names.tostring()
  71. for i in range(0, outbytes, struct_size):
  72. yield namestr[i:i + 16].split('\0', 1)[0]
  73. def test_hostname_add(self):
  74. """
  75. Test for hostname presence in log files
  76. """
  77. log_val = socket.gethostname()
  78. self.scheduler.log_match(
  79. log_val,
  80. regexp=False,
  81. starttime=self.server.ctime,
  82. max_attempts=5,
  83. interval=2)
  84. self.server.log_match(
  85. log_val,
  86. regexp=False,
  87. starttime=self.server.ctime,
  88. max_attempts=5,
  89. interval=2)
  90. self.mom.log_match(
  91. log_val,
  92. regexp=False,
  93. starttime=self.server.ctime,
  94. max_attempts=5,
  95. interval=2)
  96. def test_if_info_add(self):
  97. """
  98. Test for interface info presence in log files
  99. """
  100. interfaceGenerator = self.all_interfaces()
  101. for ifname in interfaceGenerator:
  102. name = "[(" + ifname + ")]"
  103. log_val = "[( interface: )]" + name
  104. # Workaround for PTL regex to match
  105. # entire word once using () inside []
  106. self.scheduler.log_match(
  107. log_val,
  108. regexp=True,
  109. starttime=self.server.ctime,
  110. max_attempts=5,
  111. interval=2)
  112. self.server.log_match(
  113. log_val,
  114. regexp=True,
  115. starttime=self.server.ctime,
  116. max_attempts=5,
  117. interval=2)
  118. self.mom.log_match(
  119. log_val,
  120. regexp=True,
  121. starttime=self.server.ctime,
  122. max_attempts=5,
  123. interval=2)
  124. def test_auto_sched_cycle_trigger(self):
  125. """
  126. Test case to verify that scheduling cycle is triggered automatically
  127. without any delay after restart of PBS Services.
  128. """
  129. started_time = time.time()
  130. self.logger.info('Restarting PBS Services')
  131. PBSInitServices().restart()
  132. if self.server.isUp() and self.scheduler.isUp():
  133. try:
  134. self.scheduler.log_match("Req;;Starting Scheduling Cycle",
  135. max_attempts=10,
  136. starttime=started_time)
  137. self.scheduler.log_match("Req;;Leaving Scheduling Cycle",
  138. max_attempts=10,
  139. starttime=started_time)
  140. except PtlLogMatchError:
  141. self.assertFalse(True)