TestPuppetExecutorManually.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env python2.6
  2. '''
  3. Licensed to the Apache Software Foundation (ASF) under one
  4. or more contributor license agreements. See the NOTICE file
  5. distributed with this work for additional information
  6. regarding copyright ownership. The ASF licenses this file
  7. to you under the Apache License, Version 2.0 (the
  8. "License"); you may not use this file except in compliance
  9. with the License. You may obtain a copy of the License at
  10. http://www.apache.org/licenses/LICENSE-2.0
  11. Unless required by applicable law or agreed to in writing, software
  12. distributed under the License is distributed on an "AS IS" BASIS,
  13. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. See the License for the specific language governing permissions and
  15. limitations under the License.
  16. '''
  17. from unittest import TestCase
  18. from PuppetExecutor import PuppetExecutor
  19. from pprint import pformat
  20. import socket
  21. import os
  22. import sys
  23. import logging
  24. from AmbariConfig import AmbariConfig
  25. import tempfile
  26. FILEPATH="runme.pp"
  27. logger = logging.getLogger()
  28. class TestPuppetExecutor(TestCase):
  29. def test_run(self):
  30. """
  31. Used to run arbitrary puppet manifest. Test tries to find puppet manifest 'runme.pp' and runs it.
  32. Test does not make any assertions
  33. """
  34. if not os.path.isfile(FILEPATH):
  35. return
  36. logger.info("***** RUNNING " + FILEPATH + " *****")
  37. cwd = os.getcwd()
  38. puppetexecutor = PuppetExecutor(cwd, "/x", "/y", "/tmp", AmbariConfig().getConfig())
  39. result = {}
  40. puppetEnv = os.environ
  41. _, tmpoutfile = tempfile.mkstemp()
  42. _, tmperrfile = tempfile.mkstemp()
  43. result = puppetexecutor.runPuppetFile(FILEPATH, result, puppetEnv, tmpoutfile, tmperrfile)
  44. logger.info("*** Puppet output: " + str(result['stdout']))
  45. logger.info("*** Puppet errors: " + str(result['stderr']))
  46. logger.info("*** Puppet retcode: " + str(result['exitcode']))
  47. logger.info("****** DONE *****")