blob: 373d5217f6b19508fa8ac9d1e3de784ae8a4db94 [file] [log] [blame]
Salvatore Orlandod6767d02012-08-31 04:55:20 -07001# lib/quantum
2# functions - funstions specific to quantum
3
4# Save trace setting
5XTRACE=$(set +o | grep xtrace)
6set +o xtrace
7
Nachi Ueno5db5bfa2012-10-29 11:25:29 -07008export QUANTUM_TEST_CONFIG_FILE=${QUANTUM_TEST_CONFIG_FILE:-"/etc/quantum/debug.ini"}
Gary Kotton9343df12012-11-28 10:05:53 +00009QUANTUM_AUTH_CACHE_DIR=${QUANTUM_AUTH_CACHE_DIR:-/var/cache/quantum}
Nachi Ueno5db5bfa2012-10-29 11:25:29 -070010
Salvatore Orlandod6767d02012-08-31 04:55:20 -070011# Configures keystone integration for quantum service and agents
12function quantum_setup_keystone() {
13 local conf_file=$1
14 local section=$2
15 local use_auth_url=$3
16 if [[ -n $use_auth_url ]]; then
17 iniset $conf_file $section auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_AUTH_HOST:$KEYSTONE_AUTH_PORT/v2.0"
18 else
19 iniset $conf_file $section auth_host $KEYSTONE_SERVICE_HOST
20 iniset $conf_file $section auth_port $KEYSTONE_AUTH_PORT
21 iniset $conf_file $section auth_protocol $KEYSTONE_SERVICE_PROTOCOL
22 fi
23 iniset $conf_file $section admin_tenant_name $SERVICE_TENANT_NAME
24 iniset $conf_file $section admin_user $Q_ADMIN_USERNAME
25 iniset $conf_file $section admin_password $SERVICE_PASSWORD
Gary Kotton9343df12012-11-28 10:05:53 +000026 if [[ "$KEYSTONE_TOKEN_FORMAT" == "PKI" ]]; then
27 iniset $conf_file $section signing_dir $QUANTUM_AUTH_CACHE_DIR
28 # Create cache dir
29 sudo mkdir -p $QUANTUM_AUTH_CACHE_DIR
30 sudo chown `whoami` $QUANTUM_AUTH_CACHE_DIR
31 fi
Salvatore Orlandod6767d02012-08-31 04:55:20 -070032}
33
34function quantum_setup_ovs_bridge() {
35 local bridge=$1
36 for PORT in `sudo ovs-vsctl --no-wait list-ports $bridge`; do
37 if [[ "$PORT" =~ tap* ]]; then echo `sudo ip link delete $PORT` > /dev/null; fi
38 sudo ovs-vsctl --no-wait del-port $bridge $PORT
39 done
40 sudo ovs-vsctl --no-wait -- --if-exists del-br $bridge
41 sudo ovs-vsctl --no-wait add-br $bridge
42 sudo ovs-vsctl --no-wait br-set-external-id $bridge bridge-id $bridge
43}
44
Yoshihiro Kaneko602cf9b2012-07-23 06:27:36 +000045function quantum_setup_external_bridge() {
46 local bridge=$1
47 # Create it if it does not exist
48 sudo ovs-vsctl --no-wait -- --may-exist add-br $bridge
49 # remove internal ports
50 for PORT in `sudo ovs-vsctl --no-wait list-ports $bridge`; do
51 TYPE=$(sudo ovs-vsctl get interface $PORT type)
52 if [[ "$TYPE" == "internal" ]]; then
53 echo `sudo ip link delete $PORT` > /dev/null
54 sudo ovs-vsctl --no-wait del-port $bridge $PORT
55 fi
56 done
57 # ensure no IP is configured on the public bridge
58 sudo ip addr flush dev $bridge
59}
60
61function is_quantum_ovs_base_plugin() {
Dean Troyer5a4148d2012-10-23 15:47:01 -050062 local plugin=$1
Yoshihiro Kaneko602cf9b2012-07-23 06:27:36 +000063 if [[ ",openvswitch,ryu," =~ ,${plugin}, ]]; then
64 return 0
65 fi
66 return 1
67}
68
Nachi Ueno5db5bfa2012-10-29 11:25:29 -070069function _get_net_id() {
70 quantum --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD net-list | grep $1 | awk '{print $2}'
71}
72
73function _get_probe_cmd_prefix() {
74 local from_net="$1"
75 net_id=`_get_net_id $from_net`
76 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`
77 echo "sudo ip netns exec qprobe-$probe_id"
78}
79
80function delete_probe() {
81 local from_net="$1"
82 net_id=`_get_net_id $from_net`
83 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}'`
84 quantum-debug --os-tenant-name admin --os-username admin probe-delete $probe_id
85}
86
87function _ping_check_quantum() {
88 local from_net=$1
89 local ip=$2
90 local timeout_sec=$3
91 local expected=${4:-"True"}
92 local check_command=""
93 probe_cmd=`_get_probe_cmd_prefix $from_net`
94 if [[ "$expected" = "True" ]]; then
95 check_command="while ! $probe_cmd ping -c1 -w1 $ip; do sleep 1; done"
96 else
97 check_command="while $probe_cmd ping -c1 -w1 $ip; do sleep 1; done"
98 fi
99 if ! timeout $timeout_sec sh -c "$check_command"; then
100 if [[ "$expected" = "True" ]]; then
101 echo "[Fail] Couldn't ping server"
102 else
103 echo "[Fail] Could ping server"
104 fi
105 exit 1
106 fi
107}
108
109# ssh check
110function _ssh_check_quantum() {
111 local from_net=$1
112 local key_file=$2
113 local ip=$3
114 local user=$4
115 local timeout_sec=$5
116 local probe_cmd = ""
117 probe_cmd=`_get_probe_cmd_prefix $from_net`
118 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
119 echo "server didn't become ssh-able!"
120 exit 1
121 fi
122}
123
124function setup_quantum() {
125 public_net_id=`_get_net_id $PUBLIC_NETWORK_NAME`
126 quantum-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create $public_net_id
127 private_net_id=`_get_net_id $PRIVATE_NETWORK_NAME`
128 quantum-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create $private_net_id
129}
130
131function teardown_quantum() {
132 delete_probe $PUBLIC_NETWORK_NAME
133 delete_probe $PRIVATE_NETWORK_NAME
134}
135
Salvatore Orlandod6767d02012-08-31 04:55:20 -0700136# Restore xtrace
137$XTRACE