pbs_provisioning.py 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. import time
  37. from tests.functional import *
  38. hook_begin = """
  39. import pbs
  40. pbs.logmsg(pbs.LOG_DEBUG,
  41. "executed execjob_begin hook on job %s" % (pbs.event().job.id))
  42. """
  43. hook_provision = """
  44. import pbs
  45. import time
  46. e = pbs.event()
  47. vnode = e.vnode
  48. aoe = e.aoe
  49. if aoe == 'App1':
  50. pbs.logmsg(pbs.LOG_DEBUG, "fake calling application provisioning script")
  51. e.accept(1)
  52. pbs.logmsg(pbs.LOG_DEBUG, "aoe=%s,vnode=%s" % (aoe,vnode))
  53. pbs.logmsg(pbs.LOG_DEBUG, "fake calling os provisioning script")
  54. e.accept(0)
  55. """
  56. class TestProvisioningJob(TestFunctional):
  57. """
  58. This testsuite tests whether OS provisioned jobs are getting all
  59. required hook files at MOM
  60. PRE: Have a cluster of PBS with a MOM installed on other
  61. than PBS server host.
  62. 1) Enable provisioning and set AOEs to the provisioning MOM
  63. 2) Create Hooks
  64. i) Provisioning hook which is facking OS provisioning.
  65. ii) execjob_begin hook prints a log message on MOM node.
  66. 3) Submit job with an aoe.
  67. 4) Node will go into the provisioning state while it is
  68. running provisioning hook.
  69. 5) Deletes execjob_begin hook file begin.PY from MOM
  70. 6) Restarts MOM as we are not doing actual OS provisioning
  71. 7) Then check for hook files are copied to the MOM node
  72. and job is printing log message from execjob_begin hook.
  73. """
  74. hook_list = ['begin', 'my_provisioning']
  75. hostA = ""
  76. def setUp(self):
  77. TestFunctional.setUp(self)
  78. self.momA = self.moms.values()[0]
  79. serverA = (self.servers.values()[0]).shortname
  80. self.hostA = self.momA.shortname
  81. msg = ("Server and Mom can't be on the same host. "
  82. "Provide a mom not present on server host "
  83. "while invoking the test: -p moms=<m1>")
  84. if serverA == self.hostA:
  85. self.skipTest(msg)
  86. self.momA.delete_vnode_defs()
  87. self.logger.info(self.momA.shortname)
  88. self.server.manager(
  89. MGR_CMD_DELETE, NODE, None, "", runas=ROOT_USER)
  90. self.server.manager(MGR_CMD_CREATE, NODE, id=self.hostA)
  91. a = {'provision_enable': 'true'}
  92. self.server.manager(
  93. MGR_CMD_SET, NODE, a, id=self.hostA, expect=True)
  94. self.server.manager(
  95. MGR_CMD_SET, SERVER, {
  96. 'log_events': 2047}, expect=True)
  97. self.server.expect(NODE, {'state': 'free'}, id=self.hostA)
  98. a = {'event': 'execjob_begin', 'enabled': 'True'}
  99. rv = self.server.create_import_hook(
  100. self.hook_list[0], a, hook_begin, overwrite=True)
  101. self.assertTrue(rv)
  102. a = {'event': 'provision', 'enabled': 'True', 'alarm': '300'}
  103. rv = self.server.create_import_hook(
  104. self.hook_list[1], a, hook_provision, overwrite=True)
  105. self.assertTrue(rv)
  106. def test_execjob_begin_hook_on_os_provisioned_job(self):
  107. """
  108. Test the execjob_begin hook is seen by OS provisioned job.
  109. """
  110. a = {'resources_available.aoe': 'osimage1'}
  111. self.server.manager(
  112. MGR_CMD_SET, NODE, a, id=self.hostA, expect=True)
  113. job = Job(TEST_USER1, attrs={ATTR_l: 'aoe=osimage1'})
  114. job.set_sleep_time(1)
  115. jid = self.server.submit(job)
  116. rv = self.server.expect(NODE, {'state': 'provisioning'}, id=self.hostA)
  117. self.assertTrue(rv)
  118. phome = self.momA.pbs_conf['PBS_HOME']
  119. begin = os.path.join(phome, 'mom_priv', 'hooks', 'begin.PY')
  120. ret = self.du.rm(self.momA.shortname, begin, force=True,
  121. sudo=True, logerr=False)
  122. if not ret:
  123. self.logger.error("problem deleting %s" % begin)
  124. self.momA.restart()
  125. time.sleep(5)
  126. rv = self.server.log_match(
  127. "successfully sent hook file "
  128. "/var/spool/pbs/server_priv/hooks/begin.PY",
  129. max_attempts=20,
  130. interval=1)
  131. self.assertTrue(rv)
  132. rv = self.mom.log_match("begin.PY;copy hook-related file "
  133. "request received",
  134. regexp=True,
  135. max_attempts=20,
  136. interval=1)
  137. self.assertTrue(rv)
  138. rv = self.mom.log_match("executed execjob_begin hook on job %s" % jid,
  139. regexp=True,
  140. max_attempts=20,
  141. interval=1)
  142. self.assertTrue(rv)
  143. def test_app_provisioning(self):
  144. """
  145. Test application provisioning
  146. """
  147. a = {'resources_available.aoe': 'App1'}
  148. self.server.manager(
  149. MGR_CMD_SET, NODE, a, id=self.hostA, expect=True)
  150. job = Job(TEST_USER1, attrs={ATTR_l: 'aoe=App1'})
  151. job.set_sleep_time(1)
  152. jid = self.server.submit(job)
  153. self.server.expect(JOB, {'job_state': 'R'}, id=jid)
  154. self.server.log_match(
  155. "fake calling application provisioning script",
  156. max_attempts=20,
  157. interval=1)