aboutsummaryrefslogtreecommitdiff
path: root/pym
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2010-08-12 22:08:56 -0700
committerZac Medico <zmedico@gentoo.org>2010-08-12 22:08:56 -0700
commit15e1a041ddd6bdbc6dc30b350e16c864f8d4c334 (patch)
treeb610acace1e39295f7489abf88f9c8d8cb067bd6 /pym
parentSplit out an EbuildIpcDaemon class from FifoIpcDaemon. (diff)
downloadportage-15e1a041ddd6bdbc6dc30b350e16c864f8d4c334.tar.gz
portage-15e1a041ddd6bdbc6dc30b350e16c864f8d4c334.tar.bz2
portage-15e1a041ddd6bdbc6dc30b350e16c864f8d4c334.zip
Make IpcDaemonTestCase demonstrate an EbuildIpcDaemon based
replacement for EBUILD_EXIT_STATUS_FILE.
Diffstat (limited to 'pym')
-rw-r--r--pym/_emerge/EbuildIpcDaemon.py20
-rw-r--r--pym/portage/tests/ebuild/test_ipc_daemon.py53
2 files changed, 52 insertions, 21 deletions
diff --git a/pym/_emerge/EbuildIpcDaemon.py b/pym/_emerge/EbuildIpcDaemon.py
index 48f58224b..2f4d8933c 100644
--- a/pym/_emerge/EbuildIpcDaemon.py
+++ b/pym/_emerge/EbuildIpcDaemon.py
@@ -24,7 +24,7 @@ class EbuildIpcDaemon(FifoIpcDaemon):
left orphan processes running in the backgraound (as in bug 278895).
"""
- __slots__ = ()
+ __slots__ = ('commands',)
def _input_handler(self, fd, event):
@@ -38,15 +38,15 @@ class EbuildIpcDaemon(FifoIpcDaemon):
if buf:
obj = pickle.loads(buf.tostring())
- if isinstance(obj, list) and \
- obj and \
- obj[0] == 'exit':
- output_fd = os.open(self.output_fifo, os.O_WRONLY|os.O_NONBLOCK)
- output_file = os.fdopen(output_fd, 'wb')
- pickle.dump('OK', output_file)
- output_file.close()
- self._unregister()
- self.wait()
+ cmd_key = obj[0]
+ cmd_handler = self.commands[cmd_key]
+ cmd_handler(obj, self._send_reply)
self._unregister_if_appropriate(event)
return self._registered
+
+ def _send_reply(self, reply):
+ output_fd = os.open(self.output_fifo, os.O_WRONLY|os.O_NONBLOCK)
+ output_file = os.fdopen(output_fd, 'wb')
+ pickle.dump(reply, output_file)
+ output_file.close()
diff --git a/pym/portage/tests/ebuild/test_ipc_daemon.py b/pym/portage/tests/ebuild/test_ipc_daemon.py
index 488bd3999..bd27a38d1 100644
--- a/pym/portage/tests/ebuild/test_ipc_daemon.py
+++ b/pym/portage/tests/ebuild/test_ipc_daemon.py
@@ -12,6 +12,28 @@ from _emerge.SpawnProcess import SpawnProcess
from _emerge.EbuildIpcDaemon import EbuildIpcDaemon
from _emerge.TaskScheduler import TaskScheduler
+class ExitCommand(object):
+
+ def __init__(self):
+ self.callback = None
+ self.exitcode = None
+
+ def __call__(self, argv, send_reply):
+ duplicate = False
+ if self.exitcode is not None:
+ # Ignore all but the first call, since if die is called
+ # then we certainly want to honor that exitcode, even
+ # the ebuild process manages to send a second exit
+ # command.
+ duplicate = True
+ else:
+ self.exitcode = int(argv[1])
+
+ # (stdout, stderr, returncode)
+ send_reply(('', '', 0))
+ if not duplicate and self.callback is not None:
+ self.callback()
+
class IpcDaemonTestCase(TestCase):
def testIpcDaemon(self):
@@ -25,16 +47,25 @@ class IpcDaemonTestCase(TestCase):
output_fifo = os.path.join(tmpdir, '.ipc_out')
os.mkfifo(input_fifo)
os.mkfifo(output_fifo)
- task_scheduler = TaskScheduler(max_jobs=2)
- daemon = EbuildIpcDaemon(input_fifo=input_fifo,
- output_fifo=output_fifo,
- scheduler=task_scheduler.sched_iface)
- proc = SpawnProcess(
- args=[BASH_BINARY, "-c", '"$PORTAGE_BIN_PATH"/ebuild-ipc exit 0'],
- env=env, scheduler=task_scheduler.sched_iface)
- task_scheduler.add(daemon)
- task_scheduler.add(proc)
- task_scheduler.run()
- self.assertEqual(proc.returncode, os.EX_OK)
+ for exitcode in (0, 1, 2):
+ task_scheduler = TaskScheduler(max_jobs=2)
+ exit_command = ExitCommand()
+ commands = {'exit' : exit_command}
+ daemon = EbuildIpcDaemon(commands=commands,
+ input_fifo=input_fifo,
+ output_fifo=output_fifo,
+ scheduler=task_scheduler.sched_iface)
+ proc = SpawnProcess(
+ args=[BASH_BINARY, "-c",
+ '"$PORTAGE_BIN_PATH"/ebuild-ipc exit %d' % exitcode],
+ env=env, scheduler=task_scheduler.sched_iface)
+ def exit_command_callback():
+ daemon.cancel()
+ proc.cancel()
+ exit_command.callback = exit_command_callback
+ task_scheduler.add(daemon)
+ task_scheduler.add(proc)
+ task_scheduler.run()
+ self.assertEqual(exit_command.exitcode, exitcode)
finally:
shutil.rmtree(tmpdir)