-
Notifications
You must be signed in to change notification settings - Fork 2
/
nfs4st.py
executable file
·4889 lines (3886 loc) · 159 KB
/
nfs4st.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python2
# nfs4st.py - NFS4 server tester
#
# Written by Peter Åstrand <[email protected]>
# Copyright (C) 2001 Cendio Systems AB (http://www.cendio.se)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
# TODO:
#
# Extend unittest with warnings.
#
# Handle errors such as NFS4ERR_RESOURCE and NFS4ERR_DELAY.
#
# filehandles are split into eq. classes "valid filehandle" and
# "invalid filehandle". There should probably be a class "no filehandle" as
# well. Currently, "invalid filehandle" are tested by doing operations without
# filehandles.
#
# Add testing of \ to testSlash methods.
#
# More testing of strange attributes and handling of NFS4ERR_ATTRNOTSUPP;
# more fine-grained eqv.part of attribute masks.
#
# Nomenclature: Each test class is referred to as a "test suite". Each
# test* method is a "test case".
__pychecker__ = 'no-shadow'
import unittest
import time
import sys
import os
import rpc
from nfs4constants import *
from nfs4types import *
import nfs4lib
UID = GID = 0
# Global variables
host = None
port = None
transport = "udp"
prefix = None
class SkipException(Exception):
def __init__(self, msg):
self.msg = msg
def __str__(self):
return "Skipping test: %s" % self.msg
class PartialTestClient:
__pychecker__ = 'no-classattr' # this class is a mix-in
def lookup_all_objects(self):
"""Generate a list of lists with lookup operations for all types of objects"""
return self.lookup_objects(self.nfssuite.all_objects)
def lookup_objects(self, objects):
"""Generate a list of lists with lookup operations for objects"""
result = []
for object in objects:
result.append(self.lookup_path(object))
return result
def lookup_all_objects_and_sizes(self):
return self.lookup_objects_and_sizes(self.nfssuite.all_objects)
def lookup_objects_and_sizes(self, objects):
"""Generate a list of lists of lookup operations and object sizes"""
obj_sizes = []
for object in objects:
lookupops = self.lookup_path(object)
getattrop = self.getattr([FATTR4_SIZE])
operations = [self.nfssuite.putrootfhop] + lookupops
operations.append(getattrop)
res = self.nfssuite.do_compound(operations)
self.nfssuite.assert_OK(res)
obj = res.resarray[-1].arm.arm.obj_attributes
d = nfs4lib.fattr2dict(obj)
obj_sizes.append((lookupops, d["size"]))
return obj_sizes
def lookuplist2comps(self, list):
result = []
for op in list:
result.append(op.arm.objname)
return result
class UDPTestClient(PartialTestClient, nfs4lib.UDPNFS4Client):
def __init__(self, nfssuite, host, port=None, uid=None, gid=None):
self.nfssuite = nfssuite
kwargs = {}
if port: kwargs["port"] = port
if uid != None: kwargs["uid"] = uid
if gid != None: kwargs["gid"] = gid
nfs4lib.UDPNFS4Client.__init__(self, host, **kwargs)
class TCPTestClient(PartialTestClient, nfs4lib.TCPNFS4Client):
def __init__(self, nfssuite, host, port=None, uid=None, gid=None):
self.nfssuite = nfssuite
kwargs = {}
if port: kwargs["port"] = port
if uid != None: kwargs["uid"] = uid
if gid != None: kwargs["gid"] = gid
nfs4lib.TCPNFS4Client.__init__(self, host, **kwargs)
class NFSSuite(unittest.TestCase):
def __init__(self, methodName='runTest'):
unittest.TestCase.__init__(self, methodName)
self.obj_name = None
# Filename constants. Same order as in nfs_ftype4 enum.
self.regfile = nfs4lib.unixpath2comps(prefix + "/doc/README") # NF4REG
self.dirfile = nfs4lib.unixpath2comps(prefix + "/doc") # NF4DIR
self.blockfile = nfs4lib.unixpath2comps(prefix + "/dev/fd0") # NF4BLK
self.charfile = nfs4lib.unixpath2comps(prefix + "/dev/ttyS0") # NF4CHR
self.linkfile = nfs4lib.unixpath2comps(prefix + "/dev/floppy") # NF4LNK
self.socketfile = nfs4lib.unixpath2comps(prefix + "/dev/log") # NF4SOCK
self.fifofile = nfs4lib.unixpath2comps(prefix + "/dev/initctl") # NF4FIFO
# FIXME: Add NF4ATTRDIR and NF4NAMEDATTR types.
self.special_objects = [self.blockfile, self.charfile, self.socketfile, self.fifofile]
# Note named attribute dir or named attributes are not included in all_objects.
self.all_objects = self.special_objects + [self.regfile, self.dirfile, self.linkfile]
# FIXME: Add sample named attribute.
self.tmp_dir = nfs4lib.unixpath2comps(prefix + "/tmp")
# Some more filenames
self.hello_c = nfs4lib.unixpath2comps(prefix + "/src/hello.c")
self.dirsymlinkfile = nfs4lib.unixpath2comps(prefix + "/src/doc")
self.docporting = nfs4lib.unixpath2comps(prefix + "/doc/porting")
# Should not exist
self.vaporfilename = "vapor_object"
self.vaporfile = nfs4lib.unixpath2comps(self.vaporfilename)
# Not accessable
self.notaccessibledir = nfs4lib.unixpath2comps(prefix + "/private")
self.notaccessablefile = nfs4lib.unixpath2comps(prefix + "/private/info.txt")
def create_client(self, uid, gid):
if transport == "tcp":
ncl = TCPTestClient(self, host, port, uid, gid)
elif transport == "udp":
ncl = UDPTestClient(self, host, port, uid, gid)
else:
raise RuntimeError, "Invalid protocol"
return ncl
def connect(self):
self.ncl = self.create_client(UID, GID)
def failIfRaises(self, excClass, callableObj, *args, **kwargs):
"""Fail if exception of excClass or EOFError is raised"""
try:
return apply(callableObj, args, kwargs)
except excClass, e:
self.fail(e)
except EOFError, e:
self.fail("EOFError: short response")
return None
def assert_OK(self, res):
"""Assert result from compound call is NFS4_OK"""
self.assert_status(res, [NFS4_OK])
def assert_status(self, res, errors):
"""Assert result from compound call is any of the values in errors"""
if res.status in errors:
return
if res.resarray:
lastop = res.resarray[-1]
# res.status should be equal to lastop.arm.status
if res.status != lastop.arm.status:
e = nfs4lib.InvalidCompoundRes()
self.fail(e)
else:
e = nfs4lib.BadCompoundRes(lastop.resop, res.status)
self.fail(e)
else:
e = nfs4lib.EmptyBadCompoundRes(res.status)
self.fail(e)
def info_message(self, msg):
print >> sys.stderr, "\n " + msg + ", ",
def do_rpc(self, method, *args, **kwargs):
"""Call method. Handle all rpc.RPCExceptions as failures"""
return self.failIfRaises(rpc.RPCException, method, *args, **kwargs)
def do_compound(self, *args, **kwargs):
"""Call ncl.compound. Handle all rpc.RPCExceptions as failures
Uses self.ncl as default client, or other client specified via keyword
argument "ncl".
"""
ncl = kwargs.get("ncl")
if ncl:
del kwargs["ncl"]
else:
ncl = self.ncl
return self.do_rpc(ncl.compound, *args, **kwargs)
def setUp(self):
# Note: no network communication should be done in this method.
self.connect()
self.putrootfhop = self.ncl.putrootfh_op()
def init_connection(self, ncl=None):
if not ncl: ncl=self.ncl
self.failIfRaises(rpc.RPCException, ncl.init_connection)
def get_invalid_fh(self):
"""Return a (guessed) invalid filehandle"""
return nfs4lib.long2opaque(123456780, NFS4_FHSIZE/8)
def get_invalid_verifier(self):
"""Return a (guessed) invalid verifier"""
return nfs4lib.long2opaque(123456780, NFS4_VERIFIER_SIZE/8)
def get_zero_verifier(self):
"""Return a empty verifier"""
return nfs4lib.long2opaque(000000000, NFS4_VERIFIER_SIZE/8)
def get_invalid_clientid(self):
"""Return a (guessed) invalid clientid"""
return 0x1234567890L
def get_invalid_utf8strings(self):
"""Return a list of invalid ISO10646-UTF-8 strings"""
# FIXME: More invalid strings. Do equivalence partitioning on ISO10646-UTF8 definition
return ["\xc0\xc1",
"\xe0\x8a"]
def remove_object(self, name=None, directory=None):
"""Remove object in /tmp, if it exists. Return false on failure.
object defaults to self.obj_name
"""
if not name:
name = self.obj_name
if not directory:
directory = self.tmp_dir
lookup_dir_ops = self.ncl.lookup_path(directory)
operations = [self.ncl.putrootfh_op()] + lookup_dir_ops
operations.append(self.ncl.remove_op(name))
res = self.do_compound(operations)
status = res.status in [NFS4_OK, NFS4ERR_NOENT]
if not status:
self.info_message("Cannot prepare by removing object, skipping test")
return status
def clean_dir(self, directory):
"""Clean directory. Raises SkipException on failure"""
fh = self.do_rpc(self.ncl.do_getfh, directory)
entries = self.do_rpc(self.ncl.do_readdir, fh)
names = [entry.name for entry in entries]
for name in names:
lookup_dir_ops = self.ncl.lookup_path(directory)
operations = [self.ncl.putrootfh_op()] + lookup_dir_ops
operations.append(self.ncl.remove_op(name))
res = self.do_compound(operations)
if res.status == NFS4ERR_NOTEMPTY:
# Recursive deletion
self.clean_dir(directory + [name])
elif not res.status == NFS4_OK:
raise SkipException("Cannot clean directory %s" % directory)
# Verify that all files were removed
entries = self.do_rpc(self.ncl.do_readdir, fh)
if entries:
raise SkipException("Cannot clean directory %s" % directory)
def create_object(self, name=None, directory=None):
"""Create (dir) object in /tmp, if it does not exist. Return false on failure.
object defaults to self.obj_name
"""
# We create a directory, because it's simple.
if not name:
name = self.obj_name
if not directory:
directory = self.tmp_dir
lookup_dir_ops = self.ncl.lookup_path(directory)
operations = [self.putrootfhop] + lookup_dir_ops
objtype = createtype4(self.ncl, type=NF4DIR)
operations.append(self.ncl.create(objtype, name))
res = self.do_compound(operations)
status = res.status in [NFS4_OK, NFS4ERR_EXIST]
if not status:
self.info_message("Cannot prepare by creating object, skipping test")
return status
def make_sure_nonexistent(self, name=None, directory=None):
"""Make sure file does not exist. A READDIR is done. If file is not
found in READDIR, return. If file is found in READDIR results, try to
remove it.
Returns true if file did not exist or it was possible to remove it.
Returns false if file exists and it was not possible to remove it.
"""
if not name:
name = self.obj_name
if not directory:
directory = self.tmp_dir
fh = self.do_rpc(self.ncl.do_getfh, directory)
entries = self.do_rpc(self.ncl.do_readdir, fh)
names = [entry.name for entry in entries]
if name in names:
# Strange, this file already exists
# Try to remove it.
return self.remove_object(name, directory)
else:
return 1
def create_via_create(self, dstdir, filename):
operations = [self.putrootfhop] + self.ncl.lookup_path(self.tmp_dir)
objtype = createtype4(self.ncl, type=NF4DIR)
operations.append(self.ncl.create(objtype, filename))
return operations
def create_via_link(self, dstdir, filename):
operations = [self.putrootfhop]
# Lookup source and save FH
operations.extend(self.ncl.lookup_path(self.regfile))
operations.append(self.ncl.savefh_op())
# Lookup target directory
operations.append(self.putrootfhop)
operations.extend(self.ncl.lookup_path(self.tmp_dir))
operations.append(self.ncl.link_op(filename))
return operations
def create_via_open(self, dstdir, filename):
operations = [self.putrootfhop] + self.ncl.lookup_path(self.tmp_dir)
owner = self.ncl.get_open_owner(self.ncl.default_owner)
operations.append(self.ncl.open(file=filename,
seqid=owner.get_seqid(),
owner=owner.stateowner,
share_access=OPEN4_SHARE_ACCESS_WRITE,
opentype=OPEN4_CREATE))
return operations
def create_via_rename(self, dstdir, filename):
# Create a directory, so we have something to rename
oldname = "object1"
self.create_object(name=oldname)
operations = [self.putrootfhop]
# Lookup source and save FH
operations.extend(self.ncl.lookup_path(self.tmp_dir))
operations.append(self.ncl.savefh_op())
# Lookup target directory
operations.append(self.putrootfhop)
operations.extend(self.ncl.lookup_path(self.tmp_dir))
operations.append(self.ncl.rename_op(oldname, filename))
return operations
def accepted_filename(self, filename, remove_file=1, creator=None):
"""Returns true if file name could be created via creator.
creator defaults to create_via_open. Files are created in /tmp
"""
if not creator:
creator = self.create_via_open
operations = creator(self.tmp_dir, filename)
res = self.do_compound(operations)
# FIXME: Change to NFS4ERR_INVALIDNAME or what the error code will be called.
self.assert_status(res, [NFS4_OK, NFS4ERR_INVAL])
creatable = (res.status == NFS4_OK)
if creatable and remove_file:
# Ok, the file could be created.
# Be nice and remove created object
operations = [self.putrootfhop] + self.ncl.lookup_path(self.tmp_dir)
operations.append(self.ncl.remove_op(filename))
res = self.do_compound(operations)
# Don't care about return status
return creatable
def try_file_names(self, remove_files=1, creator=None):
""" Try all kinds of interesting file names and check if they are accepted
(via accepted_filename). Creates files in self.tmp_dir. The optional argument
remove_files can be unset to save created files.
Returns a tuple of (accepted_names, rejected_names)
Raises SkipException if temporary directory cannot be cleared. You
should catch it.
"""
if not creator:
creator = self.create_via_open
try_names = []
rejected_names = []
# aa<char>bb, with char 0-255
for i in range(0, 256):
ustr = "aa" + unichr(i) + "bb"
try_names.append(ustr.encode("utf8"))
# . and ..
try_names.append(".".encode("utf8"))
try_names.append("..".encode("utf8"))
# C:
try_names.append("C:".encode("utf8"))
# Ok, lets try all these names.
# Begin with cleaning /tmp
self.clean_dir(self.tmp_dir)
for filename in try_names[:]:
# Do not remove the file after creation
if not self.accepted_filename(filename, remove_file=remove_files,
creator=creator):
try_names.remove(filename)
rejected_names.append(filename)
return (try_names, rejected_names)
class CompoundSuite(NFSSuite):
"""Test COMPOUND procedure
Equivalence partitioning:
Input Condition: tag
Valid equivalence classes:
no tag (0)
tag (1)
Invalid equivalence classes:
-
Input Condition: minorversion
Valid equivalence classes:
supported minorversions(2)
Invalid equivalence classes:
unsupported minorversions(3)
Input Condition: argarray
Valid equivalence classes:
valid operations array(4)
Invalid equivalence classes:
invalid operations array(5)
"""
#
# Testcases covering valid equivalence classes.
#
def testZeroOps(self):
"""Test COMPOUND without operations
Covered valid equivalence classes: 0, 2, 4
"""
res = self.do_compound([])
self.assert_OK(res)
def testWithTag(self):
"""Simple COMPOUND with tag
Covered valid equivalence classes: 1, 2, 4
"""
res = self.do_compound([self.putrootfhop], tag="nfs4st.py test tag")
self.assert_OK(res)
#
# Testcases covering invalid equivalence classes.
#
def testInvalidMinor(self):
"""Test COMPOUND with invalid minor version
Covered invalid equivalence classes: 3
Comments: Also verifies that the result array after
NFS4ERR_MINOR_VERS_MISMATCH is empty.
"""
res = self.do_compound([self.putrootfhop], minorversion=0xFFFF)
self.assert_status(res, [NFS4ERR_MINOR_VERS_MISMATCH])
self.failIf(res.resarray, "expected empty result array after"\
"NFS4ERR_MINOR_VERS_MISMATCH")
def _verify_notsupp(self, opnum, valid_opnum_fn):
"""Verify COMPOUND result for undefined operations"""
# nfs4types.nfs_argop4 does not allow packing invalid operations.
class custom_nfs_argop4:
def __init__(self, ncl, argop):
self.ncl = ncl
self.packer = ncl.packer
self.unpacker = ncl.unpacker
self.argop = argop
def pack(self, dummy=None):
self.packer.pack_nfs_opnum4(self.argop)
op = custom_nfs_argop4(self.ncl, argop=opnum)
try:
# This *should* raise the BadCompoundRes exception.
res = self.ncl.compound([op])
# Ouch. This should not happen.
opnum = res.resarray[0].resop
self.fail("Expected BadCompoundRes exception. INTERNAL ERROR.")
except BadDiscriminant, e:
# This should happen.
self.failIf(not valid_opnum_fn(e.value),
"Expected result array with opnum %d, got %d" % (opnum, e.value))
# We have to do things a little by hand here
pos = self.ncl.unpacker.get_position()
data = self.ncl.unpacker.get_buffer()[pos:]
errcode = nfs4lib.opaque2long(data)
self.failIf(errcode != NFS4ERR_NOTSUPP,
"Expected NFS4ERR_NOTSUPP, got %d" % errcode)
except rpc.RPCException, e:
self.fail(e)
def testUndefinedOps(self):
"""COMPOUND with operations 0, 1, 2 and 1000 should return NFS4ERR_NOTSUPP
Covered invalid equivalence classes: 5
Comments: The server should return NFS4ERR_NOTSUPP for the
undefined operations 0, 1 and 2. Although operation 2 may be
introduced in later minor versions, the server should always
return NFS4ERR_NOTSUPP if the minorversion is 0.
"""
self._verify_notsupp(0, lambda x: x == 0)
self._verify_notsupp(1, lambda x: x == 1)
self._verify_notsupp(2, lambda x: x == 2)
# For unknown operations beyound OP_WRITE, the server should return
# the largest defined operation. It should at least be OP_WRITE!
self._verify_notsupp(1000, lambda x: x > OP_WRITE)
class AccessSuite(NFSSuite):
"""Test operation 3: ACCESS
Note: We do not examine if the "access" result actually corresponds to
the correct rights. This is hard since the rights for a object can
change at any time.
FIXME: Add attribute directory and named attribute testing.
Equivalence partitioning:
Input Condition: current filehandle
Valid equivalence classes:
link(1)
block(2)
char(3)
socket(4)
FIFO(5)
dir(6)
file(7)
Invalid equivalence classes:
invalid filehandle(8)
Input Condition: accessreq
Valid equivalence classes:
valid accessreq(9)
Invalid equivalence classes:
invalid accessreq(10)
"""
maxval = ACCESS4_DELETE + ACCESS4_EXECUTE + ACCESS4_EXTEND + ACCESS4_LOOKUP \
+ ACCESS4_MODIFY + ACCESS4_READ
def valid_access_ops(self):
result = []
for i in range(AccessSuite.maxval + 1):
result.append(self.ncl.access_op(i))
return result
def invalid_access_ops(self):
result = []
for i in [64, 65, 66, 127, 128, 129]:
result.append(self.ncl.access_op(i))
return result
#
# Testcases covering valid equivalence classes.
#
def testAllObjects(self):
"""ACCESS on all type of objects
Covered valid equivalence classes: 1, 2, 3, 4, 5, 6, 7, 9
"""
for lookupops in self.ncl.lookup_all_objects():
operations = [self.putrootfhop] + lookupops
operations.append(self.ncl.access_op(ACCESS4_READ))
res = self.do_compound(operations)
self.assert_OK(res)
def testDir(self):
"""All valid combinations of ACCESS arguments on directory
Covered valid equivalence classes: 6, 9
Comments: The ACCESS operation takes an uint32_t as an
argument, which is bitwised-or'd with zero or more of all
ACCESS4* constants. This test case tests all valid
combinations of these constants. It also verifies that the
server does not respond with a right in "access" but not in
"supported".
"""
for accessop in self.valid_access_ops():
res = self.do_compound([self.putrootfhop, accessop])
self.assert_OK(res)
supported = res.resarray[1].arm.arm.supported
access = res.resarray[1].arm.arm.access
# Server should not return an access bit if this bit is not in supported.
self.failIf(access > supported, "access is %d, but supported is %d" % (access, supported))
def testFile(self):
"""All valid combinations of ACCESS arguments on file
Covered valid equivalence classes: 7, 9
Comments: See testDir.
"""
lookupops = self.ncl.lookup_path(self.regfile)
for accessop in self.valid_access_ops():
operations = [self.putrootfhop] + lookupops
operations.append(accessop)
res = self.do_compound(operations)
self.assert_OK(res)
supported = res.resarray[-1].arm.arm.supported
access = res.resarray[-1].arm.arm.access
# Server should not return an access bit if this bit is not in supported.
self.failIf(access > supported, "access is %d, but supported is %d" % (access, supported))
#
# Testcases covering invalid equivalence classes.
#
def testWithoutFh(self):
"""ACCESS should return NFS4ERR_NOFILEHANDLE if called without filehandle.
Covered invalid equivalence classes: 8
"""
accessop = self.ncl.access_op(ACCESS4_READ)
res = self.do_compound([accessop])
self.assert_status(res, [NFS4ERR_NOFILEHANDLE])
def testInvalids(self):
"""ACCESS should fail on invalid arguments
Covered invalid equivalence classes: 10
Comments: ACCESS should return with NFS4ERR_INVAL if called
with an illegal access request (eg. an integer with bits set
that does not correspond to any ACCESS4* constant).
"""
for accessop in self.invalid_access_ops():
res = self.do_compound([self.putrootfhop, accessop])
self.assert_status(res, [NFS4ERR_INVAL])
#
# Extra tests
#
def testNoExecOnDir(self):
"""ACCESS4_EXECUTE should never be returned for directory
Extra test
Comments: ACCESS4_EXECUTE has no meaning for directories and
should not be returned in "access" or "supported".
"""
for accessop in self.valid_access_ops():
res = self.do_compound([self.putrootfhop, accessop])
self.assert_OK(res)
supported = res.resarray[1].arm.arm.supported
access = res.resarray[1].arm.arm.access
self.failIf(supported & ACCESS4_EXECUTE,
"server returned ACCESS4_EXECUTE for root dir (supported=%d)" % supported)
self.failIf(access & ACCESS4_EXECUTE,
"server returned ACCESS4_EXECUTE for root dir (access=%d)" % access)
## class CloseSuite(NFSSuite):
## """Test operation 4: CLOSE
## """
## # FIXME
## pass
class CommitSuite(NFSSuite):
"""Test operation 5: COMMIT
FIXME: Add attribute directory and named attribute testing.
Equivalence partitioning:
Input Condition: current filehandle
Valid equivalence classes:
file(1)
Invalid equivalence classes:
link(2)
special object(3)
dir(7)
invalid filehandle(8)
Input Condition: offset
Valid equivalence classes:
zero(9)
nonzero(10)
Invalid equivalence classes:
-
Input Condition: count
Valid equivalence classes:
zero(11)
nonzero(12)
Invalid equivalence classes:
-
Note: We do not examine the writeverifier in any way. It's hard
since it can change at any time.
"""
#
# Testcases covering valid equivalence classes.
#
def testOffsets(self):
"""Simple COMMIT on file with offset 0, 1 and 2**64 - 1
Covered valid equivalence classes: 1, 9, 10, 11
Comments: This test case tests boundary values for the offset
parameter in the COMMIT operation. All values are
legal. Tested values are 0, 1 and 2**64 - 1 (selected by BVA)
"""
lookupops = self.ncl.lookup_path(self.regfile)
# Offset = 0
operations = [self.putrootfhop] + lookupops
operations.append(self.ncl.commit_op(0, 0))
res = self.do_compound(operations)
self.assert_OK(res)
# offset = 1
operations = [self.putrootfhop] + lookupops
operations.append(self.ncl.commit_op(1, 0))
res = self.do_compound(operations)
self.assert_OK(res)
# offset = 2**64 - 1
operations = [self.putrootfhop] + lookupops
operations.append(self.ncl.commit_op(0xffffffffffffffffL, 0))
res = self.do_compound(operations)
self.assert_OK(res)
def _testWithCount(self, count):
lookupops = self.ncl.lookup_path(self.regfile)
operations = [self.putrootfhop] + lookupops
operations.append(self.ncl.commit_op(0, count))
res = self.do_compound(operations)
self.assert_OK(res)
def testCounts(self):
"""COMMIT on file with count 0, 1 and 2**32 - 1
Covered valid equivalence classes: 1, 9, 11, 12
This test case tests boundary values for the count parameter
in the COMMIT operation. All values are legal. Tested values
are 0, 1 and 2**32 - 1 (selected by BVA)
"""
# count = 0
self._testWithCount(0)
# count = 1
self._testWithCount(1)
# count = 2**32 - 1
self._testWithCount(0xffffffffL)
#
# Testcases covering invalid equivalence classes
#
def _testOnObj(self, obj, expected_response):
lookupops = self.ncl.lookup_path(obj)
operations = [self.putrootfhop] + lookupops
operations.append(self.ncl.commit_op(0, 0))
res = self.do_compound(operations)
self.assert_status(res, [expected_response])
def testOnLink(self):
"""COMMIT should fail with NFS4ERR_SYMLINK on links
Covered invalid equivalence classes: 2
"""
self._testOnObj(self.linkfile, NFS4ERR_SYMLINK)
def testOnSpecials(self):
"""COMMIT on special objects should fail with NFS4ERR_INVAL
Covered invalid equivalence classes: 3
"""
for obj in self.special_objects:
self._testOnObj(obj, NFS4ERR_INVAL)
def testOnDir(self):
"""COMMIT should fail with NFS4ERR_ISDIR on directories
Covered invalid equivalence classes: 7
"""
self._testOnObj(self.dirfile, NFS4ERR_ISDIR)
def testWithoutFh(self):
"""COMMIT should return NFS4ERR_NOFILEHANDLE if called without filehandle.
Covered invalid equivalence classes: 8
"""
commitop = self.ncl.commit_op(0, 0)
res = self.do_compound([commitop])
self.assert_status(res, [NFS4ERR_NOFILEHANDLE])
#
# Extra tests
#
def testOverflow(self):
"""COMMIT on file with offset+count >= 2**64 should fail
Extra test
Comments: If the COMMIT operation is called with an offset
plus count that is larger than 2**64, the server should return
NFS4ERR_INVAL
"""
lookupops = self.ncl.lookup_path(self.regfile)
operations = [self.putrootfhop] + lookupops
operations.append(self.ncl.commit_op(-1, -1))
res = self.do_compound(operations)
self.assert_status(res, [NFS4ERR_INVAL])
class CreateSuite(NFSSuite):
"""Test operation 6: CREATE
FIXME: Add attribute directory and named attribute testing.
Equivalence partitioning:
Input Condition: current filehandle
Valid equivalence classes:
dir(10)
Invalid equivalence classes:
not dir(11)
no filehandle(12)
Input Condition: type
Valid equivalence classes:
link(20)
blockdev(21)
chardev(22)
socket(23)
FIFO(24)
directory(25)
Invalid equivalence classes:
regular file(26)
Input Condition: name
Valid equivalence classes:
legal name(30)
Invalid equivalence classes:
zero length(31)
Input Condition: fattr.attrmask
Valid equivalence classes:
valid attrmask(40)
Invalid equivalence classes:
invalid attrmask(41) (FATTR4_*_SET)
Input Condition: fattr.attr_vals
Valid equivalence classes:
valid attribute value(50)
Invalid equivalence classes:
valid attribute value(51)
"""
__pychecker__ = 'no-classattr'
def setUp(self):
NFSSuite.setUp(self)
self.obj_name = "object1"
self.lookup_dir_ops = self.ncl.lookup_path(self.tmp_dir)
#
# Testcases covering valid equivalence classes.
#
def testLink(self):
"""CREATE (symbolic) link
Covered valid equivalence classes: 10, 20, 30, 40, 50
"""
if not self.remove_object(): return
operations = [self.putrootfhop] + self.lookup_dir_ops
objtype = createtype4(self.ncl, type=NF4LNK, linkdata="/etc/X11")
createop = self.ncl.create(objtype, self.obj_name)
operations.append(createop)
res = self.do_compound(operations)
if res.status == NFS4ERR_BADTYPE:
self.info_message("links not supported")
self.assert_status(res, [NFS4_OK, NFS4ERR_BADTYPE])
def testBlock(self):
"""CREATE a block device
Covered valid equivalence classes: 10, 21, 30, 40, 50
"""
if not self.remove_object(): return
operations = [self.putrootfhop] + self.lookup_dir_ops
devdata = specdata4(self.ncl, 1, 2)
objtype = createtype4(self.ncl, type=NF4BLK, devdata=devdata)
createop = self.ncl.create(objtype, self.obj_name)
operations.append(createop)
# FIXME: Maybe try to create block and character devices as root.
res = self.do_compound(operations)
if res.status == NFS4ERR_BADTYPE:
self.info_message("blocks devices not supported")
elif res.status == NFS4ERR_PERM:
self.info_message("not permitted")
else:
self.assert_status(res, [NFS4_OK, NFS4ERR_BADTYPE, NFS4ERR_PERM])
def testChar(self):
"""CREATE a character device
Covered valid equivalence classes: 10, 22, 30, 40, 50
"""
if not self.remove_object(): return
operations = [self.putrootfhop] + self.lookup_dir_ops
devdata = specdata4(self.ncl, 1, 2)
objtype = createtype4(self.ncl, type=NF4CHR, devdata=devdata)
createop = self.ncl.create(objtype, self.obj_name)
operations.append(createop)
res = self.do_compound(operations)
if res.status == NFS4ERR_BADTYPE:
self.info_message("character devices not supported")
elif res.status == NFS4ERR_PERM:
self.info_message("not permitted")
else:
self.assert_status(res, [NFS4_OK, NFS4ERR_BADTYPE, NFS4ERR_PERM])
def testSocket(self):
"""CREATE a socket
Covered valid equivalence classes: 10, 23, 30, 40, 50
"""
if not self.remove_object(): return
operations = [self.putrootfhop] + self.lookup_dir_ops
objtype = createtype4(self.ncl, type=NF4SOCK)
createop = self.ncl.create(objtype, self.obj_name)
operations.append(createop)