~tvansteenburgh/charms/precise/meteor/fix-npm-install

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3

import amulet
import requests

d = amulet.Deployment()

d.add('meteor')
d.add('haproxy')
d.add('mongodb')

d.relate('meteor:website', 'haproxy:reverseproxy')
d.relate('meteor:mongodb', 'mongodb:database')

d.expose('haproxy')

try:
    d.setup(timeout=900)
    d.sentry.wait()
except amulet.helpers.TimeoutError:
    amulet.raise_status(amulet.SKIP, msg="Environment wasn't stood up in time")
except:
    raise

meteor = d.sentry.unit['meteor/0']
haproxy = d.sentry.unit['haproxy/0']
mongodb = d.sentry.unit['mongodb/0']
mongodb_rel = mongodb.relation('database', 'meteor:mongodb')

# test we can access meteor app through haproxy
page = requests.get('http://{}'.format(haproxy.info['public-address']))
page.raise_for_status()

# test we are configured with correct mongodb url
mongodb_url = 'mongodb://{private-address}:{port}/meteor-app'.format(**mongodb_rel)
output, code = meteor.run(
    'grep "env MONGO_URL={}" /etc/init/meteor.conf'.format(mongodb_url))
if code != 0:
    msg = 'Meteor upstart script has incorrect mongodb url'
    amulet.raise_status(amulet.FAIL, msg=msg)

# Now you can use d.sentry.unit[UNIT] to address each of the units and perform
# more in-depth steps. There are three test statuses: amulet.PASS, amulet.FAIL,
# and amulet.SKIP - these can be triggered with amulet.raise_status(). Each
# d.sentry.unit[] has the following methods:
# - .info - An array of the information of that unit from Juju
# - .file(PATH) - Get the details of a file on that unit
# - .file_contents(PATH) - Get plain text output of PATH file from that unit
# - .directory(PATH) - Get details of directory
# - .directory_contents(PATH) - List files and folders in PATH on that unit
# - .relation(relation, service:rel) - Get relation data from return service