Merge lp:~vila/bzr/646133-selftest-as-root into lp:bzr/2.1

Proposed by Vincent Ladeuil
Status: Merged
Approved by: John A Meinel
Approved revision: no longer in the source branch.
Merged at revision: 4861
Proposed branch: lp:~vila/bzr/646133-selftest-as-root
Merge into: lp:bzr/2.1
Diff against target: 127 lines (+28/-4)
6 files modified
NEWS (+3/-0)
bzrlib/tests/features.py (+16/-0)
bzrlib/tests/per_lock/test_lock.py (+2/-1)
bzrlib/tests/test_lockdir.py (+2/-1)
bzrlib/tests/test_osutils.py (+2/-0)
bzrlib/tests/test_selftest.py (+3/-2)
To merge this branch: bzr merge lp:~vila/bzr/646133-selftest-as-root
Reviewer Review Type Date Requested Status
John A Meinel Approve
Review via email: mp+36470@code.launchpad.net

Commit message

Skip chmod bits dependent tests when running as root

Description of the change

This fix the remaining failures in the test suite for 2.1 when running as root (bug #646133).
Some tests are creating files with 000 mode bits or 400 to exercise the code that tries to read or write them. 'root' doesn't care, so there is no point trying to run them.

I also fixed an old bug in test_selftest which has already been fixed in later releases. This is not strictly related but... doesn't deserve a dedicated merge proposal either.

To post a comment you must log in.
Revision history for this message
John A Meinel (jameinel) wrote :

Just to clarify, we need to run as root because the buildd's run everything as root. (seems silly/foolish).

Anyway, the change looks good to me.

review: Approve
Revision history for this message
Vincent Ladeuil (vila) wrote :

sent to pqm by email

Revision history for this message
Martin Pool (mbp) wrote :

That looks ok. I wonder what happens on Windows? It probably says
False even if you are an administrator, though these particular chmod
tests probably won't run there anyhow?

Could you mention this in testing.txt too please?

Revision history for this message
Vincent Ladeuil (vila) wrote :

windows raise an AttributeError when calling getuid() so it *will* return False.
Good point about testing.txt, I'll do that before landing.

Revision history for this message
Vincent Ladeuil (vila) wrote :

meh, already merged... Well, I'll do that when merging in bzr.dev then.

Revision history for this message
John A Meinel (jameinel) wrote :

Um, check your code again. It will return *True* on Windows.

+ def _probe(self):
+ try:
+ uid = os.getuid()
+ except AttributeError:
+ # If there is no uid, chances are there is no root either
+ return True
+ return uid != 0

But then again, notice that you are using a negative "NotRunningAsRoot".

Revision history for this message
Vincent Ladeuil (vila) wrote :

Meh, lol, yeah I didn't re-read the code and replied to Martin, I think we all agree the behaviour is the expected one on windows: not_running_as_root is always True. Now whether it's better to be wrong when you're right or right when you're wrong is left as an exercise for the philosopher ;)

