Merge lp:~wesmason/conn-check/configs-django-dev into lp:~ubuntuone-hackers/conn-check/configs

Proposed by Wes Mason
Status: Merged
Approved by: James Westby
Approved revision: 15
Merged at revision: 14
Proposed branch: lp:~wesmason/conn-check/configs-django-dev
Merge into: lp:~ubuntuone-hackers/conn-check/configs
Diff against target: 45 lines (+27/-7)
1 file modified
conn_check_configs/django.py (+27/-7)
To merge this branch: bzr merge lp:~wesmason/conn-check/configs-django-dev
Reviewer Review Type Date Requested Status
James Westby (community) Approve
Review via email: mp+238968@code.launchpad.net

Commit message

Ignore path based database HOST values and set other values more flexibly for db engines

Description of the change

This adds greater flexibility to the checks generated for a django DATABASES value, ignoring path based hosts (e.g. unix socket FDs used for mysql/postgres), optionally sets the port/username/password depending on their presence (maintaining integer cast for port), and sets the checks for mysql/oracle as well as postgres (as these will be added to conn-check).

To post a comment you must log in.
Revision history for this message
James Westby (james-w) :
review: Needs Fixing
Revision history for this message
Wes Mason (wesmason) :
15. By Wes Mason

Add comment about skipping db file paths

Revision history for this message
James Westby (james-w) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'conn_check_configs/django.py'
2--- conn_check_configs/django.py 2014-10-15 12:47:18 +0000
3+++ conn_check_configs/django.py 2014-10-21 14:04:05 +0000
4@@ -39,16 +39,36 @@
5
6 def make_postgres_checks(settings, options):
7 checks = []
8+ engines = {
9+ 'django.db.backends.postgresql_psycopg2': 'postgres',
10+ 'django.db.backends.mysql': 'mysql',
11+ 'django.db.backends.oracle': 'oracle',
12+ }
13 for name, db in settings.get('DATABASES', {}).items():
14- if db.get('ENGINE') == 'django.db.backends.postgresql_psycopg2':
15- checks.append({
16- 'type': 'postgres',
17+ # We exclude hosts starting with a forward slash (/) as these are
18+ # always socket filepaths for MySQL and PostgreSQL, see:
19+ # https://docs.djangoproject.com/en/dev/ref/settings/#host
20+ if db['ENGINE'] in engines and not str(db['HOST']).startswith('/'):
21+ check = {
22+ 'type': engines[db['engine']],
23 'database': db.get('NAME', options.db_name),
24 'host': db['HOST'],
25- 'port': int(db['PORT']),
26- 'username': db['USER'],
27- 'password': db['PASSWORD'],
28- })
29+ }
30+
31+ port = db['PORT']
32+ if port is not None:
33+ check['port'] = int(port)
34+
35+ username = db['USER']
36+ if username is not None:
37+ check['username'] = username
38+
39+ password = db['PASSWORD']
40+ if password is not None:
41+ check['password'] = password
42+
43+ checks.append(check)
44+
45 return checks
46
47

Subscribers

People subscribed via source and target branches

to all changes: