1
0

test_winrepo.py 3.9 KB

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