File: lfc_undelete_test.py

package info (click to toggle)
dpm-postgres 1.7.4.7-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 13,788 kB
  • ctags: 10,782
  • sloc: ansic: 146,136; sh: 13,362; perl: 11,142; python: 5,529; cpp: 5,113; sql: 1,790; makefile: 955; fortran: 113
file content (219 lines) | stat: -rw-r--r-- 7,103 bytes parent folder | download | duplicates (8)
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
####
#
#	NOTE: Removes also the file which is not writeable.
#	NOTE: Error only if the parent directory is not writeable
#
####


import os, time, lfc, sys, commands, errno
from testClass import _test, _ntest

global testHome 
global name

class test_ok(_test):
    def info(self):
	return "lfc_delete"
    def clean(self):
        lfc.lfc_unlink(name)
    def prepare(self):
        lfc.lfc_mkdir(os.path.dirname(name),0755)
        self.guid = commands.getoutput('uuidgen').split('/n')[0]
        ret = lfc.lfc_creatg(name,self.guid,0664)
        if (ret != 0):
            print "Error: cannot create testing file"
            sys.exit(1)
        lfc.lfc_delete(name)
    def test(self):
        ret = lfc.lfc_undelete(name) 
        statg=lfc.lfc_filestatg()
        lfc.lfc_statg(name,"", statg)
        return (statg,ret)
    def ret(self):
        retval=lfc.lfc_filestatg()
        retval.status='-'
        return retval
    def compare(self, testVal, retVal):
        (ret, retRetVal) = retVal
        (test, testRetVal) = testVal
        retval = True
        if (retRetVal == testRetVal):
            retval = retval & ( test.status == ret.status )
        else:
            retval = False
        return retval



class test_EACCES(_ntest):
    def info(self):
	return "lfc_undelete in permission denied (EACCES)"
    def prepare(self):
        self.guid = commands.getoutput('uuidgen').split('/n')[0]
        lfc.lfc_mkdir(os.path.dirname(name),0755)
        ret = lfc.lfc_creatg(name,self.guid,0664)
        if (ret != 0):
            print "Error: cannot create testing file"
            sys.exit(1)
        lfc.lfc_delete(name)
        lfc.lfc_chmod(os.path.dirname(name),0500)
    def clean(self):
        lfc.lfc_chmod(os.path.dirname(name),0700)
        lfc.lfc_unlink(name)
        lfc.lfc_rmdir(os.path.dirname(name))
 
    def test(self):
        ret = lfc.lfc_undelete(name)
        err = lfc.cvar.serrno
        statg=lfc.lfc_filestatg()
        lfc.lfc_statg(name,"", statg)
        return ((statg, err), ret)
    def ret(self):
        retval=lfc.lfc_filestatg()
        retval.nlink=1
        retval.filesize=0L
        return (retval, errno.EACCES)
    def compare(self, testVal, retVal):
        ((ret, reterr), retRetVal) = retVal
        ((test, testerr), testRetVal) = testVal
        retval = True
        if ((retRetVal == testRetVal) & (reterr == testerr)):
            retval = retval & ( test.nlink == ret.nlink )
            retval = retval & ( test.filesize == ret.filesize )
        else:
            retval = False
        return retval

class test_EPERM(_ntest):
    def info(self):
        return "lfc_undelete on directory (EPERM)"
    def prepare(self):
        self.guid = commands.getoutput('uuidgen').split('/n')[0]
        lfc.lfc_mkdir(os.path.dirname(name),0755)
        ret = lfc.lfc_creatg(name,self.guid,0664)
        if (ret != 0):
            print "Error: cannot create testing file"
            sys.exit(1)
    def clean(self):
        lfc.lfc_unlink(name)
        lfc.lfc_rmdir(os.path.dirname(name))

    def test(self):
        ret = lfc.lfc_undelete(os.path.dirname(name))
        err = lfc.cvar.serrno
        statg=lfc.lfc_filestatg()
        lfc.lfc_statg(name,"", statg)
        return ((statg, err), ret)
    def ret(self):
        retval=lfc.lfc_filestatg()
        retval.nlink=1
        retval.filesize=0L
        retval.fileclass=0
        retval.status=' '
        return (retval, errno.EPERM)
    def compare(self, testVal, retVal):
        ((ret, reterr), retRetVal) = retVal
        ((test, testerr), testRetVal) = testVal
        retval = True
        if ((retRetVal == testRetVal) & (reterr == testerr)):
            retval = retval & ( test.nlink == ret.nlink )
            retval = retval & ( test.filesize == ret.filesize )
            retval = retval & ( test.fileclass == ret.fileclass )
        else:
            retval = False
        return retval

