nfstest.nfs_util man page

nfstest.nfs_util — NFS utilities module

Description

Provides a set of tools for testing NFS including methods for starting a packet trace, stopping the packet trace and then open the packet trace for analysis. It also provides a mechanism to enable NFS/RPC kernel debug and saving the log messages for further analysis.

Furthermore, methods for finding specific NFSv4 operations within the packet trace are also included.

Classes

class NFSUtil(nfstest.host.Host)

NFSUtil object

NFSUtil() -> New NFSUtil object

Usage:
    from nfstest.nfs_util import NFSUtil

    # Create object for local host
    x = NFSUtil()

    # 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 stop the packet trace and unreference all client
objects

__init__(self, **kwargs)
Constructor

Initialize object's private data.

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']
tracename:
    Base name for trace files to create [default: 'tracefile']
trcdelay:
    Seconds to delay before stopping packet trace [default: 0.0]
notrace:
    Debug option so a trace is not actually started [default: False]
tcpdump:
    Tcpdump command [default: '/usr/sbin/tcpdump']
messages:
    Location of file for system messages [default: '/var/log/messages']
tmpdir:
    Temporary directory where trace files are created [default: '/tmp']
tbsize:
    Capture buffer size in kB [default: 50000]

create_host(self, host, **kwargs)
Create client host object and set defaults.

find_exchange_id(self, **kwargs)
Find the call and its corresponding reply for the NFSv4 EXCHANGE_ID
going to the server specified by the ipaddr and port.

ipaddr:
    Destination IP address [default: self.server]
port:
    Destination port [default: self.port]

Store the callback IP/TCP expression in object attribute cb_dst

Return a tuple: (pktcall, pktreply).

find_getdeviceinfo(self, deviceid=None)
Find the call and its corresponding reply for the NFSv4 GETDEVICEINFO
going to the server specified by the ipaddr for self.server and port
given by self.port.

deviceid:
    Look for an specific deviceid [default: any deviceid]

Return a tuple: (pktcall, pktreply, dslist).

find_layoutget(self, filehandle)
Find the call and its corresponding reply for the NFSv4 LAYOUTGET
of the given file handle going to the server specified by the
ipaddr for self.server and port given by self.port.

Return a tuple: (layoutget, layoutget_res, loc_body).

find_layoutrecall(self, status=0)
Find NFSv4 CB_LAYOUTRECALL call and return its reply.
The reply must also match the given status.

find_nfs_op(self, op, ipaddr, port=None, match='', status=0, src_ipaddr=None, maxindex=None, call_only=False)
Find the call and its corresponding reply for the specified NFSv4
operation going to the server specified by the ipaddr and port.
The reply must also match the given status.

op:
    NFS operation to find
ipaddr:
    Destination IP address
port:
    Destination port [default: any destination port]
match:
    Match string to include [default: '']
status:
    Match the status of the operation [default: 0]
src_ipaddr:
    Source IP address [default: any IP address]
maxindex:
    The match fails if packet index hits this limit [default: no limit]
call_only:
    Find the call only [default: False]

Return a tuple: (pktcall, pktreply).

find_open(self, **kwargs)
Find the call and its corresponding reply for the NFSv4 OPEN of the
given file going to the server specified by the ipaddr and port.

filename:
    Find open call and reply for this file [default: None]
claimfh:
    Find open call and reply for this file handle using CLAIM_FH
    [default: None]
ipaddr:
    Destination IP address [default: self.server]
port:
    Destination port [default: self.port]
deleg_type:
    Expected delegation type on reply [default: None]
deleg_stateid:
    Delegation stateid expected on call in delegate_cur_info [default: None]
fh:
    Find open call and reply for this file handle when using
    deleg_stateid [default: None]
src_ipaddr:
    Source IP address [default: any IP address]
maxindex:
    The match fails if packet index hits this limit [default: no limit]
anyclaim:
    Find open for either regular open or using delegate_cur_info [default: False]

Must specify either filename, claimfh or both.
Return a tuple: (filehandle, open_stateid, deleg_stateid).

get_abs_offset(self, offset, ds_index=None)
Get real file offset given by the (read/write) offset on the given
data server index, taking into account the type of layout
(dense/sparse), the stripe_size, first stripe index and the number
of filehandles. The layout information is taken from object
attribute layout.

get_filehandle(self, ds_index)
Return filehandle from the layout list of filehandles.

get_freebytes(self, dir=None)
Get the number of bytes available in the given directory.
It takes into account the effective user running the test.
The root user is allowed to use all the available disk space
on the device, on the other hand a regular user is allowed a
little bit less.

get_stateid(self, filename)
Search the packet trace for the file name given to get the OPEN
so all related state ids can be searched. A couple of object
attributes are defined, one is the correct state id that should
be used by I/O operations. The second is a dictionary table
which maps the state id to a string identifying if the state
id is an open, lock or delegation state id.

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.

stid_str(self, stateid)
Display the state id in CRC16 format

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().

