cp.get_url: log error message if no file could be fetched from salt:// URL

This commit is contained in:
Denys Havrysh 2016-10-11 11:02:02 +03:00
parent 99cf3038cc
commit b33f4d7b93
2 changed files with 17 additions and 7 deletions

View file

@ -556,12 +556,13 @@ class Client(object):
return url_data.path
if url_data.scheme == 'salt':
cached = self.get_file(url, dest, makedirs, saltenv, cachedir=cachedir)
if dest is None:
with salt.utils.fopen(cached, 'r') as fp_:
result = self.get_file(url, dest, makedirs, saltenv, cachedir=cachedir)
if result and dest is None:
with salt.utils.fopen(result, 'r') as fp_:
data = fp_.read()
return data
return cached
return result
if dest:
destdir = os.path.dirname(dest)
if not os.path.isdir(destdir):

View file

@ -315,6 +315,8 @@ def get_url(path, dest, saltenv='base', env=None):
destination path. To simply return the file contents instead, set
destination to ``None``.
Returns ``False`` if Salt was unable to fetch a file from a URL.
CLI Example:
.. code-block:: bash
@ -331,10 +333,17 @@ def get_url(path, dest, saltenv='base', env=None):
# Backwards compatibility
saltenv = env
if isinstance(dest, str):
return _client().get_url(path, dest, False, saltenv)
if isinstance(dest, six.string_type):
result = _client().get_url(path, dest, False, saltenv)
else:
return _client().get_url(path, None, False, saltenv, no_cache=True)
result = _client().get_url(path, None, False, saltenv, no_cache=True)
if not result:
log.error(
'Unable to fetch file {0!r} from saltenv {1!r}.'.format(
path, saltenv
)
)
return result
def get_file_str(path, saltenv='base', env=None):