pbs_systemd.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 socket
  38. class Test_systemd(TestFunctional):
  39. """
  40. Test whether you are able to control pbs using systemd
  41. """
  42. def setUp(self):
  43. TestFunctional.setUp(self)
  44. # Skip test if systemctl command is not found.
  45. is_systemctl = self.du.which(exe='systemctl')
  46. if is_systemctl == 'systemctl':
  47. self.skipTest("Systemctl command not found")
  48. def shutdown_all(self):
  49. if self.server.isUp():
  50. self.server.stop()
  51. if self.scheduler.isUp():
  52. self.scheduler.stop()
  53. if self.comm.isUp():
  54. self.comm.stop()
  55. if self.mom.isUp():
  56. self.mom.stop()
  57. def start_using_systemd(self):
  58. cmd = "systemctl start pbs"
  59. self.du.run_cmd(self.hostname, cmd, True)
  60. if ('1' == self.server.pbs_conf['PBS_START_SERVER'] and
  61. not self.server.isUp()):
  62. return False
  63. if ('1' == self.server.pbs_conf['PBS_START_SCHED'] and
  64. not self.scheduler.isUp()):
  65. return False
  66. if ('1' == self.server.pbs_conf['PBS_START_COMM'] and
  67. not self.comm.isUp()):
  68. return False
  69. if ('1' == self.server.pbs_conf['PBS_START_MOM'] and
  70. not self.mom.isUp()):
  71. return False
  72. return True
  73. def stop_using_systemd(self):
  74. cmd = "systemctl stop pbs"
  75. self.du.run_cmd(self.hostname, cmd, True)
  76. if ('1' == self.server.pbs_conf['PBS_START_SERVER'] and
  77. self.server.isUp()):
  78. return False
  79. if ('1' == self.server.pbs_conf['PBS_START_SCHED'] and
  80. self.scheduler.isUp()):
  81. return False
  82. if '1' == self.server.pbs_conf['PBS_START_COMM'] and self.comm.isUp():
  83. return False
  84. if '1' == self.server.pbs_conf['PBS_START_MOM'] and self.mom.isUp():
  85. return False
  86. return True
  87. def test_systemd(self):
  88. """
  89. Test whether you are able to control pbs using systemd
  90. """
  91. self.hostname = socket.gethostname()
  92. cmd = "systemctl daemon-reload"
  93. out = self.du.run_cmd(self.hostname, cmd, True)
  94. self.shutdown_all()
  95. rv = self.start_using_systemd()
  96. self.assertTrue(rv)
  97. rv = self.stop_using_systemd()
  98. self.assertTrue(rv)
  99. rv = self.start_using_systemd()