blob: 63f9bcb002d6ba05e152ab018a02dc1fa6e55c03 [file] [log] [blame]
Salvatore Orlandod6767d02012-08-31 04:55:20 -07001# lib/quantum
2# functions - funstions specific to quantum
3
Dean Troyer60e9c0a2012-12-06 15:52:52 -06004# Dependencies:
5# ``functions`` file
6# ``DEST`` must be defined
7
Akihiro MOTOKI66afb472012-12-21 15:34:13 +09008# ``stack.sh`` calls the entry points in this order:
9#
10# install_quantum
11# install_quantumclient
12# install_quantum_agent_packages
13# install_quantum_third_party
14# setup_quantum
15# setup_quantumclient
16# configure_quantum
17# init_quantum
18# configure_quantum_third_party
19# init_quantum_third_party
20# start_quantum_third_party
21# create_nova_conf_quantum
22# start_quantum_service_and_check
23# create_quantum_initial_network
24# setup_quantum_debug
25# start_quantum_agents
26#
27# ``unstack.sh`` calls the entry points in this order:
28#
29# stop_quantum
30
31# Functions in lib/quantum are classified into the following categories:
32#
33# - entry points (called from stack.sh or unstack.sh)
34# - internal functions
35# - quantum exercises
36# - 3rd party programs
37
Dean Troyer60e9c0a2012-12-06 15:52:52 -060038
39# Quantum Networking
40# ------------------
41
42# Make sure that quantum is enabled in ``ENABLED_SERVICES``. If you want
43# to run Quantum on this host, make sure that q-svc is also in
44# ``ENABLED_SERVICES``.
45#
46# If you're planning to use the Quantum openvswitch plugin, set
47# ``Q_PLUGIN`` to "openvswitch" and make sure the q-agt service is enabled
48# in ``ENABLED_SERVICES``. If you're planning to use the Quantum
49# linuxbridge plugin, set ``Q_PLUGIN`` to "linuxbridge" and make sure the
50# q-agt service is enabled in ``ENABLED_SERVICES``.
51#
52# See "Quantum Network Configuration" below for additional variables
53# that must be set in localrc for connectivity across hosts with
54# Quantum.
55#
56# With Quantum networking the NET_MAN variable is ignored.
57
58
Salvatore Orlandod6767d02012-08-31 04:55:20 -070059# Save trace setting
60XTRACE=$(set +o | grep xtrace)
61set +o xtrace
62
Dean Troyer60e9c0a2012-12-06 15:52:52 -060063
Akihiro MOTOKI66afb472012-12-21 15:34:13 +090064# Quantum Network Configuration
65# -----------------------------
Dean Troyer60e9c0a2012-12-06 15:52:52 -060066
67# Set up default directories
Nachi Ueno8bc21f62012-11-19 22:04:28 -080068QUANTUM_DIR=$DEST/quantum
Dean Troyer60e9c0a2012-12-06 15:52:52 -060069QUANTUMCLIENT_DIR=$DEST/python-quantumclient
Gary Kotton9343df12012-11-28 10:05:53 +000070QUANTUM_AUTH_CACHE_DIR=${QUANTUM_AUTH_CACHE_DIR:-/var/cache/quantum}
Nachi Ueno5db5bfa2012-10-29 11:25:29 -070071
Dean Troyer60e9c0a2012-12-06 15:52:52 -060072QUANTUM_CONF_DIR=/etc/quantum
73QUANTUM_CONF=$QUANTUM_CONF_DIR/quantum.conf
74export QUANTUM_TEST_CONFIG_FILE=${QUANTUM_TEST_CONFIG_FILE:-"$QUANTUM_CONF_DIR/debug.ini"}
75
76# Default Quantum Plugin
77Q_PLUGIN=${Q_PLUGIN:-openvswitch}
78# Default Quantum Port
79Q_PORT=${Q_PORT:-9696}
80# Default Quantum Host
81Q_HOST=${Q_HOST:-$HOST_IP}
Dean Troyer60e9c0a2012-12-06 15:52:52 -060082# Default admin username
83Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-quantum}
84# Default auth strategy
85Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone}
86# Use namespace or not
87Q_USE_NAMESPACE=${Q_USE_NAMESPACE:-True}
88Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True}
89# Meta data IP
90Q_META_DATA_IP=${Q_META_DATA_IP:-$HOST_IP}
Akihiro MOTOKI66afb472012-12-21 15:34:13 +090091# Allow Overlapping IP among subnets
92Q_ALLOW_OVERLAPPING_IP=${Q_ALLOW_OVERLAPPING_IP:-False}
Dean Troyer60e9c0a2012-12-06 15:52:52 -060093# Use quantum-debug command
94Q_USE_DEBUG_COMMAND=${Q_USE_DEBUG_COMMAND:-False}
Maru Newby31c94ab2012-12-19 03:59:20 +000095# The name of the default q-l3 router
96Q_ROUTER_NAME=${Q_ROUTER_NAME:-router1}
Dean Troyer60e9c0a2012-12-06 15:52:52 -060097
Nachi Ueno8bc21f62012-11-19 22:04:28 -080098if is_service_enabled quantum; then
Dean Troyer60e9c0a2012-12-06 15:52:52 -060099 Q_RR_CONF_FILE=$QUANTUM_CONF_DIR/rootwrap.conf
Nachi Ueno8bc21f62012-11-19 22:04:28 -0800100 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
101 Q_RR_COMMAND="sudo"
102 else
Nachi Uenoeb1aa3d2012-12-06 11:55:29 -0800103 QUANTUM_ROOTWRAP=$(get_rootwrap_location quantum)
104 Q_RR_COMMAND="sudo $QUANTUM_ROOTWRAP $Q_RR_CONF_FILE"
Nachi Ueno8bc21f62012-11-19 22:04:28 -0800105 fi
Nachi Ueno8bc21f62012-11-19 22:04:28 -0800106
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900107 # Provider Network Configurations
108 # --------------------------------
109
110 # The following variables control the Quantum openvswitch and
111 # linuxbridge plugins' allocation of tenant networks and
112 # availability of provider networks. If these are not configured
113 # in localrc, tenant networks will be local to the host (with no
114 # remote connectivity), and no physical resources will be
115 # available for the allocation of provider networks.
116
117 # To use GRE tunnels for tenant networks, set to True in
118 # localrc. GRE tunnels are only supported by the openvswitch
119 # plugin, and currently only on Ubuntu.
120 ENABLE_TENANT_TUNNELS=${ENABLE_TENANT_TUNNELS:-False}
121
122 # If using GRE tunnels for tenant networks, specify the range of
123 # tunnel IDs from which tenant networks are allocated. Can be
124 # overriden in localrc in necesssary.
125 TENANT_TUNNEL_RANGES=${TENANT_TUNNEL_RANGE:-1:1000}
126
127 # To use VLANs for tenant networks, set to True in localrc. VLANs
128 # are supported by the openvswitch and linuxbridge plugins, each
129 # requiring additional configuration described below.
130 ENABLE_TENANT_VLANS=${ENABLE_TENANT_VLANS:-False}
131
132 # If using VLANs for tenant networks, set in localrc to specify
133 # the range of VLAN VIDs from which tenant networks are
134 # allocated. An external network switch must be configured to
135 # trunk these VLANs between hosts for multi-host connectivity.
136 #
137 # Example: ``TENANT_VLAN_RANGE=1000:1999``
138 TENANT_VLAN_RANGE=${TENANT_VLAN_RANGE:-}
139
140 # If using VLANs for tenant networks, or if using flat or VLAN
141 # provider networks, set in localrc to the name of the physical
142 # network, and also configure OVS_PHYSICAL_BRIDGE for the
143 # openvswitch agent or LB_PHYSICAL_INTERFACE for the linuxbridge
144 # agent, as described below.
145 #
146 # Example: ``PHYSICAL_NETWORK=default``
147 PHYSICAL_NETWORK=${PHYSICAL_NETWORK:-}
148
149 # With the openvswitch plugin, if using VLANs for tenant networks,
150 # or if using flat or VLAN provider networks, set in localrc to
151 # the name of the OVS bridge to use for the physical network. The
152 # bridge will be created if it does not already exist, but a
153 # physical interface must be manually added to the bridge as a
154 # port for external connectivity.
155 #
156 # Example: ``OVS_PHYSICAL_BRIDGE=br-eth1``
157 OVS_PHYSICAL_BRIDGE=${OVS_PHYSICAL_BRIDGE:-}
158
159 # With the linuxbridge plugin, if using VLANs for tenant networks,
160 # or if using flat or VLAN provider networks, set in localrc to
161 # the name of the network interface to use for the physical
162 # network.
163 #
164 # Example: ``LB_PHYSICAL_INTERFACE=eth1``
165 LB_PHYSICAL_INTERFACE=${LB_PHYSICAL_INTERFACE:-}
166
167 # With the openvswitch plugin, set to True in localrc to enable
168 # provider GRE tunnels when ``ENABLE_TENANT_TUNNELS`` is False.
169 #
170 # Example: ``OVS_ENABLE_TUNNELING=True``
171 OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS}
172fi
Dean Troyer60e9c0a2012-12-06 15:52:52 -0600173
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900174# Quantum plugin specific functions
175# ---------------------------------
176# Please refer to lib/quantum_plugins/README.md for details.
177source $TOP_DIR/lib/quantum_plugins/$Q_PLUGIN
178
Eugene Nikanorovb7d82842013-03-06 16:28:33 +0400179# Agent loadbalancer service plugin functions
180# -------------------------------------------
181# Hardcoding for 1 service plugin for now
182source $TOP_DIR/lib/quantum_plugins/agent_loadbalancer
183
Dean Troyer60e9c0a2012-12-06 15:52:52 -0600184# Entry Points
185# ------------
186
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900187# configure_quantum()
188# Set common config for all quantum server and agents.
189function configure_quantum() {
190 _configure_quantum_common
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900191 iniset_rpc_backend quantum $QUANTUM_CONF DEFAULT
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900192
Eugene Nikanorovb7d82842013-03-06 16:28:33 +0400193 # goes before q-svc to init Q_SERVICE_PLUGIN_CLASSES
194 if is_service_enabled q-lbaas; then
195 _configure_quantum_lbaas
196 fi
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900197 if is_service_enabled q-svc; then
198 _configure_quantum_service
199 fi
200 if is_service_enabled q-agt; then
201 _configure_quantum_plugin_agent
202 fi
203 if is_service_enabled q-dhcp; then
204 _configure_quantum_dhcp_agent
205 fi
206 if is_service_enabled q-l3; then
207 _configure_quantum_l3_agent
208 fi
209 if is_service_enabled q-meta; then
210 _configure_quantum_metadata_agent
211 fi
212
213 _configure_quantum_debug_command
214
215 _cleanup_quantum
216}
217
218function create_nova_conf_quantum() {
Devananda van der Veen9bc47db2012-12-12 16:52:55 -0800219 iniset $NOVA_CONF DEFAULT network_api_class "nova.network.quantumv2.api.API"
220 iniset $NOVA_CONF DEFAULT quantum_admin_username "$Q_ADMIN_USERNAME"
221 iniset $NOVA_CONF DEFAULT quantum_admin_password "$SERVICE_PASSWORD"
222 iniset $NOVA_CONF DEFAULT quantum_admin_auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0"
223 iniset $NOVA_CONF DEFAULT quantum_auth_strategy "$Q_AUTH_STRATEGY"
224 iniset $NOVA_CONF DEFAULT quantum_admin_tenant_name "$SERVICE_TENANT_NAME"
225 iniset $NOVA_CONF DEFAULT quantum_url "http://$Q_HOST:$Q_PORT"
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900226
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900227 # set NOVA_VIF_DRIVER and optionally set options in nova_conf
228 quantum_plugin_create_nova_conf
229
Devananda van der Veen9bc47db2012-12-12 16:52:55 -0800230 iniset $NOVA_CONF DEFAULT libvirt_vif_driver "$NOVA_VIF_DRIVER"
231 iniset $NOVA_CONF DEFAULT linuxnet_interface_driver "$LINUXNET_VIF_DRIVER"
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900232 if is_service_enabled q-meta; then
Devananda van der Veen9bc47db2012-12-12 16:52:55 -0800233 iniset $NOVA_CONF DEFAULT service_quantum_metadata_proxy "True"
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900234 fi
235}
236
237# create_quantum_accounts() - Set up common required quantum accounts
238
239# Tenant User Roles
240# ------------------------------------------------------------------
241# service quantum admin # if enabled
242
243# Migrated from keystone_data.sh
244function create_quantum_accounts() {
245
246 SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
247 ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }")
248
249 if [[ "$ENABLED_SERVICES" =~ "q-svc" ]]; then
250 QUANTUM_USER=$(keystone user-create \
251 --name=quantum \
252 --pass="$SERVICE_PASSWORD" \
253 --tenant_id $SERVICE_TENANT \
254 --email=quantum@example.com \
255 | grep " id " | get_field 2)
256 keystone user-role-add \
257 --tenant_id $SERVICE_TENANT \
258 --user_id $QUANTUM_USER \
259 --role_id $ADMIN_ROLE
260 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
261 QUANTUM_SERVICE=$(keystone service-create \
262 --name=quantum \
263 --type=network \
264 --description="Quantum Service" \
265 | grep " id " | get_field 2)
266 keystone endpoint-create \
267 --region RegionOne \
268 --service_id $QUANTUM_SERVICE \
269 --publicurl "http://$SERVICE_HOST:9696/" \
270 --adminurl "http://$SERVICE_HOST:9696/" \
271 --internalurl "http://$SERVICE_HOST:9696/"
272 fi
273 fi
274}
275
276function create_quantum_initial_network() {
277 TENANT_ID=$(keystone tenant-list | grep " demo " | get_field 1)
278
279 # Create a small network
280 # Since quantum command is executed in admin context at this point,
281 # ``--tenant_id`` needs to be specified.
Devananda van der Veen37a8d152013-01-15 17:27:34 -0800282 if is_baremetal; then
283 sudo ovs-vsctl add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
284 for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do
285 sudo ip addr del $IP dev $PUBLIC_INTERFACE
286 sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE
287 done
288 NET_ID=$(quantum net-create $PHYSICAL_NETWORK --tenant_id $TENANT_ID --provider:network_type flat --provider:physical_network "$PHYSICAL_NETWORK" | grep ' id ' | get_field 2)
289 SUBNET_ID=$(quantum subnet-create --tenant_id $TENANT_ID --ip_version 4 ${ALLOCATION_POOL:+--allocation-pool $ALLOCATION_POOL} --gateway $NETWORK_GATEWAY $NET_ID $FIXED_RANGE | grep ' id ' | get_field 2)
290 sudo ifconfig $OVS_PHYSICAL_BRIDGE up
291 else
292 NET_ID=$(quantum net-create --tenant_id $TENANT_ID "$PRIVATE_NETWORK_NAME" | grep ' id ' | get_field 2)
293 SUBNET_ID=$(quantum subnet-create --tenant_id $TENANT_ID --ip_version 4 --gateway $NETWORK_GATEWAY $NET_ID $FIXED_RANGE | grep ' id ' | get_field 2)
294 fi
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900295
Dan Wendlandt555ecd02013-02-23 23:07:07 -0800296 if [[ "$Q_L3_ENABLED" == "True" ]]; then
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900297 # Create a router, and add the private subnet as one of its interfaces
Dan Wendlandt555ecd02013-02-23 23:07:07 -0800298 if [[ "$Q_L3_ROUTER_PER_TENANT" == "True" ]]; then
299 # create a tenant-owned router.
Maru Newby31c94ab2012-12-19 03:59:20 +0000300 ROUTER_ID=$(quantum router-create --tenant_id $TENANT_ID $Q_ROUTER_NAME | grep ' id ' | get_field 2)
301 else
Dan Wendlandt555ecd02013-02-23 23:07:07 -0800302 # Plugin only supports creating a single router, which should be admin owned.
Maru Newby31c94ab2012-12-19 03:59:20 +0000303 ROUTER_ID=$(quantum router-create $Q_ROUTER_NAME | grep ' id ' | get_field 2)
304 fi
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900305 quantum router-interface-add $ROUTER_ID $SUBNET_ID
306 # Create an external network, and a subnet. Configure the external network as router gw
307 EXT_NET_ID=$(quantum net-create "$PUBLIC_NETWORK_NAME" -- --router:external=True | grep ' id ' | get_field 2)
Stephen Ma8396d4f2013-02-18 05:32:59 -0800308 EXT_GW_IP=$(quantum subnet-create --ip_version 4 ${Q_FLOATING_ALLOCATION_POOL:+--allocation-pool $Q_FLOATING_ALLOCATION_POOL} $EXT_NET_ID $FLOATING_RANGE -- --enable_dhcp=False | grep 'gateway_ip' | get_field 2)
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900309 quantum router-gateway-set $ROUTER_ID $EXT_NET_ID
310
Dan Wendlandt555ecd02013-02-23 23:07:07 -0800311 if is_service_enabled q-l3; then
312 # logic is specific to using the l3-agent for l3
313 if is_quantum_ovs_base_plugin && [[ "$Q_USE_NAMESPACE" = "True" ]]; then
314 CIDR_LEN=${FLOATING_RANGE#*/}
315 sudo ip addr add $EXT_GW_IP/$CIDR_LEN dev $PUBLIC_BRIDGE
316 sudo ip link set $PUBLIC_BRIDGE up
317 ROUTER_GW_IP=`quantum port-list -c fixed_ips -c device_owner | grep router_gateway | awk -F '"' '{ print $8; }'`
318 sudo route add -net $FIXED_RANGE gw $ROUTER_GW_IP
319 fi
320 if [[ "$Q_USE_NAMESPACE" == "False" ]]; then
321 # Explicitly set router id in l3 agent configuration
322 iniset $Q_L3_CONF_FILE DEFAULT router_id $ROUTER_ID
323 fi
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900324 fi
325 fi
326}
327
328# init_quantum() - Initialize databases, etc.
329function init_quantum() {
330 :
331}
332
333# install_quantum() - Collect source and prepare
334function install_quantum() {
335 git_clone $QUANTUM_REPO $QUANTUM_DIR $QUANTUM_BRANCH
336}
337
338# install_quantumclient() - Collect source and prepare
339function install_quantumclient() {
340 git_clone $QUANTUMCLIENT_REPO $QUANTUMCLIENT_DIR $QUANTUMCLIENT_BRANCH
341}
342
343# install_quantum_agent_packages() - Collect source and prepare
344function install_quantum_agent_packages() {
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900345 # install packages that is specific to plugin agent
346 quantum_plugin_install_agent_packages
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900347}
348
349function setup_quantum() {
350 setup_develop $QUANTUM_DIR
351}
352
353function setup_quantumclient() {
354 setup_develop $QUANTUMCLIENT_DIR
355}
356
357# Start running processes, including screen
358function start_quantum_service_and_check() {
359 # Start the Quantum service
360 screen_it q-svc "cd $QUANTUM_DIR && python $QUANTUM_DIR/bin/quantum-server --config-file $QUANTUM_CONF --config-file /$Q_PLUGIN_CONF_FILE"
361 echo "Waiting for Quantum to start..."
Aaron Rosen0ae742c2013-02-21 12:10:30 -0800362 if ! timeout $SERVICE_TIMEOUT sh -c "while ! http_proxy= wget -q -O- http://$Q_HOST:$Q_PORT; do sleep 1; done"; then
Nachi Ueno07115eb2013-02-26 12:38:18 -0800363 die $LINENO "Quantum did not start"
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900364 fi
365}
366
367# Start running processes, including screen
368function start_quantum_agents() {
369 # Start up the quantum agents if enabled
370 screen_it q-agt "python $AGENT_BINARY --config-file $QUANTUM_CONF --config-file /$Q_PLUGIN_CONF_FILE"
371 screen_it q-dhcp "python $AGENT_DHCP_BINARY --config-file $QUANTUM_CONF --config-file=$Q_DHCP_CONF_FILE"
372 screen_it q-meta "python $AGENT_META_BINARY --config-file $QUANTUM_CONF --config-file=$Q_META_CONF_FILE"
373 screen_it q-l3 "python $AGENT_L3_BINARY --config-file $QUANTUM_CONF --config-file=$Q_L3_CONF_FILE"
Eugene Nikanorovb7d82842013-03-06 16:28:33 +0400374
375 if is_service_enabled q-lbaas; then
376 screen_it q-lbaas "python $AGENT_LBAAS_BINARY --config-file $QUANTUM_CONF --config-file=$LBAAS_AGENT_CONF_FILENAME"
377 fi
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900378}
379
380# stop_quantum() - Stop running processes (non-screen)
381function stop_quantum() {
382 if is_service_enabled q-dhcp; then
383 pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }')
384 [ ! -z "$pid" ] && sudo kill -9 $pid
385 fi
386}
387
388# _cleanup_quantum() - Remove residual data files, anything left over from previous
389# runs that a clean run would need to clean up
390function _cleanup_quantum() {
391 :
392}
393
394# _configure_quantum_common()
395# Set common config for all quantum server and agents.
396# This MUST be called before other _configure_quantum_* functions.
397function _configure_quantum_common() {
398 # Put config files in ``QUANTUM_CONF_DIR`` for everyone to find
399 if [[ ! -d $QUANTUM_CONF_DIR ]]; then
400 sudo mkdir -p $QUANTUM_CONF_DIR
401 fi
Attila Fazekas91b8d132013-01-06 22:40:09 +0100402 sudo chown $STACK_USER $QUANTUM_CONF_DIR
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900403
404 cp $QUANTUM_DIR/etc/quantum.conf $QUANTUM_CONF
405
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900406 # set plugin-specific variables
407 # Q_PLUGIN_CONF_PATH, Q_PLUGIN_CONF_FILENAME, Q_DB_NAME, Q_PLUGIN_CLASS
408 quantum_plugin_configure_common
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900409
410 if [[ $Q_PLUGIN_CONF_PATH == '' || $Q_PLUGIN_CONF_FILENAME == '' || $Q_PLUGIN_CLASS == '' ]]; then
Nachi Ueno07115eb2013-02-26 12:38:18 -0800411 die $LINENO "Quantum plugin not set.. exiting"
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900412 fi
413
414 # If needed, move config file from ``$QUANTUM_DIR/etc/quantum`` to ``QUANTUM_CONF_DIR``
415 mkdir -p /$Q_PLUGIN_CONF_PATH
416 Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME
417 cp $QUANTUM_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE
418
419 database_connection_url dburl $Q_DB_NAME
420 iniset /$Q_PLUGIN_CONF_FILE DATABASE sql_connection $dburl
421 unset dburl
422
423 _quantum_setup_rootwrap
424}
425
426function _configure_quantum_debug_command() {
427 if [[ "$Q_USE_DEBUG_COMMAND" != "True" ]]; then
428 return
429 fi
430
431 cp $QUANTUM_DIR/etc/l3_agent.ini $QUANTUM_TEST_CONFIG_FILE
432
433 iniset $QUANTUM_TEST_CONFIG_FILE DEFAULT verbose False
434 iniset $QUANTUM_TEST_CONFIG_FILE DEFAULT debug False
435 iniset $QUANTUM_TEST_CONFIG_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
436 iniset $QUANTUM_TEST_CONFIG_FILE DEFAULT root_helper "$Q_RR_COMMAND"
Gary Kottond9ca2b22013-01-30 13:52:43 +0000437 # Intermediate fix until Quantum patch lands and then line above will
438 # be cleaned.
439 iniset $QUANTUM_TEST_CONFIG_FILE AGENT root_helper "$Q_RR_COMMAND"
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900440
441 _quantum_setup_keystone $QUANTUM_TEST_CONFIG_FILE DEFAULT set_auth_url
442 _quantum_setup_interface_driver $QUANTUM_TEST_CONFIG_FILE
443
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900444 quantum_plugin_configure_debug_command
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900445}
446
447function _configure_quantum_dhcp_agent() {
448 AGENT_DHCP_BINARY="$QUANTUM_DIR/bin/quantum-dhcp-agent"
449 Q_DHCP_CONF_FILE=$QUANTUM_CONF_DIR/dhcp_agent.ini
450
451 cp $QUANTUM_DIR/etc/dhcp_agent.ini $Q_DHCP_CONF_FILE
452
453 iniset $Q_DHCP_CONF_FILE DEFAULT verbose True
454 iniset $Q_DHCP_CONF_FILE DEFAULT debug True
455 iniset $Q_DHCP_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900456 iniset $Q_DHCP_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
457
458 _quantum_setup_keystone $Q_DHCP_CONF_FILE DEFAULT set_auth_url
459 _quantum_setup_interface_driver $Q_DHCP_CONF_FILE
460
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900461 quantum_plugin_configure_dhcp_agent
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900462}
463
464function _configure_quantum_l3_agent() {
Dan Wendlandt555ecd02013-02-23 23:07:07 -0800465 Q_L3_ENABLED=True
466 # for l3-agent, only use per tenant router if we have namespaces
467 Q_L3_ROUTER_PER_TENANT=$Q_USE_NAMESPACE
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900468 AGENT_L3_BINARY="$QUANTUM_DIR/bin/quantum-l3-agent"
469 PUBLIC_BRIDGE=${PUBLIC_BRIDGE:-br-ex}
470 Q_L3_CONF_FILE=$QUANTUM_CONF_DIR/l3_agent.ini
471
472 cp $QUANTUM_DIR/etc/l3_agent.ini $Q_L3_CONF_FILE
473
474 iniset $Q_L3_CONF_FILE DEFAULT verbose True
475 iniset $Q_L3_CONF_FILE DEFAULT debug True
476 iniset $Q_L3_CONF_FILE DEFAULT use_namespaces $Q_USE_NAMESPACE
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900477 iniset $Q_L3_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
478
479 _quantum_setup_keystone $Q_L3_CONF_FILE DEFAULT set_auth_url
480 _quantum_setup_interface_driver $Q_L3_CONF_FILE
481
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900482 quantum_plugin_configure_l3_agent
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900483}
484
485function _configure_quantum_metadata_agent() {
486 AGENT_META_BINARY="$QUANTUM_DIR/bin/quantum-metadata-agent"
487 Q_META_CONF_FILE=$QUANTUM_CONF_DIR/metadata_agent.ini
488
489 cp $QUANTUM_DIR/etc/metadata_agent.ini $Q_META_CONF_FILE
490
491 iniset $Q_META_CONF_FILE DEFAULT verbose True
492 iniset $Q_META_CONF_FILE DEFAULT debug True
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900493 iniset $Q_META_CONF_FILE DEFAULT nova_metadata_ip $Q_META_DATA_IP
494 iniset $Q_META_CONF_FILE DEFAULT root_helper "$Q_RR_COMMAND"
495
496 _quantum_setup_keystone $Q_META_CONF_FILE DEFAULT set_auth_url
497}
498
Eugene Nikanorovb7d82842013-03-06 16:28:33 +0400499function _configure_quantum_lbaas()
500{
501 quantum_agent_lbaas_install_agent_packages
502 quantum_agent_lbaas_configure_common
503 quantum_agent_lbaas_configure_agent
504}
505
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900506# _configure_quantum_plugin_agent() - Set config files for quantum plugin agent
507# It is called when q-agt is enabled.
508function _configure_quantum_plugin_agent() {
Maru Newby2298ca42012-10-25 23:46:42 +0000509 # Specify the default root helper prior to agent configuration to
Gary Kotton98e18e92013-01-28 14:26:56 +0000510 # ensure that an agent's configuration can override the default
Maru Newby2298ca42012-10-25 23:46:42 +0000511 iniset /$Q_PLUGIN_CONF_FILE AGENT root_helper "$Q_RR_COMMAND"
512
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900513 # Configure agent for plugin
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900514 quantum_plugin_configure_plugin_agent
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900515}
516
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900517# _configure_quantum_service() - Set config files for quantum service
518# It is called when q-svc is enabled.
519function _configure_quantum_service() {
520 Q_API_PASTE_FILE=$QUANTUM_CONF_DIR/api-paste.ini
521 Q_POLICY_FILE=$QUANTUM_CONF_DIR/policy.json
522
523 cp $QUANTUM_DIR/etc/api-paste.ini $Q_API_PASTE_FILE
524 cp $QUANTUM_DIR/etc/policy.json $Q_POLICY_FILE
525
526 if is_service_enabled $DATABASE_BACKENDS; then
527 recreate_database $Q_DB_NAME utf8
528 else
Nachi Ueno07115eb2013-02-26 12:38:18 -0800529 die $LINENO "A database must be enabled in order to use the $Q_PLUGIN Quantum plugin."
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900530 fi
531
532 # Update either configuration file with plugin
533 iniset $QUANTUM_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS
534
Eugene Nikanorovb7d82842013-03-06 16:28:33 +0400535 if [[ $Q_SERVICE_PLUGIN_CLASSES != '' ]]; then
536 iniset $QUANTUM_CONF DEFAULT service_plugins $Q_SERVICE_PLUGIN_CLASSES
537 fi
538
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900539 iniset $QUANTUM_CONF DEFAULT verbose True
540 iniset $QUANTUM_CONF DEFAULT debug True
Akihiro MOTOKI3c6e9a52013-02-26 14:50:56 +0900541 iniset $QUANTUM_CONF DEFAULT state_path $DATA_DIR/quantum
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900542 iniset $QUANTUM_CONF DEFAULT allow_overlapping_ips $Q_ALLOW_OVERLAPPING_IP
543
544 iniset $QUANTUM_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY
Akihiro MOTOKI712feb62013-02-11 23:45:19 +0900545 _quantum_setup_keystone $QUANTUM_CONF keystone_authtoken
546 # Comment out keystone authtoken configuration in api-paste.ini
547 # It is required to avoid any breakage in Quantum where the sample
548 # api-paste.ini has authtoken configurations.
549 _quantum_commentout_keystone_authtoken $Q_API_PASTE_FILE filter:authtoken
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900550
551 # Configure plugin
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900552 quantum_plugin_configure_service
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900553}
554
555# Utility Functions
556#------------------
557
558# _quantum_setup_rootwrap() - configure Quantum's rootwrap
559function _quantum_setup_rootwrap() {
Nachi Uenoeb1aa3d2012-12-06 11:55:29 -0800560 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
561 return
562 fi
563 # Deploy new rootwrap filters files (owned by root).
564 # Wipe any existing rootwrap.d files first
Dean Troyer60e9c0a2012-12-06 15:52:52 -0600565 Q_CONF_ROOTWRAP_D=$QUANTUM_CONF_DIR/rootwrap.d
Nachi Uenoeb1aa3d2012-12-06 11:55:29 -0800566 if [[ -d $Q_CONF_ROOTWRAP_D ]]; then
567 sudo rm -rf $Q_CONF_ROOTWRAP_D
568 fi
Dean Troyer60e9c0a2012-12-06 15:52:52 -0600569 # Deploy filters to $QUANTUM_CONF_DIR/rootwrap.d
Nachi Uenoeb1aa3d2012-12-06 11:55:29 -0800570 mkdir -p -m 755 $Q_CONF_ROOTWRAP_D
571 cp -pr $QUANTUM_DIR/etc/quantum/rootwrap.d/* $Q_CONF_ROOTWRAP_D/
572 sudo chown -R root:root $Q_CONF_ROOTWRAP_D
573 sudo chmod 644 $Q_CONF_ROOTWRAP_D/*
Dean Troyer60e9c0a2012-12-06 15:52:52 -0600574 # Set up rootwrap.conf, pointing to $QUANTUM_CONF_DIR/rootwrap.d
Nachi Uenoeb1aa3d2012-12-06 11:55:29 -0800575 sudo cp -p $QUANTUM_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE
576 sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE
577 sudo chown root:root $Q_RR_CONF_FILE
578 sudo chmod 0644 $Q_RR_CONF_FILE
579 # Specify rootwrap.conf as first parameter to quantum-rootwrap
580 ROOTWRAP_SUDOER_CMD="$QUANTUM_ROOTWRAP $Q_RR_CONF_FILE *"
581
582 # Set up the rootwrap sudoers for quantum
583 TEMPFILE=`mktemp`
584 echo "$USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE
585 chmod 0440 $TEMPFILE
586 sudo chown root:root $TEMPFILE
587 sudo mv $TEMPFILE /etc/sudoers.d/quantum-rootwrap
Gary Kotton98e18e92013-01-28 14:26:56 +0000588
589 # Update the root_helper
590 iniset $QUANTUM_CONF AGENT root_helper "$Q_RR_COMMAND"
Nachi Uenoeb1aa3d2012-12-06 11:55:29 -0800591}
592
Salvatore Orlandod6767d02012-08-31 04:55:20 -0700593# Configures keystone integration for quantum service and agents
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900594function _quantum_setup_keystone() {
Salvatore Orlandod6767d02012-08-31 04:55:20 -0700595 local conf_file=$1
596 local section=$2
597 local use_auth_url=$3
598 if [[ -n $use_auth_url ]]; then
599 iniset $conf_file $section auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_AUTH_HOST:$KEYSTONE_AUTH_PORT/v2.0"
600 else
601 iniset $conf_file $section auth_host $KEYSTONE_SERVICE_HOST
602 iniset $conf_file $section auth_port $KEYSTONE_AUTH_PORT
603 iniset $conf_file $section auth_protocol $KEYSTONE_SERVICE_PROTOCOL
604 fi
605 iniset $conf_file $section admin_tenant_name $SERVICE_TENANT_NAME
606 iniset $conf_file $section admin_user $Q_ADMIN_USERNAME
607 iniset $conf_file $section admin_password $SERVICE_PASSWORD
Akihiro MOTOKI5e3deb62012-12-11 17:09:02 +0900608 iniset $conf_file $section signing_dir $QUANTUM_AUTH_CACHE_DIR
609 # Create cache dir
610 sudo mkdir -p $QUANTUM_AUTH_CACHE_DIR
Attila Fazekas91b8d132013-01-06 22:40:09 +0100611 sudo chown $STACK_USER $QUANTUM_AUTH_CACHE_DIR
Vishvananda Ishaya23431f32012-12-12 15:57:33 -0800612 rm -f $QUANTUM_AUTH_CACHE_DIR/*
Salvatore Orlandod6767d02012-08-31 04:55:20 -0700613}
614
Akihiro MOTOKI712feb62013-02-11 23:45:19 +0900615function _quantum_commentout_keystone_authtoken() {
616 local conf_file=$1
617 local section=$2
618
619 inicomment $conf_file $section auth_host
620 inicomment $conf_file $section auth_port
621 inicomment $conf_file $section auth_protocol
622 inicomment $conf_file $section auth_url
623
624 inicomment $conf_file $section admin_tenant_name
625 inicomment $conf_file $section admin_user
626 inicomment $conf_file $section admin_password
627 inicomment $conf_file $section signing_dir
628}
629
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900630function _quantum_setup_interface_driver() {
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900631 quantum_plugin_setup_interface_driver $1
Yoshihiro Kaneko602cf9b2012-07-23 06:27:36 +0000632}
633
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900634# Functions for Quantum Exercises
635#--------------------------------
636
637function delete_probe() {
638 local from_net="$1"
639 net_id=`_get_net_id $from_net`
640 probe_id=`quantum-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-list -c id -c network_id | grep $net_id | awk '{print $2}'`
641 quantum-debug --os-tenant-name admin --os-username admin probe-delete $probe_id
642}
643
644function setup_quantum_debug() {
645 if [[ "$Q_USE_DEBUG_COMMAND" == "True" ]]; then
646 public_net_id=`_get_net_id $PUBLIC_NETWORK_NAME`
647 quantum-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create $public_net_id
648 private_net_id=`_get_net_id $PRIVATE_NETWORK_NAME`
649 quantum-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create $private_net_id
Yoshihiro Kaneko602cf9b2012-07-23 06:27:36 +0000650 fi
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900651}
652
653function teardown_quantum_debug() {
654 delete_probe $PUBLIC_NETWORK_NAME
655 delete_probe $PRIVATE_NETWORK_NAME
Yoshihiro Kaneko602cf9b2012-07-23 06:27:36 +0000656}
657
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700658function _get_net_id() {
659 quantum --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD net-list | grep $1 | awk '{print $2}'
660}
661
662function _get_probe_cmd_prefix() {
663 local from_net="$1"
664 net_id=`_get_net_id $from_net`
665 probe_id=`quantum-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-list -c id -c network_id | grep $net_id | awk '{print $2}' | head -n 1`
Nachi Ueno8bc21f62012-11-19 22:04:28 -0800666 echo "$Q_RR_COMMAND ip netns exec qprobe-$probe_id"
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700667}
668
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700669function _ping_check_quantum() {
670 local from_net=$1
671 local ip=$2
672 local timeout_sec=$3
673 local expected=${4:-"True"}
674 local check_command=""
675 probe_cmd=`_get_probe_cmd_prefix $from_net`
676 if [[ "$expected" = "True" ]]; then
Nachi Ueno8bc21f62012-11-19 22:04:28 -0800677 check_command="while ! $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700678 else
Nachi Ueno8bc21f62012-11-19 22:04:28 -0800679 check_command="while $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700680 fi
681 if ! timeout $timeout_sec sh -c "$check_command"; then
682 if [[ "$expected" = "True" ]]; then
Nachi Ueno07115eb2013-02-26 12:38:18 -0800683 die $LINENO "[Fail] Couldn't ping server"
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700684 else
Nachi Ueno07115eb2013-02-26 12:38:18 -0800685 die $LINENO "[Fail] Could ping server"
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700686 fi
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700687 fi
688}
689
690# ssh check
691function _ssh_check_quantum() {
692 local from_net=$1
693 local key_file=$2
694 local ip=$3
695 local user=$4
696 local timeout_sec=$5
697 local probe_cmd = ""
698 probe_cmd=`_get_probe_cmd_prefix $from_net`
699 if ! timeout $timeout_sec sh -c "while ! $probe_cmd ssh -o StrictHostKeyChecking=no -i $key_file ${user}@$ip echo success ; do sleep 1; done"; then
Nachi Ueno07115eb2013-02-26 12:38:18 -0800700 die $LINENO "server didn't become ssh-able!"
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700701 fi
702}
703
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900704# Quantum 3rd party programs
705#---------------------------
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900706# please refer to lib/quantum_thirdparty/README.md for details
707QUANTUM_THIRD_PARTIES=""
708for f in $TOP_DIR/lib/quantum_thirdparty/*; do
709 third_party=$(basename $f)
710 if is_service_enabled $third_party; then
711 source $TOP_DIR/lib/quantum_thirdparty/$third_party
712 QUANTUM_THIRD_PARTIES="$QUANTUM_THIRD_PARTIES,$third_party"
713 fi
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900714done
715
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900716function _quantum_third_party_do() {
717 for third_party in ${QUANTUM_THIRD_PARTIES//,/ }; do
718 ${1}_${third_party}
719 done
720}
721
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900722# configure_quantum_third_party() - Set config files, create data dirs, etc
723function configure_quantum_third_party() {
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900724 _quantum_third_party_do configure
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700725}
726
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900727# init_quantum_third_party() - Initialize databases, etc.
728function init_quantum_third_party() {
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900729 _quantum_third_party_do init
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700730}
731
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900732# install_quantum_third_party() - Collect source and prepare
733function install_quantum_third_party() {
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900734 _quantum_third_party_do install
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900735}
736
737# start_quantum_third_party() - Start running processes, including screen
738function start_quantum_third_party() {
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900739 _quantum_third_party_do start
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900740}
741
742# stop_quantum_third_party - Stop running processes (non-screen)
743function stop_quantum_third_party() {
Isaku Yamahata0dd34df2012-12-28 13:15:31 +0900744 _quantum_third_party_do stop
Akihiro MOTOKI66afb472012-12-21 15:34:13 +0900745}
746
747
Salvatore Orlandod6767d02012-08-31 04:55:20 -0700748# Restore xtrace
749$XTRACE