Exemple #1
0
def get_nfstime(t=None):
    """Convert time.time() output to nfstime4 format"""
    if t is None:
        t = time.time()
    sec = int(t)
    nsec = int((t - sec) * 1000000000)
    return nfs4_type.nfstime4(sec, nsec)
Exemple #2
0
def get_nfstime(t=None):
    """Convert time.time() output to nfstime4 format"""
    if t is None:
        t = time.time()
    sec = int(t)
    nsec = int((t - sec) * 1000000000)
    return nfs4_type.nfstime4(sec, nsec)
Exemple #3
0
def testInvalidTime(t, env):
    """SETATTR(FATTR4_TIME_MODIFY_SET) with invalid nseconds

    nseconds larger than 999999999 are considered invalid.
    SETATTR(FATTR4_TIME_MODIFY_SET) should return NFS4ERR_INVAL on
    such values. 

    FLAGS: setattr all
    DEPEND: MKDIR
    CODE: SATT10
    """
    c = env.c1
    path = c.homedir + [t.code]
    res = c.create_obj(path)
    check(res)
    supported = c.supportedAttrs()
    if not (supported & 2**FATTR4_TIME_MODIFY_SET):
        t.fail_support("FATTR4_TIME_MODIFY_SET not supported")
    time = nfstime4(seconds=500000000, nseconds=int(1E9))
    settime = settime4(set_it=SET_TO_CLIENT_TIME4, time=time)
    ops = c.use_obj(path) + [c.setattr({FATTR4_TIME_MODIFY_SET: settime})]
    res = c.compound(ops)
    check(res, NFS4ERR_INVAL,
          "SETATTR(FATTR4_TIME_MODIFY_SET) with nseconds=1E9")
Exemple #4
0
def testInvalidTime(t, env):
    """SETATTR(FATTR4_TIME_MODIFY_SET) with invalid nseconds

    nseconds larger than 999999999 are considered invalid.
    SETATTR(FATTR4_TIME_MODIFY_SET) should return NFS4ERR_INVAL on
    such values. 

    FLAGS: setattr all
    DEPEND: MKDIR
    CODE: SATT10
    """
    c = env.c1
    path = c.homedir + [t.code]
    res = c.create_obj(path)
    check(res)
    supported = c.supportedAttrs()
    if not (supported & 2**FATTR4_TIME_MODIFY_SET):
        t.fail_support("FATTR4_TIME_MODIFY_SET not supported")
    time = nfstime4(seconds=500000000, nseconds=int(1E9))
    settime = settime4(set_it=SET_TO_CLIENT_TIME4, time=time)
    ops = c.use_obj(path) + [c.setattr({FATTR4_TIME_MODIFY_SET: settime})]
    res = c.compound(ops)
    check(res, NFS4ERR_INVAL,
          "SETATTR(FATTR4_TIME_MODIFY_SET) with nseconds=1E9")
Exemple #5
0
class Environment(testmod.Environment):
    # STUB
    attr_info = [ \
        AttrInfo('supported_attrs', 'rm', []),
        AttrInfo('type', 'rm', 1),
        AttrInfo('fh_expire_type', 'rm', 0),
        AttrInfo('change', 'rm', 0),
        AttrInfo('size', 'rwm', 0),
        AttrInfo('link_support', 'rm', False),
        AttrInfo('symlink_support', 'rm', False),
        AttrInfo('named_attr', 'rm', False),
        AttrInfo('fsid', 'rm', fsid4(0, 0)),
        AttrInfo('unique_handles', 'rm', False),
        AttrInfo('lease_time', 'rm', 0),
        AttrInfo('rdattr_error', 'rm', 0),
        AttrInfo('filehandle', 'rm', 'nonsense'),
        AttrInfo('acl', 'rw', [nfsace4(0,0,0,'EVERYONE@')]),
        AttrInfo('aclsupport', 'r', 0),
        AttrInfo('archive', 'rw', False),
        AttrInfo('cansettime', 'r', False),
        AttrInfo('case_insensitive', 'r', False),
        AttrInfo('case_preserving', 'r', False),
        AttrInfo('chown_restricted', 'r', False),
        AttrInfo('fileid', 'r', 0),
        AttrInfo('files_avail', 'r', 0),
        AttrInfo('files_free', 'r', 0),
        AttrInfo('files_total', 'r', 0),
        # FRED - packer did not complain about missing [] about server
        AttrInfo('fs_locations', 'r',
                 fs_locations4('root',[fs_location4(['server'],'path')])),
        AttrInfo('hidden', 'rw', False),
        AttrInfo('homogeneous', 'r', False),
        AttrInfo('maxfilesize', 'r', 0),
        AttrInfo('maxlink', 'r', 0),
        AttrInfo('maxname', 'r', 0),
        AttrInfo('maxread', 'r', 0),
        AttrInfo('maxwrite', 'r', 0),
        AttrInfo('mimetype', 'rw', 'nonsense'),
        AttrInfo('mode', 'rw', 0),
        AttrInfo('no_trunc', 'r', False),
        AttrInfo('numlinks', 'r', 0),
        AttrInfo('owner', 'rw', 'nonsense'),
        AttrInfo('owner_group', 'rw', 'nonsense'),
        AttrInfo('quota_avail_hard', 'r', 0),
        AttrInfo('quota_avail_soft', 'r', 0),
        AttrInfo('quota_used', 'r', 0),
        AttrInfo('rawdev', 'r', specdata4(0, 0)),
        AttrInfo('space_avail', 'r', 0),
        AttrInfo('space_free', 'r', 0),
        AttrInfo('space_total', 'r', 0),
        AttrInfo('space_used', 'r', 0),
        AttrInfo('system', 'rw', False),
        AttrInfo('time_access', 'r', nfstime4(0, 0)),
        AttrInfo('time_access_set', 'w', settime4(0)),
        AttrInfo('time_backup', 'rw', nfstime4(0, 0)),
        AttrInfo('time_create', 'rw', nfstime4(0, 0)),
        AttrInfo('time_delta', 'r', nfstime4(0, 0)),
        AttrInfo('time_metadata', 'r', nfstime4(0, 0)),
        AttrInfo('time_modify', 'r', nfstime4(0, 0)),
        AttrInfo('time_modify_set', 'w', settime4(0)),
        AttrInfo('mounted_on_fileid', 'r', 0),
        ]

    def __init__(self, opts):
        sec1, sec2 = self._get_security(opts)
        #        authsys1 = rpc.SecAuthSys(0, opts.machinename, opts.uid, opts.gid, [])
        authsys2 = rpc.SecAuthSys(0, opts.machinename, opts.uid + 1,
                                  opts.gid + 1, [])
        self.c1 = NFS4Client('client1_pid%i' % os.getpid(),
                             opts.server,
                             opts.port,
                             opts.path,
                             sec_list=[sec1],
                             opts=opts)
        self.c2 = NFS4Client('client2_pid%i' % os.getpid(),
                             opts.server,
                             opts.port,
                             opts.path,
                             sec_list=[authsys2],
                             opts=opts)
        self.longname = "a" * 512
        self.uid = 0
        self.gid = 0
        self.opts = opts
        self.filedata = "This is the file test data."
        self.linkdata = "/etc/X11"
        self.stateid0 = stateid4(0, '')
        self.stateid1 = stateid4(0xffffffffL, '\xff' * 12)

    def _get_security(self, opts):
        if opts.security == 'none':
            return [opts.flavor(), opts.flavor()]
        elif opts.security == 'sys':
            sec1 = opts.flavor(0, opts.machinename, opts.uid, opts.gid, [])
            sec2 = opts.flavor(0, opts.machinename, opts.uid + 1, opts.gid + 1,
                               [])
            return [sec1, sec2]
        elif opts.security.startswith('krb5'):
            sec1 = opts.flavor(opts.service)
            sec2 = opts.flavor(opts.service)
            return [sec1, sec2]
        else:
            raise 'Bad security %s' % opts.security

    def init(self):
        """Run once before any test is run"""
        c = self.c1
        if self.opts.maketree:
            self._maketree()
        if self.opts.noinit:
            return
        # Make sure opts.path exists
        res = c.compound(c.use_obj(self.opts.path))
        check(res, msg="Could not LOOKUP /%s," % '/'.join(self.opts.path))
        # Make sure it is empty
        c.clean_dir(self.opts.path)
        c.null()

    def _maketree(self):
        """Make testtree"""
        c = self.c1
        # make /tmp (and path leading up to it if necesary)
        path = []
        for comp in self.opts.path:
            path.append(comp)
            res = c.compound(c.use_obj(path))
            checklist(res, [NFS4_OK, NFS4ERR_NOENT],
                      "Could not LOOKUP /%s," % '/'.join(path))
            if res.status == NFS4ERR_NOENT:
                res = c.create_obj(path)
                check(res, msg="Trying to create /%s," % '/'.join(path))
        # remove /tree/*
        tree = self.opts.path[:-1] + ['tree']
        res = c.compound(c.use_obj(tree))
        checklist(res, [NFS4_OK, NFS4ERR_NOENT])
        if res.status == NFS4ERR_NOENT:
            res = c.create_obj(tree)
            check(res, msg="Trying to create /%s," % '/'.join(tree))
        else:
            c.clean_dir(tree)

        # make objects in /tree
        name = {
            NF4DIR: 'dir',
            NF4SOCK: 'socket',
            NF4FIFO: 'fifo',
            NF4LNK: 'link',
            NF4BLK: 'block',
            NF4CHR: 'char'
        }
        for type in name:
            path = tree + [name[type]]
            res = c.create_obj(path, type)
            if res.status != NFS4_OK:
                print "WARNING - could not create /%s" % '/'.join(path)
        c.init_connection()
        fh, stateid = c.create_confirm('maketree',
                                       tree + ['file'],
                                       deny=OPEN4_SHARE_DENY_NONE)
        ops = [
            c.putfh_op(fh),
            c.write_op(stateid, 0, FILE_SYNC4, self.filedata)
        ]
        res = c.compound(ops)
        check(res, msg="Writing data to /%s/file" % '/'.join(tree))
        res = c.close_file('maketree', fh, stateid)
        check(res)

    def finish(self):
        """Run once after all tests are run"""
        if self.opts.nocleanup:
            return
        c = self.c1
        c.null()
        c.null()
        c.clean_dir(self.opts.path)

    def startUp(self):
        """Run before each test"""
        self.c1.null()

    def sleep(self, sec, msg=''):
        """Sleep for given seconds"""
        print "Sleeping for %g seconds:" % sec, msg
        time.sleep(sec)
        print "Woke up"

    def serverhelper(self, args):
        """Perform a special operation on the server side (such as
        rebooting the server)"""
        if self.opts.serverhelper is None:
            print "Manual operation required on server:"
            print args + " and hit ENTER when done"
            sys.stdin.readline()
            print "Continuing with test"
        else:
            cmd = self.opts.serverhelper
            if self.opts.serverhelperarg:
                cmd += ' ' + self.opts.serverhelperarg
            cmd += ' ' + args
            os.system(cmd)

    def clean_sessions(self):
        return