Esempio n. 1
0
 def test_unlinkold_no_metadata(self):
     assert not os.path.exists("/tmp/foo")
     gdf = DiskFile("/tmp/foo", "vol0", "p57", "ufo47", "bar",
                            "z", self.lg)
     assert gdf.metadata == {}
     _saved_rmobjdir = gluster.swift.obj.diskfile.rmobjdir
     gluster.swift.obj.diskfile.rmobjdir = _mock_rmobjdir
     try:
         gdf.unlinkold(None)
     except MockException as exp:
         self.fail(str(exp))
     finally:
         gluster.swift.obj.diskfile.rmobjdir = _saved_rmobjdir
Esempio n. 2
0
    def test_unlinkold_is_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 = DiskFile(td, "vol0", "p57", "ufo47", "bar",
                                   "d", self.lg, keep_data_fp=True)
            assert gdf.data_file == the_dir
            assert gdf._is_dir

            later = float(gdf.metadata['X-Timestamp']) + 1
            gdf.unlinkold(normalize_timestamp(later))
            assert os.path.isdir(gdf.datadir)
            assert not os.path.exists(os.path.join(gdf.datadir, gdf._obj))
        finally:
            shutil.rmtree(td)
Esempio n. 3
0
    def test_unlinkold_file(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 = 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
            gdf.unlinkold(normalize_timestamp(later))
            assert os.path.isdir(gdf.datadir)
            assert not os.path.exists(os.path.join(gdf.datadir, gdf._obj))
        finally:
            shutil.rmtree(td)
Esempio n. 4
0
    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 = 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

            def _mock_os_unlink_eacces_err(f):
                raise OSError(errno.EACCES, os.strerror(errno.EACCES))

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

                # Handle the case os_unlink() raises an OSError
                with patch("os.unlink", _mock_os_unlink_eacces_err):
                    try:
                        gdf.unlinkold(normalize_timestamp(later))
                    except OSError as e:
                        assert e.errno == errno.EACCES
                    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)