Merge lp:~brad-marshall/charms/trusty/swift-proxy/add-nrpe-checks into lp:~openstack-charmers-archive/charms/trusty/swift-proxy/trunk

Proposed by Brad Marshall
Status: Merged
Merged at revision: 76
Proposed branch: lp:~brad-marshall/charms/trusty/swift-proxy/add-nrpe-checks
Merge into: lp:~openstack-charmers-archive/charms/trusty/swift-proxy/trunk
Diff against target: 559 lines (+462/-0) (has conflicts)
7 files modified
charm-helpers-hooks.yaml (+1/-0)
config.yaml (+11/-0)
hooks/charmhelpers/contrib/charmsupport/nrpe.py (+222/-0)
hooks/charmhelpers/contrib/charmsupport/volumes.py (+156/-0)
hooks/swift_hooks.py (+61/-0)
hooks/swift_utils.py (+8/-0)
metadata.yaml (+3/-0)
Text conflict in hooks/swift_hooks.py
To merge this branch: bzr merge lp:~brad-marshall/charms/trusty/swift-proxy/add-nrpe-checks
Reviewer Review Type Date Requested Status
Liam Young (community) Disapprove
Review via email: mp+241484@code.launchpad.net

Description of the change

Adds nrpe-external-master interface and adds basic nrpe checks.

To post a comment you must log in.
Revision history for this message
Ryan Beisner (1chb1n) wrote :

UOSCI bot says:
charm_unit_test #822 trusty-swift-proxy for brad-marshall mp241484
    UNIT OK: passed

UNIT Results (max last 5 lines):
  hooks/swift_hooks 190 190 0% 3-388
  hooks/swift_utils 189 189 0% 1-393
  TOTAL 464 464 0%
  Ran 5 tests in 0.179s
  OK

Full unit test output: http://paste.ubuntu.com/8955706/
Build: http://10.98.191.181:8080/job/charm_unit_test/822/

Revision history for this message
Ryan Beisner (1chb1n) wrote :

UOSCI bot says:
charm_lint_check #987 trusty-swift-proxy for brad-marshall mp241484
    LINT FAIL: lint-test failed

LINT Results (max last 5 lines):
  hooks/swift_hooks.py:357:80: E501 line too long (92 > 79 characters)
  hooks/swift_hooks.py:378:18: E251 unexpected spaces around keyword / parameter equals
  hooks/swift_hooks.py:378:20: E251 unexpected spaces around keyword / parameter equals
  hooks/swift_hooks.py:379:9: E123 closing bracket does not match indentation of opening bracket's line
  make: *** [lint] Error 1

Full lint test output: http://paste.ubuntu.com/8955707/
Build: http://10.98.191.181:8080/job/charm_lint_check/987/

Revision history for this message
Ryan Beisner (1chb1n) wrote :

UOSCI bot says:
charm_amulet_test #367 trusty-swift-proxy for brad-marshall mp241484
    AMULET FAIL: amulet-test failed

AMULET Results (max last 5 lines):
  juju-test.conductor DEBUG : Tearing down osci-sv05 juju environment
  juju-test.conductor DEBUG : Calling "juju destroy-environment -y osci-sv05"
  juju-test INFO : Results: 1 passed, 2 failed, 0 errored
  ERROR subprocess encountered error code 2
  make: *** [test] Error 2

Full amulet test output: http://paste.ubuntu.com/8955846/
Build: http://10.98.191.181:8080/job/charm_amulet_test/367/

72. By Brad Marshall

[bradm] Added sysvinit daemon monitoring, use services() instead of hard coded daemon list, pep8 fixes

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

UOSCI bot says:
charm_lint_check #1084 trusty-swift-proxy for brad-marshall mp241484
    LINT FAIL: lint-test failed

LINT Results (max last 5 lines):
INFO:root:command: make -f Makefile lint
ERROR:root:Make target returned non-zero.
  hooks/swift_hooks.py:387:17: E123 closing bracket does not match indentation of opening bracket's line
  hooks/swift_hooks.py:404:17: E123 closing bracket does not match indentation of opening bracket's line
  make: *** [lint] Error 1

