test_zookeeper.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 Salt Testing Libs
  8. from tests.support.unit import skipIf
  9. from tests.support.case import ModuleCase
  10. from tests.support.helpers import destructiveTest
  11. from tests.support.mixins import SaltReturnAssertsMixin
  12. # Import Salt Libs
  13. import salt.utils.path
  14. try:
  15. import kazoo # pylint: disable=import-error,unused-import
  16. HAS_KAZOO = True
  17. except ImportError:
  18. HAS_KAZOO = False
  19. @destructiveTest
  20. @skipIf(not salt.utils.path.which('dockerd'), 'Docker not installed')
  21. @skipIf(not HAS_KAZOO, 'kazoo python library not installed')
  22. class ZookeeperTestCase(ModuleCase, SaltReturnAssertsMixin):
  23. '''
  24. Test zookeeper states
  25. '''
  26. def setUp(self):
  27. '''
  28. '''
  29. self.run_state('docker_image.present', name='zookeeper')
  30. self.run_state('docker_container.running', name='zookeeper', image='zookeeper', port_bindings='2181:2181')
  31. def tearDown(self):
  32. self.run_state('docker_container.stopped', name='zookeeper')
  33. self.run_state('docker_container.absent', name='zookeeper')
  34. self.run_state('docker_image.absent', name='docker.io/zookeeper', force=True)
  35. def test_zookeeper_present(self):
  36. ret = self.run_state(
  37. 'zookeeper.present',
  38. name='/test/name',
  39. value='testuser',
  40. makepath=True,
  41. )
  42. self.assertSaltTrueReturn(ret)
  43. ret = self.run_state(
  44. 'zookeeper.present',
  45. name='/test/name',
  46. value='daniel',
  47. acls=[
  48. {'username': 'daniel', 'password': 'test', 'read': True, 'admin': True, 'write': True, },
  49. {'username': 'testuser', 'password': 'test', 'read': True},
  50. ],
  51. profile='prod',
  52. )
  53. self.assertSaltTrueReturn(ret)
  54. def test_zookeeper_absent(self):
  55. self.run_state(
  56. 'zookeeper.present',
  57. name='/test/name',
  58. value='testuser',
  59. makepath=True,
  60. )
  61. ret = self.run_state(
  62. 'zookeeper.absent',
  63. name='/test/name',
  64. )
  65. self.assertSaltTrueReturn(ret)
  66. self.assertTrue(bool(ret['zookeeper_|-/test/name_|-/test/name_|-absent']['changes']))
  67. ret = self.run_state(
  68. 'zookeeper.absent',
  69. name='/test/name',
  70. )
  71. self.assertFalse(bool(ret['zookeeper_|-/test/name_|-/test/name_|-absent']['changes']))
  72. def test_zookeeper_acls(self):
  73. ret = self.run_state(
  74. 'zookeeper.acls',
  75. name='/test/name',
  76. acls=[
  77. {'username': 'daniel', 'password': 'test', 'read': True, 'admin': True, 'write': True, },
  78. {'username': 'testuser', 'password': 'test', 'read': True},
  79. ]
  80. )
  81. self.assertSaltFalseReturn(ret)
  82. ret = self.run_state(
  83. 'zookeeper.present',
  84. name='/test/name',
  85. value='testuser',
  86. makepath=True,
  87. )
  88. ret = self.run_state(
  89. 'zookeeper.acls',
  90. name='/test/name',
  91. acls=[
  92. {'username': 'daniel', 'password': 'test', 'read': True, 'admin': True, 'write': True, },
  93. {'username': 'testuser', 'password': 'test', 'read': True},
  94. ]
  95. )
  96. self.assertSaltTrueReturn(ret)