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 Testing Libs
  8. from tests.support.runtests import RUNTIME_VARS
  9. from tests.support.mixins import LoaderModuleMockMixin
  10. from tests.support.unit import TestCase
  11. # Import salt libs
  12. import salt.utils.files
  13. import salt.utils.stringutils
  14. import salt.runners.winrepo as winrepo
  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': {
  41. 'WinSCP 5.7.4': 'winscp_x86',
  42. 'WinSCP 5.7.5': 'winscp_x86'
  43. },
  44. 'repo': {
  45. 'winscp_x86': {
  46. '5.7.5': {
  47. 'full_name': 'WinSCP 5.7.5',
  48. 'installer': 'http://heanet.dl.sourceforge.net/project/winscp/WinSCP/5.7.5/winscp575setup.exe',
  49. 'install_flags': '/SP- /verysilent /norestart',
  50. 'uninstaller': '%PROGRAMFILES%\\WinSCP\\unins000.exe',
  51. 'uninstall_flags': '/verysilent',
  52. 'msiexec': False,
  53. 'locale': 'en_US',
  54. 'reboot': False
  55. },
  56. '5.7.4': {
  57. 'full_name': 'WinSCP 5.7.4',
  58. 'installer': 'http://cznic.dl.sourceforge.net/project/winscp/WinSCP/5.7.4/winscp574setup.exe',
  59. 'install_flags': '/SP- /verysilent /norestart',
  60. 'uninstaller': '%PROGRAMFILES%\\WinSCP\\unins000.exe',
  61. 'uninstall_flags': '/verysilent',
  62. 'msiexec': False,
  63. 'locale': 'en_US',
  64. 'reboot': False
  65. }
  66. }
  67. }
  68. }
  69. class WinrepoTest(TestCase, LoaderModuleMockMixin):
  70. '''
  71. Test the winrepo runner
  72. '''
  73. def setup_loader_modules(self):
  74. self.winrepo_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP)
  75. self.addCleanup(shutil.rmtree, self.winrepo_dir, ignore_errors=True)
  76. self.extmods_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP)
  77. self.addCleanup(shutil.rmtree, self.extmods_dir, ignore_errors=True)
  78. self.winrepo_sls_dir = os.path.join(self.winrepo_dir, 'repo_sls')
  79. os.mkdir(self.winrepo_sls_dir)
  80. return {
  81. winrepo: {
  82. '__opts__': {
  83. 'winrepo_cachefile': 'winrepo.p',
  84. 'optimization_order': [0, 1, 2],
  85. 'renderer': 'yaml',
  86. 'renderer_blacklist': [],
  87. 'renderer_whitelist': [],
  88. 'file_roots': {'base': [self.winrepo_dir]},
  89. 'winrepo_dir': self.winrepo_dir,
  90. 'extension_modules': self.extmods_dir
  91. }
  92. }
  93. }
  94. def test_genrepo(self):
  95. '''
  96. Test winrepo.genrepo runner
  97. '''
  98. sls_file = os.path.join(self.winrepo_sls_dir, 'wireshark.sls')
  99. # Add a winrepo SLS file
  100. with salt.utils.files.fopen(sls_file, 'w') as fp_:
  101. fp_.write(salt.utils.stringutils.to_str(_WINREPO_SLS))
  102. self.assertEqual(winrepo.genrepo(), _WINREPO_GENREPO_DATA)