Exemple #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_replicator.get_hashes(part)
     self.assertEquals(hashed, 1)
     self.assert_("a83" in hashes)
     hashed, hashes = object_replicator.get_hashes(part, do_listdir=True)
     self.assertEquals(hashed, 0)
     self.assert_("a83" in hashes)
     hashed, hashes = object_replicator.get_hashes(part, recalculate=["a83"])
     self.assertEquals(hashed, 1)
     self.assert_("a83" in hashes)
 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_replicator.get_hashes(part)
     i = [0]
     def getmtime(filename):
         i[0] += 1
         return 1
     with mock({'os.path.getmtime': getmtime}):
         hashed, hashes = object_replicator.get_hashes(
             part, recalculate=['a83'])
     self.assertEquals(i[0], 2)
Exemple #3
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_replicator.get_hashes(part)
     i = [0]
     def getmtime(filename):
         i[0] += 1
         return 1
     with mock({'os.path.getmtime': getmtime}):
         hashed, hashes = object_replicator.get_hashes(
             part, recalculate=['a83'])
     self.assertEquals(i[0], 2)
 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_replicator.get_hashes(part)
     self.assertEquals(hashed, 1)
     self.assert_('a83' in hashes)
     hashed, hashes = object_replicator.get_hashes(part, do_listdir=True)
     self.assertEquals(hashed, 0)
     self.assert_('a83' in hashes)
     hashed, hashes = object_replicator.get_hashes(part, recalculate=['a83'])
     self.assertEquals(hashed, 1)
     self.assert_('a83' in hashes)
Exemple #5
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_replicator.get_hashes(part)
        i = [0]

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

        with mock({"os.path.getmtime": getmtime}):
            hashed, hashes = object_replicator.get_hashes(part, recalculate=["a83"])
        self.assertEquals(i[0], 2)
Exemple #6
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_replicator.get_hashes(part)
     self.assertEquals(hashed, 1)
     self.assert_('a83' in hashes)
     hashed, hashes = object_replicator.get_hashes(part, do_listdir=True)
     self.assertEquals(hashed, 0)
     self.assert_('a83' in hashes)
     hashed, hashes = object_replicator.get_hashes(part,
                                                   recalculate=['a83'])
     self.assertEquals(hashed, 1)
     self.assert_('a83' in hashes)
 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_replicator.get_hashes(part)
     self.assertEquals(hashed, 1)
     self.assert_('a83' in hashes)
     self.assert_('bad' not in hashes)
Exemple #8
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_replicator.get_hashes(part)
     self.assertEquals(hashed, 1)
     self.assert_('a83' in hashes)
     self.assert_('bad' not in hashes)
Exemple #9
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_replicator.get_hashes(part)
     self.assertEquals(hashed, 1)
     self.assert_("a83" in hashes)
     self.assert_("bad" not in hashes)
 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_replicator.HASH_FILE), 'w')
     # Now the hash file is zero bytes.
     i = [0]
     def getmtime(filename):
         i[0] += 1
         return 1
     with mock({'os.path.getmtime': getmtime}):
         hashed, hashes = object_replicator.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)
Exemple #11
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_replicator.HASH_FILE), 'w')
     # Now the hash file is zero bytes.
     i = [0]
     def getmtime(filename):
         i[0] += 1
         return 1
     with mock({'os.path.getmtime': getmtime}):
         hashed, hashes = object_replicator.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)
Exemple #12
0
        """
        try:
            device, partition, suffix = split_path(
                unquote(request.path), 2, 3, True)
        except ValueError, e:
            return HTTPBadRequest(body=str(e), request=request,
                                  content_type='text/plain')
        if self.mount_check and not check_mount(self.devices, device):
            return Response(status='507 %s is not mounted' % device)
        path = os.path.join(self.devices, device, DATADIR, partition)
        if not os.path.exists(path):
            mkdirs(path)
        if suffix:
            recalculate_hashes(path, suffix.split('-'))
            return Response()
        _junk, hashes = get_hashes(path, do_listdir=False)
        return Response(body=pickle.dumps(hashes))

    def __call__(self, env, start_response):
        """WSGI Application entry point for the Swift Object Server."""
        start_time = time.time()
        req = Request(env)
        self.logger.txn_id = req.headers.get('x-cf-trans-id', None)
        if not check_utf8(req.path_info):
            res = HTTPPreconditionFailed(body='Invalid UTF8')
        else:
            try:
                if hasattr(self, req.method):
                    res = getattr(self, req.method)(req)
                else:
                    res = HTTPMethodNotAllowed()