Merge lp:~chad.smith/charms/precise/swift-storage/swift-storage-with-health into lp:~charmers/charms/precise/swift-storage/trunk

Proposed by Chad Smith
Status: Merged
Merged at revision: 22
Proposed branch: lp:~chad.smith/charms/precise/swift-storage/swift-storage-with-health
Merge into: lp:~charmers/charms/precise/swift-storage/trunk
Diff against target: 167 lines (+106/-5)
6 files modified
hooks/lib/openstack-common (+39/-0)
hooks/swift-storage-node-relations (+22/-4)
revision (+1/-1)
scripts/health_checks.d/service_ports_live (+13/-0)
scripts/health_checks.d/service_swift_running (+15/-0)
scripts/health_checks.d/service_url_checks (+16/-0)
To merge this branch: bzr merge lp:~chad.smith/charms/precise/swift-storage/swift-storage-with-health
Reviewer Review Type Date Requested Status
James Page Pending
Adam Gandelman Pending
Review via email: mp+153684@code.launchpad.net

Description of the change

Add run-parts health_scripts.d directory to be used by landscape-client during rolling OpenStack upgrades to validate the health of swift services after a system reboot. These health scripts use the same mechanism as other openstack charms to create a scriptrc file which will define OPENSTACK_* environment variables used by health scripts to validate various swift services and ports are active on the swift-storage unit. Landscape-client will use run-parts to validate all health scripts exit zero as a validation that any known swift services are in place and running appropriately before upgrading any other swift-storage nodes.

To post a comment you must log in.
Revision history for this message
Chad Smith (chad.smith) wrote :

