virttest.remote_commander package

Submodules

virttest.remote_commander.messenger module

Created on Dec 6, 2013

author:jzupka
class virttest.remote_commander.messenger.DataWrapper[source]

Bases: object

Basic implementation of IOWrapper for stdio.

decode(data)[source]

Decodes the data which was read.

Returns:decoded data.
encode(data)[source]

Encode data.

Returns:encoded data.
class virttest.remote_commander.messenger.DataWrapperBase64[source]

Bases: virttest.remote_commander.messenger.DataWrapper

Basic implementation of IOWrapper for stdio.

decode(data)[source]
encode(data)[source]
class virttest.remote_commander.messenger.IOWrapper(obj)[source]

Bases: object

Class encaptulates io opearation to be more consist in different implementations. (stdio, sockets, etc..)

close()[source]
fileno()[source]

Function should return file descriptor number. If object should be used for standard io operation.

Returns:File number.
read(max_len, timeout=None)[source]

Read function should be reinmplemented as blocking reading from data source when timeout is None and nonblocking for timeout is not None. Implementation example StdIWrapper.

Params max_len:Max len of readed data.
Parameters:timeout (float) – Timeout of reading operation.
Returns:Readed data.
write(data)[source]

Write funciton should be implemented for object uded for writing.

Parameters:data (str.) – Data to write.
class virttest.remote_commander.messenger.Messenger(stdin, stdout)[source]

Bases: object

Class could be used for communication between two python process connected by communication canal wrapped by IOWrapper class. Pickling is used for communication and thus it is possible to communicate every picleable object.

close()[source]
flush_stdin()[source]

Flush all input data from communication interface.

format_msg(data)[source]

Format message where first 10 char is length of message and rest is piclked message.

read_msg(timeout=None)[source]

Read data from com interface.

Parameters:timeout (float) – timeout for reading data.
Returns:(True, data) when reading is successful. (False, None) when other side is closed. (None, None) when reading is timeouted.
write_msg(data)[source]

Write formated message to communication interface.

exception virttest.remote_commander.messenger.MessengerError(msg)[source]

Bases: exceptions.Exception

class virttest.remote_commander.messenger.StdIOWrapper(obj)[source]

Bases: virttest.remote_commander.messenger.IOWrapper, virttest.remote_commander.messenger.DataWrapper

Basic implementation of IOWrapper for stdio.

close()[source]
fileno()[source]
class virttest.remote_commander.messenger.StdIOWrapperIn(obj)[source]

Bases: virttest.remote_commander.messenger.StdIOWrapper

Basic implementation of IOWrapper for stdin

read(max_len, timeout=None)[source]
class virttest.remote_commander.messenger.StdIOWrapperInBase64(obj)[source]

Bases: virttest.remote_commander.messenger.StdIOWrapperIn, virttest.remote_commander.messenger.DataWrapperBase64

Basic implementation of IOWrapper for stdin

class virttest.remote_commander.messenger.StdIOWrapperOut(obj)[source]

Bases: virttest.remote_commander.messenger.StdIOWrapper

Basic implementation of IOWrapper for stdout

write(data)[source]
class virttest.remote_commander.messenger.StdIOWrapperOutBase64(obj)[source]

Bases: virttest.remote_commander.messenger.StdIOWrapperOut, virttest.remote_commander.messenger.DataWrapperBase64

Basic implementation of IOWrapper for stdout

virttest.remote_commander.remote_interface module

Created on Dec 11, 2013

author:jzupka
class virttest.remote_commander.remote_interface.BaseCmd(func_cmd, *args, **kargs)[source]

Bases: virttest.remote_commander.remote_interface.CmdMessage

Class used for moveing information about commands between master and slave.

args
cmd_hash
func
is_async()[source]
Returns:True if command is async else False
is_finished()[source]
Returns:True if command is finished else False
kargs
nh_stderr
nh_stdin
nh_stdout
results
single_cmd_id = 0
update(basecmd)[source]

