[Python-checkins] cpython (2.7): Issue #15747: skip chflags UF_IMMUTABLE tests if EOPNOTSUPP is raised.

victor.stinner python-checkins at python.org
Tue Dec 4 10:07:47 CET 2012


http://hg.python.org/cpython/rev/4beb1630544f
changeset:   80720:4beb1630544f
branch:      2.7
parent:      80717:6dc1f417ec56
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Tue Dec 04 10:07:16 2012 +0100
summary:
  Issue #15747: skip chflags UF_IMMUTABLE tests if EOPNOTSUPP is raised.

This is necessary for ZFS systems, which don't support UF_IMMUTABLE.
--
Kubilay Kocak (koobs) asked me on IRC to backport this fix to Python 2.7: done!

files:
  Lib/test/test_posix.py |  23 ++++++++++++++++++++---
  Misc/NEWS              |   4 ++++
  2 files changed, 24 insertions(+), 3 deletions(-)


diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py
--- a/Lib/test/test_posix.py
+++ b/Lib/test/test_posix.py
@@ -334,7 +334,16 @@
     def _test_chflags_regular_file(self, chflags_func, target_file):
         st = os.stat(target_file)
         self.assertTrue(hasattr(st, 'st_flags'))
-        chflags_func(target_file, st.st_flags | stat.UF_IMMUTABLE)
+
+        # ZFS returns EOPNOTSUPP when attempting to set flag UF_IMMUTABLE.
+        try:
+            chflags_func(target_file, st.st_flags | stat.UF_IMMUTABLE)
+        except OSError as err:
+            if err.errno != errno.EOPNOTSUPP:
+                raise
+            msg = 'chflag UF_IMMUTABLE not supported by underlying fs'
+            self.skipTest(msg)
+
         try:
             new_st = os.stat(target_file)
             self.assertEqual(st.st_flags | stat.UF_IMMUTABLE, new_st.st_flags)
@@ -363,8 +372,16 @@
         self.teardown_files.append(_DUMMY_SYMLINK)
         dummy_symlink_st = os.lstat(_DUMMY_SYMLINK)
 
-        posix.lchflags(_DUMMY_SYMLINK,
-                       dummy_symlink_st.st_flags | stat.UF_IMMUTABLE)
+        # ZFS returns EOPNOTSUPP when attempting to set flag UF_IMMUTABLE.
+        try:
+            posix.lchflags(_DUMMY_SYMLINK,
+                           dummy_symlink_st.st_flags | stat.UF_IMMUTABLE)
+        except OSError as err:
+            if err.errno != errno.EOPNOTSUPP:
+                raise
+            msg = 'chflag UF_IMMUTABLE not supported by underlying fs'
+            self.skipTest(msg)
+
         try:
             new_testfn_st = os.stat(test_support.TESTFN)
             new_dummy_symlink_st = os.lstat(_DUMMY_SYMLINK)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -530,6 +530,10 @@
 Tests
 -----
 
+- Issue #15747: ZFS always returns EOPNOTSUPP when attempting to set the
+  UF_IMMUTABLE flag (via either chflags or lchflags); refactor affected
+  tests in test_posix.py to account for this.
+
 - Issue #16549: Add tests for json.tools.  Initial patch by Berker Peksag
   and Serhiy Storchaka.
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list