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
=== modified file 'NEWS'
--- NEWS 2010-09-17 19:58:09 +0000
+++ NEWS 2010-09-23 16:41:25 +0000
@@ -19,6 +19,9 @@
19Bug Fixes19Bug Fixes
20*********20*********
2121
22* Skip the tests that requires respecting the chmod bits when running as root.
23 (Vincent Ladeuil, #646133)
24
22Improvements25Improvements
23************26************
2427
2528
=== modified file 'bzrlib/tests/features.py'
--- bzrlib/tests/features.py 2010-02-17 17:11:16 +0000
+++ bzrlib/tests/features.py 2010-09-23 16:41:25 +0000
@@ -14,11 +14,27 @@
14# along with this program; if not, write to the Free Software14# along with this program; if not, write to the Free Software
15# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA15# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1616
17import os
1718
18from bzrlib import tests19from bzrlib import tests
19from bzrlib.symbol_versioning import deprecated_in20from bzrlib.symbol_versioning import deprecated_in
2021
2122
23class _NotRunningAsRoot(tests.Feature):
24
25 def _probe(self):
26 try:
27 uid = os.getuid()
28 except AttributeError:
29 # If there is no uid, chances are there is no root either
30 return True
31 return uid != 0
32
33 def feature_name(self):
34 return 'Not running as root'
35
36
37not_running_as_root = _NotRunningAsRoot()
22apport = tests.ModuleAvailableFeature('apport')38apport = tests.ModuleAvailableFeature('apport')
23ApportFeature = tests._CompatabilityThunkFeature('bzrlib.tests.features',39ApportFeature = tests._CompatabilityThunkFeature('bzrlib.tests.features',
24 'ApportFeature', 'bzrlib.tests.features.apport', deprecated_in((2,1,0)))40 'ApportFeature', 'bzrlib.tests.features.apport', deprecated_in((2,1,0)))
2541
=== modified file 'bzrlib/tests/per_lock/test_lock.py'
--- bzrlib/tests/per_lock/test_lock.py 2009-07-07 09:00:59 +0000
+++ bzrlib/tests/per_lock/test_lock.py 2010-09-23 16:41:25 +0000
@@ -21,7 +21,7 @@
21 osutils,21 osutils,
22 )22 )
2323
24from bzrlib.tests import UnicodeFilenameFeature24from bzrlib.tests import (features, UnicodeFilenameFeature)
25from bzrlib.tests.per_lock import TestCaseWithLock25from bzrlib.tests.per_lock import TestCaseWithLock
2626
2727
@@ -63,6 +63,7 @@
6363
64 But we shouldn't be able to take a write lock.64 But we shouldn't be able to take a write lock.
65 """65 """
66 self.requireFeature(features.not_running_as_root)
66 osutils.make_readonly('a-file')67 osutils.make_readonly('a-file')
67 # Make sure the file is read-only (on all platforms)68 # Make sure the file is read-only (on all platforms)
68 self.assertRaises(IOError, open, 'a-file', 'rb+')69 self.assertRaises(IOError, open, 'a-file', 'rb+')
6970
=== modified file 'bzrlib/tests/test_lockdir.py'
--- bzrlib/tests/test_lockdir.py 2010-09-10 05:13:57 +0000
+++ bzrlib/tests/test_lockdir.py 2010-09-23 16:41:25 +0000
@@ -39,7 +39,7 @@
39 LockNotHeld,39 LockNotHeld,
40 )40 )
41from bzrlib.lockdir import LockDir41from bzrlib.lockdir import LockDir
42from bzrlib.tests import TestCaseWithTransport42from bzrlib.tests import (features, TestCaseWithTransport)
43from bzrlib.trace import note43from bzrlib.trace import note
4444
45# These tests sometimes use threads to test the behaviour of lock files with45# These tests sometimes use threads to test the behaviour of lock files with
@@ -669,6 +669,7 @@
669 ld1.unlock()669 ld1.unlock()
670670
671 def test_lock_permission(self):671 def test_lock_permission(self):
672 self.requireFeature(features.not_running_as_root)
672 if not osutils.supports_posix_readonly():673 if not osutils.supports_posix_readonly():
673 raise tests.TestSkipped('Cannot induce a permission failure')674 raise tests.TestSkipped('Cannot induce a permission failure')
674 ld1 = self.get_lock()675 ld1 = self.get_lock()
675676
=== modified file 'bzrlib/tests/test_osutils.py'
--- bzrlib/tests/test_osutils.py 2010-05-27 04:00:01 +0000
+++ bzrlib/tests/test_osutils.py 2010-09-23 16:41:25 +0000
@@ -33,6 +33,7 @@
33 win32utils,33 win32utils,
34 )34 )
35from bzrlib.tests import (35from bzrlib.tests import (
36 features,
36 file_utils,37 file_utils,
37 test__walkdirs_win32,38 test__walkdirs_win32,
38 )39 )
@@ -1067,6 +1068,7 @@
1067 if sys.platform == 'win32':1068 if sys.platform == 'win32':
1068 raise tests.TestNotApplicable(1069 raise tests.TestNotApplicable(
1069 "readdir IOError not tested on win32")1070 "readdir IOError not tested on win32")
1071 self.requireFeature(features.not_running_as_root)
1070 os.mkdir("test-unreadable")1072 os.mkdir("test-unreadable")
1071 os.chmod("test-unreadable", 0000)1073 os.chmod("test-unreadable", 0000)
1072 # must chmod it back so that it can be removed1074 # must chmod it back so that it can be removed
10731075
=== modified file 'bzrlib/tests/test_selftest.py'
--- bzrlib/tests/test_selftest.py 2010-02-17 17:11:16 +0000
+++ bzrlib/tests/test_selftest.py 2010-09-23 16:41:25 +0000
@@ -609,12 +609,13 @@
609 l.attempt_lock()609 l.attempt_lock()
610 test = TestDanglingLock('test_function')610 test = TestDanglingLock('test_function')
611 result = test.run()611 result = test.run()
612 total_failures = result.errors + result.failures
612 if self._lock_check_thorough:613 if self._lock_check_thorough:
613 self.assertEqual(1, len(result.errors))614 self.assertEqual(1, len(total_failures))
614 else:615 else:
615 # When _lock_check_thorough is disabled, then we don't trigger a616 # When _lock_check_thorough is disabled, then we don't trigger a
616 # failure617 # failure
617 self.assertEqual(0, len(result.errors))618 self.assertEqual(0, len(total_failures))
618619
619620
620class TestTestCaseWithTransport(tests.TestCaseWithTransport):621class TestTestCaseWithTransport(tests.TestCaseWithTransport):

Subscribers

People subscribed via source and target branches