Sync local class with class moved over the messanger.

Parameters:basecmd (BaseCmd) – basecmd from which should be sync data to this instance
update_cmd_hash(basecmd)[source]
class virttest.remote_commander.remote_interface.CmdMessage(cmd_id)[source]

Bases: object

Base cmd message class

cmd_id
isCmdMsg()[source]
exception virttest.remote_commander.remote_interface.CmdTraceBack(msg)[source]

Bases: exceptions.Exception

Represent back-trace used for error tracing on remote side.

exception virttest.remote_commander.remote_interface.CommanderError(msg)[source]

Bases: virttest.remote_commander.remote_interface.MessengerError

Represent error in Commnader

exception virttest.remote_commander.remote_interface.MessengerError(msg)[source]

Bases: exceptions.Exception

Represented error in messanger.

class virttest.remote_commander.remote_interface.StdErr(msg, cmd_id=None)[source]

Bases: virttest.remote_commander.remote_interface.StdStream

Represent message from stderr string data from remote client

class virttest.remote_commander.remote_interface.StdOut(msg, cmd_id=None)[source]

Bases: virttest.remote_commander.remote_interface.StdStream

Represent message from stdout string data from remote client

class virttest.remote_commander.remote_interface.StdStream(msg, cmd_id=None)[source]

Bases: virttest.remote_commander.remote_interface.CmdMessage

Represent message string data from remote client

msg

virttest.remote_commander.remote_master module

Created on Dec 6, 2013

author:jzupka
class virttest.remote_commander.remote_master.CmdEncapsulation(master, obj_name, name)[source]

Bases: object

Class parse command name cmd.nohup.shell -> [“nohup”, “shell”]

class virttest.remote_commander.remote_master.CmdMaster(commander, name, *args, **kargs)[source]

Bases: object

Representation of BaseCmd on master side.

basecmd

Property basecmd getter

getbasecmd()[source]

Property basecmd getter

getstderr()[source]

Property stderr getter

getstdout()[source]

Property stdout getter

send_stdin(msg)[source]

Send data to stdin

set_commander(commander)[source]

For nohup commands it allows connect cmd to new created commander.

setbasecmd(value)[source]

Property basecmd setter _resuls_cnt identify if value was change from last reading.

setstderr(value)[source]

Property stderr setter _stderr_cnt identify if value was change from last reading.

setstdout(value)[source]

Property stdout setter _stdout_cnt identify if value was change from last reading.

stderr

Property stderr getter

stdout

Property stdout getter

wait()[source]

Wait until command return results.

wait_response(timeout=None)[source]

Wait until command return any cmd.

exception virttest.remote_commander.remote_master.CmdTimeout(msg)[source]

Bases: virttest.remote_commander.remote_interface.MessengerError

Raised when waiting for cmd exceeds time define by timeout.

class virttest.remote_commander.remote_master.Commander[source]

Bases: object

Commander representation for transfer over network.

class virttest.remote_commander.remote_master.CommanderMaster(stdin, stdout, debug=False)[source]

Bases: virttest.remote_commander.messenger.Messenger

Class commander master is responsible for communication with commander slave. It invoke commands to slave part and receive messages from them. For communication is used only stdin and stdout which are streams from slave part.

close()[source]
cmd(cmd, timeout=60)[source]

Invoke command on client side.

listen_cmds(cmd)[source]

Manage basecmds from slave side.

listen_errors(cmd)[source]

Listen for errors raised from slave part of commander.

listen_messenger(timeout=60)[source]

Wait for msg from slave side and take care about them.

listen_streams(cmd)[source]

Listen on all streams included in Commander commands.

wait(cmd, timeout=60)[source]

Wait until command return results.

wait_response(cmd, timeout=60)[source]

Wait until command return any cmd.

virttest.remote_commander.remote_master.getsource(obj)[source]
virttest.remote_commander.remote_master.wait_timeout(timeout)[source]

