當前位置: 首頁>>代碼示例>>Python>>正文


Python diskfile.DiskFile類代碼示例

本文整理匯總了Python中swift.obj.diskfile.DiskFile的典型用法代碼示例。如果您正苦於以下問題:Python DiskFile類的具體用法?Python DiskFile怎麽用?Python DiskFile使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了DiskFile類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_object_run_once_multi_devices

 def test_object_run_once_multi_devices(self):
     self.auditor = auditor.AuditorWorker(self.conf, self.logger)
     timestamp = str(normalize_timestamp(time.time()))
     pre_quarantines = self.auditor.quarantines
     data = '0' * 10
     etag = md5()
     with self.disk_file.writer() as writer:
         writer.write(data)
         etag.update(data)
         etag = etag.hexdigest()
         metadata = {
             'ETag': etag,
             'X-Timestamp': timestamp,
             'Content-Length': str(os.fstat(writer.fd).st_size),
         }
         writer.put(metadata)
     self.auditor.audit_all_objects()
     self.disk_file = DiskFile(self.devices, 'sdb', '0', 'a', 'c',
                               'ob', self.logger)
     data = '1' * 10
     etag = md5()
     with self.disk_file.writer() as writer:
         writer.write(data)
         etag.update(data)
         etag = etag.hexdigest()
         metadata = {
             'ETag': etag,
             'X-Timestamp': timestamp,
             'Content-Length': str(os.fstat(writer.fd).st_size),
         }
         writer.put(metadata)
         os.write(writer.fd, 'extra_data')
     self.auditor.audit_all_objects()
     self.assertEquals(self.auditor.quarantines, pre_quarantines + 1)
開發者ID:r0mik,項目名稱:swift,代碼行數:34,代碼來源:test_auditor.py

示例2: test_object_audit_diff_data

    def test_object_audit_diff_data(self):
        self.auditor = auditor.AuditorWorker(self.conf, self.logger)
        data = '0' * 1024
        etag = md5()
        timestamp = str(normalize_timestamp(time.time()))
        with self.disk_file.writer() as writer:
            writer.write(data)
            etag.update(data)
            etag = etag.hexdigest()
            metadata = {
                'ETag': etag,
                'X-Timestamp': timestamp,
                'Content-Length': str(os.fstat(writer.fd).st_size),
            }
            writer.put(metadata)
            pre_quarantines = self.auditor.quarantines

        # remake so it will have metadata
        self.disk_file = DiskFile(self.devices, 'sda', '0', 'a', 'c', 'o',
                                  self.logger)

        self.auditor.object_audit(
            os.path.join(self.disk_file.datadir, timestamp + '.data'),
            'sda', '0')
        self.assertEquals(self.auditor.quarantines, pre_quarantines)
        etag = md5()
        etag.update('1' + '0' * 1023)
        etag = etag.hexdigest()
        metadata['ETag'] = etag

        with self.disk_file.writer() as writer:
            writer.write(data)
            writer.put(metadata)

        self.auditor.object_audit(
            os.path.join(self.disk_file.datadir, timestamp + '.data'),
            'sda', '0')
        self.assertEquals(self.auditor.quarantines, pre_quarantines + 1)
開發者ID:r0mik,項目名稱:swift,代碼行數:38,代碼來源:test_auditor.py

示例3: setUp

    def setUp(self):
        self.testdir = os.path.join(mkdtemp(), 'tmp_test_object_auditor')
        self.devices = os.path.join(self.testdir, 'node')
        self.logger = FakeLogger()
        rmtree(self.testdir, ignore_errors=1)
        mkdirs(os.path.join(self.devices, 'sda'))
        self.objects = os.path.join(self.devices, 'sda', 'objects')

        os.mkdir(os.path.join(self.devices, 'sdb'))
        self.objects_2 = os.path.join(self.devices, 'sdb', 'objects')

        os.mkdir(self.objects)
        self.parts = {}
        for part in ['0', '1', '2', '3']:
            self.parts[part] = os.path.join(self.objects, part)
            os.mkdir(os.path.join(self.objects, part))

        self.conf = dict(
            devices=self.devices,
            mount_check='false',
            object_size_stats='10,100,1024,10240')
        self.disk_file = DiskFile(self.devices, 'sda', '0', 'a', 'c', 'o',
                                  self.logger)
開發者ID:r0mik,項目名稱:swift,代碼行數:23,代碼來源:test_auditor.py

