Merge lp:~joetalbott/adt-cloud-service/add_log_rotation into lp:adt-cloud-service

Proposed by Joe Talbott
Status: Merged
Approved by: Joe Talbott
Approved revision: 25
Merged at revision: 22
Proposed branch: lp:~joetalbott/adt-cloud-service/add_log_rotation
Merge into: lp:adt-cloud-service
Diff against target: 256 lines (+45/-29)
8 files modified
adt_cloud_service/__init__.py (+11/-7)
adt_cloud_service/errors.py (+2/-2)
adt_cloud_service/image.py (+10/-7)
adt_cloud_service/tests/test_functional.py (+9/-8)
adt_cloud_service/v1.py (+3/-2)
called-by-tarmac.py (+5/-0)
setup.py (+3/-2)
test_requirements.txt (+2/-1)
To merge this branch: bzr merge lp:~joetalbott/adt-cloud-service/add_log_rotation
Reviewer Review Type Date Requested Status
Celso Providelo (community) Approve
Review via email: mp+256231@code.launchpad.net

Commit message

Add log rotation.

Description of the change

Add log rotation.

To post a comment you must log in.
23. By Joe Talbott

Fix flake8 issues.

24. By Joe Talbott

Fix flake8 issues.

25. By Joe Talbott

Add flake8 to called-by-tarmac.py

Revision history for this message
Celso Providelo (cprov) wrote :

