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


Python DiskFile.Gluster_DiskFile类代码示例

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


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

示例1: test_get_data_file_size_os_err

 def test_get_data_file_size_os_err(self):
     td = tempfile.mkdtemp()
     the_path = os.path.join(td, "vol0", "bar")
     the_file = os.path.join(the_path, "z")
     try:
         os.makedirs(the_path)
         with open(the_file, "wb") as fd:
             fd.write("1234")
         gdf = Gluster_DiskFile(td, "vol0", "p57", "ufo47", "bar",
                                "z", self.lg)
         assert gdf._obj == "z"
         assert gdf.data_file == the_file
         assert not gdf._is_dir
         stats = os.stat(the_path)
         os.chmod(the_path, 0)
         __os_path_getsize = os.path.getsize
         os.path.getsize = _mock_getsize_eaccess_err
         try:
             s = gdf.get_data_file_size()
         except OSError as err:
             assert err.errno == errno.EACCES
         else:
             self.fail("Expected OSError exception")
         finally:
             os.path.getsize = __os_path_getsize
             os.chmod(the_path, stats.st_mode)
     finally:
         shutil.rmtree(td)
开发者ID:ajarr,项目名称:gluster-swift,代码行数:28,代码来源:test_diskfile.py

示例2: test_unlinkold_is_dir_failure

    def test_unlinkold_is_dir_failure(self):
        td = tempfile.mkdtemp()
        the_path = os.path.join(td, "vol0", "bar")
        the_dir = os.path.join(the_path, "d")
        try:
            os.makedirs(the_dir)
            gdf = Gluster_DiskFile(td, "vol0", "p57", "ufo47", "bar",
                                   "d", self.lg, keep_data_fp=True)
            assert gdf.data_file == the_dir
            assert gdf._is_dir

            stats = os.stat(gdf.datadir)
            os.chmod(gdf.datadir, 0)
            __os_rmdir = os.rmdir
            os.rmdir = _mock_do_rmdir_eacces_err
            try:
                later = float(gdf.metadata['X-Timestamp']) + 1
                gdf.unlinkold(normalize_timestamp(later))
            finally:
                os.chmod(gdf.datadir, stats.st_mode)
                os.rmdir = __os_rmdir
            assert os.path.isdir(gdf.datadir)
            self.assertTrue(gdf.data_file is None)
        finally:
            shutil.rmtree(td)
开发者ID:ajarr,项目名称:gluster-swift,代码行数:25,代码来源:test_diskfile.py

示例3: test_mkstemp

 def test_mkstemp(self):
     td = tempfile.mkdtemp()
     the_path = os.path.join(td, "vol0", "bar")
     the_dir = os.path.join(the_path, "dir")
     try:
         gdf = Gluster_DiskFile(td, "vol0", "p57", "ufo47", "bar",
                                "dir/z", self.lg)
         saved_tmppath = ''
         with gdf.mkstemp() as fd:
             assert gdf.datadir == os.path.join(td, "vol0", "bar", "dir")
             assert os.path.isdir(gdf.datadir)
             saved_tmppath = gdf.tmppath
             assert os.path.dirname(saved_tmppath) == gdf.datadir
             assert os.path.basename(saved_tmppath)[:3] == '.z.'
             assert os.path.exists(saved_tmppath)
             os.write(fd, "123")
         # At the end of previous with block a close on fd is called.
         # Calling os.close on the same fd will raise an OSError
         # exception and we must catch it.
         try:
             os.close(fd)
         except OSError as err:
             pass
         else:
             self.fail("Exception expected")
         assert not os.path.exists(saved_tmppath)
     finally:
         shutil.rmtree(td)
开发者ID:ajarr,项目名称:gluster-swift,代码行数:28,代码来源:test_diskfile.py

示例4: test_unlinkold_file_unlink_error

    def test_unlinkold_file_unlink_error(self):
        td = tempfile.mkdtemp()
        the_path = os.path.join(td, "vol0", "bar")
        the_file = os.path.join(the_path, "z")
        try:
            os.makedirs(the_path)
            with open(the_file, "wb") as fd:
                fd.write("1234")
            gdf = Gluster_DiskFile(td, "vol0", "p57", "ufo47", "bar",
                                   "z", self.lg)
            assert gdf._obj == "z"
            assert gdf.data_file == the_file
            assert not gdf._is_dir

            later = float(gdf.metadata['X-Timestamp']) + 1

            stats = os.stat(the_path)
            os.chmod(the_path, stats.st_mode & (~stat.S_IWUSR))

            # Handle the case do_unlink() raises an OSError
            try:
                gdf.unlinkold(normalize_timestamp(later))
            except OSError as e:
                assert e.errno != errno.ENOENT
            else:
                self.fail("Excepted an OSError when unlinking file")
            finally:
                os.chmod(the_path, stats.st_mode)

            assert os.path.isdir(gdf.datadir)
            assert os.path.exists(os.path.join(gdf.datadir, gdf._obj))
        finally:
            shutil.rmtree(td)
