test_winrepo.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. # -*- coding: utf-8 -*-
  2. # Import Python Libs
  3. from __future__ import absolute_import, print_function, unicode_literals
  4. import os
  5. import shutil
  6. import tempfile
  7. import salt.runners.winrepo as winrepo
  8. # Import salt libs
  9. import salt.utils.files
  10. import salt.utils.stringutils
  11. from tests.support.mixins import LoaderModuleMockMixin
  12. # Import Salt Testing Libs
  13. from tests.support.runtests import RUNTIME_VARS
  14. from tests.support.unit import TestCase
  15. # Can't use raw string with unicode_literals, since the \u in the uninstaller
  16. # will be interpreted as a unicode code point and the interpreter will raise a
  17. # SyntaxError.
  18. _WINREPO_SLS = """
  19. winscp_x86:
  20. 5.7.5:
  21. full_name: 'WinSCP 5.7.5'
  22. installer: 'http://heanet.dl.sourceforge.net/project/winscp/WinSCP/5.7.5/winscp575setup.exe'
  23. install_flags: '/SP- /verysilent /norestart'
  24. uninstaller: '%PROGRAMFILES%\\WinSCP\\unins000.exe'
  25. uninstall_flags: '/verysilent'
  26. msiexec: False
  27. locale: en_US
  28. reboot: False
  29. 5.7.4:
  30. full_name: 'WinSCP 5.7.4'
  31. installer: 'http://cznic.dl.sourceforge.net/project/winscp/WinSCP/5.7.4/winscp574setup.exe'
  32. install_flags: '/SP- /verysilent /norestart'
  33. uninstaller: '%PROGRAMFILES%\\WinSCP\\unins000.exe'
  34. uninstall_flags: '/verysilent'
  35. msiexec: False
  36. locale: en_US
  37. reboot: False
  38. """
  39. _WINREPO_GENREPO_DATA = {
  40. "name_map": {"WinSCP 5.7.4": "winscp_x86", "WinSCP 5.7.5": "winscp_x86"},
  41. "repo": {
  42. "winscp_x86": {
  43. "5.7.5": {
  44. "full_name": "WinSCP 5.7.5",
  45. "installer": "http://heanet.dl.sourceforge.net/project/winscp/WinSCP/5.7.5/winscp575setup.exe",
  46. "install_flags": "/SP- /verysilent /norestart",
  47. "uninstaller": "%PROGRAMFILES%\\WinSCP\\unins000.exe",
  48. "uninstall_flags": "/verysilent",
  49. "msiexec": False,
  50. "locale": "en_US",
  51. "reboot": False,
  52. },
  53. "5.7.4": {
  54. "full_name": "WinSCP 5.7.4",
  55. "installer": "http://cznic.dl.sourceforge.net/project/winscp/WinSCP/5.7.4/winscp574setup.exe",
  56. "install_flags": "/SP- /verysilent /norestart",
  57. "uninstaller": "%PROGRAMFILES%\\WinSCP\\unins000.exe",
  58. "uninstall_flags": "/verysilent",
  59. "msiexec": False,
  60. "locale": "en_US",
  61. "reboot": False,
  62. },
  63. }
  64. },
  65. }
  66. class WinrepoTest(TestCase, LoaderModuleMockMixin):
  67. """
  68. Test the winrepo runner
  69. """
  70. def setup_loader_modules(self):
  71. self.winrepo_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP)
  72. self.addCleanup(shutil.rmtree, self.winrepo_dir, ignore_errors=True)
  73. self.extmods_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP)
  74. self.addCleanup(shutil.rmtree, self.extmods_dir, ignore_errors=True)
  75. self.winrepo_sls_dir = os.path.join(self.winrepo_dir, "repo_sls")
  76. os.mkdir(self.winrepo_sls_dir)
  77. return {
  78. winrepo: {
  79. "__opts__": {
  80. "winrepo_cachefile": "winrepo.p",
  81. "optimization_order": [0, 1, 2],
  82. "renderer": "yaml",
  83. "renderer_blacklist": [],
  84. "renderer_whitelist": [],
  85. "file_roots": {"base": [self.winrepo_dir]},
  86. "winrepo_dir": self.winrepo_dir,
  87. "extension_modules": self.extmods_dir,
  88. }
  89. }
  90. }
  91. def test_genrepo(self):
  92. """
  93. Test winrepo.genrepo runner
  94. """
  95. sls_file = os.path.join(self.winrepo_sls_dir, "wireshark.sls")
  96. # Add a winrepo SLS file
  97. with salt.utils.files.fopen(sls_file, "w") as fp_:
  98. fp_.write(salt.utils.stringutils.to_str(_WINREPO_SLS))
  99. self.assertEqual(winrepo.genrepo(), _WINREPO_GENREPO_DATA)