| 1 |
#!/usr/bin/env python3 |
| 2 |
#=============================================================================== |
| 3 |
# Copyright 2014 NetApp, Inc. All Rights Reserved, |
| 4 |
# contribution by Jorge Mora <[email protected]> |
| 5 |
# |
| 6 |
# This program is free software; you can redistribute it and/or modify it under |
| 7 |
# the terms of the GNU General Public License as published by the Free Software |
| 8 |
# Foundation; either version 2 of the License, or (at your option) any later |
| 9 |
# version. |
| 10 |
# |
| 11 |
# This program is distributed in the hope that it will be useful, but WITHOUT |
| 12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 13 |
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 14 |
#=============================================================================== |
| 15 |
|
| 16 |
import nfstest_config as c |
| 17 |
from nfstest.file_io import * |
| 18 |
from optparse import OptionParser,OptionGroup,IndentedHelpFormatter,SUPPRESS_HELP |
| 19 |
|
| 20 |
# Module constants |
| 21 |
__author__ = "Jorge Mora (%s)" % c.NFSTEST_AUTHOR_EMAIL |
| 22 |
__copyright__ = "Copyright (C) 2014 NetApp, Inc." |
| 23 |
__license__ = "GPL v2" |
| 24 |
__version__ = "1.2" |
| 25 |
|
| 26 |
USAGE = """%prog -d <datadir> [options] |
| 27 |
|
| 28 |
I/O tool |
| 29 |
======== |
| 30 |
This I/O tool is used to create and manipulate files of different types. |
| 31 |
The arguments allow running for a specified period of time as well as running |
| 32 |
multiple processes. Each process modifies a single file at a time and the |
| 33 |
file name space is different for each process so there are no collisions |
| 34 |
between two different processes modifying the same file.""" |
| 35 |
|
| 36 |
################################################################################ |
| 37 |
# Entry point |
| 38 |
################################################################################ |
| 39 |
# Define command line options |
| 40 |
opts = OptionParser(USAGE, formatter = IndentedHelpFormatter(2, 25), version = "%prog " + __version__) |
| 41 |
opts.add_option("-d", "--datadir", help="Top level directory where files will be created, it will be created if it does not exist") |
| 42 |
opts.add_option("-s", "--seed", type="int", default=None, help="Seed to initialized the random number generator [default: automatically generated]") |
| 43 |
opts.add_option("-n", "--nprocs", type="int", default=1, help="Number of processes to use [default: %default]") |
| 44 |
opts.add_option("-r", "--runtime", type="int", default=0, help="Run time [default: '%default']") |
| 45 |
opts.add_option("-v", "--verbose", default="none", help="Verbose level: none|info|debug|dbg1-7|all [default: '%default']") |
| 46 |
opts.add_option("-e", "--exiterr", action="store_true", default=False, help="Exit on first error") |
| 47 |
|
| 48 |
# Hidden options |
| 49 |
opts.add_option("--list--options", action="store_true", default=False, help=SUPPRESS_HELP) |
| 50 |
|
| 51 |
writegroup = OptionGroup(opts, "Read and write") |
| 52 |
writegroup.add_option("--read", type="float", default=P_READ, help="Read file percentage [default: %default]") |
| 53 |
writegroup.add_option("--write", type="float", default=P_WRITE, help="Write file percentage [default: %default]") |
| 54 |
writegroup.add_option("--rdwr", type="float", default=P_RDWR, help="Read/write file percentage [default: %default]") |
| 55 |
writegroup.add_option("--randio", type="float", default=P_RANDIO, help="Random file access percentage [default: %default]") |
| 56 |
writegroup.add_option("--iodelay", type="float", default=P_IODELAY, help="Seconds to delay I/O operations [default: %default]") |
| 57 |
writegroup.add_option("--direct", action="store_true", default=False, help="Use direct I/O") |
| 58 |
writegroup.add_option("--rdwronly", action="store_true", default=False, help="Use read and write only, no rename, remove, etc.") |
| 59 |
opts.add_option_group(writegroup) |
| 60 |
|
| 61 |
opgroup = OptionGroup(opts, "File operations") |
| 62 |
opgroup.add_option("--create", type="float", default=P_CREATE, help="Create file percentage [default: %default]") |
| 63 |
opgroup.add_option("--odgrade", type="float", default=P_ODGRADE, help="Open downgrade percentage [default: %default]") |
| 64 |
opgroup.add_option("--osync", type="float", default=P_OSYNC, help="Open file with O_SYNC [default: %default]") |
| 65 |
opgroup.add_option("--fsync", type="float", default=P_FSYNC, help="Percentage of fsync after write [default: %default]") |
| 66 |
opgroup.add_option("--rename", type="float", default=P_RENAME, help="Rename file percentage [default: %default]") |
| 67 |
opgroup.add_option("--remove", type="float", default=P_REMOVE, help="Remove file percentage [default: %default]") |
| 68 |
opgroup.add_option("--trunc", type="float", default=P_TRUNC, help="Truncate file percentage [default: %default]") |
| 69 |
opgroup.add_option("--ftrunc", type="float", default=P_FTRUNC, help="Truncate opened file percentage [default: %default]") |
| 70 |
opgroup.add_option("--link", type="float", default=P_LINK, help="Create hard link percentage [default: %default]") |
| 71 |
opgroup.add_option("--slink", type="float", default=P_SLINK, help="Create symbolic link percentage [default: %default]") |
| 72 |
opgroup.add_option("--readdir", type="float", default=P_READDIR, help="List contents of directory percentage [default: %default]") |
| 73 |
opgroup.add_option("--lock", type="float", default=P_LOCK, help="Lock file percentage [default: %default]") |
| 74 |
opgroup.add_option("--unlock", type="float", default=P_UNLOCK, help="Unlock file percentage [default: %default]") |
| 75 |
opgroup.add_option("--tlock", type="float", default=P_TLOCK, help="Lock test percentage [default: %default]") |
| 76 |
opgroup.add_option("--lockfull", type="float", default=P_LOCKFULL, help="Lock full file percentage [default: %default]") |
| 77 |
opgroup.add_option("--minfiles", default=str(MIN_FILES), help="Minimum number of files to create before any file operation is executed [default: %default]") |
| 78 |
opts.add_option_group(opgroup) |
| 79 |
|
| 80 |
filegroup = OptionGroup(opts, "File size options") |
| 81 |
filegroup.add_option("--fsizeavg", default=P_FILESIZE, help="File size average [default: %default]") |
| 82 |
filegroup.add_option("--fsizedev", default=P_FSIZEDEV, help="File size standard deviation [default: %default]") |
| 83 |
filegroup.add_option("--rsize", default=P_RSIZE, help="Read block size [default: %default]") |
| 84 |
filegroup.add_option("--rsizedev", default=P_RSIZEDEV, help="Read block size standard deviation [default: %default]") |
| 85 |
filegroup.add_option("--wsize", default=P_WSIZE, help="Write block size [default: %default]") |
| 86 |
filegroup.add_option("--wsizedev", default=P_WSIZEDEV, help="Write block size standard deviation [default: %default]") |
| 87 |
filegroup.add_option("--sizemult", default=P_SIZEMULT, help="Size multiplier [default: %default]") |
| 88 |
opts.add_option_group(filegroup) |
| 89 |
|
| 90 |
loggroup = OptionGroup(opts, "Logging options") |
| 91 |
loggroup.add_option("--createlog", action="store_true", default=P_CREATELOG, help="Create log file") |
| 92 |
loggroup.add_option("--createlogs", action="store_true", default=P_CREATELOGS, help="Create a log file for each process") |
| 93 |
loggroup.add_option("--logdir", default=P_TMPDIR, help="Log directory [default: '%default']") |
| 94 |
opts.add_option_group(loggroup) |
| 95 |
|
| 96 |
# Run parse_args to get options and process dependencies |
| 97 |
vopts, args = opts.parse_args() |
| 98 |
if vopts.rdwronly: |
| 99 |
# Set new defaults |
| 100 |
opts.set_defaults(rename=0) |
| 101 |
opts.set_defaults(remove=0) |
| 102 |
opts.set_defaults(trunc=0) |
| 103 |
opts.set_defaults(ftrunc=0) |
| 104 |
opts.set_defaults(link=0) |
| 105 |
opts.set_defaults(slink=0) |
| 106 |
opts.set_defaults(readdir=0) |
| 107 |
opts.set_defaults(lock=0) |
| 108 |
opts.set_defaults(unlock=0) |
| 109 |
opts.set_defaults(tlock=0) |
| 110 |
opts.set_defaults(lockfull=0) |
| 111 |
|
| 112 |
# Defaults given above are for displaying purposes only |
| 113 |
# Set defaults for read and write to know which options are given |
| 114 |
opts.set_defaults(write=None) |
| 115 |
opts.set_defaults(read=None) |
| 116 |
opts.set_defaults(rdwr=None) |
| 117 |
|
| 118 |
# Re-run parse_args with new default values |
| 119 |
vopts, args = opts.parse_args() |
| 120 |
|
| 121 |
if vopts.list__options: |
| 122 |
hidden_opts = ("--list--options",) |
| 123 |
long_opts = [x for x in opts._long_opt.keys() if x not in hidden_opts] |
| 124 |
print("\n".join(list(opts._short_opt.keys()) + long_opts)) |
| 125 |
sys.exit(0) |
| 126 |
|
| 127 |
if vopts.datadir is None: |
| 128 |
opts.error("datadir option is required") |
| 129 |
|
| 130 |
# Remove empty keys |
| 131 |
empty_keys = [k for k,v in vopts.__dict__.items() if v is None] |
| 132 |
for k in empty_keys: |
| 133 |
del vopts.__dict__[k] |
| 134 |
|
| 135 |
x = FileIO(**vopts.__dict__) |
| 136 |
x.run() |