clustershell icon indicating copy to clipboard operation
clustershell copied to clipboard

iter_buffers returns WorkerPopen rather than a string for nodelist

Open sunilangadi2 opened this issue 6 years ago • 2 comments

Code: result = {} for output,nodelist in task.iter_buffers():   for node in nodelist:     result[node] = str(output)

this produces output

{<ClusterShell.Worker.Popen.WorkerPopen object at 0x7f919c13ded0>: "invalid parameter dump_kernel'\nopen(dump_kernel) failed: No such file or directory"}

sunilangadi2 avatar Oct 15 '18 06:10 sunilangadi2

Hi @sunilangadi2,

For local "workers", the nodelist will actually consists in local Worker instances (eg. WorkerPopen) if a worker "key" is not provided earlier.

For example, you can set a custom key when calling task.shell() or task.run() (here the key is "local"):

from ClusterShell.Task import task_self

task = task_self()
task.run("echo foo", key="local")
for buf, keys in task.iter_buffers():
    for key in keys:
        print(key, buf.message())
$ python test.py
('local', 'foo')

For remote workers (eg. task.shell(..., nodes=...), the keys will be the node names. Hope that makes sense!

thiell avatar Oct 17 '18 02:10 thiell

Thanks for your solution @thiell

sunilangadi2 avatar Oct 17 '18 06:10 sunilangadi2