virttest.remote_commander.remote_runner module

Created on Dec 6, 2013

author:jzupka
class virttest.remote_commander.remote_runner.CmdFinish(parent=False)[source]

Bases: object

Class used for communication with child process. This class

pid
class virttest.remote_commander.remote_runner.CmdSlave(baseCmd)[source]

Bases: object

Representation of BaseCmd on slave side.

close_pipes()[source]

Close command communication pipe.

finish(commander)[source]

Remove cmd from commander commands on finish of process.

parse_func_name(func_name, commander)[source]

Parse name sended from master.

format: ["manage|async|nohup| ", "fnname1", "fnname2", ...]

Parameters:
  • func_name – Function name
  • commander – Where to execute the command (remote or local)
recover_fds()[source]

Helper function for reconnect to daemon/nohup process.

recover_paths()[source]

Helper function for reconnect to daemon/nohup process.

work()[source]

Wait for message from running child process

class virttest.remote_commander.remote_runner.CommanderSlave(stdin, stdout, o_stdout, o_stderr)[source]

Bases: virttest.remote_commander.messenger.Messenger

Class commander slace is responsible for communication with commander master. It invoke commands to slave part and receive messages from them. For communication is used only stdin and stdout which are streams from slave part.

cmd_loop()[source]

Wait for commands from master and receive results and outputs from commands.

class virttest.remote_commander.remote_runner.CommanderSlaveCmds(stdin, stdout, o_stdout, o_stderr)[source]

Bases: virttest.remote_commander.remote_runner.CommanderSlave

Class extends CommanderSlave and adds to them special commands like shell process, interactive python, send_msg to cmd.

add_function(f_code)[source]

Adds function to client code.

Parameters:f_code (str.) – Code of function.
copy_file(name, path, content)[source]

Really naive implementation of copping files. Should be used only for short files.

exit()[source]

Method for killing command slave.

import_src(name, path=None)[source]

Import file to running python session.

interactive()[source]

Starts interactive python.

register_cmd(basecmd, basecmd_cmd_id)[source]

Second side of set_commander cmd from master. It register existing cmd to CommandSlave dict.

Parameters:
  • basecmd (BaseCmd) – cmd which should be added to CommandSlave dict
  • basecmd_cmd_id (int) – number under which should be stored
send_msg(msg, cmd_id)[source]

Send msg to cmd with id == cmd_id

Parameters:
  • msg (str) – message passed to cmd over the stdin
  • cmd_id – id of cmd.
shell(cmd)[source]

Starts shell process. Stdout is automatically copyed to basecmd.stdout

Parameters:cmd – Command which should be started.
Returns:basecmd with return code of cmd.
virttest.remote_commander.remote_runner.clean_tmp_dir(path)[source]

Clean up directory.

virttest.remote_commander.remote_runner.close_unused_fds(fds)[source]

Close all file descriptors which are not necessary anymore.

Parameters:fds (list []) – file descriptors
virttest.remote_commander.remote_runner.create_process_cmd()[source]

Create child process without clean process data thanks that it is possible call function and classes from child process.

virttest.remote_commander.remote_runner.daemonize(pipe_root_path='/tmp')[source]

Init daemon.

Parameters:pipe_root_path – path to directory for pipe.
Returns:[True if child, stdin_path, stdou_path, stderr_path]
virttest.remote_commander.remote_runner.gen_tmp_dir(root_path)[source]

Try to create tmp dir with special name.

virttest.remote_commander.remote_runner.remote_agent(in_stream_cls, out_stream_cls)[source]

Connect file descriptors to right pipe and start slave command loop. When something happend it raise exception which could be caught by cmd master.

Params in_stream_cls:
 Class encapsulated input stream.
Params out_stream_cls:
 Class encapsulated output stream.
virttest.remote_commander.remote_runner.sort_fds_event(fds)[source]

Module contents