~ubuntu-branches/ubuntu/raring/swift/raring-security

« back to all changes in this revision

Viewing changes to test/unit/obj/test_auditor.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2013-01-28 09:40:30 UTC
  • mfrom: (1.2.16)
  • Revision ID: package-import@ubuntu.com-20130128094030-aetz57x2qz9ye2d4
Tags: 1.7.6-0ubuntu1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
        unit.xattr_data = {}
62
62
 
63
63
    def test_object_audit_extra_data(self):
64
 
        self.auditor = auditor.AuditorWorker(self.conf)
 
64
        self.auditor = auditor.AuditorWorker(self.conf, self.logger)
65
65
        data = '0' * 1024
66
66
        etag = md5()
67
 
        with self.disk_file.mkstemp() as (fd, tmppath):
 
67
        with self.disk_file.mkstemp() as fd:
68
68
            os.write(fd, data)
69
69
            etag.update(data)
70
70
            etag = etag.hexdigest()
74
74
                'X-Timestamp': timestamp,
75
75
                'Content-Length': str(os.fstat(fd).st_size),
76
76
            }
77
 
            self.disk_file.put(fd, tmppath, metadata)
 
77
            self.disk_file.put(fd, metadata)
78
78
            pre_quarantines = self.auditor.quarantines
79
79
 
80
80
            self.auditor.object_audit(
89
89
            self.assertEquals(self.auditor.quarantines, pre_quarantines + 1)
90
90
 
91
91
    def test_object_audit_diff_data(self):
92
 
        self.auditor = auditor.AuditorWorker(self.conf)
 
92
        self.auditor = auditor.AuditorWorker(self.conf, self.logger)
93
93
        data = '0' * 1024
94
94
        etag = md5()
95
95
        timestamp = str(normalize_timestamp(time.time()))
96
 
        with self.disk_file.mkstemp() as (fd, tmppath):
 
96
        with self.disk_file.mkstemp() as fd:
97
97
            os.write(fd, data)
98
98
            etag.update(data)
99
99
            etag = etag.hexdigest()
102
102
                'X-Timestamp': timestamp,
103
103
                'Content-Length': str(os.fstat(fd).st_size),
104
104
            }
105
 
            self.disk_file.put(fd, tmppath, metadata)
 
105
            self.disk_file.put(fd, metadata)
106
106
            pre_quarantines = self.auditor.quarantines
107
107
            # remake so it will have metadata
108
108
            self.disk_file = DiskFile(self.devices, 'sda', '0', 'a', 'c', 'o',
131
131
        fp.write('0' * 1024)
132
132
        fp.close()
133
133
        invalidate_hash(os.path.dirname(self.disk_file.datadir))
134
 
        self.auditor = auditor.AuditorWorker(self.conf)
 
134
        self.auditor = auditor.AuditorWorker(self.conf, self.logger)
135
135
        pre_quarantines = self.auditor.quarantines
136
136
        self.auditor.object_audit(
137
137
            os.path.join(self.disk_file.datadir, timestamp + '.data'),
139
139
        self.assertEquals(self.auditor.quarantines, pre_quarantines + 1)
140
140
 
141
141
    def test_object_audit_bad_args(self):
142
 
        self.auditor = auditor.AuditorWorker(self.conf)
 
142
        self.auditor = auditor.AuditorWorker(self.conf, self.logger)
143
143
        pre_errors = self.auditor.errors
144
144
        self.auditor.object_audit(5, 'sda', '0')
145
145
        self.assertEquals(self.auditor.errors, pre_errors + 1)
148
148
        self.assertEquals(self.auditor.errors, pre_errors)  # just returns
149
149
 
150
150
    def test_object_run_once_pass(self):
151
 
        self.auditor = auditor.AuditorWorker(self.conf)
 
151
        self.auditor = auditor.AuditorWorker(self.conf, self.logger)
152
152
        self.auditor.log_time = 0
153
153
        timestamp = str(normalize_timestamp(time.time()))
154
154
        pre_quarantines = self.auditor.quarantines
155
155
        data = '0' * 1024
156
156
        etag = md5()
157
 
        with self.disk_file.mkstemp() as (fd, tmppath):
 
157
        with self.disk_file.mkstemp() as fd:
158
158
            os.write(fd, data)
159
159
            etag.update(data)
160
160
            etag = etag.hexdigest()
163
163
                'X-Timestamp': timestamp,
164
164
                'Content-Length': str(os.fstat(fd).st_size),
165
165
            }
166
 
            self.disk_file.put(fd, tmppath, metadata)
 
166
            self.disk_file.put(fd, metadata)
167
167
            self.disk_file.close()
168
168
        self.auditor.audit_all_objects()
169
169
        self.assertEquals(self.auditor.quarantines, pre_quarantines)
170
170
 
171
171
    def test_object_run_once_no_sda(self):
172
 
        self.auditor = auditor.AuditorWorker(self.conf)
 
172
        self.auditor = auditor.AuditorWorker(self.conf, self.logger)
173
173
        timestamp = str(normalize_timestamp(time.time()))
174
174
        pre_quarantines = self.auditor.quarantines
175
175
        data = '0' * 1024
176
176
        etag = md5()
177
 
        with self.disk_file.mkstemp() as (fd, tmppath):
 
177
        with self.disk_file.mkstemp() as fd:
178
178
            os.write(fd, data)
179
179
            etag.update(data)
180
180
            etag = etag.hexdigest()
183
183
                'X-Timestamp': timestamp,
184
184
                'Content-Length': str(os.fstat(fd).st_size),
185
185
            }
