test_zookeeper.py 3.9 KB

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