~matsubara/charms/trusty/mongodb/bug-1410847

« back to all changes in this revision

Viewing changes to tests/200_deploy.test

  • Committer: Jorge Niedbalski
  • Date: 2014-12-09 15:07:49 UTC
  • mto: This revision was merged to the branch mainline in revision 60.
  • Revision ID: jorge.niedbalski@canonical.com-20141209150749-d9k2rjv52vu1zzj5
tidy and cleanup of makefile and test targets

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python3
2
 
 
3
 
import amulet
4
 
import requests
5
 
from pymongo import MongoClient
6
 
 
7
 
#########################################################
8
 
# Test Quick Config
9
 
#########################################################
10
 
scale = 1
11
 
seconds = 2500
12
 
 
13
 
#########################################################
14
 
# 3shard cluster configuration
15
 
#########################################################
16
 
d = amulet.Deployment(series='trusty')
17
 
 
18
 
d.add('configsvr', charm='mongodb', units=scale)
19
 
d.add('mongos', charm='mongodb', units=scale)
20
 
d.add('shard1', charm='mongodb', units=scale)
21
 
d.add('shard2', charm='mongodb', units=scale)
22
 
 
23
 
#Setup the config svr
24
 
d.configure('configsvr', {'replicaset': 'configsvr'})
25
 
 
26
 
# define each shardset
27
 
d.configure('shard1', {'replicaset': 'shard1'})
28
 
d.configure('shard2', {'replicaset': 'shard2'})
29
 
 
30
 
d.configure('mongos', {})
31
 
 
32
 
#Connect the config servers to mongo shell
33
 
d.relate('configsvr:configsvr', 'mongos:mongos-cfg')
34
 
 
35
 
#connect each shard to the mongo shell
36
 
d.relate('mongos:mongos', 'shard1:database')
37
 
d.relate('mongos:mongos', 'shard2:database')
38
 
d.expose('configsvr')
39
 
d.expose('mongos')
40
 
 
41
 
# Perform the setup for the deployment.
42
 
try:
43
 
    d.setup(seconds)
44
 
    d.sentry.wait(seconds)
45
 
except amulet.helpers.TimeoutError:
46
 
    message = 'The environment did not setup in %d seconds.', seconds
47
 
    amulet.raise_status(amulet.SKIP, msg=message)
48
 
except:
49
 
    raise
50
 
 
51
 
sentry_dict = {
52
 
    'config-sentry': d.sentry.unit['configsvr/0'],
53
 
    'mongos-sentry': d.sentry.unit['mongos/0'],
54
 
    'shard1-sentry': d.sentry.unit['shard1/0'],
55
 
    'shard2-sentry': d.sentry.unit['shard2/0']
56
 
}
57
 
 
58
 
 
59
 
#############################################################
60
 
# Check presence of MongoDB GUI HEALTH Status
61
 
#############################################################
62
 
def validate_status_interface():
63
 
    r = requests.get("http://{}:28017".format(
64
 
        sentry_dict['config-sentry'].info['public-address']),
65
 
        verify=False)
66
 
    r.raise_for_status
67
 
 
68
 
 
69
 
#############################################################
70
 
# Validate that each unit has an active mongo service
71
 
#############################################################
72
 
def validate_running_services():
73
 
    for service in sentry_dict:
74
 
        output = sentry_dict[service].run('service mongodb status')
75
 
        service_active = str(output).find('mongodb start/running')
76
 
        if service_active == -1:
77
 
            message = "Failed to find running MongoDB on host {}".format(service)
78
 
            amulet.raise_status(amulet.SKIP, msg=message)
79
 
 
80
 
 
81
 
#############################################################
82
 
# Validate connectivity from $WORLD
83
 
#############################################################
84
 
def validate_world_connectivity():
85
 
    client = MongoClient(d.sentry.unit['mongos/0'].info['public-address'])
86
 
 
87
 
    db = client['test']
88
 
    #Can we successfully insert?
89
 
    insert_id = db.amulet.insert({'assert': True})
90
 
    if insert_id is None:
91
 
        amulet.raise_status(amulet.FAIL, msg="Failed to insert test data")
92
 
    #Can we delete from a shard using the Mongos hub?
93
 
    result = db.amulet.remove(insert_id)
94
 
    if result['err'] is not None:
95
 
        amulet.raise_status(amulet.FAIL, msg="Failed to remove test data")
96
 
 
97
 
 
98
 
#############################################################
99
 
# Validate relationships
100
 
#############################################################
101
 
#broken pending 1273312
102
 
def validate_relationships():
103
 
    d.sentry.unit['configsvr/0'].relation('configsvr', 'mongos:mongos-cfg')
104
 
    d.sentry.unit['shard1/0'].relation('database', 'mongos:mongos')
105
 
    d.sentry.unit['shard2/0'].relation('database', 'mongos:mongos')
106
 
    print(d.sentry.unit['shard1/0'].relation('database', 'mongos:mongos'))
107
 
 
108
 
 
109
 
def validate_manual_connection():
110
 
    output, code = d.sentry.unit['shard1/0'].run("mongo {}".format(
111
 
        d.sentry.unit['mongos/0'].info['public-address']))
112
 
    if code != 0:
113
 
        message = "Manual Connection failed for unit shard1"
114
 
        amulet.raise_status(amulet.SKIP, msg=message)
115
 
 
116
 
    output, code = d.sentry.unit['shard2/0'].run("mongo {}".format(
117
 
        d.sentry.unit['mongos/0'].info['public-address']))
118
 
    if code != 0:
119
 
        message = "Manual Connection failed for unit shard2"
120
 
        amulet.raise_status(amulet.SKIP, msg=message)
121
 
 
122
 
 
123
 
validate_status_interface()
124
 
validate_running_services()
125
 
#validate_relationships()
126
 
validate_manual_connection()
127
 
validate_world_connectivity()