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
=== modified file 'Makefile'
--- Makefile 2013-08-28 14:47:13 +0000
+++ Makefile 2013-08-30 10:38:12 +0000
@@ -14,7 +14,7 @@
14# You should have received a copy of the GNU Affero General Public License14# You should have received a copy of the GNU Affero General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.15# along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
17JUJUTEST = juju-test --timeout=60m -v -e "$(JUJU_ENV)" --upload-tools17JUJUTEST = juju-test --timeout=90m -v -e "$(JUJU_ENV)" --upload-tools
18VENV = ./tests/.venv18VENV = ./tests/.venv
19SYSDEPS = build-essential bzr libapt-pkg-dev python-pip python-virtualenv xvfb19SYSDEPS = build-essential bzr libapt-pkg-dev python-pip python-virtualenv xvfb
2020
2121
=== modified file 'hooks/backend.py'
--- hooks/backend.py 2013-08-26 12:18:19 +0000
+++ hooks/backend.py 2013-08-30 10:38:12 +0000
@@ -254,22 +254,17 @@
254 self.prev_config = prev_config254 self.prev_config = prev_config
255 self.mixins = []255 self.mixins = []
256256
257 sandbox = config['sandbox']257 is_legacy_juju = utils.legacy_juju()
258 staging = config['staging']
259258
260 if utils.legacy_juju():259 if config['staging']:
261 if staging:260 if not is_legacy_juju:
262 self.mixins.append(ImprovMixin())
263 elif sandbox:
264 self.mixins.append(SandboxMixin())
265 else:
266 self.mixins.append(PythonMixin())
267 else:
268 if staging:
269 raise ValueError('Unable to use staging with go backend')261 raise ValueError('Unable to use staging with go backend')
270 elif sandbox:262 self.mixins.append(ImprovMixin())
271 raise ValueError('Unable to use sandbox with go backend')263 elif config['sandbox']:
272 self.mixins.append(GoMixin())264 self.mixins.append(SandboxMixin())
265 else:
266 mixin = PythonMixin() if is_legacy_juju else GoMixin()
267 self.mixins.append(mixin)
273268
274 # We always install and start the GUI.269 # We always install and start the GUI.
275 self.mixins.append(GuiMixin())270 self.mixins.append(GuiMixin())
276271
=== modified file 'revision'
--- revision 2013-08-28 14:44:52 +0000
+++ revision 2013-08-30 10:38:12 +0000
@@ -1,1 +1,1 @@
177178
22
=== modified file 'tests/20-functional.test'
--- tests/20-functional.test 2013-08-14 18:14:11 +0000
+++ tests/20-functional.test 2013-08-30 10:38:12 +0000
@@ -177,6 +177,15 @@
177 # The staging environment contains five deployed services.177 # The staging environment contains five deployed services.
178 self.assertSetEqual(set(STAGING_SERVICES), self.get_service_names())178 self.assertSetEqual(set(STAGING_SERVICES), self.get_service_names())
179179
180 def test_sandbox(self):
181 # The GUI is correctly deployed and set up in sandbox mode.
182 unit_info = self.juju_deploy(
183 self.charm, options={'builtin-server': 'true', 'sandbox': 'true'})
184 hostname = unit_info['public-address']
185 self.navigate_to(hostname)
186 self.handle_browser_warning()
187 self.assertEnvironmentIsConnected()
188
180 def test_builtin_server(self):189 def test_builtin_server(self):
181 # Ensure the Juju GUI and builtin server are correctly set up.190 # Ensure the Juju GUI and builtin server are correctly set up.
182 unit_info = self.juju_deploy(191 unit_info = self.juju_deploy(
183192
=== modified file 'tests/test_backends.py'
--- tests/test_backends.py 2013-08-23 11:00:21 +0000
+++ tests/test_backends.py 2013-08-30 10:38:12 +0000
@@ -19,12 +19,12 @@
1919
20from collections import defaultdict20from collections import defaultdict
21from contextlib import contextmanager21from contextlib import contextmanager
22import os
23import shutil22import shutil
24import tempfile23import tempfile
25import unittest24import unittest
2625
27import charmhelpers26import charmhelpers
27import mock
28import shelltoolbox28import shelltoolbox
2929
30import backend30import backend
@@ -45,18 +45,14 @@
45class TestBackendProperties(unittest.TestCase):45class TestBackendProperties(unittest.TestCase):
46 """Ensure the correct mixins and property values are collected."""46 """Ensure the correct mixins and property values are collected."""
4747
48 def test_staging_backend(self):48 simulate_pyjuju = mock.patch(
49 test_backend = backend.Backend(config={49 'utils.legacy_juju', mock.Mock(return_value=True))
50 'sandbox': False, 'staging': True, 'builtin-server': False})50 simulate_juju_core = mock.patch(
51 mixin_names = get_mixin_names(test_backend)51 'utils.legacy_juju', mock.Mock(return_value=False))
52 self.assertEqual(
53 ('ImprovMixin', 'GuiMixin', 'HaproxyApacheMixin'),
54 mixin_names)
55 self.assertEqual(
56 frozenset(('apache2', 'curl', 'haproxy', 'openssl', 'zookeeper')),
57 test_backend.debs)
5852
59 def test_sandbox_backend(self):53 def check_sandbox_mode(self):
54 """The backend includes the correct mixins when sandbox mode is active.
55 """
60 test_backend = backend.Backend(config={56 test_backend = backend.Backend(config={
61 'sandbox': True, 'staging': False, 'builtin-server': False})57 'sandbox': True, 'staging': False, 'builtin-server': False})
62 mixin_names = get_mixin_names(test_backend)58 mixin_names = get_mixin_names(test_backend)
@@ -67,39 +63,68 @@
67 frozenset(('apache2', 'curl', 'haproxy', 'openssl')),63 frozenset(('apache2', 'curl', 'haproxy', 'openssl')),
68 test_backend.debs)64 test_backend.debs)
6965
66 def test_python_staging_backend(self):
67 with self.simulate_pyjuju:
68 test_backend = backend.Backend(config={
69 'sandbox': False, 'staging': True, 'builtin-server': False})
70 mixin_names = get_mixin_names(test_backend)
71 self.assertEqual(
72 ('ImprovMixin', 'GuiMixin', 'HaproxyApacheMixin'),
73 mixin_names)
74 debs = ('apache2', 'curl', 'haproxy', 'openssl', 'zookeeper')
75 self.assertEqual(frozenset(debs), test_backend.debs)
76
77 def test_go_staging_backend(self):
78 config = {'sandbox': False, 'staging': True, 'builtin-server': False}
79 with self.simulate_juju_core:
80 with self.assertRaises(ValueError) as context_manager:
81 backend.Backend(config=config)
82 error = str(context_manager.exception)
83 self.assertEqual('Unable to use staging with go backend', error)
84
85 def test_python_sandbox_backend(self):
86 with self.simulate_pyjuju:
87 self.check_sandbox_mode()
88
89 def test_go_sandbox_backend(self):
90 with self.simulate_juju_core:
91 self.check_sandbox_mode()
92
70 def test_python_backend(self):93 def test_python_backend(self):
71 test_backend = backend.Backend(config={94 with self.simulate_pyjuju:
72 'sandbox': False, 'staging': False, 'builtin-server': False})95 test_backend = backend.Backend(config={
73 mixin_names = get_mixin_names(test_backend)96 'sandbox': False, 'staging': False, 'builtin-server': False})
74 self.assertEqual(97 mixin_names = get_mixin_names(test_backend)
75 ('PythonMixin', 'GuiMixin', 'HaproxyApacheMixin'),98 self.assertEqual(
76 mixin_names)99 ('PythonMixin', 'GuiMixin', 'HaproxyApacheMixin'),
77 self.assertEqual(100 mixin_names)
78 frozenset(('apache2', 'curl', 'haproxy', 'openssl')),101 self.assertEqual(
79 test_backend.debs)102 frozenset(('apache2', 'curl', 'haproxy', 'openssl')),
103 test_backend.debs)
80104
81 def test_go_backend(self):105 def test_go_backend(self):
82 # Monkeypatch utils.CURRENT_DIR.106 with self.simulate_juju_core:
83 base_dir = tempfile.mkdtemp()107 test_backend = backend.Backend(config={
84 orig_current_dir = utils.CURRENT_DIR108 'sandbox': False, 'staging': False, 'builtin-server': False})
85 utils.CURRENT_DIR = tempfile.mkdtemp(dir=base_dir)109 mixin_names = get_mixin_names(test_backend)
86 # Create a fake agent file.110 self.assertEqual(
87 agent_path = os.path.join(base_dir, 'agent.conf')111 ('GoMixin', 'GuiMixin', 'HaproxyApacheMixin'),
88 open(agent_path, 'w').close()112 mixin_names)
89 test_backend = backend.Backend(config={113 self.assertEqual(
90 'sandbox': False, 'staging': False, 'builtin-server': False})114 frozenset(
91 # Cleanup.115 ('apache2', 'curl', 'haproxy', 'openssl', 'python-yaml')),
92 utils.CURRENT_DIR = orig_current_dir116 test_backend.debs)
93 shutil.rmtree(base_dir)117
94 # Tests118 def test_builtin_server(self):
95 mixin_names = get_mixin_names(test_backend)119 expected_mixins = ('GoMixin', 'GuiMixin', 'BuiltinServerMixin')
96 self.assertEqual(120 expected_debs = set([
97 ('GoMixin', 'GuiMixin', 'HaproxyApacheMixin'),121 'python-pip', 'python-yaml', 'curl', 'openssl', 'python-bzrlib'])
98 mixin_names)122 with self.simulate_juju_core:
99 self.assertEqual(123 test_backend = backend.Backend(config={
100 frozenset(124 'sandbox': False, 'staging': False, 'builtin-server': True})
101 ('apache2', 'curl', 'haproxy', 'openssl', 'python-yaml')),125 mixin_names = get_mixin_names(test_backend)
102 test_backend.debs)126 self.assertEqual(expected_mixins, mixin_names)
127 self.assertEqual(expected_debs, test_backend.debs)
103128
104129
105class TestBackendCommands(unittest.TestCase):130class TestBackendCommands(unittest.TestCase):

Subscribers

People subscribed via source and target branches