| 1 |
#!/usr/bin/env python3 |
| 2 |
#=============================================================================== |
| 3 |
# Copyright 2019 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 |
import os |
| 16 |
import errno |
| 17 |
import traceback |
| 18 |
import nfstest_config as c |
| 19 |
from nfstest.test_util import TestUtil |
| 20 |
|
| 21 |
# Module constants |
| 22 |
__author__ = "Jorge Mora (%s)" % c.NFSTEST_AUTHOR_EMAIL |
| 23 |
__copyright__ = "Copyright (C) 2019 NetApp, Inc." |
| 24 |
__license__ = "GPL v2" |
| 25 |
__version__ = "1.0" |
| 26 |
|
| 27 |
USAGE = """%prog --server <server> [options] |
| 28 |
|
| 29 |
NFS file compare |
| 30 |
================ |
| 31 |
Create a file using one set of NFS mount options and then verify the data |
| 32 |
is correct by reading the file using another set of NFS mount options. |
| 33 |
|
| 34 |
Examples: |
| 35 |
Use positional arguments with nfsversion=3 for second mount: |
| 36 |
%prog -s 192.168.0.2 -e /exports --nfsopts :::3 |
| 37 |
|
| 38 |
Use named arguments instead: |
| 39 |
%prog -s 192.168.0.2 -e /exports --nfsopts nfsversion=3 |
| 40 |
|
| 41 |
Notes: |
| 42 |
The user id in the local host must have access to run commands as root |
| 43 |
using the 'sudo' command without the need for a password.""" |
| 44 |
|
| 45 |
# Test script ID |
| 46 |
SCRIPT_ID = "FCMP" |
| 47 |
|
| 48 |
TESTNAMES = ["test01", "test02"] |
| 49 |
|
| 50 |
class FcmpTest(TestUtil): |
| 51 |
"""FcmpTest object |
| 52 |
|
| 53 |
FcmpTest() -> New test object |
| 54 |
|
| 55 |
Usage: |
| 56 |
x = FcmpTest(testnames=['test01']) |
| 57 |
|
| 58 |
# Run all the tests |
| 59 |
x.run_tests() |
| 60 |
x.exit() |
| 61 |
""" |
| 62 |
def __init__(self, **kwargs): |
| 63 |
"""Constructor |
| 64 |
|
| 65 |
Initialize object's private data. |
| 66 |
""" |
| 67 |
TestUtil.__init__(self, **kwargs) |
| 68 |
|
| 69 |
hmsg = "NFS options used for comparing test file. " \ |
| 70 |
"NFS mount definition is a list of arguments separated by a ':' " \ |
| 71 |
"given in the following order if positional arguments are used " \ |
| 72 |
"(see examples): " \ |
| 73 |
"::export:nfsversion:port:proto:sec" |
| 74 |
self.test_opgroup.add_option("--nfsopts", default=None, help=hmsg) |
| 75 |
hmsg = "NFS mount options used for comparing test file other " \ |
| 76 |
"than the ones specified in --nfsopts [default: '%default']" |
| 77 |
self.test_opgroup.add_option("--cmpopts", default="hard", help=hmsg) |
| 78 |
|
| 79 |
self.opts.version = "%prog " + __version__ |
| 80 |
self.opts.set_defaults(nfiles=0) |
| 81 |
self.opts.set_defaults(filesize="1m") |
| 82 |
self.opts.set_defaults(rsize="64k") |
| 83 |
self.opts.set_defaults(wsize="64k") |
| 84 |
self.opts.set_defaults(mtopts="hard") |
| 85 |
|
| 86 |
self.scan_options() |
| 87 |
|
| 88 |
# Disable createtraces option |
| 89 |
self.createtraces = False |
| 90 |
|
| 91 |
nfsopts_item = self.process_client_option("nfsopts", remote=False)[0] |
| 92 |
# Create a copy of the nfsopts item |
| 93 |
client_args = dict(nfsopts_item) |
| 94 |
# Create a Host object for the given client |
| 95 |
client_args.pop("client", "") |
| 96 |
client_args["mtpoint"] = self.mtpoint |
| 97 |
client_args["mtopts"] = self.cmpopts |
| 98 |
self.create_host("", **client_args) |
| 99 |
|
| 100 |
def test01_test(self): |
| 101 |
"""Verify data read from file is correct""" |
| 102 |
try: |
| 103 |
self.test_group("Verify data read from file is correct") |
| 104 |
self.test_info("Create file using second mount options") |
| 105 |
|
| 106 |
self.trace_start() |
| 107 |
self.clientobj.mount() |
| 108 |
self.mtdir = self.clientobj.mtdir |
| 109 |
try: |
| 110 |
fmsg = "" |
| 111 |
expr = True |
| 112 |
self.create_file(verbose=1, dlevels=["DBG2"]) |
| 113 |
except OSError as error: |
| 114 |
expr = False |
| 115 |
err = error.errno |
| 116 |
fmsg = ", got error [%s] %s" % (errno.errorcode.get(err,err), os.strerror(err)) |
| 117 |
self.test(expr, "File should be created", failmsg=fmsg) |
| 118 |
if not expr: |
| 119 |
return |
| 120 |
except Exception: |
| 121 |
self.test(False, traceback.format_exc()) |
| 122 |
return |
| 123 |
finally: |
| 124 |
self.clientobj.umount() |
| 125 |
|
| 126 |
try: |
| 127 |
self.test_info("Compare file's data using main mount options") |
| 128 |
self.mount() |
| 129 |
self.verify_file_data("Data read from file is correct") |
| 130 |
except Exception: |
| 131 |
self.test(False, traceback.format_exc()) |
| 132 |
finally: |
| 133 |
self.umount() |
| 134 |
self.trace_stop() |
| 135 |
|
| 136 |
def test02_test(self): |
| 137 |
"""Verify data written to file is correct""" |
| 138 |
try: |
| 139 |
self.test_group("Verify data written to file is correct") |
| 140 |
self.test_info("Create file using main mount options") |
| 141 |
|
| 142 |
self.trace_start() |
| 143 |
self.mount() |
| 144 |
|
| 145 |
try: |
| 146 |
fmsg = "" |
| 147 |
expr = True |
| 148 |
self.create_file(verbose=1, dlevels=["DBG2"]) |
| 149 |
except OSError as error: |
| 150 |
expr = False |
| 151 |
err = error.errno |
| 152 |
fmsg = ", got error [%s] %s" % (errno.errorcode.get(err,err), os.strerror(err)) |
| 153 |
self.test(expr, "File should be created", failmsg=fmsg) |
| 154 |
if not expr: |
| 155 |
return |
| 156 |
except Exception: |
| 157 |
self.test(False, traceback.format_exc()) |
| 158 |
return |
| 159 |
finally: |
| 160 |
self.umount() |
| 161 |
|
| 162 |
try: |
| 163 |
self.test_info("Compare file's data using second mount options") |
| 164 |
self.clientobj.mount() |
| 165 |
self.verify_file_data("Data written to file is correct") |
| 166 |
except Exception: |
| 167 |
self.test(False, traceback.format_exc()) |
| 168 |
finally: |
| 169 |
self.clientobj.umount() |
| 170 |
self.trace_stop() |
| 171 |
|
| 172 |
################################################################################ |
| 173 |
# Entry point |
| 174 |
x = FcmpTest(usage=USAGE, testnames=TESTNAMES, sid=SCRIPT_ID) |
| 175 |
|
| 176 |
try: |
| 177 |
# Run all the tests |
| 178 |
x.run_tests() |
| 179 |
except Exception: |
| 180 |
x.test(False, traceback.format_exc()) |
| 181 |
finally: |
| 182 |
x.cleanup() |
| 183 |
x.exit() |