Merge lp:~thumper/charms/trusty/python-django/support-1.7 into lp:charms/python-django

Proposed by Tim Penhey
Status: Merged
Merged at revision: 38
Proposed branch: lp:~thumper/charms/trusty/python-django/support-1.7
Merge into: lp:charms/python-django
Diff against target: 199 lines (+46/-37)
1 file modified
hooks/hooks.py (+46/-37)
To merge this branch: bzr merge lp:~thumper/charms/trusty/python-django/support-1.7
Reviewer Review Type Date Requested Status
Charles Butler (community) Approve
Review via email: mp+259889@code.launchpad.net

Description of the change

This branch introduces a few tweaks, and support for Django 1.7 and above.

Some renaming was done in the code for my own sanity.
  sanitized_unit_name
became
  sanitized_service_name

The unit_name variable has been removed. Assigning service_name into unit_name was just confusing.

In order to handle checking the version number of django, a new pip package was added semantic_version.
Support for installing this package was added to the install and upgrade hooks.

The install hook didn't install the CHARM_PACKAGES (now called CHARM_DEB_PACKAGES) if the extra_deb_pkgs value was empty.

I haven't managed to work out how to run the unit tests inside the hooks dir.

If someone can help point that out, I'll add some unit tests for the 1.7 checking code.

To post a comment you must log in.
Revision history for this message
Charles Butler (lazypower) wrote :

Tim,

Thank you for this contribution! It's great to see the python-django charm getting some love as its one of our few framework charms. I feel like your contributions have made a great impact in cleaning up some of the nomenclature and functionality of the charm for future contributors.

I deployed the charm and gave the charm a deploy test along with stressing the existing charm before pulling in your changes.

There is a minor linting issue that cropped up on this contribution:

FAIL: python-django::make lint
[/usr/bin/make -s lint exit 2]
Lint check (flake8)
hooks/hooks.py:44:19: E128 continuation line under-indented for visual indent
hooks/hooks.py:251:22: F821 undefined name 'semantic_version'
hooks/hooks.py:254:40: F821 undefined name 'semantic_version'
make: *** [lint] Error 1

If you could get those cleaned up in a subsequent patch, that would be +1 from me.

Thank you for taking the time to submit this fix for the charm store. We appreciate your work. I've merged this branch and it should be available in the charm store after the next ingestion. I look forward to the forthcoming updates to the python-django ecosystem from you :)

If you have any questions/comments/concerns about the review contact us in #juju on irc.freenode.net or email the mailing list <email address hidden>, or ask a question tagged with "juju" on http://askubuntu.com.

review: Approve
Revision history for this message
Tim Penhey (thumper) wrote :

On 23/05/15 07:54, Charles Butler wrote:
> Review: Approve
>
> Tim,
>
> Thank you for this contribution! It's great to see the python-django charm getting some love as its one of our few framework charms. I feel like your contributions have made a great impact in cleaning up some of the nomenclature and functionality of the charm for future contributors.
>
> I deployed the charm and gave the charm a deploy test along with stressing the existing charm before pulling in your changes.
>
> There is a minor linting issue that cropped up on this contribution:
>
> FAIL: python-django::make lint
> [/usr/bin/make -s lint exit 2]
> Lint check (flake8)
> hooks/hooks.py:44:19: E128 continuation line under-indented for visual indent
> hooks/hooks.py:251:22: F821 undefined name 'semantic_version'
> hooks/hooks.py:254:40: F821 undefined name 'semantic_version'
> make: *** [lint] Error 1
>
> If you could get those cleaned up in a subsequent patch, that would be +1 from me.
>
>
> Thank you for taking the time to submit this fix for the charm store. We appreciate your work. I've merged this branch and it should be available in the charm store after the next ingestion. I look forward to the forthcoming updates to the python-django ecosystem from you :)
>
>
> If you have any questions/comments/concerns about the review contact us in #juju on irc.freenode.net or email the mailing list <email address hidden>, or ask a question tagged with "juju" on http://askubuntu.com.

I think we need to look at the process for checking that the charm works.

The lint issues identified above show that the code is clearly broken.
I have submitted another merge proposal that not only fixes this lint,
but adds tests to make sure it works as expected.

