From: Juha Kosonen Date: Thu, 22 Aug 2019 11:14:03 +0000 (+0300) Subject: Add Robot test for validating Helm charts X-Git-Tag: 2.0.0~50^2 X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F48%2F1448%2F1;p=validation.git Add Robot test for validating Helm charts Uses linter to check charts are well-formed and tests rendering by dry-running the install. JIRA: VAL-43 Change-Id: If0eaaf6d5e5deaf4e9bd2d8fb6303b66d2035a1f Signed-off-by: Juha Kosonen --- diff --git a/docker/README.rst b/docker/README.rst index 4694cde..7179bee 100644 --- a/docker/README.rst +++ b/docker/README.rst @@ -274,3 +274,38 @@ want to enter the container, add */bin/sh* at the end of the command above. Normally, this conainer is not used directly, but instead leveraged via sonobuoy. + +The helm container +================== + +Building and pushing the container +---------------------------------- + +To build just the helm container, use the command: + +.. code-block:: console + + make helm-build [ REGISTRY= NAME=] + +To both build and push the container, use the command: + +.. code-block:: console + + make helm [ REGISTRY= NAME=] + +Using the container +------------------- + +Container needs to be started with the SSH key file mounted. Users +credentials can be provided via a mounted variables.yaml file. + +The results folder can be mounted as well; this way the logs are +stored on the local server. + +.. code-block:: console + + docker run -ti -v /home/jenkins/openrc:/root/openrc \ + -v /home/foobar/.ssh/id_rsa:/root/.ssh/id_rsa \ + -v /home/foobar/variables.yaml:/opt/akraino/validation/tests/variables.yaml \ + -v /home/foobar/helm_results:/opt/akraino/results/ \ + akraino/validation:helm-latest diff --git a/docker/helm/Dockerfile b/docker/helm/Dockerfile new file mode 100644 index 0000000..841d261 --- /dev/null +++ b/docker/helm/Dockerfile @@ -0,0 +1,48 @@ +############################################################################## +# 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 python:3.6-alpine3.9 as build + +# Install dependencies +COPY pip-requirements.txt /wheels/requirements/pip-requirements.txt +RUN apk --no-cache add --update \ + gcc \ + git \ + libc-dev \ + libffi \ + libffi-dev \ + make \ + openssl-dev + +# Build binaries +WORKDIR /wheels +RUN pip3 install wheel +RUN pip3 wheel -r /wheels/requirements/pip-requirements.txt +RUN git clone https://gerrit.akraino.org/r/validation /opt/akraino/validation + +# Copy binaries in the final container and install requirements +FROM python:3.6-alpine3.9 +COPY --from=build /wheels /wheels +COPY --from=build /opt/akraino/validation /opt/akraino/validation + +RUN pip3 install -r /wheels/requirements/pip-requirements.txt \ + -f /wheels && \ + rm -rf /wheels && \ + rm -rf /root/.cache/pip/* + +# Install blueval dependencies +RUN pip install -r /opt/akraino/validation/bluval/requirements.txt diff --git a/docker/helm/Makefile b/docker/helm/Makefile new file mode 100644 index 0000000..a5b4099 --- /dev/null +++ b/docker/helm/Makefile @@ -0,0 +1,23 @@ +############################################################################## +# 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. # +############################################################################## + +.PHONY: all +all: .push_image .push_manifest + +.PHONY: build +build: .build + +include ../build.mk diff --git a/docker/helm/pip-requirements.txt b/docker/helm/pip-requirements.txt new file mode 100644 index 0000000..af1d9bf --- /dev/null +++ b/docker/helm/pip-requirements.txt @@ -0,0 +1,2 @@ +robotframework +robotframework-sshlibrary diff --git a/tests/helm/helm_chart.resource b/tests/helm/helm_chart.resource new file mode 100644 index 0000000..4657ba6 --- /dev/null +++ b/tests/helm/helm_chart.resource @@ -0,0 +1,71 @@ +############################################################################## +# Copyright (c) 2019 AT&T Intellectual Property. # +# Copyright (c) 2019 Nokia. # +# # +# 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. # +############################################################################## + + +*** Settings *** +Library SSHLibrary +Library String + + +*** Variables *** +${REPORTDIR} ${LOG_PATH}${/}${SUITE_NAME.replace(' ','_')} +${CHARTDIR} /tmp/helm-chart +${SERVECMD} helm serve --repo-path /home/${USERNAME}/.helm/repository/local + + +*** Keywords *** +Open Connection And Log In + Open Connection ${HOST} + Login With Public Key ${USERNAME} ${SSH_KEYFILE} + +Start Local Chart Repository Server + Stop Local Chart Repository Server + Start Command ${SERVECMD} + ${rc}= Execute Command pgrep -xf "${SERVECMD}" + ... return_stdout=False + ... return_rc=True + Should Be Equal As Integers ${rc} 0 + +Stop Local Chart Repository Server + Execute Command pkill -xf "${SERVECMD}" + +List Charts In Repositories + ${stdout}= Execute Command helm search --regexp . | tail -n +2 | cut -f1 + @{CHARTS}= Split String ${stdout} + Set Suite Variable @{CHARTS} + +Fetch Charts + Execute Command rm -r ${CHARTDIR} + Execute Command mkdir -p ${CHARTDIR} + :FOR ${chart} IN @{CHARTS} + \ ${rc}= Execute Command helm fetch ${chart} -d ${CHARTDIR} + ... return_stdout=False + ... return_rc=True + \ Should Be Equal As Integers ${rc} 0 + +Lint Charts + @{files}= List Files In Directory ${CHARTDIR} + :FOR ${file} IN @{files} + \ ${stdout}= Execute Command helm lint ${CHARTDIR}/${file} + \ Should Contain ${stdout} 1 chart(s) linted, no failures + +Simulate Install + :FOR ${chart} IN @{CHARTS} + \ ${rc}= Execute Command helm install --dry-run ${chart} + ... return_stdout=False + ... return_rc=True + \ Should Be Equal As Integers ${rc} 0 diff --git a/tests/helm/helm_chart.robot b/tests/helm/helm_chart.robot new file mode 100644 index 0000000..516d44a --- /dev/null +++ b/tests/helm/helm_chart.robot @@ -0,0 +1,36 @@ +############################################################################## +# Copyright (c) 2019 AT&T Intellectual Property. # +# Copyright (c) 2019 Nokia. # +# # +# 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. # +############################################################################## + + +*** Settings *** +Documentation Tests to validate Helm charts available in chart +... repositories. +Resource helm_chart.resource +Suite Setup Run Keywords Open Connection And Log In + ... List Charts In Repositories + ... Start Local Chart Repository Server +Suite Teardown Run Keywords Stop Local Chart Repository Server + ... Close All Connections + + +*** Test Cases *** +Validate Formatting + Fetch Charts + Lint Charts + +Validate Rendering + Simulate Install