示例#1
0
 def test_get_hashes(self):
     df = DiskFile(self.devices, "sda", "0", "a", "c", "o", FakeLogger())
     mkdirs(df.datadir)
     with open(os.path.join(df.datadir, normalize_timestamp(time.time()) + ".ts"), "wb") as f:
         f.write("1234567890")
     part = os.path.join(self.objects, "0")
     hashed, hashes = object_base.get_hashes(part)
     self.assertEquals(hashed, 1)
     self.assert_("a83" in hashes)
     hashed, hashes = object_base.get_hashes(part, do_listdir=True)
     self.assertEquals(hashed, 0)
     self.assert_("a83" in hashes)
     hashed, hashes = object_base.get_hashes(part, recalculate=["a83"])
     self.assertEquals(hashed, 1)
     self.assert_("a83" in hashes)
示例#2
0
    def test_get_hashes_unmodified(self):
        df = DiskFile(self.devices, "sda", "0", "a", "c", "o", FakeLogger())
        mkdirs(df.datadir)
        with open(os.path.join(df.datadir, normalize_timestamp(time.time()) + ".ts"), "wb") as f:
            f.write("1234567890")
        part = os.path.join(self.objects, "0")
        hashed, hashes = object_base.get_hashes(part)
        i = [0]

        def getmtime(filename):
            i[0] += 1
            return 1

        with unit_mock({"os.path.getmtime": getmtime}):
            hashed, hashes = object_base.get_hashes(part, recalculate=["a83"])
        self.assertEquals(i[0], 2)
示例#3
0
 def test_get_hashes(self):
     df = DiskFile(self.devices, 'sda', '0', 'a', 'c', 'o', FakeLogger())
     mkdirs(df.datadir)
     with open(
             os.path.join(df.datadir,
                          normalize_timestamp(time.time()) + '.ts'),
             'wb') as f:
         f.write('1234567890')
     part = os.path.join(self.objects, '0')
     hashed, hashes = object_base.get_hashes(part)
     self.assertEquals(hashed, 1)
     self.assert_('a83' in hashes)
     hashed, hashes = object_base.get_hashes(part, do_listdir=True)
     self.assertEquals(hashed, 0)
     self.assert_('a83' in hashes)
     hashed, hashes = object_base.get_hashes(part, recalculate=['a83'])
     self.assertEquals(hashed, 1)
     self.assert_('a83' in hashes)
示例#4
0
    def test_get_hashes_unmodified(self):
        df = DiskFile(self.devices, 'sda', '0', 'a', 'c', 'o', FakeLogger())
        mkdirs(df.datadir)
        with open(
                os.path.join(df.datadir,
                             normalize_timestamp(time.time()) + '.ts'),
                'wb') as f:
            f.write('1234567890')
        part = os.path.join(self.objects, '0')
        hashed, hashes = object_base.get_hashes(part)
        i = [0]

        def getmtime(filename):
            i[0] += 1
            return 1

        with unit_mock({'os.path.getmtime': getmtime}):
            hashed, hashes = object_base.get_hashes(part, recalculate=['a83'])
        self.assertEquals(i[0], 2)
示例#5
0
 def test_get_hashes_bad_dir(self):
     df = DiskFile(self.devices, 'sda', '0', 'a', 'c', 'o', FakeLogger())
     mkdirs(df.datadir)
     with open(os.path.join(self.objects, '0', 'bad'), 'wb') as f:
         f.write('1234567890')
     part = os.path.join(self.objects, '0')
     hashed, hashes = object_base.get_hashes(part)
     self.assertEquals(hashed, 1)
     self.assert_('a83' in hashes)
     self.assert_('bad' not in hashes)
示例#6
0
 def test_get_hashes_bad_dir(self):
     df = DiskFile(self.devices, "sda", "0", "a", "c", "o", FakeLogger())
     mkdirs(df.datadir)
     with open(os.path.join(self.objects, "0", "bad"), "wb") as f:
         f.write("1234567890")
     part = os.path.join(self.objects, "0")
     hashed, hashes = object_base.get_hashes(part)
     self.assertEquals(hashed, 1)
     self.assert_("a83" in hashes)
     self.assert_("bad" not in hashes)
示例#7
0
    def test_get_hashes_unmodified_and_zero_bytes(self):
        df = DiskFile(self.devices, 'sda', '0', 'a', 'c', 'o', FakeLogger())
        mkdirs(df.datadir)
        part = os.path.join(self.objects, '0')
        open(os.path.join(part, object_base.HASH_FILE), 'w')
        # Now the hash file is zero bytes.
        i = [0]

        def getmtime(filename):
            i[0] += 1
            return 1

        with unit_mock({'os.path.getmtime': getmtime}):
            hashed, hashes = object_base.get_hashes(part, recalculate=[])
        # getmtime will actually not get called.  Initially, the pickle.load
        # will raise an exception first and later, force_rewrite will
        # short-circuit the if clause to determine whether to write out a fresh
        # hashes_file.
        self.assertEquals(i[0], 0)
        self.assertTrue('a83' in hashes)
示例#8
0
    def test_get_hashes_unmodified_and_zero_bytes(self):
        df = DiskFile(self.devices, "sda", "0", "a", "c", "o", FakeLogger())
        mkdirs(df.datadir)
        part = os.path.join(self.objects, "0")
        open(os.path.join(part, object_base.HASH_FILE), "w")
        # Now the hash file is zero bytes.
        i = [0]

        def getmtime(filename):
            i[0] += 1
            return 1

        with unit_mock({"os.path.getmtime": getmtime}):
            hashed, hashes = object_base.get_hashes(part, recalculate=[])
        # getmtime will actually not get called.  Initially, the pickle.load
        # will raise an exception first and later, force_rewrite will
        # short-circuit the if clause to determine whether to write out a fresh
        # hashes_file.
        self.assertEquals(i[0], 0)
        self.assertTrue("a83" in hashes)