~jcsackett/charmworld/better-sparklines

« back to all changes in this revision

Viewing changes to charmworld/views/tests/test_misc.py

  • Committer: Tarmac
  • Author(s): Abel Deuring
  • Date: 2013-11-14 17:28:49 UTC
  • mfrom: (455.1.10 more-heartbeat-info-3)
  • Revision ID: tarmac-20131114172849-2axbyqee2p4a368d
heartbeat page:
  - show a warning if charmworld's crontab file is missing
  - show the time when the last ingest job finished
  - show the time when the charmworld app server(s) were started.

Approved by Juju Gui Bot, Abel Deuring, Benji York.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
    WebTestBase,
18
18
)
19
19
from charmworld.tests.test_health import TestCheckMixin
 
20
from charmworld.utils import (
 
21
    LAST_INGEST_JOB_FINISHED,
 
22
    record_server_start_time,
 
23
    set_status_timestamp,
 
24
)
20
25
from charmworld.views.misc import heartbeat
21
26
 
22
27
 
119
124
        self.use_index_client()
120
125
        self.index_client.index_charm(charm_data)
121
126
        FeaturedSource.from_db(self.db).set_featured(charm_data, 'charm')
 
127
        record_server_start_time(self.db)
 
128
        set_status_timestamp(self.db, LAST_INGEST_JOB_FINISHED)
122
129
 
123
130
        def make_all_collection_names():
124
131
            def all_collection_names():
127
134
                    'bundles', 'charm-queue', 'charms']
128
135
            return all_collection_names
129
136
 
 
137
        def make_fake_listdir():
 
138
            def fake_listdir(path):
 
139
                return ('foo', 'charmworld')
 
140
            return fake_listdir
 
141
 
130
142
        request = self.getRequest()
131
143
        with patch.object(request.db, 'collection_names',
132
144
                          new_callable=make_all_collection_names):
133
 
            response = heartbeat(request)
 
145
            with patch.object(os, 'listdir', new_callable=make_fake_listdir):
 
146
                response = heartbeat(request)
134
147
 
135
148
        checks = response['checks']
136
 
        self.assertEqual(9, len(checks))
 
149
        self.assertEqual(12, len(checks))
137
150
        remark = '1 charms found'
138
151
        self.assertCheck(checks[0], 'charms collection', 'Pass', remark)
139
152
        remark = '1 bundles found'
149
162
        self.assertCheck(checks[6], 'Ingest queue sizes', 'Pass', remark)
150
163
        self.assertCheck(checks[7], 'BZR revision', 'Pass')
151
164
        self.assertCheck(checks[8], 'ElasticSearch server', 'Pass')
 
165
        self.assertCheck(checks[9], 'Crontab', 'Pass')
 
166
        self.assertCheck(checks[10], 'Server started', 'Pass')
 
167
        self.assertCheck(checks[11], 'Last ingest job', 'Pass')
152
168
 
153
169
    def test_checks_fail(self):
154
170
        # When services or data are not available, the checks fail.
155
171
        # No setup is performed, creating a case where services and data
156
172
        # are not available
157
173
        from charmworld import health
 
174
 
 
175
        def make_fake_listdir():
 
176
            def fake_listdir(path):
 
177
                return ('foo', )
 
178
            return fake_listdir
 
179
 
158
180
        with patch.object(health, 'get_transport',
159
181
                          new_callable=self.makeFailCallable):
160
 
            response = heartbeat(self.getRequest())
 
182
            with patch.object(os, 'listdir', new_callable=make_fake_listdir):
 
183
                response = heartbeat(self.getRequest())
 
184
 
161
185
        checks = response['checks']
162
 
        self.assertEqual(9, len(checks))
 
186
        self.assertEqual(12, len(checks))
163
187
        remark = 'There are no charms. Is ingest running?'
164
188
        self.assertCheck(checks[0], 'charms collection', 'Fail', remark)
165
189
        remark = 'There are no bundles. Is ingest running?'
180
204
        self.assertCheck(checks[7], 'BZR revision', 'Fail', remark)
181
205
        remark = "Can't retrieve the ES server's health status."
182
206
        self.assertCheck(checks[8], 'ElasticSearch server', 'Fail', remark)
 
207
        remark = 'Crontab file for charmworld not found.'
 
208
        self.assertCheck(checks[9], 'Crontab', 'Fail', remark)
 
209
        remark = "Can't retrieve the server's start time."
 
210
        self.assertCheck(checks[10], 'Server started', 'Fail', remark)
 
211
        remark = "Can't retrieve the time when the last ingest job finished."
 
212
        self.assertCheck(checks[11], 'Last ingest job', 'Fail', remark)