From: Cristina Pauna Date: Fri, 10 May 2019 10:40:53 +0000 (+0300) Subject: [Conformance] Add tests to container X-Git-Tag: 2.0.0~87 X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=commitdiff_plain;h=8f8c2d70787bc305df2c2e3b89016d3f5566b823;p=validation.git [Conformance] Add tests to container - Add the validation repo to the k8s container - Add the command to run the test as default in the container - Adapt the conformance test to use the tools inside the container: - SSH library is removed as all the tools are inside the container - The test for sonobuoy and golang are no longer necessary - Test setup is added to check that the k8s conf file is mounted in the container and k8s cluster is reachable - Modified the test to wait for sonobuoy to finish and check for failures - Added teardown to cleanup sonobuoy containers after test is ran - Use absolute paths for files - Log all the result files in one folder that can be mounted as volume in the container for persistence - Save the sonobouy archive in the log folder To test the changes: - copy /etc/kubernetes/admin.conf from k8s cluster to the jumpserver - run the container while mounting the admin.conf file and the results folder JIRA: VAL-18 Change-Id: I8afd2e79775436538e5f3a5d54040a64e05d4c59 Signed-off-by: Cristina Pauna --- diff --git a/conformance/conformance.robot b/conformance/conformance.robot index 1e0e636..a18b56a 100644 --- a/conformance/conformance.robot +++ b/conformance/conformance.robot @@ -1,6 +1,7 @@ ############################################################################## # Copyright (c) 2019 AT&T Intellectual Property. # # Copyright (c) 2019 Nokia. # +# Copyright (c) 2019 Enea AB # # # Licensed under the Apache License, Version 2.0 (the "License"); # # you maynot use this file except in compliance with the License. # @@ -15,61 +16,51 @@ # limitations under the License. # ############################################################################## - *** Settings *** -Documentation Run K8s Conformance Test -Library SSHLibrary +Documentation Run k8s conformance test using sonobuoy Library OperatingSystem Library BuiltIn -Suite Setup Open Connection And Log In -Suite Teardown Close All Connections +Test Setup Check that k8s cluster is reachable +Test Teardown Cleanup Sonobuoy *** Variables *** -${HOST} localhost -${USERNAME} localadmin -${LOG} /opt/akraino/validation/conformance/print_conformance.txt +${RESULT_PATH} /opt/akraino/validation/results/conformance/ +${REPO_PATH} /opt/akraino/validation/repo/conformance/ +${LOG} ${RESULT_PATH}${/}conformance.log *** Test Cases *** -Get Robot Version - [Documentation] Verify Robot - Start Command robot --version - ${stdout}= Read Command Output - Append To File ${LOG} ${stdout}${\n} - Should Contain ${stdout} Robot Framework - -Verify Go Package - [Documentation] Verify Go Package - Start Command hello - ${stdout}= Read Command Output - Append To File ${LOG} ${stdout}${\n} - Should Contain ${stdout} Hello, world! - - -Start Sonobuoy Conformance Test - [Documentation] Test will take about 1hr and 40 mins to complete - ${output}= Execute Command cat /opt/akraino/validation/conformance/sonobuoy.yaml | kubectl apply -f - sudo=True +Run Sonobuoy Conformance Test + # Start the test + Run kubectl apply -f ${REPO_PATH}${/}sonobuoy.yaml + Sleep 5s + ${rc} ${output}= Run And Return Rc And Output + ... kubectl describe pod/sonobuoy -n heptio-sonobuoy Append To File ${LOG} ${output}${\n} - Sleep 3s - Should Contain ${output} pod/sonobuoy created + # Wait until the test finishes execution + Run until sonobuoy status | grep "Sonobuoy has completed"; do sleep 120; done + Append To File ${LOG} "Sonobuoy has completed"${\n} -Description of Sonobuoy Pods - [Documentation] Description of Sonobuoy Pod - ${output} ${rc}= Execute Command kubectl describe pod/sonobuoy -n heptio-sonobuoy return_rc=True sudo=True + # Get the result and store the sonobuoy logs + ${rc} ${output}= Run And Return Rc And Output + ... results=$(sonobuoy retrieve ${RESULT_PATH}) && sonobuoy e2e $results Append To File ${LOG} ${output}${\n} - Should Be Equal As Integers ${rc} 0 + Should Contain ${output} failed tests: 0 +*** Keywords *** +Check that k8s cluster is reachable + # Check that the config file is mounted in the container + File Should Not Be Empty /root/.kube/config -Verify Conformance Test is Running - [Documentation] Conformance Test ongoing - ${output} ${rc}= Execute Command kubectl get pods --all-namespaces -o wide | grep heptio return_rc=True sudo=True + # Make sure the pod is reachable with the local k8s client + ${rc} ${output}= Run And Return Rc And Output + ... kubectl get pods --all-namespaces Append To File ${LOG} ${output}${\n} - Should Be Equal As Integers ${rc} 0 - - - -*** Keywords *** -Open Connection And Log In - Open Connection ${HOST} - Login With Public Key ${USERNAME} /root/.ssh/${USERNAME}_id_rsa + Should Contain ${output} kube-system +Cleanup Sonobuoy + ${rc} ${output}= Run And Return Rc And Output + ... kubectl delete -f ${REPO_PATH}${/}sonobuoy.yaml + Append To File ${LOG} ${output}${\n} + Sleep 3s + Should Contain ${output} service "sonobuoy-master" deleted diff --git a/docker/k8s/Dockerfile b/docker/k8s/Dockerfile index 1d41d00..34bdd7d 100644 --- a/docker/k8s/Dockerfile +++ b/docker/k8s/Dockerfile @@ -48,6 +48,7 @@ RUN if [ $(uname -m) == 'aarch64' ]; then HOST_ARCH=arm64; else HOST_ARCH=amd64; make kubectl ginkgo && \ make WHAT=test/e2e/e2e.test ARCH=$HOST_ARCH RUN go get -u -v github.com/heptio/sonobuoy +RUN git clone https://gerrit.akraino.org/r/validation /opt/akraino/validation/repo WORKDIR /wheels RUN pip3 install wheel @@ -58,8 +59,14 @@ FROM python:3.6-alpine3.9 COPY --from=build /src/k8s.io/kubernetes/_output/bin /usr/local/bin COPY --from=build /go/bin/sonobuoy /bin/sonobuoy COPY --from=build /wheels /wheels +COPY --from=build /opt/akraino/validation/repo /opt/akraino/validation/repo RUN pip3 install -r /wheels/requirements/pip-requirements.txt \ -f /wheels && \ rm -rf /wheels && \ rm -rf /root/.cache/pip/* + +# Set the default command for running the tests +CMD /usr/local/bin/robot --loglevel DEBUG \ + --outputdir /opt/akraino/validation/results/conformance \ + /opt/akraino/validation/repo/conformance/conformance.robot