1
0

test_alternatives.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # -*- coding: utf-8 -*-
  2. '''
  3. Integration tests for the alternatives state module
  4. '''
  5. # Import Python libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. import os
  8. # Import Salt Testing libs
  9. from tests.support.case import ModuleCase
  10. from tests.support.helpers import destructiveTest
  11. from tests.support.mixins import SaltReturnAssertsMixin
  12. from tests.support.runtests import RUNTIME_VARS
  13. from tests.support.unit import skipIf
  14. NO_ALTERNATIVES = False
  15. if not os.path.exists('/etc/alternatives'):
  16. NO_ALTERNATIVES = True
  17. @skipIf(NO_ALTERNATIVES, '/etc/alternatives does not exist on the system')
  18. class AlterantivesStateTest(ModuleCase, SaltReturnAssertsMixin):
  19. @destructiveTest
  20. def test_install_set_and_remove(self):
  21. ret = self.run_state('alternatives.set', name='alt-test', path=RUNTIME_VARS.SHELL_TRUE_PATH)
  22. self.assertSaltFalseReturn(ret)
  23. ret = self.run_state('alternatives.install', name='alt-test',
  24. link='/usr/local/bin/alt-test', path=RUNTIME_VARS.SHELL_TRUE_PATH, priority=50)
  25. self.assertSaltTrueReturn(ret)
  26. self.assertSaltStateChangesEqual(ret, RUNTIME_VARS.SHELL_TRUE_PATH, keys=['path'])
  27. ret = self.run_state('alternatives.install', name='alt-test',
  28. link='/usr/local/bin/alt-test', path=RUNTIME_VARS.SHELL_TRUE_PATH, priority=50)
  29. self.assertSaltTrueReturn(ret)
  30. self.assertSaltStateChangesEqual(ret, {})
  31. ret = self.run_state('alternatives.install', name='alt-test',
  32. link='/usr/local/bin/alt-test', path=RUNTIME_VARS.SHELL_FALSE_PATH, priority=90)
  33. self.assertSaltTrueReturn(ret)
  34. self.assertSaltStateChangesEqual(ret, RUNTIME_VARS.SHELL_FALSE_PATH, keys=['path'])
  35. ret = self.run_state('alternatives.set', name='alt-test', path=RUNTIME_VARS.SHELL_FALSE_PATH)
  36. self.assertSaltTrueReturn(ret)
  37. self.assertSaltStateChangesEqual(ret, {})
  38. ret = self.run_state('alternatives.set', name='alt-test', path=RUNTIME_VARS.SHELL_TRUE_PATH)
  39. self.assertSaltTrueReturn(ret)
  40. self.assertSaltStateChangesEqual(ret, RUNTIME_VARS.SHELL_TRUE_PATH, keys=['path'])
  41. ret = self.run_state('alternatives.set', name='alt-test', path=RUNTIME_VARS.SHELL_TRUE_PATH)
  42. self.assertSaltTrueReturn(ret)
  43. self.assertSaltStateChangesEqual(ret, {})
  44. ret = self.run_state('alternatives.remove', name='alt-test', path=RUNTIME_VARS.SHELL_TRUE_PATH)
  45. self.assertSaltTrueReturn(ret)
  46. ret = self.run_state('alternatives.remove', name='alt-test', path=RUNTIME_VARS.SHELL_FALSE_PATH)
  47. self.assertSaltTrueReturn(ret)