From 0ee3ecf464f02fc0147731ea1e773c80ed9be857 Mon Sep 17 00:00:00 2001 From: Daniel Wallace Date: Mon, 24 Apr 2017 11:44:17 -0600 Subject: [PATCH 1/5] Add tests for Zookeeper states --- tests/integration/files/conf/minion | 24 +++++ tests/integration/states/test_zookeeper.py | 102 +++++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 tests/integration/states/test_zookeeper.py diff --git a/tests/integration/files/conf/minion b/tests/integration/files/conf/minion index f1b1d3be4e..b946687366 100644 --- a/tests/integration/files/conf/minion +++ b/tests/integration/files/conf/minion @@ -64,6 +64,30 @@ grains: keystone.password: demopass keystone.tenant: demo keystone.auth_url: 'http://127.0.0.1:5000/v3/' + zookeeper: + prod: + hosts: 'localhost:2181' + default_acl: + - username: daniel + password: test + read: true + write: true + create: true + delete: true + admin: true + username: daniel + password: test + hosts: 'localhost:2181' + default_acl: + - username: daniel + password: test + read: true + write: true + create: true + delete: true + admin: true + username: daniel + password: test config_test: spam: eggs diff --git a/tests/integration/states/test_zookeeper.py b/tests/integration/states/test_zookeeper.py new file mode 100644 index 0000000000..b1ed5048f1 --- /dev/null +++ b/tests/integration/states/test_zookeeper.py @@ -0,0 +1,102 @@ +# -*- coding: utf-8 -*- +''' +Integration tests for the zookeeper states +''' + +# Import Python Libs +from __future__ import absolute_import + +# Import Salt Testing Libs +from tests.support.unit import skipIf +from tests.support.case import ModuleCase +from tests.support.helpers import destructiveTest +from tests.support.mixins import SaltReturnAssertsMixin + +# Import Salt Libs +import salt.utils + + +@destructiveTest +@skipIf(not salt.utils.which('dockerd'), 'Docker not installed') +class ZookeeperTestCase(ModuleCase, SaltReturnAssertsMixin): + ''' + Test zookeeper states + ''' + def setUp(self): + ''' + ''' + self.run_state('docker_image.present', name='zookeeper') + self.run_state('docker_container.running', name='zookeeper', image='zookeeper', port_bindings='2181:2181') + + def tearDown(self): + self.run_state('docker_container.stopped', name='zookeeper') + self.run_state('docker_container.absent', name='zookeeper') + self.run_state('docker_image.absent', name='docker.io/zookeeper', force=True) + + def test_zookeeper_present(self): + ret = self.run_state( + 'zookeeper.present', + name='/test/name', + value='testuser', + makepath=True, + ) + self.assertSaltTrueReturn(ret) + + ret = self.run_state( + 'zookeeper.present', + name='/test/name', + value='daniel', + acls=[ + {'username': 'daniel', 'password': 'test', 'read': True, 'admin': True, 'write': True, }, + {'username': 'testuser', 'password': 'test', 'read': True}, + ], + profile='prod', + ) + self.assertSaltTrueReturn(ret) + + def test_zookeeper_absent(self): + self.run_state( + 'zookeeper.present', + name='/test/name', + value='testuser', + makepath=True, + ) + ret = self.run_state( + 'zookeeper.absent', + name='/test/name', + ) + self.assertSaltTrueReturn(ret) + self.assertTrue(bool(ret['zookeeper_|-/test/name_|-/test/name_|-absent']['changes'])) + ret = self.run_state( + 'zookeeper.absent', + name='/test/name', + ) + self.assertFalse(bool(ret['zookeeper_|-/test/name_|-/test/name_|-absent']['changes'])) + + def test_zookeeper_acls(self): + ret = self.run_state( + 'zookeeper.acls', + name='/test/name', + acls=[ + {'username': 'daniel', 'password': 'test', 'read': True, 'admin': True, 'write': True, }, + {'username': 'testuser', 'password': 'test', 'read': True}, + ] + ) + self.assertSaltFalseReturn(ret) + + ret = self.run_state( + 'zookeeper.present', + name='/test/name', + value='testuser', + makepath=True, + ) + + ret = self.run_state( + 'zookeeper.acls', + name='/test/name', + acls=[ + {'username': 'daniel', 'password': 'test', 'read': True, 'admin': True, 'write': True, }, + {'username': 'testuser', 'password': 'test', 'read': True}, + ] + ) + self.assertSaltTrueReturn(ret) From d9fc14b6c6427c7609017919550ae7ffc34763db Mon Sep 17 00:00:00 2001 From: Erik Johnson Date: Mon, 24 Apr 2017 17:05:45 -0500 Subject: [PATCH 2/5] Fix docker.push/pull Resolves https://github.com/saltstack/salt/issues/40864 --- salt/modules/dockermod.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/salt/modules/dockermod.py b/salt/modules/dockermod.py index b43e8ff06a..efbfae5401 100644 --- a/salt/modules/dockermod.py +++ b/salt/modules/dockermod.py @@ -317,10 +317,10 @@ def _get_docker_py_versioninfo(): pass -def _get_client(**kwargs): +def _get_client(timeout=NOTSET, **kwargs): client_kwargs = {} - if 'client_timeout' in kwargs: - client_kwargs['timeout'] = kwargs.pop('client_timeout') + if timeout is not NOTSET: + client_kwargs['timeout'] = timeout for key, val in (('base_url', 'docker.url'), ('version', 'docker.version')): param = __salt__['config.get'](val, NOTSET) @@ -389,9 +389,22 @@ def _docker_client(wrapped): ''' Ensure that the client is present ''' - if 'docker.client' not in __context__: - __context__['docker.client'] = _get_client(**kwargs) - return wrapped(*args, **salt.utils.clean_kwargs(**kwargs)) + kwargs = salt.utils.clean_kwargs(**kwargs) + timeout = kwargs.pop('client_timeout', NOTSET) + if 'docker.client' not in __context__ \ + or not hasattr(__context__['docker.client'], 'timeout'): + __context__['docker.client'] = _get_client(timeout=timeout, **kwargs) + orig_timeout = None + if timeout is not NOTSET \ + and hasattr(__context__['docker.client'], 'timeout') \ + and __context__['docker.client'].timeout != timeout: + # Temporarily override timeout + orig_timeout = __context__['docker.client'].timeout + __context__['docker.client'].timeout = timeout + ret = wrapped(*args, **kwargs) + if orig_timeout is not None: + __context__['docker.client'].timeout = orig_timeout + return ret return wrapper From f3825d3f5ef378d4d1ac3fae88556e0defdee399 Mon Sep 17 00:00:00 2001 From: Daniel Wallace Date: Tue, 25 Apr 2017 12:20:35 -0600 Subject: [PATCH 3/5] skip tests if kazoo is not installed --- tests/integration/states/test_zookeeper.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/integration/states/test_zookeeper.py b/tests/integration/states/test_zookeeper.py index b1ed5048f1..d10189a398 100644 --- a/tests/integration/states/test_zookeeper.py +++ b/tests/integration/states/test_zookeeper.py @@ -15,9 +15,16 @@ from tests.support.mixins import SaltReturnAssertsMixin # Import Salt Libs import salt.utils +try: + import kazoo + HAS_KAZOO = True +except ImportError: + HAS_KAZOO = False + @destructiveTest @skipIf(not salt.utils.which('dockerd'), 'Docker not installed') +@skipIf(not HAS_KAZOO, 'kazoo python library not installed') class ZookeeperTestCase(ModuleCase, SaltReturnAssertsMixin): ''' Test zookeeper states From eb24f5381a53affd052aea5f085c73125d3c7845 Mon Sep 17 00:00:00 2001 From: Daniel Wallace Date: Tue, 25 Apr 2017 15:26:12 -0600 Subject: [PATCH 4/5] fix pylint --- tests/integration/states/test_zookeeper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/states/test_zookeeper.py b/tests/integration/states/test_zookeeper.py index d10189a398..262cb6fcb9 100644 --- a/tests/integration/states/test_zookeeper.py +++ b/tests/integration/states/test_zookeeper.py @@ -16,7 +16,7 @@ from tests.support.mixins import SaltReturnAssertsMixin import salt.utils try: - import kazoo + import kazoo # pylint: disable=import-error,unused-import HAS_KAZOO = True except ImportError: HAS_KAZOO = False From 2ad5025ecb0652c3c1a22fa69a6bb68c800ad70b Mon Sep 17 00:00:00 2001 From: Daniel Wallace Date: Tue, 25 Apr 2017 17:26:29 -0600 Subject: [PATCH 5/5] add doc for make_digest_acl --- salt/modules/zookeeper.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/salt/modules/zookeeper.py b/salt/modules/zookeeper.py index cc8b22fd41..a6525dabd1 100644 --- a/salt/modules/zookeeper.py +++ b/salt/modules/zookeeper.py @@ -7,6 +7,8 @@ Zookeeper Module :platform: all :depends: kazoo +.. versionadded:: Oxygen + Configuration ============= @@ -513,4 +515,39 @@ def delete(path, version=-1, recursive=False, profile=None, hosts=None, scheme=N def make_digest_acl(username, password, read=False, write=False, create=False, delete=False, admin=False, allperms=False): + ''' + Generate acl object + + .. note:: This is heavily used in the zookeeper state and probably is not useful as a cli module + + username + username of acl + + password + plain text password of acl + + read + read acl + + write + write acl + + create + create acl + + delete + delete acl + + admin + admin acl + + allperms + set all other acls to True + + CLI Example: + + .. code-block:: bash + + salt minion1 zookeeper.make_digest_acl username=daniel password=mypass allperms=True + ''' return kazoo.security.make_digest_acl(username, password, read, write, create, delete, admin, allperms)