Merge lp:~frankban/charms/precise/juju-gui/enable-go-sandbox into lp:~juju-gui/charms/precise/juju-gui/trunk

Proposed by Francesco Banconi
Status: Merged
Merged at revision: 99
Proposed branch: lp:~frankban/charms/precise/juju-gui/enable-go-sandbox
Merge into: lp:~juju-gui/charms/precise/juju-gui/trunk
Diff against target: 218 lines (+87/-58)
5 files modified
Makefile (+1/-1)
hooks/backend.py (+9/-14)
revision (+1/-1)
tests/20-functional.test (+9/-0)
tests/test_backends.py (+67/-42)
To merge this branch: bzr merge lp:~frankban/charms/precise/juju-gui/enable-go-sandbox
Reviewer Review Type Date Requested Status
charmers Pending
Review via email: mp+183124@code.launchpad.net

Description of the change

Enable sandbox mode in juju-core environments.

Also added a sandbox functional test and
improved the backend framework unit tests.

https://codereview.appspot.com/13424043/

To post a comment you must log in.
Revision history for this message
Francesco Banconi (frankban) wrote :

Reviewers: mp+183124_code.launchpad.net,

Message:
Please take a look.

Description:
Enable sandbox mode in juju-core environments.

Also added a sandbox functional test and
improved the backend framework unit tests.

https://code.launchpad.net/~frankban/charms/precise/juju-gui/enable-go-sandbox/+merge/183124

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/13424043/

Affected files:
   M Makefile
   A [revision details]
   M hooks/backend.py
   M revision
   M tests/20-functional.test
   M tests/test_backends.py

Revision history for this message
Richard Harding (rharding) wrote :
Revision history for this message
Francesco Banconi (frankban) wrote :

*** Submitted:

Enable sandbox mode in juju-core environments.

Also added a sandbox functional test and
improved the backend framework unit tests.

R=rharding
CC=
https://codereview.appspot.com/13424043

https://codereview.appspot.com/13424043/

