Salvatore Orlando | d6767d0 | 2012-08-31 04:55:20 -0700 | [diff] [blame] | 1 | # lib/quantum |
| 2 | # functions - funstions specific to quantum |
| 3 | |
| 4 | # Save trace setting |
| 5 | XTRACE=$(set +o | grep xtrace) |
| 6 | set +o xtrace |
| 7 | |
Nachi Ueno | 5db5bfa | 2012-10-29 11:25:29 -0700 | [diff] [blame] | 8 | export QUANTUM_TEST_CONFIG_FILE=${QUANTUM_TEST_CONFIG_FILE:-"/etc/quantum/debug.ini"} |
| 9 | |
Salvatore Orlando | d6767d0 | 2012-08-31 04:55:20 -0700 | [diff] [blame] | 10 | # Configures keystone integration for quantum service and agents |
| 11 | function 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 | |
| 27 | function 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 Kaneko | 602cf9b | 2012-07-23 06:27:36 +0000 | [diff] [blame] | 38 | function 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 | |
| 54 | function is_quantum_ovs_base_plugin() { |
Dean Troyer | 5a4148d | 2012-10-23 15:47:01 -0500 | [diff] [blame] | 55 | local plugin=$1 |
Yoshihiro Kaneko | 602cf9b | 2012-07-23 06:27:36 +0000 | [diff] [blame] | 56 | if [[ ",openvswitch,ryu," =~ ,${plugin}, ]]; then |
| 57 | return 0 |
| 58 | fi |
| 59 | return 1 |
| 60 | } |
| 61 | |
Nachi Ueno | 5db5bfa | 2012-10-29 11:25:29 -0700 | [diff] [blame] | 62 | function _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 | |
| 66 | function _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 | |
| 73 | function 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 | |
| 80 | function _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 |
| 103 | function _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 | |
| 117 | function 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 | |
| 124 | function teardown_quantum() { |
| 125 | delete_probe $PUBLIC_NETWORK_NAME |
| 126 | delete_probe $PRIVATE_NETWORK_NAME |
| 127 | } |
| 128 | |
Salvatore Orlando | d6767d0 | 2012-08-31 04:55:20 -0700 | [diff] [blame] | 129 | # Restore xtrace |
| 130 | $XTRACE |