Merge lp:~chad.smith/charms/precise/swift-proxy/swift-proxy-ha-with-health into lp:~openstack-charmers/charms/precise/swift-proxy/ha-support

Proposed by Chad Smith
Status: Merged
Merged at revision: 41
Proposed branch: lp:~chad.smith/charms/precise/swift-proxy/swift-proxy-ha-with-health
Merge into: lp:~openstack-charmers/charms/precise/swift-proxy/ha-support
Diff against target: 93 lines (+53/-0)
6 files modified
hooks/lib/openstack_common.py (+16/-0)
hooks/swift_utils.py (+5/-0)
scripts/add_to_cluster (+2/-0)
scripts/health_checks.d/service_ports_live (+13/-0)
scripts/health_checks.d/service_swift_running (+15/-0)
scripts/remove_from_cluster (+2/-0)
To merge this branch: bzr merge lp:~chad.smith/charms/precise/swift-proxy/swift-proxy-ha-with-health
Reviewer Review Type Date Requested Status
Adam Gandelman Pending
James Page Pending
Review via email: mp+152066@code.launchpad.net

This proposal supersedes a proposal from 2013-03-02.

Description of the change

This is a merge proposal to establish a potential template for health_script.d, add_to_cluster and remove_from_cluster delivery within the ha-supported openstack charms. The *cluster* simple scripts will be common on each charm that uses corosync configs. The health_scripts.d dir will contain some common scripts and some additional scripts that are appropriate health checks for the specific service.

The basic architecture we are hoping for is an extendable set of run-parts scripts in health_checks.d that can be seeded with juju config environment variables written into a /var/lib/juju/units/<charm_name>/charm/scripts/scriptrc file. Landscape client will do the work of calling these scripts and validating charm service health during openstack service upgrades. Both Jerry and I are tackling the initial push to add health/cluster scripts to the charms. Hopefully the model works and we can iterate on extending health or cluster scripts as service HA configuration gets more complex.

much thanks for the review.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/lib/openstack_common.py'
2--- hooks/lib/openstack_common.py 2013-03-05 00:58:25 +0000
3+++ hooks/lib/openstack_common.py 2013-03-06 22:26:25 +0000
4@@ -245,3 +245,19 @@
5 f.write(template.render(context))
6 with open(HAPROXY_DEFAULT, 'w') as f:
7 f.write('ENABLED=1')
8+
9+def save_script_rc(script_path="scripts/scriptrc", **env_vars):
10+ """
11+ Write an rc file in the charm-delivered directory containing
12+ exported environment variables provided by env_vars. Any charm scripts run
13+ outside the juju hook environment can source this scriptrc to obtain
14+ updated config information necessary to perform health checks or
15+ service changes.
16+ """
17+ unit_name = os.getenv('JUJU_UNIT_NAME').replace('/', '-')
18+ juju_rc_path="/var/lib/juju/units/%s/charm/%s" % (unit_name, script_path)
19+ with open(juju_rc_path, 'wb') as rc_script:
20+ rc_script.write(
21+ "#!/bin/bash\n")
22+ [rc_script.write('export %s=%s\n' % (u, p))
23+ for u, p in env_vars.iteritems() if u != "script_path"]
24
25=== modified file 'hooks/swift_utils.py'
26--- hooks/swift_utils.py 2013-01-17 18:35:04 +0000
27+++ hooks/swift_utils.py 2013-03-06 22:26:25 +0000
28@@ -167,6 +167,11 @@
29 import multiprocessing
30 workers = multiprocessing.cpu_count()
31
32+ env_vars = {'OPENSTACK_SERVICE_SWIFT': 'proxy-server',
33+ 'OPENSTACK_PORT_API': bind_port,
34+ 'OPENSTACK_PORT_MEMCACHED': 11211}
35+ openstack.save_script_rc(**env_vars)
36+
37 ctxt = {
38 'proxy_ip': utils.get_host_ip(),
39 'bind_port': bind_port,
40
41=== added directory 'scripts'
42=== added file 'scripts/add_to_cluster'
43--- scripts/add_to_cluster 1970-01-01 00:00:00 +0000
44+++ scripts/add_to_cluster 2013-03-06 22:26:25 +0000
45@@ -0,0 +1,2 @@
46+#!/bin/bash
47+crm node online
48
49=== added directory 'scripts/health_checks.d'
50=== added file 'scripts/health_checks.d/service_ports_live'
51--- scripts/health_checks.d/service_ports_live 1970-01-01 00:00:00 +0000
52+++ scripts/health_checks.d/service_ports_live 2013-03-06 22:26:25 +0000
53@@ -0,0 +1,13 @@
54+#!/bin/bash
55+# Validate that service ports are active
56+HEALTH_DIR=`dirname $0`
57+SCRIPTS_DIR=`dirname $HEALTH_DIR`
58+. $SCRIPTS_DIR/scriptrc
59+set -e
60+
61+# Grab any OPENSTACK_PORT* environment variables
62+openstack_ports=`env| awk -F '=' '(/OPENSTACK_PORT/){print $2}'`
63+for port in $openstack_ports
64+do
65+ netstat -ln | grep -q ":$port "
66+done
67
68=== added file 'scripts/health_checks.d/service_swift_running'
69--- scripts/health_checks.d/service_swift_running 1970-01-01 00:00:00 +0000
70+++ scripts/health_checks.d/service_swift_running 2013-03-06 22:26:25 +0000
71@@ -0,0 +1,15 @@
72+#!/bin/bash
73+# Validate that service is running
74+HEALTH_DIR=`dirname $0`
75+SCRIPTS_DIR=`dirname $HEALTH_DIR`
76+. $SCRIPTS_DIR/scriptrc
77+set -e
78+
79+# Grab any OPENSTACK_SWIFT_SERVICE* environment variables
80+openstack_service_names=`env| awk -F '=' '(/OPENSTACK_SWIFT_SERVICE/){print $2}'`
81+for service_name in $openstack_service_names
82+do
83+ # Double-negative: we want to ensure swift-init does not return
84+ # 'No <service_name> running'
85+ swift-init $service_name status 2>/dev/null | grep -vq "No $service_name running"
86+done
87
88=== added file 'scripts/remove_from_cluster'
89--- scripts/remove_from_cluster 1970-01-01 00:00:00 +0000
90+++ scripts/remove_from_cluster 2013-03-06 22:26:25 +0000
91@@ -0,0 +1,2 @@
92+#!/bin/bash
93+crm node standby

Subscribers

People subscribed via source and target branches