1
0

test_win_dsc.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # -*- coding: utf-8 -*-
  2. # Import Python libs
  3. from __future__ import absolute_import
  4. import os
  5. # Import Salt Libs
  6. import salt.utils.files
  7. import salt.utils.platform
  8. from tests.support.case import ModuleCase
  9. from tests.support.helpers import destructiveTest
  10. # Import Salt Testing libs
  11. from tests.support.runtests import RUNTIME_VARS
  12. from tests.support.unit import skipIf
  13. @skipIf(not salt.utils.platform.is_windows(), "Tests for only Windows")
  14. class DscModuleTest(ModuleCase):
  15. """
  16. Validate PowerShell DSC module
  17. """
  18. def setUp(self):
  19. self.ps1file = os.path.join(RUNTIME_VARS.TMP, "HelloWorld.ps1")
  20. with salt.utils.files.fopen(
  21. os.path.join(RUNTIME_VARS.FILES, "file", "base", "HelloWorld.ps1"), "rb"
  22. ) as sfp:
  23. with salt.utils.files.fopen(self.ps1file, "wb") as dfp:
  24. dfp.write(sfp.read())
  25. self.psd1file = os.path.join(RUNTIME_VARS.TMP, "HelloWorld.psd1")
  26. with salt.utils.files.fopen(
  27. os.path.join(RUNTIME_VARS.FILES, "file", "base", "HelloWorld.psd1"), "rb"
  28. ) as sfp:
  29. with salt.utils.files.fopen(self.psd1file, "wb") as dfp:
  30. dfp.write(sfp.read())
  31. super(DscModuleTest, self).setUp()
  32. def tearDown(self):
  33. if os.path.isfile(self.ps1file):
  34. os.remove(self.ps1file)
  35. if os.path.isfile(self.psd1file):
  36. os.remove(self.psd1file)
  37. super(DscModuleTest, self).tearDown()
  38. @destructiveTest
  39. def test_compile_config(self):
  40. ret = self.run_function(
  41. "dsc.compile_config",
  42. self.ps1file,
  43. config_name="HelloWorld",
  44. config_data=self.psd1file,
  45. )
  46. self.assertTrue(ret["Exists"])