verify_commit(self, ipaddr, port, filehandle, init=False)
Verify commits are properly sent to the server specified by the
given ipaddr and port.

ipaddr:
    Destination IP address of MDS or DS
port:
    Destination port number of MDS or DS
filehandle:
    Find commits for this file handle
init:
    Initialized test variables [default: False]

Return the number of commits sent to the server.

verify_create_session(self, ipaddr, port, ds=False, nocreate=False, ds_index=None, exchid_status=0, cs_status=0)
Verify initial connection to the metadata server(MDS)/data server(DS).
Verify if EXCHANGE_ID, CREATE_SESSION, RECLAIM_COMPLETE,
GETATTR asking for FATTR4_LEASE_TIME, and GETATTR asking for
FATTR4_FS_LAYOUT_TYPES are all sent or not to the server.

ipaddr:
    Destination IP address of MDS or DS
port:
    Destination port number of MDS or DS
ds:
    True if ipaddr/port defines a DS, otherwise MDS [default: False]
nocreate:
    True if expecting the client NOT to send EXCHANGE_ID,
    CREATE_SESSION, and RECLAIM_COMPLETE. Otherwise, verify all
    these operations are sent by the client [default: False]
ds_index:
    DS index used for displaying purposes only [default: None]
exchid_status:
    Expected status for EXCHANGE_ID [default: 0]
cs_status:
    Expected status for CREATE_SESSION [default: 0]

Return the sessionid and it is also stored in the object
attribute sessionid.

verify_io(self, iomode, stateid, ipaddr=None, port=None, src_ipaddr=None, filehandle=None, ds_index=None, init=False, maxindex=None, pattern=None)
Verify I/O is sent to the server specified by the ipaddr and port.

iomode:
    Verify reads (iomode == 1) or writes (iomode == 2)
stateid:
    Expected stateid to use in all I/O requests
ipaddr:
    Destination IP address of MDS or DS
    [default: do not match destination]
port:
    Destination port number of MDS or DS
    [default: do not match destination port]
src_ipaddr:
    Source IP address of request
    [default: do not match source]
filehandle:
    Find I/O for this file handle. This option is used when
    verifying I/O sent to the MDS
    [default: use filehandle given by ds_index]
ds_index:
    Data server index. This option is used when verifying I/O sent
    to the DS -- filehandle is taken from x.layout for this index
    [default: None]
init:
    Initialized test variables [default: False]
maxindex:
    The match fails if packet index hits this limit [default: no limit]
pattern:
    Data pattern to compare [default: default data pattern]

Return the number of I/O operations sent to the server.

verify_layoutcommit(self, filehandle, filesize)
Verify layoutcommit is properly sent to the server specified by
the ipaddr for self.server and port given by self.port.
Verify a GETATTR asking for file size is sent within the same
compound as the LAYOUTCOMMIT.
Verify GETATTR returns correct size for the file.

filehandle:
    Find layoutcommit for this file handle
filesize:
    Expected size of file

verify_layoutget(self, filehandle, iomode, riomode=None, status=0, offset=None, length=None)
Verify the client sends a LAYOUTGET for the given file handle.

filehandle:
    Find LAYOUTGET for this file handle
iomode:
    Expected I/O mode for LAYOUTGET call
riomode:
    Expected I/O mode for LAYOUTGET reply if specified, else verify
    reply I/O mode is equal to call I/O mode if iomode == 2.
    If iomode == 1, the reply I/O mode could be equal to 1 or 2
status:
    Expected status for LAYOUTGET reply [default: 0]
offset:
    Expected layout range for LAYOUTGET reply [default: None]
length:
    Expected layout range for LAYOUTGET reply [default: None]

If both offset and length are not given, verify LAYOUTGET reply
should be a full layout [0, NFS4_UINT64_MAX]. If only one is
provided the following defaults are used: offset = 0,
length = NFS4_UINT64_MAX.

Layout information is stored in the object attribute layout.

Return a tuple: (layoutget, layoutget_res, loc_body).

verify_stripe(self, offset, size, ds_index)
Verify if read/write is sent to the correct data server according
to stripe size, first stripe index and the number of filehandles.
The layout information is taken from object attribute layout.

offset:
    Real file offset
size:
    I/O size
ds_index:
    Data server index

Return True if stripe is correctly verified, False otherwise.

Static methods defined here:
----------------------------

bitmap_str(bitmap, count, bmap, blist)
Return the string representation of bitmap.

bitmap:
    Bitmap to convert
count:
    Number of occurrences of bitmap
bmap:
    Dictionary mapping the bits to strings
blist:
    List of all possible bit combinations

iomode_str(iomode)
Return a string representation of iomode.
This could be run as an instance or class method.

See Also

baseobj(3), nfstest.host(3), packet.nfs.nfs4_const(3), packet.pktt(3)

Bugs

No known bugs.

Author

Jorge Mora (mora@netapp.com)

Referenced By

nfstest.test_util(3).

23 November 2015 NFStest 2.1.1 nfs_util 2.0