From Adam (Merged):
Retargetted and merged against lp:~openstack-charmers/charms/precise/swift-storage/ha-support which contains the most recent common code and will let us track this against the other WIP charms focusing on these features.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added symlink 'hooks/config-changed'
2=== target is u'swift-storage-node-relations'
3=== modified file 'hooks/lib/openstack-common'
4--- hooks/lib/openstack-common 2013-01-11 18:33:34 +0000
5+++ hooks/lib/openstack-common 2013-03-17 15:25:24 +0000
6@@ -314,3 +314,42 @@
7 echo "$found"
8 return 0
9 }
10+
11+##########################################################################
12+# Description: Creates an rc file exporting environment variables to a
13+# script_path local to the charm's installed directory.
14+# Any charm scripts run outside the juju hook environment can source this
15+# scriptrc to obtain updated config information necessary to perform health
16+# checks or service changes
17+#
18+# Parameters:
19+# An array of '=' delimited ENV_VAR:value combinations to export.
20+# If optional script_path key is not provided in the array, script_path
21+# defaults to scripts/scriptrc
22+##########################################################################
23+function save_script_rc {
24+ if [ ! -n "$JUJU_UNIT_NAME" ]; then
25+ echo "Error: Missing JUJU_UNIT_NAME environment variable"
26+ exit 1
27+ fi
28+ # our default unit_path
29+ unit_path="/var/lib/juju/units/${JUJU_UNIT_NAME/\//-}/charm/scripts/scriptrc"
30+ echo $unit_path
31+ tmp_rc="/tmp/${JUJU_UNIT_NAME/\//-}rc"
32+
33+ echo "#!/bin/bash" > $tmp_rc
34+ for env_var in "${@}"
35+ do
36+ if `echo $env_var | grep -q script_path`; then
37+ # well then we need to reset the new unit-local script path
38+ unit_path="/var/lib/juju/units/${JUJU_UNIT_NAME/\//-}/charm/${env_var/script_path=/}"
39+ else
40+ echo "export $env_var" >> $tmp_rc
41+ fi
42+ done
43+ chmod 755 $tmp_rc
44+ mv $tmp_rc $unit_path
45+}
46+
47+
48+
49
50=== modified file 'hooks/swift-storage-node-relations'
51--- hooks/swift-storage-node-relations 2013-01-15 18:40:49 +0000
52+++ hooks/swift-storage-node-relations 2013-03-17 15:25:24 +0000
53@@ -11,6 +11,26 @@
54 echo "ERROR: Could not load swift-storage-node-common from $CHARM_DIR"
55 fi
56
57+function config_changed {
58+
59+ declare -a env_vars=()
60+ for i in account container object ; do
61+ port=$(config-get ${i}-server-port)
62+ local url="http://$STORAGE_LOCAL_NET_IP:$port/recon/diskusage"
63+ # append to env_vars
64+ env_vars+=("OPENSTACK_PORT_${i^^}=$port")
65+ env_vars+=("OPENSTACK_SWIFT_SERVICE_${i^^}=${i}-server")
66+
67+ # Ensure we have at least one device mounted as reported by swift-recon
68+ env_vars+=('OPENSTACK_URL_'${i^^}'="'$url'|\"mounted\":+\"true\""')
69+
70+ create_server_conf $i "$port"
71+ done
72+
73+ # Save our scriptrc env variables for health checks
74+ save_script_rc ${env_vars[@]}
75+}
76+
77 function install_hook {
78 apt-get -y --force-yes install python-software-properties || exit 1
79
80@@ -27,10 +47,7 @@
81 configure_rsyncd
82 swift-init all stop || true
83 setup_storage
84- for i in account container object ; do
85- port=$(config-get ${i}-server-port)
86- create_server_conf $i "$port"
87- done
88+ config_changed
89 }
90
91 function storage_joined {
92@@ -70,6 +87,7 @@
93 case $ARG0 in
94 "install") install_hook ;;
95 "start"|"stop") exit 0 ;;
96+ "config-changed") config_changed ;;
97 "swift-storage-relation-joined") storage_joined ;;
98 "swift-storage-relation-changed") storage_changed ;;
99 esac
100
101=== modified file 'revision'
102--- revision 2013-01-11 18:33:34 +0000
103+++ revision 2013-03-17 15:25:24 +0000
104@@ -1,1 +1,1 @@
105-53
106+54
107
108=== added directory 'scripts'
109=== added directory 'scripts/health_checks.d'
110=== added file 'scripts/health_checks.d/service_ports_live'
111--- scripts/health_checks.d/service_ports_live 1970-01-01 00:00:00 +0000
112+++ scripts/health_checks.d/service_ports_live 2013-03-17 15:25:24 +0000
113@@ -0,0 +1,13 @@
114+#!/bin/bash
115+# Validate that service ports are active
116+HEALTH_DIR=`dirname $0`
117+SCRIPTS_DIR=`dirname $HEALTH_DIR`
118+. $SCRIPTS_DIR/scriptrc
119+set -e
120+
121+# Grab any OPENSTACK_PORT* environment variables
122+openstack_ports=`env| awk -F '=' '(/OPENSTACK_PORT/){print $2}'`
123+for port in $openstack_ports
124+do
125+ netstat -ln | grep -q $port
126+done
127
128=== added file 'scripts/health_checks.d/service_swift_running'
129--- scripts/health_checks.d/service_swift_running 1970-01-01 00:00:00 +0000
130+++ scripts/health_checks.d/service_swift_running 2013-03-17 15:25:24 +0000
131@@ -0,0 +1,15 @@
132+#!/bin/bash
133+# Validate that service is running
134+HEALTH_DIR=`dirname $0`
135+SCRIPTS_DIR=`dirname $HEALTH_DIR`
136+. $SCRIPTS_DIR/scriptrc
137+set -e
138+
139+# Grab any OPENSTACK_SWIFT_SERVICE* environment variables
140+openstack_service_names=`env| awk -F '=' '(/OPENSTACK_SWIFT_SERVICE/){print $2}'`
141+for service_name in $openstack_service_names
142+do
143+ # Double-negative: we want to ensure swift-init does not return
144+ # 'No <service_name> running'
145+ swift-init $service_name status 2>/dev/null | grep -vq "No $service_name running"
146+done
147
148=== added file 'scripts/health_checks.d/service_url_checks'
149--- scripts/health_checks.d/service_url_checks 1970-01-01 00:00:00 +0000
150+++ scripts/health_checks.d/service_url_checks 2013-03-17 15:25:24 +0000
151@@ -0,0 +1,16 @@
152+#!/bin/bash
153+# Validate that service urls return expected content
154+HEALTH_DIR=`dirname $0`
155+SCRIPTS_DIR=`dirname $HEALTH_DIR`
156+. $SCRIPTS_DIR/scriptrc
157+set -e
158+
159+# Grab any OPENSTACK_URL* environment variables and validate content response
160+openstack_urls=`env| awk -F '=' '(/OPENSTACK_URL/){print $2 }'`
161+for url_check in $openstack_urls
162+do
163+ url=`echo $url_check| awk -F '|' '{print $1}'`
164+ expected_content=`echo $url_check| awk -F '|' '{print $2}'`
165+ wget -q -O - $url | grep -q "${expected_content//+/ }"
166+done
167+

Subscribers

People subscribed via source and target branches

to all changes: