nfstest.host man page

nfstest.host — Host module

Description

Provides a set of tools for running commands on the local host or a remote host, including a mechanism for running commands in the background. It provides methods for mounting and unmounting from an NFS server and a mechanism to simulate a network partition via the use of 'iptables'. Currently, there is no mechanism to restore the iptables rules to their original state.

Classes

class Host(baseobj.BaseObj)

Host object

Host() -> New Host object

Usage:
    from nfstest.host import Host

    # Create host object for local host
    x = Host()
    # Create host object for remote host
    y = Host(host='192.168.0.11')

    # Run command to the local host
    x.run_cmd("ls -l")

    # Send command to the remote host and run it as root
    y.run_cmd("ls -l", sudo=True)

    # Run command in the background
    x.run_cmd("tcpdump", sudo=True, wait=False)
    ....
    ....
    # Stop command running in the background
    x.stop_cmd()

    # Mount volume using default options
    x.mount()

    # Unmount volume
    x.umount()

    # Start packet trace
    x.trace_start()

    # Stop packet trace
    x.trace_stop()

    # Open packet trace
    x.trace_open()

    # Enable NFS kernel debug
    x.nfs_debug_enable(nfsdebug='all'):

    # Stop NFS kernel debug
    x.nfs_debug_reset()


Methods defined here:
---------------------

__del__(self)
Destructor

Gracefully unmount volume and reset network.

__init__(self, **kwargs)
Constructor

Initialize object's private data.

host: Hostname or IP address [default: localhost] user: User to log in to host [default: ''] server: NFS server name or IP address [default: None] nfsversion: NFS version [default: 4.1] proto: NFS protocol name [default: 'tcp'] port: NFS server port [default: 2049] sec: Security flavor [default: 'sys'] export: Exported file system to mount [default: '/'] mtpoint: Mount point [default: '/mnt/t'] datadir: Data directory where files are created [default: ''] mtopts: Mount options [default: 'hard,rsize=4096,wsize=4096'] interface: Network device interface [default: 'eth0'] nomount: Debug option so the server is not actually mounted [default: False] tracename: Base name for trace files to create [default: 'tracefile'] trcdelay: Seconds to delay before stopping packet trace [default: 0.0] tcpdump: Tcpdump command [default: '/usr/sbin/tcpdump'] tbsize: Capture buffer size in kB [default: 150000] notrace: Debug option so a trace is not actually started [default: False] rpcdebug: Set RPC kernel debug flags and save log messages [default: ''] nfsdebug: Set NFS kernel debug flags and save log messages [default: ''] dbgname: Base name for log messages files to create [default: 'dbgfile'] messages: Location of file for system messages [default: '/var/log/messages'] tmpdir: Temporary directory where trace/debug files are created [default: '/tmp'] iptables: Iptables command [default: '/usr/sbin/iptables'] sudo: Sudo command [default: '/usr/bin/sudo']

abspath(self, filename, dir=None) Return the absolute path for the given file name. get_route(self, ipaddr) Get routing information for destination IP address Returns a tuple: (gateway, device name, src IP address) mount(self, **kwargs) Mount the file system on the given mount point.

server: NFS server name or IP address [default: self.server] nfsversion: NFS version [default: self.nfsversion] proto: NFS protocol name [default: self.proto] port: NFS server port [default: self.port] sec: Security flavor [default: self.sec] export: Exported file system to mount [default: self.export] mtpoint: Mount point [default: self.mtpoint] datadir: Data directory where files are created [default: self.datadir] mtopts: Mount options [default: self.mtopts]

Return the mount point.network_drop(self, ipaddr, port) Simulate a network drop by dropping all tcp packets going to the given ipaddr and port using the iptables commands. network_reset(self) Reset the network by flushing all the chains in the table using the iptables command. nfs_debug_enable(self, **kwargs) Enable NFS debug messages.

rpcdebug: Set RPC kernel debug flags and save log messages [default: self.rpcdebug] nfsdebug: Set NFS kernel debug flags and save log messages [default: self.nfsdebug] dbgfile: Name of log messages file to create, default is a unique name created in the temporary directory using self.dbgname as the base name.

nfs_debug_reset(self) Reset NFS debug messages. nfsstr(self, version=None) Return the NFS string for the given NFS version

version: NFS version, default is the object attribute nfsversion

nfsvers(self, version=None) Return major and minor version for the given NFS version

version: NFS version, default is the object attribute nfsversion

run_cmd(self, cmd, sudo=False, dlevel='DBG1', msg='', wait=True) Run the command to the remote machine using ssh. There is no user authentication, so remote host must allow ssh connection without any passwords for the user. For a localhost the command is just executed and ssh is not used. The object for the process of the command is stored in object attribute 'self.process' to be used by methods wait_cmd() and stop_cmd(). The standard output of the command is also stored in the object attribute 'self.pstdout' while the standard error output of the command is stored in 'self.pstderr'.

cmd: Command to execute sudo: Run command using sudo if option is True dlevel: Debug level for displaying the command to the user msg: Prefix this message to the debug message to be displayed wait: Wait for command to complete before returning

Return the standard output of the command and the return code or exit status is stored in the object attribute 'self.returncode'.stop_cmd(self, process=None, dlevel=None, msg='') Terminate command started by run_cmd() by calling wait_cmd() with the 'terminate' option set to True.

process: The object for the process of the command to terminate, or terminate all commands started by run_cmd() if this option is not given dlevel: Debug level for displaying the command to the user, default is the level given by run_cmd() msg: Prefix this message to the debug message to be displayed

Return the exit status of the last commandsudo_cmd(self, cmd) Prefix the SUDO command if effective user is not root. trace_open(self, tracefile=None, **kwargs) Open the trace file given or the trace file started by trace_start(). All extra options are passed directly to the packet trace object. Return the packet trace object created, the packet trace object is also stored in the object attribute pktt. trace_start(self, tracefile=None, interface=None, capsize=None, clients=None) Start trace on interface given

tracefile: Name of trace file to create, default is a unique name created in the temporary directory using self.tracename as the base name. capsize: Use the -C option of tcpdump to split the trace files every 1000000*capsize bytes. See documentation for tcpdump for more information clients: List of Host() objects to monitor

Return the name of the trace file created.trace_stop(self) Stop the trace started by trace_start(). umount(self) Unmount the file system. wait_cmd(self, process=None, terminate=False, dlevel=None, msg='') Wait for command started by run_cmd() to finish.

process: The object for the process of the command to wait for, or wait for all commands started by run_cmd() if this option is not given terminate: If True, send a signal to terminate the command or commands and then wait for all commands to finish dlevel: Debug level for displaying the command to the user, default is the level given by run_cmd() msg: Prefix this message to the debug message to be displayed

Return the exit status of the last commandStatic methods defined here: ---------------------------- get_ip_address(host='', ipv6=False) Get IP address associated with the given host name. This could be run as an instance or class method.

See Also

baseobj(3), packet.pktt(3)

Bugs

No known bugs.

Author

Jorge Mora (mora@netapp.com)

Referenced By

nfstest.nfs_util(3), nfstest.test_util(3).

14 February 2017 NFStest 2.1.5 host 1.3