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
=== modified file 'adt_cloud_service/__init__.py'
--- adt_cloud_service/__init__.py 2015-03-19 21:53:51 +0000
+++ adt_cloud_service/__init__.py 2015-04-14 22:25:59 +0000
@@ -53,22 +53,21 @@
53 lambda: 'Adt-Cloud-Service - Copyright (C) 2015 Canonical\n'53 lambda: 'Adt-Cloud-Service - Copyright (C) 2015 Canonical\n'
54 )54 )
5555
56
57 @app.errorhandler(errors.MissingRequestParameters)56 @app.errorhandler(errors.MissingRequestParameters)
58 def handle_invalid_usage(error):57 def handle_missing_request_parameter(error):
59 response = flask.jsonify(error.to_dict())58 response = flask.jsonify(error.to_dict())
60 response.status_code = error.status59 response.status_code = error.status
61 return response60 return response
6261
63 @app.errorhandler(errors.ImageMapperError)62 @app.errorhandler(errors.ImageMapperError)
64 def handle_invalid_usage(error):63 def handle_image_mapper_error(error):
65 response = flask.jsonify(error.to_dict())64 response = flask.jsonify(error.to_dict())
66 response.status_code = error.status65 response.status_code = error.status
67 return response66 return response
6867
69 app.extensions['rabbit'] = queue.RabbitQueuer(config)68 app.extensions['rabbit'] = queue.RabbitQueuer(config)
70 app.extensions['image-mapper'] = image.ImageMapperProxy(config69 app.extensions['image-mapper'] = image.ImageMapperProxy(
71 ['image_mapper']['url']70 config['image_mapper']['url']
72 )71 )
73 app.config['SWIFT_URL'] = config['swift']['public_url']72 app.config['SWIFT_URL'] = config['swift']['public_url']
74 app.config['PROPAGATE_EXCEPTIONS'] = True73 app.config['PROPAGATE_EXCEPTIONS'] = True
@@ -83,9 +82,14 @@
83 log_dir = os.path.dirname(log_path)82 log_dir = os.path.dirname(log_path)
84 handler = None83 handler = None
85 if os.path.exists(log_dir):84 if os.path.exists(log_dir):
86 handler = logging.FileHandler(log_path)85 handler = logging.handlers.TimedRotatingFileHandler(
86 log_path,
87 when='D',
88 interval=1
89 )
87 else:90 else:
88 print("'logs' directory '{}' does not exist, using stderr for app log.".format(log_dir))91 print("'logs' directory '{}' does not exist, "
92 "using stderr for app log.".format(log_dir))
89 handler = logging.StreamHandler()93 handler = logging.StreamHandler()
90 handler.setFormatter(94 handler.setFormatter(
91 logging.Formatter(95 logging.Formatter(
9296
=== modified file 'adt_cloud_service/errors.py'
--- adt_cloud_service/errors.py 2015-03-16 03:30:35 +0000
+++ adt_cloud_service/errors.py 2015-04-14 22:25:59 +0000
@@ -29,8 +29,8 @@
2929
30 def to_dict(self):30 def to_dict(self):
31 return {31 return {
32 "message": "The following required parameters are missing: '%s'" \32 "message": "The following required parameters are missing: '%s'"
33 % ', '.join(self.missing_parameter_names),33 % ', '.join(self.missing_parameter_names),
34 "additional_message": self.additional_message34 "additional_message": self.additional_message
35 }35 }
3636
3737
=== modified file 'adt_cloud_service/image.py'
--- adt_cloud_service/image.py 2015-03-18 20:10:04 +0000
+++ adt_cloud_service/image.py 2015-04-14 22:25:59 +0000
@@ -33,7 +33,8 @@
33 self._image_mapper_url = image_mapper_remote_address33 self._image_mapper_url = image_mapper_remote_address
3434
35 def get_image_name_for_series_and_architectiure(self, series, arch):35 def get_image_name_for_series_and_architectiure(self, series, arch):
36 """Attempt to get a nova image name for a given series and architecture.36 """Attempt to get a nova image name for a given series and
37 architecture.
3738
38 Internally this attempts to talk to the adt-image-mapper service, and39 Internally this attempts to talk to the adt-image-mapper service, and
39 returns whatever that service tells us to use.40 returns whatever that service tells us to use.
@@ -44,7 +45,8 @@
44 )45 )
45 path = '/v1/image'46 path = '/v1/image'
46 query = urllib.parse.urlencode(dict(series=series, architecture=arch))47 query = urllib.parse.urlencode(dict(series=series, architecture=arch))
47 url = urllib.parse.urlunparse((scheme, netloc, path, params, query, frag))48 url = urllib.parse.urlunparse((scheme, netloc, path, params, query,
49 frag))
48 try:50 try:
49 with urllib.request.urlopen(url, timeout=10) as f:51 with urllib.request.urlopen(url, timeout=10) as f:
50 return process_image_mapper_result(f.status, f.read())52 return process_image_mapper_result(f.status, f.read())
@@ -58,7 +60,6 @@
58 )60 )
5961
6062
61
62def process_image_mapper_result(status, probably_json):63def process_image_mapper_result(status, probably_json):
63 """Process the reply from the image-mapper.64 """Process the reply from the image-mapper.
6465
@@ -72,8 +73,10 @@
72 data = json.loads(probably_json.decode())73 data = json.loads(probably_json.decode())
73 except UnicodeDecodeError as e:74 except UnicodeDecodeError as e:
74 raise ImageMapperError(75 raise ImageMapperError(
75 "Unable to decode image-mapper response to unicode: {}".format(str(e)),76 "Unable to decode image-mapper response to unicode: {}".format(
76 "Data from image-mapper is: {}".format(probably_json.decode('unicode_escape'))77 str(e)),
78 "Data from image-mapper is: {}".format(
79 probably_json.decode('unicode_escape'))
77 )80 )
78 except Exception as e:81 except Exception as e:
79 raise ImageMapperError(82 raise ImageMapperError(
@@ -83,5 +86,5 @@
83 if status == 200:86 if status == 200:
84 return data['image_name']87 return data['image_name']
85 else:88 else:
86 raise ImageMapperError("Error from image-mapper service: {}".format(data['message']))89 raise ImageMapperError(
8790 "Error from image-mapper service: {}".format(data['message']))
8891
=== modified file 'adt_cloud_service/tests/test_functional.py'
--- adt_cloud_service/tests/test_functional.py 2015-03-18 20:20:47 +0000
+++ adt_cloud_service/tests/test_functional.py 2015-04-14 22:25:59 +0000
@@ -23,7 +23,6 @@
23import kombu23import kombu
24import testtools24import testtools
25from testtools.matchers import (25from testtools.matchers import (
26 Contains,
27 Equals,26 Equals,
28 HasLength,27 HasLength,
29 raises,28 raises,
@@ -76,7 +75,9 @@
76 return instance75 return instance
7776
78 def set_image_mapper_double(self):77 def set_image_mapper_double(self):
79 instance = self.server_app.extensions['image-mapper'] = ImageMapperProxyDouble()78 instance = ImageMapperProxyDouble()
79 self.server_app.extensions['image-mapper'] = instance
80
80 return instance81 return instance
8182
82 def assertEndpointDisallowsMethods(self, endpoint, methods):83 def assertEndpointDisallowsMethods(self, endpoint, methods):
@@ -123,7 +124,7 @@
123 self.set_image_mapper_double()124 self.set_image_mapper_double()
124 resp = self.client.post(125 resp = self.client.post(
125 '/v1/test',126 '/v1/test',
126 data = {127 data={
127 'package-name': 'librepng',128 'package-name': 'librepng',
128 'architecture': 'i386',129 'architecture': 'i386',
129 'platform': 'nova',130 'platform': 'nova',
@@ -165,7 +166,8 @@
165166
166class ImageMapperProxyDouble(object):167class ImageMapperProxyDouble(object):
167168
168 """A test double for the image mapper proxy. Simply returns a simple string."""169 """A test double for the image mapper proxy. Simply returns a simple
170 string."""
169171
170 def get_image_name_for_series_and_architectiure(self, series, arch):172 def get_image_name_for_series_and_architectiure(self, series, arch):
171 return "some-nova-image"173 return "some-nova-image"
@@ -179,8 +181,8 @@
179 unit tests.181 unit tests.
180182
181 What we can do, which is a reasonable half-measure is to configure the183 What we can do, which is a reasonable half-measure is to configure the
182 queuer class with an in-memory transport, and attempt to rigerously test the184 queuer class with an in-memory transport, and attempt to rigerously test
183 interface between the queuer and it's caller.185 the interface between the queuer and it's caller.
184186
185 """187 """
186 def test_queueing_does_not_alter_payload(self):188 def test_queueing_does_not_alter_payload(self):
@@ -193,7 +195,7 @@
193 'series': 'trusty',195 'series': 'trusty',
194 }196 }
195 copy_payload = test_payload.copy()197 copy_payload = test_payload.copy()
196 request_id = q.queue_test(copy_payload)198 q.queue_test(copy_payload)
197 self.assertEqual(test_payload, copy_payload)199 self.assertEqual(test_payload, copy_payload)
198200
199 def test_attempt_queue_test(self):201 def test_attempt_queue_test(self):
@@ -218,7 +220,6 @@
218 self.assertEqual(test_payload, message.payload)220 self.assertEqual(test_payload, message.payload)
219221
220222
221
222class ImageMapperFunctionalTests(testtools.TestCase):223class ImageMapperFunctionalTests(testtools.TestCase):
223224
224 """Tests for the utility functions in the image module"""225 """Tests for the utility functions in the image module"""
225226
=== modified file 'adt_cloud_service/v1.py'
--- adt_cloud_service/v1.py 2015-03-19 21:53:51 +0000
+++ adt_cloud_service/v1.py 2015-04-14 22:25:59 +0000
@@ -20,7 +20,7 @@
20import logging20import logging
21import urllib.parse21import urllib.parse
2222
23from flask import current_app, request, url_for, jsonify23from flask import current_app, request, jsonify
2424
25from adt_cloud_service.errors import MissingRequestParameters25from adt_cloud_service.errors import MissingRequestParameters
2626
@@ -36,7 +36,8 @@
36 }36 }
37 missing = required_keys.difference(set(request.form.keys()))37 missing = required_keys.difference(set(request.form.keys()))
38 if missing:38 if missing:
39 logger.error("Got request %r with missing keys %r", dict(request.form), missing)39 logger.error("Got request %r with missing keys %r",
40 dict(request.form), missing)
40 raise MissingRequestParameters(missing)41 raise MissingRequestParameters(missing)
4142
42 rabbit_request = dict()43 rabbit_request = dict()
4344
=== modified file 'called-by-tarmac.py'
--- called-by-tarmac.py 2015-03-17 13:49:18 +0000
+++ called-by-tarmac.py 2015-04-14 22:25:59 +0000
@@ -89,6 +89,11 @@
89 'setup.py',89 'setup.py',
90 'test',90 'test',
91 ],91 ],
92 [
93 os.path.join(ve_dir, 'bin', 'python3'),
94 'setup.py',
95 'flake8',
96 ],
92 )97 )
93 for cmd in all_cmds:98 for cmd in all_cmds:
94 ret = _run_command(cmd)99 ret = _run_command(cmd)
95100
=== modified file 'setup.py'
--- setup.py 2015-03-13 02:19:05 +0000
+++ setup.py 2015-04-14 22:25:59 +0000
@@ -21,7 +21,7 @@
21import sys21import sys
22assert sys.version_info >= (3,), 'Python 3 is required'22assert sys.version_info >= (3,), 'Python 3 is required'
2323
24from setuptools import find_packages, setup, Extension24from setuptools import find_packages, setup
2525
2626
27VERSION = '1.0.0'27VERSION = '1.0.0'
@@ -30,7 +30,8 @@
30setup(30setup(
31 name='adt-cloud-service',31 name='adt-cloud-service',
32 version=VERSION,32 version=VERSION,
33 description='A microservice that queues test runs via a RESTful interface.',33 description='A microservice that queues test runs '
34 'via a RESTful interface.',
34 author='Canonical CI Engineering Team',35 author='Canonical CI Engineering Team',
35 author_email='canonical-ci-engineering@lists.launchpad.net',36 author_email='canonical-ci-engineering@lists.launchpad.net',
36 url='https://launchpad.net/adt-cloud-service',37 url='https://launchpad.net/adt-cloud-service',
3738
=== modified file 'test_requirements.txt'
--- test_requirements.txt 2015-03-09 03:29:34 +0000
+++ test_requirements.txt 2015-04-14 22:25:59 +0000
@@ -1,1 +1,2 @@
1testtools==1.5.0
2\ No newline at end of file1\ No newline at end of file
2testtools==1.5.0
3flake8==2.4.0

Subscribers

People subscribed via source and target branches