pbs_node_partition.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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.interfaces import *
  37. @tags('multisched')
  38. class TestNodePartition(TestInterfaces):
  39. """
  40. Test suite to test partition attr for node
  41. """
  42. # Node id is MoM's short name
  43. host_name = socket.gethostname().split('.')[0]
  44. def set_node_partition_attr(self, mgr_cmd="MGR_CMD_SET", n_name=host_name,
  45. partition="P1", user=ROOT_USER):
  46. """
  47. Common function to set partition attribute to node object
  48. :param mgr_cmd: qmgr "MGR_CMD_SET/MGR_CMD_UNSET" cmd,
  49. Defaults to MGR_CMD_SET
  50. :type mgr_cmd: str
  51. :param n_name: name of the vnode, Defaults to "hostname of server"
  52. :type n_name: str
  53. :param partition: "partition" attribute of node object,
  54. Defaults to "P1"
  55. :type partition: str
  56. :param user: one of the pre-defined set of users
  57. :type user: :py:class:`~ptl.lib.pbs_testlib.PbsUser`
  58. """
  59. attr = {'partition': partition}
  60. if mgr_cmd is "MGR_CMD_SET":
  61. self.server.manager(MGR_CMD_SET, NODE, attr,
  62. id=n_name, expect=True, runas=user)
  63. elif mgr_cmd is "MGR_CMD_UNSET":
  64. self.server.manager(MGR_CMD_UNSET, NODE,
  65. "partition", id=n_name, expect=True,
  66. runas=user)
  67. else:
  68. msg = ("Error: test_set_node_partition_attr function takes only "
  69. "MGR_CMD_SET/MGR_CMD_UNSET value for mgr_cmd")
  70. self.assertTrue(False, msg)
  71. def test_set_unset_partition_node_attr(self):
  72. """
  73. Test to set/unset the partition attribute of node object
  74. """
  75. self.set_node_partition_attr()
  76. self.set_node_partition_attr(partition="P2")
  77. # resetting the same partition value
  78. self.set_node_partition_attr(partition="P2")
  79. self.set_node_partition_attr(mgr_cmd="MGR_CMD_UNSET")
  80. def test_set_partition_node_attr_user_permissions(self):
  81. """
  82. Test to check the user permissions for set/unset the partition
  83. attribute of node
  84. """
  85. self.set_node_partition_attr()
  86. msg1 = "Unauthorized Request"
  87. msg2 = "didn't receive expected error message"
  88. try:
  89. self.set_node_partition_attr(partition="P2", user=TEST_USER)
  90. except PbsManagerError as e:
  91. self.assertTrue(msg1 in e.msg[0], msg2)
  92. try:
  93. self.set_node_partition_attr(mgr_cmd="MGR_CMD_UNSET",
  94. user=TEST_USER)
  95. except PbsManagerError as e:
  96. # self.assertEquals(e.rc, 15007)
  97. # The above code has to be uncommented when the PTL framework
  98. # bug PP-881 gets fixed
  99. self.assertTrue(msg1 in e.msg[0], msg2)
  100. def test_partition_association_with_node_and_queue(self):
  101. """
  102. Test to check the set of partition attribute and association
  103. between queue and node
  104. """
  105. attr = {'queue_type': "execution", 'enabled': "True",
  106. 'started': "True", 'partition': "P1"}
  107. self.server.manager(MGR_CMD_CREATE,
  108. QUEUE, attr,
  109. id="Q1", expect=True)
  110. self.set_node_partition_attr()
  111. attr = {'queue_type': "execution", 'enabled': "True",
  112. 'started': "True", 'partition': "P2"}
  113. self.server.manager(MGR_CMD_CREATE,
  114. QUEUE, attr,
  115. id="Q2", expect=True)
  116. self.set_node_partition_attr(mgr_cmd="MGR_CMD_UNSET")
  117. self.server.manager(MGR_CMD_SET, NODE, {
  118. 'queue': "Q2"}, id=self.host_name, expect=True)
  119. self.set_node_partition_attr(partition="P2")
  120. def test_mismatch_of_partition_on_node_and_queue(self):
  121. """
  122. Test to check the set of partition attribute is disallowed
  123. if partition ids do not match on queue and node
  124. """
  125. self.test_partition_association_with_node_and_queue()
  126. msg1 = "Invalid partition in queue"
  127. msg2 = "didn't receive expected error message"
  128. try:
  129. self.server.manager(MGR_CMD_SET,
  130. QUEUE, {'partition': "P1"},
  131. id="Q2")
  132. except PbsManagerError as e:
  133. # self.assertEquals(e.rc, 15221)
  134. # The above code has to be uncommented when the PTL framework
  135. # bug PP-881 gets fixed
  136. self.assertTrue(msg1 in e.msg[0], msg2)
  137. msg1 = "Partition P2 is not part of queue for node"
  138. try:
  139. self.server.manager(MGR_CMD_SET,
  140. NODE, {'queue': "Q1"},
  141. id=self.host_name)
  142. except PbsManagerError as e:
  143. # self.assertEquals(e.rc, 15220)
  144. # The above code has to be uncommented when the PTL framework
  145. # bug PP-881 gets fixed
  146. self.assertTrue(msg1 in e.msg[0], msg2)
  147. msg1 = "Queue Q2 is not part of partition for node"
  148. try:
  149. self.set_node_partition_attr()
  150. except PbsManagerError as e:
  151. # self.assertEquals(e.rc, 15219)
  152. # The above code has to be uncommented when the PTL framework
  153. # bug PP-881 gets fixed
  154. self.assertTrue(msg1 in e.msg[0], msg2)