mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Merge pull request #18063 from basepi/merge-forward
Merge forward from 2014.7 to develop
This commit is contained in:
commit
30ef488767
@ -94,7 +94,7 @@ capabilities. It has been designed to allow for development into features
|
||||
which out ZeroMQ topologies can't match.
|
||||
|
||||
Many of the proposed features are still under development and will be
|
||||
announced as they enter proff of concept phases, but these features include
|
||||
announced as they enter proof of concept phases, but these features include
|
||||
`salt-fuse` - a filesystem over salt, `salt-vt` - a parallel api driven shell
|
||||
over the salt transport and many others.
|
||||
|
||||
|
@ -753,7 +753,7 @@ def reformat_node(item=None, full=False):
|
||||
|
||||
# remove all the extra key value pairs to provide a brief listing
|
||||
if not full:
|
||||
for key in item:
|
||||
for key in item.keys(): # iterate over a copy of the keys
|
||||
if key not in desired_keys:
|
||||
del item[key]
|
||||
|
||||
|
@ -1895,7 +1895,7 @@ def get_id(opts, minion_id=False):
|
||||
if opts.get('minion_id_caching', True):
|
||||
try:
|
||||
with salt.utils.fopen(id_cache) as idf:
|
||||
name = idf.read().strip()
|
||||
name = idf.readline().strip()
|
||||
if name.startswith(codecs.BOM): # Remove BOM if exists
|
||||
name = name.replace(codecs.BOM, '', 1)
|
||||
if name:
|
||||
|
@ -258,7 +258,7 @@ def vgcreate(vgname, devices, **kwargs):
|
||||
return vgdata
|
||||
|
||||
|
||||
def lvcreate(lvname, vgname, size=None, extents=None, snapshot=None, pv='', **kwargs):
|
||||
def lvcreate(lvname, vgname, size=None, extents=None, snapshot=None, pv=None, **kwargs):
|
||||
'''
|
||||
Create a new logical volume, with option for which physical volume to be used
|
||||
|
||||
|
@ -374,6 +374,9 @@ def sync_all(saltenv=None, refresh=True):
|
||||
Sync down all of the dynamic modules from the file server for a specific
|
||||
environment
|
||||
|
||||
refresh : True
|
||||
Also refresh the execution modules available to the minion.
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
@ -64,7 +64,7 @@ def list_(show_all=False, return_yaml=True):
|
||||
if 'schedule' in __pillar__:
|
||||
schedule.update(__pillar__['schedule'])
|
||||
|
||||
for job in schedule:
|
||||
for job in schedule.keys(): # iterate over a copy since we will mutate it
|
||||
if job == 'enabled':
|
||||
continue
|
||||
|
||||
|
@ -193,7 +193,7 @@ class SREQ(object):
|
||||
'''
|
||||
if hasattr(self, '_socket'):
|
||||
if isinstance(self.poller.sockets, dict):
|
||||
for socket in self.poller.sockets:
|
||||
for socket in self.poller.sockets.keys():
|
||||
self.poller.unregister(socket)
|
||||
else:
|
||||
for socket in self.poller.sockets:
|
||||
@ -235,7 +235,7 @@ class SREQ(object):
|
||||
|
||||
def destroy(self):
|
||||
if isinstance(self.poller.sockets, dict):
|
||||
for socket in self.poller.sockets:
|
||||
for socket in self.poller.sockets.keys():
|
||||
if socket.closed is False:
|
||||
socket.setsockopt(zmq.LINGER, 1)
|
||||
socket.close()
|
||||
|
@ -222,7 +222,7 @@ def render(input, saltenv='base', sls='', argline='', **kws):
|
||||
tmplctx = STATE_CONF.copy()
|
||||
if tmplctx:
|
||||
prefix = sls + '::'
|
||||
for k in tmplctx:
|
||||
for k in tmplctx.keys(): # iterate over a copy of keys
|
||||
if k.startswith(prefix):
|
||||
tmplctx[k[len(prefix):]] = tmplctx[k]
|
||||
del tmplctx[k]
|
||||
|
@ -216,7 +216,7 @@ class ZeroMQChannel(Channel):
|
||||
if master_type == 'failover':
|
||||
# remove all cached sreqs to the old master to prevent
|
||||
# zeromq from reconnecting to old masters automagically
|
||||
for check_key in self.sreq_cache:
|
||||
for check_key in self.sreq_cache.keys():
|
||||
if self.opts['master_uri'] != check_key[0]:
|
||||
del self.sreq_cache[check_key]
|
||||
log.debug('Removed obsolete sreq-object from '
|
||||
|
@ -819,7 +819,7 @@ class SaltNova(OpenStackComputeShell):
|
||||
'priority', 'project_id', 'vlan_start', 'vpn_start'
|
||||
]
|
||||
|
||||
for variable in kwargs:
|
||||
for variable in kwargs.keys(): # iterate over a copy, we might delete some
|
||||
if variable not in params:
|
||||
del kwargs[variable]
|
||||
return kwargs
|
||||
|
@ -1,11 +1,8 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Import salt libs
|
||||
import salt.cli
|
||||
from salt.scripts import salt_api
|
||||
|
||||
def main():
|
||||
sapi = salt.cli.SaltAPI()
|
||||
sapi.run()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
salt_api()
|
||||
|
65
setup.py
65
setup.py
@ -712,40 +712,37 @@ class SaltDistribution(distutils.dist.Distribution):
|
||||
'scripts/salt-unity'])
|
||||
return scripts
|
||||
|
||||
# We don't actually need to set the console_scripts entry point since the
|
||||
# packaged scripts with do the same work
|
||||
#@property
|
||||
#def _property_entry_points(self):
|
||||
# return {}
|
||||
# # console scripts common to all scenarios
|
||||
# scripts = ['salt-call = salt.scripts:salt_call']
|
||||
# if self.ssh_packaging or PACKAGED_FOR_SALT_SSH:
|
||||
# scripts.append('salt-ssh = salt.scripts:salt_ssh')
|
||||
# if IS_WINDOWS_PLATFORM:
|
||||
# return {'console_scripts': scripts}
|
||||
# scripts.extend(['salt-cloud = salt.scripts:salt_cloud',
|
||||
# 'salt-run = salt.scripts:salt_run'])
|
||||
# return {'console_scripts': scripts}
|
||||
#
|
||||
# if IS_WINDOWS_PLATFORM:
|
||||
# scripts.extend(['salt-cp = salt.scripts:salt_cp'
|
||||
# 'salt-minion = salt.scripts:salt_minion',
|
||||
# 'salt-unity = salt.scripts:salt_unity'])
|
||||
# return {'console_scripts': scripts}
|
||||
#
|
||||
# # *nix, so, we need all scripts
|
||||
# scripts.extend(['salt = salt.scripts:salt_main',
|
||||
# 'salt-api = salt.scripts:salt_api',
|
||||
# 'salt-cloud = salt.scripts:salt_cloud',
|
||||
# 'salt-cp = salt.scripts:salt_cp',
|
||||
# 'salt-key = salt.scripts:salt_key',
|
||||
# 'salt-master = salt.scripts:salt_master',
|
||||
# 'salt-minion = salt.scripts:salt_minion',
|
||||
# 'salt-run = salt.scripts:salt_run',
|
||||
# 'salt-ssh = salt.scripts:salt_ssh',
|
||||
# 'salt-syndic = salt.scripts:salt_syndic',
|
||||
# 'salt-unity = salt.scripts:salt_unity'])
|
||||
# return {'console_scripts': scripts}
|
||||
@property
|
||||
def _property_entry_points(self):
|
||||
# console scripts common to all scenarios
|
||||
scripts = ['salt-call = salt.scripts:salt_call']
|
||||
if self.ssh_packaging or PACKAGED_FOR_SALT_SSH:
|
||||
scripts.append('salt-ssh = salt.scripts:salt_ssh')
|
||||
if IS_WINDOWS_PLATFORM:
|
||||
return {'console_scripts': scripts}
|
||||
scripts.extend(['salt-cloud = salt.scripts:salt_cloud',
|
||||
'salt-run = salt.scripts:salt_run'])
|
||||
return {'console_scripts': scripts}
|
||||
|
||||
if IS_WINDOWS_PLATFORM:
|
||||
scripts.extend(['salt-cp = salt.scripts:salt_cp'
|
||||
'salt-minion = salt.scripts:salt_minion',
|
||||
'salt-unity = salt.scripts:salt_unity'])
|
||||
return {'console_scripts': scripts}
|
||||
|
||||
# *nix, so, we need all scripts
|
||||
scripts.extend(['salt = salt.scripts:salt_main',
|
||||
'salt-api = salt.scripts:salt_api',
|
||||
'salt-cloud = salt.scripts:salt_cloud',
|
||||
'salt-cp = salt.scripts:salt_cp',
|
||||
'salt-key = salt.scripts:salt_key',
|
||||
'salt-master = salt.scripts:salt_master',
|
||||
'salt-minion = salt.scripts:salt_minion',
|
||||
'salt-run = salt.scripts:salt_run',
|
||||
'salt-ssh = salt.scripts:salt_ssh',
|
||||
'salt-syndic = salt.scripts:salt_syndic',
|
||||
'salt-unity = salt.scripts:salt_unity'])
|
||||
return {'console_scripts': scripts}
|
||||
# <---- Dynamic Data ---------------------------------------------------------------------------------------------
|
||||
|
||||
# ----- Esky Setup ---------------------------------------------------------------------------------------------->
|
||||
|
@ -16,9 +16,15 @@ ensure_in_syspath('../')
|
||||
# Import salt libs
|
||||
import salt.payload
|
||||
from salt.utils.odict import OrderedDict
|
||||
import salt.exceptions
|
||||
|
||||
# Import 3rd-party libs
|
||||
import msgpack
|
||||
import zmq
|
||||
|
||||
import errno
|
||||
import threading
|
||||
import time
|
||||
|
||||
|
||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||
@ -48,6 +54,106 @@ class PayloadTestCase(TestCase):
|
||||
self.assertEqual(idata, odata)
|
||||
|
||||
|
||||
class SREQTestCase(TestCase):
|
||||
port = 8845 # TODO: dynamically assign a port?
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
'''
|
||||
Class to set up zmq echo socket
|
||||
'''
|
||||
def echo_server():
|
||||
'''
|
||||
A server that echos the message sent to it over zmq
|
||||
|
||||
Optional "sleep" can be sent to delay response
|
||||
'''
|
||||
context = zmq.Context()
|
||||
socket = context.socket(zmq.REP)
|
||||
socket.bind("tcp://*:{0}".format(SREQTestCase.port))
|
||||
payload = salt.payload.Serial('msgpack')
|
||||
|
||||
while SREQTestCase.thread_running.is_set():
|
||||
try:
|
||||
# Wait for next request from client
|
||||
message = socket.recv(zmq.NOBLOCK)
|
||||
msg_deserialized = payload.loads(message)
|
||||
if isinstance(msg_deserialized['load'], dict) and msg_deserialized['load'].get('sleep'):
|
||||
time.sleep(msg_deserialized['load']['sleep'])
|
||||
socket.send(message)
|
||||
except zmq.ZMQError as exc:
|
||||
if exc.errno == errno.EAGAIN:
|
||||
continue
|
||||
raise
|
||||
SREQTestCase.thread_running = threading.Event()
|
||||
SREQTestCase.thread_running.set()
|
||||
SREQTestCase.echo_server = threading.Thread(target=echo_server)
|
||||
SREQTestCase.echo_server.start()
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
'''
|
||||
Remove echo server
|
||||
'''
|
||||
# kill the thread
|
||||
SREQTestCase.thread_running.clear()
|
||||
SREQTestCase.echo_server.join()
|
||||
|
||||
def get_sreq(self):
|
||||
return salt.payload.SREQ('tcp://127.0.0.1:{0}'.format(SREQTestCase.port))
|
||||
|
||||
def test_send_auto(self):
|
||||
'''
|
||||
Test creation, send/rect
|
||||
'''
|
||||
sreq = self.get_sreq()
|
||||
# check default of empty load and enc clear
|
||||
assert sreq.send_auto({}) == {'enc': 'clear', 'load': {}}
|
||||
|
||||
# check that the load always gets passed
|
||||
assert sreq.send_auto({'load': 'foo'}) == {'load': 'foo', 'enc': 'clear'}
|
||||
|
||||
def test_send(self):
|
||||
sreq = self.get_sreq()
|
||||
assert sreq.send('clear', 'foo') == {'enc': 'clear', 'load': 'foo'}
|
||||
|
||||
def test_timeout(self):
|
||||
'''
|
||||
Test SREQ Timeouts
|
||||
'''
|
||||
sreq = self.get_sreq()
|
||||
# client-side timeout
|
||||
start = time.time()
|
||||
with self.assertRaises(salt.exceptions.SaltReqTimeoutError):
|
||||
sreq.send('clear', 'foo', tries=0, timeout=0)
|
||||
assert time.time() - start < 1 # ensure we didn't wait
|
||||
|
||||
# server-side timeout
|
||||
start = time.time()
|
||||
with self.assertRaises(salt.exceptions.SaltReqTimeoutError):
|
||||
sreq.send('clear', {'sleep': 2}, tries=1, timeout=1)
|
||||
assert time.time() - start >= 1 # ensure we actually tried once (1s)
|
||||
|
||||
# server-side timeout with retries
|
||||
start = time.time()
|
||||
with self.assertRaises(salt.exceptions.SaltReqTimeoutError):
|
||||
sreq.send('clear', {'sleep': 2}, tries=2, timeout=1)
|
||||
assert time.time() - start >= 2 # ensure we actually tried twice (2s)
|
||||
|
||||
# test a regular send afterwards (to make sure sockets aren't in a twist
|
||||
assert sreq.send('clear', 'foo') == {'enc': 'clear', 'load': 'foo'}
|
||||
|
||||
def test_destroy(self):
|
||||
'''
|
||||
Test the __del__ capabilities
|
||||
'''
|
||||
sreq = self.get_sreq()
|
||||
# ensure no exceptions when we go to destroy the sreq, since __del__
|
||||
# swallows exceptions, we have to call destroy directly
|
||||
sreq.destroy()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from integration import run_tests
|
||||
run_tests(PayloadTestCase, needs_daemon=False)
|
||||
run_tests(SREQTestCase, needs_daemon=False)
|
||||
|
Loading…
Reference in New Issue
Block a user