pbs_root_owned_script.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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_RootOwnedScript(TestFunctional):
  38. """
  39. Test suite to test whether the root owned script is getting rejected
  40. and the comment is getting updated when root_reject_scripts set to true.
  41. """
  42. def setUp(self):
  43. """
  44. Set up the parameters required for Test_RootOwnedScript
  45. """
  46. if os.getuid() != 0:
  47. self.skipTest("Test need to run as root")
  48. TestFunctional.setUp(self)
  49. mom_conf_attr = {'$reject_root_scripts': 'true'}
  50. qmgr_attr = {'acl_roots': ROOT_USER}
  51. self.mom.add_config(mom_conf_attr)
  52. self.mom.restart()
  53. self.server.manager(MGR_CMD_SET, SERVER, qmgr_attr)
  54. self.sleep_5 = """#!/bin/bash
  55. sleep 5
  56. """
  57. def test_root_owned_script(self):
  58. """
  59. Edit the mom config to reject root script
  60. submit a script as root and observe the job comment.
  61. """
  62. j = Job(ROOT_USER)
  63. j.create_script(self.sleep_5)
  64. jid = self.server.submit(j)
  65. self.server.expect(JOB, {'job_state': 'Q'}, id=jid)
  66. _comment = 'Not Running: PBS Error: Execution server rejected request'
  67. self.server.expect(JOB, {'comment': _comment}, id=jid)
  68. def test_non_root_script(self):
  69. """
  70. Edit the mom config to reject root script
  71. submit a script as TEST_USER and observe the job comment.
  72. """
  73. j = Job(TEST_USER)
  74. j.create_script(self.sleep_5)
  75. jid = self.server.submit(j)
  76. self.server.expect(JOB, {'job_state': 'R'}, id=jid)