2 ##############################################################################
3 # Copyright (c) 2015 Ericsson AB, Huawei Technologies Co.,Ltd and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
11 # Perepare the environment to run yardstick ci
13 : ${DEPLOY_TYPE:='bm'} # Can be any of 'bm' (Bare Metal) or 'virt' (Virtual)
14 : ${INSTALLER_TYPE:='unknown'}
15 : ${NODE_NAME:='unknown'}
16 : ${EXTERNAL_NETWORK:='admin_floating_net'}
17 : ${USER_NAME:='ubuntu'}
18 : ${SSH_KEY:='/root/.ssh/id_rsa'}
19 : ${DEPLOY_SCENARIO:='unknown'}
21 # Extract network name from EXTERNAL_NETWORK
22 # e.g. EXTERNAL_NETWORK='ext-net;flat;192.168.0.2;192.168.0.253;192.168.0.1;192.168.0.0/24'
23 EXTERNAL_NETWORK=$(echo ${EXTERNAL_NETWORK} | cut -f1 -d \;)
24 export EXTERNAL_NETWORK
26 # Create openstack credentials
27 echo "INFO: Creating openstack credentials .."
28 mkdir -p /etc/yardstick
29 OPENRC=/etc/yardstick/openstack.creds
30 INSTALLERS=(apex compass fuel joid)
33 if [[ "${OS_AUTH_URL}" && "${OS_USERNAME}" && "${OS_PASSWORD}" && "${EXTERNAL_NETWORK}" ]];then
37 if [[ "${RC_VAR_EXIST}" = false && -f ${OPENRC} ]]; then
41 export EXTERNAL_NETWORK INSTALLER_TYPE DEPLOY_TYPE NODE_NAME
43 # Prepare a admin-rc file for StorPerf integration
44 "${YARDSTICK_REPO_DIR}"/tests/ci/prepare_storperf_admin-rc.sh
46 # copy Storperf related files to the deployment location
47 if [ "$INSTALLER_TYPE" == "compass" ]; then
48 . "${YARDSTICK_REPO_DIR}"/tests/ci/scp_storperf_files.sh
51 # Fetching id_rsa file from jump_server..."
52 verify_connectivity() {
54 echo "Verifying connectivity to $ip..."
55 for i in $(seq 0 10); do
56 if ping -c 1 -W 1 "${ip}" > /dev/null; then
57 echo "$ip is reachable!"
62 error "Can not talk to $ip."
65 ssh_options="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
66 if [ "$INSTALLER_TYPE" == "apex" ]; then
68 # check the connection
69 verify_connectivity "${INSTALLER_IP}"
71 pod_yaml="$YARDSTICK_REPO_DIR/etc/yardstick/nodes/apex_baremetal/pod.yaml"
73 # update "ip" according to the CI env
74 ssh -l root "${INSTALLER_IP}" -i ${SSH_KEY} ${ssh_options} \
75 "source /home/stack/stackrc && openstack server list -f yaml" > node_info
77 controller_ips=($(awk '/control/{getline; {print $2}}' < node_info | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}'))
78 compute_ips=($(awk '/compute/{getline; {print $2}}' < node_info | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}'))
80 # Get ODL's cluster default module-shard Leader IP in HA scenario
81 if [[ ${DEPLOY_SCENARIO} == os-odl-*-ha ]]; then
82 for ip in "${controller_ips[@]}";
84 if [[ "$odl_ip" ]]; then
87 for ((i=0; i<${#controller_ips[@]}; i++));
89 ODL_STATE=$(curl -s -u admin:admin -H "Accept: application/json" -H "Content-Type: application/json" \
90 "http://"${ip}":8081/jolokia/read/org.opendaylight.controller:Category=Shards,name=member-"${i}"-shard-default-operational,type=DistributedOperationalDatastore" \
91 | grep -o \"RaftState\"\:\"Leader\" | tr ":" "\n" | sed -n '2p' | sed 's/\"//g');
93 if [[ ${ODL_STATE} == "Leader" ]]; then
100 if [[ -z "$odl_ip" ]]; then
101 echo "ERROR: Opendaylight Leader IP is emtpy"
105 elif [[ ${DEPLOY_SCENARIO} == *"odl"* ]]; then
106 odl_ip=${controller_ips[0]}
109 if [[ ${controller_ips[0]} ]]; then
110 sed -i "s|ip1|${controller_ips[0]}|" "${pod_yaml}"
112 if [[ ${controller_ips[1]} ]]; then
113 sed -i "s|ip2|${controller_ips[1]}|" "${pod_yaml}"
115 if [[ ${controller_ips[2]} ]]; then
116 sed -i "s|ip3|${controller_ips[2]}|" "${pod_yaml}"
118 if [[ ${compute_ips[0]} ]]; then
119 sed -i "s|ip4|${compute_ips[0]}|" "${pod_yaml}"
121 if [[ ${compute_ips[1]} ]]; then
122 sed -i "s|ip5|${compute_ips[1]}|" "${pod_yaml}"
124 if [[ ${odl_ip} ]]; then
125 sed -i "s|ip6|${odl_ip}|" "${pod_yaml}"
129 # update 'key_filename' according to the CI env
130 sed -i "s|node_keyfile|${SSH_KEY}|" "${pod_yaml}"
133 if [ "$INSTALLER_TYPE" == "fuel" ]; then
135 # check the connection
136 verify_connectivity "${INSTALLER_IP}"
138 pod_yaml="$YARDSTICK_REPO_DIR/etc/yardstick/nodes/fuel_baremetal/pod.yaml"
140 # update "ip" according to the CI env
141 ssh -l ubuntu "${INSTALLER_IP}" -i ${SSH_KEY} ${ssh_options} \
142 "sudo salt -C 'ctl* or cmp* or odl01* or gtw*' grains.get fqdn_ip4 --out yaml">node_info
144 controller_ips=($(awk '/ctl/{getline; print $2}' < node_info))
145 compute_ips=($(awk '/cmp/{getline; print $2}' < node_info))
146 odl_ip=($(awk '/odl01/{getline; print $2}' < node_info))
147 gateway_ip=($(awk '/gtw/{getline; print $2}' < node_info))
149 if [[ ${controller_ips[0]} ]]; then
150 sed -i "s|ip1|${controller_ips[0]}|" "${pod_yaml}"
152 if [[ ${controller_ips[1]} ]]; then
153 sed -i "s|ip2|${controller_ips[1]}|" "${pod_yaml}"
155 if [[ ${controller_ips[2]} ]]; then
156 sed -i "s|ip3|${controller_ips[2]}|" "${pod_yaml}"
158 if [[ ${compute_ips[0]} ]]; then
159 sed -i "s|ip4|${compute_ips[0]}|" "${pod_yaml}"
161 if [[ ${compute_ips[1]} ]]; then
162 sed -i "s|ip5|${compute_ips[1]}|" "${pod_yaml}"
164 if [[ ${odl_ip[0]} ]]; then
165 sed -i "s|ip6|${odl_ip[0]}|" "${pod_yaml}"
167 if [[ ${gateway_ip[0]} ]]; then
168 sed -i "s|ip7|${gateway_ip[0]}|" "${pod_yaml}"
171 # update 'user' and 'key_filename' according to the CI env
172 sed -i "s|node_username|${USER_NAME}|;s|node_keyfile|${SSH_KEY}|" "${pod_yaml}"