Full lint test output: http://paste.ubuntu.com/9052124/
Build: http://10.98.191.181:8080/job/charm_lint_check/1084/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

UOSCI bot says:
charm_unit_test #918 trusty-swift-proxy for brad-marshall mp241484
    UNIT OK: passed

UNIT Results (max last 5 lines):
  hooks/swift_hooks 203 203 0% 3-413
  hooks/swift_utils 194 194 0% 1-401
  TOTAL 482 482 0%
  Ran 5 tests in 0.190s
  OK

Full unit test output: http://paste.ubuntu.com/9052125/
Build: http://10.98.191.181:8080/job/charm_unit_test/918/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

UOSCI bot says:
charm_amulet_test #426 trusty-swift-proxy for brad-marshall mp241484
    AMULET FAIL: amulet-test failed

AMULET Results (max last 5 lines):
  juju-test.conductor DEBUG : Tearing down osci-sv07 juju environment
  juju-test.conductor DEBUG : Calling "juju destroy-environment -y osci-sv07"
  juju-test INFO : Results: 1 passed, 2 failed, 0 errored
  ERROR subprocess encountered error code 2
  make: *** [test] Error 2

Full amulet test output: http://paste.ubuntu.com/9052216/
Build: http://10.98.191.181:8080/job/charm_amulet_test/426/

73. By Brad Marshall

[bradm] Removed puppet header from nagios_plugin module

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

UOSCI bot says:
charm_lint_check #1096 trusty-swift-proxy for brad-marshall mp241484
    LINT FAIL: lint-test failed

LINT Results (max last 5 lines):
INFO:root:command: make -f Makefile lint
ERROR:root:Make target returned non-zero.
  hooks/swift_hooks.py:387:17: E123 closing bracket does not match indentation of opening bracket's line
  hooks/swift_hooks.py:404:17: E123 closing bracket does not match indentation of opening bracket's line
  make: *** [lint] Error 1

Full lint test output: http://paste.ubuntu.com/9052966/
Build: http://10.98.191.181:8080/job/charm_lint_check/1096/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

UOSCI bot says:
charm_unit_test #930 trusty-swift-proxy for brad-marshall mp241484
    UNIT OK: passed

UNIT Results (max last 5 lines):
  hooks/swift_hooks 203 203 0% 3-413
  hooks/swift_utils 194 194 0% 1-401
  TOTAL 482 482 0%
  Ran 5 tests in 0.224s
  OK

Full unit test output: http://paste.ubuntu.com/9052969/
Build: http://10.98.191.181:8080/job/charm_unit_test/930/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

UOSCI bot says:
charm_amulet_test #438 trusty-swift-proxy for brad-marshall mp241484
    AMULET FAIL: amulet-test failed

AMULET Results (max last 5 lines):
  juju-test.conductor DEBUG : Calling "juju destroy-environment -y osci-sv07"
  WARNING cannot delete security group "juju-osci-sv07-0". Used by another environment?
  juju-test INFO : Results: 1 passed, 2 failed, 0 errored
  ERROR subprocess encountered error code 2
  make: *** [test] Error 2

Full amulet test output: http://paste.ubuntu.com/9053031/
Build: http://10.98.191.181:8080/job/charm_amulet_test/438/

74. By Brad Marshall

[bradm] Removed nagios check files that were moved to nrpe-external-master charm

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

UOSCI bot says:
charm_lint_check #1112 trusty-swift-proxy for brad-marshall mp241484
    LINT FAIL: lint-test failed

LINT Results (max last 5 lines):
ERROR:root:Make target returned non-zero.
  hooks/swift_hooks.py:387:17: E123 closing bracket does not match indentation of opening bracket's line
  hooks/swift_hooks.py:390:13: F841 local variable 'checkpath' is assigned to but never used
  hooks/swift_hooks.py:404:17: E123 closing bracket does not match indentation of opening bracket's line
  make: *** [lint] Error 1

