当前位置: 首页>>代码示例>>Python>>正文


Python server.write_metadata函数代码示例

本文整理汇总了Python中swift.obj.server.write_metadata函数的典型用法代码示例。如果您正苦于以下问题:Python write_metadata函数的具体用法?Python write_metadata怎么用?Python write_metadata使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了write_metadata函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run_quarantine_range_etag

    def run_quarantine_range_etag(self):
        container = 'container-range-%s' % uuid4()
        obj = 'object-range-%s' % uuid4()
        onode, opart, data_file = self._setup_data_file(container, obj,
                                                        'RANGE')
        with open(data_file) as fp:
            metadata = read_metadata(fp)
        metadata['ETag'] = 'badetag'
        with open(data_file) as fp:
            write_metadata(fp, metadata)
        for header, result in [({'Range': 'bytes=0-2'}, 'RAN'),
                               ({'Range': 'bytes=1-11'}, 'ANGE'),
                               ({'Range': 'bytes=0-11'}, 'RANGE')]:
            odata = direct_client.direct_get_object(onode, opart,
                                              self.account, container, obj,
                                              headers=header)[-1]

            self.assertEquals(odata, result)

        try:
            resp = direct_client.direct_get_object(onode, opart, self.account,
                                                   container, obj)
            raise "Did not quarantine object"
        except client.ClientException, e:
            self.assertEquals(e.http_status, 404)
开发者ID:BillTheBest,项目名称:swift,代码行数:25,代码来源:test_object_failures.py

示例2: setup_bad_zero_byte

    def setup_bad_zero_byte(self, with_ts=False):
        self.auditor = auditor.ObjectAuditor(self.conf)
        self.auditor.log_time = 0
        ts_file_path = ''
        if with_ts:

            name_hash = hash_path('a', 'c', 'o')
            dir_path = os.path.join(self.devices, 'sda',
                               storage_directory(DATADIR, '0', name_hash))
            ts_file_path = os.path.join(dir_path, '99999.ts')
            if not os.path.exists(dir_path):
                mkdirs(dir_path)
            fp = open(ts_file_path, 'w')
            fp.close()

        etag = md5()
        with self.disk_file.mkstemp() as (fd, tmppath):
            etag = etag.hexdigest()
            metadata = {
                'ETag': etag,
                'X-Timestamp': str(normalize_timestamp(time.time())),
                'Content-Length': 10,
            }
            self.disk_file.put(fd, tmppath, metadata)
            etag = md5()
            etag = etag.hexdigest()
            metadata['ETag'] = etag
            write_metadata(fd, metadata)
        if self.disk_file.data_file:
            return self.disk_file.data_file
        return ts_file_path
开发者ID:BillTheBest,项目名称:swift,代码行数:31,代码来源:test_auditor.py

示例3: test_object_audit_diff_data

    def test_object_audit_diff_data(self):
        self.auditor = auditor.AuditorWorker(self.conf)
        data = '0' * 1024
        etag = md5()
        timestamp = str(normalize_timestamp(time.time()))
        with self.disk_file.mkstemp() as (fd, tmppath):
            os.write(fd, data)
            etag.update(data)
            etag = etag.hexdigest()
            metadata = {
                'ETag': etag,
                'X-Timestamp': timestamp,
                'Content-Length': str(os.fstat(fd).st_size),
            }
            self.disk_file.put(fd, tmppath, 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
            write_metadata(fd, 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:BillTheBest,项目名称:swift,代码行数:34,代码来源:test_auditor.py

示例4: test_object_run_fast_track_non_zero

    def test_object_run_fast_track_non_zero(self):
        self.auditor = auditor.ObjectAuditor(self.conf)
        self.auditor.log_time = 0
        data = '0' * 1024
        etag = md5()
        with self.disk_file.mkstemp() as (fd, tmppath):
            os.write(fd, data)
            etag.update(data)
            etag = etag.hexdigest()
            metadata = {
                'ETag': etag,
                'X-Timestamp': str(normalize_timestamp(time.time())),
                'Content-Length': str(os.fstat(fd).st_size),
            }
            self.disk_file.put(fd, tmppath, metadata)
            etag = md5()
            etag.update('1' + '0' * 1023)
            etag = etag.hexdigest()
            metadata['ETag'] = etag
            write_metadata(fd, metadata)

        quarantine_path = os.path.join(self.devices,
                                       'sda', 'quarantined', 'objects')
        self.auditor.run_once(zero_byte_fps=50)
        self.assertFalse(os.path.isdir(quarantine_path))
        self.auditor.run_once()
        self.assertTrue(os.path.isdir(quarantine_path))
开发者ID:BillTheBest,项目名称:swift,代码行数:27,代码来源:test_auditor.py

示例5: test_object_audit_diff_data

    def test_object_audit_diff_data(self):
        self.auditor = auditor.AuditorWorker(self.conf)
        data = "0" * 1024
        etag = md5()
        timestamp = str(normalize_timestamp(time.time()))
        with self.disk_file.mkstemp() as (fd, tmppath):
            os.write(fd, data)
            etag.update(data)
            etag = etag.hexdigest()
            metadata = {"ETag": etag, "X-Timestamp": timestamp, "Content-Length": str(os.fstat(fd).st_size)}
            self.disk_file.put(fd, tmppath, 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
            write_metadata(fd, 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:jness,项目名称:python-swift,代码行数:25,代码来源:test_auditor.py

示例6: setup_bad_zero_byte

    def setup_bad_zero_byte(self, with_ts=False):
        self.auditor = auditor.ObjectAuditor(self.conf)
        self.auditor.log_time = 0
        ts_file_path = ""
        if with_ts:

            name_hash = hash_path("a", "c", "o")
            dir_path = os.path.join(self.devices, "sda", storage_directory(DATADIR, "0", name_hash))
            ts_file_path = os.path.join(dir_path, "99999.ts")
            if not os.path.exists(dir_path):
                mkdirs(dir_path)
            fp = open(ts_file_path, "w")
            fp.close()

        etag = md5()
        with self.disk_file.mkstemp() as (fd, tmppath):
            etag = etag.hexdigest()
            metadata = {"ETag": etag, "X-Timestamp": str(normalize_timestamp(time.time())), "Content-Length": 10}
            self.disk_file.put(fd, tmppath, metadata)
            etag = md5()
            etag = etag.hexdigest()
            metadata["ETag"] = etag
            write_metadata(fd, metadata)
        if self.disk_file.data_file:
            return self.disk_file.data_file
        return ts_file_path
开发者ID:jness,项目名称:python-swift,代码行数:26,代码来源:test_auditor.py

示例7: test_object_run_fast_track_non_zero

    def test_object_run_fast_track_non_zero(self):
        self.auditor = auditor.ObjectAuditor(self.conf)
        self.auditor.log_time = 0
        data = "0" * 1024
        etag = md5()
        with self.disk_file.mkstemp() as (fd, tmppath):
            os.write(fd, data)
            etag.update(data)
            etag = etag.hexdigest()
            metadata = {
                "ETag": etag,
                "X-Timestamp": str(normalize_timestamp(time.time())),
                "Content-Length": str(os.fstat(fd).st_size),
            }
            self.disk_file.put(fd, tmppath, metadata)
            etag = md5()
            etag.update("1" + "0" * 1023)
            etag = etag.hexdigest()
            metadata["ETag"] = etag
            write_metadata(fd, metadata)

        quarantine_path = os.path.join(self.devices, "sda", "quarantined", "objects")
        self.auditor.run_once(zero_byte_fps=50)
        self.assertFalse(os.path.isdir(quarantine_path))
        self.auditor.run_once()
        self.assertTrue(os.path.isdir(quarantine_path))
开发者ID:jness,项目名称:python-swift,代码行数:26,代码来源:test_auditor.py

示例8: run_quarantine_zero_byte_head

    def run_quarantine_zero_byte_head(self):
        container = 'container-zbyte-%s' % uuid4()
        obj = 'object-zbyte-%s' % uuid4()
        onode, opart, data_file = self._setup_data_file(container, obj, 'DATA')
        with open(data_file) as fpointer:
            metadata = read_metadata(fpointer)
        unlink(data_file)

        with open(data_file, 'w') as fpointer:
            write_metadata(fpointer, metadata)
        try:
            direct_client.direct_head_object(onode, opart, self.account,
                                             container, obj, conn_timeout=1,
                                             response_timeout=1)
            raise Exception("Did not quarantine object")
        except client.ClientException, err:
            self.assertEquals(err.http_status, 404)
开发者ID:ChicoTeam,项目名称:swift,代码行数:17,代码来源:test_object_failures.py

示例9: run_quarantine

    def run_quarantine(self):
        container = 'container-%s' % uuid4()
        obj = 'object-%s' % uuid4()
        onode, opart, data_file = self._setup_data_file(container, obj,
                                                        'VERIFY')
        with open(data_file) as fp:
            metadata = read_metadata(fp)
        metadata['ETag'] = 'badetag'
        with open(data_file) as fp:
            write_metadata(fp, metadata)

        odata = direct_client.direct_get_object(onode, opart,
                                          self.account, container, obj)[-1]
        self.assertEquals(odata, 'VERIFY')
        try:
            resp = direct_client.direct_get_object(onode, opart, self.account,
                                                   container, obj)
            raise "Did not quarantine object"
        except client.ClientException, e:
            self.assertEquals(e.http_status, 404)
开发者ID:BillTheBest,项目名称:swift,代码行数:20,代码来源:test_object_failures.py

示例10: run_quarantine_zero_byte_post

    def run_quarantine_zero_byte_post(self):
        container = 'container-zbyte-%s' % uuid4()
        obj = 'object-zbyte-%s' % uuid4()
        onode, opart, data_file = self._setup_data_file(container, obj, 'DATA')
        with open(data_file) as fp:
            metadata = read_metadata(fp)
        os.unlink(data_file)

        with open(data_file, 'w') as fp:
            write_metadata(fp, metadata)
        try:
            resp = direct_client.direct_post_object(
                onode, opart, self.account,
                container, obj,
                {'X-Object-Meta-1': 'One', 'X-Object-Meta-Two': 'Two'},
                conn_timeout=1,
                response_timeout=1)
            raise "Did not quarantine object"
        except client.ClientException, e:
            self.assertEquals(e.http_status, 404)
开发者ID:BillTheBest,项目名称:swift,代码行数:20,代码来源:test_object_failures.py


注:本文中的swift.obj.server.write_metadata函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。