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
=== modified file 'README.md'
--- README.md 2011-11-30 22:02:41 +0000
+++ README.md 2011-12-18 14:29:23 +0000
@@ -4,22 +4,28 @@
44
5## Riak setup ##5## Riak setup ##
66
7 wget http://downloads.basho.com/riak/CURRENT/riak_1.0.2-1_ubuntu_11_amd64.deb7> wget http://downloads.basho.com/riak/CURRENT/riak_1.0.2-1_ubuntu_11_amd64.deb
8 sudo dpkg -i riak_1.0.2-1_ubuntu_11_amd64.deb8> sudo dpkg -i riak_1.0.2-1_ubuntu_11_amd64.deb
99
10You need to make a few changes to Riak's app.config.10You need to make a few changes to Riak's app.config.
1111
12 sudo sed -e '/^ {riak_kv/ a {delete_mode, immediate},' \12> sudo sed -e '/^ {riak_kv/ a {delete_mode, immediate},' \
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/' \
14 -e '/^ {riak_search/,+2 s/enabled, false/enabled, true/' -i.bak /etc/riak/app.config14> -e '/^ {riak_search/,+2 s/enabled, false/enabled, true/' -i.bak /etc/riak/app.config
1515
16Now we're ready to start Riak:16Now we're ready to start Riak:
1717
18 sudo /etc/init.d/riak start18> sudo /etc/init.d/riak start
1919
20## Other dependencies ##20## Other dependencies ##
2121
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:
2323
24 tools/setup_virtualenv.sh24> tools/setup_virtualenv.sh
25 .venv/bin/python setup.py nosetests25> .venv/bin/python setup.py nosetests
26
27## Running Surveilr ##
28
29You can start Surveilr this easily:
30
31> paster serve surveilr/defaults.cfg
2632
=== modified file 'setup.py'
--- setup.py 2011-11-29 23:14:20 +0000
+++ setup.py 2011-12-18 14:29:23 +0000
@@ -20,6 +20,19 @@
20#20#
21from setuptools import setup21from setuptools import setup
2222
23def get_install_requires():
24 install_requires = []
25 with open('tools/pip-requirements.txt', 'r') as fp:
26 for l in fp:
27 l = l.strip()
28 if l.startswith('#'):
29 continue
30 elif l.startswith('-e'):
31 install_requires.append(l[l.index('#egg=')+5:])
32 else:
33 install_requires.append(l)
34 return install_requires
35
23setup(36setup(
24 name='surveilr',37 name='surveilr',
25 version='0.1a1',38 version='0.1a1',
@@ -29,7 +42,7 @@
29 author_email='soren@linux2go.dk',42 author_email='soren@linux2go.dk',
30 url='http://surveilr.org/',43 url='http://surveilr.org/',
31 packages=['surveilr'],44 packages=['surveilr'],
32 install_requires=['riakalchemy'],45 install_requires=get_install_requires(),
33 test_suite='nose.collector',46 test_suite='nose.collector',
34 install_package_data=True,47 install_package_data=True,
35 classifiers=[48 classifiers=[
3649
=== modified file 'surveilr/api/server.py'
--- surveilr/api/server.py 2011-12-12 10:25:03 +0000
+++ surveilr/api/server.py 2011-12-18 14:29:23 +0000
@@ -182,6 +182,9 @@
182 controller='NotificationController',182 controller='NotificationController',
183 path_prefix='/users/{user_id}')183 path_prefix='/users/{user_id}')
184184
185 def __init__(self, global_config):
186 pass
187
185 @wsgify188 @wsgify
186 def __call__(self, req):189 def __call__(self, req):
187 """Where it all happens190 """Where it all happens
@@ -202,17 +205,20 @@
202205
203 return getattr(controller, method)(req, **kwargs)206 return getattr(controller, method)(req, **kwargs)
204207
205application = SurveilrApplication()208def server_factory(global_conf, host, port):
206209 port = int(port)
210 def serve(app):
211 socket = eventlet.listen((host, port))
212 eventlet.wsgi.server(socket, app)
213 return serve
207214
208def main():215def main():
209 riak_host = config.get_str('riak', 'host')216 riak_host = config.get_str('riak', 'host')
210 riak_port = config.get_int('riak', 'port')217 riak_port = config.get_int('riak', 'port')
211218
212 riakalchemy.connect(host=riak_host, port=riak_port)219 riakalchemy.connect(host=riak_host, port=riak_port)
213 socket = eventlet.listen(('', 9877))
214 eventlet.wsgi.server(socket, application)
215220
221 server_factory({}, '', 9877)(SurveilrApplication({}))
216222
217if __name__ == '__main__': # pragma: nocover223if __name__ == '__main__': # pragma: nocover
218 main()224 main()
219225
=== modified file 'surveilr/defaults.cfg'
--- surveilr/defaults.cfg 2011-11-30 09:57:31 +0000
+++ surveilr/defaults.cfg 2011-12-18 14:29:23 +0000
@@ -9,3 +9,15 @@
9[riak]9[riak]
10host = 127.0.0.110host = 127.0.0.1
11port = 809811port = 8098
12
13[server:main]
14paste.server_factory = surveilr.api.server:server_factory
15host = 0.0.0.0
16port = 8977
17
18[composite:main]
19use = egg:Paste#urlmap
20/surveilr = core
21
22[app:core]
23paste.app_factory = surveilr.api.server:SurveilrApplication
1224
=== modified file 'surveilr/tests/test_api_server.py'
--- surveilr/tests/test_api_server.py 2011-12-12 10:25:03 +0000
+++ surveilr/tests/test_api_server.py 2011-12-18 14:29:23 +0000
@@ -28,13 +28,14 @@
28from surveilr import models28from surveilr import models
29from surveilr import utils29from surveilr import utils
30from surveilr.api import server30from surveilr.api import server
31from surveilr.api.server import application31from surveilr.api.server import SurveilrApplication
3232
3333
34class APIServerTests(unittest.TestCase):34class APIServerTests(unittest.TestCase):
35 def setUp(self):35 def setUp(self):
36 import riakalchemy36 import riakalchemy
37 riakalchemy.connect()37 riakalchemy.connect()
38 self.application = SurveilrApplication({})
3839
39 def test_create_retrieve_user(self):40 def test_create_retrieve_user(self):
40 """Create, retrieve, delete, attempt to retrieve again"""41 """Create, retrieve, delete, attempt to retrieve again"""
@@ -42,13 +43,13 @@
42 method='POST',43 method='POST',
43 POST=json.dumps({'messaging_driver': 'fake',44 POST=json.dumps({'messaging_driver': 'fake',
44 'messaging_address': 'foo'}))45 'messaging_address': 'foo'}))
45 resp = application(req)46 resp = self.application(req)
46 self.assertEquals(resp.status_int, 200)47 self.assertEquals(resp.status_int, 200)
4748
48 service_id = json.loads(resp.body)['id']49 service_id = json.loads(resp.body)['id']
4950
50 req = Request.blank('/users/%s' % service_id)51 req = Request.blank('/users/%s' % service_id)
51 resp = application(req)52 resp = self.application(req)
52 self.assertEquals(resp.status_int, 200)53 self.assertEquals(resp.status_int, 200)
5354
54 user = json.loads(resp.body)55 user = json.loads(resp.body)
@@ -56,18 +57,18 @@
56 self.assertEquals(user['messaging_address'], 'foo')57 self.assertEquals(user['messaging_address'], 'foo')
5758
58 req = Request.blank('/users/%s' % service_id, method='DELETE')59 req = Request.blank('/users/%s' % service_id, method='DELETE')
59 resp = application(req)60 resp = self.application(req)
60 self.assertEquals(resp.status_int, 200)61 self.assertEquals(resp.status_int, 200)
6162
62 req = Request.blank('/users/%s' % service_id)63 req = Request.blank('/users/%s' % service_id)
63 resp = application(req)64 resp = self.application(req)
64 self.assertEquals(resp.status_int, 404)65 self.assertEquals(resp.status_int, 404)
6566
66 def test_send_notification(self):67 def test_send_notification(self):
67 req = Request.blank('/users',68 req = Request.blank('/users',
68 method='POST',69 method='POST',
69 POST=json.dumps({}))70 POST=json.dumps({}))
70 resp = application(req)71 resp = self.application(req)
71 self.assertEquals(resp.status_int, 200)72 self.assertEquals(resp.status_int, 200)
7273
73 user_id = json.loads(resp.body)['id']74 user_id = json.loads(resp.body)['id']
@@ -77,7 +78,7 @@
77 'timestamp': 13217362355575,78 'timestamp': 13217362355575,
78 'metrics': {'duration': 85000,79 'metrics': {'duration': 85000,
79 'response_size': 12435}}))80 'response_size': 12435}}))
80 resp = application(req)81 resp = self.application(req)
81 self.assertEquals(resp.status_int, 200)82 self.assertEquals(resp.status_int, 200)
8283
83 def test_create_retrieve_service(self):84 def test_create_retrieve_service(self):
@@ -85,21 +86,21 @@
85 req = Request.blank('/services',86 req = Request.blank('/services',
86 method='POST',87 method='POST',
87 POST=json.dumps({'name': 'this_or_the_other'}))88 POST=json.dumps({'name': 'this_or_the_other'}))
88 resp = application(req)89 resp = self.application(req)
89 self.assertEquals(resp.status_int, 200)90 self.assertEquals(resp.status_int, 200)
9091
91 service_id = json.loads(resp.body)['id']92 service_id = json.loads(resp.body)['id']
9293
93 req = Request.blank('/services/%s' % service_id)94 req = Request.blank('/services/%s' % service_id)
94 resp = application(req)95 resp = self.application(req)
95 self.assertEquals(resp.status_int, 200)96 self.assertEquals(resp.status_int, 200)
9697
97 req = Request.blank('/services/%s' % service_id, method='DELETE')98 req = Request.blank('/services/%s' % service_id, method='DELETE')
98 resp = application(req)99 resp = self.application(req)
99 self.assertEquals(resp.status_int, 200)100 self.assertEquals(resp.status_int, 200)
100101
101 req = Request.blank('/services/%s' % service_id)102 req = Request.blank('/services/%s' % service_id)
102 resp = application(req)103 resp = self.application(req)
103 self.assertEquals(resp.status_int, 404)104 self.assertEquals(resp.status_int, 404)
104105
105 def test_add_remove_plugin_to_service(self):106 def test_add_remove_plugin_to_service(self):
@@ -107,21 +108,21 @@
107 req = Request.blank('/services',108 req = Request.blank('/services',
108 method='POST',109 method='POST',
109 POST=json.dumps({'name': 'this_or_the_other'}))110 POST=json.dumps({'name': 'this_or_the_other'}))
110 resp = application(req)111 resp = self.application(req)
111 self.assertEquals(resp.status_int, 200)112 self.assertEquals(resp.status_int, 200)
112113
113 service_id = json.loads(resp.body)['id']114 service_id = json.loads(resp.body)['id']
114115
115 def get_plugins(service_id):116 def get_plugins(service_id):
116 req = Request.blank('/services/%s' % service_id)117 req = Request.blank('/services/%s' % service_id)
117 resp = application(req)118 resp = self.application(req)
118 self.assertEquals(resp.status_int, 200)119 self.assertEquals(resp.status_int, 200)
119 print 'body', resp.body120 print 'body', resp.body
120 return json.loads(resp.body)['plugins']121 return json.loads(resp.body)['plugins']
121122
122 req = Request.blank('/services/%s' % service_id, method="PUT",123 req = Request.blank('/services/%s' % service_id, method="PUT",
123 POST=json.dumps({'plugins': [url]}))124 POST=json.dumps({'plugins': [url]}))
124 resp = application(req)125 resp = self.application(req)
125 self.assertEquals(resp.status_int, 200)126 self.assertEquals(resp.status_int, 200)
126127
127 plugins = get_plugins(service_id)128 plugins = get_plugins(service_id)
@@ -129,7 +130,7 @@
129130
130 req = Request.blank('/services/%s' % service_id, method="PUT",131 req = Request.blank('/services/%s' % service_id, method="PUT",
131 POST=json.dumps({'plugins': []}))132 POST=json.dumps({'plugins': []}))
132 resp = application(req)133 resp = self.application(req)
133 self.assertEquals(resp.status_int, 200)134 self.assertEquals(resp.status_int, 200)
134135
135 plugins = get_plugins(service_id)136 plugins = get_plugins(service_id)
@@ -140,7 +141,7 @@
140 req = Request.blank('/services',141 req = Request.blank('/services',
141 method='POST',142 method='POST',
142 POST='{"name": "this_or_the_other"}')143 POST='{"name": "this_or_the_other"}')
143 resp = application(req)144 resp = self.application(req)
144 self.assertEquals(resp.status_int, 200)145 self.assertEquals(resp.status_int, 200)
145146
146 service_id = json.loads(resp.body)['id']147 service_id = json.loads(resp.body)['id']
@@ -151,7 +152,7 @@
151 'metrics': {'duration': 85000,152 'metrics': {'duration': 85000,
152 'response_size': 12435}}))153 'response_size': 12435}}))
153 with mock.patch('surveilr.api.server.eventlet') as eventlet:154 with mock.patch('surveilr.api.server.eventlet') as eventlet:
154 resp = application(req)155 resp = self.application(req)
155156
156 self.assertEquals(eventlet.spawn_n.call_args[0][0],157 self.assertEquals(eventlet.spawn_n.call_args[0][0],
157 utils.enhance_data_point)158 utils.enhance_data_point)
@@ -161,11 +162,11 @@
161 self.assertEquals(resp.status_int, 200)162 self.assertEquals(resp.status_int, 200)
162163
163 req = Request.blank('/services/%s/metrics' % service_id)164 req = Request.blank('/services/%s/metrics' % service_id)
164 resp = application(req)165 resp = self.application(req)
165166
166 def test_invalid_url(self):167 def test_invalid_url(self):
167 req = Request.blank('/stuff')168 req = Request.blank('/stuff')
168 resp = application(req)169 resp = self.application(req)
169 self.assertEquals(resp.status_int, 404)170 self.assertEquals(resp.status_int, 404)
170171
171 @mock.patch('surveilr.api.server.eventlet', spec=['listen', 'wsgi'])172 @mock.patch('surveilr.api.server.eventlet', spec=['listen', 'wsgi'])
@@ -177,5 +178,6 @@
177178
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)
179 eventlet.listen.assert_called_with(('', 9877))180 eventlet.listen.assert_called_with(('', 9877))
180 eventlet.wsgi.server.assert_called_with(socket_sentinel,181 self.assertEquals(eventlet.wsgi.server.call_args[0][0], socket_sentinel)
181 application)182 self.assertEquals(type(eventlet.wsgi.server.call_args[0][1]),
183 type(self.application))
182184
=== modified file 'tools/pip-requirements.txt'
--- tools/pip-requirements.txt 2011-12-12 10:50:37 +0000
+++ tools/pip-requirements.txt 2011-12-18 14:29:23 +0000
@@ -9,3 +9,6 @@
9httplib29httplib2
10yanc10yanc
11nosexcover11nosexcover
12pastedeploy
13paste
14PasteScript

Subscribers

People subscribed via source and target branches

to all changes: