HOST(3)
π HOST(3) β the host module, bestie edition β¨
from the host manual, version 1.7 π
πΈ NAME πΈ
nfstest.host β the Host module π
π¦ DESCRIPTION π¦
okay so. nfstest.host is basically your little toolbox for running commands β whether they're chillin' on the local host or vibing on a remote host. π«Ά
And yes, she thought of everything: there's also a mechanism for running commands in the background, so you're not just sitting there staring at your terminal like π waiting for something to finish. main character energy honestly.
she also comes with methods for mounting and unmounting from an NFS server β so like, you can hop on and off a server whenever, no cap β¨
and for the drama girlies: there's a mechanism to simulate a network partition using iptables π₯ literally building fake breakups between your hosts. iconic.
β οΈ but bestie listen β as of right now, there is no mechanism to restore the iptables rules to their original state. so once you partition that network, those rules are justβ¦ out there. living their life. π no undo button, no take-backs, fr fr. be careful with that one. π
πΈ CLASSES πΈ
π class Host(baseobj.BaseObj) π
Host object, and it's giving main character energy for all your NFS test host needs. π
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. The goodbye kiss, the Irish exit, the bye bestie π__init__(self, **kwargs)β Constructor. Initialize object's private data. Here's every kwarg you can pass, no cap β¨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']nconnect:β Multiple TCP connections option [default:1]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:'']tracepoints:β List of trace points modules to enable [default:'']nfsstats:β Get NFS stats [default:False]dbgname:β Base name for log messages files to create [default:'dbgfile']trcpname:β Base name for trace point files to create [default:'trcpfile']nfsstatname:β Base name for NFS stats files to create [default:'nfsstatfile']messages:β Location of file for system messages [default:'/var/log/messages']trcevents:β Tracing events directory [default:'/sys/kernel/debug/tracing/events']trcpipe:β Trace pipe file [default:'/sys/kernel/debug/tracing/trace_pipe']tmpdir:β Temporary directory where trace/debug files are created [default:'/tmp']iptables:β Iptables command [default:'/usr/sbin/iptables']kill:β kill command [default:'/usr/bin/kill']nfsstat:β nfsstat command [default:'/usr/bin/nfsstat']sudo:β Sudo command [default:'/usr/bin/sudo']
abspath(self, filename, dir=None)β Return the absolute path for the given file name.cleanup(self)β Gracefully unmount volume and reset network.get_pids(self, pid)β Get all descendant PIDs for the given PID.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. Like, actually attach that NFS thing π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]nconnect:β Multiple TCP connections option [default:self.nconnect]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 givenipaddrandportusing 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. Let's snoop, but respectfully π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 usingself.dbgnameas the base name.
nfs_debug_reset(self)β Reset NFS debug messages.nfsstat_get(self)β Get NFS stats.nfsstat_init(self)β Initialize NFS stats.nfsstr(self, version=None, prefix='NFSv')β Return the NFS string for the given NFS version.version:β NFS version, default is the object attributenfsversion
nfsvers(self, version=None)β Return major and minor version for the given NFS version.version:β NFS version, default is the object attributenfsversion
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.processto be used by methodswait_cmd()andstop_cmd(). The standard output of the command is also stored in the object attributeself.pstdoutwhile the standard error output of the command is stored inself.pstderr. cmd:β Command to executesudo:β Run command using sudo if option isTruedlevel:β Debug level for displaying the command to the usermsg:β Prefix this message to the debug message to be displayedwait:β 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. π₯
- The object for the process of the command is stored in object attribute
stop_cmd(self, process=None, dlevel=None, msg='')β Terminate command started byrun_cmd()by callingwait_cmd()with the'terminate'option set toTrue. Bye bye, process πprocess:β The object for the process of the command to terminate, or terminate all commands started byrun_cmd()if this option is not givendlevel:β Debug level for displaying the command to the user, default is the level given byrun_cmd()msg:β Prefix this message to the debug message to be displayed- Return the exit status of the last command.
sudo_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 bytrace_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_points_enable(self)β Enable trace points.trace_points_reset(self)β Reset trace points.trace_start(self, tracefile=None, interface=None, capsize=None, clients=None)β Start trace on interface given. Theinterfacearg is the interface, and here are the rest:tracefile:β Name of trace file to create, default is a unique name created in the temporary directory usingself.tracenameas the base name.capsize:β Use the-Coption of tcpdump to split the trace files every1000000*capsizebytes. See documentation for tcpdump for more informationclients:β List ofHost()objects to monitor- Return the name of the trace file created.
trace_stop(self)β Stop the trace started bytrace_start().umount(self)β Unmount the file system.wait_cmd(self, process=None, terminate=False, dlevel=None, msg='')β Wait for command started byrun_cmd()to finish. Patience, bestie π§process:β The object for the process of the command to wait for, or wait for all commands started byrun_cmd()if this option is not giventerminate:β IfTrue, send a signal to terminate the command or commands and then wait for all commands to finishdlevel:β Debug level for displaying the command to the user, default is the level given byrun_cmd()msg:β Prefix this message to the debug message to be displayed- Return the exit status of the last command.
β Static 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 π
π BUGS π
No known bugs. So clean, so slay. β¨
π AUTHOR π
Jorge Mora (mora@netapp.com)
This page is from NFStest 3.2, dated 21 March 2023 β and that's the whole Host(3) vibe, bestie. π
π¦ where this page comes from
- debian trixie: nfstest 3.2-3
- fedora 43: NFStest 3.2-14.fc43 Β· GPL-2.0-or-later
- fedora 44: NFStest 3.2-16.fc44 Β· GPL-2.0-or-later
- ubuntu noble: nfstest 3.2-2
- ubuntu questing: nfstest 3.2-3
- ubuntu resolute: nfstest 3.2-3build1
- ubuntu stonking: nfstest 3.2-5
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms