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
1diff --git a/src/maascli/snappy.py b/src/maascli/snappy.py
2index 20150d5..e352a59 100644
3--- a/src/maascli/snappy.py
4+++ b/src/maascli/snappy.py
5@@ -1263,6 +1263,9 @@ class cmd_status(SnappyCommand):
6 """Status of controller services."""
7
8 def handle(self, options):
9+ if os.getuid() != 0:
10+ raise SystemExit("The 'status' command must be run by root.")
11+
12 if get_current_mode() == "none":
13 print_msg("MAAS is not configured")
14 sys.exit(1)
15diff --git a/src/maascli/tests/test_snappy.py b/src/maascli/tests/test_snappy.py
16index 2540398..4e892d2 100644
17--- a/src/maascli/tests/test_snappy.py
18+++ b/src/maascli/tests/test_snappy.py
19@@ -860,3 +860,14 @@ class TestCmdInit(MAASTestCase):
20 },
21 settings,
22 )
23+
24+
25+class TestCmdStatus(MAASTestCase):
26+ def test_requires_root(self):
27+ parser = ArgumentParser()
28+ cmd = snappy.cmd_status(parser)
29+ self.patch(os, "getuid").return_value = 1000
30+ error = self.assertRaises(SystemExit, cmd, parser.parse_args([]))
31+ self.assertEqual(
32+ str(error), "The 'status' command must be run by root."
33+ )

Subscribers

People subscribed via source and target branches