From 309fafddc51697deb9c6f8bf723c10539224cb4d Mon Sep 17 00:00:00 2001 From: Mauro Sardara Date: Tue, 16 Aug 2022 09:43:05 +0200 Subject: ci(functional-tests): add functional tests scripts - Add scripts/functional-tests.sh script - Add `download_artifacts` functions, allowing to retrieve artifacts of a gerrit patch - Robot: redirect output of topology build to files, thus preventing robot from hanging - Share folders between host and containers with the :z flag - Use sudo to install executable in docker-compose scripts, as the user of the docker is not root anymore - Makefile: decouple installation and build Ref: HICN-732 Change-Id: Ib945cf7bd0ee331e33270cf1005dfebd085862eb Signed-off-by: Mauro Sardara --- Dockerfile.dev | 8 +++-- Makefile | 30 +++++++++++++++--- scripts/build-packages.sh | 16 ---------- scripts/functional-tests.sh | 35 +++++++++++++++++++++ scripts/functions.sh | 46 ++++++++++++++++++++++++++-- tests/1-node.yml | 2 +- tests/2-nodes-hicn-light.yml | 4 +-- tests/2-nodes-vpp-bridge.yml | 8 ++--- tests/2-nodes-vpp-memif-replication.yml | 12 ++++---- tests/2-nodes-vpp-memif.yml | 12 ++++---- tests/2-nodes.yml | 4 +-- tests/build.yml | 41 +++++++++++++++++++++++++ tests/config.sh | 2 +- tests/resources/libraries/robot/common.robot | 2 +- 14 files changed, 171 insertions(+), 51 deletions(-) create mode 100644 scripts/functional-tests.sh create mode 100644 tests/build.yml diff --git a/Dockerfile.dev b/Dockerfile.dev index 326f4676c..e8c9097bb 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -2,13 +2,15 @@ FROM ubuntu:focal ENV DEBIAN_FRONTEND=noninteractive WORKDIR /hicn-build -COPY Makefile versions.cmake ./ -COPY scripts scripts/ - ARG USERNAME=ubuntu ARG USER_UID=1000 ARG USER_GID=${USER_UID} +COPY Makefile versions.cmake ./ +COPY scripts scripts/ + +USER root + RUN apt update && apt-get install -y \ make \ sudo \ diff --git a/Makefile b/Makefile index 1fb963292..91d9eb888 100644 --- a/Makefile +++ b/Makefile @@ -106,10 +106,16 @@ debug-tools: define build_folder $(eval LOWER_BUILDTYPE=$(shell echo $(2) | tr A-Z a-z)) - $(eval BUILD_FOLDER=$(or $(BUILD_PATH), build-$(LOWER_BUILDTYPE)-$(OS_ID))) + $(eval BUILD_FOLDER=$(or $(BUILD_PATH), $(WS_ROOT)/build-$(LOWER_BUILDTYPE)-$(OS_ID))) $(1) := $$(BUILD_FOLDER) endef +define install_folder + $(eval LOWER_BUILDTYPE=$(shell echo $(2) | tr A-Z a-z)) + $(eval INSTALL_FOLDER=$(or $(INSTALL_PREFIX), $(WS_ROOT)/install-$(LOWER_BUILDTYPE))) + $(1) := $$(INSTALL_FOLDER) +endef + define configure $(eval $(call build_folder,BUILD_FOLDER,$(1))) $(eval PREFIX=$(or $(INSTALL_PREFIX), $(WS_ROOT)/install-$(LOWER_BUILDTYPE))) @@ -137,11 +143,16 @@ define configure -DBUILD_TESTS=ON endef -define build +define install $(eval $(call build_folder,BUILD_FOLDER,$(1))) cmake --build $(BUILD_FOLDER) -- -j 4 install endef +define build + $(eval $(call build_folder,BUILD_FOLDER,$(1))) + cmake --build $(BUILD_FOLDER) -- -j 4 +endef + define build_coverage $(eval $(call build_folder,BUILD_FOLDER,$(1))) $(eval SONAR_OUT_DIR=$(or $(SONAR_OUT_DIR), $(WS_ROOT)/sonarqube-output)) @@ -186,10 +197,19 @@ package: build package-release: build-release $(call package,Release,) +.PHONY = install +install: build + $(call install,Debug,) + +.PHONY = install-release +install-release: build-release + $(call install,Release,) + define wipe - $(eval LOWER_BUILDTYPE=$(shell echo $(1) | tr A-Z a-z)) - $(RM) -rf build-$(LOWER_BUILDTYPE)-$(OS_ID) - $(RM) -rf install-$(LOWER_BUILDTYPE) + $(eval $(call build_folder,BUILD_FOLDER,$(1))) + $(eval $(call install_folder,INSTALL_FOLDER,$(1))) + $(RM) -rf $(BUILD_FOLDER) + $(RM) -rf $(INSTALL_FOLDER) endef .PHONY = wipe diff --git a/scripts/build-packages.sh b/scripts/build-packages.sh index c1e548bf0..0ac9dce8b 100644 --- a/scripts/build-packages.sh +++ b/scripts/build-packages.sh @@ -40,21 +40,6 @@ function build_package() { echo "*******************************************************************" } -function functional_test() { - echo "*******************************************************************" - echo "********************* STARTING FUNCTIONAL TESTS *******************" - echo "*******************************************************************" - - # Run functional tests - pushd ${SCRIPT_PATH}/.. - BUILD_SOFTWARE=0 DOCKERFILE="tests/Dockerfile.ci" bash ./tests/run-functional.sh - popd - - echo "*******************************************************************" - echo "********** FUNCTIONAL TESTS COMPLETED SUCCESSFULLY ***************" - echo "*******************************************************************" -} - build_sphinx() { setup @@ -84,7 +69,6 @@ case "${1}" in ;; packages) build_package - functional_test ;; vpp_master) ;; diff --git a/scripts/functional-tests.sh b/scripts/functional-tests.sh new file mode 100644 index 000000000..05cc4193b --- /dev/null +++ b/scripts/functional-tests.sh @@ -0,0 +1,35 @@ +# Copyright (c) 2017-2022 Cisco and/or its affiliates. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#!/bin/bash + +set -euxo pipefail + +SCRIPT_PATH=$( cd "$(dirname "${BASH_SOURCE}")" ; pwd -P ) +source "${SCRIPT_PATH}/functions.sh" + +echo "---------------------------------------------------------" +echo "----- INSTALLING FUNCTIONAL TEST DEPENDENCIES ---------" +echo "---------------------------------------------------------" + +# This docker compose version is well supported also in CentOS. +# Versions >= 2.0.0 do not seem to work. +DOCKER_COMPOSE_VERSION=1.29.2 + +sudo curl -L "https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose +sudo chmod +x /usr/local/bin/docker-compose +sudo pip3 install robotframework + +functional_test + +exit 0 diff --git a/scripts/functions.sh b/scripts/functions.sh index 147f6669c..06673f888 100644 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -56,8 +56,6 @@ function call_once() { # Install dependencies function install_deps() { - curl -fsSL https://get.docker.com -o get-docker.sh - sudo sh get-docker.sh make -C ${SCRIPT_PATH}/.. deps } @@ -75,3 +73,47 @@ function setup_extras() { call_once install_deps call_once install_collectd_headers } + +# Download artifacts of this patchset from jenkins +function download_artifacts() { + if [[ -n ${GERRIT_HOST:-} ]] && + [[ -n ${GERRIT_CHANGE_NUMBER:-} ]] && + [[ -n ${GERRIT_PATCHSET_NUMBER:-} ]]; then + + # Retrieve the Jenkins URL of the build relative to this PATCHSET + JENKINS_URL=$( + curl -s "https://${GERRIT_HOST}/r/changes/${GERRIT_CHANGE_NUMBER}/detail" | + tail -n +2 | jq '.messages[].message?' | + grep -E "Patch Set ${GERRIT_PATCHSET_NUMBER}:.*hicn-verify-build.*build_success-hicn-ubuntu2004-$(uname -m)" | + grep -Eo "https?://jenkins.fd.io/job/hicn-verify-build-hicn-ubuntu2004-$(uname -m)[^ ]+" + ) + ARTIFACTS_URL="${JENKINS_URL}/artifact/packages/*zip*/packages.zip" + + # Download artifacts + curl -o "${SCRIPT_PATH}/../packages.zip" -L "${ARTIFACTS_URL}" + + # Unzip them + unzip "${SCRIPT_PATH}/../packages.zip" -d "${SCRIPT_PATH}/.." + else + echo "GERRIT_* environment is not set. Impossible to download artifacts." >&2 + exit 1 + fi +} + +# Run functional tests +function functional_test() { + echo "*******************************************************************" + echo "********************* STARTING FUNCTIONAL TESTS *******************" + echo "*******************************************************************" + + download_artifacts + + # Run functional tests + pushd ${SCRIPT_PATH}/../tests + BUILD_SOFTWARE=0 DOCKERFILE="tests/Dockerfile.ci" bash ./run-functional.sh + popd + + echo "*******************************************************************" + echo "********** FUNCTIONAL TESTS COMPLETED SUCCESSFULLY ***************" + echo "*******************************************************************" +} diff --git a/tests/1-node.yml b/tests/1-node.yml index be693c792..5b412d2fb 100644 --- a/tests/1-node.yml +++ b/tests/1-node.yml @@ -9,7 +9,7 @@ services: container_name: forwarder working_dir: /workspace volumes: - - ..:/workspace + - ..:/workspace:z entrypoint: [/bin/bash, -ex, -c] command: - | diff --git a/tests/2-nodes-hicn-light.yml b/tests/2-nodes-hicn-light.yml index 674df3ea4..c0e22f9b7 100644 --- a/tests/2-nodes-hicn-light.yml +++ b/tests/2-nodes-hicn-light.yml @@ -5,7 +5,7 @@ services: command: - | if [ -d /workspace/build-dev ]; then - ninja -C /workspace/build-dev install + sudo ninja -C /workspace/build-dev install fi sudo ip link add br0 type bridge @@ -34,7 +34,7 @@ services: command: - | if [ -d /workspace/build-dev ]; then - ninja -C /workspace/build-dev install + sudo ninja -C /workspace/build-dev install fi sudo ip link add br0 type bridge diff --git a/tests/2-nodes-vpp-bridge.yml b/tests/2-nodes-vpp-bridge.yml index 5a61874ac..f162c7b46 100644 --- a/tests/2-nodes-vpp-bridge.yml +++ b/tests/2-nodes-vpp-bridge.yml @@ -2,12 +2,10 @@ version: "3" services: client: container_name: ${TEST_VPP_BRIDGE}-client - volumes: - - ..:/workspace command: - | if [ -d /workspace/build-dev ]; then - ninja -C /workspace/build-dev install + sudo ninja -C /workspace/build-dev install fi sudo ip link add br0 type bridge @@ -54,12 +52,10 @@ services: server: container_name: ${TEST_VPP_BRIDGE}-server - volumes: - - ..:/workspace command: - | if [ -d /workspace/build-dev ]; then - ninja -C /workspace/build-dev install + sudo ninja -C /workspace/build-dev install fi sudo ip link add br0 type bridge diff --git a/tests/2-nodes-vpp-memif-replication.yml b/tests/2-nodes-vpp-memif-replication.yml index c5b0d3865..9fbb57a40 100644 --- a/tests/2-nodes-vpp-memif-replication.yml +++ b/tests/2-nodes-vpp-memif-replication.yml @@ -10,13 +10,13 @@ services: container_name: ${TEST_VPP_MEMIF_REPLICATION}-client hostname: client volumes: - - /tmp/memif:/memif - - ..:/workspace + - /tmp/memif:/memif:z + - ..:/workspace:z entrypoint: [/bin/bash, -c] command: - | if [ -d /workspace/build-dev ]; then - ninja -C /workspace/build-dev install + sudo ninja -C /workspace/build-dev install fi sudo mkdir -p /var/log/vpp @@ -79,13 +79,13 @@ services: container_name: ${TEST_VPP_MEMIF_REPLICATION}-server hostname: server volumes: - - /tmp/memif:/memif - - ..:/workspace + - /tmp/memif:/memif:z + - ..:/workspace:z entrypoint: [/bin/bash, -c] command: - | if [ -d /workspace/build-dev ]; then - ninja -C /workspace/build-dev install + sudo ninja -C /workspace/build-dev install fi sudo mkdir -p /var/log/vpp diff --git a/tests/2-nodes-vpp-memif.yml b/tests/2-nodes-vpp-memif.yml index e02c947a6..ace522dc6 100644 --- a/tests/2-nodes-vpp-memif.yml +++ b/tests/2-nodes-vpp-memif.yml @@ -4,12 +4,12 @@ services: container_name: ${TEST_VPP_MEMIF}-client networks: [] volumes: - - /tmp/memif:/memif - - ..:/workspace + - /tmp/memif:/memif:z + - ..:/workspace:z command: - | if [ -d /workspace/build-dev ]; then - ninja -C /workspace/build-dev install + sudo ninja -C /workspace/build-dev install fi sudo mkdir -p /var/log/vpp @@ -61,12 +61,12 @@ services: container_name: ${TEST_VPP_MEMIF}-server networks: [] volumes: - - /tmp/memif:/memif - - ..:/workspace + - /tmp/memif:/memif:z + - ..:/workspace:z command: - | if [ -d /workspace/build-dev ]; then - ninja -C /workspace/build-dev install + sudo ninja -C /workspace/build-dev install fi sudo mkdir -p /var/log/vpp diff --git a/tests/2-nodes.yml b/tests/2-nodes.yml index e1740dbf7..064ed5453 100644 --- a/tests/2-nodes.yml +++ b/tests/2-nodes.yml @@ -12,7 +12,7 @@ services: networks: - kernel volumes: - - ..:/workspace + - ..:/workspace:z entrypoint: [/bin/bash, -x, -c] command: - tail -f /dev/null @@ -29,7 +29,7 @@ services: networks: - kernel volumes: - - ..:/workspace + - ..:/workspace:z entrypoint: [/bin/bash, -x, -c] command: - tail -f /dev/null diff --git a/tests/build.yml b/tests/build.yml new file mode 100644 index 000000000..859262632 --- /dev/null +++ b/tests/build.yml @@ -0,0 +1,41 @@ +version: "3" +services: + dev: + build: + context: .. + dockerfile: ${DOCKERFILE} + image: hicn-base + stdin_open: true + tty: true + working_dir: /workspace + container_name: dev + hostname: dev + environment: + - BUILD_SOFTWARE + volumes: + - ..:/workspace:z + entrypoint: [/bin/bash, -ex, -c] + command: + - | + whoami + + if [[ "${BUILD_SOFTWARE}" -ne 1 ]]; then + exit 0 + fi + + if [[ ! -z "${REBUILD}" ]]; then + rm -fr build-dev + fi + + git config --global --add safe.directory \* + + mkdir -p build-dev + cd build-dev + cmake -G Ninja \ + -DCMAKE_INSTALL_PREFIX=/usr \ + -DCMAKE_BUILD_TYPE=Release \ + -DBUILD_APPS=ON \ + -DBUILD_TESTS=ON \ + -DENABLE_RELY=OFF \ + -DBUILD_HICNPLUGIN=ON .. + sudo ninja install diff --git a/tests/config.sh b/tests/config.sh index 9d8e80d62..2d8323a56 100755 --- a/tests/config.sh +++ b/tests/config.sh @@ -171,7 +171,7 @@ function error() { function build() { docker-compose -f build.yml build - docker-compose -f build.yml up --force-recreate --remove-orphans >/dev/null + docker-compose -f build.yml up --force-recreate --remove-orphans } function setup() { diff --git a/tests/resources/libraries/robot/common.robot b/tests/resources/libraries/robot/common.robot index 7550db788..21d1ace1d 100644 --- a/tests/resources/libraries/robot/common.robot +++ b/tests/resources/libraries/robot/common.robot @@ -10,7 +10,7 @@ Library String Build Topology [Arguments] ${TEST_TOPOLOGY}=${NONE} ${TEST_CONFIGURATION}=${NONE} Log to console Building topology ${TEST_TOPOLOGY} ${TEST_CONFIGURATION} - ${result_setup} = Run Process ${EXECDIR}/config.sh build setup ${TEST_TOPOLOGY} ${TEST_CONFIGURATION} + ${result_setup} = Run Process ${EXECDIR}/config.sh build setup ${TEST_TOPOLOGY} ${TEST_CONFIGURATION} stdout=${TEMPDIR}/stdout.txt stderr=${TEMPDIR}/stderr.txt Log to console Done Log Many stdout: ${result_setup.stdout} stderr: ${result_setup.stderr} Should Be Equal As Integers ${result_setup.rc} 0 -- cgit 1.2.3-korg