mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
commit
76d6419cfd
@ -317,10 +317,10 @@ def _get_docker_py_versioninfo():
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def _get_client(**kwargs):
|
def _get_client(timeout=NOTSET, **kwargs):
|
||||||
client_kwargs = {}
|
client_kwargs = {}
|
||||||
if 'client_timeout' in kwargs:
|
if timeout is not NOTSET:
|
||||||
client_kwargs['timeout'] = kwargs.pop('client_timeout')
|
client_kwargs['timeout'] = timeout
|
||||||
for key, val in (('base_url', 'docker.url'),
|
for key, val in (('base_url', 'docker.url'),
|
||||||
('version', 'docker.version')):
|
('version', 'docker.version')):
|
||||||
param = __salt__['config.get'](val, NOTSET)
|
param = __salt__['config.get'](val, NOTSET)
|
||||||
@ -389,9 +389,22 @@ def _docker_client(wrapped):
|
|||||||
'''
|
'''
|
||||||
Ensure that the client is present
|
Ensure that the client is present
|
||||||
'''
|
'''
|
||||||
if 'docker.client' not in __context__:
|
kwargs = salt.utils.clean_kwargs(**kwargs)
|
||||||
__context__['docker.client'] = _get_client(**kwargs)
|
timeout = kwargs.pop('client_timeout', NOTSET)
|
||||||
return wrapped(*args, **salt.utils.clean_kwargs(**kwargs))
|
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
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,6 +7,8 @@ Zookeeper Module
|
|||||||
:platform: all
|
:platform: all
|
||||||
:depends: kazoo
|
:depends: kazoo
|
||||||
|
|
||||||
|
.. versionadded:: Oxygen
|
||||||
|
|
||||||
Configuration
|
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,
|
def make_digest_acl(username, password, read=False, write=False, create=False, delete=False, admin=False,
|
||||||
allperms=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)
|
return kazoo.security.make_digest_acl(username, password, read, write, create, delete, admin, allperms)
|
||||||
|
@ -64,6 +64,30 @@ grains:
|
|||||||
keystone.password: demopass
|
keystone.password: demopass
|
||||||
keystone.tenant: demo
|
keystone.tenant: demo
|
||||||
keystone.auth_url: 'http://127.0.0.1:5000/v3/'
|
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:
|
config_test:
|
||||||
spam: eggs
|
spam: eggs
|
||||||
|
109
tests/integration/states/test_zookeeper.py
Normal file
109
tests/integration/states/test_zookeeper.py
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
# -*- 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
|
||||||
|
|
||||||
|
try:
|
||||||
|
import kazoo # pylint: disable=import-error,unused-import
|
||||||
|
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
|
||||||
|
'''
|
||||||
|
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)
|
Loading…
Reference in New Issue
Block a user