Some of the tests I modified *also* check for the supports_posix_readonly feature which see *OR* are already skipped on windows.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2010-09-17 19:58:09 +0000
3+++ NEWS 2010-09-23 16:41:25 +0000
4@@ -19,6 +19,9 @@
5 Bug Fixes
6 *********
7
8+* Skip the tests that requires respecting the chmod bits when running as root.
9+ (Vincent Ladeuil, #646133)
10+
11 Improvements
12 ************
13
14
15=== modified file 'bzrlib/tests/features.py'
16--- bzrlib/tests/features.py 2010-02-17 17:11:16 +0000
17+++ bzrlib/tests/features.py 2010-09-23 16:41:25 +0000
18@@ -14,11 +14,27 @@
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
22+import os
23
24 from bzrlib import tests
25 from bzrlib.symbol_versioning import deprecated_in
26
27
28+class _NotRunningAsRoot(tests.Feature):
29+
30+ def _probe(self):
31+ try:
32+ uid = os.getuid()
33+ except AttributeError:
34+ # If there is no uid, chances are there is no root either
35+ return True
36+ return uid != 0
37+
38+ def feature_name(self):
39+ return 'Not running as root'
40+
41+
42+not_running_as_root = _NotRunningAsRoot()
43 apport = tests.ModuleAvailableFeature('apport')
44 ApportFeature = tests._CompatabilityThunkFeature('bzrlib.tests.features',
45 'ApportFeature', 'bzrlib.tests.features.apport', deprecated_in((2,1,0)))
46
47=== modified file 'bzrlib/tests/per_lock/test_lock.py'
48--- bzrlib/tests/per_lock/test_lock.py 2009-07-07 09:00:59 +0000
49+++ bzrlib/tests/per_lock/test_lock.py 2010-09-23 16:41:25 +0000
50@@ -21,7 +21,7 @@
51 osutils,
52 )
53
54-from bzrlib.tests import UnicodeFilenameFeature
55+from bzrlib.tests import (features, UnicodeFilenameFeature)
56 from bzrlib.tests.per_lock import TestCaseWithLock
57
58
59@@ -63,6 +63,7 @@
60
61 But we shouldn't be able to take a write lock.
62 """
63+ self.requireFeature(features.not_running_as_root)
64 osutils.make_readonly('a-file')
65 # Make sure the file is read-only (on all platforms)
66 self.assertRaises(IOError, open, 'a-file', 'rb+')
67
68=== modified file 'bzrlib/tests/test_lockdir.py'
69--- bzrlib/tests/test_lockdir.py 2010-09-10 05:13:57 +0000
70+++ bzrlib/tests/test_lockdir.py 2010-09-23 16:41:25 +0000
71@@ -39,7 +39,7 @@
72 LockNotHeld,
73 )
74 from bzrlib.lockdir import LockDir
75-from bzrlib.tests import TestCaseWithTransport
76+from bzrlib.tests import (features, TestCaseWithTransport)
77 from bzrlib.trace import note
78
79 # These tests sometimes use threads to test the behaviour of lock files with
80@@ -669,6 +669,7 @@
81 ld1.unlock()
82
83 def test_lock_permission(self):
84+ self.requireFeature(features.not_running_as_root)
85 if not osutils.supports_posix_readonly():
86 raise tests.TestSkipped('Cannot induce a permission failure')
87 ld1 = self.get_lock()
88
89=== modified file 'bzrlib/tests/test_osutils.py'
90--- bzrlib/tests/test_osutils.py 2010-05-27 04:00:01 +0000
91+++ bzrlib/tests/test_osutils.py 2010-09-23 16:41:25 +0000
92@@ -33,6 +33,7 @@
93 win32utils,
94 )
95 from bzrlib.tests import (
96+ features,
97 file_utils,
98 test__walkdirs_win32,
99 )
100@@ -1067,6 +1068,7 @@
101 if sys.platform == 'win32':
102 raise tests.TestNotApplicable(
103 "readdir IOError not tested on win32")
104+ self.requireFeature(features.not_running_as_root)
105 os.mkdir("test-unreadable")
106 os.chmod("test-unreadable", 0000)
107 # must chmod it back so that it can be removed
108
109=== modified file 'bzrlib/tests/test_selftest.py'
110--- bzrlib/tests/test_selftest.py 2010-02-17 17:11:16 +0000
111+++ bzrlib/tests/test_selftest.py 2010-09-23 16:41:25 +0000
112@@ -609,12 +609,13 @@
113 l.attempt_lock()
114 test = TestDanglingLock('test_function')
115 result = test.run()
116+ total_failures = result.errors + result.failures
117 if self._lock_check_thorough:
118- self.assertEqual(1, len(result.errors))
119+ self.assertEqual(1, len(total_failures))
120 else:
121 # When _lock_check_thorough is disabled, then we don't trigger a
122 # failure
123- self.assertEqual(0, len(result.errors))
124+ self.assertEqual(0, len(total_failures))
125
126
127 class TestTestCaseWithTransport(tests.TestCaseWithTransport):

Subscribers

People subscribed via source and target branches