186
 
            self.disk_file.put(fd, tmppath, metadata)
 
186
            self.disk_file.put(fd, metadata)
187
187
            self.disk_file.close()
188
188
            os.write(fd, 'extra_data')
189
189
        self.auditor.audit_all_objects()
190
190
        self.assertEquals(self.auditor.quarantines, pre_quarantines + 1)
191
191
 
192
192
    def test_object_run_once_multi_devices(self):
193
 
        self.auditor = auditor.AuditorWorker(self.conf)
 
193
        self.auditor = auditor.AuditorWorker(self.conf, self.logger)
194
194
        timestamp = str(normalize_timestamp(time.time()))
195
195
        pre_quarantines = self.auditor.quarantines
196
196
        data = '0' * 10
197
197
        etag = md5()
198
 
        with self.disk_file.mkstemp() as (fd, tmppath):
 
198
        with self.disk_file.mkstemp() as fd:
199
199
            os.write(fd, data)
200
200
            etag.update(data)
201
201
            etag = etag.hexdigest()
204
204
                'X-Timestamp': timestamp,
205
205
                'Content-Length': str(os.fstat(fd).st_size),
206
206
            }
207
 
            self.disk_file.put(fd, tmppath, metadata)
 
207
            self.disk_file.put(fd, metadata)
208
208
            self.disk_file.close()
209
209
        self.auditor.audit_all_objects()
210
210
        self.disk_file = DiskFile(self.devices, 'sdb', '0', 'a', 'c',
211
211
                                  'ob', self.logger)
212
212
        data = '1' * 10
213
213
        etag = md5()
214
 
        with self.disk_file.mkstemp() as (fd, tmppath):
 
214
        with self.disk_file.mkstemp() as fd:
215
215
            os.write(fd, data)
216
216
            etag.update(data)
217
217
            etag = etag.hexdigest()
220
220
                'X-Timestamp': timestamp,
221
221
                'Content-Length': str(os.fstat(fd).st_size),
222
222
            }
223
 
            self.disk_file.put(fd, tmppath, metadata)
 
223
            self.disk_file.put(fd, metadata)
224
224
            self.disk_file.close()
225
225
            os.write(fd, 'extra_data')
226
226
        self.auditor.audit_all_objects()
231
231
        self.auditor.log_time = 0
232
232
        data = '0' * 1024
233
233
        etag = md5()
234
 
        with self.disk_file.mkstemp() as (fd, tmppath):
 
234
        with self.disk_file.mkstemp() as fd:
235
235
            os.write(fd, data)
236
236
            etag.update(data)
237
237
            etag = etag.hexdigest()
240
240
                'X-Timestamp': str(normalize_timestamp(time.time())),
241
241
                'Content-Length': str(os.fstat(fd).st_size),
242
242
            }
243
 
            self.disk_file.put(fd, tmppath, metadata)
 
243
            self.disk_file.put(fd, metadata)
244
244
            etag = md5()
245
245
            etag.update('1' + '0' * 1023)
246
246
            etag = etag.hexdigest()
270
270
            fp.close()
271
271
 
272
272
        etag = md5()
273
 
        with self.disk_file.mkstemp() as (fd, tmppath):
 
273
        with self.disk_file.mkstemp() as fd:
274
274
            etag = etag.hexdigest()
275
275
            metadata = {
276
276
                'ETag': etag,
277
277
                'X-Timestamp': str(normalize_timestamp(time.time())),
278
278
                'Content-Length': 10,
279
279
            }
280
 
            self.disk_file.put(fd, tmppath, metadata)
 
280
            self.disk_file.put(fd, metadata)
281
281
            etag = md5()
282
282
            etag = etag.hexdigest()
283
283
            metadata['ETag'] = etag