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
1=== added file 'hooks/charmhelpers/contrib/hardening/apache/templates/__init__.py'
2=== added file 'hooks/charmhelpers/contrib/hardening/defaults/__init__.py'
3=== added file 'hooks/charmhelpers/contrib/hardening/host/templates/__init__.py'
4=== added file 'hooks/charmhelpers/contrib/hardening/mysql/templates/__init__.py'
5=== added file 'hooks/charmhelpers/contrib/hardening/ssh/templates/__init__.py'
6=== modified file 'hooks/charmhelpers/core/host.py'
7--- hooks/charmhelpers/core/host.py 2016-03-21 05:58:51 +0000
8+++ hooks/charmhelpers/core/host.py 2016-05-03 06:51:45 +0000
9@@ -128,6 +128,13 @@
10 return subprocess.call(cmd) == 0
11
12
13+def systemv_services_running():
14+ output = subprocess.check_output(
15+ ['service', '--status-all'],
16+ stderr=subprocess.STDOUT).decode('UTF-8')
17+ return [row.split()[-1] for row in output.split('\n') if '[ + ]' in row]
18+
19+
20 def service_running(service_name):
21 """Determine whether a system service is running"""
22 if init_is_systemd():
23@@ -140,11 +147,15 @@
24 except subprocess.CalledProcessError:
25 return False
26 else:
27+ # This works for upstart scripts where the 'service' command
28+ # returns a consistent string to represent running 'start/running'
29 if ("start/running" in output or "is running" in output or
30 "up and running" in output):
31 return True
32- else:
33- return False
34+ # Check System V scripts init script return codes
35+ if service_name in systemv_services_running():
36+ return True
37+ return False
38
39
40 def service_available(service_name):
41@@ -412,7 +423,7 @@
42 pass
43
44
45-def restart_on_change(restart_map, stopstart=False):
46+def restart_on_change(restart_map, stopstart=False, restart_functions=None):
47 """Restart services based on configuration files changing
48
49 This function is used a decorator, for example::
50@@ -433,18 +444,22 @@
51
52 @param restart_map: {path_file_name: [service_name, ...]
53 @param stopstart: DEFAULT false; whether to stop, start OR restart
54+ @param restart_functions: nonstandard functions to use to restart services
55+ {svc: func, ...}
56 @returns result from decorated function
57 """
58 def wrap(f):
59 @functools.wraps(f)
60 def wrapped_f(*args, **kwargs):
61 return restart_on_change_helper(
62- (lambda: f(*args, **kwargs)), restart_map, stopstart)
63+ (lambda: f(*args, **kwargs)), restart_map, stopstart,
64+ restart_functions)
65 return wrapped_f
66 return wrap
67
68
69-def restart_on_change_helper(lambda_f, restart_map, stopstart=False):
70+def restart_on_change_helper(lambda_f, restart_map, stopstart=False,
71+ restart_functions=None):
72 """Helper function to perform the restart_on_change function.
73
74 This is provided for decorators to restart services if files described
75@@ -453,8 +468,12 @@
76 @param lambda_f: function to call.
77 @param restart_map: {file: [service, ...]}
78 @param stopstart: whether to stop, start or restart a service
79+ @param restart_functions: nonstandard functions to use to restart services
80+ {svc: func, ...}
81 @returns result of lambda_f()
82 """
83+ if restart_functions is None:
84+ restart_functions = {}
85 checksums = {path: path_hash(path) for path in restart_map}
86 r = lambda_f()
87 # create a list of lists of the services to restart
88@@ -465,9 +484,12 @@
89 services_list = list(OrderedDict.fromkeys(itertools.chain(*restarts)))
90 if services_list:
91 actions = ('stop', 'start') if stopstart else ('restart',)
92- for action in actions:
93- for service_name in services_list:
94- service(action, service_name)
95+ for service_name in services_list:
96+ if service_name in restart_functions:
97+ restart_functions[service_name](service_name)
98+ else:
99+ for action in actions:
100+ service(action, service_name)
101 return r
102
103
104
105=== modified file 'hooks/ntpmaster_hooks.py'
106--- hooks/ntpmaster_hooks.py 2016-03-21 06:18:46 +0000
107+++ hooks/ntpmaster_hooks.py 2016-05-03 06:51:45 +0000
108@@ -1,4 +1,4 @@
109-#!/usr/bin/python
110+#!/usr/bin/python3
111
112 import sys
113 import shutil

Subscribers

People subscribed via source and target branches

to all changes: