Esempio n. 1
0
def _compare(t, entries, expect, attrlist=[]):
    names = [e.name for e in entries]
    names.sort()
    expect.sort()
    if names != expect:
        t.fail("Expected READDIR to return %s, instead got %s" %
               (expect, names))
    for e in entries:
        for attr in attrlist:
            if attr not in e.attrdict:
                t.fail("Requested attribute %s not returned for %s" %
                       (get_attr_name(attr), repr(e.name)))
        for attr in e.attrdict:
            if attr not in attrlist:
                t.fail("Unrequested attribute %s returned for %s" %
                       (get_attr_name(attr), repr(e.name)))
Esempio n. 2
0
def _compare(t, entries, expect, attrlist=[]):
    names = [e.name for e in entries]
    names.sort()
    expect.sort()
    if names != expect:
        t.fail("Expected READDIR to return %s, instead got %s" %
               (expect, names))
    for e in entries:
        for attr in attrlist:
            if attr not in e.attrdict:
                t.fail("Requested attribute %s not returned for %s" %
                       (get_attr_name(attr), repr(e.name)))
        for attr in e.attrdict:
            if attr not in attrlist:
                t.fail("Unrequested attribute %s returned for %s" %
                       (get_attr_name(attr), repr(e.name)))
Esempio n. 3
0
 def op_getattr(self, op):
     print "  ATTRMASK: %s" % [nfs4lib.get_attr_name(bit) for bit in nfs4lib.bitmap2list(op.opgetattr.attr_request)]
     try:
         if not self.curr_fh:
             return simple_error(NFS4ERR_NOFILEHANDLE)
         attrs = nfs4lib.bitmap2list(op.opgetattr.attr_request)
         attrvals = self.curr_fh.get_attributes(attrs)
     except NFS4Error, e:
         return simple_error(e.code)
Esempio n. 4
0
def _try_mandatory(t, env, path):
    c = env.c1
    mandatory = [attr.bitnum for attr in env.attr_info if attr.mandatory]
    ops = c.use_obj(path)
    ops += [c.getattr(mandatory)]
    res = c.compound(ops)
    check(res)
    attrs = res.resarray[-1].obj_attributes
    unsupp = [get_attr_name(a) for a in mandatory if a not in attrs]
    if unsupp:
        t.fail("Mandatory attribute(s) %s not supported" % 'and'.join(unsupp))
Esempio n. 5
0
def _try_mandatory(t, env, path):
    c = env.c1
    mandatory = [attr.bitnum for attr in env.attr_info if attr.mandatory]
    ops = c.use_obj(path)
    ops += [c.getattr(mandatory)]
    res = c.compound(ops)
    check(res)
    attrs = res.resarray[-1].obj_attributes
    unsupp = [get_attr_name(a) for a in mandatory if a not in attrs]
    if unsupp:
        t.fail("Mandatory attribute(s) %s not supported" % 'and'.join(unsupp))
Esempio n. 6
0
 def op_getattr(self, op):
     print "  ATTRMASK: %s" % [
         nfs4lib.get_attr_name(bit)
         for bit in nfs4lib.bitmap2list(op.opgetattr.attr_request)
     ]
     try:
         if not self.curr_fh:
             return simple_error(NFS4ERR_NOFILEHANDLE)
         attrs = nfs4lib.bitmap2list(op.opgetattr.attr_request)
         attrvals = self.curr_fh.get_attributes(attrs)
     except NFS4Error, e:
         return simple_error(e.code)
Esempio n. 7
0
 def op_readdir(self, op):
     # We ignore dircount hint
     print "  CURRENT FILEHANDLE %s" % repr(self.curr_fh)
     print "  COOKIEVERF: %s, %s" % (repr(
         op.opreaddir.cookieverf), repr(op.opreaddir.cookie))
     print "  DIRCOUNT: %d MAXCOUNT: %d" % (op.opreaddir.dircount,
                                            op.opreaddir.maxcount)
     print "  ATTRMASK: %s" % [
         nfs4lib.get_attr_name(bit)
         for bit in nfs4lib.bitmap2list(op.opreaddir.attr_request)
     ]
     if not self.curr_fh:
         return simple_error(NFS4ERR_NOFILEHANDLE)
     if self.curr_fh.get_type() != NF4DIR:
         return simple_error(NFS4ERR_NOTDIR)
     if op.opreaddir.cookie in [1, 2]:
         return simple_error(NFS4ERR_BAD_COOKIE)
     if op.opreaddir.maxcount == 0:
         return simple_error(NFS4ERR_TOOSMALL)
     zeroverf = '\x00\x00\x00\x00\x00\x00\x00\x00'
     if op.opreaddir.cookie == 0 and op.opreaddir.cookieverf != zeroverf:
         return simple_error(NFS4ERR_BAD_COOKIE)
     try:
         verifier = self.curr_fh.getdirverf()
         if op.opreaddir.cookie != 0:
             if op.opreaddir.cookieverf != verifier:
                 return simple_error(NFS4ERR_NOT_SAME)
         try:
             dirlist = self.curr_fh.read_dir(op.opreaddir.cookie)
         except IndexError:
             return simple_error(NFS4ERR_BAD_COOKIE)
         attrs = nfs4lib.bitmap2list(op.opreaddir.attr_request)
         entries = []
         bytecnt = 0
         packer = nfs4lib.FancyNFS4Packer()
         for entry in dirlist:
             # Get file attributes
             try:
                 attrvals = entry.fh.get_attributes(attrs)
             except NFS4Error:
                 if FATTR4_RDATTR_ERROR not in attrs: raise
                 attrvals = entry.fh.get_attributes([FATTR4_RDATTR_ERROR])
             entry.attr = attrvals
             # Compute size of XDR encoding
             e4 = entry4(entry.cookie, entry.name, entry.attr, [])
             packer.reset()
             packer.pack_entry4(e4)
             # Make sure returned value not too big
             bytecnt += len(packer.get_buffer())
             if bytecnt > op.opreaddir.maxcount - 16:
                 break
             # Add file to returned entries
             entries.insert(0, entry)
         if (not entries) and dirlist:
             return simple_error(NFS4ERR_TOOSMALL)
         # Encode entries as linked list
         e4 = []
         for entry in entries:
             e4 = [
                 entry4(entry.cookie, entry.name, entry.attr, nextentry=e4)
             ]
         if len(entries) < len(dirlist):
             d4 = dirlist4(e4, eof=0)
         else:
             d4 = dirlist4(e4, eof=1)
     except NFS4Error, e:
         return simple_error(e.code)
Esempio n. 8
0
 def op_readdir(self, op):
     # We ignore dircount hint
     print "  CURRENT FILEHANDLE %s" % repr(self.curr_fh)
     print "  COOKIEVERF: %s, %s" % (repr(op.opreaddir.cookieverf), repr(op.opreaddir.cookie))
     print "  DIRCOUNT: %d MAXCOUNT: %d" % (op.opreaddir.dircount, op.opreaddir.maxcount)
     print "  ATTRMASK: %s" % [nfs4lib.get_attr_name(bit) for bit in nfs4lib.bitmap2list(op.opreaddir.attr_request)]
     if not self.curr_fh:
         return simple_error(NFS4ERR_NOFILEHANDLE)
     if self.curr_fh.get_type() != NF4DIR:
         return simple_error(NFS4ERR_NOTDIR)
     if op.opreaddir.cookie in [1, 2]:
         return simple_error(NFS4ERR_BAD_COOKIE)
     if op.opreaddir.maxcount == 0:
         return simple_error(NFS4ERR_TOOSMALL)
     zeroverf = "\x00\x00\x00\x00\x00\x00\x00\x00"
     if op.opreaddir.cookie == 0 and op.opreaddir.cookieverf != zeroverf:
         return simple_error(NFS4ERR_BAD_COOKIE)
     try:
         verifier = self.curr_fh.getdirverf()
         if op.opreaddir.cookie != 0:
             if op.opreaddir.cookieverf != verifier:
                 return simple_error(NFS4ERR_NOT_SAME)
         try:
             dirlist = self.curr_fh.read_dir(op.opreaddir.cookie)
         except IndexError:
             return simple_error(NFS4ERR_BAD_COOKIE)
         attrs = nfs4lib.bitmap2list(op.opreaddir.attr_request)
         entries = []
         bytecnt = 0
         packer = nfs4lib.FancyNFS4Packer()
         for entry in dirlist:
             # Get file attributes
             try:
                 attrvals = entry.fh.get_attributes(attrs)
             except NFS4Error:
                 if FATTR4_RDATTR_ERROR not in attrs:
                     raise
                 attrvals = entry.fh.get_attributes([FATTR4_RDATTR_ERROR])
             entry.attr = attrvals
             # Compute size of XDR encoding
             e4 = entry4(entry.cookie, entry.name, entry.attr, [])
             packer.reset()
             packer.pack_entry4(e4)
             # Make sure returned value not too big
             bytecnt += len(packer.get_buffer())
             if bytecnt > op.opreaddir.maxcount - 16:
                 break
             # Add file to returned entries
             entries.insert(0, entry)
         if (not entries) and dirlist:
             return simple_error(NFS4ERR_TOOSMALL)
         # Encode entries as linked list
         e4 = []
         for entry in entries:
             e4 = [entry4(entry.cookie, entry.name, entry.attr, nextentry=e4)]
         if len(entries) < len(dirlist):
             d4 = dirlist4(e4, eof=0)
         else:
             d4 = dirlist4(e4, eof=1)
     except NFS4Error, e:
         return simple_error(e.code)