1
0

test_alternatives.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 pytest
  9. # Import Salt Testing libs
  10. from tests.support.case import ModuleCase
  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. @pytest.mark.destructive_test
  20. @pytest.mark.slow_test(seconds=10) # Test takes >5 and <=10 seconds
  21. def test_install_set_and_remove(self):
  22. ret = self.run_state(
  23. "alternatives.set", name="alt-test", path=RUNTIME_VARS.SHELL_TRUE_PATH
  24. )
  25. self.assertSaltFalseReturn(ret)
  26. ret = self.run_state(
  27. "alternatives.install",
  28. name="alt-test",
  29. link="/usr/local/bin/alt-test",
  30. path=RUNTIME_VARS.SHELL_TRUE_PATH,
  31. priority=50,
  32. )
  33. self.assertSaltTrueReturn(ret)
  34. self.assertSaltStateChangesEqual(
  35. ret, RUNTIME_VARS.SHELL_TRUE_PATH, keys=["path"]
  36. )
  37. ret = self.run_state(
  38. "alternatives.install",
  39. name="alt-test",
  40. link="/usr/local/bin/alt-test",
  41. path=RUNTIME_VARS.SHELL_TRUE_PATH,
  42. priority=50,
  43. )
  44. self.assertSaltTrueReturn(ret)
  45. self.assertSaltStateChangesEqual(ret, {})
  46. ret = self.run_state(
  47. "alternatives.install",
  48. name="alt-test",
  49. link="/usr/local/bin/alt-test",
  50. path=RUNTIME_VARS.SHELL_FALSE_PATH,
  51. priority=90,
  52. )
  53. self.assertSaltTrueReturn(ret)
  54. self.assertSaltStateChangesEqual(
  55. ret, RUNTIME_VARS.SHELL_FALSE_PATH, keys=["path"]
  56. )
  57. ret = self.run_state(
  58. "alternatives.set", name="alt-test", path=RUNTIME_VARS.SHELL_FALSE_PATH
  59. )
  60. self.assertSaltTrueReturn(ret)
  61. self.assertSaltStateChangesEqual(ret, {})
  62. ret = self.run_state(
  63. "alternatives.set", name="alt-test", path=RUNTIME_VARS.SHELL_TRUE_PATH
  64. )
  65. self.assertSaltTrueReturn(ret)
  66. self.assertSaltStateChangesEqual(
  67. ret, RUNTIME_VARS.SHELL_TRUE_PATH, keys=["path"]
  68. )
  69. ret = self.run_state(
  70. "alternatives.set", name="alt-test", path=RUNTIME_VARS.SHELL_TRUE_PATH
  71. )
  72. self.assertSaltTrueReturn(ret)
  73. self.assertSaltStateChangesEqual(ret, {})
  74. ret = self.run_state(
  75. "alternatives.remove", name="alt-test", path=RUNTIME_VARS.SHELL_TRUE_PATH
  76. )
  77. self.assertSaltTrueReturn(ret)
  78. ret = self.run_state(
  79. "alternatives.remove", name="alt-test", path=RUNTIME_VARS.SHELL_FALSE_PATH
  80. )
  81. self.assertSaltTrueReturn(ret)