Merge lp:~vila/u1-test-utils/sudo-opt-in into lp:u1-test-utils

Proposed by Vincent Ladeuil
Status: Merged
Approved by: Vincent Ladeuil
Approved revision: 95
Merged at revision: 96
Proposed branch: lp:~vila/u1-test-utils/sudo-opt-in
Merge into: lp:u1-test-utils
Diff against target: 102 lines (+17/-14)
2 files modified
setup_vm/tests/__init__.py (+11/-8)
setup_vm/tests/test_setup_vm.py (+6/-6)
To merge this branch: bzr merge lp:~vila/u1-test-utils/sudo-opt-in
Reviewer Review Type Date Requested Status
Natalia Bidart (community) Approve
Leo Arias (community) code review Approve
Review via email: mp+179952@code.launchpad.net

Commit message

Tests requiring sudo should use an opt-in mechanism, nobody should blindly accept running them.

Description of the change

sudo access is hard to guess but it doesn't imply the user want to use it during tests.

This use ~/.setup_vm.use_sudo_for_tests as an opt-in mechanism instead.

To post a comment you must log in.
Revision history for this message
Leo Arias (elopio) :
review: Approve (code review)
Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Looks good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'setup_vm/tests/__init__.py'
2--- setup_vm/tests/__init__.py 2013-08-08 10:10:01 +0000
3+++ setup_vm/tests/__init__.py 2013-08-13 16:04:05 +0000
4@@ -133,29 +133,32 @@
5 qemu_img_feature = ExecutableFeature('qemu-img')
6
7
8-class _SudoFeature(Feature):
9+class _UseSudoForTestsFeature(Feature):
10 """User has sudo access.
11
12 There is no direct way to test for sudo access other than trying to use
13 it. This is not something we can do in automated tests as it requires user
14 input.
15
16- Instead, we look for '~/.sudo_as_admin_succesful' as a proof that the user
17- succeeded in the past.
18-
19- This is mostly useful to avoid attempting to use sudo on jenkins where it's
20- unlikely to be configured.
21+ Whatever trick is used to guess whether or not the user *can* sudo won't
22+ tell us if she agrees to run the sudo tests. Instead, this should rely on
23+ an opt-in mechanism so each user decides whether or not she wants to run
24+ the tests.
25 """
26
27 def _probe(self):
28- path = os.path.expanduser('~/.sudo_as_admin_successful')
29+ # I.e. if you want to run the tests that requires sudo issue:
30+ # $ touch ~/.setup_vm.use_sudo_for_tests
31+ # if you don't, issue:
32+ # $ rm -f ~/.setup_vm.use_sudo_for_tests
33+ path = os.path.expanduser('~/.setup_vm.use_sudo_for_tests')
34 return os.path.exists(path)
35
36 def feature_name(self):
37 return 'sudo access'
38
39
40-sudo_feature = _SudoFeature()
41+use_sudo_for_tests_feature = _UseSudoForTestsFeature()
42
43
44 class _SshFeature(ExecutableFeature):
45
46=== modified file 'setup_vm/tests/test_setup_vm.py'
47--- setup_vm/tests/test_setup_vm.py 2013-08-09 08:06:27 +0000
48+++ setup_vm/tests/test_setup_vm.py 2013-08-13 16:04:05 +0000
49@@ -169,7 +169,7 @@
50 # level and be done -- vila 2013-08-06
51
52 def setUp(self):
53- tests.requires_feature(self, tests.sudo_feature)
54+ tests.requires_feature(self, tests.use_sudo_for_tests_feature)
55 # Downloading real isos or images is too long for tests, instead, we
56 # fake it by downloading a small but known to exist file: MD5SUMS
57 super(TestDownload, self).setUp()
58@@ -637,7 +637,7 @@
59 class TestSeedImage(TestCaseWithHome):
60
61 def setUp(self):
62- tests.requires_feature(self, tests.sudo_feature)
63+ tests.requires_feature(self, tests.use_sudo_for_tests_feature)
64 tests.requires_feature(self, tests.qemu_img_feature)
65 super(TestSeedImage, self).setUp()
66 self.conf = svm.VmStack('foo')
67@@ -662,7 +662,7 @@
68 class TestImageFromCloud(TestCaseWithHome):
69
70 def setUp(self):
71- tests.requires_feature(self, tests.sudo_feature)
72+ tests.requires_feature(self, tests.use_sudo_for_tests_feature)
73 tests.requires_feature(self, tests.qemu_img_feature)
74 super(TestImageFromCloud, self).setUp()
75 self.conf = svm.VmStack('foo')
76@@ -696,7 +696,7 @@
77 class TestImageWithBacking(TestCaseWithHome):
78
79 def setUp(self):
80- tests.requires_feature(self, tests.sudo_feature)
81+ tests.requires_feature(self, tests.use_sudo_for_tests_feature)
82 (download_cache_dir,
83 reference_cloud_image_name) = requires_known_reference_image(self)
84 super(TestImageWithBacking, self).setUp()
85@@ -870,7 +870,7 @@
86 class TestInstallWithSeed(TestCaseWithHome):
87
88 def setUp(self):
89- tests.requires_feature(self, tests.sudo_feature)
90+ tests.requires_feature(self, tests.use_sudo_for_tests_feature)
91 (download_cache,
92 reference_cloud_image_name) = requires_known_reference_image(self)
93 super(TestInstallWithSeed, self).setUp()
94@@ -907,7 +907,7 @@
95 class TestInstallWithBacking(TestCaseWithHome):
96
97 def setUp(self):
98- tests.requires_feature(self, tests.sudo_feature)
99+ tests.requires_feature(self, tests.use_sudo_for_tests_feature)
100 (download_cache_dir,
101 reference_cloud_image_name) = requires_known_reference_image(self)
102 super(TestInstallWithBacking, self).setUp()

Subscribers

People subscribed via source and target branches

to all changes: