1
0

test_win_pkg.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # -*- coding: utf-8 -*-
  2. # Import Python libs
  3. from __future__ import absolute_import, print_function, unicode_literals
  4. import os
  5. import textwrap
  6. # Import Salt Testing libs
  7. from tests.support.case import ModuleCase
  8. from tests.support.unit import skipIf
  9. from tests.support.helpers import destructiveTest
  10. from tests.support.runtests import RUNTIME_VARS
  11. # Import Salt libs
  12. import salt.utils.files
  13. import salt.utils.platform
  14. REPO_DIR = os.path.join(RUNTIME_VARS.FILES, 'file', 'base', 'win', 'repo-ng')
  15. CURL = os.path.join(REPO_DIR, 'curl.sls')
  16. @skipIf(not salt.utils.platform.is_windows(), 'windows test only')
  17. class WinPKGTest(ModuleCase):
  18. '''
  19. Tests for salt.modules.win_pkg. There are already
  20. some pkg execution module tests in the the test
  21. integration.modules.test_pkg but this will be for
  22. specific windows software respository tests while
  23. using the win_pkg module.
  24. '''
  25. @destructiveTest
  26. def test_adding_removing_pkg_sls(self):
  27. '''
  28. Test add and removing a new pkg sls
  29. in the windows software repository
  30. '''
  31. def _check_pkg(pkgs, check_refresh, exists=True):
  32. refresh = self.run_function('pkg.refresh_db')
  33. self.assertEqual(check_refresh, refresh['total'],
  34. msg='total returned {0}. Expected return {1}'.format(refresh['total'], check_refresh))
  35. repo_data = self.run_function('pkg.get_repo_data')
  36. repo_cache = os.path.join(RUNTIME_VARS.TMP, 'rootdir', 'cache', 'files', 'base', 'win', 'repo-ng')
  37. for pkg in pkgs:
  38. if exists:
  39. assert pkg in str(repo_data), str(repo_data)
  40. else:
  41. assert pkg not in str(repo_data), str(repo_data)
  42. for root, dirs, files in os.walk(repo_cache):
  43. if exists:
  44. assert pkg + '.sls' in files
  45. else:
  46. assert pkg + '.sls' not in files
  47. pkgs = ['putty', '7zip']
  48. # check putty and 7zip are in cache and repo query
  49. _check_pkg(pkgs, 2)
  50. # now add new sls
  51. with salt.utils.files.fopen(CURL, 'w') as fp_:
  52. fp_.write(textwrap.dedent('''
  53. curl:
  54. '7.46.0':
  55. full_name: 'cURL'
  56. {% if grains['cpuarch'] == 'AMD64' %}
  57. installer: 'salt://win/repo-ng/curl/curl-7.46.0-win64.msi'
  58. uninstaller: 'salt://win/repo-ng/curl/curl-7.46.0-win64.msi'
  59. {% else %}
  60. installer: 'salt://win/repo-ng/curl/curl-7.46.0-win32.msi'
  61. uninstaller: 'salt://win/repo-ng/curl/curl-7.46.0-win32.msi'
  62. {% endif %}
  63. install_flags: '/qn /norestart'
  64. uninstall_flags: '/qn /norestart'
  65. msiexec: True
  66. locale: en_US
  67. reboot: False
  68. '''))
  69. # now check if curl is also in cache and repo query
  70. pkgs.append('curl')
  71. for pkg in pkgs:
  72. self.assertIn(pkg + '.sls', os.listdir(REPO_DIR))
  73. _check_pkg(pkgs, 3)
  74. # remove curl sls and check its not in cache and repo query
  75. os.remove(CURL)
  76. _check_pkg(['curl'], 2, exists=False)
  77. def tearDown(self):
  78. if os.path.isfile(CURL):
  79. os.remove(CURL)