Full lint test output: http://paste.ubuntu.com/9063845/
Build: http://10.98.191.181:8080/job/charm_lint_check/1112/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

UOSCI bot says:
charm_unit_test #946 trusty-swift-proxy for brad-marshall mp241484
    UNIT OK: passed

UNIT Results (max last 5 lines):
  hooks/swift_hooks 203 203 0% 3-413
  hooks/swift_utils 194 194 0% 1-401
  TOTAL 482 482 0%
  Ran 5 tests in 0.200s
  OK

Full unit test output: http://paste.ubuntu.com/9063846/
Build: http://10.98.191.181:8080/job/charm_unit_test/946/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

UOSCI bot says:
charm_amulet_test #454 trusty-swift-proxy for brad-marshall mp241484
    AMULET FAIL: amulet-test failed

AMULET Results (max last 5 lines):
  juju-test.conductor DEBUG : Calling "juju destroy-environment -y osci-sv07"
  WARNING cannot delete security group "juju-osci-sv07-0". Used by another environment?
  juju-test INFO : Results: 1 passed, 2 failed, 0 errored
  ERROR subprocess encountered error code 2
  make: *** [test] Error 2

Full amulet test output: http://paste.ubuntu.com/9063932/
Build: http://10.98.191.181:8080/job/charm_amulet_test/454/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

UOSCI bot says:
charm_lint_check #1242 trusty-swift-proxy for brad-marshall mp241484
    LINT FAIL: lint-test failed

LINT Results (max last 5 lines):
ERROR:root:Make target returned non-zero.
  hooks/swift_hooks.py:387:17: E123 closing bracket does not match indentation of opening bracket's line
  hooks/swift_hooks.py:390:13: F841 local variable 'checkpath' is assigned to but never used
  hooks/swift_hooks.py:404:17: E123 closing bracket does not match indentation of opening bracket's line
  make: *** [lint] Error 1

Full lint test output: http://paste.ubuntu.com/9281256/
Build: http://10.98.191.181:8080/job/charm_lint_check/1242/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

UOSCI bot says:
charm_unit_test #1076 trusty-swift-proxy for brad-marshall mp241484
    UNIT OK: passed

UNIT Results (max last 5 lines):
  hooks/swift_hooks 203 203 0% 3-413
  hooks/swift_utils 194 194 0% 1-401
  TOTAL 482 482 0%
  Ran 5 tests in 0.160s
  OK

Full unit test output: http://paste.ubuntu.com/9281257/
Build: http://10.98.191.181:8080/job/charm_unit_test/1076/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

UOSCI bot says:
charm_amulet_test #545 trusty-swift-proxy for brad-marshall mp241484
    AMULET FAIL: amulet-test failed

AMULET Results (max last 5 lines):
  WARNING cannot delete security group "juju-osci-sv11". Used by another environment?
  WARNING cannot delete security group "juju-osci-sv11-0". Used by another environment?
  juju-test INFO : Results: 1 passed, 2 failed, 0 errored
  ERROR subprocess encountered error code 2
  make: *** [test] Error 2

Full amulet test output: http://paste.ubuntu.com/9281343/
Build: http://10.98.191.181:8080/job/charm_amulet_test/545/

Revision history for this message
Liam Young (gnuoy) wrote :

Thanks for this branch. I've taken it and fixed up a few minor bits and proposed it against the 'next' branch. It has now landed into 'next' and will promulgate to staging at the end of the month as part of the 15.01 openstack charm release.

