virttest.remote_commander package¶
Submodules¶
virttest.remote_commander.messenger module¶
Created on Dec 6, 2013
author: | jzupka, astepano |
---|---|
contact: | Andrei Stepanov <astepano@redhat.com> |
-
class
virttest.remote_commander.messenger.
DataWrapper
¶ Bases:
object
Basic implementation of IOWrapper for stdio.
-
decode
(data)¶ Decodes the data which was read.
Returns: decoded data.
-
encode
(data)¶ Encode data.
Returns: encoded data.
-
-
class
virttest.remote_commander.messenger.
DataWrapperBase64
¶ Bases:
virttest.remote_commander.messenger.DataWrapper
Basic implementation of IOWrapper for stdio.
-
decode
(data)¶ Decodes the data which was read.
Returns: decoded data.
-
encode
(data)¶ Encode data.
Returns: encoded data.
-
-
class
virttest.remote_commander.messenger.
IOWrapper
(obj)¶ Bases:
object
Class encaptulates io operation to be more consist in different implementations. (stdio, sockets, etc..)
Parameters: obj – IO obj for example file decriptor. -
close
()¶
-
fileno
()¶ Function should return file descriptor number. If object should be used for standard io operation.
Returns: File number.
-
read
(max_len, timeout=None)¶ 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)¶ Write function should be implemented for object uded for writing.
Parameters: data (str.) – Data to write.
-
-
class
virttest.remote_commander.messenger.
Messenger
(stdin, stdout)¶ 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.
Params stdin: Object for read data from communication interface. Params stdout: Object for write data to communication interface. -
close
()¶
-
flush_stdin
()¶ Flush all input data from communication interface.
-
format_msg
(data)¶ Format message where first 10 char is length of message and rest is piclked message.
-
read_msg
(timeout=None)¶ 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)¶ Write formatted message to communication interface.
-
-
exception
virttest.remote_commander.messenger.
MessengerError
(msg)¶ Bases:
exceptions.Exception
-
class
virttest.remote_commander.messenger.
StdIOWrapper
(obj)¶ Bases:
virttest.remote_commander.messenger.IOWrapper
,virttest.remote_commander.messenger.DataWrapper
Basic implementation of IOWrapper for stdio.
Parameters: obj – IO obj for example file decriptor. -
close
()¶
-
fileno
()¶ Function should return file descriptor number. If object should be used for standard io operation.
Returns: File number.
-
-
class
virttest.remote_commander.messenger.
StdIOWrapperIn
(obj)¶ Bases:
virttest.remote_commander.messenger.StdIOWrapper
Basic implementation of IOWrapper for stdin
Parameters: obj – IO obj for example file decriptor. -
read
(max_len, timeout=None)¶ 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.
-
-
class
virttest.remote_commander.messenger.
StdIOWrapperInBase64
(obj)¶ Bases:
virttest.remote_commander.messenger.StdIOWrapperIn
,virttest.remote_commander.messenger.DataWrapperBase64
Basic implementation of IOWrapper for stdin
Parameters: obj – IO obj for example file decriptor.
-
class
virttest.remote_commander.messenger.
StdIOWrapperOut
(obj)¶ Bases:
virttest.remote_commander.messenger.StdIOWrapper
Basic implementation of IOWrapper for stdout
Parameters: obj – IO obj for example file decriptor. -
write
(data)¶ Write function should be implemented for object uded for writing.
Parameters: data (str.) – Data to write.
-
-
class
virttest.remote_commander.messenger.
StdIOWrapperOutBase64
(obj)¶ Bases:
virttest.remote_commander.messenger.StdIOWrapperOut
,virttest.remote_commander.messenger.DataWrapperBase64
Basic implementation of IOWrapper for stdout
Parameters: obj – IO obj for example file decriptor.
virttest.remote_commander.remote_interface module¶
Created on Dec 11, 2013
author: | jzupka, astepano |
---|---|
contact: | Andrei Stepanov <astepano@redhat.com> |
-
class
virttest.remote_commander.remote_interface.
BaseCmd
(func_cmd, *args, **kargs)¶ Bases:
virttest.remote_commander.remote_interface.CmdMessage
Class used for moving information about commands between master and slave.
-
args
¶
-
cmd_hash
¶
-
func
¶
-
is_async
()¶ Returns: True if command is async else False
-
is_finished
()¶ Returns: True if command is finished else False
-
kargs
¶
-
nh_stderr
¶
-
nh_stdin
¶
-
nh_stdout
¶
-
results
¶
-
single_cmd_id
= 0¶
-
update
(basecmd)¶ 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)¶
-
-
class
virttest.remote_commander.remote_interface.
CmdMessage
(cmd_id)¶ Bases:
object
Base cmd message class
-
cmd_id
¶
-
isCmdMsg
()¶
-
-
class
virttest.remote_commander.remote_interface.
CmdQuery
(*args, **kargs)¶ Bases:
object
Command-msg-request from VM to avocado-vt test.
Command for asking from VM to avocado-vt.
Parameters: - args – Something pickable. Is irrelevant for messenger.
- kargs – Something pickable. Is irrelevant for messenger.
-
class
virttest.remote_commander.remote_interface.
CmdRespond
(respond)¶ Bases:
object
Command-msg-answer from avocado-test to VM.
Command for answering avocado-vt to VM.
Parameters: respond – Something pickable. Is irrelevant for messenger.
-
exception
virttest.remote_commander.remote_interface.
CmdTraceBack
(msg)¶ Bases:
exceptions.Exception
Represent back-trace used for error tracing on remote side.
-
exception
virttest.remote_commander.remote_interface.
CommanderError
(msg)¶ Bases:
virttest.remote_commander.remote_interface.MessengerError
Represent error in Commander
-
exception
virttest.remote_commander.remote_interface.
MessengerError
(msg)¶ Bases:
exceptions.Exception
Represented error in messanger.
-
class
virttest.remote_commander.remote_interface.
StdErr
(msg, cmd_id=None)¶ Bases:
virttest.remote_commander.remote_interface.StdStream
Represent message from stderr string data from remote client
-
cmd_id
¶
-
msg
¶
-
-
class
virttest.remote_commander.remote_interface.
StdOut
(msg, cmd_id=None)¶ Bases:
virttest.remote_commander.remote_interface.StdStream
Represent message from stdout string data from remote client
-
cmd_id
¶
-
msg
¶
-
-
class
virttest.remote_commander.remote_interface.
StdStream
(msg, cmd_id=None)¶ 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, astepano |
---|---|
contact: | Andrei Stepanov <astepano@redhat.com> |
-
class
virttest.remote_commander.remote_master.
CmdEncapsulation
(master, obj_name, name)¶ Bases:
object
Class parse command name cmd.nohup.shell -> [“nohup”, “shell”]
-
class
virttest.remote_commander.remote_master.
CmdMaster
(commander, name, *args, **kargs)¶ Bases:
object
Representation of BaseCmd on master side.
Params commander: Commander from which was command started. Params name: Name parsed to string representation Parmas args: list to arguments to cmd. Params kargs: {} -
basecmd
¶ Property basecmd getter
-
getbasecmd
()¶ Property basecmd getter
-
getstderr
()¶ Property stderr getter
-
getstdout
()¶ Property stdout getter
-
send_stdin
(msg)¶ Send data to stdin
-
set_commander
(commander)¶ For nohup commands it allows connect cmd to new created commander.
-
setbasecmd
(value)¶ Property basecmd setter _resuls_cnt identify if value was change from last reading.
-
setstderr
(value)¶ Property stderr setter _stderr_cnt identify if value was change from last reading.
-
setstdout
(value)¶ Property stdout setter _stdout_cnt identify if value was change from last reading.
-
stderr
¶ Property stderr getter
-
stdout
¶ Property stdout getter
-
wait
()¶ Wait until command return results.
-
wait_response
()¶ Wait until command return any cmd.
-
-
exception
virttest.remote_commander.remote_master.
CmdTimeout
(msg)¶ Bases:
virttest.remote_commander.remote_interface.MessengerError
Raised when waiting for cmd exceeds time define by timeout.
-
class
virttest.remote_commander.remote_master.
Commander
¶ Bases:
object
Commander representation for transfer over network.
-
class
virttest.remote_commander.remote_master.
CommanderMaster
(stdin, stdout, debug=False)¶ 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
()¶
-
cmd
(cmd)¶ Invoke command on client side.
-
listen_cmds
(cmd)¶ Manage basecmds from slave side.
-
listen_errors
(cmd)¶ Listen for errors raised from slave part of commander.
-
listen_messenger
(timeout=60)¶ Wait for msg from slave side and take care about them.
-
listen_queries
(cmd)¶ Manage queries from slave side.
-
listen_streams
(cmd)¶ Listen on all streams included in Commander commands.
-
set_responder
(responder)¶ Warning: Users’ helper becomes a part of a remote_commander. remote_commander is treated as a session. All sessions are part of BaseVM object. If you provide unpickable helper then your BaseVM also becomes unpickable. You can catch something like:
File "/usr/lib64/python2.7/copy_reg.py", line 74, in _reduce_ex getstate = self.__getstate__ KeyError: '__getstate__'
For more info see:
https://github.com/avocado-framework/avocado-vt/issues/455
-
wait
(cmd)¶ Wait until command return results.
-
wait_response
(cmd)¶ Wait until command return any cmd.
-
-
virttest.remote_commander.remote_master.
getsource
(obj)¶
-
virttest.remote_commander.remote_master.
wait_timeout
(timeout)¶
virttest.remote_commander.remote_runner module¶
Created on Dec 6, 2013
author: | jzupka, astepano |
---|---|
contact: | Andrei Stepanov <astepano@redhat.com> |
-
class
virttest.remote_commander.remote_runner.
CmdFinish
(parent=False)¶ Bases:
object
Class used for communication with child process. This class
-
pid
¶
-
-
class
virttest.remote_commander.remote_runner.
CmdSlave
(baseCmd)¶ Bases:
object
Representation of BaseCmd on slave side.
Parameters: baseCmd – basecmd for encapsulation. -
close_pipes
()¶ Close command communication pipe.
-
finish
(commander)¶ Remove cmd from commander commands on finish of process.
-
parse_func_name
(func_name, commander)¶ 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
()¶ Helper function for reconnect to daemon/nohup process.
-
recover_paths
()¶ Helper function for reconnect to daemon/nohup process.
-
work
()¶ Wait for message from running child process
-
-
class
virttest.remote_commander.remote_runner.
CommanderSlave
(stdin, stdout, o_stdout, o_stderr)¶ 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
()¶ 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)¶ 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)¶ Adds function to client code.
Parameters: f_code (str.) – Code of function.
-
copy_file
(name, path, content)¶ Really naive implementation of copping files. Should be used only for short files.
-
exit
()¶ Method for killing command slave.
-
import_src
(name, path=None)¶ Import file to running python session.
-
interactive
()¶ Starts interactive python.
-
python_file_run_with_helper
(test_path)¶ Call run() function at external python module.
Parameters: test_path – Path to python file. Call run() at this module. Returns: module.run().return
-
register_cmd
(basecmd, basecmd_cmd_id)¶ Second side of set_commander cmd from master. It register existing cmd to CommandSlave dict.
Parameters:
-
send_msg
(msg, cmd_id)¶ 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)¶ Starts shell process. Stdout is automatically copied to basecmd.stdout
Parameters: cmd – Command which should be started. Returns: basecmd with return code of cmd.
-
-
class
virttest.remote_commander.remote_runner.
Helper
(messenger)¶ Bases:
object
Passed to external test on VM.
-
flush_buf
()¶
-
info
(*args, **kargs)¶
-
messenger
¶
-
query_master
(*args, **kargs)¶ Read CmdRespond from master.
-
-
virttest.remote_commander.remote_runner.
clean_tmp_dir
(path)¶ Clean up directory.
-
virttest.remote_commander.remote_runner.
close_unused_fds
(fds)¶ Close all file descriptors which are not necessary anymore.
Parameters: fds (builtin.list) – file descriptors
-
virttest.remote_commander.remote_runner.
create_process_cmd
()¶ 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')¶ 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)¶ Try to create tmp dir with special name.
-
virttest.remote_commander.remote_runner.
remote_agent
(in_stream_cls, out_stream_cls)¶ Connect file descriptors to right pipe and start slave command loop. When something happened 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)¶