mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Merge branch 'develop' into develop
This commit is contained in:
commit
46d4c8b985
@ -475,6 +475,19 @@ class Client(object):
|
||||
url_path = os.path.join(
|
||||
url_data.netloc, url_data.path).rstrip(os.sep)
|
||||
|
||||
# If dest is a directory, rewrite dest with filename
|
||||
if dest is not None \
|
||||
and (os.path.isdir(dest) or dest.endswith(('/', '\\'))):
|
||||
if url_data.query or len(url_data.path) > 1 and not url_data.path.endswith('/'):
|
||||
strpath = url.split('/')[-1]
|
||||
else:
|
||||
strpath = 'index.html'
|
||||
|
||||
if salt.utils.is_windows():
|
||||
strpath = salt.utils.sanitize_win_path_string(strpath)
|
||||
|
||||
dest = os.path.join(dest, strpath)
|
||||
|
||||
if url_scheme and url_scheme.lower() in string.ascii_lowercase:
|
||||
url_path = ':'.join((url_scheme, url_path))
|
||||
url_scheme = 'file'
|
||||
@ -1059,6 +1072,14 @@ class RemoteClient(Client):
|
||||
)
|
||||
return False
|
||||
|
||||
# If dest is a directory, rewrite dest with filename
|
||||
if dest is not None \
|
||||
and (os.path.isdir(dest) or dest.endswith(('/', '\\'))):
|
||||
dest = os.path.join(dest, os.path.basename(path))
|
||||
log.debug(
|
||||
'In saltenv \'%s\', \'%s\' is a directory. Changing dest to '
|
||||
'\'%s\'', saltenv, os.path.dirname(dest), dest)
|
||||
|
||||
# Hash compare local copy with master and skip download
|
||||
# if no difference found.
|
||||
dest2check = dest
|
||||
|
@ -770,12 +770,18 @@ def grains(opts, force_refresh=False, proxy=None):
|
||||
try:
|
||||
serial = salt.payload.Serial(opts)
|
||||
serial.dump(grains_data, fp_)
|
||||
except TypeError:
|
||||
# Can't serialize pydsl
|
||||
pass
|
||||
except (IOError, OSError):
|
||||
msg = 'Unable to write to grains cache file {0}'
|
||||
log.error(msg.format(cfn))
|
||||
except TypeError as e:
|
||||
log.error('Failed to serialize grains cache: {0}'.format(e))
|
||||
raise # re-throw for cleanup
|
||||
except Exception as e:
|
||||
msg = 'Unable to write to grains cache file {0}: {1}'
|
||||
log.error(msg.format(cfn, e))
|
||||
# Based on the original exception, the file may or may not have been
|
||||
# created. If it was, we will remove it now, as the exception means
|
||||
# the serialized data is not to be trusted, no matter what the
|
||||
# exception is.
|
||||
if os.path.isfile(cfn):
|
||||
os.unlink(cfn)
|
||||
os.umask(cumask)
|
||||
|
||||
if grains_deep_merge:
|
||||
|
@ -209,6 +209,9 @@ def get_file(path,
|
||||
gzip=None,
|
||||
**kwargs):
|
||||
'''
|
||||
.. versionchanged:: Oxygen
|
||||
``dest`` can now be a directory
|
||||
|
||||
Used to get a single file from the salt master
|
||||
|
||||
CLI Example:
|
||||
@ -320,6 +323,9 @@ def get_dir(path, dest, saltenv='base', template=None, gzip=None, **kwargs):
|
||||
|
||||
def get_url(path, dest='', saltenv='base', makedirs=False):
|
||||
'''
|
||||
.. versionchanged:: Oxygen
|
||||
``dest`` can now be a directory
|
||||
|
||||
Used to get a single file from a URL.
|
||||
|
||||
path
|
||||
|
@ -25,7 +25,8 @@ __proxyenabled__ = ['*']
|
||||
# Don't shadow built-in's.
|
||||
__func_alias__ = {
|
||||
'true_': 'true',
|
||||
'false_': 'false'
|
||||
'false_': 'false',
|
||||
'try_': 'try',
|
||||
}
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
@ -171,8 +171,8 @@ Should I use :mod:`cmd.run <salt.states.cmd.run>` or :mod:`cmd.wait <salt.states
|
||||
|
||||
.. note::
|
||||
|
||||
Use ``cmd.run`` together with :mod:`onchanges </ref/states/requisites#onchanges>`
|
||||
instead of ``cmd.wait``.
|
||||
Use :mod:`cmd.run <salt.states.cmd.run>` together with :ref:`onchanges <requisites-onchanges>`
|
||||
instead of :mod:`cmd.wait <salt.states.cmd.wait>`.
|
||||
|
||||
These two states are often confused. The important thing to remember about them
|
||||
is that :mod:`cmd.run <salt.states.cmd.run>` states are run each time the SLS
|
||||
@ -415,7 +415,8 @@ def wait(name,
|
||||
|
||||
.. note::
|
||||
|
||||
Use :mod:`cmd.run <salt.states.cmd.run>` with :mod:`onchange </ref/states/requisites#onchanges>` instead.
|
||||
Use :mod:`cmd.run <salt.states.cmd.run>` together with :mod:`onchanges </ref/states/requisites#onchanges>`
|
||||
instead of :mod:`cmd.wait <salt.states.cmd.wait>`.
|
||||
|
||||
name
|
||||
The command to execute, remember that the command will execute with the
|
||||
|
@ -46,6 +46,22 @@ class CPModuleTest(ModuleCase):
|
||||
self.assertIn('KNIGHT: They\'re nervous, sire.', data)
|
||||
self.assertNotIn('bacon', data)
|
||||
|
||||
def test_get_file_to_dir(self):
|
||||
'''
|
||||
cp.get_file
|
||||
'''
|
||||
tgt = os.path.join(paths.TMP, '')
|
||||
self.run_function(
|
||||
'cp.get_file',
|
||||
[
|
||||
'salt://grail/scene33',
|
||||
tgt,
|
||||
])
|
||||
with salt.utils.fopen(tgt + 'scene33', 'r') as scene:
|
||||
data = scene.read()
|
||||
self.assertIn('KNIGHT: They\'re nervous, sire.', data)
|
||||
self.assertNotIn('bacon', data)
|
||||
|
||||
def test_get_file_templated_paths(self):
|
||||
'''
|
||||
cp.get_file
|
||||
@ -235,6 +251,22 @@ class CPModuleTest(ModuleCase):
|
||||
])
|
||||
self.assertEqual(ret, False)
|
||||
|
||||
def test_get_url_to_dir(self):
|
||||
'''
|
||||
cp.get_url with salt:// source
|
||||
'''
|
||||
tgt = os.path.join(paths.TMP, '')
|
||||
self.run_function(
|
||||
'cp.get_url',
|
||||
[
|
||||
'salt://grail/scene33',
|
||||
tgt,
|
||||
])
|
||||
with salt.utils.fopen(tgt + 'scene33', 'r') as scene:
|
||||
data = scene.read()
|
||||
self.assertIn('KNIGHT: They\'re nervous, sire.', data)
|
||||
self.assertNotIn('bacon', data)
|
||||
|
||||
def test_get_url_https(self):
|
||||
'''
|
||||
cp.get_url with https:// source given
|
||||
|
Loading…
Reference in New Issue
Block a user