~ubuntu-branches/ubuntu/trusty/swift/trusty-updates

« back to all changes in this revision

Viewing changes to test/unit/obj/test_replicator.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:
238
238
                part, recalculate=['a83'])
239
239
        self.assertEquals(i[0], 2)
240
240
 
 
241
    def test_get_hashes_unmodified_and_zero_bytes(self):
 
242
        df = DiskFile(self.devices, 'sda', '0', 'a', 'c', 'o', FakeLogger())
 
243
        mkdirs(df.datadir)
 
244
        part = os.path.join(self.objects, '0')
 
245
        open(os.path.join(part, object_replicator.HASH_FILE), 'w')
 
246
        # Now the hash file is zero bytes.
 
247
        i = [0]
 
248
        def getmtime(filename):
 
249
            i[0] += 1
 
250
            return 1
 
251
        with mock({'os.path.getmtime': getmtime}):
 
252
            hashed, hashes = object_replicator.get_hashes(
 
253
                part, recalculate=[])
 
254
        # getmtime will actually not get called.  Initially, the pickle.load
 
255
        # will raise an exception first and later, force_rewrite will
 
256
        # short-circuit the if clause to determine whether to write out a fresh
 
257
        # hashes_file.
 
258
        self.assertEquals(i[0], 0)
 
259
        self.assertTrue('a83' in hashes)
 
260
 
241
261
    def test_get_hashes_modified(self):
242
262
        df = DiskFile(self.devices, 'sda', '0', 'a', 'c', 'o', FakeLogger())
243
263
        mkdirs(df.datadir)
377
397
        self.replicator.next_check = orig_check - 30
378
398
        self.assertFalse(self.replicator.check_ring())
379
399
 
 
400
    def test_collect_jobs_mkdirs_error(self):
 
401
 
 
402
        def blowup_mkdirs(path):
 
403
            raise OSError('Ow!')
 
404
 
 
405
        mkdirs_orig = object_replicator.mkdirs
 
406
        try:
 
407
            rmtree(self.objects, ignore_errors=1)
 
408
            object_replicator.mkdirs = blowup_mkdirs
 
409
            jobs = self.replicator.collect_jobs()
 
410
            self.assertTrue('exception' in self.replicator.logger.log_dict)
 
411
            self.assertEquals(
 
412
                len(self.replicator.logger.log_dict['exception']), 1)
 
413
            exc_args, exc_kwargs, exc_str = \
 
414
                self.replicator.logger.log_dict['exception'][0]
 
415
            self.assertEquals(len(exc_args), 1)
 
416
            self.assertTrue(exc_args[0].startswith('ERROR creating '))
 
417
            self.assertEquals(exc_kwargs, {})
 
418
            self.assertEquals(exc_str, 'Ow!')
 
419
        finally:
 
420
            object_replicator.mkdirs = mkdirs_orig
 
421
 
380
422
    def test_collect_jobs(self):
381
423
        jobs = self.replicator.collect_jobs()
382
424
        jobs_to_delete = [j for j in jobs if j['delete']]