예제 #1
0
    def test_do_ismount_successes_ino(self):

        _os_lstat = os.lstat

        class MockStat(object):
            def __init__(self, mode, dev, ino):
                self.st_mode = mode
                self.st_dev = dev
                self.st_ino = ino

        def _mock_os_lstat(path):
            if path.endswith(".."):
                return _os_lstat(path)
            else:
                parent_path = os.path.join(path, "..")
                child = _os_lstat(path)
                parent = _os_lstat(parent_path)
                return MockStat(child.st_mode, parent.st_ino, child.st_dev)

        tmpdir = mkdtemp()
        try:
            with patch("os.lstat", _mock_os_lstat):
                try:
                    fs.do_ismount(tmpdir)
                except FileConnectorFileSystemOSError:
                    self.fail("Unexpected exception")
                else:
                    pass
        finally:
            shutil.rmtree(tmpdir)
예제 #2
0
    def test_do_ismount_path_error(self):
        def _mock_os_lstat(path):
            raise OSError(13, "foo")

        tmpdir = mkdtemp()
        try:
            with patch("os.lstat", _mock_os_lstat):
                try:
                    fs.do_ismount(tmpdir)
                except FileConnectorFileSystemOSError:
                    pass
                else:
                    self.fail("Expected FileConnectorFileSystemOSError")
        finally:
            shutil.rmtree(tmpdir)
예제 #3
0
    def _create_expiring_tracker_object(self, object_path):
        try:

            # Check if gsexpiring volume is present in ring
            if not any(d.get('device', None) == self.expiring_objects_account
                       for d in self.object_ring.devs):
                raise Exception("%s volume not in ring" %
                                self.expiring_objects_account)

            # Check if gsexpiring is mounted.
            expiring_objects_account_path = \
                os.path.join(self.devices, self.expiring_objects_account)
            mount_check = self._diskfile_router['junk'].mount_check
            if mount_check and not do_ismount(expiring_objects_account_path):
                raise Exception("Path %s doesn't exist or is not a mount "
                                "point" % expiring_objects_account_path)

            # Create object directory
            object_dir = os.path.dirname(object_path)
            try:
                mkdirs(object_dir)
            except OSError as err:
                mkdirs(object_dir)  # handle race

            # Create zero-byte file
            try:
                os.mknod(object_path)
            except OSError as err:
                if err.errno != errno.EEXIST:
                    raise
        except Exception as e:
            self.logger.error("Creation of tracker object %s failed: %s" %
                              (object_path, str(e)))
예제 #4
0
 def test_do_ismount_path_is_symlink(self):
     tmpdir = mkdtemp()
     try:
         link = os.path.join(tmpdir, "tmp")
         os.symlink("/tmp", link)
         assert False == fs.do_ismount(link)
     finally:
         shutil.rmtree(tmpdir)
예제 #5
0
 def test_do_ismount_path_not_mount(self):
     tmpdir = mkdtemp()
     try:
         assert False == fs.do_ismount(tmpdir)
     finally:
         shutil.rmtree(tmpdir)
예제 #6
0
 def test_do_ismount_path_does_not_exist(self):
     tmpdir = mkdtemp()
     try:
         assert False == fs.do_ismount(os.path.join(tmpdir, 'bar'))
     finally:
         shutil.rmtree(tmpdir)
예제 #7
0
 def test_do_ismount_path_is_root(self):
     assert True == fs.do_ismount('/')