Revision history for this message
Francesco Banconi (frankban) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile'
2--- Makefile 2013-08-28 14:47:13 +0000
3+++ Makefile 2013-08-30 10:38:12 +0000
4@@ -14,7 +14,7 @@
5 # You should have received a copy of the GNU Affero General Public License
6 # along with this program. If not, see <http://www.gnu.org/licenses/>.
7
8-JUJUTEST = juju-test --timeout=60m -v -e "$(JUJU_ENV)" --upload-tools
9+JUJUTEST = juju-test --timeout=90m -v -e "$(JUJU_ENV)" --upload-tools
10 VENV = ./tests/.venv
11 SYSDEPS = build-essential bzr libapt-pkg-dev python-pip python-virtualenv xvfb
12
13
14=== modified file 'hooks/backend.py'
15--- hooks/backend.py 2013-08-26 12:18:19 +0000
16+++ hooks/backend.py 2013-08-30 10:38:12 +0000
17@@ -254,22 +254,17 @@
18 self.prev_config = prev_config
19 self.mixins = []
20
21- sandbox = config['sandbox']
22- staging = config['staging']
23+ is_legacy_juju = utils.legacy_juju()
24
25- if utils.legacy_juju():
26- if staging:
27- self.mixins.append(ImprovMixin())
28- elif sandbox:
29- self.mixins.append(SandboxMixin())
30- else:
31- self.mixins.append(PythonMixin())
32- else:
33- if staging:
34+ if config['staging']:
35+ if not is_legacy_juju:
36 raise ValueError('Unable to use staging with go backend')
37- elif sandbox:
38- raise ValueError('Unable to use sandbox with go backend')
39- self.mixins.append(GoMixin())
40+ self.mixins.append(ImprovMixin())
41+ elif config['sandbox']:
42+ self.mixins.append(SandboxMixin())
43+ else:
44+ mixin = PythonMixin() if is_legacy_juju else GoMixin()
45+ self.mixins.append(mixin)
46
47 # We always install and start the GUI.
48 self.mixins.append(GuiMixin())
49
50=== modified file 'revision'
51--- revision 2013-08-28 14:44:52 +0000
52+++ revision 2013-08-30 10:38:12 +0000
53@@ -1,1 +1,1 @@
54-77
55+78
56
57=== modified file 'tests/20-functional.test'
58--- tests/20-functional.test 2013-08-14 18:14:11 +0000
59+++ tests/20-functional.test 2013-08-30 10:38:12 +0000
60@@ -177,6 +177,15 @@
61 # The staging environment contains five deployed services.
62 self.assertSetEqual(set(STAGING_SERVICES), self.get_service_names())
63
64+ def test_sandbox(self):
65+ # The GUI is correctly deployed and set up in sandbox mode.
66+ unit_info = self.juju_deploy(
67+ self.charm, options={'builtin-server': 'true', 'sandbox': 'true'})
68+ hostname = unit_info['public-address']
69+ self.navigate_to(hostname)
70+ self.handle_browser_warning()
71+ self.assertEnvironmentIsConnected()
72+
73 def test_builtin_server(self):
74 # Ensure the Juju GUI and builtin server are correctly set up.
75 unit_info = self.juju_deploy(
76
77=== modified file 'tests/test_backends.py'
78--- tests/test_backends.py 2013-08-23 11:00:21 +0000
79+++ tests/test_backends.py 2013-08-30 10:38:12 +0000
80@@ -19,12 +19,12 @@
81
82 from collections import defaultdict
83 from contextlib import contextmanager
84-import os
85 import shutil
86 import tempfile
87 import unittest
88
89 import charmhelpers
90+import mock
91 import shelltoolbox
92
93 import backend
94@@ -45,18 +45,14 @@
95 class TestBackendProperties(unittest.TestCase):
96 """Ensure the correct mixins and property values are collected."""
97
98- def test_staging_backend(self):
99- test_backend = backend.Backend(config={
100- 'sandbox': False, 'staging': True, 'builtin-server': False})
101- mixin_names = get_mixin_names(test_backend)
102- self.assertEqual(
103- ('ImprovMixin', 'GuiMixin', 'HaproxyApacheMixin'),
104- mixin_names)
105- self.assertEqual(
106- frozenset(('apache2', 'curl', 'haproxy', 'openssl', 'zookeeper')),
107- test_backend.debs)
108+ simulate_pyjuju = mock.patch(
109+ 'utils.legacy_juju', mock.Mock(return_value=True))
110+ simulate_juju_core = mock.patch(
111+ 'utils.legacy_juju', mock.Mock(return_value=False))
112
113- def test_sandbox_backend(self):
114+ def check_sandbox_mode(self):
115+ """The backend includes the correct mixins when sandbox mode is active.
116+ """
117 test_backend = backend.Backend(config={
118 'sandbox': True, 'staging': False, 'builtin-server': False})
119 mixin_names = get_mixin_names(test_backend)
120@@ -67,39 +63,68 @@
121 frozenset(('apache2', 'curl', 'haproxy', 'openssl')),
122 test_backend.debs)
123
124+ def test_python_staging_backend(self):
125+ with self.simulate_pyjuju:
126+ test_backend = backend.Backend(config={
127+ 'sandbox': False, 'staging': True, 'builtin-server': False})
128+ mixin_names = get_mixin_names(test_backend)
129+ self.assertEqual(
130+ ('ImprovMixin', 'GuiMixin', 'HaproxyApacheMixin'),
131+ mixin_names)
132+ debs = ('apache2', 'curl', 'haproxy', 'openssl', 'zookeeper')
133+ self.assertEqual(frozenset(debs), test_backend.debs)
134+
135+ def test_go_staging_backend(self):
136+ config = {'sandbox': False, 'staging': True, 'builtin-server': False}
137+ with self.simulate_juju_core:
138+ with self.assertRaises(ValueError) as context_manager:
139+ backend.Backend(config=config)
140+ error = str(context_manager.exception)
141+ self.assertEqual('Unable to use staging with go backend', error)
142+
143+ def test_python_sandbox_backend(self):
144+ with self.simulate_pyjuju:
145+ self.check_sandbox_mode()
146+
147+ def test_go_sandbox_backend(self):
148+ with self.simulate_juju_core:
149+ self.check_sandbox_mode()
150+
151 def test_python_backend(self):
152- test_backend = backend.Backend(config={
153- 'sandbox': False, 'staging': False, 'builtin-server': False})
154- mixin_names = get_mixin_names(test_backend)
155- self.assertEqual(
156- ('PythonMixin', 'GuiMixin', 'HaproxyApacheMixin'),
157- mixin_names)
158- self.assertEqual(
159- frozenset(('apache2', 'curl', 'haproxy', 'openssl')),
160- test_backend.debs)
161+ with self.simulate_pyjuju:
162+ test_backend = backend.Backend(config={
163+ 'sandbox': False, 'staging': False, 'builtin-server': False})
164+ mixin_names = get_mixin_names(test_backend)
165+ self.assertEqual(
166+ ('PythonMixin', 'GuiMixin', 'HaproxyApacheMixin'),
167+ mixin_names)
168+ self.assertEqual(
169+ frozenset(('apache2', 'curl', 'haproxy', 'openssl')),
170+ test_backend.debs)
171
172 def test_go_backend(self):
173- # Monkeypatch utils.CURRENT_DIR.
174- base_dir = tempfile.mkdtemp()
175- orig_current_dir = utils.CURRENT_DIR
176- utils.CURRENT_DIR = tempfile.mkdtemp(dir=base_dir)
177- # Create a fake agent file.
178- agent_path = os.path.join(base_dir, 'agent.conf')
179- open(agent_path, 'w').close()
180- test_backend = backend.Backend(config={
181- 'sandbox': False, 'staging': False, 'builtin-server': False})
182- # Cleanup.
183- utils.CURRENT_DIR = orig_current_dir
184- shutil.rmtree(base_dir)
185- # Tests
186- mixin_names = get_mixin_names(test_backend)
187- self.assertEqual(
188- ('GoMixin', 'GuiMixin', 'HaproxyApacheMixin'),
189- mixin_names)
190- self.assertEqual(
191- frozenset(
192- ('apache2', 'curl', 'haproxy', 'openssl', 'python-yaml')),
193- test_backend.debs)
194+ with self.simulate_juju_core:
195+ test_backend = backend.Backend(config={
196+ 'sandbox': False, 'staging': False, 'builtin-server': False})
197+ mixin_names = get_mixin_names(test_backend)
198+ self.assertEqual(
199+ ('GoMixin', 'GuiMixin', 'HaproxyApacheMixin'),
200+ mixin_names)
201+ self.assertEqual(
202+ frozenset(
203+ ('apache2', 'curl', 'haproxy', 'openssl', 'python-yaml')),
204+ test_backend.debs)
205+
206+ def test_builtin_server(self):
207+ expected_mixins = ('GoMixin', 'GuiMixin', 'BuiltinServerMixin')
208+ expected_debs = set([
209+ 'python-pip', 'python-yaml', 'curl', 'openssl', 'python-bzrlib'])
210+ with self.simulate_juju_core:
211+ test_backend = backend.Backend(config={
212+ 'sandbox': False, 'staging': False, 'builtin-server': True})
213+ mixin_names = get_mixin_names(test_backend)
214+ self.assertEqual(expected_mixins, mixin_names)
215+ self.assertEqual(expected_debs, test_backend.debs)
216
217
218 class TestBackendCommands(unittest.TestCase):

Subscribers

People subscribed via source and target branches