Beispiel #1
0
    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)
Beispiel #2
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 = 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)
Beispiel #3
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 = 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)
Beispiel #4
0
 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
Beispiel #5
0
 def test_unlinkold_same_timestamp(self):
     assert not os.path.exists("/tmp/foo")
     gdf = Gluster_DiskFile("/tmp/foo", "vol0", "p57", "ufo47", "bar",
                            "z", self.lg)
     assert gdf.metadata == {}
     gdf.metadata['X-Timestamp'] = 1
     _saved_rmdirs = gluster.swift.common.DiskFile.rmdirs
     gluster.swift.common.DiskFile.rmdirs = _mock_rmdirs
     try:
         gdf.unlinkold(1)
     except MockException as exp:
         self.fail(str(exp))
     finally:
         gluster.swift.common.DiskFile.rmdirs = _saved_rmdirs
Beispiel #6
0
 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_rmdirs = gluster.swift.common.DiskFile.rmdirs
     _saved_do_listdir = gluster.swift.common.DiskFile.do_listdir
     gluster.swift.common.DiskFile.rmdirs = _mock_rmdirs
     gluster.swift.common.DiskFile.do_listdir = _mock_do_listdir
     try:
         gdf.unlinkold(None)
     except MockException as exp:
         self.fail(str(exp))
     finally:
         gluster.swift.common.DiskFile.rmdirs = _saved_rmdirs
         gluster.swift.common.DiskFile.do_listdir = _saved_do_listdir
Beispiel #7
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 = Gluster_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)
Beispiel #8
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 = Gluster_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)
Beispiel #9
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 = 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
            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)
Beispiel #10
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 = 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
            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)