Merge "Fix SC2059 for ShellCheck 0.4.4, printf formatting"
[releng/builder.git] / jjb / integration / common-functions.sh
index e2066b4153ce550c89515ef9fe8eec664e27d983..2c466d220a3f8c8052102af87620be5fc1e0396d 100644 (file)
@@ -121,16 +121,50 @@ function get_os_deploy() {
     local -r num_systems=${1:-$NUM_OPENSTACK_SYSTEM}
     case ${num_systems} in
     1)
-        OS_DEPLOY="1cmb-0ctl-0cmp"
+        OPENSTACK_TOPO="1cmb-0ctl-0cmp"
         ;;
     2)
-        OS_DEPLOY="1cmb-0ctl-1cmp"
+        OPENSTACK_TOPO="1cmb-0ctl-1cmp"
         ;;
     3|*)
-        OS_DEPLOY="0cmb-1ctl-2cmp"
+        OPENSTACK_TOPO="0cmb-1ctl-2cmp"
         ;;
     esac
-    export OS_DEPLOY
+    export OPENSTACK_TOPO
+}
+
+function get_test_suites() {
+
+    #let the caller pick the name of the variable we will assign the suites to
+    local __suite_list=$1
+
+    echo "Locating test plan to use..."
+    testplan_filepath="${WORKSPACE}/test/csit/testplans/${STREAMTESTPLAN}"
+    if [ ! -f "${testplan_filepath}" ]; then
+        testplan_filepath="${WORKSPACE}/test/csit/testplans/${TESTPLAN}"
+    fi
+
+    echo "Changing the testplan path..."
+    cat "${testplan_filepath}" | sed "s:integration:${WORKSPACE}:" > testplan.txt
+    cat testplan.txt
+
+    # Use the testplan if specific SUITES are not defined.
+    if [ -z "${SUITES}" ]; then
+        suite_list=`egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' testplan.txt | tr '\012' ' '`
+    else
+        suite_list=""
+        workpath="${WORKSPACE}/test/csit/suites"
+        for suite in ${SUITES}; do
+            fullsuite="${workpath}/${suite}"
+            if [ -z "${suite_list}" ]; then
+                suite_list+=${fullsuite}
+            else
+                suite_list+=" "${fullsuite}
+            fi
+        done
+    fi
+
+    eval $__suite_list="'$suite_list'"
 }
 
 function run_plan() {
@@ -145,7 +179,7 @@ function run_plan() {
         ;;
     esac
 
-    printf "Locating ${type} plan to use...\n"
+    printf "Locating %s plan to use...\n" "${type}"
     plan_filepath="${WORKSPACE}/test/csit/${type}plans/$plan"
     if [ ! -f "${plan_filepath}" ]; then
         plan_filepath="${WORKSPACE}/test/csit/${type}plans/${STREAMTESTPLAN}"
@@ -155,17 +189,17 @@ function run_plan() {
     fi
 
     if [ -f "${plan_filepath}" ]; then
-        printf "${type} plan exists!!!\n"
-        printf "Changing the ${type} plan path...\n"
+        printf "%s plan exists!!!\n" "${type}"
+        printf "Changing the %s plan path...\n" "${type}"
         cat ${plan_filepath} | sed "s:integration:${WORKSPACE}:" > ${type}plan.txt
         cat ${type}plan.txt
         for line in $( egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' ${type}plan.txt ); do
-            printf "Executing ${line}...\n"
+            printf "Executing %s...\n" "${line}"
             # shellcheck source=${line} disable=SC1091
             source ${line}
         done
     fi
-    printf "Finished running ${type} plans\n"
+    printf "Finished running %s plans\n" "${type}"
 } # function run_plan()
 
 # Return elapsed time. Usage:
@@ -175,7 +209,7 @@ function timer()
 {
     if [ $# -eq 0 ]; then
         # return the current time
-        printf "$(date "+%s")"
+        printf "%s" "$(date "+%s")"
     else
         local start_time=$1
         end_time=$(date "+%s")
@@ -256,7 +290,6 @@ PUBLIC_PHYSICAL_NETWORK: ${PUBLIC_PHYSICAL_NETWORK}
 ENABLE_NETWORKING_L2GW: ${ENABLE_NETWORKING_L2GW}
 CREATE_INITIAL_NETWORKS: ${CREATE_INITIAL_NETWORKS}
 LBAAS_SERVICE_PROVIDER: ${LBAAS_SERVICE_PROVIDER}
-NUM_OPENSTACK_SITES: ${NUM_OPENSTACK_SITES}
 ODL_SFC_DRIVER: ${ODL_SFC_DRIVER}
 ODL_SNAT_MODE: ${ODL_SNAT_MODE}
 
@@ -269,7 +302,7 @@ function tcpdump_start() {
     local -r filter=$3
     filter_=${filter// /_}
 
-    printf "node ${ip}, ${prefix}_${ip}__${filter}: starting tcpdump\n"
+    printf "node %s, %s_%s__%s: starting tcpdump\n" "${ip}" "${prefix}" "${ip}" "${filter}"
     ssh ${ip} "nohup sudo /usr/sbin/tcpdump -vvv -ni eth0 ${filter} -w /tmp/tcpdump_${prefix}_${ip}__${filter_}.pcap > /tmp/tcpdump_start.log 2>&1 &"
     ${SSH} ${ip} "ps -ef | grep tcpdump"
 }
@@ -277,7 +310,7 @@ function tcpdump_start() {
 function tcpdump_stop() {
     local -r ip=$1
 
-    printf "node $ip: stopping tcpdump\n"
+    printf "node %s: stopping tcpdump\n" "$ip"
     ${SSH} ${ip} "ps -ef | grep tcpdump.sh"
     ${SSH} ${ip} "sudo pkill -f tcpdump"
     ${SSH} ${ip} "sudo xz -9ekvvf /tmp/*.pcap"
@@ -333,7 +366,7 @@ function collect_openstack_logs() {
     local -r node_type=${3}
     local oslogs="${folder}/oslogs"
 
-    printf "collect_openstack_logs for ${node_type} node: ${ip} into ${oslogs}\n"
+    printf "collect_openstack_logs for %s node: %s into %s\n" "${node_type}" "${ip}" "${oslogs}"
     rm -rf ${oslogs}
     mkdir -p ${oslogs}
     # There are always some logs in /opt/stack/logs and this also covers the
@@ -373,7 +406,7 @@ fi
 ls -al /tmp/oslogs
 EOF
 # cat > ${WORKSPACE}/collect_openstack_logs.sh << EOF
-        printf "collect_openstack_logs for ${node_type} node: ${ip} into ${oslogs}, executing script\n"
+        printf "collect_openstack_logs for %s node: %s into %s, executing script\n" "${node_type}" "${ip}" "${oslogs}"
         cat ${WORKSPACE}/collect_openstack_logs.sh
         scp ${WORKSPACE}/collect_openstack_logs.sh ${ip}:/tmp
         ${SSH} ${ip} "bash /tmp/collect_openstack_logs.sh > /tmp/collect_openstack_logs.log 2>&1"
@@ -419,7 +452,11 @@ EOF
     mkdir -p ${WORKSPACE}/archives
 
     mv /tmp/changes.txt ${WORKSPACE}/archives
+    mv /tmp/validations.txt ${WORKSPACE}/archives
     mv ${WORKSPACE}/rabbit.txt ${WORKSPACE}/archives
+    mv ${WORKSPACE}/haproxy.cfg ${WORKSPACE}/archives
+    ssh ${OPENSTACK_HAPROXY_1_IP} "sudo journalctl -u haproxy > /tmp/haproxy.log"
+    scp ${OPENSTACK_HAPROXY_1_IP}:/tmp/haproxy.log ${WORKSPACE}/archives/
 
     sleep 5
     # FIXME: Do not create .tar and gzip before copying.
@@ -508,6 +545,7 @@ EOF
         scp ${!OSIP}:/tmp/dmesg.log ${NODE_FOLDER}
         scp ${!OSIP}:/tmp/extra_debug.log ${NODE_FOLDER}
         scp ${!OSIP}:/tmp/get_devstack.sh.txt ${NODE_FOLDER}
+        scp ${!OSIP}:/tmp/install_ovs.txt ${NODE_FOLDER}
         scp ${!OSIP}:/tmp/journalctl.log ${NODE_FOLDER}
         scp ${!OSIP}:/tmp/ovsdb-tool.log ${NODE_FOLDER}
         scp ${!OSIP}:/tmp/tcpdump_start.log ${NODE_FOLDER}
@@ -550,6 +588,7 @@ EOF
         scp ${!OSIP}:/tmp/dmesg.log ${NODE_FOLDER}
         scp ${!OSIP}:/tmp/extra_debug.log ${NODE_FOLDER}
         scp ${!OSIP}:/tmp/get_devstack.sh.txt ${NODE_FOLDER}
+        scp ${!OSIP}:/tmp/install_ovs.txt ${NODE_FOLDER}
         scp ${!OSIP}:/tmp/journalctl.log ${NODE_FOLDER}
         scp ${!OSIP}:/tmp/ovsdb-tool.log ${NODE_FOLDER}
         scp ${!OSIP}:/tmp/tcpdump_start.log ${NODE_FOLDER}
@@ -582,3 +621,396 @@ EOF
         echo "tempest results not found in ${DEVSTACK_TEMPEST_DIR}/${TESTREPO}/0"
     fi
 } # collect_netvirt_logs()
+
+# Utility function for joining strings.
+function join() {
+    delim=' '
+    final=$1; shift
+
+    for str in "$@" ; do
+        final=${final}${delim}${str}
+    done
+
+    echo ${final}
+}
+
+function get_nodes_list() {
+    # Create the string for nodes
+    for i in `seq 1 ${NUM_ODL_SYSTEM}` ; do
+        CONTROLLERIP=ODL_SYSTEM_${i}_IP
+        nodes[$i]=${!CONTROLLERIP}
+    done
+
+    nodes_list=$(join "${nodes[@]}")
+    echo ${nodes_list}
+}
+
+function get_features() {
+    if [ ${CONTROLLERSCOPE} == 'all' ]; then
+        ACTUALFEATURES="odl-integration-compatible-with-all,${CONTROLLERFEATURES}"
+        export CONTROLLERMEM="3072m"
+    else
+        ACTUALFEATURES="odl-infrautils-ready,${CONTROLLERFEATURES}"
+    fi
+
+    # Some versions of jenkins job builder result in feature list containing spaces
+    # and ending in newline. Remove all that.
+    ACTUALFEATURES=`echo "${ACTUALFEATURES}" | tr -d '\n \r'`
+    echo "ACTUALFEATURES: ${ACTUALFEATURES}"
+
+    # In the case that we want to install features via karaf shell, a space separated list of
+    # ACTUALFEATURES IS NEEDED
+    SPACE_SEPARATED_FEATURES=$(echo "${ACTUALFEATURES}" | tr ',' ' ')
+    echo "SPACE_SEPARATED_FEATURES: ${SPACE_SEPARATED_FEATURES}"
+
+    export ACTUALFEATURES
+    export SPACE_SEPARATED_FEATURES
+}
+
+# Create the configuration script to be run on controllers.
+function create_configuration_script() {
+    cat > ${WORKSPACE}/configuration-script.sh <<EOF
+set -x
+source /tmp/common-functions.sh ${BUNDLEFOLDER}
+
+echo "Changing to /tmp"
+cd /tmp
+
+echo "Downloading the distribution from ${ACTUAL_BUNDLE_URL}"
+wget --progress=dot:mega '${ACTUAL_BUNDLE_URL}'
+
+echo "Extracting the new controller..."
+unzip -q ${BUNDLE}
+
+echo "Adding external repositories..."
+sed -ie "s%org.ops4j.pax.url.mvn.repositories=%org.ops4j.pax.url.mvn.repositories=https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot@id=opendaylight-snapshot@snapshots, https://nexus.opendaylight.org/content/repositories/public@id=opendaylight-mirror, http://repo1.maven.org/maven2@id=central, http://repository.springsource.com/maven/bundles/release@id=spring.ebr.release, http://repository.springsource.com/maven/bundles/external@id=spring.ebr.external, http://zodiac.springsource.com/maven/bundles/release@id=gemini, http://repository.apache.org/content/groups/snapshots-group@id=apache@snapshots@noreleases, https://oss.sonatype.org/content/repositories/snapshots@id=sonatype.snapshots.deploy@snapshots@noreleases, https://oss.sonatype.org/content/repositories/ops4j-snapshots@id=ops4j.sonatype.snapshots.deploy@snapshots@noreleases%g" ${MAVENCONF}
+cat ${MAVENCONF}
+
+if [[ "$USEFEATURESBOOT" == "True" ]]; then
+    echo "Configuring the startup features..."
+    sed -ie "s/\(featuresBoot=\|featuresBoot =\)/featuresBoot = ${ACTUALFEATURES},/g" ${FEATURESCONF}
+fi
+
+FEATURE_TEST_STRING="features-integration-test"
+KARAF_VERSION=${KARAF_VERSION:-karaf4}
+if [[ "$KARAF_VERSION" == "karaf4" ]]; then
+    FEATURE_TEST_STRING="features-test"
+fi
+
+sed -ie "s%\(featuresRepositories=\|featuresRepositories =\)%featuresRepositories = mvn:org.opendaylight.integration/\${FEATURE_TEST_STRING}/${BUNDLE_VERSION}/xml/features,mvn:org.apache.karaf.decanter/apache-karaf-decanter/1.0.0/xml/features,%g" ${FEATURESCONF}
+if [[ ! -z "${REPO_URL}" ]]; then
+   sed -ie "s%featuresRepositories =%featuresRepositories = ${REPO_URL},%g" ${FEATURESCONF}
+fi
+cat ${FEATURESCONF}
+
+configure_karaf_log "${KARAF_VERSION}" "${CONTROLLERDEBUGMAP}"
+
+set_java_vars "${JAVA_HOME}" "${CONTROLLERMEM}" "${MEMCONF}"
+
+echo "Listing all open ports on controller system..."
+netstat -pnatu
+
+# Copy shard file if exists
+if [ -f /tmp/custom_shard_config.txt ]; then
+    echo "Custom shard config exists!!!"
+    echo "Copying the shard config..."
+    cp /tmp/custom_shard_config.txt /tmp/${BUNDLEFOLDER}/bin/
+fi
+
+echo "Configuring cluster"
+/tmp/${BUNDLEFOLDER}/bin/configure_cluster.sh \$1 ${nodes_list}
+
+echo "Dump akka.conf"
+cat ${AKKACONF}
+
+echo "Dump modules.conf"
+cat ${MODULESCONF}
+
+echo "Dump module-shards.conf"
+cat ${MODULESHARDSCONF}
+EOF
+# cat > ${WORKSPACE}/configuration-script.sh <<EOF
+}
+
+# Create the startup script to be run on controllers.
+function create_startup_script() {
+    cat > ${WORKSPACE}/startup-script.sh <<EOF
+echo "Redirecting karaf console output to karaf_console.log"
+export KARAF_REDIRECT="/tmp/${BUNDLEFOLDER}/data/log/karaf_console.log"
+mkdir -p /tmp/${BUNDLEFOLDER}/data/log
+
+echo "Starting controller..."
+/tmp/${BUNDLEFOLDER}/bin/start
+EOF
+# cat > ${WORKSPACE}/startup-script.sh <<EOF
+}
+
+function create_post_startup_script() {
+    cat > ${WORKSPACE}/post-startup-script.sh <<EOF
+if [[ "$USEFEATURESBOOT" != "True" ]]; then
+
+    # wait up to 60s for karaf port 8101 to be opened, polling every 5s
+    loop_count=0;
+    until [[ \$loop_count -ge 12 ]]; do
+        netstat -na | grep 8101 && break;
+        loop_count=\$[\$loop_count+1];
+        sleep 5;
+    done
+
+    echo "going to feature:install --no-auto-refresh ${SPACE_SEPARATED_FEATURES} one at a time"
+    for feature in ${SPACE_SEPARATED_FEATURES}; do
+        sshpass -p karaf ssh -o StrictHostKeyChecking=no \
+                             -o UserKnownHostsFile=/dev/null \
+                             -o LogLevel=error \
+                             -p 8101 karaf@localhost \
+                             feature:install --no-auto-refresh \$feature;
+    done
+
+    echo "ssh to karaf console to list -i installed features"
+    sshpass -p karaf ssh -o StrictHostKeyChecking=no \
+                         -o UserKnownHostsFile=/dev/null \
+                         -o LogLevel=error \
+                         -p 8101 karaf@localhost \
+                         feature:list -i
+fi
+
+echo "Waiting up to 3 minutes for controller to come up, checking every 5 seconds..."
+for i in {1..36}; do
+    sleep 5;
+    grep 'org.opendaylight.infrautils.*System ready' /tmp/${BUNDLEFOLDER}/data/log/karaf.log
+    if [ \$? -eq 0 ]; then
+        echo "Controller is UP"
+        break
+    fi
+done;
+
+# if we ended up not finding ready status in the above loop, we can output some debugs
+grep 'org.opendaylight.infrautils.*System ready' /tmp/${BUNDLEFOLDER}/data/log/karaf.log
+if [ $? -ne 0 ]; then
+    echo "Timeout Controller DOWN"
+    echo "Dumping first 500K bytes of karaf log..."
+    head --bytes=500K "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"
+    echo "Dumping last 500K bytes of karaf log..."
+    tail --bytes=500K "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"
+    echo "Listing all open ports on controller system"
+    netstat -pnatu
+    exit 1
+fi
+
+echo "Listing all open ports on controller system..."
+netstat -pnatu
+
+function exit_on_log_file_message {
+    echo "looking for \"\$1\" in log file"
+    if grep --quiet "\$1" "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"; then
+        echo ABORTING: found "\$1"
+        echo "Dumping first 500K bytes of karaf log..."
+        head --bytes=500K "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"
+        echo "Dumping last 500K bytes of karaf log..."
+        tail --bytes=500K "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"
+        exit 1
+    fi
+}
+
+exit_on_log_file_message 'BindException: Address already in use'
+exit_on_log_file_message 'server is unhealthy'
+EOF
+# cat > ${WORKSPACE}/post-startup-script.sh <<EOF
+}
+
+# Copy over the configuration script and configuration files to each controller
+# Execute the configuration script on each controller.
+function copy_and_run_configuration_script() {
+    for i in `seq 1 ${NUM_ODL_SYSTEM}`; do
+        CONTROLLERIP=ODL_SYSTEM_${i}_IP
+        echo "Configuring member-${i} with IP address ${!CONTROLLERIP}"
+        scp ${WORKSPACE}/configuration-script.sh ${!CONTROLLERIP}:/tmp/
+        ssh ${!CONTROLLERIP} "bash /tmp/configuration-script.sh ${i}"
+    done
+}
+
+# Copy over the startup script to each controller and execute it.
+function copy_and_run_startup_script() {
+    for i in `seq 1 ${NUM_ODL_SYSTEM}`; do
+        CONTROLLERIP=ODL_SYSTEM_${i}_IP
+        echo "Starting member-${i} with IP address ${!CONTROLLERIP}"
+        scp ${WORKSPACE}/startup-script.sh ${!CONTROLLERIP}:/tmp/
+        ssh ${!CONTROLLERIP} "bash /tmp/startup-script.sh"
+    done
+}
+
+function copy_and_run_post_startup_script() {
+    seed_index=1
+    for i in `seq 1 ${NUM_ODL_SYSTEM}`; do
+        CONTROLLERIP=ODL_SYSTEM_${i}_IP
+        echo "Execute the post startup script on controller ${!CONTROLLERIP}"
+        scp ${WORKSPACE}/post-startup-script.sh ${!CONTROLLERIP}:/tmp
+        ssh ${!CONTROLLERIP} "bash /tmp/post-startup-script.sh $(( seed_index++ ))"
+        if [ $(( $i % ${NUM_ODL_SYSTEM} )) == 0 ]; then
+            seed_index=1
+        fi
+    done
+}
+
+function create_controller_variables() {
+    echo "Generating controller variables..."
+    for i in `seq 1 ${NUM_ODL_SYSTEM}`; do
+        CONTROLLERIP=ODL_SYSTEM_${i}_IP
+        odl_variables=${odl_variables}" -v ${CONTROLLERIP}:${!CONTROLLERIP}"
+        echo "Lets's take the karaf thread dump"
+        ssh ${!CONTROLLERIP} "sudo ps aux" > ${WORKSPACE}/ps_before.log
+        pid=$(grep org.apache.karaf.main.Main ${WORKSPACE}/ps_before.log | grep -v grep | tr -s ' ' | cut -f2 -d' ')
+        echo "karaf main: org.apache.karaf.main.Main, pid:${pid}"
+        ssh ${!CONTROLLERIP} "${JAVA_HOME}/bin/jstack -l ${pid}" > ${WORKSPACE}/karaf_${i}_${pid}_threads_before.log || true
+    done
+}
+
+# Function to build OVS from git repo
+function build_ovs() {
+    local -r ip=$1
+    local -r version=$2
+    local -r rpm_path="$3"
+
+    echo "Building OVS ${version} on ${ip} ..."
+    cat > ${WORKSPACE}/build_ovs.sh << EOF
+set -ex -o pipefail
+
+echo '---> Building openvswitch version ${version}'
+
+# Install running kernel devel packages
+K_VERSION=\$(uname -r)
+YUM_OPTS="-y --disablerepo=* --enablerepo=base,updates,extra,C*-base,C*-updates,C*-extras"
+# Install centos-release to update vault repos from which to fetch
+# kernel devel packages
+sudo yum \${YUM_OPTS} install centos-release yum-utils @'Development Tools' rpm-build
+sudo yum \${YUM_OPTS} install kernel-{devel,headers}-\${K_VERSION}
+
+TMP=\$(mktemp -d)
+pushd \${TMP}
+
+git clone https://github.com/openvswitch/ovs.git
+cd ovs
+
+if [ "${version}" = "v2.6.1-nsh" ]; then
+    git checkout v2.6.1
+    echo "Will apply nsh patches for OVS version 2.6.1"
+    git clone https://github.com/yyang13/ovs_nsh_patches.git ../ovs_nsh_patches
+    git apply ../ovs_nsh_patches/v2.6.1_centos7/*.patch
+else
+    git checkout ${version}
+fi
+
+# On early versions of OVS, flake warnings would fail the build.
+# Remove it.
+sudo pip uninstall -y flake8
+
+# Get rid of sphinx dep as it conflicts with the already
+# installed one (via pip). Docs wont be built.
+sed -i "/BuildRequires:.*sphinx.*/d" rhel/openvswitch-fedora.spec.in
+
+sed -e 's/@VERSION@/0.0.1/' rhel/openvswitch-fedora.spec.in > /tmp/ovs.spec
+sed -e 's/@VERSION@/0.0.1/' rhel/openvswitch-kmod-fedora.spec.in > /tmp/ovs-kmod.spec
+sed -e 's/@VERSION@/0.0.1/' rhel/openvswitch-dkms.spec.in > /tmp/ovs-dkms.spec
+sudo yum-builddep \${YUM_OPTS} /tmp/ovs.spec /tmp/ovs-kmod.spec /tmp/ovs-dkms.spec
+rm /tmp/ovs.spec /tmp/ovs-kmod.spec /tmp/ovs-dkms.spec
+./boot.sh
+./configure --build=x86_64-redhat-linux-gnu --host=x86_64-redhat-linux-gnu --with-linux=/lib/modules/\${K_VERSION}/build --program-prefix= --disable-dependency-tracking --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64 --libexecdir=/usr/libexec --localstatedir=/var --sharedstatedir=/var/lib --mandir=/usr/share/man --infodir=/usr/share/info --enable-libcapng --enable-ssl --with-pkidir=/var/lib/openvswitch/pki PYTHON=/usr/bin/python2
+make rpm-fedora RPMBUILD_OPT="--without check"
+# Build dkms only for now
+# make rpm-fedora-kmod RPMBUILD_OPT='-D "kversion \${K_VERSION}"'
+rpmbuild -D "_topdir \$(pwd)/rpm/rpmbuild" -bb --without check rhel/openvswitch-dkms.spec
+
+mkdir -p /tmp/ovs_rpms
+cp -r rpm/rpmbuild/RPMS/* /tmp/ovs_rpms/
+
+popd
+rm -rf \${TMP}
+EOF
+
+    scp ${WORKSPACE}/build_ovs.sh ${ip}:/tmp
+    ${SSH} ${ip} " bash /tmp/build_ovs.sh >> /tmp/install_ovs.txt 2>&1"
+    scp -r ${ip}:/tmp/ovs_rpms/* "${rpm_path}/"
+    ${SSH} ${ip} "rm -rf /tmp/ovs_rpms"
+}
+
+# Install OVS RPMs from yum repo
+function install_ovs_from_repo() {
+    local -r ip=$1
+    local -r rpm_repo="$2"
+
+    echo "Installing OVS from repo ${rpm_repo} on ${ip} ..."
+    cat > ${WORKSPACE}/install_ovs.sh << EOF
+set -ex -o pipefail
+
+echo '---> Installing openvswitch from ${rpm_repo}'
+
+# We need repoquery from yum-utils.
+sudo yum -y install yum-utils
+
+# Get openvswitch packages offered by custom repo.
+# dkms package will have priority over kmod.
+OVS_REPO_OPTS="--repofrompath=ovs-repo,${rpm_repo} --disablerepo=* --enablerepo=ovs-repo"
+OVS_PKGS=\$(repoquery \${OVS_REPO_OPTS} openvswitch)
+OVS_SEL_PKG=\$(repoquery \${OVS_REPO_OPTS} openvswitch-selinux-policy)
+OVS_DKMS_PKG=\$(repoquery \${OVS_REPO_OPTS} openvswitch-dkms)
+OVS_KMOD_PKG=\$(repoquery \${OVS_REPO_OPTS} openvswitch-kmod)
+[ -n "\${OVS_SEL_PKG}" ] && OVS_PKGS="\${OVS_PKGS} \${OVS_SEL_PKG}"
+[ -n "\${OVS_DKMS_PKG}" ] && OVS_PKGS="\${OVS_PKGS} \${OVS_DKMS_PKG}"
+[ -z "\${OVS_DKMS_PKG}" ] && [ -n "\${OVS_KMOD_PKG}" ] && OVS_PKGS="\${OVS_PKGS} \${OVS_KMOD_PKG}"
+
+# Bail with error if custom repo was provided but we could not
+# find suitable packages there.
+[ -z "\${OVS_PKGS}" ] && echo "No OVS packages found in custom repo." && exit 1
+
+# Install kernel & devel packages for the openvswitch dkms package.
+if [ -n "\${OVS_DKMS_PKG}" ]; then
+    # install centos-release to update vault repos from which to fetch
+    # kernel devel packages
+    sudo yum -y install centos-release
+    K_VERSION=\$(uname -r)
+    YUM_OPTS="-y --disablerepo=* --enablerepo=base,updates,extra,C*-base,C*-updates,C*-extras"
+    sudo yum \${YUM_OPTS} install kernel-{headers,devel}-\${K_VERSION} @'Development Tools' python-six
+fi
+
+PREV_MOD=\$(sudo modinfo -n openvswitch || echo '')
+
+# Install OVS offered by custom repo.
+sudo yum-config-manager --add-repo "${rpm_repo}"
+sudo yum -y versionlock delete openvswitch-*
+sudo yum -y remove openvswitch-*
+sudo yum -y --nogpgcheck install \${OVS_PKGS}
+sudo yum -y versionlock add \${OVS_PKGS}
+
+# Most recent OVS versions have some incompatibility with certain versions of iptables
+# This below line will overcome that problem.
+sudo modprobe openvswitch
+
+# Start OVS and print details
+sudo systemctl start openvswitch
+sudo systemctl enable openvswitch
+sudo ovs-vsctl --retry -t 5 show
+sudo modinfo openvswitch
+
+# dkms rpm install can fail silently (probably because the OVS version is
+# incompatible with the running kernel), verify module was updated.
+NEW_MOD=\$(sudo modinfo -n openvswitch || echo '')
+[ "\${PREV_MOD}" != "\${NEW_MOD}" ] || (echo "Kernel module was not updated" && exit 1)
+EOF
+
+    scp ${WORKSPACE}/install_ovs.sh ${ip}:/tmp
+    ${SSH} ${ip} "bash /tmp/install_ovs.sh >> /tmp/install_ovs.txt 2>&1"
+}
+
+# Install OVS RPMS from path
+function install_ovs_from_path() {
+    local -r ip=$1
+    local -r rpm_path="$2"
+
+    echo "Creating OVS RPM repo on ${ip} ..."
+    ${SSH} ${ip} "mkdir -p /tmp/ovs_rpms"
+    scp -r "${rpm_path}"/* ${ip}:/tmp/ovs_rpms
+    ${SSH} ${ip} "sudo yum -y install createrepo && createrepo --database /tmp/ovs_rpms"
+    install_ovs_from_repo ${ip} file:/tmp/ovs_rpms
+}
+
+