Merge lp:~soren/surveilr/pastify into lp:surveilr

Proposed by Soren Hansen
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
Reviewer Review Type Date Requested Status
Soren Hansen Pending
Review via email: mp+86161@code.launchpad.net

Commit message

Use PasteDeploy for service configuration

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

Subscribers

People subscribed via source and target branches

to all changes: