Merge lp:~michael.nelson/ubuntu-webcatalog/rt-61147-nagios-sca-import into lp:ubuntu-webcatalog

Proposed by Michael Nelson
Status: Rejected
Rejected by: Michael Nelson
Proposed branch: lp:~michael.nelson/ubuntu-webcatalog/rt-61147-nagios-sca-import
Merge into: lp:ubuntu-webcatalog
Diff against target: 242 lines (+55/-48)
8 files modified
.bzrignore (+1/-0)
django_project/config/main.cfg (+2/-24)
django_project/dev_logging.conf (+32/-0)
django_project/settings.py (+8/-1)
src/webcatalog/management/commands/import_exhibits.py (+1/-1)
src/webcatalog/management/commands/import_sca_apps.py (+9/-12)
src/webcatalog/templatetags/webcatalog.py (+2/-2)
src/webcatalog/wsgi.py (+0/-8)
To merge this branch: bzr merge lp:~michael.nelson/ubuntu-webcatalog/rt-61147-nagios-sca-import
Reviewer Review Type Date Requested Status
Canonical Consumer Applications Hackers Pending
Review via email: mp+182091@code.launchpad.net

Commit message

Switch to logging.config.fileConfig (as used in deployments) and add logger for import_sca_apps.

Description of the change

Switch to logging.config.fileConfig (as used in deployments) and add logger for import_sca_apps.

This is to fix RT 61147. Similar update of the deployed configs:

https://code.launchpad.net/~michael.nelson/ca-configs/uwc-add-sca-import-logging-config/+merge/182371

(it would be good to review the bracnhes together)

So I wasn't blindly updating the deployment logging config, I've updated the codebase to use the same logging config method (ie. from file). I hit one stumbling block (see the XXX), but otherwise works as expected.

To post a comment you must log in.

Unmerged revisions

189. By Michael Nelson

Removed other left-over logging config details.

188. By Michael Nelson

Switch to file-based logging config to match deployments.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2013-02-28 16:23:58 +0000
3+++ .bzrignore 2013-08-27 10:50:07 +0000
4@@ -16,3 +16,4 @@
5 django_project/local.cfg
6 django_project/sreclient.py
7 oopses/
8+tmp/*
9
10=== modified file 'django_project/config/main.cfg'
11--- django_project/config/main.cfg 2013-04-26 14:24:42 +0000
12+++ django_project/config/main.cfg 2013-08-27 10:50:07 +0000
13@@ -6,7 +6,6 @@
14 django.contrib.auth.backends.ModelBackend
15
16 databases = django_databases
17-logging = django_logging
18
19 debug = true
20 media_root = django_project/media_root_dev/
21@@ -73,29 +72,8 @@
22 engine = django.db.backends.sqlite3
23 name = webcatalog.db
24
25-[django_logging]
26-version = 1
27-disable_existing_loggers = True
28-handlers = django_logging_handlers
29-loggers = django_logging_loggers
30-root = django_logging_root
31-
32-[django_logging_root]
33-level = WARNING
34-
35-[django_logging_loggers]
36-django = django_logger
37-
38-[django_logger]
39-handlers = null
40-level = WARNING
41-
42-[django_logging_handlers]
43-null = django_null_logging_handler
44-
45-[django_null_logging_handler]
46-level = WARNING
47-class = django.utils.log.NullHandler
48+[logging]
49+webapp_logging_config = ./django_project/dev_logging.conf
50
51 [openid]
52 openid_sso_server_url = https://login.staging.ubuntu.com
53
54=== added file 'django_project/dev_logging.conf'
55--- django_project/dev_logging.conf 1970-01-01 00:00:00 +0000
56+++ django_project/dev_logging.conf 2013-08-27 10:50:07 +0000
57@@ -0,0 +1,32 @@
58+[loggers]
59+keys=root,import_sca_apps
60+
61+[handlers]
62+keys=webapp,commands
63+
64+[formatters]
65+keys=simple_formatter
66+
67+[logger_root]
68+level=INFO
69+handlers=webapp
70+
71+[logger_import_sca_apps]
72+level=INFO
73+handlers=commands
74+propagate=0
75+qualname=webcatalog.management.commands.import_sca_apps
76+
77+[handler_webapp]
78+class=FileHandler
79+args=('./tmp/webapp.log',)
80+formatter=simple_formatter
81+
82+[handler_commands]
83+class=FileHandler
84+args=('./tmp/import_sca_apps.log',)
85+formatter=simple_formatter
86+
87+[formatter_simple_formatter]
88+format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
89+datefmt=
90
91=== modified file 'django_project/settings.py'
92--- django_project/settings.py 2012-06-26 23:43:35 +0000
93+++ django_project/settings.py 2013-08-27 10:50:07 +0000
94@@ -13,7 +13,14 @@
95 'local.cfg'])
96 if os.path.exists(path)]
97
98-configglue(WebCatalogSchema, config_files, __name__)
99+parser = configglue(WebCatalogSchema, config_files, __name__)
100
101 import djcelery
102 djcelery.setup_loader()
103+
104+# XXX 2013-08-27 bug=1217290 django_configglue doesn't support file config.
105+# Configure the logging once the settings have been parsed.
106+import logging.config
107+logging.config.fileConfig(
108+ parser.get('logging', 'webapp_logging_config'),
109+ disable_existing_loggers=True)
110
111=== modified file 'src/webcatalog/management/commands/import_exhibits.py'
112--- src/webcatalog/management/commands/import_exhibits.py 2012-08-20 15:34:18 +0000
113+++ src/webcatalog/management/commands/import_exhibits.py 2013-08-27 10:50:07 +0000
114@@ -81,4 +81,4 @@
115 # Unpublish other exhibits
116 Exhibit.objects.filter(published=True).exclude(
117 sca_id__in=[xibit['id'] for xibit in exhibits]).update(
118- published=False)
119+ published=False)
120
121=== modified file 'src/webcatalog/management/commands/import_sca_apps.py'
122--- src/webcatalog/management/commands/import_sca_apps.py 2012-08-21 13:57:11 +0000
123+++ src/webcatalog/management/commands/import_sca_apps.py 2013-08-27 10:50:07 +0000
124@@ -22,6 +22,7 @@
125 from __future__ import absolute_import
126
127 import json
128+import logging
129 import os
130 import urllib
131 from collections import defaultdict
132@@ -42,12 +43,15 @@
133 __all__ = []
134
135
136+logger = logging.getLogger(__name__)
137+
138+
139 class Command(BaseCommand):
140 help = "Import for-purchase applications from Software Center."
141- verbosity = 0
142
143 def handle(self, *args, **options):
144 url = '%sapplications/any/ubuntu/any/any/' % settings.SCA_API_URL
145+ logger.info("Starting import of sca apps at {0}".format(url))
146 # call api and get apps for purchase
147 response = urllib.urlopen(url)
148 if response.code != 200:
149@@ -55,8 +59,8 @@
150 app_list = json.loads(response.read())
151 imported_apps = Application.objects.filter(
152 imported_from_sca=True).values_list(
153- 'package_name',
154- 'distroseries__code_name')
155+ 'package_name',
156+ 'distroseries__code_name')
157 existing_apps = defaultdict(list)
158 for package_name, code_name in imported_apps:
159 existing_apps[package_name].append(code_name)
160@@ -71,7 +75,7 @@
161 distroseries, created = DistroSeries.objects.get_or_create(
162 code_name=series_name)
163 if created:
164- self.output(
165+ logger.info(
166 "Created a DistroSeries record called '{0}'.\n".format(
167 series_name), 1)
168 package_name = self.import_app_from_data(
169@@ -91,6 +95,7 @@
170 Application.objects.filter(
171 package_name=package_name,
172 distroseries__code_name__in=series).delete()
173+ logger.info("Finished import of {0} sca apps.".format(len(app_list)))
174
175 def import_app_from_data(self, app_data, icon_data, distroseries):
176 form = SCAApplicationForm.from_api_data(
177@@ -100,7 +105,6 @@
178 department_names = app_data.get('department', [])
179 app.update_departments(department_names)
180 self.add_icon_to_app(app, data=icon_data)
181- self.output(u"{0} created.\n".format(app.name).encode('utf-8'), 1)
182 return app.package_name
183
184 def get_icon_data(self, app_data):
185@@ -125,10 +129,3 @@
186 finally:
187 if os.path.exists(filename):
188 os.unlink(filename)
189-
190- def output(self, message, level=None, flush=False):
191- if hasattr(self, 'stdout'):
192- if level is None or self.verbosity >= level:
193- self.stdout.write(message)
194- if flush:
195- self.stdout.flush()
196
197=== modified file 'src/webcatalog/templatetags/webcatalog.py'
198--- src/webcatalog/templatetags/webcatalog.py 2013-02-22 21:02:05 +0000
199+++ src/webcatalog/templatetags/webcatalog.py 2013-08-27 10:50:07 +0000
200@@ -79,8 +79,8 @@
201 '{application_name} is also available for '
202 '<a href="{app_in_series_url}">your version of '
203 'Ubuntu</a>.').format(
204- application_name=escape(application.name),
205- app_in_series_url=app_in_series_url)
206+ application_name=escape(application.name),
207+ app_in_series_url=app_in_series_url)
208 context['message_text'] = mark_safe(
209 context['message_text'])
210 return context
211
212=== modified file 'src/webcatalog/wsgi.py'
213--- src/webcatalog/wsgi.py 2013-02-28 16:23:58 +0000
214+++ src/webcatalog/wsgi.py 2013-08-27 10:50:07 +0000
215@@ -17,12 +17,10 @@
216
217 """wsgi stack for the Apps Directory."""
218
219-import logging.config
220 import oops_dictconfig
221 import oops_wsgi
222 import oops_wsgi.django
223 import os
224-import platform
225 import uuid
226
227 from django.conf import settings
228@@ -64,12 +62,6 @@
229 if settings.SHOULD_SERVE_HTTPS:
230 os.environ['HTTPS'] = 'on'
231
232- default_id = ''.join(x for x in platform.node() if x.isalpha())
233- appserver_id = getattr(settings, 'APPSERVER_ID', default_id)
234- logging_config = settings.WEBAPP_LOGGING_CONFIG
235- if logging_config:
236- logging.config.fileConfig(logging_config)
237-
238 non_oops_app = EagerOOPSWSGIHandler()
239
240 config = oops_dictconfig.config_from_dict(settings.OOPSES)
241
242=== added directory 'tmp'

Subscribers

People subscribed via source and target branches