From 85fb97e171273132888a0949a3b4e70579b25380 Mon Sep 17 00:00:00 2001 From: Ciprian Barbu Date: Thu, 11 Jul 2019 19:20:58 +0300 Subject: [PATCH] Add PONSim test scripts for running SIAB The test script is designed to be run from a CI job but it can be run manually by providing the K8S master to connect to and the .kube config file needed to access it. The SIAB tests, which are part of opencord/cord-tester, are run inside a Docker container, by default iecedge/cord-tester, multi-arch enabled. Also add the Dockerfile used to build the cord-tester docker image mentioned above. Signed-off-by: Ciprian Barbu Change-Id: I17475ce90c152f7541ae806b99d6709c1675cda1 --- .../build/cord-tester/Dockerfile.cord-tester | 59 ++++++++++++++++++++++ .../docker/build/cord-tester/build-cord-tester.arm | 10 ++++ .../build/cord-tester/build-k8s-api-tester.arm | 11 ++++ .../seba_on_arm/docker/build/cord-tester/build.arm | 11 ---- src/use_cases/seba_on_arm/test/README | 18 +++++++ .../seba_on_arm/test/ponsim/docker_run.sh | 35 +++++++++++++ src/use_cases/seba_on_arm/test/ponsim/test.sh | 42 +++++++++++++++ 7 files changed, 175 insertions(+), 11 deletions(-) create mode 100644 src/use_cases/seba_on_arm/docker/build/cord-tester/Dockerfile.cord-tester create mode 100755 src/use_cases/seba_on_arm/docker/build/cord-tester/build-cord-tester.arm create mode 100755 src/use_cases/seba_on_arm/docker/build/cord-tester/build-k8s-api-tester.arm delete mode 100755 src/use_cases/seba_on_arm/docker/build/cord-tester/build.arm create mode 100755 src/use_cases/seba_on_arm/test/ponsim/docker_run.sh create mode 100755 src/use_cases/seba_on_arm/test/ponsim/test.sh diff --git a/src/use_cases/seba_on_arm/docker/build/cord-tester/Dockerfile.cord-tester b/src/use_cases/seba_on_arm/docker/build/cord-tester/Dockerfile.cord-tester new file mode 100644 index 0000000..f66ef16 --- /dev/null +++ b/src/use_cases/seba_on_arm/docker/build/cord-tester/Dockerfile.cord-tester @@ -0,0 +1,59 @@ +############################################################################## +# Copyright (c) 2019 AT&T, ENEA AB, Nokia and others # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you maynot 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. # +############################################################################## + +# ref: https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#use-multi-stage-builds + +FROM ubuntu:xenial as build +ENV DIRPATH /workspace +WORKDIR $DIRPATH +# Dependency for kafka pip package; needed for aarch64 image +RUN apt update && apt install -y curl make build-essential +RUN curl -L https://github.com/edenhill/librdkafka/archive/v0.11.6.tar.gz | \ + tar xzf - \ + && cd librdkafka-0.11.6/ \ + && ./configure --prefix=/usr \ + && make -j +RUN curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg > key.gpg + +FROM ubuntu:xenial +ENV DIRPATH /workspace +WORKDIR $DIRPATH + +# Preferred Kubernetes versions 1.13 for IEC Type 2 +ARG KUBE_VERSION=1.13.0-00 +ARG TEST_USER=ubuntu + +COPY --from=build $DIRPATH/librdkafka-0.11.6 librdkafka-0.11.6 +COPY --from=build $DIRPATH/key.gpg key.gpg +RUN apt-key add key.gpg + +# Install packages required by cord-tester +RUN echo "deb http://packages.cloud.google.com/apt kubernetes-xenial main" >\ + /etc/apt/sources.list.d/kubernetes.list +RUN apt update && apt install -y lsb-release openssh-server sudo \ + python python-pip python-dev \ + git make libffi-dev libssl-dev libpq-dev \ + kubectl=$KUBE_VERSION + +RUN make -C librdkafka-0.11.6 install && rm -rf librdkafka-0.11.6 + +RUN pip install virtualenv +RUN apt-mark hold kubectl && apt autoremove -y \ + && rm -rf /var/lib/apt/lists/* +RUN useradd -m -s /bin/bash --system -G sudo \ + -p $(openssl passwd -1 $TEST_USER) $TEST_USER +RUN echo "ubuntu\tALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/90-docker-users +USER $TEST_USER diff --git a/src/use_cases/seba_on_arm/docker/build/cord-tester/build-cord-tester.arm b/src/use_cases/seba_on_arm/docker/build/cord-tester/build-cord-tester.arm new file mode 100755 index 0000000..d7137f1 --- /dev/null +++ b/src/use_cases/seba_on_arm/docker/build/cord-tester/build-cord-tester.arm @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +# This script builds the cord-tester multi-arch docker image. +# The main purpose of this image is to run the cord-tester tests, i.e. SIAB. +# The existing image in iecedge/cord-tester:arm64 also contains the amd64 +# version and specifies a manifest for proper multi-arch. +set -o errexit +set -o xtrace + +docker build -f Dockerfile.cord-tester -t iecedge/cord-tester:arm64 . diff --git a/src/use_cases/seba_on_arm/docker/build/cord-tester/build-k8s-api-tester.arm b/src/use_cases/seba_on_arm/docker/build/cord-tester/build-k8s-api-tester.arm new file mode 100755 index 0000000..6e82d11 --- /dev/null +++ b/src/use_cases/seba_on_arm/docker/build/cord-tester/build-k8s-api-tester.arm @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +# This script can be used to build the cord-tester xos-api-tester docker image +set -o errexit +set -o xtrace + +#cd $CORD-TESTER_PATH + +cd src/test/cord-api/ +docker build -f Dockerfile.k8s-api-tester \ + -t iecedge/xos-api-tester_arm64:master . diff --git a/src/use_cases/seba_on_arm/docker/build/cord-tester/build.arm b/src/use_cases/seba_on_arm/docker/build/cord-tester/build.arm deleted file mode 100755 index 11d2c22..0000000 --- a/src/use_cases/seba_on_arm/docker/build/cord-tester/build.arm +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash - -# This script builds the cord-tester docker image -set -o errexit -set -o xtrace - -#cd $CORD-TESTER_PATH - -#building cord-tester docker image -cd src/test/cord-api/ -docker build -f Dockerfile.k8s-api-tester -t iecedge/xos-api-tester_arm64:master . diff --git a/src/use_cases/seba_on_arm/test/README b/src/use_cases/seba_on_arm/test/README index 1cd68df..dfd973e 100644 --- a/src/use_cases/seba_on_arm/test/README +++ b/src/use_cases/seba_on_arm/test/README @@ -3,3 +3,21 @@ For now we rely on virtualized PON and OLT software, such as BBSim and PONSim. Each folder/testing method should contain an install.sh and test.sh scripts respectively. + +The testing phase consists of two steps: +1. Installing the PON software (for now either bbsim or ponsim). This can be +done by running the corresponding install.sh directly on the K8S master. + +2. Running the actual SIAB tests. In upstream opencord.org the SIAB tests are +run on a single machine (hence the term SEBA-in-a-Box), directly on the +machine. In contrast, the iec project aims to be able to run the SIAB tests +from a different machine, in order to not pollute the environment with +testing framework. To achieve this, it is also necessary to create a running +environment and this is done using a simple Docker container which contains +all the necessary tools for running cord-tester SIAB tests. Take a look at +src/usecases/seba_on_arm/docker/build/cord-tester/build-cord-tester.arm +script for details on this image. +Note that for runing test.sh, it is necessary to obtain the Kubernetes config +(e.g. /root/.kube/) and place it in a convenient location. This will then be +passed to the docker container. Of course, the container must also have +access to the Kubernetes cluster. diff --git a/src/use_cases/seba_on_arm/test/ponsim/docker_run.sh b/src/use_cases/seba_on_arm/test/ponsim/docker_run.sh new file mode 100755 index 0000000..1127cfd --- /dev/null +++ b/src/use_cases/seba_on_arm/test/ponsim/docker_run.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +set -ex + +CORD_REPO="${CORD_REPO:-https://github.com/opencord/cord-tester.git}" +CORD_REV="cord-6.1" +VOLTHA_REPO="${VOLTHA_REPO:-https://github.com/opencord/voltha.git}" +VOLTHA_REV="master" +K8S_MASTER_IP="${K8S_MASTER_IP:-127.0.0.1}" +KUBE_DIR="${KUBE_DIR:-/workspace/.kube}" +USER="${USER:-ubuntu}" + +# The ssh server must be running since cord-tester tries to connect +# to localhost +sudo /etc/init.d/ssh restart +cd "${HOME}" +sudo cp -r "${KUBE_DIR}" .kube +sudo chown -R "$(id -u)":"$(id -g)" .kube + +git clone "${CORD_REPO}" cord-tester -b "${CORD_REV}" +git clone "${VOLTHA_REPO}" voltha -b "${VOLTHA_REV}" + +cd cord-tester/src/test/cord-api +./setup_venv.sh +# shellcheck disable=SC1091 +source venv-cord-tester/bin/activate +# As per documentation, we set the SERVER_IP before anything +sed -i "s/SERVER_IP.*=.*'/SERVER_IP = '${K8S_MASTER_IP}'/g" \ + Properties/RestApiProperties.py +cd Tests/WorkflowValidations/ + +export SERVER_IP="${K8S_MASTER_IP}" + +robot -v ONU_STATE_VAR:onu_state --removekeywords wuks -e notready \ + -i stable -v "VOLTHA_DIR:${HOME}/voltha" SIAB.robot diff --git a/src/use_cases/seba_on_arm/test/ponsim/test.sh b/src/use_cases/seba_on_arm/test/ponsim/test.sh new file mode 100755 index 0000000..7e984f3 --- /dev/null +++ b/src/use_cases/seba_on_arm/test/ponsim/test.sh @@ -0,0 +1,42 @@ +#!/bin/bash +# shellcheck disable=SC2016 + +set -ex + +basepath=$(cd "$(dirname "$0")"; pwd) + +CORD_IMG="${CORD_IMG:-iecedge/cord-tester:latest}" +KUBE_DIR="${KUBE_DIR:-${PWD}/.kube}" +K8S_MASTER_IP="${K8S_MASTER_IP:-127.0.0.1}" +TEST_USER="${TEST_USER:-ubuntu}" + +cont_id= +trap f_clean INT EXIT + +f_clean(){ + echo "Cleaning up after ${cont_id}" + docker kill "${cont_id}" + docker rm "${cont_id}" +} + +if ! [ -d "${KUBE_DIR}" ] +then + echo ".kube dir ${KUBE_DIR} does not exist" + exit 1 +fi + +docker pull "${CORD_IMG}" +DOCKER_CMD="docker run -id -e K8S_MASTER_IP=${K8S_MASTER_IP} \ + -e USER=${TEST_USER} \ + -v ${basepath}/docker_run.sh:/workspace/docker_run.sh \ + -v ${KUBE_DIR}:/workspace/.kube \ + ${CORD_IMG} /bin/bash" +if cont_id=$(eval "${DOCKER_CMD}") +then + echo "Starting SIAB.robot in ${cont_id}" + docker exec "${cont_id}" /workspace/docker_run.sh +else + echo "Failed to execute docker command ${cont_id}" + exit 1 +fi + -- 2.16.6