class test_ENOENT(_ntest):
    def info(self):
        return "lfc_undelete nonexisting file (ENOENT)"
    def prepare(self):
        lfc.lfc_mkdir(os.path.dirname(name),0755)
    def clean(self):
        lfc.lfc_rmdir(os.path.dirname(name))

    def test(self):
        ret = lfc.lfc_undelete(name)
        err = lfc.cvar.serrno
        statg=lfc.lfc_filestatg()
        lfc.lfc_statg(name,"", statg)
        return ((statg, err), ret)
    def ret(self):
        retval=lfc.lfc_filestatg()
        retval.nlink=0
        retval.filesize=0L
        retval.fileclass=0
        retval.status=' '
        return (retval, errno.ENOENT)
    def compare(self, testVal, retVal):
        ((ret, reterr), retRetVal) = retVal
        ((test, testerr), testRetVal) = testVal
        retval = True
        if ((retRetVal == testRetVal) & (reterr == testerr)):
            retval = retval & ( test.nlink == ret.nlink )
            retval = retval & ( test.filesize == ret.filesize )
            retval = retval & ( test.fileclass == ret.fileclass )
        else:
            retval = False
        return retval

class test_ENOTDIR(_ntest):
    def info(self):
        return "lfc_undelete prefix not a DIR (ENOTDIR)"
    def prepare(self):
        self.guid = commands.getoutput('uuidgen').split('/n')[0]
        lfc.lfc_creatg(os.path.dirname(name),self.guid,0664)
    def clean(self):
        lfc.lfc_unlink(os.path.dirname(name))

    def test(self):
        ret = lfc.lfc_undelete(name)
        err = lfc.cvar.serrno
        statg=lfc.lfc_filestatg()
        lfc.lfc_statg(name,"", statg)
        return ((statg, err), ret)
    def ret(self):
        retval=lfc.lfc_filestatg()
        retval.nlink=0
        retval.filesize=0L
        retval.fileclass=0
        retval.status=' '
        return (retval, errno.ENOTDIR)
    def compare(self, testVal, retVal):
        ((ret, reterr), retRetVal) = retVal
        ((test, testerr), testRetVal) = testVal
        retval = True
        if ((retRetVal == testRetVal) & (reterr == testerr)):
            retval = retval & ( test.nlink == ret.nlink )
            retval = retval & ( test.filesize == ret.filesize )
            retval = retval & ( test.fileclass == ret.fileclass )
        else:
            retval = False
        return retval

class lfc_undelete_test:
    def __init__(self):
	self.name = "lfc_undelete_test"
        self.tests=[test_ok,test_EACCES, test_EPERM, test_ENOENT, test_ENOTDIR]

    def run(self):
        retVal = True
        for testclass in self.tests:
            testInstance = testclass()
            testInstance.prepare()
            ret1 = testInstance.compare(testInstance.test(), (testInstance.ret(), testInstance.getRetVal()))
            testInstance.clean()
            retVal = retVal & ret1
            if ret1:
                print "%-60s[OK]" % testInstance.info()
            else:
                print "%-60s[FAILED]" % testInstance.info()
        return retVal


os.environ['LFC_HOME'] = 'lxb1941.cern.ch:/grid/dteam'
os.environ['LFC_HOST'] = 'lxb1941.cern.ch'
testHome = "python_lfc_test"
name = "/grid/dteam/python_undelete_test/python_undelete_test"
lfc_undelete_test().run()