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
=== modified file 'hooks/hooks.py'
--- hooks/hooks.py 2015-04-22 09:12:36 +0000
+++ hooks/hooks.py 2015-05-22 05:41:12 +0000
@@ -40,9 +40,11 @@
4040
41hooks = Hooks()41hooks = Hooks()
4242
43CHARM_PACKAGES = ["python-pip", "python-jinja2", "mercurial", "git-core",43CHARM_DEB_PACKAGES = ["python-pip", "python-jinja2", "mercurial", "git-core",
44 "subversion", "bzr", "gettext"]44 "subversion", "bzr", "gettext"]
4545
46CHARM_PIP_PACKAGES = ["semantic_version"]
47
46INJECTED_WARNING = """48INJECTED_WARNING = """
47#------------------------------------------------------------------------------49#------------------------------------------------------------------------------
48# The following is the import code for the settings directory injected by Juju50# The following is the import code for the settings directory injected by Juju
@@ -245,17 +247,22 @@
245 applications.247 applications.
246 """248 """
247 django_admin_cmd = find_django_admin_cmd()249 django_admin_cmd = find_django_admin_cmd()
248 # TODO: only run syncdb if Django version is < 1.7250
249 try:251 django_version = semantic_version.Version(
250 run("%s syncdb --noinput --settings=%s" %252 subprocess.check_output([django_admin_cmd, '--version']),
251 (django_admin_cmd, settings_module),253 partial=True)
252 exit_on_error=exit_on_error, cwd=working_dir)254 django_migrate = django_version >= semantic_version.Version('1.7.0')
253 except:255
254 if not swallow_exceptions:256 if not django_migrate:
255 raise257 try:
256258 run("%s syncdb --noinput --settings=%s" %
257 # TODO: check should be (django_south or Django version > 1.7)259 (django_admin_cmd, settings_module),
258 if django_south:260 exit_on_error=exit_on_error, cwd=working_dir)
261 except:
262 if not swallow_exceptions:
263 raise
264
265 if django_migrate or django_south:
259 try:266 try:
260 run("%s migrate --settings=%s" %267 run("%s migrate --settings=%s" %
261 (django_admin_cmd, settings_module),268 (django_admin_cmd, settings_module),
@@ -270,16 +277,16 @@
270###############################################################################277###############################################################################
271@hooks.hook()278@hooks.hook()
272def install():279def install():
273 log("Installing {}".format(unit_name))280 log("Installing {}".format(service_name()))
274 apt_update()281 apt_update()
275282
276 packages = []283 deb_packages = list(CHARM_DEB_PACKAGES)
277 if extra_deb_pkgs:284 if extra_deb_pkgs:
278 packages = extra_deb_pkgs.split(',') + CHARM_PACKAGES285 deb_packages.extend(extra_deb_pkgs.split(','))
279286
280 for retry in range(0, 24):287 for retry in range(0, 24):
281 try:288 try:
282 apt_install(packages)289 apt_install(deb_packages)
283 except subprocess.CalledProcessError as e:290 except subprocess.CalledProcessError as e:
284 log("Error ({}) running {}. Output: {}".format(291 log("Error ({}) running {}. Output: {}".format(
285 e.returncode, e.cmd, e.output))292 e.returncode, e.cmd, e.output))
@@ -288,11 +295,13 @@
288295
289 break296 break
290297
298 pip_packages = list(CHARM_PIP_PACKAGES)
291 if extra_pip_pkgs:299 if extra_pip_pkgs:
292 for package in extra_pip_pkgs.split(','):300 pip_packages.extend(extra_pip_pkgs.split(','))
293 pip_install(package, upgrade=True)301 for package in pip_packages:
302 pip_install(package, upgrade=True)
294303
295 configure_and_install(django_version)304 configure_and_install(config_data['django_version'])
296305
297 if django_south:306 if django_south:
298 configure_and_install(django_south_version, distro="python-django-south", pip='South')307 configure_and_install(django_south_version, distro="python-django-south", pip='South')
@@ -306,9 +315,9 @@
306 if project_template_extension:315 if project_template_extension:
307 cmd = " ".join([cmd, '--extension', project_template_extension])316 cmd = " ".join([cmd, '--extension', project_template_extension])
308 try:317 try:
309 run('%s %s %s' % (cmd, sanitized_unit_name, install_root), exit_on_error=False)318 run('%s %s %s' % (cmd, sanitized_service_name, install_root), exit_on_error=False)
310 except subprocess.CalledProcessError:319 except subprocess.CalledProcessError:
311 run('%s %s' % (cmd, sanitized_unit_name), cwd=install_root)320 run('%s %s' % (cmd, sanitized_service_name), cwd=install_root)
312 elif vcs == 'hg' or vcs == 'mercurial':321 elif vcs == 'hg' or vcs == 'mercurial':
313 run('hg clone %s %s' % (repos_url, vcs_clone_dir))322 run('hg clone %s %s' % (repos_url, vcs_clone_dir))
314 elif vcs == 'git' or vcs == 'git-core':323 elif vcs == 'git' or vcs == 'git-core':
@@ -340,21 +349,21 @@
340349
341 wsgi_py_path = os.path.join(working_dir, 'wsgi.py')350 wsgi_py_path = os.path.join(working_dir, 'wsgi.py')
342 if not os.path.exists(wsgi_py_path):351 if not os.path.exists(wsgi_py_path):
343 process_template('wsgi.py.tmpl', {'project_name': sanitized_unit_name,352 process_template('wsgi.py.tmpl', {'project_name': sanitized_service_name,
344 'django_settings': settings_module},353 'django_settings': settings_module},
345 wsgi_py_path)354 wsgi_py_path)
346355
347356
348@hooks.hook()357@hooks.hook()
349def start():358def start():
350 if os.path.exists(os.path.join('/etc/init/', sanitized_unit_name + '.conf')):359 if os.path.exists(os.path.join('/etc/init/', sanitized_service_name + '.conf')):
351 service_start(sanitized_unit_name)360 service_start(sanitized_service_name)
352361
353362
354@hooks.hook()363@hooks.hook()
355def stop():364def stop():
356 if os.path.exists(os.path.join('/etc/init/', sanitized_unit_name + '.conf')):365 if os.path.exists(os.path.join('/etc/init/', sanitized_service_name + '.conf')):
357 service_stop(sanitized_unit_name)366 service_stop(sanitized_service_name)
358367
359368
360@hooks.hook()369@hooks.hook()
@@ -395,7 +404,7 @@
395 apt_update()404 apt_update()
396 for retry in range(0, 24):405 for retry in range(0, 24):
397 try:406 try:
398 apt_install(CHARM_PACKAGES)407 apt_install(CHARM_DEB_PACKAGES)
399 except subprocess.CalledProcessError as e:408 except subprocess.CalledProcessError as e:
400 log("Error ({}) running {}. Output: {}".format(409 log("Error ({}) running {}. Output: {}".format(
401 e.returncode, e.cmd, e.output))410 e.returncode, e.cmd, e.output))
@@ -406,9 +415,11 @@
406415
407 # FIXME: pull new code ?416 # FIXME: pull new code ?
408417
418 pip_packages = list(CHARM_PIP_PACKAGES)
409 if extra_pip_pkgs:419 if extra_pip_pkgs:
410 for package in extra_pip_pkgs.split(','):420 pip_packages.extend(extra_pip_pkgs.split(','))
411 pip_install(package, upgrade=True)421 for package in pip_packages:
422 pip_install(package, upgrade=True)
412423
413 if requirements_pip_files:424 if requirements_pip_files:
414 for req_file in requirements_pip_files.split(','):425 for req_file in requirements_pip_files.split(','):
@@ -629,7 +640,7 @@
629@hooks.hook('amqp-relation-joined')640@hooks.hook('amqp-relation-joined')
630def amqp_relation_joined():641def amqp_relation_joined():
631 relation_set(relation_settings={642 relation_set(relation_settings={
632 'username': sanitized_unit_name, 'vhost': sanitized_unit_name})643 'username': sanitized_service_name, 'vhost': sanitized_service_name})
633644
634645
635@hooks.hook('amqp-relation-changed')646@hooks.hook('amqp-relation-changed')
@@ -644,8 +655,8 @@
644655
645 templ_vars = config_data656 templ_vars = config_data
646 templ_vars.update({657 templ_vars.update({
647 'username': sanitized_unit_name,658 'username': sanitized_service_name,
648 'vhost': config_data['celery_amqp_vhost'] or sanitized_unit_name659 'vhost': config_data['celery_amqp_vhost'] or sanitized_service_name
649 })660 })
650661
651 templ_vars.update(relation_get())662 templ_vars.update(relation_get())
@@ -716,7 +727,6 @@
716config_data = config()727config_data = config()
717log("got config: %s" % str(config_data), DEBUG)728log("got config: %s" % str(config_data), DEBUG)
718729
719django_version = config_data['django_version']
720vcs = config_data['vcs']730vcs = config_data['vcs']
721repos_url = config_data['repos_url']731repos_url = config_data['repos_url']
722repos_username = config_data['repos_username']732repos_username = config_data['repos_username']
@@ -739,9 +749,8 @@
739django_south = config_data['django_south']749django_south = config_data['django_south']
740django_south_version = config_data['django_south_version']750django_south_version = config_data['django_south_version']
741751
742unit_name = service_name()752sanitized_service_name = sanitize(service_name())
743sanitized_unit_name = sanitize(unit_name)753vcs_clone_dir = os.path.join(install_root, sanitized_service_name)
744vcs_clone_dir = os.path.join(install_root, sanitized_unit_name)
745if application_path:754if application_path:
746 working_dir = os.path.join(vcs_clone_dir, application_path)755 working_dir = os.path.join(vcs_clone_dir, application_path)
747else:756else:
@@ -759,7 +768,7 @@
759 if application_path:768 if application_path:
760 settings_module = '.'.join([os.path.basename(working_dir), 'settings'])769 settings_module = '.'.join([os.path.basename(working_dir), 'settings'])
761 else:770 else:
762 settings_module = '.'.join([sanitized_unit_name, 'settings'])771 settings_module = '.'.join([sanitized_service_name, 'settings'])
763772
764django_run_dir = os.path.join(working_dir, "run/")773django_run_dir = os.path.join(working_dir, "run/")
765django_logs_dir = os.path.join(working_dir, "logs/")774django_logs_dir = os.path.join(working_dir, "logs/")

Subscribers

People subscribed via source and target branches