~rharding/charms/precise/juju-gui/update-nagios

« back to all changes in this revision

Viewing changes to tests/20-functional.test

  • Committer: Rick Harding
  • Date: 2014-01-15 14:50:46 UTC
  • mfrom: (147.1.8 remove-pyjuju)
  • Revision ID: rick.harding@canonical.com-20140115145046-lyh9879k9x8hwb8i
Remove support for PyJuju and rapi from charm.

- Removes the support for running rapi/pyjuju.
- Removes the agent used to communicate with zookeeper.
- Removes anything pertaining to zookeeper.
- Attempts to clean up docs and such to make sense with pure juju-core.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
from helpers import (
36
36
    get_admin_secret,
37
37
    juju_destroy_service,
38
 
    juju_version,
39
38
    make_service_name,
40
 
    stop_services,
41
39
    WebSocketClient,
42
40
)
43
41
import example
44
42
 
45
43
JUJU_GUI_TEST_BRANCH = 'lp:~juju-gui/juju-gui/charm-tests-branch'
46
 
STAGING_SERVICES = ('haproxy', 'mediawiki', 'memcached', 'mysql', 'wordpress')
47
 
is_legacy_juju = juju_version().major == 0
48
44
try:
49
45
    admin_secret = get_admin_secret()
50
46
except ValueError as err:
62
58
    of services that are started in the Juju GUI unit and that must be
63
59
    manually stopped by tests. In juju-core, the services list is always empty.
64
60
    """
65
 
    force_machine = None if is_legacy_juju else 0
66
61
    service_name = make_service_name(prefix='juju-gui-')
67
62
    unit_info = juju_deploy(
68
63
        'juju-gui', service_name=service_name, options=options,
69
 
        force_machine=force_machine)
70
 
    # XXX 2012-11-29 frankban bug=872264:
71
 
        # Just invoking ``juju destroy-service juju-gui`` in tearDown
72
 
        # should execute the ``stop`` hook, stopping all the services
73
 
        # started by the charm in the machine. Right now this does not
74
 
        # work in pyJuju, so the desired effect is achieved by keeping
75
 
        # track of started services and manually stopping them here.
76
 
    # Once pyJuju works correctly or we drop support for it altogether, we
77
 
    # can remove this shim.
 
64
        force_machine=0)
78
65
    cleanup_services = []
79
 
    if is_legacy_juju:
80
 
        if options is None:
81
 
            options = {}
82
 
        # Either stop the builtin server or the old apache2/haproxy setup.
83
 
        if options.get('builtin-server') == 'true':
84
 
            cleanup_services.append('guiserver')
85
 
        else:
86
 
            cleanup_services.extend(['haproxy', 'apache2'])
87
 
        # Staging uses improv, otherwise the API agent is used.
88
 
        if options.get('staging') == 'true':
89
 
            cleanup_services.append('juju-api-improv')
90
 
        else:
91
 
            cleanup_services.append('juju-api-agent')
 
66
    if options is None:
 
67
        options = {}
 
68
    # Either stop the builtin server or the old apache2/haproxy setup.
 
69
    if options.get('builtin-server') == 'true':
 
70
        cleanup_services.append('guiserver')
 
71
    else:
 
72
        cleanup_services.extend(['haproxy', 'apache2'])
92
73
    return service_name, unit_info, cleanup_services
93
74
 
94
75
 
177
158
        services = self.wait_for(services_found, 'Services not displayed.')
178
159
        return set([element.text for element in services])
179
160
 
180
 
    def deploy_gui(self, options=None):
181
 
        """Shim in our additional cleanup for pyJuju."""
182
 
        # Once pyJuju works correctly or we drop support for it altogether, we
183
 
        # can remove this shim.
184
 
        self.service_name, unit_info, cleanup_services = juju_deploy_gui(
185
 
            options=options)
186
 
        # XXX 2013-11-27 frankban bug=872264:
187
 
            # See juju_deploy_gui above.
188
 
        if is_legacy_juju:
189
 
            hostname = unit_info['public-address']
190
 
            self.addCleanup(stop_services, hostname, cleanup_services)
191
 
        return unit_info
192
 
 
193
161
    def get_builtin_server_info(self, hostname):
194
162
        """Return a dictionary of info as exposed by the builtin server."""
195
163
        url = 'https://{}/gui-server-info'.format(hostname)
205
173
 
206
174
    def test_stable_release(self):
207
175
        # Ensure the stable Juju GUI release is correctly set up.
208
 
        unit_info = self.deploy_gui(options={'juju-gui-source': 'stable'})
209
 
        hostname = unit_info['public-address']
210
 
        self.navigate_to(hostname)
211
 
        self.handle_browser_warning()
212
 
        self.assertEnvironmentIsConnected()
213
 
 
214
 
    @unittest.skipUnless(is_legacy_juju, 'staging only works in pyJuju')
215
 
    def test_staging(self):
216
 
        # Ensure the Juju GUI and staging services are correctly set up.
217
 
        unit_info = self.deploy_gui(options={'staging': 'true'})
218
 
        hostname = unit_info['public-address']
219
 
        self.navigate_to(hostname)
220
 
        self.handle_browser_warning()
221
 
        self.assertEnvironmentIsConnected()
222
 
        # The staging environment contains five deployed services.
223
 
        self.assertSetEqual(set(STAGING_SERVICES), self.get_service_names())
 
176
        self.service_name, unit_info, _ = juju_deploy_gui(
 
177
            options={'juju-gui-source': 'stable'})
 
178
        hostname = unit_info['public-address']
 
179
        self.navigate_to(hostname)
 
180
        self.handle_browser_warning()
 
181
        self.assertEnvironmentIsConnected()
224
182
 
225
183
    def test_sandbox(self):
226
184
        # The GUI is correctly deployed and set up in sandbox mode.
227
 
        unit_info = self.deploy_gui(options={'sandbox': 'true'})
 
185
        self.service_name, unit_info, _ = juju_deploy_gui(
 
186
            options={'sandbox': 'true'})
228
187
        hostname = unit_info['public-address']
229
188
        self.navigate_to(hostname)
230
189
        self.handle_browser_warning()
236
195
    def test_branch_source(self):
237
196
        # Ensure the Juju GUI is correctly deployed from a Bazaar branch.
238
197
        options = {'juju-gui-source': JUJU_GUI_TEST_BRANCH}
239
 
        unit_info = self.deploy_gui(options=options)
 
198
        self.service_name, unit_info, _ = juju_deploy_gui(options=options)
240
199
        hostname = unit_info['public-address']
241
200
        self.navigate_to(hostname)
242
201
        self.handle_browser_warning()
245
204
    def test_legacy_server(self):
246
205
        # The legacy apache + haproxy server configuration works correctly.
247
206
        # Also make sure the correct cache headers are sent.
248
 
        unit_info = self.deploy_gui(options={'builtin-server': 'false'})
 
207
        self.service_name, unit_info, _ = juju_deploy_gui(
 
208
            options={'builtin-server': 'false'})
249
209
        hostname = unit_info['public-address']
250
210
        self.navigate_to(hostname)
251
211
        self.handle_browser_warning()
279
239
        # Destroy the GUI service, and perform additional clean up in the case
280
240
        # we are in a pyJuju environment.
281
241
        juju_destroy_service(cls.service_name)
282
 
        # XXX 2013-11-27 frankban bug=872264:
283
 
            # See juju_deploy_gui above.
284
 
        if is_legacy_juju:
285
 
            stop_services(cls.hostname, cls.cleanup_services)
286
242
 
287
243
    def make_websocket_client(self, authenticated=True):
288
244
        """Create and return a WebSocket client connected to the Juju backend.
