pbs_sched_interface_test.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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 TestSchedulerInterface(TestInterfaces):
  38. """
  39. Test suite to test different scheduler interfaces
  40. """
  41. def setUp(self):
  42. TestInterfaces.setUp(self)
  43. a = {'partition': 'P1',
  44. 'sched_host': self.server.hostname,
  45. 'sched_port': '15051'}
  46. self.server.manager(MGR_CMD_CREATE,
  47. SCHED, a,
  48. id="TestCommonSched")
  49. self.scheds['TestCommonSched'].create_scheduler()
  50. self.scheds['TestCommonSched'].start()
  51. def test_duplicate_scheduler_name(self):
  52. """
  53. Check for the scheduler object name.
  54. """
  55. try:
  56. self.server.manager(MGR_CMD_CREATE,
  57. SCHED,
  58. {'sched_port': '15052'},
  59. id="TestCommonSched")
  60. except PbsManagerError as e:
  61. if self.server.get_op_mode() == PTL_CLI:
  62. self.assertTrue(
  63. 'qmgr: Error (15211) returned from server' in e.msg[1])
  64. def test_invalid_sched_port(self):
  65. """
  66. Test setting invalid port.
  67. """
  68. try:
  69. self.server.manager(MGR_CMD_SET, SCHED,
  70. {'sched_port': 'asdf'},
  71. id="TestCommonSched",
  72. runas=ROOT_USER)
  73. except PbsManagerError as e:
  74. err_msg = "Illegal attribute or resource value"
  75. self.assertTrue(err_msg in e.msg[0],
  76. "Error message is not expected")
  77. a = {'sched_port': 15051}
  78. self.server.expect(SCHED, a, id='TestCommonSched', max_attempts=10)
  79. def test_permission_on_scheduler(self):
  80. """
  81. Check for the permission to create/delete/modify scheduler object.
  82. """
  83. # Check for create permission
  84. try:
  85. self.server.manager(MGR_CMD_CREATE,
  86. SCHED,
  87. {'sched_port': '15052'},
  88. id="testCreateSched",
  89. runas=OPER_USER)
  90. except PbsManagerError as e:
  91. if self.server.get_op_mode() == PTL_CLI:
  92. self.assertTrue(
  93. 'qmgr: Error (15007) returned from server' in e.msg[1])
  94. self.server.manager(MGR_CMD_CREATE,
  95. SCHED,
  96. {'sched_port': '15052'},
  97. id="testCreateSched",
  98. runas=ROOT_USER)
  99. # Check for delete permission
  100. self.server.manager(MGR_CMD_CREATE,
  101. SCHED,
  102. {'sched_port': '15052'},
  103. id="testDeleteSched")
  104. try:
  105. self.server.manager(MGR_CMD_DELETE,
  106. SCHED,
  107. id="testDeleteSched",
  108. runas=OPER_USER)
  109. except PbsManagerError as e:
  110. if self.server.get_op_mode() == PTL_CLI:
  111. self.assertTrue(
  112. 'qmgr: Error (15007) returned from server' in e.msg[1])
  113. self.server.manager(MGR_CMD_DELETE,
  114. SCHED,
  115. id="testDeleteSched",
  116. runas=ROOT_USER)
  117. # Check for attribute set permission
  118. try:
  119. self.server.manager(MGR_CMD_SET,
  120. SCHED,
  121. {'sched_cycle_length': 12000},
  122. id="TestCommonSched",
  123. runas=OPER_USER)
  124. except PbsManagerError as e:
  125. if self.server.get_op_mode() == PTL_CLI:
  126. self.assertTrue(
  127. 'qmgr: Error (15007) returned from server' in e.msg[1])
  128. self.server.manager(MGR_CMD_SET,
  129. SCHED,
  130. {'sched_cycle_length': 12000},
  131. id="TestCommonSched",
  132. runas=ROOT_USER,
  133. expect=True)
  134. def test_delete_default_sched(self):
  135. """
  136. Delete default scheduler.
  137. """
  138. try:
  139. self.server.manager(MGR_CMD_DELETE,
  140. SCHED,
  141. id="default")
  142. except PbsManagerError as e:
  143. if self.server.get_op_mode() == PTL_CLI:
  144. self.assertTrue(
  145. 'qmgr: Error (15214) returned from server' in e.msg[1])
  146. def test_set_and_unset_sched_attributes(self):
  147. """
  148. Set and unset an attribute of a scheduler object .
  149. """
  150. # Set an attribute of a scheduler object.
  151. self.server.manager(MGR_CMD_SET,
  152. SCHED,
  153. {'sched_cycle_length': 1234},
  154. id="TestCommonSched",
  155. expect=True)
  156. # Unset an attribute of a scheduler object.
  157. self.server.manager(MGR_CMD_UNSET,
  158. SCHED,
  159. 'sched_cycle_length',
  160. id="TestCommonSched")
  161. a = {'sched_cycle_length': '00:20:00'}
  162. self.server.expect(SCHED, a, id='TestCommonSched', max_attempts=10)
  163. def test_sched_default_attrs(self):
  164. """
  165. Test all sched attributes are set by default on default scheduler
  166. """
  167. sched_priv = os.path.join(
  168. self.server.pbs_conf['PBS_HOME'], 'sched_priv')
  169. sched_logs = os.path.join(
  170. self.server.pbs_conf['PBS_HOME'], 'sched_logs')
  171. a = {'sched_port': 15004,
  172. 'sched_host': self.server.hostname,
  173. 'sched_priv': sched_priv,
  174. 'sched_log': sched_logs,
  175. 'scheduling': 'True',
  176. 'scheduler_iteration': 600,
  177. 'state': 'idle',
  178. 'sched_cycle_length': '00:20:00'}
  179. self.server.expect(SCHED, a, id='default',
  180. attrop=PTL_AND, max_attempts=10)
  181. def test_scheduling_attribute(self):
  182. """
  183. Test scheduling attribute on newly created scheduler is false
  184. unless made true
  185. """
  186. self.server.expect(SCHED, {'scheduling': 'False'},
  187. id='TestCommonSched', max_attempts=10)
  188. self.server.manager(MGR_CMD_SET, SCHED,
  189. {'scheduling': 'True'},
  190. runas=ROOT_USER, id='TestCommonSched')
  191. self.server.expect(SCHED, {'scheduling': 'True'},
  192. id='TestCommonSched', max_attempts=10)
  193. def test_set_sched_priv_log_duplicate_value(self):
  194. """
  195. Test setting of sched_priv and sched_log to a
  196. value assigned to another scheduler
  197. """
  198. err_msg = "Another scheduler also has same "
  199. err_msg += "value for its sched_priv directory"
  200. try:
  201. self.server.manager(MGR_CMD_SET, SCHED,
  202. {'sched_priv': '/var/spool/pbs/sched_priv'},
  203. runas=ROOT_USER, id='TestCommonSched')
  204. except PbsManagerError as e:
  205. self.assertTrue(err_msg in e.msg[0],
  206. "Error message is not expected")
  207. err_msg = "Another scheduler also has same "
  208. err_msg += "value for its sched_log directory"
  209. try:
  210. self.server.manager(MGR_CMD_SET, SCHED,
  211. {'sched_log': '/var/spool/pbs/sched_logs'},
  212. runas=ROOT_USER, id='TestCommonSched')
  213. except PbsManagerError as e:
  214. self.assertTrue(err_msg in e.msg[0],
  215. "Error message is not expected")
  216. def test_set_default_sched_not_permitted(self):
  217. """
  218. Test setting partition on default scheduler
  219. """
  220. err_msg = "Operation is not permitted on default scheduler"
  221. try:
  222. self.server.manager(MGR_CMD_SET, SCHED,
  223. {'partition': 'P1'},
  224. runas=ROOT_USER)
  225. except PbsManagerError as e:
  226. self.assertTrue(err_msg in e.msg[0],
  227. "Error message is not expected")
  228. try:
  229. self.server.manager(MGR_CMD_SET, SCHED,
  230. {'sched_priv': '/var/spool/somedir'},
  231. runas=ROOT_USER)
  232. except PbsManagerError as e:
  233. self.assertTrue(err_msg in e.msg[0],
  234. "Error message is not expected")
  235. try:
  236. self.server.manager(MGR_CMD_SET, SCHED,
  237. {'sched_log': '/var/spool/somedir'},
  238. runas=ROOT_USER)
  239. except PbsManagerError as e:
  240. self.assertTrue(err_msg in e.msg[0],
  241. "Error message is not expected")
  242. def test_sched_name_too_long(self):
  243. """
  244. Test creating a scheduler with name longer than 15 chars
  245. """
  246. try:
  247. self.server.manager(MGR_CMD_CREATE, SCHED,
  248. runas=ROOT_USER, id="TestLongScheduler")
  249. except PbsManagerError as e:
  250. self.assertTrue("Scheduler name is too long" in e.msg[0],
  251. "Error message is not expected")
  252. def test_set_default_sched_attrs(self):
  253. """
  254. Test setting scheduling and scheduler_iteration on default scheduler
  255. and it updates server attributes and vice versa
  256. """
  257. self.server.manager(MGR_CMD_SET, SCHED,
  258. {'scheduling': 'False'},
  259. runas=ROOT_USER)
  260. self.server.expect(SERVER, {'scheduling': 'False'})
  261. self.server.manager(MGR_CMD_SET, SERVER,
  262. {'scheduling': 'True'},
  263. runas=ROOT_USER)
  264. self.server.expect(SCHED, {'scheduling': 'True'},
  265. id='default', max_attempts=10)
  266. self.server.manager(MGR_CMD_SET, SCHED,
  267. {'scheduler_iteration': 300},
  268. runas=ROOT_USER)
  269. self.server.expect(SERVER, {'scheduler_iteration': 300})
  270. self.server.manager(MGR_CMD_SET, SERVER,
  271. {'scheduler_iteration': 500},
  272. runas=ROOT_USER)
  273. self.server.expect(SCHED, {'scheduler_iteration': 500},
  274. id='default', max_attempts=10)