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