Add customization in maintenance branch
PROD-27329

Change-Id: I55b06df674309ad501e2abd9585d8e428077eb8e
diff --git a/configure.sh b/configure.sh
index f0cfe27..ae4a816 100755
--- a/configure.sh
+++ b/configure.sh
@@ -20,14 +20,42 @@
 
 rally_configuration () {
   rally_version=$(rally version 2>&1)
-  # will be removed when we switch to Rally 0.9.2+
   if [ "$rally_version" == "0.9.0" ] || [ "$rally_version" == "0.9.1" ]; then
-    pip install ansible==2.3.2.0
-    sed -i '270s/,/}#,/g' /usr/local/lib/python2.7/dist-packages/rally/plugins/openstack/wrappers/network.py
+    echo "Please use rally 0.10.1"
+    exit
+  fi
+  if [ "$PROXY" != "offline" ]; then
+    if [ -n "${PROXY}" ]; then
+      export http_proxy=$PROXY
+      export https_proxy=$PROXY
+    fi
+    pip install --force-reinstall python-glanceclient==2.11
+    apt-get update; apt-get install -y iputils-ping curl wget
+    unset http_proxy
+    unset https_proxy
   fi
   sub_name=`date "+%H_%M_%S"`
+  # remove dashes from rally user passwords to fit into 32 char limit
+  sed -i 's/uuid4())/uuid4()).replace("-","")/g' /usr/local/lib/python2.7/dist-packages/rally/plugins/openstack/scenarios/keystone/utils.py
+  sed -i 's/uuid4())/uuid4()).replace("-","")/g' /usr/local/lib/python2.7/dist-packages/rally/plugins/openstack/context/keystone/users.py
   rally deployment create --fromenv --name=tempest_$sub_name
   rally deployment config
+  echo "[openstack]" >> /etc/rally/rally.conf
+  echo "pre_newton_neutron=True" >> /etc/rally/rally.conf
+}
+
+update_cacerts () {
+  # configuring certificates file
+  if [ -z ${OS_CACERT+x} ]; then
+    echo '# No OS_CACERT is set, update of crt file skipped'
+  else
+    echo '# Adding custom certificates'
+    ca=( $(find ${1} -name cacert.pem) )
+    for crt in ${ca[@]}; do
+      cat ${OS_CACERT} >>${crt}
+      echo '-> ${crt}'
+    done
+  fi
 }
 
 tempest_configuration () {
@@ -41,63 +69,99 @@
     rally verify create-verifier --name tempest_verifier_$sub_name --type tempest --source $TEMPEST_REPO --system-wide --version $tempest_version
     rally verify add-verifier-ext --source /var/lib/telemetry-tempest-plugin
     rally verify add-verifier-ext --source /var/lib/heat-tempest-plugin
+    update_cacerts "/usr/local/lib"
   else
     if [ -n "${PROXY}" ]; then
       export https_proxy=$PROXY
     fi
     rally verify create-verifier --name tempest_verifier_$sub_name --type tempest --source $TEMPEST_REPO --version $tempest_version
-    #rally verify add-verifier-ext --source https://github.com/openstack/telemetry-tempest-plugin
-    #rally verify add-verifier-ext --source https://github.com/openstack/heat-tempest-plugin
-    rally verify add-verifier-ext --source https://github.com/openstack/designate-tempest-plugin --version 0.5.0
+    #rally verify add-verifier-ext --version 7a4bff728fbd8629ec211669264ab645aa921e2b --source https://github.com/openstack/telemetry-tempest-plugin
+    rally verify add-verifier-ext --version mcp/ocata --source https://gerrit.mcp.mirantis.com/packaging/sources/heat-tempest-plugin
     pip install --force-reinstall python-cinderclient==3.2.0
     unset https_proxy
+    update_cacerts "/home/rally/.rally/verification"
   fi
+  # set password length to 32
+  data_utils_path=`find /home/rally/.rally/verification/ -name data_utils.py`
+  sed -i 's/length=15/length=32/g' $data_utils_path
+
   # supress tempest.conf display in console
   #rally verify configure-verifier --show
 }
 
