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 | 8bc21f6 | 2012-11-19 22:04:28 -0800 | [diff] [blame] | 8 | QUANTUM_DIR=$DEST/quantum |
Nachi Ueno | 5db5bfa | 2012-10-29 11:25:29 -0700 | [diff] [blame] | 9 | export QUANTUM_TEST_CONFIG_FILE=${QUANTUM_TEST_CONFIG_FILE:-"/etc/quantum/debug.ini"} |
Gary Kotton | 9343df1 | 2012-11-28 10:05:53 +0000 | [diff] [blame] | 10 | QUANTUM_AUTH_CACHE_DIR=${QUANTUM_AUTH_CACHE_DIR:-/var/cache/quantum} |
Nachi Ueno | 5db5bfa | 2012-10-29 11:25:29 -0700 | [diff] [blame] | 11 | |
Nachi Ueno | 8bc21f6 | 2012-11-19 22:04:28 -0800 | [diff] [blame] | 12 | if 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 |
| 20 | fi |
| 21 | |
Salvatore Orlando | d6767d0 | 2012-08-31 04:55:20 -0700 | [diff] [blame] | 22 | # Configures keystone integration for quantum service and agents |
| 23 | function 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 Kotton | 9343df1 | 2012-11-28 10:05:53 +0000 | [diff] [blame] | 37 | 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 Orlando | d6767d0 | 2012-08-31 04:55:20 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | function 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 Kaneko | 602cf9b | 2012-07-23 06:27:36 +0000 | [diff] [blame] | 56 | function 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 | |
| 72 | function is_quantum_ovs_base_plugin() { |
Dean Troyer | 5a4148d | 2012-10-23 15:47:01 -0500 | [diff] [blame] | 73 | local plugin=$1 |
Yoshihiro Kaneko | 602cf9b | 2012-07-23 06:27:36 +0000 | [diff] [blame] | 74 | if [[ ",openvswitch,ryu," =~ ,${plugin}, ]]; then |
| 75 | return 0 |
| 76 | fi |
| 77 | return 1 |
| 78 | } |
| 79 | |
Nachi Ueno | 5db5bfa | 2012-10-29 11:25:29 -0700 | [diff] [blame] | 80 | function _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 | |
| 84 | function _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 Ueno | 8bc21f6 | 2012-11-19 22:04:28 -0800 | [diff] [blame] | 88 | echo "$Q_RR_COMMAND ip netns exec qprobe-$probe_id" |
Nachi Ueno | 5db5bfa | 2012-10-29 11:25:29 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | function 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 | |
| 98 | function _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 Ueno | 8bc21f6 | 2012-11-19 22:04:28 -0800 | [diff] [blame] | 106 | check_command="while ! $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done" |
Nachi Ueno | 5db5bfa | 2012-10-29 11:25:29 -0700 | [diff] [blame] | 107 | else |
Nachi Ueno | 8bc21f6 | 2012-11-19 22:04:28 -0800 | [diff] [blame] | 108 | check_command="while $probe_cmd ping -w 1 -c 1 $ip; do sleep 1; done" |
Nachi Ueno | 5db5bfa | 2012-10-29 11:25:29 -0700 | [diff] [blame] | 109 | 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 |
| 121 | function _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 | |
| 135 | function 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 | |
| 142 | function teardown_quantum() { |
| 143 | delete_probe $PUBLIC_NETWORK_NAME |
| 144 | delete_probe $PRIVATE_NETWORK_NAME |
| 145 | } |
| 146 | |
Salvatore Orlando | d6767d0 | 2012-08-31 04:55:20 -0700 | [diff] [blame] | 147 | # Restore xtrace |
| 148 | $XTRACE |