~mbruzek/charms/trusty/mongodb/limited-network

« back to all changes in this revision

Viewing changes to tests/01_deploy_single.py

  • Committer: Jorge Niedbalski
  • Author(s): Mario Splivalo
  • Date: 2014-12-10 15:36:14 UTC
  • mfrom: (61.1.3 mongodb)
  • Revision ID: jorge.niedbalski@canonical.com-20141210153614-epxz8q6bqm5v6vil
[mariosplivalo, r=niedbalski] Upgrades charmhelpers, and adds contrib.hahelpers.cluster, make lint fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python3
 
2
 
 
3
import amulet
 
4
from pymongo import MongoClient
 
5
 
 
6
seconds = 900
 
7
 
 
8
d = amulet.Deployment(series='trusty')
 
9
d.add('mongodb', charm='mongodb')
 
10
d.expose('mongodb')
 
11
 
 
12
# Perform the setup for the deployment.
 
13
try:
 
14
    d.setup(seconds)
 
15
    d.sentry.wait(seconds)
 
16
except amulet.helpers.TimeoutError:
 
17
    message = 'The environment did not setup in %d seconds.', seconds
 
18
    amulet.raise_status(amulet.SKIP, msg=message)
 
19
except:
 
20
    raise
 
21
 
 
22
 
 
23
############################################################
 
24
# Validate connectivity from $WORLD
 
25
#############################################################
 
26
def validate_world_connectivity():
 
27
    client = MongoClient(d.sentry.unit['mongodb/0'].info['public-address'])
 
28
 
 
29
    db = client['test']
 
30
    # Can we successfully insert?
 
31
    insert_id = db.amulet.insert({'assert': True})
 
32
    if insert_id is None:
 
33
        amulet.raise_status(amulet.FAIL, msg="Failed to insert test data")
 
34
    # Can we delete from a shard using the Mongos hub?
 
35
    result = db.amulet.remove(insert_id)
 
36
    if result['err'] is not None:
 
37
        amulet.raise_status(amulet.FAIL, msg="Failed to remove test data")
 
38
 
 
39
 
 
40
validate_world_connectivity()