320
276
        server_header = dict(headers)['server']
321
277
        self.assertIn('TornadoServer', server_header)
322
278
 
323
 
    @unittest.skipIf(
324
 
        is_legacy_juju, 'bundle deployments are only supported in juju-core')
325
279
    def test_deployer_not_authenticated(self):
326
280
        # An error is returned trying to start a bundle deployment without
327
281
        # being authenticated.
337
291
            'unauthorized access: no user logged in', response['Error'])
338
292
 
339
293
    @unittest.skipUnless(admin_secret, 'admin secret was not found')
340
 
    @unittest.skipIf(
341
 
        is_legacy_juju, 'bundle deployments are only supported in juju-core')
342
294
    def test_deployer_invalid_bundle_name(self):
343
295
        # An error is returned trying to deploy a bundle with an invalid name.
344
296
        client = self.make_websocket_client()
353
305
            'invalid request: bundle no-such not found', response['Error'])
354
306
 
355
307
    @unittest.skipUnless(admin_secret, 'admin secret was not found')
356
 
    @unittest.skipIf(
357
 
        is_legacy_juju, 'bundle deployments are only supported in juju-core')
358
308
    def test_deployer_invalid_bundle_yaml(self):
359
309
        # An error is returned trying to deploy an invalid bundle YAML.
360
310
        client = self.make_websocket_client()
369
319
            'invalid request: invalid YAML contents', response['Error'])
370
320
 
371
321
    @unittest.skipUnless(admin_secret, 'admin secret was not found')
372
 
    @unittest.skipIf(
373
 
        is_legacy_juju, 'bundle deployments are only supported in juju-core')
374
322
    def test_deployer_watch_unknown_deployment(self):
375
323
        # An error is returned trying to watch an unknown deployment.
376
324
        client = self.make_websocket_client()
385
333
            'invalid request: deployment not found', response['Error'])
386
334
 
387
335
    @unittest.skipUnless(admin_secret, 'admin secret was not found')
388
 
    @unittest.skipIf(
389
 
        is_legacy_juju, 'bundle deployments are only supported in juju-core')
390
336
    def test_deployer(self):
391
337
        # The builtin server supports deploying bundles using juju-deployer.
392
338
        client = self.make_websocket_client()