Lots of mixed changes, but looks good ...

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'adt_cloud_service/__init__.py'
2--- adt_cloud_service/__init__.py 2015-03-19 21:53:51 +0000
3+++ adt_cloud_service/__init__.py 2015-04-14 22:25:59 +0000
4@@ -53,22 +53,21 @@
5 lambda: 'Adt-Cloud-Service - Copyright (C) 2015 Canonical\n'
6 )
7
8-
9 @app.errorhandler(errors.MissingRequestParameters)
10- def handle_invalid_usage(error):
11+ def handle_missing_request_parameter(error):
12 response = flask.jsonify(error.to_dict())
13 response.status_code = error.status
14 return response
15
16 @app.errorhandler(errors.ImageMapperError)
17- def handle_invalid_usage(error):
18+ def handle_image_mapper_error(error):
19 response = flask.jsonify(error.to_dict())
20 response.status_code = error.status
21 return response
22
23 app.extensions['rabbit'] = queue.RabbitQueuer(config)
24- app.extensions['image-mapper'] = image.ImageMapperProxy(config
25- ['image_mapper']['url']
26+ app.extensions['image-mapper'] = image.ImageMapperProxy(
27+ config['image_mapper']['url']
28 )
29 app.config['SWIFT_URL'] = config['swift']['public_url']
30 app.config['PROPAGATE_EXCEPTIONS'] = True
31@@ -83,9 +82,14 @@
32 log_dir = os.path.dirname(log_path)
33 handler = None
34 if os.path.exists(log_dir):
35- handler = logging.FileHandler(log_path)
36+ handler = logging.handlers.TimedRotatingFileHandler(
37+ log_path,
38+ when='D',
39+ interval=1
40+ )
41 else:
42- print("'logs' directory '{}' does not exist, using stderr for app log.".format(log_dir))
43+ print("'logs' directory '{}' does not exist, "
44+ "using stderr for app log.".format(log_dir))
45 handler = logging.StreamHandler()
46 handler.setFormatter(
47 logging.Formatter(
48
49=== modified file 'adt_cloud_service/errors.py'
50--- adt_cloud_service/errors.py 2015-03-16 03:30:35 +0000
51+++ adt_cloud_service/errors.py 2015-04-14 22:25:59 +0000
52@@ -29,8 +29,8 @@
53
54 def to_dict(self):
55 return {
56- "message": "The following required parameters are missing: '%s'" \
57- % ', '.join(self.missing_parameter_names),
58+ "message": "The following required parameters are missing: '%s'"
59+ % ', '.join(self.missing_parameter_names),
60 "additional_message": self.additional_message
61 }
62
63
64=== modified file 'adt_cloud_service/image.py'
65--- adt_cloud_service/image.py 2015-03-18 20:10:04 +0000
66+++ adt_cloud_service/image.py 2015-04-14 22:25:59 +0000
67@@ -33,7 +33,8 @@
68 self._image_mapper_url = image_mapper_remote_address
69
70 def get_image_name_for_series_and_architectiure(self, series, arch):
71- """Attempt to get a nova image name for a given series and architecture.
72+ """Attempt to get a nova image name for a given series and
73+ architecture.
74
75 Internally this attempts to talk to the adt-image-mapper service, and
76 returns whatever that service tells us to use.
77@@ -44,7 +45,8 @@
78 )
79 path = '/v1/image'
80 query = urllib.parse.urlencode(dict(series=series, architecture=arch))
81- url = urllib.parse.urlunparse((scheme, netloc, path, params, query, frag))
82+ url = urllib.parse.urlunparse((scheme, netloc, path, params, query,
83+ frag))
84 try:
85 with urllib.request.urlopen(url, timeout=10) as f:
86 return process_image_mapper_result(f.status, f.read())
87@@ -58,7 +60,6 @@
88 )
89
90
91-
92 def process_image_mapper_result(status, probably_json):
93 """Process the reply from the image-mapper.
94
95@@ -72,8 +73,10 @@
96 data = json.loads(probably_json.decode())
97 except UnicodeDecodeError as e:
98 raise ImageMapperError(
99- "Unable to decode image-mapper response to unicode: {}".format(str(e)),
100- "Data from image-mapper is: {}".format(probably_json.decode('unicode_escape'))
101+ "Unable to decode image-mapper response to unicode: {}".format(
102+ str(e)),
103+ "Data from image-mapper is: {}".format(
104+ probably_json.decode('unicode_escape'))
105 )
106 except Exception as e:
107 raise ImageMapperError(
108@@ -83,5 +86,5 @@
109 if status == 200:
110 return data['image_name']
111 else:
112- raise ImageMapperError("Error from image-mapper service: {}".format(data['message']))
113-
114+ raise ImageMapperError(
115+ "Error from image-mapper service: {}".format(data['message']))
116
117=== modified file 'adt_cloud_service/tests/test_functional.py'
118--- adt_cloud_service/tests/test_functional.py 2015-03-18 20:20:47 +0000
119+++ adt_cloud_service/tests/test_functional.py 2015-04-14 22:25:59 +0000
120@@ -23,7 +23,6 @@
121 import kombu
122 import testtools
123 from testtools.matchers import (
124- Contains,
125 Equals,
126 HasLength,
127 raises,
128@@ -76,7 +75,9 @@
129 return instance
130
131 def set_image_mapper_double(self):
132- instance = self.server_app.extensions['image-mapper'] = ImageMapperProxyDouble()
133+ instance = ImageMapperProxyDouble()
134+ self.server_app.extensions['image-mapper'] = instance
135+
136 return instance
137
138 def assertEndpointDisallowsMethods(self, endpoint, methods):
139@@ -123,7 +124,7 @@
140 self.set_image_mapper_double()
141 resp = self.client.post(
142 '/v1/test',
143- data = {
144+ data={
145 'package-name': 'librepng',
146 'architecture': 'i386',
147 'platform': 'nova',
148@@ -165,7 +166,8 @@
149
150 class ImageMapperProxyDouble(object):
151
152- """A test double for the image mapper proxy. Simply returns a simple string."""
153+ """A test double for the image mapper proxy. Simply returns a simple
154+ string."""
155
156 def get_image_name_for_series_and_architectiure(self, series, arch):
157 return "some-nova-image"
158@@ -179,8 +181,8 @@
159 unit tests.
160
161 What we can do, which is a reasonable half-measure is to configure the
162- queuer class with an in-memory transport, and attempt to rigerously test the
163- interface between the queuer and it's caller.
164+ queuer class with an in-memory transport, and attempt to rigerously test
165+ the interface between the queuer and it's caller.
166
167 """
168 def test_queueing_does_not_alter_payload(self):
169@@ -193,7 +195,7 @@
170 'series': 'trusty',
171 }
172 copy_payload = test_payload.copy()
173- request_id = q.queue_test(copy_payload)
174+ q.queue_test(copy_payload)
175 self.assertEqual(test_payload, copy_payload)
176
177 def test_attempt_queue_test(self):
178@@ -218,7 +220,6 @@
179 self.assertEqual(test_payload, message.payload)
180
181
182-
183 class ImageMapperFunctionalTests(testtools.TestCase):
184
185 """Tests for the utility functions in the image module"""
186
187=== modified file 'adt_cloud_service/v1.py'
188--- adt_cloud_service/v1.py 2015-03-19 21:53:51 +0000
189+++ adt_cloud_service/v1.py 2015-04-14 22:25:59 +0000
190@@ -20,7 +20,7 @@
191 import logging
192 import urllib.parse
193
194-from flask import current_app, request, url_for, jsonify
195+from flask import current_app, request, jsonify
196
197 from adt_cloud_service.errors import MissingRequestParameters
198
199@@ -36,7 +36,8 @@
200 }
201 missing = required_keys.difference(set(request.form.keys()))
202 if missing:
203- logger.error("Got request %r with missing keys %r", dict(request.form), missing)
204+ logger.error("Got request %r with missing keys %r",
205+ dict(request.form), missing)
206 raise MissingRequestParameters(missing)
207
208 rabbit_request = dict()
209
210=== modified file 'called-by-tarmac.py'
211--- called-by-tarmac.py 2015-03-17 13:49:18 +0000
212+++ called-by-tarmac.py 2015-04-14 22:25:59 +0000
213@@ -89,6 +89,11 @@
214 'setup.py',
215 'test',
216 ],
217+ [
218+ os.path.join(ve_dir, 'bin', 'python3'),
219+ 'setup.py',
220+ 'flake8',
221+ ],
222 )
223 for cmd in all_cmds:
224 ret = _run_command(cmd)
225
226=== modified file 'setup.py'
227--- setup.py 2015-03-13 02:19:05 +0000
228+++ setup.py 2015-04-14 22:25:59 +0000
229@@ -21,7 +21,7 @@
230 import sys
231 assert sys.version_info >= (3,), 'Python 3 is required'
232
233-from setuptools import find_packages, setup, Extension
234+from setuptools import find_packages, setup
235
236
237 VERSION = '1.0.0'
238@@ -30,7 +30,8 @@
239 setup(
240 name='adt-cloud-service',
241 version=VERSION,
242- description='A microservice that queues test runs via a RESTful interface.',
243+ description='A microservice that queues test runs '
244+ 'via a RESTful interface.',
245 author='Canonical CI Engineering Team',
246 author_email='canonical-ci-engineering@lists.launchpad.net',
247 url='https://launchpad.net/adt-cloud-service',
248
249=== modified file 'test_requirements.txt'
250--- test_requirements.txt 2015-03-09 03:29:34 +0000
251+++ test_requirements.txt 2015-04-14 22:25:59 +0000
252@@ -1,1 +1,2 @@
253-testtools==1.5.0
254\ No newline at end of file
255+testtools==1.5.0
256+flake8==2.4.0

Subscribers

People subscribed via source and target branches