Status: | Merged |
---|---|
Approved by: | Soren Hansen |
Approved revision: | 16 |
Merged at revision: | 15 |
Proposed branch: | lp:~soren/surveilr/pastify |
Merge into: | lp:surveilr |
Diff against target: |
311 lines (+76/-34) 6 files modified
README.md (+14/-8) setup.py (+14/-1) surveilr/api/server.py (+10/-4) surveilr/defaults.cfg (+12/-0) surveilr/tests/test_api_server.py (+23/-21) tools/pip-requirements.txt (+3/-0) |
To merge this branch: | bzr merge lp:~soren/surveilr/pastify |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Soren Hansen | Pending | ||
Review via email: mp+86161@code.launchpad.net |
Commit message
Use PasteDeploy for service configuration
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'README.md' | |||
2 | --- README.md 2011-11-30 22:02:41 +0000 | |||
3 | +++ README.md 2011-12-18 14:29:23 +0000 | |||
4 | @@ -4,22 +4,28 @@ | |||
5 | 4 | 4 | ||
6 | 5 | ## Riak setup ## | 5 | ## Riak setup ## |
7 | 6 | 6 | ||
10 | 7 | wget http://downloads.basho.com/riak/CURRENT/riak_1.0.2-1_ubuntu_11_amd64.deb | 7 | > wget http://downloads.basho.com/riak/CURRENT/riak_1.0.2-1_ubuntu_11_amd64.deb |
11 | 8 | sudo dpkg -i riak_1.0.2-1_ubuntu_11_amd64.deb | 8 | > sudo dpkg -i riak_1.0.2-1_ubuntu_11_amd64.deb |
12 | 9 | 9 | ||
13 | 10 | You need to make a few changes to Riak's app.config. | 10 | You need to make a few changes to Riak's app.config. |
14 | 11 | 11 | ||
18 | 12 | sudo sed -e '/^ {riak_kv/ a {delete_mode, immediate},' \ | 12 | > sudo sed -e '/^ {riak_kv/ a {delete_mode, immediate},' \ |
19 | 13 | -e 's/storage_backend, riak_kv_bitcask_backend/storage_backend, riak_kv_eleveldb_backend/' \ | 13 | > -e 's/storage_backend, riak_kv_bitcask_backend/storage_backend, riak_kv_eleveldb_backend/' \ |
20 | 14 | -e '/^ {riak_search/,+2 s/enabled, false/enabled, true/' -i.bak /etc/riak/app.config | 14 | > -e '/^ {riak_search/,+2 s/enabled, false/enabled, true/' -i.bak /etc/riak/app.config |
21 | 15 | 15 | ||
22 | 16 | Now we're ready to start Riak: | 16 | Now we're ready to start Riak: |
23 | 17 | 17 | ||
25 | 18 | sudo /etc/init.d/riak start | 18 | > sudo /etc/init.d/riak start |
26 | 19 | 19 | ||
27 | 20 | ## Other dependencies ## | 20 | ## Other dependencies ## |
28 | 21 | 21 | ||
29 | 22 | `tools/setup_virtualenv.sh` will pull in all the necessary dependencies and should let you run the test suite: | 22 | `tools/setup_virtualenv.sh` will pull in all the necessary dependencies and should let you run the test suite: |
30 | 23 | 23 | ||
33 | 24 | tools/setup_virtualenv.sh | 24 | > tools/setup_virtualenv.sh |
34 | 25 | .venv/bin/python setup.py nosetests | 25 | > .venv/bin/python setup.py nosetests |
35 | 26 | |||
36 | 27 | ## Running Surveilr ## | ||
37 | 28 | |||
38 | 29 | You can start Surveilr this easily: | ||
39 | 30 | |||
40 | 31 | > paster serve surveilr/defaults.cfg | ||
41 | 26 | 32 | ||
42 | === modified file 'setup.py' | |||
43 | --- setup.py 2011-11-29 23:14:20 +0000 | |||
44 | +++ setup.py 2011-12-18 14:29:23 +0000 | |||
45 | @@ -20,6 +20,19 @@ | |||
46 | 20 | # | 20 | # |
47 | 21 | from setuptools import setup | 21 | from setuptools import setup |
48 | 22 | 22 | ||
49 | 23 | def get_install_requires(): | ||
50 | 24 | install_requires = [] | ||
51 | 25 | with open('tools/pip-requirements.txt', 'r') as fp: | ||
52 | 26 | for l in fp: | ||
53 | 27 | l = l.strip() | ||
54 | 28 | if l.startswith('#'): | ||
55 | 29 | continue | ||
56 | 30 | elif l.startswith('-e'): | ||
57 | 31 | install_requires.append(l[l.index('#egg=')+5:]) | ||
58 | 32 | else: | ||
59 | 33 | install_requires.append(l) | ||
60 | 34 | return install_requires | ||
61 | 35 | |||
62 | 23 | setup( | 36 | setup( |
63 | 24 | name='surveilr', | 37 | name='surveilr', |
64 | 25 | version='0.1a1', | 38 | version='0.1a1', |
65 | @@ -29,7 +42,7 @@ | |||
66 | 29 | author_email='soren@linux2go.dk', | 42 | author_email='soren@linux2go.dk', |
67 | 30 | url='http://surveilr.org/', | 43 | url='http://surveilr.org/', |
68 | 31 | packages=['surveilr'], | 44 | packages=['surveilr'], |
70 | 32 | install_requires=['riakalchemy'], | 45 | install_requires=get_install_requires(), |
71 | 33 | test_suite='nose.collector', | 46 | test_suite='nose.collector', |
72 | 34 | install_package_data=True, | 47 | install_package_data=True, |
73 | 35 | classifiers=[ | 48 | classifiers=[ |
74 | 36 | 49 | ||
75 | === modified file 'surveilr/api/server.py' | |||
76 | --- surveilr/api/server.py 2011-12-12 10:25:03 +0000 | |||
77 | +++ surveilr/api/server.py 2011-12-18 14:29:23 +0000 | |||
78 | @@ -182,6 +182,9 @@ | |||
79 | 182 | controller='NotificationController', | 182 | controller='NotificationController', |
80 | 183 | path_prefix='/users/{user_id}') | 183 | path_prefix='/users/{user_id}') |
81 | 184 | 184 | ||
82 | 185 | def __init__(self, global_config): | ||
83 | 186 | pass | ||
84 | 187 | |||
85 | 185 | @wsgify | 188 | @wsgify |
86 | 186 | def __call__(self, req): | 189 | def __call__(self, req): |
87 | 187 | """Where it all happens | 190 | """Where it all happens |
88 | @@ -202,17 +205,20 @@ | |||
89 | 202 | 205 | ||
90 | 203 | return getattr(controller, method)(req, **kwargs) | 206 | return getattr(controller, method)(req, **kwargs) |
91 | 204 | 207 | ||
94 | 205 | application = SurveilrApplication() | 208 | def server_factory(global_conf, host, port): |
95 | 206 | 209 | port = int(port) | |
96 | 210 | def serve(app): | ||
97 | 211 | socket = eventlet.listen((host, port)) | ||
98 | 212 | eventlet.wsgi.server(socket, app) | ||
99 | 213 | return serve | ||
100 | 207 | 214 | ||
101 | 208 | def main(): | 215 | def main(): |
102 | 209 | riak_host = config.get_str('riak', 'host') | 216 | riak_host = config.get_str('riak', 'host') |
103 | 210 | riak_port = config.get_int('riak', 'port') | 217 | riak_port = config.get_int('riak', 'port') |
104 | 211 | 218 | ||
105 | 212 | riakalchemy.connect(host=riak_host, port=riak_port) | 219 | riakalchemy.connect(host=riak_host, port=riak_port) |
106 | 213 | socket = eventlet.listen(('', 9877)) | ||
107 | 214 | eventlet.wsgi.server(socket, application) | ||
108 | 215 | 220 | ||
109 | 221 | server_factory({}, '', 9877)(SurveilrApplication({})) | ||
110 | 216 | 222 | ||
111 | 217 | if __name__ == '__main__': # pragma: nocover | 223 | if __name__ == '__main__': # pragma: nocover |
112 | 218 | main() | 224 | main() |
113 | 219 | 225 | ||
114 | === modified file 'surveilr/defaults.cfg' | |||
115 | --- surveilr/defaults.cfg 2011-11-30 09:57:31 +0000 | |||
116 | +++ surveilr/defaults.cfg 2011-12-18 14:29:23 +0000 | |||
117 | @@ -9,3 +9,15 @@ | |||
118 | 9 | [riak] | 9 | [riak] |
119 | 10 | host = 127.0.0.1 | 10 | host = 127.0.0.1 |
120 | 11 | port = 8098 | 11 | port = 8098 |
121 | 12 | |||
122 | 13 | [server:main] | ||
123 | 14 | paste.server_factory = surveilr.api.server:server_factory | ||
124 | 15 | host = 0.0.0.0 | ||
125 | 16 | port = 8977 | ||
126 | 17 | |||
127 | 18 | [composite:main] | ||
128 | 19 | use = egg:Paste#urlmap | ||
129 | 20 | /surveilr = core | ||
130 | 21 | |||
131 | 22 | [app:core] | ||
132 | 23 | paste.app_factory = surveilr.api.server:SurveilrApplication | ||
133 | 12 | 24 | ||
134 | === modified file 'surveilr/tests/test_api_server.py' | |||
135 | --- surveilr/tests/test_api_server.py 2011-12-12 10:25:03 +0000 | |||
136 | +++ surveilr/tests/test_api_server.py 2011-12-18 14:29:23 +0000 | |||
137 | @@ -28,13 +28,14 @@ | |||
138 | 28 | from surveilr import models | 28 | from surveilr import models |
139 | 29 | from surveilr import utils | 29 | from surveilr import utils |
140 | 30 | from surveilr.api import server | 30 | from surveilr.api import server |
142 | 31 | from surveilr.api.server import application | 31 | from surveilr.api.server import SurveilrApplication |
143 | 32 | 32 | ||
144 | 33 | 33 | ||
145 | 34 | class APIServerTests(unittest.TestCase): | 34 | class APIServerTests(unittest.TestCase): |
146 | 35 | def setUp(self): | 35 | def setUp(self): |
147 | 36 | import riakalchemy | 36 | import riakalchemy |
148 | 37 | riakalchemy.connect() | 37 | riakalchemy.connect() |
149 | 38 | self.application = SurveilrApplication({}) | ||
150 | 38 | 39 | ||
151 | 39 | def test_create_retrieve_user(self): | 40 | def test_create_retrieve_user(self): |
152 | 40 | """Create, retrieve, delete, attempt to retrieve again""" | 41 | """Create, retrieve, delete, attempt to retrieve again""" |
153 | @@ -42,13 +43,13 @@ | |||
154 | 42 | method='POST', | 43 | method='POST', |
155 | 43 | POST=json.dumps({'messaging_driver': 'fake', | 44 | POST=json.dumps({'messaging_driver': 'fake', |
156 | 44 | 'messaging_address': 'foo'})) | 45 | 'messaging_address': 'foo'})) |
158 | 45 | resp = application(req) | 46 | resp = self.application(req) |
159 | 46 | self.assertEquals(resp.status_int, 200) | 47 | self.assertEquals(resp.status_int, 200) |
160 | 47 | 48 | ||
161 | 48 | service_id = json.loads(resp.body)['id'] | 49 | service_id = json.loads(resp.body)['id'] |
162 | 49 | 50 | ||
163 | 50 | req = Request.blank('/users/%s' % service_id) | 51 | req = Request.blank('/users/%s' % service_id) |
165 | 51 | resp = application(req) | 52 | resp = self.application(req) |
166 | 52 | self.assertEquals(resp.status_int, 200) | 53 | self.assertEquals(resp.status_int, 200) |
167 | 53 | 54 | ||
168 | 54 | user = json.loads(resp.body) | 55 | user = json.loads(resp.body) |
169 | @@ -56,18 +57,18 @@ | |||
170 | 56 | self.assertEquals(user['messaging_address'], 'foo') | 57 | self.assertEquals(user['messaging_address'], 'foo') |
171 | 57 | 58 | ||
172 | 58 | req = Request.blank('/users/%s' % service_id, method='DELETE') | 59 | req = Request.blank('/users/%s' % service_id, method='DELETE') |
174 | 59 | resp = application(req) | 60 | resp = self.application(req) |
175 | 60 | self.assertEquals(resp.status_int, 200) | 61 | self.assertEquals(resp.status_int, 200) |
176 | 61 | 62 | ||
177 | 62 | req = Request.blank('/users/%s' % service_id) | 63 | req = Request.blank('/users/%s' % service_id) |
179 | 63 | resp = application(req) | 64 | resp = self.application(req) |
180 | 64 | self.assertEquals(resp.status_int, 404) | 65 | self.assertEquals(resp.status_int, 404) |
181 | 65 | 66 | ||
182 | 66 | def test_send_notification(self): | 67 | def test_send_notification(self): |
183 | 67 | req = Request.blank('/users', | 68 | req = Request.blank('/users', |
184 | 68 | method='POST', | 69 | method='POST', |
185 | 69 | POST=json.dumps({})) | 70 | POST=json.dumps({})) |
187 | 70 | resp = application(req) | 71 | resp = self.application(req) |
188 | 71 | self.assertEquals(resp.status_int, 200) | 72 | self.assertEquals(resp.status_int, 200) |
189 | 72 | 73 | ||
190 | 73 | user_id = json.loads(resp.body)['id'] | 74 | user_id = json.loads(resp.body)['id'] |
191 | @@ -77,7 +78,7 @@ | |||
192 | 77 | 'timestamp': 13217362355575, | 78 | 'timestamp': 13217362355575, |
193 | 78 | 'metrics': {'duration': 85000, | 79 | 'metrics': {'duration': 85000, |
194 | 79 | 'response_size': 12435}})) | 80 | 'response_size': 12435}})) |
196 | 80 | resp = application(req) | 81 | resp = self.application(req) |
197 | 81 | self.assertEquals(resp.status_int, 200) | 82 | self.assertEquals(resp.status_int, 200) |
198 | 82 | 83 | ||
199 | 83 | def test_create_retrieve_service(self): | 84 | def test_create_retrieve_service(self): |
200 | @@ -85,21 +86,21 @@ | |||
201 | 85 | req = Request.blank('/services', | 86 | req = Request.blank('/services', |
202 | 86 | method='POST', | 87 | method='POST', |
203 | 87 | POST=json.dumps({'name': 'this_or_the_other'})) | 88 | POST=json.dumps({'name': 'this_or_the_other'})) |
205 | 88 | resp = application(req) | 89 | resp = self.application(req) |
206 | 89 | self.assertEquals(resp.status_int, 200) | 90 | self.assertEquals(resp.status_int, 200) |
207 | 90 | 91 | ||
208 | 91 | service_id = json.loads(resp.body)['id'] | 92 | service_id = json.loads(resp.body)['id'] |
209 | 92 | 93 | ||
210 | 93 | req = Request.blank('/services/%s' % service_id) | 94 | req = Request.blank('/services/%s' % service_id) |
212 | 94 | resp = application(req) | 95 | resp = self.application(req) |
213 | 95 | self.assertEquals(resp.status_int, 200) | 96 | self.assertEquals(resp.status_int, 200) |
214 | 96 | 97 | ||
215 | 97 | req = Request.blank('/services/%s' % service_id, method='DELETE') | 98 | req = Request.blank('/services/%s' % service_id, method='DELETE') |
217 | 98 | resp = application(req) | 99 | resp = self.application(req) |
218 | 99 | self.assertEquals(resp.status_int, 200) | 100 | self.assertEquals(resp.status_int, 200) |
219 | 100 | 101 | ||
220 | 101 | req = Request.blank('/services/%s' % service_id) | 102 | req = Request.blank('/services/%s' % service_id) |
222 | 102 | resp = application(req) | 103 | resp = self.application(req) |
223 | 103 | self.assertEquals(resp.status_int, 404) | 104 | self.assertEquals(resp.status_int, 404) |
224 | 104 | 105 | ||
225 | 105 | def test_add_remove_plugin_to_service(self): | 106 | def test_add_remove_plugin_to_service(self): |
226 | @@ -107,21 +108,21 @@ | |||
227 | 107 | req = Request.blank('/services', | 108 | req = Request.blank('/services', |
228 | 108 | method='POST', | 109 | method='POST', |
229 | 109 | POST=json.dumps({'name': 'this_or_the_other'})) | 110 | POST=json.dumps({'name': 'this_or_the_other'})) |
231 | 110 | resp = application(req) | 111 | resp = self.application(req) |
232 | 111 | self.assertEquals(resp.status_int, 200) | 112 | self.assertEquals(resp.status_int, 200) |
233 | 112 | 113 | ||
234 | 113 | service_id = json.loads(resp.body)['id'] | 114 | service_id = json.loads(resp.body)['id'] |
235 | 114 | 115 | ||
236 | 115 | def get_plugins(service_id): | 116 | def get_plugins(service_id): |
237 | 116 | req = Request.blank('/services/%s' % service_id) | 117 | req = Request.blank('/services/%s' % service_id) |
239 | 117 | resp = application(req) | 118 | resp = self.application(req) |
240 | 118 | self.assertEquals(resp.status_int, 200) | 119 | self.assertEquals(resp.status_int, 200) |
241 | 119 | print 'body', resp.body | 120 | print 'body', resp.body |
242 | 120 | return json.loads(resp.body)['plugins'] | 121 | return json.loads(resp.body)['plugins'] |
243 | 121 | 122 | ||
244 | 122 | req = Request.blank('/services/%s' % service_id, method="PUT", | 123 | req = Request.blank('/services/%s' % service_id, method="PUT", |
245 | 123 | POST=json.dumps({'plugins': [url]})) | 124 | POST=json.dumps({'plugins': [url]})) |
247 | 124 | resp = application(req) | 125 | resp = self.application(req) |
248 | 125 | self.assertEquals(resp.status_int, 200) | 126 | self.assertEquals(resp.status_int, 200) |
249 | 126 | 127 | ||
250 | 127 | plugins = get_plugins(service_id) | 128 | plugins = get_plugins(service_id) |
251 | @@ -129,7 +130,7 @@ | |||
252 | 129 | 130 | ||
253 | 130 | req = Request.blank('/services/%s' % service_id, method="PUT", | 131 | req = Request.blank('/services/%s' % service_id, method="PUT", |
254 | 131 | POST=json.dumps({'plugins': []})) | 132 | POST=json.dumps({'plugins': []})) |
256 | 132 | resp = application(req) | 133 | resp = self.application(req) |
257 | 133 | self.assertEquals(resp.status_int, 200) | 134 | self.assertEquals(resp.status_int, 200) |
258 | 134 | 135 | ||
259 | 135 | plugins = get_plugins(service_id) | 136 | plugins = get_plugins(service_id) |
260 | @@ -140,7 +141,7 @@ | |||
261 | 140 | req = Request.blank('/services', | 141 | req = Request.blank('/services', |
262 | 141 | method='POST', | 142 | method='POST', |
263 | 142 | POST='{"name": "this_or_the_other"}') | 143 | POST='{"name": "this_or_the_other"}') |
265 | 143 | resp = application(req) | 144 | resp = self.application(req) |
266 | 144 | self.assertEquals(resp.status_int, 200) | 145 | self.assertEquals(resp.status_int, 200) |
267 | 145 | 146 | ||
268 | 146 | service_id = json.loads(resp.body)['id'] | 147 | service_id = json.loads(resp.body)['id'] |
269 | @@ -151,7 +152,7 @@ | |||
270 | 151 | 'metrics': {'duration': 85000, | 152 | 'metrics': {'duration': 85000, |
271 | 152 | 'response_size': 12435}})) | 153 | 'response_size': 12435}})) |
272 | 153 | with mock.patch('surveilr.api.server.eventlet') as eventlet: | 154 | with mock.patch('surveilr.api.server.eventlet') as eventlet: |
274 | 154 | resp = application(req) | 155 | resp = self.application(req) |
275 | 155 | 156 | ||
276 | 156 | self.assertEquals(eventlet.spawn_n.call_args[0][0], | 157 | self.assertEquals(eventlet.spawn_n.call_args[0][0], |
277 | 157 | utils.enhance_data_point) | 158 | utils.enhance_data_point) |
278 | @@ -161,11 +162,11 @@ | |||
279 | 161 | self.assertEquals(resp.status_int, 200) | 162 | self.assertEquals(resp.status_int, 200) |
280 | 162 | 163 | ||
281 | 163 | req = Request.blank('/services/%s/metrics' % service_id) | 164 | req = Request.blank('/services/%s/metrics' % service_id) |
283 | 164 | resp = application(req) | 165 | resp = self.application(req) |
284 | 165 | 166 | ||
285 | 166 | def test_invalid_url(self): | 167 | def test_invalid_url(self): |
286 | 167 | req = Request.blank('/stuff') | 168 | req = Request.blank('/stuff') |
288 | 168 | resp = application(req) | 169 | resp = self.application(req) |
289 | 169 | self.assertEquals(resp.status_int, 404) | 170 | self.assertEquals(resp.status_int, 404) |
290 | 170 | 171 | ||
291 | 171 | @mock.patch('surveilr.api.server.eventlet', spec=['listen', 'wsgi']) | 172 | @mock.patch('surveilr.api.server.eventlet', spec=['listen', 'wsgi']) |
292 | @@ -177,5 +178,6 @@ | |||
293 | 177 | 178 | ||
294 | 178 | riakalchemy.connect.assert_called_with(host='127.0.0.1', port=8098) | 179 | riakalchemy.connect.assert_called_with(host='127.0.0.1', port=8098) |
295 | 179 | eventlet.listen.assert_called_with(('', 9877)) | 180 | eventlet.listen.assert_called_with(('', 9877)) |
298 | 180 | eventlet.wsgi.server.assert_called_with(socket_sentinel, | 181 | self.assertEquals(eventlet.wsgi.server.call_args[0][0], socket_sentinel) |
299 | 181 | application) | 182 | self.assertEquals(type(eventlet.wsgi.server.call_args[0][1]), |
300 | 183 | type(self.application)) | ||
301 | 182 | 184 | ||
302 | === modified file 'tools/pip-requirements.txt' | |||
303 | --- tools/pip-requirements.txt 2011-12-12 10:50:37 +0000 | |||
304 | +++ tools/pip-requirements.txt 2011-12-18 14:29:23 +0000 | |||
305 | @@ -9,3 +9,6 @@ | |||
306 | 9 | httplib2 | 9 | httplib2 |
307 | 10 | yanc | 10 | yanc |
308 | 11 | nosexcover | 11 | nosexcover |
309 | 12 | pastedeploy | ||
310 | 13 | paste | ||
311 | 14 | PasteScript |