pbs_partition.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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. class TestPartition(TestInterfaces):
  38. """
  39. Test suite to test partition attr
  40. """
  41. def partition_attr(self, mgr_cmd=MGR_CMD_SET,
  42. obj_name="QUEUE", q_type=None,
  43. name="Q1", enable="True",
  44. start="True", partition="P1", user=ROOT_USER):
  45. """
  46. Common function to set partition attribute/s to node/queue object
  47. :param mgr_cmd: qmgr "MGR_CMD_SET/MGR_CMD_UNSET/MGR_CMD_CREATE" cmd,
  48. Defaults to MGR_CMD_SET
  49. :type mgr_cmd: int
  50. :param obj_name: PBS object vnode/queue. Defaults to queue
  51. :type obj_name: str
  52. :param q_type: "queue_type" attribute of queue object ,
  53. Defaults to "execution"
  54. :type q_type: str
  55. :param name: name of the queue/vnode , Defaults to Q1 for Queue object,
  56. and server shortname for Node object
  57. :type name: str
  58. :param enable: "enabled" attribute of queue object, Defaults to "True"
  59. :type enable: boolean
  60. :param start: "started" attribute of queue object, Defaults to "True"
  61. :type start: boolean
  62. :param partition: "partition" attribute of vnode/queue object,
  63. Defaults to "P1"
  64. :type partition: str
  65. :param user: one of the pre-defined set of users
  66. :type user: :py:class:`~ptl.lib.pbs_testlib.PbsUser`
  67. """
  68. if obj_name is "QUEUE":
  69. if mgr_cmd == MGR_CMD_CREATE:
  70. if q_type is None:
  71. attr = {'partition': partition}
  72. else:
  73. attr = {
  74. 'queue_type': q_type,
  75. 'enabled': enable,
  76. 'started': start,
  77. 'partition': partition}
  78. self.server.manager(MGR_CMD_CREATE,
  79. QUEUE, attr,
  80. id=name, expect=True, runas=user)
  81. elif mgr_cmd == MGR_CMD_SET:
  82. attr = {'partition': partition}
  83. self.server.manager(
  84. MGR_CMD_SET,
  85. QUEUE,
  86. attr,
  87. id=name,
  88. expect=True,
  89. runas=user)
  90. elif mgr_cmd == MGR_CMD_UNSET:
  91. self.server.manager(MGR_CMD_UNSET, QUEUE,
  92. "partition", id=name, expect=True,
  93. runas=user)
  94. else:
  95. msg = ("Error: partition_attr function takes only "
  96. "MGR_CMD_[CREATE/SET/UNSET] value for mgr_cmd when "
  97. "pbs object is queue")
  98. self.assertTrue(False, msg)
  99. elif obj_name is "NODE":
  100. if name is "Q1":
  101. name = self.server.shortname
  102. attr = {'partition': partition}
  103. if mgr_cmd == MGR_CMD_SET:
  104. self.server.manager(MGR_CMD_SET, NODE, attr,
  105. id=name, expect=True, runas=user)
  106. elif mgr_cmd == MGR_CMD_UNSET:
  107. self.server.manager(MGR_CMD_UNSET, NODE,
  108. "partition", id=name, expect=True,
  109. runas=user)
  110. else:
  111. msg = ("Error: partition_attr function takes only "
  112. "MGR_CMD_SET/MGR_CMD_UNSET value for mgr_cmd when "
  113. "pbs object is node")
  114. self.assertTrue(False, msg)
  115. else:
  116. msg = ("Error: partition_attr function takes only "
  117. "QUEUE/NODE objects value for obj_name")
  118. self.assertTrue(False, msg)
  119. def test_set_unset_queue_partition(self):
  120. """
  121. Test to set/unset the partition attribute of queue object
  122. """
  123. self.partition_attr(mgr_cmd=MGR_CMD_CREATE, q_type="execution")
  124. self.partition_attr(mgr_cmd=MGR_CMD_SET, partition="P2")
  125. # resetting the same partition value
  126. self.partition_attr(mgr_cmd=MGR_CMD_SET, partition="P2")
  127. self.partition_attr(mgr_cmd=MGR_CMD_UNSET)
  128. def test_set_queue_partition_user_permissions(self):
  129. """
  130. Test to check the user permissions for set/unset the partition
  131. attribute of queue
  132. """
  133. self.partition_attr(mgr_cmd=MGR_CMD_CREATE, q_type="execution")
  134. msg1 = "Unauthorized Request"
  135. msg2 = "checking the qmgr error message"
  136. try:
  137. self.partition_attr(mgr_cmd=MGR_CMD_SET, partition="P2")
  138. except PbsManagerError as e:
  139. self.assertTrue(msg1 in e.msg[0], msg2)
  140. try:
  141. self.partition_attr(mgr_cmd=MGR_CMD_UNSET)
  142. except PbsManagerError as e:
  143. # self.assertEquals(e.rc, 15007)
  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. def test_set_partition_to_routing_queue(self):
  148. """
  149. Test to check the set of partition attribute on routing queue
  150. """
  151. msg0 = "Route queues are incompatible with the "\
  152. "partition attribute enabled"
  153. msg1 = "Cannot assign a partition to route queue"
  154. msg2 = "Qmgr error message do not match"
  155. try:
  156. self.partition_attr(
  157. mgr_cmd=MGR_CMD_CREATE,
  158. q_type="route",
  159. enable="False",
  160. start="False")
  161. except PbsManagerError as e:
  162. # self.assertEquals(e.rc, 15217)
  163. # The above code has to be uncommented when the PTL framework
  164. # bug PP-881 gets fixed
  165. self.assertTrue(msg0 in e.msg[0], msg2)
  166. self.server.manager(
  167. MGR_CMD_CREATE, QUEUE, {
  168. 'queue_type': 'route'}, id='Q1')
  169. try:
  170. self.partition_attr(mgr_cmd=MGR_CMD_SET)
  171. except PbsManagerError as e:
  172. # self.assertEquals(e.rc, 15007)
  173. # The above code has to be uncommented when the PTL framework
  174. # bug PP-881 gets fixed
  175. self.assertTrue(msg1 in e.msg[0], msg2)
  176. def test_modify_queue_with_partition_to_routing(self):
  177. """
  178. Test to check the modify of execution queue to routing when
  179. partition attribute is set
  180. """
  181. self.partition_attr(mgr_cmd=MGR_CMD_CREATE, q_type="execution")
  182. msg1 = ("Route queues are incompatible "
  183. "with the partition attribute queue_type")
  184. msg2 = "checking the qmgr error message"
  185. try:
  186. self.partition_attr(mgr_cmd=MGR_CMD_SET, q_type="route")
  187. except PbsManagerError as e:
  188. # self.assertEquals(e.rc, 15218)
  189. # The above code has to be uncommented when the PTL framework
  190. # bug PP-881 gets fixed
  191. self.assertTrue(msg1 in e.msg[0], msg2)
  192. def test_set_partition_without_queue_type(self):
  193. """
  194. Test to check the set of partition attribute on queue
  195. with not queue_type set
  196. """
  197. self.partition_attr(mgr_cmd=MGR_CMD_CREATE)
  198. self.partition_attr(mgr_cmd=MGR_CMD_SET, partition="P2")
  199. self.partition_attr(mgr_cmd=MGR_CMD_SET, q_type="execution")
  200. def test_partition_node_attr(self):
  201. """
  202. Test to set/unset the partition attribute of node object
  203. """
  204. self.partition_attr(obj_name="NODE")
  205. self.partition_attr(obj_name="NODE", partition="P2")
  206. # resetting the same partition value
  207. self.partition_attr(obj_name="NODE", partition="P2")
  208. self.partition_attr(mgr_cmd=MGR_CMD_UNSET, obj_name="NODE")
  209. def test_set_partition_node_attr_user_permissions(self):
  210. """
  211. Test to check the user permissions for set/unset the partition
  212. attribute of node
  213. """
  214. self.partition_attr(obj_name="NODE")
  215. msg1 = "Unauthorized Request"
  216. msg2 = "didn't receive expected error message"
  217. try:
  218. self.partition_attr(
  219. obj_name="NODE",
  220. partition="P2",
  221. user=TEST_USER)
  222. except PbsManagerError as e:
  223. self.assertTrue(msg1 in e.msg[0], msg2)
  224. try:
  225. self.partition_attr(mgr_cmd=MGR_CMD_UNSET,
  226. obj_name="NODE", user=TEST_USER)
  227. except PbsManagerError as e:
  228. # self.assertEquals(e.rc, 15007)
  229. # The above code has to be uncommented when the PTL framework
  230. # bug PP-881 gets fixed
  231. self.assertTrue(msg1 in e.msg[0], msg2)
  232. def test_partition_association_with_node_and_queue(self):
  233. """
  234. Test to check the set of partition attribute and association
  235. between queue and node
  236. """
  237. self.partition_attr(mgr_cmd=MGR_CMD_CREATE, q_type="execution")
  238. self.partition_attr(obj_name="NODE")
  239. self.partition_attr(
  240. mgr_cmd=MGR_CMD_CREATE,
  241. q_type="execution",
  242. name="Q2",
  243. partition="P2")
  244. self.partition_attr(mgr_cmd=MGR_CMD_UNSET, obj_name="NODE")
  245. self.server.manager(MGR_CMD_SET, NODE, {
  246. 'queue': "Q2"}, id=self.server.shortname,
  247. expect=True)
  248. self.partition_attr(obj_name="NODE", partition="P2")
  249. def test_mismatch_of_partition_on_node_and_queue(self):
  250. """
  251. Test to check the set of partition attribute is disallowed
  252. if partition ids do not match on queue and node
  253. """
  254. self.test_partition_association_with_node_and_queue()
  255. msg1 = "Invalid partition in queue"
  256. msg2 = "didn't receive expected error message"
  257. try:
  258. self.partition_attr(mgr_cmd=MGR_CMD_SET, name="Q2")
  259. except PbsManagerError as e:
  260. # self.assertEquals(e.rc, 15221)
  261. # The above code has to be uncommented when the PTL framework
  262. # bug PP-881 gets fixed
  263. self.assertTrue(msg1 in e.msg[0], msg2)
  264. msg1 = "Partition P2 is not part of queue for node"
  265. try:
  266. self.server.manager(MGR_CMD_SET,
  267. NODE, {'queue': "Q1"},
  268. id=self.server.shortname)
  269. except PbsManagerError as e:
  270. # self.assertEquals(e.rc, 15220)
  271. # The above code has to be uncommented when the PTL framework
  272. # bug PP-881 gets fixed
  273. self.assertTrue(msg1 in e.msg[0], msg2)
  274. msg1 = "Queue Q2 is not part of partition for node"
  275. try:
  276. self.partition_attr(obj_name="NODE")
  277. except PbsManagerError as e:
  278. # self.assertEquals(e.rc, 15219)
  279. # The above code has to be uncommented when the PTL framework
  280. # bug PP-881 gets fixed
  281. self.assertTrue(msg1 in e.msg[0], msg2)