| 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 |
import os |
| 16 |
import inspect |
| 17 |
import traceback |
| 18 |
import nfstest_config as c |
| 19 |
from nfstest.test_util import TestUtil |
| 20 |
import packet.nfs.nfs3_const as nfs3_const |
| 21 |
import packet.nfs.nfs4_const as nfs4_const |
| 22 |
|
| 23 |
# Module constants |
| 24 |
__author__ = "Jorge Mora (%s)" % c.NFSTEST_AUTHOR_EMAIL |
| 25 |
__copyright__ = "Copyright (C) 2014 NetApp, Inc." |
| 26 |
__license__ = "GPL v2" |
| 27 |
__version__ = "1.1" |
| 28 |
|
| 29 |
USAGE = """%prog --server <server> [options] |
| 30 |
|
| 31 |
NFS interoperability tests |
| 32 |
========================== |
| 33 |
Basic interoperability tests verify that a file written with different |
| 34 |
versions of NFS is written correctly. The contents of the file are verified |
| 35 |
by reading the file back using one of the NFS versions. |
| 36 |
|
| 37 |
The tests append different data from different versions of NFS one at a |
| 38 |
time then reads the contents of the file to verify it was written |
| 39 |
correctly. This is done twice for each test: |
| 40 |
|
| 41 |
1) Mount different versions of NFS (NFSv3, NFSv4, NFSv4.1) |
| 42 |
2) Create empty file |
| 43 |
3) Append data using NFSv3 |
| 44 |
4) Append data using NFSv4 |
| 45 |
5) Append data using NFSv4.1 |
| 46 |
6) Read file and verify contents are correct |
| 47 |
7) Append data using NFSv3 |
| 48 |
8) Append data using NFSv4 |
| 49 |
9) Append data using NFSv4.1 |
| 50 |
10) Read file and verify contents are correct""" |
| 51 |
|
| 52 |
# Test script ID |
| 53 |
SCRIPT_ID = "INTEROP" |
| 54 |
|
| 55 |
TESTNAMES = [] |
| 56 |
for index in range(1,46): |
| 57 |
TESTNAMES.append("test%02d" % index) |
| 58 |
|
| 59 |
class InteropTest(TestUtil): |
| 60 |
"""InteropTest object |
| 61 |
|
| 62 |
InteropTest() -> New test object |
| 63 |
|
| 64 |
Usage: |
| 65 |
x = InteropTest(testnames=['test01']) |
| 66 |
|
| 67 |
# Run all the tests |
| 68 |
x.run_tests() |
| 69 |
x.exit() |
| 70 |
""" |
| 71 |
def __init__(self, **kwargs): |
| 72 |
"""Constructor |
| 73 |
|
| 74 |
Initialize object's private data. |
| 75 |
""" |
| 76 |
TestUtil.__init__(self, **kwargs) |
| 77 |
self.opts.version = "%prog " + __version__ |
| 78 |
|
| 79 |
# Options specific for this test script |
| 80 |
hmsg = "Size of data to be written by each version of NFS [default: '%default']" |
| 81 |
self.test_opgroup.add_option("--datasize", type="int", default=10, help=hmsg) |
| 82 |
self.scan_options() |
| 83 |
# NFS version mount option for NFSv4 |
| 84 |
self.nfsvers4 = 4.0 |
| 85 |
# Disable createtraces option |
| 86 |
self.createtraces = False |
| 87 |
|
| 88 |
def setup(self, **kwargs): |
| 89 |
"""Setup test environment""" |
| 90 |
self.umount() |
| 91 |
try: |
| 92 |
self.dprint('DBG4', "Try NFSv4 mount using vers=4.0") |
| 93 |
self.mount(nfsversion=4.0) |
| 94 |
except: |
| 95 |
if self.perror.find("incorrect mount option") >= 0: |
| 96 |
self.dprint('DBG4', "NFSv4 mount using vers=4.0 is not supported, using vers=4 instead") |
| 97 |
self.mount(nfsversion=4) |
| 98 |
self.nfsvers4 = 4 |
| 99 |
# Get block size for mounted volume |
| 100 |
self.statvfs = os.statvfs(self.mtdir) |
| 101 |
super(InteropTest, self).setup(**kwargs) |
| 102 |
self.umount() |
| 103 |
|
| 104 |
def do_read(self, absfile, version): |
| 105 |
"""Read contents of given file""" |
| 106 |
self.dprint('DBG1', "Read contents of %s using NFS%s" % (absfile, version)) |
| 107 |
with open(absfile, "rb") as fd: |
| 108 |
data = fd.read() |
| 109 |
return data |
| 110 |
|
| 111 |
def do_write(self, absfile, data, version): |
| 112 |
"""Append data to given file""" |
| 113 |
self.dprint('DBG1', "Append data to %s using NFS%s" % (absfile, version)) |
| 114 |
fd = os.open(absfile, os.O_WRONLY|os.O_APPEND) |
| 115 |
self.dprint('DBG2', " Written data: %r" % data.decode()) |
| 116 |
os.write(fd, data) |
| 117 |
os.close(fd) |
| 118 |
self.write_data += data |
| 119 |
|
| 120 |
def do_test(self, version, vlist): |
| 121 |
"""NFS interoperability tests""" |
| 122 |
self.test_group(getattr(self, inspect.stack()[1][3]).__doc__) |
| 123 |
ofd = None |
| 124 |
# Write data for each version of NFS |
| 125 |
data_map = { |
| 126 |
"v3" : {"args":{"nfsversion":3, "mtpoint":self.mtpoint+"_v30"}, |
| 127 |
"data":self.data_pattern(0, self.datasize, b"A")}, |
| 128 |
"v4" : {"args":{"nfsversion":self.nfsvers4, "mtpoint":self.mtpoint+"_v40"}, |
| 129 |
"data":self.data_pattern(0, self.datasize, b"B")}, |
| 130 |
"v4.1" : {"args":{"nfsversion":4.1, "mtpoint":self.mtpoint+"_v41"}, |
| 131 |
"data":self.data_pattern(0, self.datasize, b"C")}, |
| 132 |
} |
| 133 |
# Initialize expected data to be read |
| 134 |
self.write_data = b"" |
| 135 |
|
| 136 |
try: |
| 137 |
# Ignore option --nfsversion and use the version given for the |
| 138 |
# specific test instead. This mount is used for reading the file |
| 139 |
# after data has been written by other NFS versions. |
| 140 |
mtargs = dict(data_map[version]["args"]) |
| 141 |
mtargs["mtpoint"] = self.mtpoint |
| 142 |
self.trace_start() |
| 143 |
self.mount(**mtargs) |
| 144 |
|
| 145 |
self.set_nfserr_list( |
| 146 |
nfs3list=[nfs3_const.NFS3ERR_NOENT, nfs3_const.NFS3ERR_JUKEBOX], |
| 147 |
nfs4list=[nfs4_const.NFS4ERR_NOENT, nfs4_const.NFS4ERR_DELAY], |
| 148 |
) |
| 149 |
|
| 150 |
# Get a new file name |
| 151 |
testfile = self.get_filename() |
| 152 |
|
| 153 |
# Create a Host object for every version of NFS to use to append |
| 154 |
# data and create a list of arguments for each write |
| 155 |
darray = [] |
| 156 |
for ver in vlist: |
| 157 |
hostobj = self.create_host("", **data_map[ver]["args"]) |
| 158 |
hostobj.mount() |
| 159 |
absfile = os.path.join(hostobj.mtdir, testfile) |
| 160 |
darray.append([absfile, data_map[ver]["data"], ver]) |
| 161 |
|
| 162 |
if version != "v3": |
| 163 |
# Open a different file to make sure the a READ delegation |
| 164 |
# is granted for the file under test |
| 165 |
rd_absfile = self.abspath(self.files[0]) |
| 166 |
self.dprint('DBG4', "Opening file %s using NFS%s so owner sticks around" % (rd_absfile, version)) |
| 167 |
ofd = os.open(rd_absfile, os.O_RDONLY) |
| 168 |
|
| 169 |
self.dprint('DBG1', "Create empty file %s using NFS%s" % (self.absfile, version)) |
| 170 |
fd = os.open(self.absfile, os.O_WRONLY|os.O_CREAT) |
| 171 |
os.close(fd) |
| 172 |
|
| 173 |
# Append data for all versions of NFS given |
| 174 |
for item in darray: |
| 175 |
self.do_write(*item) |
| 176 |
|
| 177 |
# Read data from a different mount point |
| 178 |
read_data = self.do_read(self.absfile, version) |
| 179 |
expr = read_data == self.write_data |
| 180 |
self.test(expr, "Read data using NFS%s should be correct" % version) |
| 181 |
if not expr: |
| 182 |
self.dprint('DBG2', "Expected data: %s" % self.write_data) |
| 183 |
self.dprint('DBG2', "Read data: %s" % read_data) |
| 184 |
|
| 185 |
# Append data for all versions of NFS given |
| 186 |
for item in darray: |
| 187 |
self.do_write(*item) |
| 188 |
|
| 189 |
# Read data from a different mount point |
| 190 |
read_data = self.do_read(self.absfile, version) |
| 191 |
expr = read_data == self.write_data |
| 192 |
self.test(expr, "Read data using NFS%s should be correct" % version) |
| 193 |
if not expr: |
| 194 |
self.dprint('DBG2', "Expected data: %s" % self.write_data) |
| 195 |
self.dprint('DBG2', "Read data: %s" % read_data) |
| 196 |
except Exception: |
| 197 |
self.test(False, traceback.format_exc()) |
| 198 |
finally: |
| 199 |
if ofd is not None: |
| 200 |
os.close(ofd) |
| 201 |
# Umount and destroy Host objects |
| 202 |
while self.clients: |
| 203 |
clientobj = self.clients.pop() |
| 204 |
clientobj.cleanup() |
| 205 |
self.umount() |
| 206 |
self.trace_stop() |
| 207 |
self.trace_open() |
| 208 |
self.pktt.close() |
| 209 |
|
| 210 |
def test01_test(self): |
| 211 |
"""Verify appending data with NFSv3 is correctly read using NFSv3""" |
| 212 |
self.do_test("v3", ["v3"]) |
| 213 |
|
| 214 |
def test02_test(self): |
| 215 |
"""Verify appending data with NFSv3 is correctly read using NFSv4""" |
| 216 |
self.do_test("v4", ["v3"]) |
| 217 |
|
| 218 |
def test03_test(self): |
| 219 |
"""Verify appending data with NFSv3 is correctly read using NFSv4.1""" |
| 220 |
self.do_test("v4.1", ["v3"]) |
| 221 |
|
| 222 |
def test04_test(self): |
| 223 |
"""Verify appending data with NFSv4 is correctly read using NFSv3""" |
| 224 |
self.do_test("v3", ["v4"]) |
| 225 |
|
| 226 |
def test05_test(self): |
| 227 |
"""Verify appending data with NFSv4 is correctly read using NFSv4""" |
| 228 |
self.do_test("v4", ["v4"]) |
| 229 |
|
| 230 |
def test06_test(self): |
| 231 |
"""Verify appending data with NFSv4 is correctly read using NFSv4.1""" |
| 232 |
self.do_test("v4.1", ["v4"]) |
| 233 |
|
| 234 |
def test07_test(self): |
| 235 |
"""Verify appending data with NFSv4.1 is correctly read using NFSv3""" |
| 236 |
self.do_test("v3", ["v4.1"]) |
| 237 |
|
| 238 |
def test08_test(self): |
| 239 |
"""Verify appending data with NFSv4.1 is correctly read using NFSv4""" |
| 240 |
self.do_test("v4", ["v4.1"]) |
| 241 |
|
| 242 |
def test09_test(self): |
| 243 |
"""Verify appending data with NFSv4.1 is correctly read using NFSv4.1""" |
| 244 |
self.do_test("v4.1", ["v4.1"]) |
| 245 |
|
| 246 |
def test10_test(self): |
| 247 |
"""Verify appending data with NFSv3 and NFSv4 is correctly read using NFSv3""" |
| 248 |
self.do_test("v3", ["v3", "v4"]) |
| 249 |
|
| 250 |
def test11_test(self): |
| 251 |
"""Verify appending data with NFSv3 and NFSv4 is correctly read using NFSv4""" |
| 252 |
self.do_test("v4", ["v3", "v4"]) |
| 253 |
|
| 254 |
def test12_test(self): |
| 255 |
"""Verify appending data with NFSv3 and NFSv4 is correctly read using NFSv4.1""" |
| 256 |
self.do_test("v4.1", ["v3", "v4"]) |
| 257 |
|
| 258 |
def test13_test(self): |
| 259 |
"""Verify appending data with NFSv4 and NFSv3 is correctly read using NFSv3""" |
| 260 |
self.do_test("v3", ["v4", "v3"]) |
| 261 |
|
| 262 |
def test14_test(self): |
| 263 |
"""Verify appending data with NFSv4 and NFSv3 is correctly read using NFSv4""" |
| 264 |
self.do_test("v4", ["v4", "v3"]) |
| 265 |
|
| 266 |
def test15_test(self): |
| 267 |
"""Verify appending data with NFSv4 and NFSv3 is correctly read using NFSv4.1""" |
| 268 |
self.do_test("v4.1", ["v4", "v3"]) |
| 269 |
|
| 270 |
def test16_test(self): |
| 271 |
"""Verify appending data with NFSv3 and NFSv4.1 is correctly read using NFSv3""" |
| 272 |
self.do_test("v3", ["v3", "v4.1"]) |
| 273 |
|
| 274 |
def test17_test(self): |
| 275 |
"""Verify appending data with NFSv3 and NFSv4.1 is correctly read using NFSv4""" |
| 276 |
self.do_test("v4", ["v3", "v4.1"]) |
| 277 |
|
| 278 |
def test18_test(self): |
| 279 |
"""Verify appending data with NFSv3 and NFSv4.1 is correctly read using NFSv4.1""" |
| 280 |
self.do_test("v4.1", ["v3", "v4.1"]) |
| 281 |
|
| 282 |
def test19_test(self): |
| 283 |
"""Verify appending data with NFSv4.1 and NFSv3 is correctly read using NFSv3""" |
| 284 |
self.do_test("v3", ["v4.1", "v3"]) |
| 285 |
|
| 286 |
def test20_test(self): |
| 287 |
"""Verify appending data with NFSv4.1 and NFSv3 is correctly read using NFSv4""" |
| 288 |
self.do_test("v4", ["v4.1", "v3"]) |
| 289 |
|
| 290 |
def test21_test(self): |
| 291 |
"""Verify appending data with NFSv4.1 and NFSv3 is correctly read using NFSv4.1""" |
| 292 |
self.do_test("v4.1", ["v4.1", "v3"]) |
| 293 |
|
| 294 |
def test22_test(self): |
| 295 |
"""Verify appending data with NFSv4 and NFSv4.1 is correctly read using NFSv3""" |
| 296 |
self.do_test("v3", ["v4", "v4.1"]) |
| 297 |
|
| 298 |
def test23_test(self): |
| 299 |
"""Verify appending data with NFSv4 and NFSv4.1 is correctly read using NFSv4""" |
| 300 |
self.do_test("v4", ["v4", "v4.1"]) |
| 301 |
|
| 302 |
def test24_test(self): |
| 303 |
"""Verify appending data with NFSv4 and NFSv4.1 is correctly read using NFSv4.1""" |
| 304 |
self.do_test("v4.1", ["v4", "v4.1"]) |
| 305 |
|
| 306 |
def test25_test(self): |
| 307 |
"""Verify appending data with NFSv4.1 and NFSv4 is correctly read using NFSv3""" |
| 308 |
self.do_test("v3", ["v4.1", "v4"]) |
| 309 |
|
| 310 |
def test26_test(self): |
| 311 |
"""Verify appending data with NFSv4.1 and NFSv4 is correctly read using NFSv4""" |
| 312 |
self.do_test("v4", ["v4.1", "v4"]) |
| 313 |
|
| 314 |
def test27_test(self): |
| 315 |
"""Verify appending data with NFSv4.1 and NFSv4 is correctly read using NFSv4.1""" |
| 316 |
self.do_test("v4.1", ["v4.1", "v4"]) |
| 317 |
|
| 318 |
def test28_test(self): |
| 319 |
"""Verify appending data with NFSv3, NFSv4 and NFSv4.1 is correctly read using NFSv3""" |
| 320 |
self.do_test("v3", ["v3", "v4", "v4.1"]) |
| 321 |
|
| 322 |
def test29_test(self): |
| 323 |
"""Verify appending data with NFSv3, NFSv4 and NFSv4.1 is correctly read using NFSv4""" |
| 324 |
self.do_test("v4", ["v3", "v4", "v4.1"]) |
| 325 |
|
| 326 |
def test30_test(self): |
| 327 |
"""Verify appending data with NFSv3, NFSv4 and NFSv4.1 is correctly read using NFSv4.1""" |
| 328 |
self.do_test("v4.1", ["v3", "v4", "v4.1"]) |
| 329 |
|
| 330 |
def test31_test(self): |
| 331 |
"""Verify appending data with NFSv4, NFSv3 and NFSv4.1 is correctly read using NFSv3""" |
| 332 |
self.do_test("v3", ["v4", "v3", "v4.1"]) |
| 333 |
|
| 334 |
def test32_test(self): |
| 335 |
"""Verify appending data with NFSv4, NFSv3 and NFSv4.1 is correctly read using NFSv4""" |
| 336 |
self.do_test("v4", ["v4", "v3", "v4.1"]) |
| 337 |
|
| 338 |
def test33_test(self): |
| 339 |
"""Verify appending data with NFSv4, NFSv3 and NFSv4.1 is correctly read using NFSv4.1""" |
| 340 |
self.do_test("v4.1", ["v4", "v3", "v4.1"]) |
| 341 |
|
| 342 |
def test34_test(self): |
| 343 |
"""Verify appending data with NFSv4, NFSv4.1 and NFSv3 is correctly read using NFSv3""" |
| 344 |
self.do_test("v3", ["v4", "v4.1", "v3"]) |
| 345 |
|
| 346 |
def test35_test(self): |
| 347 |
"""Verify appending data with NFSv4, NFSv4.1 and NFSv3 is correctly read using NFSv4""" |
| 348 |
self.do_test("v4", ["v4", "v4.1", "v3"]) |
| 349 |
|
| 350 |
def test36_test(self): |
| 351 |
"""Verify appending data with NFSv4, NFSv4.1 and NFSv3 is correctly read using NFSv4.1""" |
| 352 |
self.do_test("v4.1", ["v4", "v4.1", "v3"]) |
| 353 |
|
| 354 |
def test37_test(self): |
| 355 |
"""Verify appending data with NFSv4.1, NFSv4 and NFSv3 is correctly read using NFSv3""" |
| 356 |
self.do_test("v3", ["v4.1", "v4", "v3"]) |
| 357 |
|
| 358 |
def test38_test(self): |
| 359 |
"""Verify appending data with NFSv4.1, NFSv4 and NFSv3 is correctly read using NFSv4""" |
| 360 |
self.do_test("v4", ["v4.1", "v4", "v3"]) |
| 361 |
|
| 362 |
def test39_test(self): |
| 363 |
"""Verify appending data with NFSv4.1, NFSv4 and NFSv3 is correctly read using NFSv4.1""" |
| 364 |
self.do_test("v4.1", ["v4.1", "v4", "v3"]) |
| 365 |
|
| 366 |
def test40_test(self): |
| 367 |
"""Verify appending data with NFSv4.1, NFSv3 and NFSv4 is correctly read using NFSv3""" |
| 368 |
self.do_test("v3", ["v4.1", "v3", "v4"]) |
| 369 |
|
| 370 |
def test41_test(self): |
| 371 |
"""Verify appending data with NFSv4.1, NFSv3 and NFSv4 is correctly read using NFSv4""" |
| 372 |
self.do_test("v4", ["v4.1", "v3", "v4"]) |
| 373 |
|
| 374 |
def test42_test(self): |
| 375 |
"""Verify appending data with NFSv4.1, NFSv3 and NFSv4 is correctly read using NFSv4.1""" |
| 376 |
self.do_test("v4.1", ["v4.1", "v3", "v4"]) |
| 377 |
|
| 378 |
def test43_test(self): |
| 379 |
"""Verify appending data with NFSv3, NFSv4.1 and NFSv4 is correctly read using NFSv3""" |
| 380 |
self.do_test("v3", ["v3", "v4.1", "v4"]) |
| 381 |
|
| 382 |
def test44_test(self): |
| 383 |
"""Verify appending data with NFSv3, NFSv4.1 and NFSv4 is correctly read using NFSv4""" |
| 384 |
self.do_test("v4", ["v3", "v4.1", "v4"]) |
| 385 |
|
| 386 |
def test45_test(self): |
| 387 |
"""Verify appending data with NFSv3, NFSv4.1 and NFSv4 is correctly read using NFSv4.1""" |
| 388 |
self.do_test("v4.1", ["v3", "v4.1", "v4"]) |
| 389 |
|
| 390 |
################################################################################ |
| 391 |
# Entry point |
| 392 |
x = InteropTest(usage=USAGE, testnames=TESTNAMES, sid=SCRIPT_ID) |
| 393 |
|
| 394 |
try: |
| 395 |
x.setup(nfiles=1) |
| 396 |
|
| 397 |
# Run all the tests |
| 398 |
x.run_tests() |
| 399 |
except Exception: |
| 400 |
x.test(False, traceback.format_exc()) |
| 401 |
finally: |
| 402 |
x.cleanup() |
| 403 |
x.exit() |