1HOST(3)                            host 1.7                            HOST(3)
2
3
4

NAME

6       nfstest.host - Host module
7

DESCRIPTION

9       Provides a set of tools for running commands on the local host or a re‐
10       mote host, including a mechanism for  running  commands  in  the  back‐
11       ground.   It  provides  methods for mounting and unmounting from an NFS
12       server and a mechanism to simulate a network partition via the  use  of
13       'iptables'.   Currently,  there is no mechanism to restore the iptables
14       rules to their original state.
15

CLASSES

17   class Host(baseobj.BaseObj)
18       Host object
19
20       Host() -> New Host object
21
22       Usage:
23           from nfstest.host import Host
24
25           # Create host object for local host
26           x = Host()
27           # Create host object for remote host
28           y = Host(host='192.168.0.11')
29
30           # Run command to the local host
31           x.run_cmd("ls -l")
32
33           # Send command to the remote host and run it as root
34           y.run_cmd("ls -l", sudo=True)
35
36           # Run command in the background
37           x.run_cmd("tcpdump", sudo=True, wait=False)
38           ....
39           ....
40           # Stop command running in the background
41           x.stop_cmd()
42
43           # Mount volume using default options
44           x.mount()
45
46           # Unmount volume
47           x.umount()
48
49           # Start packet trace
50           x.trace_start()
51
52           # Stop packet trace
53           x.trace_stop()
54
55           # Open packet trace
56           x.trace_open()
57
58           # Enable NFS kernel debug
59           x.nfs_debug_enable(nfsdebug='all'):
60
61           # Stop NFS kernel debug
62           x.nfs_debug_reset()
63
64
65       Methods defined here:
66       ---------------------
67
68       __del__(self)
69       Destructor
70
71       __init__(self, **kwargs)
72       Constructor
73
74       Initialize object's private data.
75
76
77              host:  Hostname or IP address [default: localhost]
78
79              user:  User to log in to host [default: '']
80
81              server:
82                     NFS server name or IP address [default: None]
83
84              nfsversion:
85                     NFS version [default: 4.1]
86
87              proto: NFS protocol name [default: 'tcp']
88
89              port:  NFS server port [default: 2049]
90
91              sec:   Security flavor [default: 'sys']
92
93              nconnect:
94                     Multiple TCP connections option [default: 1]
95
96              export:
97                     Exported file system to mount [default: '/']
98
99              mtpoint:
100                     Mount point [default: '/mnt/t']
101
102              datadir:
103                     Data directory where files are created [default: '']
104
105              mtopts:
106                     Mount options [default: 'hard,rsize=4096,wsize=4096']
107
108              interface:
109                     Network device interface [default: 'eth0']
110
111              nomount:
112                     Debug option so the server is not actually mounted [default: False]
113
114              tracename:
115                     Base name for trace files to create [default: 'tracefile']
116
117              trcdelay:
118                     Seconds to delay before stopping packet trace [default: 0.0]
119
120              tcpdump:
121                     Tcpdump command [default: '/usr/sbin/tcpdump']
122
123              tbsize:
124                     Capture buffer size in kB [default: 150000]
125
126              notrace:
127                     Debug option so a trace is not actually started [default: False]
128
129              rpcdebug:
130                     Set RPC kernel debug flags and save log messages [default: '']
131
132              nfsdebug:
133                     Set NFS kernel debug flags and save log messages [default: '']
134
135              tracepoints:
136                     List of trace points modules to enable [default: '']
137
138              nfsstats:
139                     Get NFS stats [default: False]
140
141              dbgname:
142                     Base name for log messages files to create [default: 'dbgfile']
143
144              trcpname:
145                     Base name for trace point files to create [default: 'trcpfile']
146
147              nfsstatname:
148                     Base name for NFS stats files to create [default: 'nfsstatfile']
149
150              messages:
151                     Location of file for system messages [default: '/var/log/messages']
152
153              trcevents:
154                     Tracing events directory [default: '/sys/kernel/debug/tracing/events']
155
156              trcpipe:
157                     Trace pipe file [default: '/sys/kernel/debug/tracing/trace_pipe']
158
159              tmpdir:
160                     Temporary directory where trace/debug files are created
161                     [default: '/tmp']
162
163              iptables:
164                     Iptables command [default: '/usr/sbin/iptables']
165
166              kill:  kill command [default: '/usr/bin/kill']
167
168              nfsstat:
169                     nfsstat command [default: '/usr/bin/nfsstat']
170
171              sudo:  Sudo command [default: '/usr/bin/sudo']
172
173       abspath(self, filename, dir=None)
174       Return the absolute path for the given file name.
175
176       cleanup(self)
177       Gracefully unmount volume and reset network
178
179       get_pids(self, pid)
180       Get all descendant PIDs for the given PID
181
182       get_route(self, ipaddr)
183       Get routing information for destination IP address
184       Returns a tuple: (gateway, device name, src IP address)
185
186       mount(self, **kwargs)
187       Mount the file system on the given mount point.
188
189
190              server:
191                     NFS server name or IP address [default: self.server]
192
193              nfsversion:
194                     NFS version [default: self.nfsversion]
195
196              proto: NFS protocol name [default: self.proto]
197
198              port:  NFS server port [default: self.port]
199
200              sec:   Security flavor [default: self.sec]
201
202              nconnect:
203                     Multiple TCP connections option [default: self.nconnect]
204
205              export:
206                     Exported file system to mount [default: self.export]
207
208              mtpoint:
209                     Mount point [default: self.mtpoint]
210
211              datadir:
212                     Data directory where files are created [default: self.datadir]
213
214              mtopts:
215                     Mount options [default: self.mtopts]
216
217              Return the mount point.
218
219       network_drop(self, ipaddr, port)
220       Simulate a network drop by dropping all tcp packets going to the
221       given ipaddr and port using the iptables commands.
222
223       network_reset(self)
224       Reset the network by flushing all the chains in the table using
225       the iptables command.
226
227       nfs_debug_enable(self, **kwargs)
228       Enable NFS debug messages.
229
230
231              rpcdebug:
232                     Set RPC kernel debug flags and save log messages [default: self.rpcdebug]
233
234              nfsdebug:
235                     Set NFS kernel debug flags and save log messages [default: self.nfsdebug]
236
237              dbgfile:
238                     Name of log messages file to create, default is a unique name
239                     created in the temporary directory using self.dbgname as the
240                     base name.
241
242       nfs_debug_reset(self)
243       Reset NFS debug messages.
244
245       nfsstat_get(self)
246       Get NFS stats.
247
248       nfsstat_init(self)
249       Initialize NFS stats.
250
251       nfsstr(self, version=None, prefix='NFSv')
252       Return the NFS string for the given NFS version
253
254
255              version:
256                     NFS version, default is the object attribute nfsversion
257
258       nfsvers(self, version=None)
259       Return major and minor version for the given NFS version
260
261
262              version:
263                     NFS version, default is the object attribute nfsversion
264
265       run_cmd(self, cmd, sudo=False, dlevel='DBG1', msg='', wait=True)
266       Run the command to the remote machine using ssh.
267       There is no user authentication, so remote host must allow
268       ssh connection without any passwords for the user.
269       For a localhost the command is just executed and ssh is not used.
270
271       The object for the process of the command is stored in object
272       attribute 'self.process' to be used by methods wait_cmd() and
273       stop_cmd(). The standard output of the command is also stored
274       in the object attribute 'self.pstdout' while the standard error
275       output of the command is stored in 'self.pstderr'.
276
277
278              cmd:   Command to execute
279
280              sudo:  Run command using sudo if option is True
281
282              dlevel:
283                     Debug level for displaying the command to the user
284
285              msg:   Prefix this message to the debug message to be displayed
286
287              wait:  Wait for command to complete before returning
288
289              Return the standard output of the command and the return code or
290              exit status is stored in the object attribute 'self.returncode'.
291
292       stop_cmd(self, process=None, dlevel=None, msg='')
293       Terminate command started by run_cmd() by calling wait_cmd()
294       with the 'terminate' option set to True.
295
296
297              process:
298                     The object for the process of the command to terminate,
299                     or terminate all commands started by run_cmd() if this
300                     option is not given
301
302              dlevel:
303                     Debug level for displaying the command to the user, default
304                     is the level given by run_cmd()
305
306              msg:   Prefix this message to the debug message to be displayed
307
308              Return the exit status of the last command
309
310       sudo_cmd(self, cmd)
311       Prefix the SUDO command if effective user is not root.
312
313       trace_open(self, tracefile=None, **kwargs)
314       Open the trace file given or the trace file started by trace_start().
315
316       All extra options are passed directly to the packet trace object.
317
318       Return the packet trace object created, the packet trace object
319       is also stored in the object attribute pktt.
320
321       trace_points_enable(self)
322       Enable trace points.
323
324       trace_points_reset(self)
325       Reset trace points.
326
327       trace_start(self, tracefile=None, interface=None, capsize=None, clients=None)
328       Start trace on interface given
329
330
331              tracefile:
332                     Name of trace file to create, default is a unique name
333                     created in the temporary directory using self.tracename as the
334                     base name.
335
336              capsize:
337                     Use the -C option of tcpdump to split the trace files every
338                     1000000*capsize bytes. See documentation for tcpdump for more
339                     information
340
341              clients:
342                     List of Host() objects to monitor
343
344              Return the name of the trace file created.
345
346       trace_stop(self)
347       Stop the trace started by trace_start().
348
349       umount(self)
350       Unmount the file system.
351
352       wait_cmd(self, process=None, terminate=False, dlevel=None, msg='')
353       Wait for command started by run_cmd() to finish.
354
355
356              process:
357                     The object for the process of the command to wait for,
358                     or wait for all commands started by run_cmd() if this
359                     option is not given
360
361              terminate:
362                     If True, send a signal to terminate the command or commands
363                     and then wait for all commands to finish
364
365              dlevel:
366                     Debug level for displaying the command to the user, default
367                     is the level given by run_cmd()
368
369              msg:   Prefix this message to the debug message to be displayed
370
371              Return the exit status of the last command
372
373       Static methods defined here:
374       ----------------------------
375
376       get_ip_address(host='', ipv6=False)
377       Get IP address associated with the given host name.
378       This could be run as an instance or class method.
379

SEE ALSO

381       baseobj(3), packet.pktt(3)
382
383

BUGS

385       No known bugs.
386

AUTHOR

388       Jorge Mora (mora@netapp.com)
389
390
391
392NFStest 3.2                      21 March 2023                         HOST(3)
Impressum