pbs_qmgr.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 os
  37. from tests.functional import *
  38. from ptl.lib.pbs_ifl_mock import *
  39. class TestQmgr(TestFunctional):
  40. """
  41. Test suite for PBSPro's qmgr command
  42. """
  43. def __check_whitespace_prefix(self, line):
  44. """
  45. Check whether the whitespace prefix for the line specified is correct
  46. :param line: the line to check
  47. :type line: String
  48. """
  49. if line is None:
  50. return
  51. if line[0] == " ":
  52. # Spaces are the prefix for new attribute lines
  53. # Make sure that this is a new attribute line
  54. self.assertTrue("=" in line)
  55. elif line[0] == "\t":
  56. # Tabs are prefix for line extensions
  57. # Make sure that this is a line extension
  58. self.assertTrue("=" not in line)
  59. def test_listcmd_whitespaces(self):
  60. """
  61. Check that the prefix for new attributes listed out by qmgr list
  62. are spaces and that for line extensions is a tab
  63. """
  64. fn = self.du.create_temp_file()
  65. node_prefix = "vn"
  66. nodename = node_prefix + "[0]"
  67. vndef_file = None
  68. qmgr_path = os.path.join(self.server.pbs_conf["PBS_EXEC"], "bin",
  69. "qmgr")
  70. if not os.path.isfile(qmgr_path):
  71. self.server.skipTest("qmgr binary not found!")
  72. try:
  73. # Check 1: New attributes are prefixed with spaces and not tabs
  74. # Execute qmgr -c 'list sched' and store output in a temp file
  75. if self.du.is_localhost(self.server.hostname) is True:
  76. qmgr_cmd = [qmgr_path, "-c", "list sched"]
  77. else:
  78. qmgr_cmd = [qmgr_path, "-c", "\'list sched\'"]
  79. with open(fn, "w+") as tempfd:
  80. ret = self.du.run_cmd(self.server.hostname, qmgr_cmd,
  81. stdout=tempfd)
  82. self.assertTrue(ret['rc'] == 0)
  83. for line in tempfd:
  84. self.__check_whitespace_prefix(line)
  85. # Check 2: line extensions are prefixed with tabs and not spaces
  86. # Create a random long, comma separated string
  87. blah = "blah"
  88. long_string = ""
  89. for i in range(49):
  90. long_string += blah + ","
  91. long_string += blah
  92. # Create a new vnode
  93. attrs = {ATTR_rescavail + ".ncpus": 2}
  94. self.server.create_vnodes(node_prefix, attrs, 1, self.mom)
  95. # Set 'comment' attribute to the long string we created above
  96. attrs = {ATTR_comment: long_string}
  97. self.server.manager(MGR_CMD_SET, VNODE, attrs, nodename)
  98. # Execute "qmgr 'list node vn[0]'"
  99. # The comment attribute should generate a line extension
  100. if self.du.is_localhost(self.server.hostname) is True:
  101. qmgr_cmd = [qmgr_path, "-c", "list node " + nodename]
  102. else:
  103. qmgr_cmd = [qmgr_path, "-c", "\'list node " + nodename + "\'"]
  104. with open(fn, "w+") as tempfd:
  105. ret = self.du.run_cmd(self.server.hostname, qmgr_cmd,
  106. stdout=tempfd)
  107. self.assertTrue(ret['rc'] == 0)
  108. for line in tempfd:
  109. self.__check_whitespace_prefix(line)
  110. finally:
  111. # Cleanup
  112. # Remove the temporary file
  113. os.remove(fn)
  114. # Delete the vnode created
  115. if vndef_file is not None:
  116. self.mom.delete_vnodes()
  117. self.server.manager(MGR_CMD_DELETE, VNODE, id=nodename)
  118. def test_multi_attributes(self):
  119. """
  120. Test to verify that if multiple attributes are set
  121. simultaneously and out of which one fail then none
  122. will be set.
  123. """
  124. a = {'queue_type': 'execution',
  125. 'enabled': 'True',
  126. 'started': 'True'}
  127. self.server.manager(MGR_CMD_CREATE, QUEUE, a, id='workq2')
  128. a = {'partition': 'foo'}
  129. self.server.manager(MGR_CMD_SET, QUEUE, a, id='workq')
  130. a = {'partition': 'bar'}
  131. self.server.manager(MGR_CMD_SET, QUEUE, a, id='workq2')
  132. a = {'queue': 'workq', 'partition': 'bar'}
  133. try:
  134. self.server.manager(MGR_CMD_SET, NODE, a,
  135. id=self.mom.shortname)
  136. except PbsManagerError as e:
  137. self.assertNotEqual(e.rc, '0')
  138. # Due to PP-1073 checking for the partial message
  139. msg = " is not part of queue for node"
  140. self.logger.info("looking for error, %s" % msg)
  141. self.assertTrue(msg in e.msg[0])
  142. self.server.expect(NODE, 'queue', op=UNSET, id=self.mom.shortname)