pbs_pbstestsuite.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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.selftest import *
  37. from ptl.utils.pbs_snaputils import *
  38. class TestPBSTestSuite(TestSelf):
  39. """
  40. Contains tests for pbs_testsuite module's functionality
  41. """
  42. def test_revert_pbsconf_onehost(self):
  43. """
  44. Test the functionality of PBSTestSuite.revert_pbsconf()
  45. for a single host type 1 installation
  46. """
  47. pbs_conf_val = self.du.parse_pbs_config(self.server.hostname)
  48. self.assertTrue(pbs_conf_val and len(pbs_conf_val) >= 1,
  49. "Could not parse pbs.conf on host %s" %
  50. (self.server.hostname))
  51. # Since the setUp already ran, check that the start bits are turned on
  52. self.assertEqual(pbs_conf_val["PBS_START_MOM"], "1")
  53. self.assertEqual(pbs_conf_val["PBS_START_SERVER"], "1")
  54. self.assertEqual(pbs_conf_val["PBS_START_SCHED"], "1")
  55. self.assertEqual(pbs_conf_val["PBS_START_COMM"], "1")
  56. self.server.pi.stop()
  57. # Now, change pbs.conf to turn the sched off
  58. pbs_conf_val["PBS_START_SCHED"] = "0"
  59. self.du.set_pbs_config(confs=pbs_conf_val)
  60. # Start PBS again
  61. self.server.pi.start()
  62. # Verify that the scheduler didn't come up
  63. self.assertFalse(self.scheduler.isUp())
  64. # Now call revert_pbsconf()
  65. self.revert_pbsconf()
  66. # Verify that the scheduler came up and start bit is 1
  67. self.assertTrue(self.scheduler.isUp())
  68. pbs_conf_val = self.du.parse_pbs_config(self.server.hostname)
  69. self.assertEqual(pbs_conf_val["PBS_START_SCHED"], "1")
  70. def test_revert_pbsconf_remotemom(self):
  71. """
  72. Test the functionality of PBSTestSuite.revert_pbsconf()
  73. with a remote mom setup
  74. """
  75. remotemom = None
  76. for mom in self.moms.values():
  77. if not self.du.is_localhost(mom.hostname):
  78. remotemom = mom
  79. break
  80. if remotemom is None:
  81. self.skip_test("Test needs at least one remote Mom host,"
  82. " use -p moms=<hostname>")
  83. pbs_conf_val = self.du.parse_pbs_config(self.server.hostname)
  84. self.assertTrue(pbs_conf_val and len(pbs_conf_val) >= 1,
  85. "Could not parse pbs.conf on host %s" %
  86. (self.server.hostname))
  87. # Check that the start bits on server host are set correctly
  88. self.assertEqual(pbs_conf_val["PBS_START_SERVER"], "1")
  89. self.assertEqual(pbs_conf_val["PBS_START_SCHED"], "1")
  90. self.assertEqual(pbs_conf_val["PBS_START_COMM"], "1")
  91. if self.server.hostname in self.moms:
  92. self.assertEqual(pbs_conf_val["PBS_START_MOM"], "1")
  93. else:
  94. self.assertEqual(pbs_conf_val["PBS_START_MOM"], "0")
  95. # Check that the remote mom's pbs.conf has mom start bit on
  96. pbs_conf_val = self.du.parse_pbs_config(remotemom.hostname)
  97. self.assertEqual(pbs_conf_val["PBS_START_MOM"], "1")
  98. # Now set it to 0 and restart the mom
  99. remotemom.pi.stop(remotemom.hostname)
  100. pbs_conf_val["PBS_START_MOM"] = "0"
  101. self.du.set_pbs_config(remotemom.hostname, confs=pbs_conf_val)
  102. remotemom.pi.start(remotemom.hostname)
  103. # Confirm that the mom is down
  104. self.assertFalse(remotemom.isUp())
  105. # Now call revert_pbsconf()
  106. self.revert_pbsconf()
  107. # Confirm that the mom came up and start bit is 1
  108. self.assertTrue(remotemom.isUp())
  109. pbs_conf_val = self.du.parse_pbs_config(remotemom.hostname)
  110. self.assertEqual(pbs_conf_val["PBS_START_MOM"], "1")
  111. def test_revert_pbsconf_corelimit(self):
  112. """
  113. Test the functionality of PBSTestSuite.revert_pbsconf() when
  114. PBS_CORE_LIMIT is set to a value other than the default
  115. """
  116. pbs_conf_val = self.du.parse_pbs_config(self.server.hostname)
  117. self.assertTrue(pbs_conf_val and len(pbs_conf_val) >= 1,
  118. "Could not parse pbs.conf on host %s" %
  119. (self.server.hostname))
  120. # Since the setUp already ran, check that PBS_CORE_LIMIT is set to
  121. # unlimited
  122. self.assertEqual(pbs_conf_val["PBS_CORE_LIMIT"], "unlimited")
  123. # Now, set the core limit to 0 and restart PBS
  124. self.server.pi.stop()
  125. pbs_conf_val["PBS_CORE_LIMIT"] = "0"
  126. self.du.set_pbs_config(confs=pbs_conf_val)
  127. self.server.pi.start()
  128. # First, check that there's no existing core file in mom_priv
  129. mom_priv_path = os.path.join(self.server.pbs_conf["PBS_HOME"],
  130. "mom_priv")
  131. mom_priv_filenames = self.du.listdir(self.server.hostname,
  132. mom_priv_path, sudo=True,
  133. fullpath=False)
  134. for filename in mom_priv_filenames:
  135. if filename.startswith("core"):
  136. # Found a core file, delete it
  137. corepath = os.path.join(mom_priv_path, filename)
  138. self.du.rm(self.server.hostname, corepath, sudo=True,
  139. force=True)
  140. # Send SIGSEGV to pbs_mom
  141. self.assertTrue(self.mom.isUp())
  142. self.mom.signal("-SEGV")
  143. self.assertFalse(self.mom.isUp())
  144. # Confirm that no core file was generated
  145. mom_priv_filenames = self.du.listdir(self.server.hostname,
  146. mom_priv_path, sudo=True,
  147. fullpath=False)
  148. corefound = False
  149. for filename in mom_priv_filenames:
  150. if filename.startswith("core"):
  151. corefound = True
  152. break
  153. self.assertFalse(corefound, "mom unexpectedly dumped core")
  154. # Now, call self.revert_pbsconf()
  155. self.revert_pbsconf()
  156. # Confirm that PBS_CORE_LIMIT was reverted
  157. pbs_conf_val = self.du.parse_pbs_config(self.server.hostname)
  158. self.assertEqual(pbs_conf_val["PBS_CORE_LIMIT"], "unlimited")
  159. # Send another SIGSEGV to pbs_mom
  160. self.assertTrue(self.mom.isUp())
  161. self.mom.signal("-SEGV")
  162. self.assertFalse(self.mom.isUp())
  163. # Confirm that a core file was generated this time
  164. mom_priv_filenames = self.du.listdir(self.server.hostname,
  165. mom_priv_path, sudo=True,
  166. fullpath=False)
  167. corefound = False
  168. for filename in mom_priv_filenames:
  169. if filename.startswith("core"):
  170. corefound = True
  171. break
  172. self.assertTrue(corefound,
  173. "mom was expected to dump core but it didn't")
  174. def test_revert_pbsconf_extra_vars(self):
  175. """
  176. Test the functionality of PBSTestSuite.revert_pbsconf() when
  177. there are extra pbs.conf variables than the default
  178. """
  179. pbs_conf_val = self.du.parse_pbs_config(self.server.hostname)
  180. self.assertTrue(pbs_conf_val and len(pbs_conf_val) >= 1,
  181. "Could not parse pbs.conf on host %s" %
  182. (self.server.hostname))
  183. # Set a non-default pbs.conf variables, let's say
  184. # PBS_LOG_HIGHRES_TIMESTAMP, and restart PBS
  185. self.server.pi.stop()
  186. pbs_conf_val["PBS_LOG_HIGHRES_TIMESTAMP"] = "1"
  187. self.du.set_pbs_config(confs=pbs_conf_val)
  188. self.server.pi.start()
  189. # Confirm that the pbs.conf variable is set
  190. pbs_conf_val = self.du.parse_pbs_config(self.server.hostname)
  191. self.assertEqual(pbs_conf_val["PBS_LOG_HIGHRES_TIMESTAMP"], "1")
  192. # Now, call self.revert_pbsconf()
  193. self.revert_pbsconf()
  194. # Confirm that the value gets removed from the list as it is not
  195. # a default setting
  196. pbs_conf_val = self.du.parse_pbs_config(self.server.hostname)
  197. self.assertFalse("PBS_LOG_HIGHRES_TIMESTAMP" in pbs_conf_val)
  198. def test_revert_pbsconf_fewer_vars(self):
  199. """
  200. Test the functionality of PBSTestSuite.revert_pbsconf() when
  201. there are fewer pbs.conf variables than the default
  202. """
  203. pbs_conf_val = self.du.parse_pbs_config(self.server.hostname)
  204. self.assertTrue(pbs_conf_val and len(pbs_conf_val) >= 1,
  205. "Could not parse pbs.conf on host %s" %
  206. (self.server.hostname))
  207. # Remove a default pbs.conf variable, say PBS_CORE_LIMIT,
  208. # and restart PBS
  209. self.server.pi.stop()
  210. del pbs_conf_val["PBS_CORE_LIMIT"]
  211. self.du.set_pbs_config(confs=pbs_conf_val, append=False)
  212. self.server.pi.start()
  213. # Confirm that the pbs.conf variable is gone
  214. pbs_conf_val = self.du.parse_pbs_config(self.server.hostname)
  215. self.assertNotIn("PBS_CORE_LIMIT", pbs_conf_val)
  216. # Now, call self.revert_pbsconf()
  217. self.revert_pbsconf()
  218. # Confirm that the variable was set again
  219. pbs_conf_val = self.du.parse_pbs_config(self.server.hostname)
  220. self.assertIn("PBS_CORE_LIMIT", pbs_conf_val)