Merge lp:~gandelman-a/charms/precise/nova-compute/openstack-charmers-merge-migration into lp:~openstack-charmers/charms/precise/nova-compute/ha-support
- Precise Pangolin (12.04)
- openstack-charmers-merge-migration
- Merge into ha-support
Proposed by
Adam Gandelman
Status: | Merged |
---|---|
Merged at revision: | 43 |
Proposed branch: | lp:~gandelman-a/charms/precise/nova-compute/openstack-charmers-merge-migration |
Merge into: | lp:~openstack-charmers/charms/precise/nova-compute/ha-support |
Diff against target: |
414 lines (+251/-16) 9 files modified
config.yaml (+11/-1) hooks/lib/nova/essex (+2/-2) hooks/lib/nova/folsom (+3/-5) hooks/lib/nova/grizzly (+80/-0) hooks/lib/nova/nova-common (+31/-4) hooks/nova-compute-common (+87/-2) hooks/nova-compute-relations (+33/-1) metadata.yaml (+3/-0) revision (+1/-1) |
To merge this branch: | bzr merge lp:~gandelman-a/charms/precise/nova-compute/openstack-charmers-merge-migration |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
OpenStack Charmers | Pending | ||
Review via email: mp+143803@code.launchpad.net |
Commit message
Description of the change
Rebased in-progress live migration work against the other HA stuff we've been doing off of lp:~openstack-charmers branches. Original merge proposal @ https:/
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 'config.yaml' |
2 | --- config.yaml 2012-12-05 11:46:15 +0000 |
3 | +++ config.yaml 2013-01-18 00:42:23 +0000 |
4 | @@ -37,7 +37,17 @@ |
5 | virt-type: |
6 | default: kvm |
7 | type: string |
8 | - description: "Virtualization flavor. Supported: kvm, xen, uml, lxc. qemu" |
9 | + description: Virtualization flavor (kvm, xen, uml, lxc, qemu) |
10 | + enable-live-migration: |
11 | + default: False |
12 | + type: boolean |
13 | + description: Configure libvirt for live migration. |
14 | + migration-auth-type: |
15 | + default: sasl |
16 | + type: string |
17 | + description: | |
18 | + TCP authentication scheme for libvirt live migration. Available options |
19 | + include sasl or none. |
20 | # needed if using flatmanager |
21 | bridge-interface: |
22 | default: br100 |
23 | |
24 | === modified file 'hooks/lib/nova/essex' |
25 | --- hooks/lib/nova/essex 2012-10-02 23:41:28 +0000 |
26 | +++ hooks/lib/nova/essex 2013-01-18 00:42:23 +0000 |
27 | @@ -12,7 +12,7 @@ |
28 | |
29 | local nova_conf=${NOVA_CONF:-/etc/nova/nova.conf} |
30 | local api_conf=${API_CONF:-/etc/nova/api-paste.ini} |
31 | - |
32 | + local libvirtd_conf=${LIBVIRTD_CONF:-/etc/libvirt/libvirtd.conf} |
33 | [[ -z $key ]] && juju-log "$CHARM set_or_update: value $value missing key" && exit 1 |
34 | [[ -z $value ]] && juju-log "$CHARM set_or_update: key $key missing value" && exit 1 |
35 | [[ -z "$conf_file" ]] && conf_file=$nova_conf |
36 | @@ -22,7 +22,7 @@ |
37 | pattern="--$key=" |
38 | out=$pattern |
39 | ;; |
40 | - "$api_conf") match="^$key = " |
41 | + "$api_conf"|"$libvirtd_conf") match="^$key = " |
42 | pattern="$match" |
43 | out="$key = " |
44 | ;; |
45 | |
46 | === modified file 'hooks/lib/nova/folsom' |
47 | --- hooks/lib/nova/folsom 2012-12-03 11:18:59 +0000 |
48 | +++ hooks/lib/nova/folsom 2013-01-18 00:42:23 +0000 |
49 | @@ -15,6 +15,7 @@ |
50 | local quantum_conf=${QUANTUM_CONF:-/etc/quantum/quantum.conf} |
51 | local quantum_api_conf=${QUANTUM_API_CONF:-/etc/quantum/api-paste.ini} |
52 | local quantum_plugin_conf=${QUANTUM_PLUGIN_CONF:-/etc/quantum/plugins/openvswitch/ovs_quantum_plugin.ini} |
53 | + local libvirtd_conf=${LIBVIRTD_CONF:-/etc/libvirt/libvirtd.conf} |
54 | |
55 | [[ -z $key ]] && juju-log "$CHARM: set_or_update: value $value missing key" && exit 1 |
56 | [[ -z $value ]] && juju-log "$CHARM: set_or_update: key $key missing value" && exit 1 |
57 | @@ -27,11 +28,8 @@ |
58 | pattern="$key=" |
59 | out=$pattern |
60 | ;; |
61 | - "$api_conf") match="^$key = " |
62 | - pattern="$match" |
63 | - out="$key = " |
64 | - ;; |
65 | - "$quantum_conf"|"$quantum_api_conf"|"$quantum_plugin_conf") |
66 | + "$api_conf"|"$quantum_conf"|"$quantum_api_conf"|"$quantum_plugin_conf"| \ |
67 | + "$libvirtd_conf") |
68 | match="^$key = " |
69 | pattern="$match" |
70 | out="$key = " |
71 | |
72 | === added file 'hooks/lib/nova/grizzly' |
73 | --- hooks/lib/nova/grizzly 1970-01-01 00:00:00 +0000 |
74 | +++ hooks/lib/nova/grizzly 2013-01-18 00:42:23 +0000 |
75 | @@ -0,0 +1,80 @@ |
76 | +#!/bin/bash -e |
77 | + |
78 | +# Folsom-specific functions |
79 | + |
80 | +nova_set_or_update() { |
81 | + # TODO: This needs to be shared among folsom, grizzly and beyond. |
82 | + # Set a config option in nova.conf or api-paste.ini, depending |
83 | + # Defaults to updating nova.conf |
84 | + local key="$1" |
85 | + local value="$2" |
86 | + local conf_file="$3" |
87 | + local section="${4:-DEFAULT}" |
88 | + |
89 | + local nova_conf=${NOVA_CONF:-/etc/nova/nova.conf} |
90 | + local api_conf=${API_CONF:-/etc/nova/api-paste.ini} |
91 | + local quantum_conf=${QUANTUM_CONF:-/etc/quantum/quantum.conf} |
92 | + local quantum_api_conf=${QUANTUM_API_CONF:-/etc/quantum/api-paste.ini} |
93 | + local quantum_plugin_conf=${QUANTUM_PLUGIN_CONF:-/etc/quantum/plugins/openvswitch/ovs_quantum_plugin.ini} |
94 | + local libvirtd_conf=${LIBVIRTD_CONF:-/etc/libvirt/libvirtd.conf} |
95 | + |
96 | + [[ -z $key ]] && juju-log "$CHARM: set_or_update: value $value missing key" && exit 1 |
97 | + [[ -z $value ]] && juju-log "$CHARM: set_or_update: key $key missing value" && exit 1 |
98 | + |
99 | + [[ -z "$conf_file" ]] && conf_file=$nova_conf |
100 | + |
101 | + local pattern="" |
102 | + case "$conf_file" in |
103 | + "$nova_conf") match="^$key=" |
104 | + pattern="$key=" |
105 | + out=$pattern |
106 | + ;; |
107 | + "$api_conf"|"$quantum_conf"|"$quantum_api_conf"|"$quantum_plugin_conf"| \ |
108 | + "$libvirtd_conf") |
109 | + match="^$key = " |
110 | + pattern="$match" |
111 | + out="$key = " |
112 | + ;; |
113 | + *) juju-log "$CHARM ERROR: set_or_update: Invalid conf_file ($conf_file)" |
114 | + esac |
115 | + |
116 | + cat $conf_file | grep "$match$value" >/dev/null && |
117 | + juju-log "$CHARM: $key=$value already in set in $conf_file" \ |
118 | + && return 0 |
119 | + |
120 | + case $conf_file in |
121 | + "$quantum_conf"|"$quantum_api_conf"|"$quantum_plugin_conf") |
122 | + python -c " |
123 | +import ConfigParser |
124 | +config = ConfigParser.RawConfigParser() |
125 | +config.read('$conf_file') |
126 | +config.set('$section','$key','$value') |
127 | +with open('$conf_file', 'wb') as configfile: |
128 | + config.write(configfile) |
129 | +" |
130 | + ;; |
131 | + *) |
132 | + if cat $conf_file | grep "$match" >/dev/null ; then |
133 | + juju-log "$CHARM: Updating $conf_file, $key=$value" |
134 | + sed -i "s|\($pattern\).*|\1$value|" $conf_file |
135 | + else |
136 | + juju-log "$CHARM: Setting new option $key=$value in $conf_file" |
137 | + echo "$out$value" >>$conf_file |
138 | + fi |
139 | + ;; |
140 | + esac |
141 | +} |
142 | + |
143 | +# Upgrade Helpers |
144 | +nova_pre_upgrade() { |
145 | + # Pre-upgrade helper. Caller should pass the version of OpenStack we are |
146 | + # upgrading from. |
147 | + return 0 # Nothing to do here, yet. |
148 | +} |
149 | + |
150 | +nova_post_upgrade() { |
151 | + # Post-upgrade helper. Caller should pass the version of OpenStack we are |
152 | + # upgrading from. |
153 | + juju-log "$CHARM: Running post-upgrade hook: $upgrade_from -> folsom." |
154 | + # nothing to do here yet. |
155 | +} |
156 | |
157 | === modified file 'hooks/lib/nova/nova-common' |
158 | --- hooks/lib/nova/nova-common 2012-12-06 10:21:10 +0000 |
159 | +++ hooks/lib/nova/nova-common 2013-01-18 00:42:23 +0000 |
160 | @@ -32,9 +32,15 @@ |
161 | |
162 | configure_volume_service() { |
163 | local svc="$1" |
164 | + local cur_vers="$(get_os_codename_package "nova-common")" |
165 | case "$svc" in |
166 | - "cinder") set_or_update "volume_api_class" "nova.volume.cinder.API" ;; |
167 | - "nova-volume") set_or_update "volume_api_class" "nova.volume.api.API" ;; |
168 | + "cinder") |
169 | + set_or_update "volume_api_class" "nova.volume.cinder.API" ;; |
170 | + "nova-volume") |
171 | + # nova-volume only supported before grizzly. |
172 | + [[ "$cur_vers" == "essex" ]] || [[ "$cur_vers" == "folsom" ]] && |
173 | + set_or_update "volume_api_class" "nova.volume.api.API" |
174 | + ;; |
175 | *) juju-log "$CHARM ERROR - configure_volume_service: Invalid service $svc" |
176 | return 1 ;; |
177 | esac |
178 | @@ -49,11 +55,32 @@ |
179 | ;; |
180 | "FlatDHCPManager") |
181 | set_or_update "network_manager" "nova.network.manager.FlatDHCPManager" |
182 | + |
183 | + if [[ "$CHARM" == "nova-compute" ]] ; then |
184 | + local flat_interface=$(config-get flat-interface) |
185 | + local ec2_host=$(relation-get ec2_host) |
186 | + set_or_update flat_inteface "$flat_interface" |
187 | + set_or_update ec2_dmz_host "$ec2_host" |
188 | + |
189 | + # Ensure flat_interface has link. |
190 | + if ip link show $flat_interface >/dev/null 2>&1 ; then |
191 | + ip link set $flat_interface up |
192 | + fi |
193 | + |
194 | + # work around (LP: #1035172) |
195 | + if [[ -e /dev/vhost-net ]] ; then |
196 | + iptables -A POSTROUTING -t mangle -p udp --dport 68 -j CHECKSUM \ |
197 | + --checksum-fill |
198 | + fi |
199 | + fi |
200 | + |
201 | ;; |
202 | "Quantum") |
203 | local local_ip=$(get_ip `unit-get private-address`) |
204 | - [[ -n $local_ip ]] || juju-log "Unable to resolve local IP address" \ |
205 | - && exit 1 |
206 | + [[ -n $local_ip ]] || { |
207 | + juju-log "Unable to resolve local IP address" |
208 | + exit 1 |
209 | + } |
210 | set_or_update "network_api_class" "nova.network.quantumv2.api.API" |
211 | set_or_update "quantum_auth_strategy" "keystone" |
212 | set_or_update "core_plugin" "$QUANTUM_CORE_PLUGIN" "$QUANTUM_CONF" |
213 | |
214 | === modified file 'hooks/nova-compute-common' |
215 | --- hooks/nova-compute-common 2012-12-18 01:02:10 +0000 |
216 | +++ hooks/nova-compute-common 2013-01-18 00:42:23 +0000 |
217 | @@ -7,6 +7,7 @@ |
218 | NOVA_CONF=$(config-get nova-config) |
219 | API_CONF="/etc/nova/api-paste.ini" |
220 | QUANTUM_CONF="/etc/quantum/quantum.conf" |
221 | +LIBVIRTD_CONF="/etc/libvirt/libvirtd.conf" |
222 | |
223 | if [ -f /etc/nova/nm.conf ]; then |
224 | NET_MANAGER=$(cat /etc/nova/nm.conf) |
225 | @@ -49,7 +50,7 @@ |
226 | "xen") compute_pkg="nova-compute-xen";; |
227 | "uml") compute_pkg="nova-compute-uml";; |
228 | "lxc") compute_pkg="nova-compute-lxc";; |
229 | - *) error_out" ERROR: Unsupported virt_type=$virt_type";; |
230 | + *) error_out "ERROR: Unsupported virt_type=$virt_type";; |
231 | esac |
232 | echo "$compute_pkg" |
233 | } |
234 | @@ -165,6 +166,83 @@ |
235 | fi |
236 | } |
237 | |
238 | +function initialize_ssh_keys { |
239 | + # generate ssh keypair for root if one does not exist or |
240 | + # the pari is not complete. |
241 | + local pub="/root/.ssh/id_rsa" |
242 | + local priv="/root/.ssh/id_rsa.pub" |
243 | + if [[ -e $pub ]] && |
244 | + [[ -e $priv ]] ; then |
245 | + juju-log "$CHARM: SSH credentials already exist for root." |
246 | + return 0 |
247 | + fi |
248 | + juju-log "$CHARM: Initializing new SSH key pair for live migration." |
249 | + [[ -e $pub ]] && mv $pub $pub.$(date +"%s") |
250 | + [[ -e $priv ]] && mv $priv $priv.$(date +"%s") |
251 | + local keyname=$(echo $JUJU_UNIT_NAME | sed -e 's,/,-,g') |
252 | + echo -e "\n" | ssh-keygen -C "$keyname" -N "" |
253 | +} |
254 | + |
255 | +function libvirt_tcp_listening { |
256 | + # toggle libvirtd's tcp listening in both /etc/default/libvirt-bin |
257 | + # and /etc/libvirt/libvirtd.conf. |
258 | + local toggle="$1" |
259 | + juju-log "$CHARM: Configuring libvirt tcp listening: $toggle." |
260 | + local cur_opts=$(grep "^libvirtd_opts" /etc/default/libvirt-bin | |
261 | + cut -d= -f2 | sed -e 's/\"//g') |
262 | + local new_opts="" |
263 | + |
264 | + if [[ "$toggle" == "on" ]] ; then |
265 | + if [[ -z "$cur_opts" ]] ; then |
266 | + echo "libvirtd_opts=\"-d -l\"" >>/etc/default/libvirt-bin |
267 | + elif ! echo "$cur_opts" | grep -q "\-l" ; then |
268 | + new_opts="$cur_opts -l" |
269 | + sed -i "s|\(libvirtd_opts=\).*|\1\"$new_opts\"|" /etc/default/libvirt-bin |
270 | + fi |
271 | + set_or_update "listen_tcp" 1 $LIBVIRTD_CONF |
272 | + elif [[ "$toggle" == "off" ]] ; then |
273 | + if echo "$cur_opts" | grep -q "\-l" ; then |
274 | + new_opts=$(echo $cur_opts | sed -e 's/\-l//g') |
275 | + fi |
276 | + set_or_update "listen_tcp" 0 $LIBVIRTD_CONF |
277 | + fi |
278 | + |
279 | + [[ -n "$new_opts" ]] && |
280 | + sed -i "s|\(libvirtd_opts=\).*|\1\"$new_opts\"|" /etc/default/libvirt-bin |
281 | + |
282 | + return 0 |
283 | +} |
284 | + |
285 | + |
286 | +function configure_migration { |
287 | + local enable_migration=$(config-get enable-live-migration) |
288 | + |
289 | + if [[ "$enable_migration" != "True" ]] && |
290 | + [[ "$enable_migraiton" != "true" ]] ; then |
291 | + libvirt_tcp_listening "off" |
292 | + return $? |
293 | + fi |
294 | + |
295 | + libvirt_tcp_listening "on" |
296 | + |
297 | + case "$(config-get migration-auth-type)" in |
298 | + "none"|"None") |
299 | + set_or_update "listen_tls" 0 $LIBVIRTD_CONF |
300 | + set_or_update "auth_tcp" "\"none\"" $LIBVIRTD_CONF |
301 | + ;; |
302 | + "ssh") |
303 | + set_or_update "listen_tls" 0 $LIBVIRTD_CONF |
304 | + set_or_update "live_migration_uri" "qemu+ssh://%s/system" $NOVA_CONF |
305 | + initialize_ssh_keys |
306 | + # check in with nova-c-c and register our new key. |
307 | + for id in $(relation-ids cloud-compute) ; do |
308 | + compute_joined $id |
309 | + done |
310 | + service_ctl nova-compute restart ;; |
311 | + "sasl") return 0 ;; |
312 | + esac |
313 | +} |
314 | + |
315 | function configure_libvirt { |
316 | cat > /etc/libvirt/qemu.conf << EOF |
317 | # File installed by Juju nova-compute charm |
318 | @@ -175,5 +253,12 @@ |
319 | "/dev/rtc", "/dev/hpet", "/dev/net/tun", |
320 | ] |
321 | EOF |
322 | - service libvirt-bin reload |
323 | + configure_migration |
324 | + service libvirt-bin restart |
325 | +} |
326 | + |
327 | +function migration_enabled { |
328 | + local migration="$(config-get enable-live-migration)" |
329 | + [[ "$migration" == "true" ]] || [[ "$migration" == "True" ]] && return 0 |
330 | + return 1 |
331 | } |
332 | |
333 | === modified file 'hooks/nova-compute-relations' |
334 | --- hooks/nova-compute-relations 2013-01-17 01:12:35 +0000 |
335 | +++ hooks/nova-compute-relations 2013-01-18 00:42:23 +0000 |
336 | @@ -35,6 +35,11 @@ |
337 | do_openstack_upgrade "$install_src" $PACKAGES |
338 | fi |
339 | |
340 | + # set this here until its fixed in grizzly packaging. (adam_g) |
341 | + [[ "$cur" == "grizzly" ]] && |
342 | + set_or_update "compute_driver" "libvirt.LibvirtDriver" |
343 | + |
344 | + configure_libvirt |
345 | set_config_flags |
346 | service_ctl all restart |
347 | } |
348 | @@ -141,6 +146,18 @@ |
349 | service_ctl all restart |
350 | } |
351 | |
352 | +function compute_joined { |
353 | + migration_enabled || return 0 |
354 | + local relid="$1" |
355 | + [[ -n "$relid" ]] && relid="-r $relid" |
356 | + migration_auth="$(config-get migration-auth-type)" |
357 | + case "$migration_auth" in |
358 | + "none"|"None") return 0 ;; |
359 | + "ssh") relation-set $relid ssh_public_key="$(cat /root/.ssh/id_rsa.pub)" ;; |
360 | + esac |
361 | + relation-set $relid migration_auth_type="$migration_auth" |
362 | +} |
363 | + |
364 | function compute_changed { |
365 | # nova-c-c will inform us of the configured network manager. nova-compute |
366 | # needs to configure itself accordingly. |
367 | @@ -185,6 +202,21 @@ |
368 | volume_service=`relation-get volume_service` |
369 | [[ -n "$volume_service" ]] && configure_volume_service "$volume_service" |
370 | |
371 | + if migration_enabled ; then |
372 | + case "$(config-get migration-auth-type)" in |
373 | + "ssh") |
374 | + local known_hosts="$(relation-get known_hosts)" |
375 | + local authorized_keys="$(relation-get authorized_keys)" |
376 | + if [[ -n "$known_hosts" ]] && |
377 | + [[ -n "$authorized_keys" ]] ; then |
378 | + juju-log "$CHARM: Saving new known_hosts+authorized_keys file." |
379 | + echo "$known_hosts" | base64 -di >/root/.ssh/known_hosts |
380 | + echo "$authorized_keys" | base64 -di >/root/.ssh/authorized_keys |
381 | + fi |
382 | + ;; |
383 | + esac |
384 | + fi |
385 | + |
386 | # restart on all changed events. nova-c-c may send out a uuid to trigger |
387 | # remote restarts of services here (after db migrations, for instance) |
388 | service_ctl all restart |
389 | @@ -258,6 +290,6 @@ |
390 | "identity-service-relation-changed") exit 0 ;; |
391 | "ceph-relation-joined") ceph_joined;; |
392 | "ceph-relation-changed") ceph_changed;; |
393 | - "cloud-compute-relation-joined" ) exit 0 ;; |
394 | + "cloud-compute-relation-joined" ) compute_joined ;; |
395 | "cloud-compute-relation-changed") compute_changed ;; |
396 | esac |
397 | |
398 | === modified file 'metadata.yaml' |
399 | --- metadata.yaml 2012-10-25 14:41:09 +0000 |
400 | +++ metadata.yaml 2013-01-18 00:42:23 +0000 |
401 | @@ -17,3 +17,6 @@ |
402 | interface: glance |
403 | ceph: |
404 | interface: ceph-client |
405 | +peers: |
406 | + compute-peer: |
407 | + interface: nova |
408 | |
409 | === modified file 'revision' |
410 | --- revision 2013-01-18 00:39:29 +0000 |
411 | +++ revision 2013-01-18 00:42:23 +0000 |
412 | @@ -1,1 +1,1 @@ |
413 | -81 |
414 | +82 |