Merge lp:~tribaal/charms/trusty/ntpmaster/python3-hooks into lp:charms/trusty/ntpmaster

Proposed by Chris Glass
Status: Merged
Merged at revision: 16
Proposed branch: lp:~tribaal/charms/trusty/ntpmaster/python3-hooks
Merge into: lp:charms/trusty/ntpmaster
Diff against target: 113 lines (+31/-9)
2 files modified
hooks/charmhelpers/core/host.py (+30/-8)
hooks/ntpmaster_hooks.py (+1/-1)
To merge this branch: bzr merge lp:~tribaal/charms/trusty/ntpmaster/python3-hooks
Reviewer Review Type Date Requested Status
Review Queue (community) automated testing Needs Fixing
Charles Butler (community) Approve
Review via email: mp+293587@code.launchpad.net

Description of the change

This branch makes the charm code run on python3 instead of python2, since the latter is not available on a Xenial+ image by default.

Steps taken:

- Refresh charmhelpers (they now use six where necesseary)
- Change the shebang to point to python3 instead of python.

Tests done:

Autopilot deployments didn't reveal any problems (charm installs and works as expected) on both trusty and xenial.

To post a comment you must log in.
Revision history for this message
Chris Glass (tribaal) wrote :

This exact code is already published to the charm store at cs:~tribaal/xenial/ntpmaster-python3-0 for testing purposes.

Revision history for this message
Charles Butler (lazypower) wrote :

+1 LGTM

It gets a clean bill of health from bundle tester
PASS: 4 Total: 4 (357.364986 sec)

Thanks for the contribution!

review: Approve
Revision history for this message
Charles Butler (lazypower) wrote :

Thanks for the submission! A few things I did as a follow up i want documented as the new charm store bits may have some dragons in there...

- pushed this to cs:~landscape-charmers/trusty/ntpmaster-0
- set acl to read=everyone
- promulgated this to ntpmaster-5 in the store

Any future pushes to cs:~landscape-charmers/trusty/ntpmaster should auto-rev the promulgated version. Use best practices for testing releases before pushing directly to this space :)

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.

Revision history for this message
Review Queue (review-queue) wrote :

This item has failed automated testing! Results available here http://juju-ci.vapour.ws:8080/job/charm-bundle-test-lxc/3987/

review: Needs Fixing (automated testing)
Revision history for this message
Review Queue (review-queue) wrote :

This item has failed automated testing! Results available here http://juju-ci.vapour.ws:8080/job/charm-bundle-test-aws/4028/

