pbs_hook_crosslink_mom.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. @tags('hooks')
  38. class TestPbsHookCrossLinkMom(TestFunctional):
  39. """
  40. When a hook updates attributes of vnodes not belonging to MoM on which
  41. the hook is running, the server wrongly cross links the MoM with the vnode.
  42. This testsuite tests the fix for this issue and needs two MoMs.
  43. """
  44. def setUp(self):
  45. TestFunctional.setUp(self)
  46. if len(self.moms) != 2:
  47. self.skipTest('test requires two MoMs as input, ' +
  48. 'use -p moms=<mom1>:<mom2>')
  49. self.momA = self.moms.values()[0]
  50. self.momB = self.moms.values()[1]
  51. self.hostA = self.momA.shortname
  52. self.hostB = self.momB.shortname
  53. a = {'job_history_enable': 'True'}
  54. self.server.manager(MGR_CMD_SET, SERVER, a)
  55. def test_crosslink(self):
  56. """
  57. This test creates a execjob_end hook which updates an attribute of
  58. all vnodes. A job is submitted that runs on two different MoM hosts.
  59. When the job has finished, the test checks if the server did the wrong
  60. cross-linking or not.
  61. """
  62. status = self.server.status(NODE, id=self.hostA)
  63. Mom1_before = status[0][ATTR_NODE_Mom]
  64. status = self.server.status(NODE, id=self.hostB)
  65. Mom2_before = status[0][ATTR_NODE_Mom]
  66. hook_name = "job_end"
  67. hook_body = """
  68. import pbs
  69. this_event = pbs.event()
  70. if this_event.type == pbs.EXECJOB_END:
  71. job = this_event.job
  72. exec_vnode = str(job.exec_vnode).replace("(", "").replace(")", "")
  73. vnodes = sorted(set([x.partition(':')[0]
  74. for x in exec_vnode.split('+')]))
  75. for h in vnodes:
  76. try:
  77. pbs.logjobmsg(job.id, "vnode is %s ======" % h)
  78. pbs.event().vnode_list[h].current_eoe = None
  79. except:
  80. pass
  81. this_event.accept()
  82. """
  83. a = {'event': "execjob_end", 'enabled': 'true', 'debug': 'true'}
  84. self.server.create_import_hook(hook_name, a, hook_body)
  85. select = "1:host=" + self.hostA + ":ncpus=1+1:host=" \
  86. + self.hostB + ":ncpus=1"
  87. a = {'Resource_List.select': select, ATTR_k: 'oe'}
  88. j = Job(TEST_USER, a)
  89. j.set_sleep_time(1)
  90. jid = self.server.submit(j)
  91. self.server.expect(JOB, {'job_state': 'F'}, id=jid, extend='x')
  92. status = self.server.status(NODE, id=self.hostA)
  93. Mom = status[0][ATTR_NODE_Mom]
  94. self.assertEquals(Mom, Mom1_before)
  95. status = self.server.status(NODE, id=self.hostB)
  96. Mom = status[0][ATTR_NODE_Mom]
  97. self.assertEquals(Mom, Mom2_before)