Inside of runner, do not 'import *' from utils, so we can more easily tell where functions come from

This commit is contained in:
Michael DeHaan 2012-03-18 17:04:07 -04:00
parent 9837a616eb
commit 33aa50eae7

View file

@ -31,8 +31,7 @@ import traceback
import tempfile import tempfile
import subprocess import subprocess
# FIXME: stop importing *, use as utils/errors from ansible import utils
from ansible.utils import *
from ansible.errors import * from ansible.errors import *
# should be True except in debug # should be True except in debug
@ -51,7 +50,7 @@ def _executor_hook(job_queue, result_queue):
result_queue.put(runner._executor(host)) result_queue.put(runner._executor(host))
except Queue.Empty: except Queue.Empty:
pass pass
except AnsibleError, ae: except errors.AnsibleError, ae:
result_queue.put([host, False, str(ae)]) result_queue.put([host, False, str(ae)])
except Exception, ee: except Exception, ee:
# probably should include the full trace # probably should include the full trace
@ -168,7 +167,7 @@ class Runner(object):
try: try:
groups = json.loads(out) groups = json.loads(out)
except: except:
raise AnsibleError("invalid JSON response from script: %s" % host_list) raise errors.AnsibleError("invalid JSON response from script: %s" % host_list)
for (groupname, hostlist) in groups.iteritems(): for (groupname, hostlist) in groups.iteritems():
for host in hostlist: for host in hostlist:
if host not in results: if host not in results:
@ -222,7 +221,7 @@ class Runner(object):
try: try:
# try to parse the JSON response # try to parse the JSON response
return [ host, True, parse_json(result) ] return [ host, True, utils.parse_json(result) ]
except Exception, e: except Exception, e:
# it failed, say so, but return the string anyway # it failed, say so, but return the string anyway
return [ host, False, "%s/%s" % (str(e), result) ] return [ host, False, "%s/%s" % (str(e), result) ]
@ -307,7 +306,7 @@ class Runner(object):
try: try:
inject2 = json.loads(out) inject2 = json.loads(out)
except: except:
raise AnsibleError("%s returned invalid result when called with hostname %s" % ( raise errors.AnsibleError("%s returned invalid result when called with hostname %s" % (
Runner._external_variable_script, Runner._external_variable_script,
host host
)) ))
@ -363,7 +362,7 @@ class Runner(object):
if self.module_name == 'setup': if self.module_name == 'setup':
host = conn.host host = conn.host
try: try:
var_result = parse_json(result) var_result = utils.parse_json(result)
except: except:
var_result = {} var_result = {}
@ -412,7 +411,7 @@ class Runner(object):
# transfer the file to a remote tmp location # transfer the file to a remote tmp location
tmp_path = tmp tmp_path = tmp
tmp_src = tmp_path + source.split('/')[-1] tmp_src = tmp_path + source.split('/')[-1]
self._transfer_file(conn, path_dwim(self.basedir, source), tmp_src) self._transfer_file(conn, utils.path_dwim(self.basedir, source), tmp_src)
# install the copy module # install the copy module
self.module_name = 'copy' self.module_name = 'copy'
@ -463,7 +462,7 @@ class Runner(object):
tpath = tmp tpath = tmp
tempname = os.path.split(source)[-1] tempname = os.path.split(source)[-1]
temppath = tpath + tempname temppath = tpath + tempname
self._transfer_file(conn, path_dwim(self.basedir, source), temppath) self._transfer_file(conn, utils.path_dwim(self.basedir, source), temppath)
# install the template module # install the template module
template_module = self._transfer_module(conn, tmp, 'template') template_module = self._transfer_module(conn, tmp, 'template')