示例4: _quarantine

 def _quarantine(self, data_file, msg):
     rat[0] = True
     DiskFile._quarantine(self, data_file, msg)
開發者ID:AsherBond,項目名稱:swift,代碼行數:3,代碼來源:test_auditor.py

示例5: close

 def close(self, verify_file=True):
     rat[0] = True
     DiskFile.close(self, verify_file=verify_file)
開發者ID:r0mik,項目名稱:swift,代碼行數:3,代碼來源:test_auditor.py

示例6: TestAuditor

class TestAuditor(unittest.TestCase):

    def setUp(self):
        self.testdir = os.path.join(mkdtemp(), 'tmp_test_object_auditor')
        self.devices = os.path.join(self.testdir, 'node')
        self.logger = FakeLogger()
        rmtree(self.testdir, ignore_errors=1)
        mkdirs(os.path.join(self.devices, 'sda'))
        self.objects = os.path.join(self.devices, 'sda', 'objects')

        os.mkdir(os.path.join(self.devices, 'sdb'))
        self.objects_2 = os.path.join(self.devices, 'sdb', 'objects')

        os.mkdir(self.objects)
        self.parts = {}
        for part in ['0', '1', '2', '3']:
            self.parts[part] = os.path.join(self.objects, part)
            os.mkdir(os.path.join(self.objects, part))

        self.conf = dict(
            devices=self.devices,
            mount_check='false',
            object_size_stats='10,100,1024,10240')
        self.disk_file = DiskFile(self.devices, 'sda', '0', 'a', 'c', 'o',
                                  self.logger)

    def tearDown(self):
        rmtree(os.path.dirname(self.testdir), ignore_errors=1)
        unit.xattr_data = {}

    def test_object_audit_extra_data(self):
        self.auditor = auditor.AuditorWorker(self.conf, self.logger)
        data = '0' * 1024
        etag = md5()
        with self.disk_file.writer() as writer:
            writer.write(data)
            etag.update(data)
            etag = etag.hexdigest()
            timestamp = str(normalize_timestamp(time.time()))
            metadata = {
                'ETag': etag,
                'X-Timestamp': timestamp,
                'Content-Length': str(os.fstat(writer.fd).st_size),
            }
            writer.put(metadata)
            pre_quarantines = self.auditor.quarantines

            self.auditor.object_audit(
                os.path.join(self.disk_file.datadir, timestamp + '.data'),
                'sda', '0')
            self.assertEquals(self.auditor.quarantines, pre_quarantines)

            os.write(writer.fd, 'extra_data')
            self.auditor.object_audit(
                os.path.join(self.disk_file.datadir, timestamp + '.data'),
                'sda', '0')
            self.assertEquals(self.auditor.quarantines, pre_quarantines + 1)

    def test_object_audit_diff_data(self):
        self.auditor = auditor.AuditorWorker(self.conf, self.logger)
        data = '0' * 1024
        etag = md5()
        timestamp = str(normalize_timestamp(time.time()))
        with self.disk_file.writer() as writer:
            writer.write(data)
            etag.update(data)
            etag = etag.hexdigest()
            metadata = {
                'ETag': etag,
                'X-Timestamp': timestamp,
                'Content-Length': str(os.fstat(writer.fd).st_size),
            }
            writer.put(metadata)
            pre_quarantines = self.auditor.quarantines

        # remake so it will have metadata
        self.disk_file = DiskFile(self.devices, 'sda', '0', 'a', 'c', 'o',
                                  self.logger)

        self.auditor.object_audit(
            os.path.join(self.disk_file.datadir, timestamp + '.data'),
            'sda', '0')
        self.assertEquals(self.auditor.quarantines, pre_quarantines)
        etag = md5()
        etag.update('1' + '0' * 1023)
        etag = etag.hexdigest()
        metadata['ETag'] = etag

        with self.disk_file.writer() as writer:
            writer.write(data)
            writer.put(metadata)

        self.auditor.object_audit(
            os.path.join(self.disk_file.datadir, timestamp + '.data'),
            'sda', '0')
        self.assertEquals(self.auditor.quarantines, pre_quarantines + 1)

    def test_object_audit_no_meta(self):
        timestamp = str(normalize_timestamp(time.time()))
        path = os.path.join(self.disk_file.datadir, timestamp + '.data')
#.........這裏部分代碼省略.........
開發者ID:r0mik,項目名稱:swift,代碼行數:101,代碼來源:test_auditor.py


注:本文中的swift.obj.diskfile.DiskFile類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。