tests: more ansible fixes from recent brakage.

pull/244/head
David Wilson 8 years ago
parent b20174729d
commit 69f58875c8

@ -114,8 +114,9 @@ class Runner(object):
def setup(self): def setup(self):
""" """
Prepare the current process for running a module. The base Prepare for running a module, including fetching necessary dependencies
implementation simply prepares the environment. from the parent, as :meth:`run` may detach prior to beginning
execution. The base implementation simply prepares the environment.
""" """
self._env = TemporaryEnvironment(self.env) self._env = TemporaryEnvironment(self.env)
@ -234,6 +235,14 @@ class ProgramRunner(Runner):
super(ProgramRunner, self).setup() super(ProgramRunner, self).setup()
self._setup_program() self._setup_program()
def _get_program_filename(self):
"""
Return the filename used for program on disk. Ansible uses the original
filename for non-Ansiballz runs, and "ansible_module_+filename for
Ansiballz runs.
"""
return os.path.basename(self.path)
program_fp = None program_fp = None
def _setup_program(self): def _setup_program(self):
@ -241,8 +250,8 @@ class ProgramRunner(Runner):
Create a temporary file containing the program code. The code is Create a temporary file containing the program code. The code is
fetched via :meth:`_get_program`. fetched via :meth:`_get_program`.
""" """
name = 'ansible_module_' + os.path.basename(self.path) filename = self._get_program_filename()
path = os.path.join(ansible_mitogen.target.temp_dir, name) path = os.path.join(ansible_mitogen.target.temp_dir, filename)
self.program_fp = open(path, 'wb') self.program_fp = open(path, 'wb')
self.program_fp.write(self._get_program()) self.program_fp.write(self._get_program())
self.program_fp.flush() self.program_fp.flush()
@ -394,6 +403,12 @@ class NewStyleRunner(ScriptRunner):
self._stdio.revert() self._stdio.revert()
super(NewStyleRunner, self).revert() super(NewStyleRunner, self).revert()
def _get_program_filename(self):
"""
See ProgramRunner._get_program_filename().
"""
return 'ansible_module_' + os.path.basename(self.path)
def _setup_args(self): def _setup_args(self):
pass pass

@ -235,6 +235,7 @@ def _on_broker_shutdown():
prune_tree(temp_dir) prune_tree(temp_dir)
@mitogen.core.takes_econtext
def reset_temp_dir(econtext): def reset_temp_dir(econtext):
""" """
Create one temporary directory to be reused by all runner.py invocations Create one temporary directory to be reused by all runner.py invocations
@ -277,6 +278,7 @@ def init_child(econtext):
def start_fork_child(wrap_async, kwargs, econtext): def start_fork_child(wrap_async, kwargs, econtext):
mitogen.parent.upgrade_router(econtext) mitogen.parent.upgrade_router(econtext)
context = econtext.router.fork() context = econtext.router.fork()
context.call(reset_temp_dir)
if not wrap_async: if not wrap_async:
try: try:
return context.call(run_module, kwargs) return context.call(run_module, kwargs)
@ -386,7 +388,6 @@ def run_module_async(job_id, kwargs, econtext):
""" """
try: try:
try: try:
reset_temp_dir(econtext)
_run_module_async(job_id, kwargs, econtext) _run_module_async(job_id, kwargs, econtext)
except Exception: except Exception:
LOG.exception('_run_module_async crashed') LOG.exception('_run_module_async crashed')

@ -11,16 +11,10 @@ def usage():
sys.stderr.write('Usage: %s <input.json>\n' % (sys.argv[0],)) sys.stderr.write('Usage: %s <input.json>\n' % (sys.argv[0],))
sys.exit(1) sys.exit(1)
# Also must slurp in our own source code, to verify the encoding string was
# added.
with open(sys.argv[0]) as fp:
me = fp.read()
input_json = sys.stdin.read() input_json = sys.stdin.read()
print "{" print "{"
print " \"changed\": false," print " \"changed\": false,"
print " \"msg\": \"Here is my input\"," print " \"msg\": \"Here is my input\","
print " \"source\": [%s]," % (json.dumps(me),)
print " \"input\": [%s]" % (input_json,) print " \"input\": [%s]" % (input_json,)
print "}" print "}"

@ -12,11 +12,6 @@ def usage():
sys.stderr.write('Usage: %s <input.json>\n' % (sys.argv[0],)) sys.stderr.write('Usage: %s <input.json>\n' % (sys.argv[0],))
sys.exit(1) sys.exit(1)
# Also must slurp in our own source code, to verify the encoding string was
# added.
with open(sys.argv[0]) as fp:
me = fp.read()
input_json = sys.stdin.read() input_json = sys.stdin.read()
print "{" print "{"
@ -27,6 +22,5 @@ print " \"__file__\": \"%s\"," % (__file__,)
# Python sets this during a regular import. # Python sets this during a regular import.
print " \"__package__\": \"%s\"," % (__package__,) print " \"__package__\": \"%s\"," % (__package__,)
print " \"msg\": \"Here is my input\"," print " \"msg\": \"Here is my input\","
print " \"source\": [%s]," % (json.dumps(me),)
print " \"input\": [%s]" % (input_json,) print " \"input\": [%s]" % (input_json,)
print "}" print "}"

Loading…
Cancel
Save