Repository: borgbackup/borg

Issue:
centos7 fuse test fail
```
[vagrant@localhost ~]$ sudo chmod 666 /dev/fuse
(borg-env) [vagrant@localhost borg]$ py.test -k fuse
============================= test session starts ==============================
platform linux -- Python 3.5.2, pytest-3.0.3, py-1.4.31, pluggy-0.4.0
benchmark: 3.0.0 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=5.00us max_time=1.00s calibration_precision=10 warmup=False warmup_iterations=100000)
rootdir: /vagrant/borg/borg, inifile: setup.cfg
plugins: benchmark-3.0.0, cov-2.4.0
collected 592 items 

borg/testsuite/archiver.py F.ssF.

=================================== FAILURES ===================================
__________________________ ArchiverTestCase.test_fuse __________________________

self = <borg.testsuite.archiver.ArchiverTestCase testMethod=test_fuse>

    @unittest.skipUnless(has_llfuse, 'llfuse not installed')
    def test_fuse(self):
        def has_noatime(some_file):
            atime_before = os.stat(some_file).st_atime_ns
            try:
                os.close(os.open(some_file, flags_noatime))
            except PermissionError:
                return False
            else:
                atime_after = os.stat(some_file).st_atime_ns
                noatime_used = flags_noatime != flags_normal
                return noatime_used and atime_before == atime_after

        self.cmd('init', self.repository_location)
        self.create_test_files()
        have_noatime = has_noatime('input/file1')
        self.cmd('create', self.repository_location + '::archive', 'input')
        self.cmd('create', self.repository_location + '::archive2', 'input')
        if has_lchflags:
            # remove the file we did not backup, so input and mount become equal
            os.remove(os.path.join('input', 'flagfile'))
        mountpoint = os.path.join(self.tmpdir, 'mountpoint')
        # mount the whole repository, archive contents shall show up in archivename subdirs of mountpoint:
        with self.fuse_mount(self.repository_location, mountpoint):
>           self.assert_dirs_equal(self.input_path, os.path.join(mountpoint, 'archive', 'input'))

borg/testsuite/archiver.py:1042: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
borg/testsuite/__init__.py:56: in assert_dirs_equal
    self._assert_dirs_equal_cmp(diff)
borg/testsuite/__init__.py:92: in _assert_dirs_equal_cmp
    self.assert_equal(d1, d2)
E   AssertionError: Lists differ: ['emp[56 chars]security.selinux': b'unconfined_u:object_r:user_tmp_t:s0\x00'}] != ['emp[56 chars]security.selinux': b'system_u:object_r:fusefs_t:s0\x00'}]
E   
E   First differing element 7:
E   {'security.selinux': b'unconfined_u:object_r:user_tmp_t:s0\x00'}
E   {'security.selinux': b'system_u:object_r:fusefs_t:s0\x00'}
E   
E     ['empty',
E      33152,
E      1000,
E      1000,
E      None,
E      1,
E      2147483647000000000,
E   -  {'security.selinux': b'unconfined_u:object_r:user_tmp_t:s0\x00'}]
E   ?                         ^^^^^^^^ ^               ^^^^^
E   
E   +  {'security.selinux': b'system_u:object_r:fusefs_t:s0\x00'}]
E   ?                         ^^^^ ^            +   ^^
_______________________ RemoteArchiverTestCase.test_fuse _______________________

self = <borg.testsuite.archiver.RemoteArchiverTestCase testMethod=test_fuse>

    @unittest.skipUnless(has_llfuse, 'llfuse not installed')
    def test_fuse(self):
        def has_noatime(some_file):
            atime_before = os.stat(some_file).st_atime_ns
            try:
                os.close(os.open(some_file, flags_noatime))
            except PermissionError:
                return False
            else:
                atime_after = os.stat(some_file).st_atime_ns
                noatime_used = flags_noatime != flags_normal
                return noatime_used and atime_before == atime_after

        self.cmd('init', self.repository_location)
        self.create_test_files()
        have_noatime = has_noatime('input/file1')
        self.cmd('create', self.repository_location + '::archive', 'input')
        self.cmd('create', self.repository_location + '::archive2', 'input')
        if has_lchflags:
            # remove the file we did not backup, so input and mount become equal
            os.remove(os.path.join('input', 'flagfile'))
        mountpoint = os.path.join(self.tmpdir, 'mountpoint')
        # mount the whole repository, archive contents shall show up in archivename subdirs of mountpoint:
        with self.fuse_mount(self.repository_location, mountpoint):
>           self.assert_dirs_equal(self.input_path, os.path.join(mountpoint, 'archive', 'input'))

borg/testsuite/archiver.py:1042: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
borg/testsuite/__init__.py:56: in assert_dirs_equal
    self._assert_dirs_equal_cmp(diff)
borg/testsuite/__init__.py:92: in _assert_dirs_equal_cmp
    self.assert_equal(d1, d2)
E   AssertionError: Lists differ: ['emp[56 chars]security.selinux': b'unconfined_u:object_r:user_tmp_t:s0\x00'}] != ['emp[56 chars]security.selinux': b'system_u:object_r:fusefs_t:s0\x00'}]
E   
E   First differing element 7:
E   {'security.selinux': b'unconfined_u:object_r:user_tmp_t:s0\x00'}
E   {'security.selinux': b'system_u:object_r:fusefs_t:s0\x00'}
E   
E     ['empty',
E      33152,
E      1000,
E      1000,
E      None,
E      1,
E      2147483647000000000,
E   -  {'security.selinux': b'unconfined_u:object_r:user_tmp_t:s0\x00'}]
E   ?                         ^^^^^^^^ ^               ^^^^^
E   
E   +  {'security.selinux': b'system_u:object_r:fusefs_t:s0\x00'}]
E   ?                         ^^^^ ^            +   ^^
```



Discussion:

Resolving patch:
diff --git a/borg/testsuite/__init__.py b/borg/testsuite/__init__.py
--- a/borg/testsuite/__init__.py
+++ b/borg/testsuite/__init__.py
@@ -35,6 +35,15 @@
 setup_logging()
 
 
+def no_selinux(x):
+    # selinux fails our FUSE tests, thus ignore selinux xattrs
+    SELINUX_KEY = 'security.selinux'
+    if isinstance(x, dict):
+        return {k: v for k, v in x.items() if k != SELINUX_KEY}
+    if isinstance(x, list):
+        return [k for k in x if k != SELINUX_KEY]
+
+
 class BaseTestCase(unittest.TestCase):
     """
     """
@@ -87,8 +96,8 @@ def _assert_dirs_equal_cmp(self, diff):
             else:
                 d1.append(round(s1.st_mtime_ns, st_mtime_ns_round))
                 d2.append(round(s2.st_mtime_ns, st_mtime_ns_round))
-            d1.append(get_all(path1, follow_symlinks=False))
-            d2.append(get_all(path2, follow_symlinks=False))
+            d1.append(no_selinux(get_all(path1, follow_symlinks=False)))
+            d2.append(no_selinux(get_all(path2, follow_symlinks=False)))
             self.assert_equal(d1, d2)
         for sub_diff in diff.subdirs.values():
             self._assert_dirs_equal_cmp(sub_diff)
diff --git a/borg/testsuite/archiver.py b/borg/testsuite/archiver.py
--- a/borg/testsuite/archiver.py
+++ b/borg/testsuite/archiver.py
@@ -26,7 +26,7 @@
 from ..keymanager import RepoIdMismatch, NotABorgKeyFile
 from ..remote import RemoteRepository, PathNotAllowed
 from ..repository import Repository
-from . import BaseTestCase, changedir, environment_variable
+from . import BaseTestCase, changedir, environment_variable, no_selinux
 
 try:
     import llfuse
@@ -1067,7 +1067,7 @@ def has_noatime(some_file):
             in_fn = 'input/fusexattr'
             out_fn = os.path.join(mountpoint, 'input', 'fusexattr')
             if not xattr.XATTR_FAKEROOT and xattr.is_enabled(self.input_path):
-                assert xattr.listxattr(out_fn) == ['user.foo', ]
+                assert no_selinux(xattr.listxattr(out_fn)) == ['user.foo', ]
                 assert xattr.getxattr(out_fn, 'user.foo') == b'bar'
             else:
                 assert xattr.listxattr(out_fn) == []


Test patch: