Better error messages when the file to be transferred does not exist.

pull/11357/head
Toshio Kuratomi 10 years ago
parent 7490044bbe
commit 61e367f549

@ -134,25 +134,27 @@ class Connection(object):
vvv("PUT %s TO %s" % (in_path, out_path), host=self.jail) vvv("PUT %s TO %s" % (in_path, out_path), host=self.jail)
with open(in_path, 'rb') as in_file: try:
try: with open(in_path, 'rb') as in_file:
p = self._buffered_exec_command('dd of=%s' % out_path, None, stdin=in_file) try:
except OSError: p = self._buffered_exec_command('dd of=%s' % out_path, None, stdin=in_file)
raise errors.AnsibleError("jail connection requires dd command in the jail") except OSError:
try: raise errors.AnsibleError("jail connection requires dd command in the jail")
stdout, stderr = p.communicate() try:
except: stdout, stderr = p.communicate()
traceback.print_exc() except:
raise errors.AnsibleError("failed to transfer file to %s" % out_path) traceback.print_exc()
if p.returncode != 0: raise errors.AnsibleError("failed to transfer file %s to %s" % (in_path, out_path))
raise errors.AnsibleError("failed to transfer file to %s:\n%s\n%s" % (out_path, stdout, stderr)) if p.returncode != 0:
raise errors.AnsibleError("failed to transfer file %s to %s:\n%s\n%s" % (in_path, out_path, stdout, stderr))
except IOError:
raise errors.AnsibleError("file or module does not exist at: %s" % in_path)
def fetch_file(self, in_path, out_path): def fetch_file(self, in_path, out_path):
''' fetch a file from jail to local ''' ''' fetch a file from jail to local '''
vvv("FETCH %s TO %s" % (in_path, out_path), host=self.jail) vvv("FETCH %s TO %s" % (in_path, out_path), host=self.jail)
try: try:
p = self._buffered_exec_command('dd if=%s bs=%s' % (in_path, BUFSIZE), None) p = self._buffered_exec_command('dd if=%s bs=%s' % (in_path, BUFSIZE), None)
except OSError: except OSError:
@ -164,10 +166,10 @@ class Connection(object):
out_file.write(chunk) out_file.write(chunk)
except: except:
traceback.print_exc() traceback.print_exc()
raise errors.AnsibleError("failed to transfer file to %s" % out_path) raise errors.AnsibleError("failed to transfer file %s to %s" % (in_path, out_path))
stdout, stderr = p.communicate() stdout, stderr = p.communicate()
if p.returncode != 0: if p.returncode != 0:
raise errors.AnsibleError("failed to transfer file to %s:\n%s\n%s" % (out_path, stdout, stderr)) raise errors.AnsibleError("failed to transfer file %s to %s:\n%s\n%s" % (in_path, out_path, stdout, stderr))
def close(self): def close(self):
''' terminate the connection; nothing to do here ''' ''' terminate the connection; nothing to do here '''

@ -147,18 +147,21 @@ class Connection(object):
vvv("PUT %s TO %s" % (in_path, out_path), host=self.zone) vvv("PUT %s TO %s" % (in_path, out_path), host=self.zone)
with open(in_path, 'rb') as in_file: try:
try: with open(in_path, 'rb') as in_file:
p = self._buffered_exec_command('dd of=%s' % out_path, None, stdin=in_file) try:
except OSError: p = self._buffered_exec_command('dd of=%s' % out_path, None, stdin=in_file)
raise errors.AnsibleError("zone connection requires dd command in the zone") except OSError:
try: raise errors.AnsibleError("jail connection requires dd command in the jail")
stdout, stderr = p.communicate() try:
except: stdout, stderr = p.communicate()
traceback.print_exc() except:
raise errors.AnsibleError("failed to transfer file to %s" % out_path) traceback.print_exc()
if p.returncode != 0: raise errors.AnsibleError("failed to transfer file %s to %s" % (in_path, out_path))
raise errors.AnsibleError("failed to transfer file to %s:\n%s\n%s" % (out_path, stdout, stderr)) if p.returncode != 0:
raise errors.AnsibleError("failed to transfer file %s to %s:\n%s\n%s" % (in_path, out_path, stdout, stderr))
except IOError:
raise errors.AnsibleError("file or module does not exist at: %s" % in_path)
def fetch_file(self, in_path, out_path): def fetch_file(self, in_path, out_path):
''' fetch a file from zone to local ''' ''' fetch a file from zone to local '''
@ -178,10 +181,10 @@ class Connection(object):
out_file.write(chunk) out_file.write(chunk)
except: except:
traceback.print_exc() traceback.print_exc()
raise errors.AnsibleError("failed to transfer file to %s" % out_path) raise errors.AnsibleError("failed to transfer file %s to %s" % (in_path, out_path))
stdout, stderr = p.communicate() stdout, stderr = p.communicate()
if p.returncode != 0: if p.returncode != 0:
raise errors.AnsibleError("failed to transfer file to %s:\n%s\n%s" % (out_path, stdout, stderr)) raise errors.AnsibleError("failed to transfer file %s to %s:\n%s\n%s" % (in_path, out_path, stdout, stderr))
def close(self): def close(self):
''' terminate the connection; nothing to do here ''' ''' terminate the connection; nothing to do here '''

Loading…
Cancel
Save