开发者ID:jayunit100,项目名称:glusterfs,代码行数:33,代码来源:test_diskfile.py

示例5: test_create_dir_object_exists

 def test_create_dir_object_exists(self):
     td = tempfile.mkdtemp()
     the_path = os.path.join(td, "vol0", "bar")
     the_dir = os.path.join(the_path, "dir")
     try:
         os.makedirs(the_path)
         with open(the_dir, "wb") as fd:
             fd.write("1234")
         gdf = Gluster_DiskFile(td, "vol0", "p57", "ufo47", "bar",
                                "dir/z", self.lg)
         # Not created, dir object path is different, just checking
         assert gdf._obj == "z"
         def _mock_do_chown(p, u, g):
             assert u == DEFAULT_UID
             assert g == DEFAULT_GID
         dc = gluster.swift.common.DiskFile.do_chown
         gluster.swift.common.DiskFile.do_chown = _mock_do_chown
         try:
             gdf._create_dir_object(the_dir)
         finally:
             gluster.swift.common.DiskFile.do_chown = dc
         assert os.path.isdir(the_dir)
         assert the_dir in _metadata
     finally:
         shutil.rmtree(td)
开发者ID:hfeeki,项目名称:glusterfs,代码行数:25,代码来源:test_diskfile.py

示例6: test_put

    def test_put(self):
        td = tempfile.mkdtemp()
        try:
            gdf = Gluster_DiskFile(td, "vol0", "p57", "ufo47", "bar", "z", self.lg)
            assert gdf._obj == "z"
            assert gdf._obj_path == ""
            assert gdf.name == "bar"
            assert gdf.datadir == os.path.join(td, "vol0", "bar")
            assert gdf.data_file is None

            body = "1234\n"
            etag = md5()
            etag.update(body)
            etag = etag.hexdigest()
            metadata = {"X-Timestamp": "1234", "Content-Type": "file", "ETag": etag, "Content-Length": "5"}

            with gdf.mkstemp() as fd:
                assert gdf.tmppath is not None
                tmppath = gdf.tmppath
                os.write(fd, body)
                gdf.put(fd, metadata)

            assert gdf.data_file == os.path.join(td, "vol0", "bar", "z")
            assert os.path.exists(gdf.data_file)
            assert not os.path.exists(tmppath)
        finally:
            shutil.rmtree(td)
开发者ID:portante,项目名称:glusterfs,代码行数:27,代码来源:test_diskfile.py

示例7: test_close

    def test_close(self):
        assert not os.path.exists("/tmp/foo")
        gdf = Gluster_DiskFile("/tmp/foo", "vol0", "p57", "ufo47", "bar",
                               "z", self.lg)
        # Should be a no-op, as by default is_dir is False, but fp is None
        gdf.close()

        gdf._is_dir = True
        gdf.fp = "123"
        # Should still be a no-op as is_dir is True (marker directory)
        gdf.close()
        assert gdf.fp == "123"

        gdf._is_dir = False
        saved_dc = gluster.swift.common.DiskFile.do_close
        self.called = False
        def our_do_close(fp):
            self.called = True
        gluster.swift.common.DiskFile.do_close = our_do_close
        try:
            gdf.close()
            assert self.called
            assert gdf.fp is None
        finally:
            gluster.swift.common.DiskFile.do_close = saved_dc
开发者ID:ajarr,项目名称:gluster-swift,代码行数:25,代码来源:test_diskfile.py

示例8: test_is_deleted

 def test_is_deleted(self):
     assert not os.path.exists("/tmp/foo")
     gdf = Gluster_DiskFile("/tmp/foo", "vol0", "p57", "ufo47", "bar",
                            "z", self.lg)
     assert gdf.is_deleted()
     gdf.data_file = "/tmp/foo/bar"
     assert not gdf.is_deleted()
开发者ID:ajarr,项目名称:gluster-swift,代码行数:7,代码来源:test_diskfile.py

示例9: test_put_w_tombstone

    def test_put_w_tombstone(self):
        assert not os.path.exists("/tmp/foo")
        gdf = Gluster_DiskFile("/tmp/foo", "vol0", "p57", "ufo47", "bar", "z", self.lg)
        assert gdf.metadata == {}

        gdf.put_metadata({"x": "1"}, tombstone=True)
        assert gdf.metadata == {}
开发者ID:portante,项目名称:glusterfs,代码行数:7,代码来源:test_diskfile.py

示例10: test_put_obj_path

    def test_put_obj_path(self):
        the_obj_path = os.path.join("b", "a")
        the_file = os.path.join(the_obj_path, "z")
        td = tempfile.mkdtemp()
        try:
            gdf = Gluster_DiskFile(td, "vol0", "p57", "ufo47", "bar",
                                   the_file, self.lg)
            assert gdf._obj == "z"
            assert gdf._obj_path == the_obj_path
            assert gdf.name == os.path.join("bar", "b", "a")
            assert gdf.datadir == os.path.join(td, "vol0", "bar", "b", "a")
            assert gdf.data_file is None

            body = '1234\n'
            etag = md5()
            etag.update(body)
            etag = etag.hexdigest()
            metadata = {
                'X-Timestamp': '1234',
                'Content-Type': 'file',
                'ETag': etag,
                'Content-Length': '5',
                }

            with gdf.mkstemp() as fd:
                assert gdf.tmppath is not None
                tmppath = gdf.tmppath
                os.write(fd, body)
                gdf.put(fd, metadata)

            assert gdf.data_file == os.path.join(td, "vol0", "bar", "b", "a", "z")
            assert os.path.exists(gdf.data_file)
            assert not os.path.exists(tmppath)
        finally:
            shutil.rmtree(td)
开发者ID:ajarr,项目名称:gluster-swift,代码行数:35,代码来源:test_diskfile.py

示例11: test_put_is_dir

 def test_put_is_dir(self):
     td = tempfile.mkdtemp()
     the_path = os.path.join(td, "vol0", "bar")
     the_dir = os.path.join(the_path, "dir")
     try:
         os.makedirs(the_dir)
         gdf = Gluster_DiskFile(td, "vol0", "p57", "ufo47", "bar",
                                "dir", self.lg)
         origmd = gdf.metadata.copy()
         origfmd = _metadata[the_dir]
         newmd = gdf.metadata.copy()
         # FIXME: This is a hack to get to the code-path; it is not clear
         # how this can happen normally.
         newmd['Content-Type'] = ''
         newmd['X-Object-Meta-test'] = '1234'
         try:
             gdf.put(None, newmd, extension='.data')
         except AlreadyExistsAsDir:
             pass
         else:
             self.fail("Expected to encounter 'already-exists-as-dir' exception")
         assert gdf.metadata == origmd
         assert _metadata[the_dir] == origfmd
     finally:
         shutil.rmtree(td)
开发者ID:ajarr,项目名称:gluster-swift,代码行数:25,代码来源:test_diskfile.py

示例12: test_get_data_file_size_dne

 def test_get_data_file_size_dne(self):
     assert not os.path.exists("/tmp/foo")
     gdf = Gluster_DiskFile("/tmp/foo", "vol0", "p57", "ufo47", "bar", "/b/a/z/", self.lg)
     try:
         s = gdf.get_data_file_size()
     except DiskFileNotExist:
         pass
     else:
         self.fail("Expected DiskFileNotExist exception")
开发者ID:portante,项目名称:glusterfs,代码行数:9,代码来源:test_diskfile.py

示例13: test_create_dir_object

 def test_create_dir_object(self):
     td = tempfile.mkdtemp()
     the_dir = os.path.join(td, "vol0", "bar", "dir")
     try:
         gdf = Gluster_DiskFile(td, "vol0", "p57", "ufo47", "bar", "dir/z", self.lg)
         # Not created, dir object path is different, just checking
         assert gdf._obj == "z"
         gdf._create_dir_object(the_dir)
         assert os.path.isdir(the_dir)
         assert the_dir in _metadata
     finally:
         shutil.rmtree(td)
开发者ID:portante,项目名称:glusterfs,代码行数:12,代码来源:test_diskfile.py

示例14: test_unlinkold_no_metadata

 def test_unlinkold_no_metadata(self):
     assert not os.path.exists("/tmp/foo")
     gdf = Gluster_DiskFile("/tmp/foo", "vol0", "p57", "ufo47", "bar",
                            "z", self.lg)
     assert gdf.metadata == {}
     _saved_rmobjdir = gluster.swift.common.DiskFile.rmobjdir
     gluster.swift.common.DiskFile.rmobjdir = _mock_rmobjdir
     try:
         gdf.unlinkold(None)
     except MockException as exp:
         self.fail(str(exp))
     finally:
         gluster.swift.common.DiskFile.rmobjdir = _saved_rmobjdir
开发者ID:ajarr,项目名称:gluster-swift,代码行数:13,代码来源:test_diskfile.py

示例15: test_get_data_file_size_dir

 def test_get_data_file_size_dir(self):
     td = tempfile.mkdtemp()
     the_path = os.path.join(td, "vol0", "bar")
     the_dir = os.path.join(the_path, "d")
     try:
         os.makedirs(the_dir)
         gdf = Gluster_DiskFile(td, "vol0", "p57", "ufo47", "bar", "d", self.lg, keep_data_fp=True)
         assert gdf._obj == "d"
         assert gdf.data_file == the_dir
         assert gdf._is_dir
         assert 0 == gdf.get_data_file_size()
     finally:
         shutil.rmtree(td)
开发者ID:portante,项目名称:glusterfs,代码行数:13,代码来源:test_diskfile.py


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