mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge remote-tracking branch 'upstream/2014.7' into merge-forward-2015.5
This commit is contained in:
commit
eafa20cdfb
3 changed files with 87 additions and 42 deletions
|
@ -995,6 +995,7 @@ class RemoteClient(Client):
|
|||
)
|
||||
)
|
||||
d_tries = 0
|
||||
transport_tries = 0
|
||||
path = self._check_proto(path)
|
||||
load = {'path': path,
|
||||
'saltenv': saltenv,
|
||||
|
@ -1012,45 +1013,54 @@ class RemoteClient(Client):
|
|||
else:
|
||||
return False
|
||||
fn_ = salt.utils.fopen(dest, 'wb+')
|
||||
|
||||
while True:
|
||||
if not fn_:
|
||||
load['loc'] = 0
|
||||
else:
|
||||
load['loc'] = fn_.tell()
|
||||
data = self.channel.send(load)
|
||||
if 'data' not in data:
|
||||
log.error('Data is {0}'.format(data))
|
||||
self._refresh_channel()
|
||||
if not data['data']:
|
||||
if not fn_ and data['dest']:
|
||||
# This is a 0 byte file on the master
|
||||
try:
|
||||
if not data['data']:
|
||||
if not fn_ and data['dest']:
|
||||
# This is a 0 byte file on the master
|
||||
with self._cache_loc(data['dest'], saltenv) as cache_dest:
|
||||
dest = cache_dest
|
||||
with salt.utils.fopen(cache_dest, 'wb+') as ofile:
|
||||
ofile.write(data['data'])
|
||||
if 'hsum' in data and d_tries < 3:
|
||||
# Master has prompted a file verification, if the
|
||||
# verification fails, re-download the file. Try 3 times
|
||||
d_tries += 1
|
||||
hsum = salt.utils.get_hash(dest, data.get('hash_type', 'md5'))
|
||||
if hsum != data['hsum']:
|
||||
log.warn('Bad download of file {0}, attempt {1} '
|
||||
'of 3'.format(path, d_tries))
|
||||
continue
|
||||
break
|
||||
if not fn_:
|
||||
with self._cache_loc(data['dest'], saltenv) as cache_dest:
|
||||
dest = cache_dest
|
||||
with salt.utils.fopen(cache_dest, 'wb+') as ofile:
|
||||
ofile.write(data['data'])
|
||||
if 'hsum' in data and d_tries < 3:
|
||||
# Master has prompted a file verification, if the
|
||||
# verification fails, re-download the file. Try 3 times
|
||||
d_tries += 1
|
||||
hsum = salt.utils.get_hash(dest, data.get('hash_type', 'md5'))
|
||||
if hsum != data['hsum']:
|
||||
log.warn('Bad download of file {0}, attempt {1} '
|
||||
'of 3'.format(path, d_tries))
|
||||
continue
|
||||
break
|
||||
if not fn_:
|
||||
with self._cache_loc(data['dest'], saltenv) as cache_dest:
|
||||
dest = cache_dest
|
||||
# If a directory was formerly cached at this path, then
|
||||
# remove it to avoid a traceback trying to write the file
|
||||
if os.path.isdir(dest):
|
||||
salt.utils.rm_rf(dest)
|
||||
fn_ = salt.utils.fopen(dest, 'wb+')
|
||||
if data.get('gzip', None):
|
||||
data = salt.utils.gzip_util.uncompress(data['data'])
|
||||
else:
|
||||
data = data['data']
|
||||
fn_.write(data)
|
||||
# If a directory was formerly cached at this path, then
|
||||
# remove it to avoid a traceback trying to write the file
|
||||
if os.path.isdir(dest):
|
||||
salt.utils.rm_rf(dest)
|
||||
fn_ = salt.utils.fopen(dest, 'wb+')
|
||||
if data.get('gzip', None):
|
||||
data = salt.utils.gzip_util.uncompress(data['data'])
|
||||
else:
|
||||
data = data['data']
|
||||
fn_.write(data)
|
||||
except (TypeError, KeyError) as e:
|
||||
transport_tries += 1
|
||||
log.error('Data transport is broken, got: {0}, type: {1}, '
|
||||
'exception: {2}, attempt {3} of 3'.format(
|
||||
data, type(data), e, transport_tries)
|
||||
)
|
||||
self._refresh_channel()
|
||||
if transport_tries > 3:
|
||||
break
|
||||
|
||||
if fn_:
|
||||
fn_.close()
|
||||
log.info(
|
||||
|
|
|
@ -46,16 +46,35 @@ def _normalize_dir(string):
|
|||
|
||||
def rehash():
|
||||
'''
|
||||
Send a WM_SETTINGCHANGE Broadcast to Windows to rehash the Environment variables
|
||||
Send a WM_SETTINGCHANGE Broadcast to Windows to refresh the Environment variables
|
||||
|
||||
CLI Example:
|
||||
|
||||
... code-block:: bash
|
||||
|
||||
salt '*' win_path.rehash
|
||||
'''
|
||||
return win32gui.SendMessageTimeout(win32con.HWND_BROADCAST, win32con.WM_SETTINGCHANGE, 0, 'Environment', 0, 10000)[0] == 1
|
||||
return win32gui.SendMessageTimeout(win32con.HWND_BROADCAST,
|
||||
win32con.WM_SETTINGCHANGE,
|
||||
0,
|
||||
'Environment',
|
||||
0,
|
||||
10000)[0] == 1
|
||||
|
||||
|
||||
def get_path():
|
||||
'''
|
||||
Returns the system path
|
||||
Returns a list of items in the SYSTEM path
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' win_path.get_path
|
||||
'''
|
||||
ret = __salt__['reg.read_key']('HKEY_LOCAL_MACHINE', 'SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment', 'PATH').split(';')
|
||||
ret = __salt__['reg.read_key']('HKEY_LOCAL_MACHINE',
|
||||
'SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment',
|
||||
'PATH').split(';')
|
||||
|
||||
# Trim ending backslash
|
||||
return list(map(_normalize_dir, ret))
|
||||
|
@ -66,6 +85,9 @@ def exists(path):
|
|||
Check if the directory is configured in the SYSTEM path
|
||||
Case-insensitive and ignores trailing backslash
|
||||
|
||||
Returns:
|
||||
boolean True if path exists, False if not
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
@ -84,6 +106,9 @@ def add(path, index=0):
|
|||
'''
|
||||
Add the directory to the SYSTEM path in the index location
|
||||
|
||||
Returns:
|
||||
boolean True if successful, False if unsuccessful
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
@ -123,7 +148,7 @@ def add(path, index=0):
|
|||
'PATH',
|
||||
';'.join(sysPath),
|
||||
'REG_EXPAND_SZ'
|
||||
)
|
||||
)
|
||||
|
||||
# Broadcast WM_SETTINGCHANGE to Windows
|
||||
if regedit:
|
||||
|
@ -133,11 +158,22 @@ def add(path, index=0):
|
|||
|
||||
|
||||
def remove(path):
|
||||
'''
|
||||
r'''
|
||||
Remove the directory from the SYSTEM path
|
||||
|
||||
Returns:
|
||||
boolean True if successful, False if unsuccessful
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
# Will remove C:\Python27 from the path
|
||||
salt '*' win_path.remove 'c:\\python27'
|
||||
'''
|
||||
path = _normalize_dir(path)
|
||||
sysPath = get_path()
|
||||
|
||||
try:
|
||||
sysPath.remove(path)
|
||||
except ValueError:
|
||||
|
|
|
@ -302,12 +302,11 @@ class SaltEvent(object):
|
|||
start = time.time()
|
||||
timeout_at = start + wait
|
||||
while not wait or time.time() <= timeout_at:
|
||||
# convert to milliseconds
|
||||
socks = dict(self.poller.poll(wait * 1000))
|
||||
if socks.get(self.sub) != zmq.POLLIN:
|
||||
continue
|
||||
|
||||
try:
|
||||
# convert to milliseconds
|
||||
socks = dict(self.poller.poll(wait * 1000))
|
||||
if socks.get(self.sub) != zmq.POLLIN:
|
||||
continue
|
||||
# Please do not use non-blocking mode here.
|
||||
# Reliability is more important than pure speed on the event bus.
|
||||
ret = self.get_event_block()
|
||||
|
|
Loading…
Add table
Reference in a new issue