blob: 14a3a4ad5ef230ceabe3b2f64506b546b688b1cc [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 Ueno8bc21f62012-11-19 22:04:28 -08008QUANTUM_DIR=$DEST/quantum
Nachi Ueno5db5bfa2012-10-29 11:25:29 -07009export QUANTUM_TEST_CONFIG_FILE=${QUANTUM_TEST_CONFIG_FILE:-"/etc/quantum/debug.ini"}
Gary Kotton9343df12012-11-28 10:05:53 +000010QUANTUM_AUTH_CACHE_DIR=${QUANTUM_AUTH_CACHE_DIR:-/var/cache/quantum}
Nachi Ueno5db5bfa2012-10-29 11:25:29 -070011
Nachi Ueno8bc21f62012-11-19 22:04:28 -080012if is_service_enabled quantum; then
13 Q_CONF_FILE=/etc/quantum/quantum.conf
14 Q_RR_CONF_FILE=/etc/quantum/rootwrap.conf
15 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
16 Q_RR_COMMAND="sudo"
17 else
18 Q_RR_COMMAND="sudo $QUANTUM_DIR/bin/quantum-rootwrap $Q_RR_CONF_FILE"
19 fi
20fi
21
Salvatore Orlandod6767d02012-08-31 04:55:20 -070022# Configures keystone integration for quantum service and agents
23function quantum_setup_keystone() {
24 local conf_file=$1
25 local section=$2
26 local use_auth_url=$3
27 if [[ -n $use_auth_url ]]; then
28 iniset $conf_file $section auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_AUTH_HOST:$KEYSTONE_AUTH_PORT/v2.0"
29 else
30 iniset $conf_file $section auth_host $KEYSTONE_SERVICE_HOST
31 iniset $conf_file $section auth_port $KEYSTONE_AUTH_PORT
32 iniset $conf_file $section auth_protocol $KEYSTONE_SERVICE_PROTOCOL
33 fi
34 iniset $conf_file $section admin_tenant_name $SERVICE_TENANT_NAME
35 iniset $conf_file $section admin_user $Q_ADMIN_USERNAME
36 iniset $conf_file $section admin_password $SERVICE_PASSWORD
Gary Kotton9343df12012-11-28 10:05:53 +000037 if [[ "$KEYSTONE_TOKEN_FORMAT" == "PKI" ]]; then
38 iniset $conf_file $section signing_dir $QUANTUM_AUTH_CACHE_DIR
39 # Create cache dir
40 sudo mkdir -p $QUANTUM_AUTH_CACHE_DIR
41 sudo chown `whoami` $QUANTUM_AUTH_CACHE_DIR
42 fi
Salvatore Orlandod6767d02012-08-31 04:55:20 -070043}
44
45function quantum_setup_ovs_bridge() {
46 local bridge=$1
47 for PORT in `sudo ovs-vsctl --no-wait list-ports $bridge`; do
48 if [[ "$PORT" =~ tap* ]]; then echo `sudo ip link delete $PORT` > /dev/null; fi
49 sudo ovs-vsctl --no-wait del-port $bridge $PORT
50 done
51 sudo ovs-vsctl --no-wait -- --if-exists del-br $bridge
52 sudo ovs-vsctl --no-wait add-br $bridge
53 sudo ovs-vsctl --no-wait br-set-external-id $bridge bridge-id $bridge
54}
55
Yoshihiro Kaneko602cf9b2012-07-23 06:27:36 +000056function quantum_setup_external_bridge() {
57 local bridge=$1
58 # Create it if it does not exist
59 sudo ovs-vsctl --no-wait -- --may-exist add-br $bridge
60 # remove internal ports
61 for PORT in `sudo ovs-vsctl --no-wait list-ports $bridge`; do
62 TYPE=$(sudo ovs-vsctl get interface $PORT type)
63 if [[ "$TYPE" == "internal" ]]; then
64 echo `sudo ip link delete $PORT` > /dev/null
65 sudo ovs-vsctl --no-wait del-port $bridge $PORT
66 fi
67 done
68 # ensure no IP is configured on the public bridge
69 sudo ip addr flush dev $bridge
70}
71
72function is_quantum_ovs_base_plugin() {
Dean Troyer5a4148d2012-10-23 15:47:01 -050073 local plugin=$1
Yoshihiro Kaneko602cf9b2012-07-23 06:27:36 +000074 if [[ ",openvswitch,ryu," =~ ,${plugin}, ]]; then
75 return 0
76 fi
77 return 1
78}
79
Nachi Ueno5db5bfa2012-10-29 11:25:29 -070080function _get_net_id() {
81 quantum --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD net-list | grep $1 | awk '{print $2}'
82}
83
84function _get_probe_cmd_prefix() {
85 local from_net="$1"
86 net_id=`_get_net_id $from_net`
87 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 -080088 echo "$Q_RR_COMMAND ip netns exec qprobe-$probe_id"
Nachi Ueno5db5bfa2012-10-29 11:25:29 -070089}
90
91function delete_probe() {
92 local from_net="$1"
93 net_id=`_get_net_id $from_net`
94 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}'`
95 quantum-debug --os-tenant-name admin --os-username admin probe-delete $probe_id
96}
97
98function _ping_check_quantum() {
99 local from_net=$1
100 local ip=$2
101 local timeout_sec=$3
102 local expected=${4:-"True"}
103 local check_command=""
104 probe_cmd=`_get_probe_cmd_prefix $from_net`
105 if [[ "$expected" = "True" ]]; then
Nachi Ueno8bc21f62012-11-19 22:04:28 -0800106 check_command="while ! $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700107 else
Nachi Ueno8bc21f62012-11-19 22:04:28 -0800108 check_command="while $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done"
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700109 fi
110 if ! timeout $timeout_sec sh -c "$check_command"; then
111 if [[ "$expected" = "True" ]]; then
112 echo "[Fail] Couldn't ping server"
113 else
114 echo "[Fail] Could ping server"
115 fi
116 exit 1
117 fi
118}
119
120# ssh check
121function _ssh_check_quantum() {
122 local from_net=$1
123 local key_file=$2
124 local ip=$3
125 local user=$4
126 local timeout_sec=$5
127 local probe_cmd = ""
128 probe_cmd=`_get_probe_cmd_prefix $from_net`
129 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
130 echo "server didn't become ssh-able!"
131 exit 1
132 fi
133}
134
135function setup_quantum() {
136 public_net_id=`_get_net_id $PUBLIC_NETWORK_NAME`
137 quantum-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create $public_net_id
138 private_net_id=`_get_net_id $PRIVATE_NETWORK_NAME`
139 quantum-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create $private_net_id
140}
141
142function teardown_quantum() {
143 delete_probe $PUBLIC_NETWORK_NAME
144 delete_probe $PRIVATE_NETWORK_NAME
145}
146
Salvatore Orlandod6767d02012-08-31 04:55:20 -0700147# Restore xtrace
148$XTRACE