review: Needs Fixing (automated testing)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'hooks/charmhelpers/contrib/hardening/apache/templates/__init__.py'
=== added file 'hooks/charmhelpers/contrib/hardening/defaults/__init__.py'
=== added file 'hooks/charmhelpers/contrib/hardening/host/templates/__init__.py'
=== added file 'hooks/charmhelpers/contrib/hardening/mysql/templates/__init__.py'
=== added file 'hooks/charmhelpers/contrib/hardening/ssh/templates/__init__.py'
=== modified file 'hooks/charmhelpers/core/host.py'
--- hooks/charmhelpers/core/host.py 2016-03-21 05:58:51 +0000
+++ hooks/charmhelpers/core/host.py 2016-05-03 06:51:45 +0000
@@ -128,6 +128,13 @@
128 return subprocess.call(cmd) == 0128 return subprocess.call(cmd) == 0
129129
130130
131def systemv_services_running():
132 output = subprocess.check_output(
133 ['service', '--status-all'],
134 stderr=subprocess.STDOUT).decode('UTF-8')
135 return [row.split()[-1] for row in output.split('\n') if '[ + ]' in row]
136
137
131def service_running(service_name):138def service_running(service_name):
132 """Determine whether a system service is running"""139 """Determine whether a system service is running"""
133 if init_is_systemd():140 if init_is_systemd():
@@ -140,11 +147,15 @@
140 except subprocess.CalledProcessError:147 except subprocess.CalledProcessError:
141 return False148 return False
142 else:149 else:
150 # This works for upstart scripts where the 'service' command
151 # returns a consistent string to represent running 'start/running'
143 if ("start/running" in output or "is running" in output or152 if ("start/running" in output or "is running" in output or
144 "up and running" in output):153 "up and running" in output):
145 return True154 return True
146 else:155 # Check System V scripts init script return codes
147 return False156 if service_name in systemv_services_running():
157 return True
158 return False
148159
149160
150def service_available(service_name):161def service_available(service_name):
@@ -412,7 +423,7 @@
412 pass423 pass
413424
414425
415def restart_on_change(restart_map, stopstart=False):426def restart_on_change(restart_map, stopstart=False, restart_functions=None):
416 """Restart services based on configuration files changing427 """Restart services based on configuration files changing
417428
418 This function is used a decorator, for example::429 This function is used a decorator, for example::
@@ -433,18 +444,22 @@
433444
434 @param restart_map: {path_file_name: [service_name, ...]445 @param restart_map: {path_file_name: [service_name, ...]
435 @param stopstart: DEFAULT false; whether to stop, start OR restart446 @param stopstart: DEFAULT false; whether to stop, start OR restart
447 @param restart_functions: nonstandard functions to use to restart services
448 {svc: func, ...}
436 @returns result from decorated function449 @returns result from decorated function
437 """450 """
438 def wrap(f):451 def wrap(f):
439 @functools.wraps(f)452 @functools.wraps(f)
440 def wrapped_f(*args, **kwargs):453 def wrapped_f(*args, **kwargs):
441 return restart_on_change_helper(454 return restart_on_change_helper(
442 (lambda: f(*args, **kwargs)), restart_map, stopstart)455 (lambda: f(*args, **kwargs)), restart_map, stopstart,
456 restart_functions)
443 return wrapped_f457 return wrapped_f
444 return wrap458 return wrap
445459
446460
447def restart_on_change_helper(lambda_f, restart_map, stopstart=False):461def restart_on_change_helper(lambda_f, restart_map, stopstart=False,
462 restart_functions=None):
448 """Helper function to perform the restart_on_change function.463 """Helper function to perform the restart_on_change function.
449464
450 This is provided for decorators to restart services if files described465 This is provided for decorators to restart services if files described
@@ -453,8 +468,12 @@
453 @param lambda_f: function to call.468 @param lambda_f: function to call.
454 @param restart_map: {file: [service, ...]}469 @param restart_map: {file: [service, ...]}
455 @param stopstart: whether to stop, start or restart a service470 @param stopstart: whether to stop, start or restart a service
471 @param restart_functions: nonstandard functions to use to restart services
472 {svc: func, ...}
456 @returns result of lambda_f()473 @returns result of lambda_f()
457 """474 """
475 if restart_functions is None:
476 restart_functions = {}
458 checksums = {path: path_hash(path) for path in restart_map}477 checksums = {path: path_hash(path) for path in restart_map}
459 r = lambda_f()478 r = lambda_f()
460 # create a list of lists of the services to restart479 # create a list of lists of the services to restart
@@ -465,9 +484,12 @@
465 services_list = list(OrderedDict.fromkeys(itertools.chain(*restarts)))484 services_list = list(OrderedDict.fromkeys(itertools.chain(*restarts)))
466 if services_list:485 if services_list:
467 actions = ('stop', 'start') if stopstart else ('restart',)486 actions = ('stop', 'start') if stopstart else ('restart',)
468 for action in actions:487 for service_name in services_list:
469 for service_name in services_list:488 if service_name in restart_functions:
470 service(action, service_name)489 restart_functions[service_name](service_name)
490 else:
491 for action in actions:
492 service(action, service_name)
471 return r493 return r
472494
473495
474496
=== modified file 'hooks/ntpmaster_hooks.py'
--- hooks/ntpmaster_hooks.py 2016-03-21 06:18:46 +0000
+++ hooks/ntpmaster_hooks.py 2016-05-03 06:51:45 +0000
@@ -1,4 +1,4 @@
1#!/usr/bin/python1#!/usr/bin/python3
22
3import sys3import sys
4import shutil4import shutil

Subscribers

People subscribed via source and target branches

to all changes: