Merge ~ack/maas:1879978-snap-status-require-root into maas:master

Proposed by Alberto Donato
Status: Merged
Approved by: Alberto Donato
Approved revision: 41bedf09e8f90bab57d7458f7ffec01b7a626416
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~ack/maas:1879978-snap-status-require-root
Merge into: maas:master
Diff against target: 33 lines (+14/-0)
2 files modified
src/maascli/snappy.py (+3/-0)
src/maascli/tests/test_snappy.py (+11/-0)
Reviewer Review Type Date Requested Status
Dougal Matthews (community) Approve
Björn Tillenius Approve
Review via email: mp+384491@code.launchpad.net

Commit message

LP: #1879978 - snap: require running status command as root

To post a comment you must log in.
Revision history for this message
Björn Tillenius (bjornt) wrote :

+1

review: Approve
Revision history for this message
Dougal Matthews (d0ugal) wrote :

lgtm

review: Approve

There was an error fetching revisions from git servers. Please try again in a few minutes. If the problem persists, contact Launchpad support.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/src/maascli/snappy.py b/src/maascli/snappy.py
index 20150d5..e352a59 100644
--- a/src/maascli/snappy.py
+++ b/src/maascli/snappy.py
@@ -1263,6 +1263,9 @@ class cmd_status(SnappyCommand):
1263 """Status of controller services."""1263 """Status of controller services."""
12641264
1265 def handle(self, options):1265 def handle(self, options):
1266 if os.getuid() != 0:
1267 raise SystemExit("The 'status' command must be run by root.")
1268
1266 if get_current_mode() == "none":1269 if get_current_mode() == "none":
1267 print_msg("MAAS is not configured")1270 print_msg("MAAS is not configured")
1268 sys.exit(1)1271 sys.exit(1)
diff --git a/src/maascli/tests/test_snappy.py b/src/maascli/tests/test_snappy.py
index 2540398..4e892d2 100644
--- a/src/maascli/tests/test_snappy.py
+++ b/src/maascli/tests/test_snappy.py
@@ -860,3 +860,14 @@ class TestCmdInit(MAASTestCase):
860 },860 },
861 settings,861 settings,
862 )862 )
863
864
865class TestCmdStatus(MAASTestCase):
866 def test_requires_root(self):
867 parser = ArgumentParser()
868 cmd = snappy.cmd_status(parser)
869 self.patch(os, "getuid").return_value = 1000
870 error = self.assertRaises(SystemExit, cmd, parser.parse_args([]))
871 self.assertEqual(
872 str(error), "The 'status' command must be run by root."
873 )

Subscribers

People subscribed via source and target branches