1
0

test_zookeeper.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 Testing Libs
  9. from tests.support.unit import skipIf
  10. from tests.support.case import ModuleCase
  11. from tests.support.mixins import SaltReturnAssertsMixin
  12. # Import Salt Libs
  13. import salt.utils.path
  14. import pytest
  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. @pytest.mark.destructive_test
  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('docker_container.running', name=self.container_name, image='zookeeper', port_bindings='2181:2181')
  34. def tearDown(self):
  35. self.run_state('docker_container.stopped', name=self.container_name)
  36. self.run_state('docker_container.absent', name=self.container_name)
  37. self.run_state('docker_image.absent', name='docker.io/zookeeper', force=True)
  38. def test_zookeeper_present(self):
  39. ret = self.run_state(
  40. 'zookeeper.present',
  41. name='/test/name',
  42. value='testuser',
  43. 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. {'username': 'daniel', 'password': 'test', 'read': True, 'admin': True, 'write': True, },
  52. {'username': 'testuser', 'password': 'test', 'read': True},
  53. ],
  54. profile='prod',
  55. )
  56. self.assertSaltTrueReturn(ret)
  57. def test_zookeeper_absent(self):
  58. self.run_state(
  59. 'zookeeper.present',
  60. name='/test/name',
  61. value='testuser',
  62. makepath=True,
  63. )
  64. ret = self.run_state(
  65. 'zookeeper.absent',
  66. name='/test/name',
  67. )
  68. self.assertSaltTrueReturn(ret)
  69. self.assertTrue(bool(ret['zookeeper_|-/test/name_|-/test/name_|-absent']['changes']))
  70. ret = self.run_state(
  71. 'zookeeper.absent',
  72. name='/test/name',
  73. )
  74. self.assertFalse(bool(ret['zookeeper_|-/test/name_|-/test/name_|-absent']['changes']))
  75. def test_zookeeper_acls(self):
  76. ret = self.run_state(
  77. 'zookeeper.acls',
  78. name='/test/name',
  79. acls=[
  80. {'username': 'daniel', 'password': 'test', 'read': True, 'admin': True, 'write': True, },
  81. {'username': 'testuser', 'password': 'test', 'read': True},
  82. ]
  83. )
  84. self.assertSaltFalseReturn(ret)
  85. ret = self.run_state(
  86. 'zookeeper.present',
  87. name='/test/name',
  88. value='testuser',
  89. makepath=True,
  90. )
  91. ret = self.run_state(
  92. 'zookeeper.acls',
  93. name='/test/name',
  94. acls=[
  95. {'username': 'daniel', 'password': 'test', 'read': True, 'admin': True, 'write': True, },
  96. {'username': 'testuser', 'password': 'test', 'read': True},
  97. ]
  98. )
  99. self.assertSaltTrueReturn(ret)