Build the Go test server on devstack test-config

Every time we update the Go test server code, we have to re-compile it
locally and commit the binary file. Git is not great for binary blobs.
One other reason that carrying the binary in-tree is suboptimal is it
is compiled against amd64 architecture, thus not much multi-arch
friendly.

This change drops the need to compile and carry the test server binary
file in the Git tree. The test server will now be compiled at devstack
test-config phase. On my work station, it takes less than 6 seconds.

Change-Id: I3d8ad18ddd1f23720618d733a9d8a53a6b4e6dfc
diff --git a/devstack/plugin.sh b/devstack/plugin.sh
index babf033..4b8f60b 100644
--- a/devstack/plugin.sh
+++ b/devstack/plugin.sh
@@ -1,14 +1,49 @@
+#!/usr/bin/env bash
+
+saveenv=$-
+set -e
 
 # install_octavia_tempest_plugin
 function install_octavia_tempest_plugin {
     setup_dev_lib "octavia-tempest-plugin"
 }
 
+function build_backend_test_server {
+    if is_fedora || is_ubuntu; then
+        install_package golang
+    else
+        die "Distribution not supported. Supported distributions are: RHEL, CentOS, Fedora, Ubuntu"
+    fi
+
+    go_path=$(find $DEST/tempest/.tox/tempest/ -name test_server.go)
+    bin_path=${go_path%.go}.bin
+    CGO_ENABLED=0 GOOS=linux go build \
+        -a -ldflags '-s -w -extldflags -static' -o $bin_path \
+        ${DEST}/octavia-tempest-plugin/octavia_tempest_plugin/contrib/test_server/test_server.go
+}
+
 if [[ "$1" == "stack" ]]; then
     case "$2" in
         install)
-            echo_summary "Installing octavia-tempest-plugin"
-            install_octavia_tempest_plugin
+            # Install dev library if
+            # - the release is more recent than stein (devstack in stein would
+            #   try to install it in a python2 env, but octavia-tempest-plugin is
+            #   now a python3-only project)
+            # - or the user explicitly requests it (INSTALL_TEMPEST=True)
+            if [[ "$DEVSTACK_SERIES" != "stein" ]] || [[ "$(trueorfalse False INSTALL_TEMPEST)" == "True" ]]; then
+                echo_summary "Installing octavia-tempest-plugin"
+                install_octavia_tempest_plugin
+            fi
+            ;;
+        test-config)
+            echo_summary "Building backend test server"
+            build_backend_test_server
             ;;
     esac
 fi
+
+if [[ $saveenv =~ e ]]; then
+    set -e
+else
+    set +e
+fi
diff --git a/octavia_tempest_plugin/contrib/test_server/README.rst b/octavia_tempest_plugin/contrib/test_server/README.rst
index ba959f9..f6ec4bb 100644
--- a/octavia_tempest_plugin/contrib/test_server/README.rst
+++ b/octavia_tempest_plugin/contrib/test_server/README.rst
@@ -16,14 +16,11 @@
 
     sudo apt-get install -y golang
 
-Install dependencies for Centos (use golang 1.10 from go-toolset-7) and launch
-a shell into the new environment:
+Install dependencies for Centos:
 
 ::
 
-    sudo yum install -y centos-release-scl
-    sudo yum install -y go-toolset-7-golang-bin glibc-static openssl-static zlib-static
-    scl enable go-toolset-7 bash
+    sudo dnf install -y golang
 
 Build the binary:
 
diff --git a/octavia_tempest_plugin/contrib/test_server/test_server.bin b/octavia_tempest_plugin/contrib/test_server/test_server.bin
deleted file mode 100755
index 75ec2f2..0000000
--- a/octavia_tempest_plugin/contrib/test_server/test_server.bin
+++ /dev/null
Binary files differ
diff --git a/zuul.d/jobs.yaml b/zuul.d/jobs.yaml
index 97a3dfe..afffbd2 100644
--- a/zuul.d/jobs.yaml
+++ b/zuul.d/jobs.yaml
@@ -80,7 +80,6 @@
     vars:
       configure_swap_size: 8192
       devstack_localrc:
-        TEMPEST_PLUGINS: /opt/stack/octavia-tempest-plugin
         USE_PYTHON3: true
         LIBVIRT_TYPE: kvm
         LIBVIRT_CPU_MODE: host-passthrough
@@ -115,6 +114,9 @@
         tempest: true
       devstack_plugins:
         octavia: https://opendev.org/openstack/octavia.git
+        octavia-tempest-plugin: https://opendev.org/openstack/octavia-tempest-plugin.git
+      tempest_plugins:
+        - octavia-tempest-plugin
 
 - job:
     name: octavia-dsvm-base-ipv6-only
@@ -134,7 +136,6 @@
       - ^releasenotes/.*$
     vars:
       devstack_localrc:
-        TEMPEST_PLUGINS: /opt/stack/octavia-tempest-plugin
         USE_PYTHON3: true
         LIBVIRT_TYPE: kvm
         LIBVIRT_CPU_MODE: host-passthrough
@@ -169,6 +170,9 @@
         tempest: true
       devstack_plugins:
         octavia: https://opendev.org/openstack/octavia.git
+        octavia-tempest-plugin: https://opendev.org/openstack/octavia-tempest-plugin.git
+      tempest_plugins:
+        - octavia-tempest-plugin
 
 - job:
     name: octavia-dsvm-live-base
@@ -270,7 +274,6 @@
           MULTI_HOST: 1
           SERVICE_HOST: "{{ hostvars['controller']['nodepool']['private_ipv4'] }}"
           HOST_IP: "{{ hostvars['controller']['nodepool']['private_ipv4'] }}"
-          TEMPEST_PLUGINS: /opt/stack/octavia-tempest-plugin
           USE_PYTHON3: true
           LIBVIRT_TYPE: kvm
           LIBVIRT_CPU_MODE: host-passthrough
@@ -283,6 +286,9 @@
         devstack_plugins:
           neutron: https://opendev.org/openstack/neutron.git
           octavia: https://opendev.org/openstack/octavia.git
+          octavia-tempest-plugin: https://opendev.org/openstack/octavia-tempest-plugin.git
+        tempest_plugins:
+          - octavia-tempest-plugin
         zuul_copy_output:
           '/var/log/dib-build' : logs
           '/var/log/octavia-amphora.log': logs
@@ -323,6 +329,9 @@
           OCTAVIA_MGMT_PORT_IP: 192.168.0.4
         devstack_plugins:
           octavia: https://opendev.org/openstack/octavia.git
+          octavia-tempest-plugin: https://opendev.org/openstack/octavia-tempest-plugin.git
+        tempest_plugins:
+          - octavia-tempest-plugin
         zuul_copy_output:
           '/var/log/octavia-amphora.log': logs
           '/var/log/octavia-tenant-traffic.log': logs
@@ -648,8 +657,9 @@
         barbican: true
       devstack_plugins:
         barbican: https://opendev.org/openstack/barbican.git
-      devstack_localrc:
-        TEMPEST_PLUGINS: '"/opt/stack/octavia-tempest-plugin /opt/stack/barbican-tempest-plugin"'
+      tempest_plugins:
+        - octavia-tempest-plugin
+        - barbican-tempest-plugin
     irrelevant-files:
       - ^.*\.rst$
       - ^api-ref/.*$