-quick_configuration () {
+glance_image() {
 current_path=$(pwd)
-# Remove this if you use local gerrit cvp-configuration repo
-if [ "$PROXY" == "offline" ]; then
-  current_path=/var/lib
-fi
-#image
-glance image-list | grep "\btestvm\b" 2>&1 >/dev/null || {
-    if [ -n "${PROXY}" ] && [ "$PROXY" -ne "offline" ]; then
+# fetch image with exact name: testvm
+IMAGE_NAME2=testvm
+IMAGE_REF2=$(glance image-list | grep "\b${IMAGE_NAME2}\b" | awk '{print $2}')
+if [ "${IMAGE_REF2}" == "" ]; then
+  if [ "$PROXY" != "offline" ]; then
+    if [ -n "${PROXY}" ]; then
       export http_proxy=$PROXY
+      export https_proxy=$PROXY
     fi
     ls $current_path/cvp-configuration/cirros-0.3.4-x86_64-disk.img || wget http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img -O $current_path/cvp-configuration/cirros-0.3.4-x86_64-disk.img
     unset http_proxy
+    unset https_proxy
+  fi
+  if [ -e $current_path/cvp-configuration/cirros-0.3.4-x86_64-disk.img ]; then
     echo "MD5 should be ee1eca47dc88f4879d8a229cc70a07c6"
     md5sum $current_path/cvp-configuration/cirros-0.3.4-x86_64-disk.img
-    glance image-create --name=testvm --visibility=public --container-format=bare --disk-format=qcow2 < $current_path/cvp-configuration/cirros-0.3.4-x86_64-disk.img
+    glance image-create --name=${IMAGE_NAME2} --visibility=public --container-format=bare --disk-format=qcow2 < $current_path/cvp-configuration/cirros-0.3.4-x86_64-disk.img
+    IMAGE_REF2=$(glance image-list | grep "\b${IMAGE_NAME2}\b" | awk '{print $2}')
+  else
+    echo "Cirros image was not downloaded! Some tests may fail"
+    IMAGE_REF2=""
+  fi
+fi
+sed -i 's/${IMAGE_REF2}/'$IMAGE_REF2'/g' $current_path/cvp-configuration/tempest/tempest_ext.conf
+sed -i 's/${IMAGE_NAME2}/'$IMAGE_NAME2'/g' $current_path/cvp-configuration/tempest/tempest_ext.conf
 }
-IMAGE_REF2=$(glance image-list | grep 'testvm' | awk '{print $2}')
+
+quick_configuration () {
+current_path=$(pwd)
+#image
+glance_image
 #flavor for rally
 nova flavor-list | grep tiny 2>&1 >/dev/null || {
     echo "Let's create m1.tiny flavor"
     nova flavor-create --is-public true m1.tiny auto 128 1 1
 }
 #shared fixed network
-shared_count=`neutron net-list -c name -c shared | grep True | wc -l`
-if [ $shared_count -gt 1 ]; then
-  echo "TOO MANY SHARED NETWORKS! Script will choose just 1 random"
-fi
+shared_count=`neutron net-list -c name -c shared | grep True | grep "fixed-net" | wc -l`
 if [ $shared_count -eq 0 ]; then
   echo "Let's create shared fixed net"
   neutron net-create --shared fixed-net
-  neutron subnet-create --name fixed-subnet --gateway 192.168.0.1 --allocation-pool start=192.168.0.2,end=192.168.0.254 --ip-version 4 fixed-net 192.168.0.0/24
+  FIXED_NET_ID=$(neutron net-list -c id -c name -c shared | grep "fixed-net" | grep True | awk '{print $2}' | tail -n 1)
+  neutron subnet-create --name fixed-subnet --gateway 192.168.0.1 --allocation-pool start=192.168.0.2,end=192.168.0.254 --ip-version 4 $FIXED_NET_ID 192.168.0.0/24
 fi
-FIXED_NET=$(neutron net-list -c name -c shared | grep True | awk '{print $2}' | tail -n 1)
-echo "Fixed net is: $FIXED_NET"
-#Updating of tempest_full.conf file is skipped/deprecated
-sed -i 's/${IMAGE_REF2}/'$IMAGE_REF2'/g' $current_path/cvp-configuration/tempest/tempest_ext.conf
+fixed_count=`neutron net-list | grep "fixed-net" | wc -l`
+if [ $fixed_count -gt 1 ]; then
+  echo "TOO MANY NETWORKS WITH fixed-net NAME! This may affect tests. Please review your network list."
+fi
+# public/floating net
+PUBLIC_NET=$(neutron net-list -c name -c router:external | grep True | awk '{print $2}' | tail -n 1)
+FIXED_NET=$(neutron net-list -c name -c shared | grep "fixed-net" | grep True | awk '{print $2}' | tail -n 1)
+FIXED_NET_ID=$(neutron net-list -c id -c name -c shared | grep "fixed-net" | grep True | awk '{print $2}' | tail -n 1)
+FIXED_SUBNET_ID=$(neutron net-show $FIXED_NET_ID -c subnets | grep subnets | awk '{print $4}')
+FIXED_SUBNET_NAME=$(neutron subnet-show -c name $FIXED_SUBNET_ID | grep name | awk '{print $4}')
+echo "Public net name is $PUBLIC_NET"
+echo "Fixed net name is $FIXED_NET, id is $FIXED_NET_ID"
+echo "Fixed subnet is: $FIXED_SUBNET_ID, name: $FIXED_SUBNET_NAME"
 sed -i 's/${FIXED_NET}/'$FIXED_NET'/g' $current_path/cvp-configuration/tempest/tempest_ext.conf
+sed -i 's/${FIXED_SUBNET_NAME}/'$FIXED_SUBNET_NAME'/g' $current_path/cvp-configuration/tempest/tempest_ext.conf
+sed -i 's/${OS_USERNAME}/'$OS_USERNAME'/g' $current_path/cvp-configuration/tempest/tempest_ext.conf
+sed -i 's/${OS_TENANT_NAME}/'$OS_TENANT_NAME'/g' $current_path/cvp-configuration/tempest/tempest_ext.conf
+sed -i 's/${OS_REGION_NAME}/'$OS_REGION_NAME'/g' $current_path/cvp-configuration/tempest/tempest_ext.conf
+sed -i 's|${OS_AUTH_URL}|'"${OS_AUTH_URL}"'|g' $current_path/cvp-configuration/tempest/tempest_ext.conf
+sed -i 's|${OS_PASSWORD}|'"${OS_PASSWORD}"'|g' $current_path/cvp-configuration/tempest/tempest_ext.conf
+sed -i 's|${PUBLIC_NET}|'"${PUBLIC_NET}"'|g' $current_path/cvp-configuration/tempest/tempest_ext.conf
 sed -i 's/publicURL/'$TEMPEST_ENDPOINT_TYPE'/g' $current_path/cvp-configuration/tempest/tempest_ext.conf
 #supress tempest.conf display in console
 #cat $current_path/cvp-configuration/tempest/tempest_ext.conf
 cp $current_path/cvp-configuration/tempest/boot_config_none_env.yaml /home/rally/boot_config_none_env.yaml
+cp $current_path/cvp-configuration/cleanup.sh /home/rally/cleanup.sh
+chmod 755 /home/rally/cleanup.sh
 }
 
 if [ "$1" == "reconfigure" ]; then
@@ -110,16 +174,19 @@
 
 check_variables
 rally_configuration
+quick_configuration
 if [ -n "${TEMPEST_REPO}" ]; then
     tempest_configuration
-    quick_configuration
+    # If you do not have fip network, use this command
+    #cat $current_path/cvp-configuration/tempest/skip-list-fip-only.yaml >> $current_path/cvp-configuration/tempest/skip-list-queens.yaml
     # If Opencontrail is deployed, use this command
-    #cat $current_path/cvp-configuration/tempest/skip-list-oc4.yaml >> $current_path/cvp-configuration/tempest/skip-list-pike.yaml
+    #cat $current_path/cvp-configuration/tempest/skip-list-oc4.yaml >> $current_path/cvp-configuration/tempest/skip-list-queens.yaml
+    #cat $current_path/cvp-configuration/tempest/skip-list-heat.yaml >> $current_path/cvp-configuration/tempest/skip-list-queens.yaml
     rally verify configure-verifier --extend $current_path/cvp-configuration/tempest/tempest_ext.conf
     rally verify configure-verifier --show
     # If Barbican tempest plugin is installed, use this
-    # mkdir /etc/tempest
-    # rally verify configure-verifier --show | grep -v "rally.api" > /etc/tempest/tempest.conf
+    #mkdir /etc/tempest
+    #rally verify configure-verifier --show | grep -v "rally.api" > /etc/tempest/tempest.conf
     # Add 2 additional tempest tests (live migration to all nodes + ssh to all nodes)
     # TBD
     #cat tempest/test_extension.py >> repo/tempest/scenario/test_server_multinode.py