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 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. 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 using self.dbgname as 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 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. Bye bye, process πŸ’€
    • 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 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 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_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. The interface arg 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 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. Patience, bestie 🧘
    • 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 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. πŸ’–