Tim

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/hooks.py'
2--- hooks/hooks.py 2015-04-22 09:12:36 +0000
3+++ hooks/hooks.py 2015-05-22 05:41:12 +0000
4@@ -40,9 +40,11 @@
5
6 hooks = Hooks()
7
8-CHARM_PACKAGES = ["python-pip", "python-jinja2", "mercurial", "git-core",
9+CHARM_DEB_PACKAGES = ["python-pip", "python-jinja2", "mercurial", "git-core",
10 "subversion", "bzr", "gettext"]
11
12+CHARM_PIP_PACKAGES = ["semantic_version"]
13+
14 INJECTED_WARNING = """
15 #------------------------------------------------------------------------------
16 # The following is the import code for the settings directory injected by Juju
17@@ -245,17 +247,22 @@
18 applications.
19 """
20 django_admin_cmd = find_django_admin_cmd()
21- # TODO: only run syncdb if Django version is < 1.7
22- try:
23- run("%s syncdb --noinput --settings=%s" %
24- (django_admin_cmd, settings_module),
25- exit_on_error=exit_on_error, cwd=working_dir)
26- except:
27- if not swallow_exceptions:
28- raise
29-
30- # TODO: check should be (django_south or Django version > 1.7)
31- if django_south:
32+
33+ django_version = semantic_version.Version(
34+ subprocess.check_output([django_admin_cmd, '--version']),
35+ partial=True)
36+ django_migrate = django_version >= semantic_version.Version('1.7.0')
37+
38+ if not django_migrate:
39+ try:
40+ run("%s syncdb --noinput --settings=%s" %
41+ (django_admin_cmd, settings_module),
42+ exit_on_error=exit_on_error, cwd=working_dir)
43+ except:
44+ if not swallow_exceptions:
45+ raise
46+
47+ if django_migrate or django_south:
48 try:
49 run("%s migrate --settings=%s" %
50 (django_admin_cmd, settings_module),
51@@ -270,16 +277,16 @@
52 ###############################################################################
53 @hooks.hook()
54 def install():
55- log("Installing {}".format(unit_name))
56+ log("Installing {}".format(service_name()))
57 apt_update()
58
59- packages = []
60+ deb_packages = list(CHARM_DEB_PACKAGES)
61 if extra_deb_pkgs:
62- packages = extra_deb_pkgs.split(',') + CHARM_PACKAGES
63+ deb_packages.extend(extra_deb_pkgs.split(','))
64
65 for retry in range(0, 24):
66 try:
67- apt_install(packages)
68+ apt_install(deb_packages)
69 except subprocess.CalledProcessError as e:
70 log("Error ({}) running {}. Output: {}".format(
71 e.returncode, e.cmd, e.output))
72@@ -288,11 +295,13 @@
73
74 break
75
76+ pip_packages = list(CHARM_PIP_PACKAGES)
77 if extra_pip_pkgs:
78- for package in extra_pip_pkgs.split(','):
79- pip_install(package, upgrade=True)
80+ pip_packages.extend(extra_pip_pkgs.split(','))
81+ for package in pip_packages:
82+ pip_install(package, upgrade=True)
83
84- configure_and_install(django_version)
85+ configure_and_install(config_data['django_version'])
86
87 if django_south:
88 configure_and_install(django_south_version, distro="python-django-south", pip='South')
89@@ -306,9 +315,9 @@
90 if project_template_extension:
91 cmd = " ".join([cmd, '--extension', project_template_extension])
92 try:
93- run('%s %s %s' % (cmd, sanitized_unit_name, install_root), exit_on_error=False)
94+ run('%s %s %s' % (cmd, sanitized_service_name, install_root), exit_on_error=False)
95 except subprocess.CalledProcessError:
96- run('%s %s' % (cmd, sanitized_unit_name), cwd=install_root)
97+ run('%s %s' % (cmd, sanitized_service_name), cwd=install_root)
98 elif vcs == 'hg' or vcs == 'mercurial':
99 run('hg clone %s %s' % (repos_url, vcs_clone_dir))
100 elif vcs == 'git' or vcs == 'git-core':
101@@ -340,21 +349,21 @@
102
103 wsgi_py_path = os.path.join(working_dir, 'wsgi.py')
104 if not os.path.exists(wsgi_py_path):
105- process_template('wsgi.py.tmpl', {'project_name': sanitized_unit_name,
106+ process_template('wsgi.py.tmpl', {'project_name': sanitized_service_name,
107 'django_settings': settings_module},
108 wsgi_py_path)
109
110
111 @hooks.hook()
112 def start():
113- if os.path.exists(os.path.join('/etc/init/', sanitized_unit_name + '.conf')):
114- service_start(sanitized_unit_name)
115+ if os.path.exists(os.path.join('/etc/init/', sanitized_service_name + '.conf')):
116+ service_start(sanitized_service_name)
117
118
119 @hooks.hook()
120 def stop():
121- if os.path.exists(os.path.join('/etc/init/', sanitized_unit_name + '.conf')):
122- service_stop(sanitized_unit_name)
123+ if os.path.exists(os.path.join('/etc/init/', sanitized_service_name + '.conf')):
124+ service_stop(sanitized_service_name)
125
126
127 @hooks.hook()
128@@ -395,7 +404,7 @@
129 apt_update()
130 for retry in range(0, 24):
131 try:
132- apt_install(CHARM_PACKAGES)
133+ apt_install(CHARM_DEB_PACKAGES)
134 except subprocess.CalledProcessError as e:
135 log("Error ({}) running {}. Output: {}".format(
136 e.returncode, e.cmd, e.output))
137@@ -406,9 +415,11 @@
138
139 # FIXME: pull new code ?
140
141+ pip_packages = list(CHARM_PIP_PACKAGES)
142 if extra_pip_pkgs:
143- for package in extra_pip_pkgs.split(','):
144- pip_install(package, upgrade=True)
145+ pip_packages.extend(extra_pip_pkgs.split(','))
146+ for package in pip_packages:
147+ pip_install(package, upgrade=True)
148
149 if requirements_pip_files:
150 for req_file in requirements_pip_files.split(','):
151@@ -629,7 +640,7 @@
152 @hooks.hook('amqp-relation-joined')
153 def amqp_relation_joined():
154 relation_set(relation_settings={
155- 'username': sanitized_unit_name, 'vhost': sanitized_unit_name})
156+ 'username': sanitized_service_name, 'vhost': sanitized_service_name})
157
158
159 @hooks.hook('amqp-relation-changed')
160@@ -644,8 +655,8 @@
161
162 templ_vars = config_data
163 templ_vars.update({
164- 'username': sanitized_unit_name,
165- 'vhost': config_data['celery_amqp_vhost'] or sanitized_unit_name
166+ 'username': sanitized_service_name,
167+ 'vhost': config_data['celery_amqp_vhost'] or sanitized_service_name
168 })
169
170 templ_vars.update(relation_get())
171@@ -716,7 +727,6 @@
172 config_data = config()
173 log("got config: %s" % str(config_data), DEBUG)
174
175-django_version = config_data['django_version']
176 vcs = config_data['vcs']
177 repos_url = config_data['repos_url']
178 repos_username = config_data['repos_username']
179@@ -739,9 +749,8 @@
180 django_south = config_data['django_south']
181 django_south_version = config_data['django_south_version']
182
183-unit_name = service_name()
184-sanitized_unit_name = sanitize(unit_name)
185-vcs_clone_dir = os.path.join(install_root, sanitized_unit_name)
186+sanitized_service_name = sanitize(service_name())
187+vcs_clone_dir = os.path.join(install_root, sanitized_service_name)
188 if application_path:
189 working_dir = os.path.join(vcs_clone_dir, application_path)
190 else:
191@@ -759,7 +768,7 @@
192 if application_path:
193 settings_module = '.'.join([os.path.basename(working_dir), 'settings'])
194 else:
195- settings_module = '.'.join([sanitized_unit_name, 'settings'])
196+ settings_module = '.'.join([sanitized_service_name, 'settings'])
197
198 django_run_dir = os.path.join(working_dir, "run/")
199 django_logs_dir = os.path.join(working_dir, "logs/")

Subscribers

People subscribed via source and target branches