1
0

test_zookeeper.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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=30) # Test takes >10 and <=30 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. @pytest.mark.slow_test(seconds=120) # Test takes >60 and <=120 seconds
  64. def test_zookeeper_absent(self):
  65. self.run_state(
  66. "zookeeper.present", name="/test/name", value="testuser", makepath=True,
  67. )
  68. ret = self.run_state("zookeeper.absent", name="/test/name",)
  69. self.assertSaltTrueReturn(ret)
  70. self.assertTrue(
  71. bool(ret["zookeeper_|-/test/name_|-/test/name_|-absent"]["changes"])
  72. )
  73. ret = self.run_state("zookeeper.absent", name="/test/name",)
  74. self.assertFalse(
  75. bool(ret["zookeeper_|-/test/name_|-/test/name_|-absent"]["changes"])
  76. )
  77. @pytest.mark.slow_test(seconds=30) # Test takes >10 and <=30 seconds
  78. def test_zookeeper_acls(self):
  79. ret = self.run_state(
  80. "zookeeper.acls",
  81. name="/test/name",
  82. acls=[
  83. {
  84. "username": "daniel",
  85. "password": "test",
  86. "read": True,
  87. "admin": True,
  88. "write": True,
  89. },
  90. {"username": "testuser", "password": "test", "read": True},
  91. ],
  92. )
  93. self.assertSaltFalseReturn(ret)
  94. ret = self.run_state(
  95. "zookeeper.present", name="/test/name", value="testuser", makepath=True,
  96. )
  97. ret = self.run_state(
  98. "zookeeper.acls",
  99. name="/test/name",
  100. acls=[
  101. {
  102. "username": "daniel",
  103. "password": "test",
  104. "read": True,
  105. "admin": True,
  106. "write": True,
  107. },
  108. {"username": "testuser", "password": "test", "read": True},
  109. ],
  110. )
  111. self.assertSaltTrueReturn(ret)