Merge lp:~free.ekanayaka/landscape-client/help-as-non-root into lp:~landscape/landscape-client/trunk

Proposed by Free Ekanayaka
Status: Merged
Approved by: Jamu Kakar
Approved revision: 282
Merge reported by: Free Ekanayaka
Merged at revision: not available
Proposed branch: lp:~free.ekanayaka/landscape-client/help-as-non-root
Merge into: lp:~landscape/landscape-client/trunk
Diff against target: 65 lines (+27/-1)
2 files modified
landscape/configuration.py (+6/-1)
landscape/tests/test_configuration.py (+21/-0)
To merge this branch: bzr merge lp:~free.ekanayaka/landscape-client/help-as-non-root
Reviewer Review Type Date Requested Status
Jamu Kakar (community) Approve
Kevin McDermott (community) Approve
Review via email: mp+31727@code.launchpad.net

Description of the change

In case --help is passed, no check on the process uid is performed.

To post a comment you must log in.
Revision history for this message
Kevin McDermott (bigkevmcd) wrote :

-h is a synonym for --help, so that should probably be included...

Other than that, this has annoyed me too, so am happy to see it fixed :-)

review: Approve
282. By Free Ekanayaka

Also let 'landscape-config -h' be run as non-root

Revision history for this message
Free Ekanayaka (free.ekanayaka) wrote :

Good point Kevin, that's fixed, thanks!

Revision history for this message
Jamu Kakar (jkakar) wrote :

[1]

The docstrings for the two new tests can go on a single line.

Thanks for fixing this, +1!

review: Approve
Revision history for this message
Free Ekanayaka (free.ekanayaka) wrote :

Thanks Jamu, that's fixed!

283. By Free Ekanayaka

Fit docstrings in one line (Jamu)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'landscape/configuration.py'
2--- landscape/configuration.py 2010-07-30 10:04:18 +0000
3+++ landscape/configuration.py 2010-08-06 07:46:42 +0000
4@@ -607,16 +607,21 @@
5
6
7 def main(args):
8+ config = LandscapeSetupConfiguration(fetch_import_url)
9+ if args in (["-h"], ["--help"]):
10+ # We let landscape-config --help to be run as normal user
11+ config.load(args)
12+
13 if os.getuid() != 0:
14 sys.exit("landscape-config must be run as root.")
15
16- config = LandscapeSetupConfiguration(fetch_import_url)
17 try:
18 config.load(args)
19 except ImportOptionError, error:
20 print_text(str(error), error=True)
21 sys.exit(1)
22
23+
24 # Disable startup on boot and stop the client, if one is running.
25 if config.disable:
26 stop_client_and_disable_init_script()
27
28=== modified file 'landscape/tests/test_configuration.py'
29--- landscape/tests/test_configuration.py 2010-07-30 13:05:59 +0000
30+++ landscape/tests/test_configuration.py 2010-08-06 07:46:42 +0000
31@@ -1,6 +1,7 @@
32 import os
33 from getpass import getpass
34 from ConfigParser import ConfigParser
35+from cStringIO import StringIO
36
37 from twisted.internet.defer import succeed, fail
38
39@@ -1077,6 +1078,26 @@
40 main, ["-c", self.make_working_config()])
41 self.assertIn("landscape-config must be run as root", str(sys_exit))
42
43+ def test_main_with_help_and_non_root(self):
44+ """It's possible to call 'landscape-config --help' as normal user."""
45+ self.mocker.reset() # Forget the thing done in setUp
46+ output = StringIO()
47+ self.mocker.replace("sys.stdout").write(ANY)
48+ self.mocker.call(output.write)
49+ self.mocker.replay()
50+ self.assertRaises(SystemExit, main, ["--help"])
51+ self.assertIn("show this help message and exit", output.getvalue())
52+
53+ def test_main_with_help_and_non_root_short(self):
54+ """It's possible to call 'landscape-config -h' as normal user."""
55+ self.mocker.reset() # Forget the thing done in setUp
56+ output = StringIO()
57+ self.mocker.replace("sys.stdout").write(ANY)
58+ self.mocker.call(output.write)
59+ self.mocker.replay()
60+ self.assertRaises(SystemExit, main, ["-h"])
61+ self.assertIn("show this help message and exit", output.getvalue())
62+
63 def test_import_from_file(self):
64 sysvconfig_mock = self.mocker.patch(SysVConfig)
65 sysvconfig_mock.set_start_on_boot(True)

Subscribers

People subscribed via source and target branches

to all changes: