pbs_expect.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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.selftest import *
  37. from StringIO import StringIO
  38. import logging
  39. class TestExpect(TestSelf):
  40. """
  41. Contains tests for the expect() function
  42. """
  43. def test_attribute_case(self):
  44. """
  45. Test that when verifying attribute list containing attribute names
  46. with different case, expect() is case insensitive
  47. """
  48. # Create a queue
  49. a = {'queue_type': 'execution'}
  50. self.server.manager(MGR_CMD_CREATE, QUEUE, a, 'expressq')
  51. # Set the Priority attribute on the queue but provide 'p' lowercase
  52. # Set other attributes normally
  53. a = {'enabled': 'True', 'started': 'True', 'priority': 150}
  54. self.server.manager(MGR_CMD_SET, QUEUE, a, 'expressq', expect=True)
  55. def test_unsupported_operator(self):
  56. """
  57. Test that expect can handle unsupported operators correctly
  58. """
  59. # Add a new log handler which writes into a StringIO buffer
  60. logbuffer = StringIO()
  61. ptllogger = logging.getLogger('ptl')
  62. temploghandler = logging.StreamHandler(logbuffer)
  63. tempfmt = logging.Formatter("%(message)s")
  64. temploghandler.setFormatter(tempfmt)
  65. ptllogger.addHandler(temploghandler)
  66. ptllogger.propagate = True
  67. # Call manager on an unsupported operator (INCR)
  68. # As expect is done automatically for set operations,
  69. # we should see a log message for unsupported operator
  70. manager = str(MGR_USER) + '@*'
  71. rc = self.server.manager(MGR_CMD_SET, SERVER,
  72. {'managers': (INCR, manager)}, sudo=True)
  73. self.assertEqual(rc, 0)
  74. ptllogger.removeHandler(temploghandler)
  75. # Verify that expect logged the expected log message
  76. logmsg = "Operator not supported by expect(), " +\
  77. "cannot verify change in managers"
  78. msgfound = False
  79. for line in logbuffer.getvalue().splitlines():
  80. if line == logmsg:
  81. msgfound = True
  82. break
  83. self.assertTrue(msgfound,
  84. "Didn't find expected log message from expect()")