review: Disapprove

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'charm-helpers-hooks.yaml'
--- charm-helpers-hooks.yaml 2014-10-02 09:28:13 +0000
+++ charm-helpers-hooks.yaml 2014-11-18 01:29:44 +0000
@@ -11,3 +11,4 @@
11 - payload.execd11 - payload.execd
12 - contrib.network.ip12 - contrib.network.ip
13 - contrib.peerstorage13 - contrib.peerstorage
14 - contrib.charmsupport
1415
=== modified file 'config.yaml'
--- config.yaml 2014-10-02 20:31:24 +0000
+++ config.yaml 2014-11-18 01:29:44 +0000
@@ -177,3 +177,14 @@
177 order for this charm to function correctly, the privacy extension must be177 order for this charm to function correctly, the privacy extension must be
178 disabled and a non-temporary address must be configured/available on178 disabled and a non-temporary address must be configured/available on
179 your network interface.179 your network interface.
180 nagios_context:
181 default: "juju"
182 type: string
183 description: |
184 Used by the nrpe-external-master subordinate charm.
185 A string that will be prepended to instance name to set the host name
186 in nagios. So for instance the hostname would be something like:
187 juju-myservice-0
188 If you're running multiple environments with the same services in them
189 this allows you to differentiate between them.
190
180191
=== added directory 'files'
=== added directory 'hooks/charmhelpers/contrib/charmsupport'
=== added file 'hooks/charmhelpers/contrib/charmsupport/__init__.py'
=== added file 'hooks/charmhelpers/contrib/charmsupport/nrpe.py'
--- hooks/charmhelpers/contrib/charmsupport/nrpe.py 1970-01-01 00:00:00 +0000
+++ hooks/charmhelpers/contrib/charmsupport/nrpe.py 2014-11-18 01:29:44 +0000
@@ -0,0 +1,222 @@
1"""Compatibility with the nrpe-external-master charm"""
2# Copyright 2012 Canonical Ltd.
3#
4# Authors:
5# Matthew Wedgwood <matthew.wedgwood@canonical.com>
6
7import subprocess
8import pwd
9import grp
10import os
11import re
12import shlex
13import yaml
14
15from charmhelpers.core.hookenv import (
16 config,
17 local_unit,
18 log,
19 relation_ids,
20 relation_set,
21)
22
23from charmhelpers.core.host import service
24
25# This module adds compatibility with the nrpe-external-master and plain nrpe
26# subordinate charms. To use it in your charm:
27#
28# 1. Update metadata.yaml
29#
30# provides:
31# (...)
32# nrpe-external-master:
33# interface: nrpe-external-master
34# scope: container
35#
36# and/or
37#
38# provides:
39# (...)
40# local-monitors:
41# interface: local-monitors
42# scope: container
43
44#
45# 2. Add the following to config.yaml
46#
47# nagios_context:
48# default: "juju"
49# type: string
50# description: |
51# Used by the nrpe subordinate charms.
52# A string that will be prepended to instance name to set the host name
53# in nagios. So for instance the hostname would be something like:
54# juju-myservice-0
55# If you're running multiple environments with the same services in them
56# this allows you to differentiate between them.
57#
58# 3. Add custom checks (Nagios plugins) to files/nrpe-external-master
59#
60# 4. Update your hooks.py with something like this:
61#
62# from charmsupport.nrpe import NRPE
63# (...)
64# def update_nrpe_config():
65# nrpe_compat = NRPE()
66# nrpe_compat.add_check(
67# shortname = "myservice",
68# description = "Check MyService",
69# check_cmd = "check_http -w 2 -c 10 http://localhost"
70# )
71# nrpe_compat.add_check(
72# "myservice_other",
73# "Check for widget failures",
74# check_cmd = "/srv/myapp/scripts/widget_check"
75# )
76# nrpe_compat.write()
77#
78# def config_changed():
79# (...)
80# update_nrpe_config()
81#
82# def nrpe_external_master_relation_changed():
83# update_nrpe_config()
84#
85# def local_monitors_relation_changed():
86# update_nrpe_config()
87#
88# 5. ln -s hooks.py nrpe-external-master-relation-changed
89# ln -s hooks.py local-monitors-relation-changed
90
91
92class CheckException(Exception):
93 pass
94
95
96class Check(object):
97 shortname_re = '[A-Za-z0-9-_]+$'
98 service_template = ("""
99#---------------------------------------------------
100# This file is Juju managed
101#---------------------------------------------------
102define service {{
103 use active-service
104 host_name {nagios_hostname}
105 service_description {nagios_hostname}[{shortname}] """
106 """{description}
107 check_command check_nrpe!{command}
108 servicegroups {nagios_servicegroup}
109}}
110""")
111
112 def __init__(self, shortname, description, check_cmd):
113 super(Check, self).__init__()
114 # XXX: could be better to calculate this from the service name
115 if not re.match(self.shortname_re, shortname):
116 raise CheckException("shortname must match {}".format(
117 Check.shortname_re))
118 self.shortname = shortname
119 self.command = "check_{}".format(shortname)
120 # Note: a set of invalid characters is defined by the
121 # Nagios server config
122 # The default is: illegal_object_name_chars=`~!$%^&*"|'<>?,()=
123 self.description = description
124 self.check_cmd = self._locate_cmd(check_cmd)
125
126 def _locate_cmd(self, check_cmd):
127 search_path = (
128 '/',
129 os.path.join(os.environ['CHARM_DIR'],
130 'files/nrpe-external-master'),
131 '/usr/lib/nagios/plugins',
132 '/usr/local/lib/nagios/plugins',
133 )
134 parts = shlex.split(check_cmd)
135 for path in search_path:
136 if os.path.exists(os.path.join(path, parts[0])):
137 command = os.path.join(path, parts[0])
138 if len(parts) > 1:
139 command += " " + " ".join(parts[1:])
140 return command
141 log('Check command not found: {}'.format(parts[0]))
142 return ''
143
144 def write(self, nagios_context, hostname):
145 nrpe_check_file = '/etc/nagios/nrpe.d/{}.cfg'.format(
146 self.command)
147 with open(nrpe_check_file, 'w') as nrpe_check_config:
148 nrpe_check_config.write("# check {}\n".format(self.shortname))
149 nrpe_check_config.write("command[{}]={}\n".format(
150 self.command, self.check_cmd))
151
152 if not os.path.exists(NRPE.nagios_exportdir):
153 log('Not writing service config as {} is not accessible'.format(
154 NRPE.nagios_exportdir))
155 else:
156 self.write_service_config(nagios_context, hostname)
157
158 def write_service_config(self, nagios_context, hostname):
159 for f in os.listdir(NRPE.nagios_exportdir):
160 if re.search('.*{}.cfg'.format(self.command), f):
161 os.remove(os.path.join(NRPE.nagios_exportdir, f))
162
163 templ_vars = {
164 'nagios_hostname': hostname,
165 'nagios_servicegroup': nagios_context,
166 'description': self.description,
167 'shortname': self.shortname,
168 'command': self.command,
169 }
170 nrpe_service_text = Check.service_template.format(**templ_vars)
171 nrpe_service_file = '{}/service__{}_{}.cfg'.format(
172 NRPE.nagios_exportdir, hostname, self.command)
173 with open(nrpe_service_file, 'w') as nrpe_service_config:
174 nrpe_service_config.write(str(nrpe_service_text))
175
176 def run(self):
177 subprocess.call(self.check_cmd)
178
179
180class NRPE(object):
181 nagios_logdir = '/var/log/nagios'
182 nagios_exportdir = '/var/lib/nagios/export'
183 nrpe_confdir = '/etc/nagios/nrpe.d'
184
185 def __init__(self, hostname=None):
186 super(NRPE, self).__init__()
187 self.config = config()
188 self.nagios_context = self.config['nagios_context']
189 self.unit_name = local_unit().replace('/', '-')
190 if hostname:
191 self.hostname = hostname
192 else:
193 self.hostname = "{}-{}".format(self.nagios_context, self.unit_name)
194 self.checks = []
195
196 def add_check(self, *args, **kwargs):
197 self.checks.append(Check(*args, **kwargs))
198
199 def write(self):
200 try:
201 nagios_uid = pwd.getpwnam('nagios').pw_uid
202 nagios_gid = grp.getgrnam('nagios').gr_gid
203 except:
204 log("Nagios user not set up, nrpe checks not updated")
205 return
206
207 if not os.path.exists(NRPE.nagios_logdir):
208 os.mkdir(NRPE.nagios_logdir)
209 os.chown(NRPE.nagios_logdir, nagios_uid, nagios_gid)
210
211 nrpe_monitors = {}
212 monitors = {"monitors": {"remote": {"nrpe": nrpe_monitors}}}
213 for nrpecheck in self.checks:
214 nrpecheck.write(self.nagios_context, self.hostname)
215 nrpe_monitors[nrpecheck.shortname] = {
216 "command": nrpecheck.command,
217 }
218
219 service('restart', 'nagios-nrpe-server')
220
221 for rid in relation_ids("local-monitors"):
222 relation_set(relation_id=rid, monitors=yaml.dump(monitors))
0223
=== added file 'hooks/charmhelpers/contrib/charmsupport/volumes.py'
--- hooks/charmhelpers/contrib/charmsupport/volumes.py 1970-01-01 00:00:00 +0000
+++ hooks/charmhelpers/contrib/charmsupport/volumes.py 2014-11-18 01:29:44 +0000
@@ -0,0 +1,156 @@
1'''
2Functions for managing volumes in juju units. One volume is supported per unit.
3Subordinates may have their own storage, provided it is on its own partition.
4
5Configuration stanzas:
6 volume-ephemeral:
7 type: boolean
8 default: true
9 description: >
10 If false, a volume is mounted as sepecified in "volume-map"
11 If true, ephemeral storage will be used, meaning that log data
12 will only exist as long as the machine. YOU HAVE BEEN WARNED.
13 volume-map:
14 type: string
15 default: {}
16 description: >
17 YAML map of units to device names, e.g:
18 "{ rsyslog/0: /dev/vdb, rsyslog/1: /dev/vdb }"
19 Service units will raise a configure-error if volume-ephemeral
20 is 'true' and no volume-map value is set. Use 'juju set' to set a
21 value and 'juju resolved' to complete configuration.
22
23Usage:
24 from charmsupport.volumes import configure_volume, VolumeConfigurationError
25 from charmsupport.hookenv import log, ERROR
26 def post_mount_hook():
27 stop_service('myservice')
28 def post_mount_hook():
29 start_service('myservice')
30
31 if __name__ == '__main__':
32 try:
33 configure_volume(before_change=pre_mount_hook,
34 after_change=post_mount_hook)
35 except VolumeConfigurationError:
36 log('Storage could not be configured', ERROR)
37'''
38
39# XXX: Known limitations
40# - fstab is neither consulted nor updated
41
42import os
43from charmhelpers.core import hookenv
44from charmhelpers.core import host
45import yaml
46
47
48MOUNT_BASE = '/srv/juju/volumes'
49
50
51class VolumeConfigurationError(Exception):
52 '''Volume configuration data is missing or invalid'''
53 pass
54
55
56def get_config():
57 '''Gather and sanity-check volume configuration data'''
58 volume_config = {}
59 config = hookenv.config()
60
61 errors = False
62
63 if config.get('volume-ephemeral') in (True, 'True', 'true', 'Yes', 'yes'):
64 volume_config['ephemeral'] = True
65 else:
66 volume_config['ephemeral'] = False
67
68 try:
69 volume_map = yaml.safe_load(config.get('volume-map', '{}'))
70 except yaml.YAMLError as e:
71 hookenv.log("Error parsing YAML volume-map: {}".format(e),
72 hookenv.ERROR)
73 errors = True
74 if volume_map is None:
75 # probably an empty string
76 volume_map = {}
77 elif not isinstance(volume_map, dict):
78 hookenv.log("Volume-map should be a dictionary, not {}".format(
79 type(volume_map)))
80 errors = True
81
82 volume_config['device'] = volume_map.get(os.environ['JUJU_UNIT_NAME'])
83 if volume_config['device'] and volume_config['ephemeral']:
84 # asked for ephemeral storage but also defined a volume ID
85 hookenv.log('A volume is defined for this unit, but ephemeral '
86 'storage was requested', hookenv.ERROR)
87 errors = True
88 elif not volume_config['device'] and not volume_config['ephemeral']:
89 # asked for permanent storage but did not define volume ID
90 hookenv.log('Ephemeral storage was requested, but there is no volume '
91 'defined for this unit.', hookenv.ERROR)
92 errors = True
93
94 unit_mount_name = hookenv.local_unit().replace('/', '-')
95 volume_config['mountpoint'] = os.path.join(MOUNT_BASE, unit_mount_name)
96
97 if errors:
98 return None
99 return volume_config
100
101
102def mount_volume(config):
103 if os.path.exists(config['mountpoint']):
104 if not os.path.isdir(config['mountpoint']):
105 hookenv.log('Not a directory: {}'.format(config['mountpoint']))
106 raise VolumeConfigurationError()
107 else:
108 host.mkdir(config['mountpoint'])
109 if os.path.ismount(config['mountpoint']):
110 unmount_volume(config)
111 if not host.mount(config['device'], config['mountpoint'], persist=True):
112 raise VolumeConfigurationError()
113
114
115def unmount_volume(config):
116 if os.path.ismount(config['mountpoint']):
117 if not host.umount(config['mountpoint'], persist=True):
118 raise VolumeConfigurationError()
119
120
121def managed_mounts():
122 '''List of all mounted managed volumes'''
123 return filter(lambda mount: mount[0].startswith(MOUNT_BASE), host.mounts())
124
125
126def configure_volume(before_change=lambda: None, after_change=lambda: None):
127 '''Set up storage (or don't) according to the charm's volume configuration.
128 Returns the mount point or "ephemeral". before_change and after_change
129 are optional functions to be called if the volume configuration changes.
130 '''
131
132 config = get_config()
133 if not config:
134 hookenv.log('Failed to read volume configuration', hookenv.CRITICAL)
135 raise VolumeConfigurationError()
136
137 if config['ephemeral']:
138 if os.path.ismount(config['mountpoint']):
139 before_change()
140 unmount_volume(config)
141 after_change()
142 return 'ephemeral'
143 else:
144 # persistent storage
145 if os.path.ismount(config['mountpoint']):
146 mounts = dict(managed_mounts())
147 if mounts.get(config['mountpoint']) != config['device']:
148 before_change()
149 unmount_volume(config)
150 mount_volume(config)
151 after_change()
152 else:
153 before_change()
154 mount_volume(config)
155 after_change()
156 return config['mountpoint']
0157
=== added symlink 'hooks/nrpe-external-master-relation-changed'
=== target is u'swift_hooks.py'
=== added symlink 'hooks/nrpe-external-master-relation-joined'
=== target is u'swift_hooks.py'
=== modified file 'hooks/swift_hooks.py'
--- hooks/swift_hooks.py 2014-10-23 16:17:57 +0000
+++ hooks/swift_hooks.py 2014-11-18 01:29:44 +0000
@@ -11,6 +11,7 @@
11from swift_utils import (11from swift_utils import (
12 register_configs,12 register_configs,
13 restart_map,13 restart_map,
14 services,
14 determine_packages,15 determine_packages,
15 ensure_swift_dir,16 ensure_swift_dir,
16 SWIFT_RINGS, get_www_dir,17 SWIFT_RINGS, get_www_dir,
@@ -35,10 +36,16 @@
35 relation_set,36 relation_set,
36 relation_ids,37 relation_ids,
37 relation_get,38 relation_get,
39<<<<<<< TREE
38 log,40 log,
39 INFO,41 INFO,
40 WARNING,42 WARNING,
41 ERROR,43 ERROR,
44=======
45 relations_of_type,
46 local_unit,
47 log, ERROR,
48>>>>>>> MERGE-SOURCE
42 Hooks, UnregisteredHookError,49 Hooks, UnregisteredHookError,
43 open_port50 open_port
44)51)
@@ -69,6 +76,8 @@
6976
70from charmhelpers.contrib.openstack.context import ADDRESS_TYPES77from charmhelpers.contrib.openstack.context import ADDRESS_TYPES
7178
79from charmhelpers.contrib.charmsupport.nrpe import NRPE
80
72extra_pkgs = [81extra_pkgs = [
73 "haproxy",82 "haproxy",
74 "python-jinja2"83 "python-jinja2"
@@ -275,6 +284,7 @@
275284
276 configure_https()285 configure_https()
277 open_port(config('bind-port'))286 open_port(config('bind-port'))
287 update_nrpe_config()
278 # Determine whether or not we should do an upgrade, based on the288 # Determine whether or not we should do an upgrade, based on the
279 # the version offered in keyston-release.289 # the version offered in keyston-release.
280 if (openstack.openstack_upgrade_available('python-swift')):290 if (openstack.openstack_upgrade_available('python-swift')):
@@ -454,6 +464,57 @@
454 write_rc_script()464 write_rc_script()
455465
456466
467@hooks.hook('nrpe-external-master-relation-joined',
468 'nrpe-external-master-relation-changed')
469def update_nrpe_config():
470 apt_install('python-dbus')
471 # Find out if nrpe set nagios_hostname
472 hostname = None
473 host_context = None
474 for rel in relations_of_type('nrpe-external-master'):
475 if 'nagios_hostname' in rel:
476 hostname = rel['nagios_hostname']
477 host_context = rel['nagios_host_context']
478 break
479 nrpe = NRPE(hostname=hostname)
480
481 if host_context:
482 current_unit = "%s:%s" % (host_context, local_unit())
483 else:
484 current_unit = local_unit()
485
486 services_to_monitor = services()
487 for service in services_to_monitor:
488 upstart_init = '/etc/init/%s.conf' % service
489 sysv_init = '/etc/init.d/%s' % service
490
491 if os.path.exists(upstart_init):
492 nrpe.add_check(
493 shortname=service,
494 description='process check {%s}' % current_unit,
495 check_cmd='check_upstart_job %s' % service,
496 )
497 elif os.path.exists(sysv_init):
498 cronpath = '/etc/cron.d/nagios-service-check-%s' % service
499 checkpath = os.path.join(os.environ['CHARM_DIR'],
500 'files/nrpe-external-master',
501 'check_exit_status.pl'),
502 cron_template = '*/5 * * * * root \
503/usr/local/lib/nagios/plugins/check_exit_status.pl -s /etc/init.d/%s \
504status > /var/lib/nagios/service-check-%s.txt\n' % (service, service)
505 f = open(cronpath, 'w')
506 f.write(cron_template)
507 f.close()
508 nrpe.add_check(
509 shortname=service,
510 description='process check {%s}' % current_unit,
511 check_cmd='check_status_file.py -f \
512/var/lib/nagios/service-check-%s.txt' % service,
513 )
514
515 nrpe.write()
516
517
457def main():518def main():
458 try:519 try:
459 hooks.execute(sys.argv)520 hooks.execute(sys.argv)
460521
=== modified file 'hooks/swift_utils.py'
--- hooks/swift_utils.py 2014-10-21 08:32:52 +0000
+++ hooks/swift_utils.py 2014-11-18 01:29:44 +0000
@@ -166,6 +166,14 @@
166 return OrderedDict(_map)166 return OrderedDict(_map)
167167
168168
169def services():
170 ''' Returns a list of services associate with this charm '''
171 _services = []
172 for v in restart_map().values():
173 _services = _services + v
174 return list(set(_services))
175
176
169def swift_user(username='swift'):177def swift_user(username='swift'):
170 user = pwd.getpwnam(username)178 user = pwd.getpwnam(username)
171 return (user.pw_uid, user.pw_gid)179 return (user.pw_uid, user.pw_gid)
172180
=== modified file 'metadata.yaml'
--- metadata.yaml 2013-07-11 19:18:37 +0000
+++ metadata.yaml 2014-11-18 01:29:44 +0000
@@ -7,6 +7,9 @@
7categories:7categories:
8 - cache-proxy8 - cache-proxy
9provides:9provides:
10 nrpe-external-master:
11 interface: nrpe-external-master
12 scope: container
10 object-store:13 object-store:
11 interface: swift-proxy14 interface: swift-proxy
12requires:15requires:

Subscribers

People subscribed via source and target branches