test_zookeeper.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. # -*- coding: utf-8 -*-
  2. """
  3. Integration tests for the zookeeper states
  4. """
  5. # Import Python Libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. import logging
  8. # Import Salt Libs
  9. import salt.utils.path
  10. from tests.support.case import ModuleCase
  11. from tests.support.helpers import destructiveTest
  12. from tests.support.mixins import SaltReturnAssertsMixin
  13. # Import Salt Testing Libs
  14. from tests.support.unit import skipIf
  15. try:
  16. import kazoo # pylint: disable=import-error,unused-import
  17. HAS_KAZOO = True
  18. except ImportError:
  19. HAS_KAZOO = False
  20. log = logging.getLogger(__name__)
  21. @destructiveTest
  22. @skipIf(not salt.utils.path.which("dockerd"), "Docker not installed")
  23. @skipIf(not HAS_KAZOO, "kazoo python library not installed")
  24. class ZookeeperTestCase(ModuleCase, SaltReturnAssertsMixin):
  25. """
  26. Test zookeeper states
  27. """
  28. @classmethod
  29. def setUpClass(cls):
  30. cls.container_name = "zookeeper_salt"
  31. def setUp(self):
  32. self.run_state("docker_image.present", name="zookeeper")
  33. self.run_state(
  34. "docker_container.running",
  35. name=self.container_name,
  36. image="zookeeper",
  37. port_bindings="2181:2181",
  38. )
  39. def tearDown(self):
  40. self.run_state("docker_container.stopped", name=self.container_name)
  41. self.run_state("docker_container.absent", name=self.container_name)
  42. self.run_state("docker_image.absent", name="docker.io/zookeeper", force=True)
  43. @skipIf(True, "SLOWTEST skip")
  44. def test_zookeeper_present(self):
  45. ret = self.run_state(
  46. "zookeeper.present", name="/test/name", value="testuser", makepath=True,
  47. )
  48. self.assertSaltTrueReturn(ret)
  49. ret = self.run_state(
  50. "zookeeper.present",
  51. name="/test/name",
  52. value="daniel",
  53. acls=[
  54. {
  55. "username": "daniel",
  56. "password": "test",
  57. "read": True,
  58. "admin": True,
  59. "write": True,
  60. },
  61. {"username": "testuser", "password": "test", "read": True},
  62. ],
  63. profile="prod",
  64. )
  65. self.assertSaltTrueReturn(ret)
  66. @skipIf(True, "SLOWTEST skip")
  67. def test_zookeeper_absent(self):
  68. self.run_state(
  69. "zookeeper.present", name="/test/name", value="testuser", makepath=True,
  70. )
  71. ret = self.run_state("zookeeper.absent", name="/test/name",)
  72. self.assertSaltTrueReturn(ret)
  73. self.assertTrue(
  74. bool(ret["zookeeper_|-/test/name_|-/test/name_|-absent"]["changes"])
  75. )
  76. ret = self.run_state("zookeeper.absent", name="/test/name",)
  77. self.assertFalse(
  78. bool(ret["zookeeper_|-/test/name_|-/test/name_|-absent"]["changes"])
  79. )
  80. @skipIf(True, "SLOWTEST skip")
  81. def test_zookeeper_acls(self):
  82. ret = self.run_state(
  83. "zookeeper.acls",
  84. name="/test/name",
  85. acls=[
  86. {
  87. "username": "daniel",
  88. "password": "test",
  89. "read": True,
  90. "admin": True,
  91. "write": True,
  92. },
  93. {"username": "testuser", "password": "test", "read": True},
  94. ],
  95. )
  96. self.assertSaltFalseReturn(ret)
  97. ret = self.run_state(
  98. "zookeeper.present", name="/test/name", value="testuser", makepath=True,
  99. )
  100. ret = self.run_state(
  101. "zookeeper.acls",
  102. name="/test/name",
  103. acls=[
  104. {
  105. "username": "daniel",
  106. "password": "test",
  107. "read": True,
  108. "admin": True,
  109. "write": True,
  110. },
  111. {"username": "testuser", "password": "test", "read": True},
  112. ],
  113. )
  114. self.assertSaltTrueReturn(ret)