Merge lp:~andreserl/maas/lp1604169_2.0 into lp:maas/2.0

Proposed by Andres Rodriguez
Status: Merged
Approved by: Andres Rodriguez
Approved revision: 5168
Merged at revision: 5167
Proposed branch: lp:~andreserl/maas/lp1604169_2.0
Merge into: lp:maas/2.0
Diff against target: 91 lines (+35/-10)
3 files modified
docs/changelog.rst (+2/-0)
src/maascli/cli.py (+7/-1)
src/maascli/tests/test_cli.py (+26/-9)
To merge this branch: bzr merge lp:~andreserl/maas/lp1604169_2.0
Reviewer Review Type Date Requested Status
Andres Rodriguez (community) Approve
Review via email: mp+300607@code.launchpad.net

Commit message

Backport rev5189 from trunk :Ensure maasserver is available before allowing maas cli to run with extra commands, otherwise don't show maasserver related commands

To post a comment you must log in.
lp:~andreserl/maas/lp1604169_2.0 updated
5168. By Andres Rodriguez on 2016-07-20

Update Changelog

Revision history for this message
Andres Rodriguez (andreserl) wrote :

self approve! Fix landed in trunk.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'docs/changelog.rst'
2--- docs/changelog.rst 2016-07-18 23:44:06 +0000
3+++ docs/changelog.rst 2016-07-20 13:51:35 +0000
4@@ -23,6 +23,8 @@
5
6 LP: #1604128 [2.0rc2] Unable to add a public SSH Key due to lp1604147
7
8+LP: #1604169 [2.0] maas login yields "ImportError: No module named 'maasserver'"
9+
10
11 2.0.0 (rc2)
12 ===========
13
14=== modified file 'src/maascli/cli.py'
15--- src/maascli/cli.py 2016-06-13 15:48:16 +0000
16+++ src/maascli/cli.py 2016-07-20 13:51:35 +0000
17@@ -9,6 +9,7 @@
18
19 from functools import partial
20 import os
21+import pkgutil
22 import sys
23 from textwrap import fill
24
25@@ -187,7 +188,7 @@
26
27 # Setup and the allowed django commands into the maascli.
28 management = get_django_management()
29- if management is not None:
30+ if management is not None and is_maasserver_available():
31 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "maas.settings")
32 sys.path.append('/usr/share/maas')
33 load_regiond_commands(management, parser)
34@@ -204,6 +205,11 @@
35 return management
36
37
38+def is_maasserver_available():
39+ """Ensure that 'maasserver' module is available."""
40+ return pkgutil.find_loader("maasserver") is not None
41+
42+
43 def run_regiond_command(management, parser):
44 """Called to run the regiond command.
45
46
47=== modified file 'src/maascli/tests/test_cli.py'
48--- src/maascli/tests/test_cli.py 2016-07-13 18:26:47 +0000
49+++ src/maascli/tests/test_cli.py 2016-07-20 13:51:35 +0000
50@@ -43,15 +43,32 @@
51 cli.cmd_login)
52
53 def test_doesnt_call_load_regiond_commands_if_no_management(self):
54- self.patch(cli, "get_django_management").return_value = None
55- mock_load_regiond_commands = self.patch(cli, "load_regiond_commands")
56- parser = ArgumentParser()
57- cli.register_cli_commands(parser)
58- self.assertThat(mock_load_regiond_commands, MockNotCalled())
59-
60- def test_calls_load_regiond_commands_when_management(self):
61- self.patch(
62- cli, "get_django_management").return_value = sentinel.management
63+ self.patch(
64+ cli, "get_django_management").return_value = None
65+ self.patch(
66+ cli,
67+ "is_maasserver_available").return_value = sentinel.pkg_util
68+ mock_load_regiond_commands = self.patch(cli, "load_regiond_commands")
69+ parser = ArgumentParser()
70+ cli.register_cli_commands(parser)
71+ self.assertThat(mock_load_regiond_commands, MockNotCalled())
72+
73+ def test_doesnt_call_load_regiond_commands_if_no_maasserver(self):
74+ self.patch(
75+ cli, "get_django_management").return_value = sentinel.management
76+ self.patch(
77+ cli, "is_maasserver_available").return_value = None
78+ mock_load_regiond_commands = self.patch(cli, "load_regiond_commands")
79+ parser = ArgumentParser()
80+ cli.register_cli_commands(parser)
81+ self.assertThat(mock_load_regiond_commands, MockNotCalled())
82+
83+ def test_calls_load_regiond_commands_when_management_and_maasserver(self):
84+ self.patch(
85+ cli, "get_django_management").return_value = sentinel.management
86+ self.patch(
87+ cli,
88+ "is_maasserver_available").return_value = sentinel.pkg_util
89 mock_load_regiond_commands = self.patch(cli, "load_regiond_commands")
90 parser = ArgumentParser()
91 cli.register_cli_commands(parser)

Subscribers

People subscribed via source and target branches