Merge lp:~javier.collado/utah/bug1071020 into lp:utah

Proposed by Javier Collado
Status: Merged
Approved by: Javier Collado
Approved revision: 828
Merged at revision: 827
Proposed branch: lp:~javier.collado/utah/bug1071020
Merge into: lp:utah
Diff against target: 33 lines (+12/-0)
2 files modified
debian/changelog (+2/-0)
utah/client/common.py (+10/-0)
To merge this branch: bzr merge lp:~javier.collado/utah/bug1071020
Reviewer Review Type Date Requested Status
Max Brustkern (community) Approve
Review via email: mp+151527@code.launchpad.net

Description of the change

This branch creates a fake command result when the run_as user is not found in
the password database with an error that is friendlier than the error that the
user would get if the command were really executed.

I don't like much creating fake results to convey error messages, but I haven't
found any better way to do this. Maybe we could create a different result
dictionary for those commands that haven't been executed, but I don't really
thing that is worth the effort for now. Please let me now your thoughts on this.

To post a comment you must log in.
Revision history for this message
Andy Doan (doanac) wrote :

+1

Revision history for this message
Max Brustkern (nuclearbob) wrote :

This looks good to me. At some point, I think it would be nice if we could find a good way to support a generic 'unprivileged' user that would use the default user on the system, but maybe the real answer is that provisioning should always install the system with the same unprivileged user...

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2013-02-28 12:41:10 +0000
3+++ debian/changelog 2013-03-04 14:57:21 +0000
4@@ -3,6 +3,8 @@
5 * Added battery_measurements boolean variable to runlist (defaults to False)
6 * Added success command failure detection (LP: #1126115)
7 * Added installation failure log message (LP: #1126361)
8+ * Added check to make sure user is in the password database
9+ (LP: #1071020)
10
11 -- Javier Collado <javier.collado@canonical.com> Wed, 27 Feb 2013 09:28:58 +0100
12
13
14=== modified file 'utah/client/common.py'
15--- utah/client/common.py 2013-02-27 09:05:41 +0000
16+++ utah/client/common.py 2013-03-04 14:57:21 +0000
17@@ -108,6 +108,16 @@
18 """
19
20 if run_as is not None:
21+ # check username exists in the password database
22+ try:
23+ pwd.getpwnam(run_as)
24+ except KeyError:
25+ return make_result(
26+ command,
27+ FAIL,
28+ stderr=('{!r} user not found in the password database'
29+ .format(run_as)))
30+
31 # add -n so sudo will not prompt for a password on the tty
32 cmd_prefix = "sudo -n -u {} ".format(run_as)
33 else:

Subscribers

People subscribed via source and target branches