pbs_acl_host_moms.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 Test_acl_host_moms(TestFunctional):
  38. """
  39. This test suite is for testing the server attribute acl_host_moms_enable
  40. and this test requires two moms.
  41. """
  42. def setUp(self):
  43. """
  44. Determine the remote host and set acl_host_enable = True
  45. """
  46. TestFunctional.setUp(self)
  47. usage_string = 'test requires a MoM and a client as input, ' + \
  48. ' use -p moms=<mom>,client=<client>'
  49. # PBSTestSuite returns the moms passed in as parameters as dictionary
  50. # of hostname and MoM object
  51. self.momA = self.moms.values()[0]
  52. self.momA.delete_vnode_defs()
  53. self.hostA = self.momA.shortname
  54. if not self.du.is_localhost(self.server.client):
  55. # acl_hosts expects FQDN
  56. self.hostB = socket.getfqdn(self.server.client)
  57. else:
  58. self.skip_test(usage_string)
  59. self.remote_host = None
  60. if not self.du.is_localhost(self.hostA):
  61. self.remote_host = self.hostA
  62. else:
  63. self.skip_test(usage_string)
  64. self.assertTrue(self.remote_host)
  65. self.server.manager(MGR_CMD_SET, SERVER, {
  66. 'acl_hosts': self.hostB}, expect=True)
  67. self.server.manager(MGR_CMD_SET, SERVER, {
  68. 'acl_host_enable': True}, expect=True)
  69. self.pbsnodes_cmd = os.path.join(self.server.pbs_conf[
  70. 'PBS_EXEC'], 'bin', 'pbsnodes') + ' -av'
  71. self.qstat_cmd = os.path.join(self.server.pbs_conf[
  72. 'PBS_EXEC'], 'bin', 'qstat')
  73. def test_acl_host_moms_enable(self):
  74. """
  75. Set acl_host_moms_enable = True and check whether or not the remote
  76. host is able run pbsnodes and qstat.
  77. """
  78. self.server.manager(MGR_CMD_SET, SERVER, {
  79. 'acl_host_moms_enable': True}, expect=True)
  80. ret = self.du.run_cmd(self.remote_host, cmd=self.pbsnodes_cmd)
  81. self.assertEqual(ret['rc'], 0)
  82. ret = self.du.run_cmd(self.remote_host, cmd=self.qstat_cmd)
  83. self.assertEqual(ret['rc'], 0)
  84. def test_acl_host_moms_disable(self):
  85. """
  86. Set acl_host_moms_enable = False and check whether or not the remote
  87. host is forbidden to run pbsnodes and qstat.
  88. """
  89. self.server.manager(MGR_CMD_SET, SERVER, {
  90. 'acl_host_moms_enable': False}, expect=True)
  91. ret = self.du.run_cmd(self.remote_host, cmd=self.pbsnodes_cmd)
  92. self.assertNotEqual(ret['rc'], 0)
  93. ret = self.du.run_cmd(self.remote_host, cmd=self.qstat_cmd)
  94. self.assertNotEqual(ret['rc'], 0)
  95. def test_acl_host_moms_hooks_and_jobs(self):
  96. """
  97. Use hooks to test whether remote host is able to run pbs.server()
  98. and check whether the job that is submitted goes to the 'R' state.
  99. """
  100. hook_name = "hook_acl_host_moms_t"
  101. hook_body = """
  102. import pbs
  103. e = pbs.event()
  104. svr = pbs.server().server_state
  105. e.accept()
  106. """
  107. try:
  108. self.server.manager(MGR_CMD_DELETE, HOOK, None, hook_name)
  109. except Exception:
  110. pass
  111. a = {'event': 'execjob_begin', 'enabled': 'True'}
  112. self.server.create_import_hook(
  113. hook_name, a, hook_body, overwrite=True)
  114. self.server.manager(MGR_CMD_SET, SERVER, {
  115. 'acl_host_moms_enable': False}, expect=True)
  116. j = Job()
  117. j.set_sleep_time(10)
  118. jid = self.server.submit(j)
  119. self.server.expect(JOB, {'job_state': 'H'}, id=jid)
  120. self.server.manager(MGR_CMD_SET, SERVER, {
  121. 'acl_host_moms_enable': True}, expect=True)
  122. j = Job()
  123. j.set_sleep_time(10)
  124. jid = self.server.submit(j)
  125. self.server.expect(JOB, {'job_state': 'R'}, id=jid)
  126. def test_acl_host_mom_queue_access(self):
  127. """
  128. Test that remote host cannot submit jobs to queue where
  129. acl_host_enable is True and acl_host_moms_enable is set
  130. on server, but remote host is not added in acl_hosts.
  131. """
  132. queue_n = 'tempq'
  133. queue_params = {'queue_type': 'Execution', 'enabled': 'True',
  134. 'started': 'True', 'acl_host_enable': 'True'}
  135. self.server.manager(MGR_CMD_CREATE, QUEUE, queue_params, id='tempq')
  136. self.server.manager(MGR_CMD_SET, SERVER, {
  137. 'acl_host_moms_enable': True}, expect=True)
  138. # Setting acl_host_enable on queue overrides acl_host_moms_enable
  139. # on server and requires acl_hosts to include remote host's name.
  140. self.server.manager(MGR_CMD_SET, SERVER, {
  141. 'flatuid': True}, expect=True)
  142. # Setting flatuid lets us submit jobs on server as a remote
  143. # host without creating a seperate user account there.
  144. qsub_cmd_on_queue = os.path.join(self.server.pbs_conf[
  145. 'PBS_EXEC'], 'bin',
  146. 'qsub') + ' -q ' + queue_n + ' -- /bin/sleep 10'
  147. j = Job(attrs={ATTR_queue: queue_n})
  148. j.set_sleep_time(10)
  149. cannot_submit = 0
  150. try:
  151. jid = self.server.submit(j)
  152. except PbsSubmitError:
  153. cannot_submit = 1
  154. self.assertEqual(cannot_submit, 1)