~ibm-demo/charms/trusty/wordpress/trunk

« back to all changes in this revision

Viewing changes to tests/02-memcached

  • Committer: Marco Ceppi
  • Date: 2014-10-29 12:15:43 UTC
  • Revision ID: marco@ceppi.net-20141029121543-ho5rmsi7av0pu0dv
Tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python3
 
2
 
 
3
import os
 
4
import amulet
 
5
import requests
 
6
 
 
7
from .lib import helper
 
8
 
 
9
d = amulet.Deployment()
 
10
d.add('mysql')
 
11
d.add('wordpress')
 
12
d.relate('mysql:db', 'wordpress:db')
 
13
d.expose('wordpress')
 
14
 
 
15
try:
 
16
    # Create the deployment described above, give us 900 seconds to do it
 
17
    d.setup(timeout=900)
 
18
    # Setup will only make sure the services are deployed, related, and in a
 
19
    # "started" state. We can employ the sentries to actually make sure there
 
20
    # are no more hooks being executed on any of the nodes.
 
21
    d.sentry.wait()
 
22
except amulet.helpers.TimeoutError:
 
23
    amulet.raise_status(amulet.SKIP, msg="Environment wasn't stood up in time")
 
24
except:
 
25
    # Something else has gone wrong, raise the error so we can see it and this
 
26
    # will automatically "FAIL" the test.
 
27
    raise
 
28
 
 
29
# Shorten the names a little to make working with unit data easier
 
30
wp_unit = d.sentry.unit['wordpress/0']
 
31
mysql_unit = d.sentry.unit['mysql/0']
 
32
 
 
33
# WordPress requires user input to "finish" a setup. This code is contained in
 
34
# the helper.py file found in the lib directory. If it's not able to complete
 
35
# the WordPress setup we need to quit the test, not as failed per se, but as a
 
36
# SKIPed test since we can't accurately setup the environment
 
37
try:
 
38
    helper.finish_setup(wp_unit.info['public-address'], password='amulet-test')
 
39
except:
 
40
    amulet.raise_status(amulet.SKIP, msg="Unable to finish WordPress setup")
 
41
 
 
42
home_page = requests.get('http://%s/' % wp_unit.info['public-address'])
 
43
home_page.raise_for_status() # Make sure it's not 5XX error
 
44
 
 
45
# Augment our deployment by adding a few more services, currently memcached
 
46
# relation only works after MySQL has been established and the user has
 
47
# completed the setup process. This isn't considered good practice in charms
 
48
# but it's simply a limitation to be addressed in the near future.
 
49
d.add('memcached')
 
50
d.relate('wordpress:cache', 'memcached:cache')
 
51
 
 
52
# Since we've changed the schema of our deployment, we need to run setup again
 
53
 
 
54
try:
 
55
    # Default timeout should be enough time to get memcached up and related
 
56
    d.setup()
 
57
    d.sentry.wait()
 
58
except amulet.helpers.TimeoutError:
 
59
    amulet.raise_status(amulet.SKIP, msg="Memcached wasn't stood up in time.")
 
60
except:
 
61
    # Incase deployer throws an error
 
62
    raise
 
63
 
 
64
# Verify WordPress still responds with a 200
 
65
home_page = requests.get('http://%s/' % wp_unit.info['public-address'])
 
66
home_page.raise_for_status()
 
67
 
 
68
# Verify the WordPress plugin was installed correctly
 
69
wp_unit.directory('/var/www/wp-content/plugins/wp-ffpc')