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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# Copyright 2013 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
from collections import namedtuple
Check = namedtuple('check', 'name status remark')
PASS = 'Pass'
FAIL = 'Fail'
def check_mongodb(request):
"""Return a Check of the mongodb charms collection."""
status = FAIL
try:
count = request.db.charms.count()
if count > 0:
remark = '{0} charms found'.format(count)
status = PASS
else:
remark = 'There are no charms. Is ingest running?'
except:
remark = 'The mongodb charm collection is not available.'
finally:
check = Check('charms collection', status, remark)
return check
def check_elasticsearch(request):
"""Return a Check of the elasticsearch charms index."""
status = FAIL
try:
results = request.index_client.search(terms='')
if results['result_total'] > 0:
remark = '{0} matches found'.format(results['result_total'])
status = PASS
else:
remark = 'There are no matches. Is ingest running?'
except:
remark = 'The elasticsearch charm index is not available.'
finally:
check = Check('charms index', status, remark)
return check
def check_api2(request):
"""Return a Check of the API charms interesting end point."""
status = FAIL
try:
from charmworld.views.api import API2
api = API2(request)
interesting = api.charms(path=['interesting'])['result']
if (interesting['new']
and interesting['popular']
and interesting['featured']):
status = PASS
remark = 'Interesting has new, popular, and featured.'
else:
remark = 'Interesting is missing new, popular, or featured.'
except:
remark = 'The API2 is not available.'
finally:
check = Check('API2 interesting', status, remark)
return check
def check_api3(request):
"""Return a Check of the API charms interesting end point."""
status = FAIL
try:
from charmworld.views.api import API3
api = API3(request)
interesting = api.search(path=['interesting'])['result']
if (interesting['new']
and interesting['popular']
and interesting['featured']):
status = PASS
remark = 'Interesting has new, popular, and featured.'
else:
remark = 'Interesting is missing new, popular, or featured.'
except:
remark = 'The API3 is not available.'
finally:
check = Check('API3 interesting', status, remark)
return check
|