Merge lp:~rvb/maas/sudo-mipf into lp:~maas-committers/maas/trunk

Proposed by Raphaël Badin
Status: Merged
Approved by: Raphaël Badin
Approved revision: no longer in the source branch.
Merged at revision: 1327
Proposed branch: lp:~rvb/maas/sudo-mipf
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 37 lines (+5/-4)
2 files modified
src/provisioningserver/tasks.py (+1/-1)
src/provisioningserver/tests/test_tasks.py (+4/-3)
To merge this branch: bzr merge lp:~rvb/maas/sudo-mipf
Reviewer Review Type Date Requested Status
Jeroen T. Vermeulen (community) Approve
Review via email: mp+132873@code.launchpad.net

Commit message

Fix the call to maas-import-pxe-files, this script needs root access.

This fix goes hand in hand with the packaging fix in https://code.launchpad.net/~rvb/maas/packaging.sudo-mipf/+merge/132874.

To post a comment you must log in.
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

Yup, that needs root! I wasn't aware of mock.ANY -- it solves a problem that I've been wondering about for some time.

One question: can you think of any situations where the difference between "maas-import-pxe-files" (in the script invocation) and "/usr/sbin/maas-import-pxe-files" (in the sudoers file) might cause trouble?

review: Approve
Revision history for this message
Raphaël Badin (rvb) wrote :

> Yup, that needs root! I wasn't aware of mock.ANY -- it solves a problem that
> I've been wondering about for some time.
>
> One question: can you think of any situations where the difference between
> "maas-import-pxe-files" (in the script invocation) and "/usr/sbin/maas-import-
> pxe-files" (in the sudoers file) might cause trouble?

Not really. I think this is the right thing to do:
- the sudo rule allows one to run /usr/sbin/maas-import-pxe-files, which is the script that the package installs.
- the code simply calls 'maas-import-pxe-files', thus allowing the user to override the script if he wants to.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/provisioningserver/tasks.py'
2--- src/provisioningserver/tasks.py 2012-10-30 11:19:02 +0000
3+++ src/provisioningserver/tasks.py 2012-11-05 11:58:36 +0000
4@@ -381,4 +381,4 @@
5 if http_proxy is not None:
6 env['http_proxy'] = http_proxy
7 env['https_proxy'] = http_proxy
8- check_call(['maas-import-pxe-files'], env=env)
9+ check_call(['sudo', '-n', 'maas-import-pxe-files'], env=env)
10
11=== modified file 'src/provisioningserver/tests/test_tasks.py'
12--- src/provisioningserver/tests/test_tasks.py 2012-10-30 11:19:02 +0000
13+++ src/provisioningserver/tests/test_tasks.py 2012-11-05 11:58:36 +0000
14@@ -543,14 +543,15 @@
15 def test_import_pxe_files(self):
16 recorder = self.patch(tasks, 'check_call', Mock())
17 import_pxe_files()
18- recorder.assert_called_once_with(['maas-import-pxe-files'], env=ANY)
19+ recorder.assert_called_once_with(
20+ ['sudo', '-n', 'maas-import-pxe-files'], env=ANY)
21 self.assertIsInstance(import_pxe_files, Task)
22
23 def test_import_pxe_files_preserves_environment(self):
24 recorder = self.patch(tasks, 'check_call', Mock())
25 import_pxe_files()
26 recorder.assert_called_once_with(
27- ['maas-import-pxe-files'], env=os.environ)
28+ ['sudo', '-n', 'maas-import-pxe-files'], env=os.environ)
29
30 def test_import_pxe_files_sets_proxy(self):
31 recorder = self.patch(tasks, 'check_call', Mock())
32@@ -558,4 +559,4 @@
33 import_pxe_files(http_proxy=proxy)
34 expected_env = dict(os.environ, http_proxy=proxy, https_proxy=proxy)
35 recorder.assert_called_once_with(
36- ['maas-import-pxe-files'], env=expected_env)
37+ ['sudo', '-n', 'maas-import-pxe-files'], env=expected_env)