diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a2914e4348f29c8b212babe26ce720dad0949e86..06637fe73be9fc859529b580914e13007edec0e8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -27,7 +27,7 @@ before_script: - k8srunner before_script: - '[ -f .make/oci.mk ] || exit 1' - - 'make help | grep oci.mk:oci-build' + - 'make help | grep oci-build' - echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY - echo $CAR_OCI_REGISTRY_PASSWORD | docker login -u $CAR_OCI_REGISTRY_USERNAME --password-stdin $CAR_OCI_REGISTRY_HOST script: @@ -555,39 +555,6 @@ test-chart-templates: reports: junit: build/reports/chart_template_tests.xml -test-chart: - stage: test - variables: - MINIKUBE: "false" - tags: - - k8srunner - image: $SKA_K8S_TOOLS_DEPLOY_IMAGE - script: - - kubectl version - - helm version - - make install-chart CAR_OCI_REGISTRY_HOST=${CI_REGISTRY}/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME} - - make wait - - make test - - mkdir -p ./build/reports ./build/htmlcov - - mv build/report.xml ./build/reports/unit-tests.xml - after_script: - - make uninstall-chart - - make delete_namespace - environment: - name: test - kubernetes: - namespace: ci-$CI_PROJECT_NAME-$CI_COMMIT_SHORT_SHA - artifacts: - name: "$CI_PROJECT_NAME-$CI_JOB_ID" - paths: - - "build/" - reports: - junit: build/reports/unit-tests.xml - rules: - - if: '$CI_COMMIT_TAG' - # don't run on master as the new images are not available yet (on Merge) - - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH' - # Custom OCI Image publish stage oci-image-publish: #Executed on a tag for CAR stage: publish @@ -596,7 +563,7 @@ oci-image-publish: #Executed on a tag for CAR - k8srunner before_script: - '[ -f .make/oci.mk ] || (echo "File oci.mk not included in Makefile; exit 1")' - - 'make help | grep oci.mk:oci-publish' + - 'make help | grep oci-publish' - echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY - echo $CAR_OCI_REGISTRY_PASSWORD | docker login -u $CAR_OCI_REGISTRY_USERNAME --password-stdin $CAR_OCI_REGISTRY_HOST script: @@ -613,18 +580,20 @@ include: # Helm Charts - project: 'ska-telescope/templates-repository' - file: 'gitlab-ci/includes/helm-chart.gitlab-ci.yml' - + file: 'gitlab-ci/includes/helm-chart.gitlab-ci.yml' + # Raw - project: 'ska-telescope/templates-repository' file: 'gitlab-ci/includes/raw.gitlab-ci.yml' - ref: master # Docs pages - project: 'ska-telescope/templates-repository' file: 'gitlab-ci/includes/docs-pages.gitlab-ci.yml' - # ref: master # .post step finalisers eg: badges - project: 'ska-telescope/templates-repository' file: 'gitlab-ci/includes/finaliser.gitlab-ci.yml' + +# k8s steps + - project: 'ska-telescope/templates-repository' + file: 'gitlab-ci/includes/k8s.gitlab-ci.yml' diff --git a/.make b/.make index 3147e518066888b16adebc8126f20ccabdf3b42c..b54b8f3d97d4cb9abc8c4441acf3749dcad74bc7 160000 --- a/.make +++ b/.make @@ -1 +1 @@ -Subproject commit 3147e518066888b16adebc8126f20ccabdf3b42c +Subproject commit b54b8f3d97d4cb9abc8c4441acf3749dcad74bc7 diff --git a/LICENSE b/LICENSE index c2650a7735d92b577e6b2d1feb2fc7982effac01..eb4db2a9f535a95f8418b14a3ac394b0da8219fb 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,6 @@ -Copyright 2018 SKA Organisation +BSD 3-Clause License + +Copyright 2021 SKA Observatory Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/Makefile b/Makefile index f1a0e245e753ba6d82bfc6954b2f553e80dd9690..1098078f94638ef77a585ba4b9b65656e95a2cb5 100644 --- a/Makefile +++ b/Makefile @@ -6,42 +6,41 @@ OCI_IMAGES_TO_PUBLISH ?= $(OCI_IMAGES) KUBE_NAMESPACE ?= ska-tango-images#namespace to be used RELEASE_NAME ?= test## release name of the chart -UMBRELLA_CHART_PATH ?= ska-tango-umbrella/## Path of the umbrella chart to work with -# HELM_HOST ?= https://artefact.skatelescope.org # helm host url https +K8S_CHART = ska-tango-umbrella MINIKUBE ?= true ## Minikube or not -MARK ?= all -IMAGE_TO_TEST ?= artefact.skao.int/ska-tango-images-tango-itango:9.3.4 ## TODO: UGUR docker image that will be run for testing purpose +K8S_TEST_IMAGE_TO_TEST ?= artefact.skao.int/ska-tango-images-tango-itango:9.3.7 ## TODO: UGUR docker image that will be run for testing purpose CI_JOB_ID ?= local##pipeline job id TEST_RUNNER ?= test-mk-runner-$(CI_JOB_ID)##name of the pod running the k8s_tests -TANGO_HOST ?= tango-host-databaseds-from-makefile-$(RELEASE_NAME):10000## TANGO_HOST is an input! -CHARTS ?= ska-tango-util ska-tango-base ska-tango-umbrella## list of charts to be published on gitlab -- umbrella charts for testing purpose -# LINTING_OUTPUT=$(shell helm lint --with-subcharts $(UMBRELLA_CHART_PATH) | grep ERROR -c | tail -1) +TANGO_HOST ?= my-personal-databaseds-also-node-port:10000## TANGO_HOST connection to the Tango DS +TANGO_SERVER_PORT ?= 45450## TANGO_SERVER_PORT - fixed listening port for local server +K8S_CHARTS ?= ska-tango-util ska-tango-base ska-tango-umbrella## list of charts to be published on gitlab -- umbrella charts for testing purpose CI_PROJECT_PATH_SLUG ?= ska-tango-images CI_ENVIRONMENT_SLUG ?= ska-tango-images +# K8S_TEST_MAKE_PARAMS = KUBE_NAMESPACE=$(KUBE_NAMESPACE) HELM_RELEASE=$(RELEASE_NAME) TANGO_HOST=$(TANGO_HOST) MARK=$(MARK) +# K8S_CHART_PARAMS = --set global.minikube=$(MINIKUBE) --set global.tango_host=$(TANGO_HOST) --values $(BASE)/charts/values.yaml + +PYTHON_VARS_BEFORE_PYTEST = PYTHONPATH=/app:/app/tests KUBE_NAMESPACE=$(KUBE_NAMESPACE) HELM_RELEASE=$(RELEASE_NAME) TANGO_HOST=$(TANGO_HOST) + +PYTHON_VARS_AFTER_PYTEST = --disable-pytest-warnings --timeout=300 + RELEASE_SUPPORT := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))/.make-release-support # include OCI Images support include .make/oci.mk +# include k8s support +include .make/k8s.mk + # include Helm Chart support include .make/helm.mk -# include make support -include .make/make.mk - -# include help support -include .make/help.mk - -# include core release support -include .make/release.mk - # include raw support include .make/raw.mk -# include docs support -include .make/docs.mk +# include core make support +include .make/base.mk # include your own private variables for custom deployment configuration -include PrivateRules.mak @@ -91,13 +90,17 @@ make-a-release: ## Step through the process of bumping .release and creating a t @printf "\nStep 2: Select and bump OCI Image .release's \n Tell me which of the following OCI_IMAGES_TO_PUBLISH list to bump patch release for: $(OCI_IMAGES_TO_PUBLISH)\n"; \ read -p "$(POWDER_BLUE)Enter list here$(NORMAL): " OCI_IMAGES_TO_RELEASE; \ printf "\n You provided: $${OCI_IMAGES_TO_RELEASE}\n"; \ - read -p "$(POWDER_BLUE)Do you wish to continue (you will be prompted at each step)$(NORMAL) $(YELLOW)[N/y]$(NORMAL): " SHALL_WE; \ + read -p "$(POWDER_BLUE)Do you wish to continue (you will be prompted at each step)$(NORMAL) $(YELLOW)[N=No/s=skip/y=yes]$(NORMAL): " SHALL_WE; \ if [[ "y" == "$${SHALL_WE}" ]] || [[ "Y" == "$${SHALL_WE}" ]]; then \ - echo "$(GREEN) OK - ✨ bumping patch .release files ...$(NORMAL)"; \ + echo "$(GREEN) OK - ✨ bumping patch for .release files ...$(NORMAL)"; \ make oci-bump-patch-release OCI_IMAGES_TO_PUBLISH="$${OCI_IMAGES_TO_RELEASE}"; \ else \ - printf "$(RED) 😱 OK - aborting$(NORMAL).\n 💀"; \ - exit 1; \ + if [[ "s" == "$${SHALL_WE}" ]] || [[ "S" == "$${SHALL_WE}" ]]; then \ + echo "$(YELLOW) OK - 👍 Skipping bumping patch for .release files ...$(NORMAL)"; \ + else \ + printf "$(RED) 😱 OK - aborting$(NORMAL).\n 💀"; \ + exit 1; \ + fi; \ fi; @printf "\nStep 3: Bump project .release AND update Helm Chart release\n"; \ @@ -149,22 +152,6 @@ k8s: ## Which kubernetes are we connected to @echo "Helm version:" @helm version --client -namespace: ## create the kubernetes namespace - @kubectl describe namespace $(KUBE_NAMESPACE) > /dev/null 2>&1 ; \ - K_DESC=$$? ; \ - if [ $$K_DESC -eq 0 ] ; \ - then kubectl describe namespace $(KUBE_NAMESPACE); \ - else kubectl create namespace $(KUBE_NAMESPACE); \ - fi - -delete_namespace: ## delete the kubernetes namespace - @if [ "default" = "$(KUBE_NAMESPACE)" ] || [ "kube-system" = "$(KUBE_NAMESPACE)" ]; then \ - echo "You cannot delete Namespace: $(KUBE_NAMESPACE)"; \ - exit 1; \ - else \ - kubectl describe namespace $(KUBE_NAMESPACE) && kubectl delete namespace $(KUBE_NAMESPACE); \ - fi - package: helm-pre-publish ## package charts @echo "Packaging helm charts. Any existing file won't be overwritten."; \ mkdir -p ./tmp @@ -181,128 +168,21 @@ helm-pre-publish: ## hook before helm chart publish helm-pre-lint: helm-pre-publish ## make sure auto-generate values.yaml happens -dep-up: helm-pre-publish ## update dependencies for every charts in the env var CHARTS - @cd charts; \ - for i in $(CHARTS); do \ - helm dependency update $${i}; \ - done; - -install-chart: clean dep-up namespace## install the helm chart with name RELEASE_NAME and path UMBRELLA_CHART_PATH on the namespace KUBE_NAMESPACE - @cd charts; \ - sed -e 's/CI_PROJECT_PATH_SLUG/$(CI_PROJECT_PATH_SLUG)/' ci-values.yaml > generated_values.yaml; \ - sed -e 's/CI_ENVIRONMENT_SLUG/$(CI_ENVIRONMENT_SLUG)/' generated_values.yaml > values.yaml; \ - helm install $(RELEASE_NAME) \ - --set global.minikube=$(MINIKUBE) \ - --set global.tango_host=$(TANGO_HOST) \ - --values values.yaml \ - $(UMBRELLA_CHART_PATH) --namespace $(KUBE_NAMESPACE); \ - rm generated_values.yaml; \ - rm values.yaml - -template-chart: clean dep-up## install the helm chart with name RELEASE_NAME and path UMBRELLA_CHART_PATH on the namespace KUBE_NAMESPACE - @cd charts; \ - sed -e 's/CI_PROJECT_PATH_SLUG/$(CI_PROJECT_PATH_SLUG)/' ci-values.yaml > generated_values.yaml; \ - sed -e 's/CI_ENVIRONMENT_SLUG/$(CI_ENVIRONMENT_SLUG)/' generated_values.yaml > values.yaml; \ - helm template $(RELEASE_NAME) \ - --set global.minikube=$(MINIKUBE) \ - --set global.tango_host=$(TANGO_HOST) \ - --values values.yaml \ - --debug \ - $(UMBRELLA_CHART_PATH) --namespace $(KUBE_NAMESPACE); \ - rm generated_values.yaml; \ - rm values.yaml - -uninstall-chart: ## uninstall the ska-tango-images helm chart on the namespace ska-tango-images +# use pre update hook to update chart values +k8s-pre-install-chart: + make helm-pre-publish + @echo "k8s-pre-install-chart: setting up charts/values.yaml" @cd charts; \ sed -e 's/CI_PROJECT_PATH_SLUG/$(CI_PROJECT_PATH_SLUG)/' ci-values.yaml > generated_values.yaml; \ - sed -e 's/CI_ENVIRONMENT_SLUG/$(CI_ENVIRONMENT_SLUG)/' generated_values.yaml > values.yaml; \ - helm template $(RELEASE_NAME) \ - --set global.minikube=$(MINIKUBE) \ - --set global.tango_host=$(TANGO_HOST) \ - --values values.yaml \ - $(UMBRELLA_CHART_PATH) --namespace $(KUBE_NAMESPACE) | kubectl delete -f - ; \ - rm generated_values.yaml; \ - rm values.yaml; \ - helm uninstall $(RELEASE_NAME) --namespace $(KUBE_NAMESPACE) - -reinstall-chart: uninstall-chart install-chart ## reinstall the ska-tango-images helm chart on the namespace ska-tango-images - -# chart_lint: clean dep-up## lint check the helm chart -# mkdir -p build; helm lint $(UMBRELLA_CHART_PATH) --with-subcharts --namespace $(KUBE_NAMESPACE); \ -# echo "<testsuites><testsuite errors=\"$(LINTING_OUTPUT)\" failures=\"0\" name=\"helm-lint\" skipped=\"0\" tests=\"0\" time=\"0.000\" timestamp=\"$(shell date)\"> </testsuite> </testsuites>" > build/linting.xml -# exit $(LINTING_OUTPUT) - -wait: ## wait for pods to be ready - @echo "Waiting for pods to be ready" - @date - @kubectl -n $(KUBE_NAMESPACE) get pods - #jobs=$$(kubectl get job --output=jsonpath={.items..metadata.name} -n $(KUBE_NAMESPACE)); kubectl wait job --for=condition=complete --timeout=900s $$jobs -n $(KUBE_NAMESPACE) - @kubectl -n $(KUBE_NAMESPACE) wait --for=condition=ready -l app=ska-tango-images --timeout=900s pods || exit 1 - @date - -# -# defines a function to copy the ./test-harness directory into the K8s TEST_RUNNER -# and then runs the requested make target in the container. -# capture the output of the test in a tar file -# stream the tar file base64 encoded to the Pod logs -# -k8s_test = tar -c tests/post-deployment/ | \ - kubectl run $(TEST_RUNNER) \ - --namespace $(KUBE_NAMESPACE) -i --wait --restart=Never \ - --image-pull-policy=IfNotPresent \ - --image=$(IMAGE_TO_TEST) \ - --limits='cpu=1000m,memory=500Mi' \ - --requests='cpu=900m,memory=400Mi' -- \ - /bin/bash -c "mkdir testing && tar xv --directory testing --strip-components 2 --warning=all && cd testing && \ - make KUBE_NAMESPACE=$(KUBE_NAMESPACE) HELM_RELEASE=$(RELEASE_NAME) TANGO_HOST=$(TANGO_HOST) MARK=$(MARK) $1 && \ - tar -czvf /tmp/build.tgz build && \ - echo '~~~~BOUNDARY~~~~' && \ - cat /tmp/build.tgz | base64 && \ - echo '~~~~BOUNDARY~~~~'" \ - 2>&1 - -# call 'k8s_test' and pass it arg 'test' - look for $1 -# run the test function -# save the status -# clean out build dir -# print the logs minus the base64 encoded payload -# pull out the base64 payload and unpack build/ dir -# base64 payload is given a boundary "~~~~BOUNDARY~~~~" and extracted using perl -# clean up the run to completion container -# exit the saved status -test: helm-pre-publish ## test the application on K8s - cp charts/ska-tango-base/values.yaml tests/post-deployment/tango_values.yaml; \ - $(call k8s_test,test); \ - status=$$?; \ - rm -fr build; \ - kubectl --namespace $(KUBE_NAMESPACE) logs $(TEST_RUNNER) | \ - perl -ne 'BEGIN {$$on=0;}; if (index($$_, "~~~~BOUNDARY~~~~")!=-1){$$on+=1;next;}; print if $$on % 2;' | \ - base64 -d | tar -xzf -; \ - kubectl --namespace $(KUBE_NAMESPACE) delete pod $(TEST_RUNNER); \ - rm tests/post-deployment/tango_values.yaml; \ - echo "Status set at \"$$status\" in ./Makefile test target"; \ - exit $$status - -chart_test: helm-pre-publish #clean dep-up - helm package charts/ska-tango-util/ -d charts/ska-tango-base/charts/; \ - mkdir -p charts/build; helm unittest charts/ska-tango-base/ --helm3 --with-subchart --output-type JUnit --output-file charts/build/chart_template_tests.xml; \ - -show: - echo $$TANGO_HOST + sed -e 's/CI_ENVIRONMENT_SLUG/$(CI_ENVIRONMENT_SLUG)/' generated_values.yaml > values.yaml +k8s-pre-template-chart: + make helm-pre-publish -# OCI_SUPPORT := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))/.make/.make-oci-support +k8s-pre-test: + @echo "k8s-pre-test: setting up tests/values.yaml" + cp charts/ska-tango-base/values.yaml tests/tango_values.yaml -# xoci-publish: -# @. $(OCI_SUPPORT) ; \ -# OCI_NEXUS_REPO=$(OCI_NEXUS_REPO) \ -# ociImageExists "$(OCI_IMAGE)" "$(VERSION)" && (echo "oci-publish:WARNING: $(CAR_OCI_REGISTRY_HOST)/$(OCI_IMAGE):$(VERSION) already exists, skipping " >&2; exit 0) ; -# # pull GitLab registry version and then push to CAR -# @echo "oci-do-publish: Pulling $${CI_REGISTRY}/$${CI_PROJECT_NAMESPACE}/$${CI_PROJECT_NAME}/$(OCI_IMAGE):$(VERSION)-dev.$${CI_COMMIT_SHORT_SHA}" -# $(OCI_BUILDER) pull $${CI_REGISTRY}/$${CI_PROJECT_NAMESPACE}/$${CI_PROJECT_NAME}/$(OCI_IMAGE):$(VERSION)-dev.$${CI_COMMIT_SHORT_SHA} -# $(OCI_BUILDER) tag $${CI_REGISTRY}/$${CI_PROJECT_NAMESPACE}/$${CI_PROJECT_NAME}/$(OCI_IMAGE):$(VERSION)-dev.$${CI_COMMIT_SHORT_SHA} $(CAR_OCI_REGISTRY_HOST)/$(OCI_IMAGE):$(VERSION) -# @echo "oci-do-publish: Pushing to $(CAR_OCI_REGISTRY_HOST)/$(OCI_IMAGE):$(VERSION)" -# $(OCI_BUILDER) push $(CAR_OCI_REGISTRY_HOST)/$(OCI_IMAGE):$(VERSION) - -# xoci-publish-all: ## Publish all OCI Images in OCI_IMAGES_TO_PUBLISH -# $(foreach ociimage,$(OCI_IMAGES_TO_PUBLISH), make xoci-publish OCI_IMAGE=$(ociimage);) +chart_test: helm-pre-publish + helm package charts/ska-tango-util/ -d charts/ska-tango-base/charts/; \ + mkdir -p charts/build; helm unittest charts/ska-tango-base/ --helm3 --with-subchart --output-type JUnit --output-file charts/build/chart_template_tests.xml; \ diff --git a/charts/ska-tango-base/values.yaml.sh b/charts/ska-tango-base/values.yaml.sh index c7142f1fd47cb0c8bfea7dd878cb1aacc8533df4..fab22f1c869a9fd051dac06d564c4234b567b658 100644 --- a/charts/ska-tango-base/values.yaml.sh +++ b/charts/ska-tango-base/values.yaml.sh @@ -107,14 +107,14 @@ databaseds: memory: 256Mi # 256Mi = 0.25 GB mem ephemeral-storage: 1Gi livenessProbe: - enabled: false + enabled: true initialDelaySeconds: 0 periodSeconds: 10 timeoutSeconds: 1 successThreshold: 1 failureThreshold: 3 readinessProbe: - enabled: false + enabled: true initialDelaySeconds: 0 periodSeconds: 10 timeoutSeconds: 1 @@ -194,14 +194,14 @@ tangodb: ephemeral-storage: 2Gi livenessProbe: enabled: false - initialDelaySeconds: 0 + initialDelaySeconds: 10 periodSeconds: 10 timeoutSeconds: 1 successThreshold: 1 failureThreshold: 3 readinessProbe: enabled: false - initialDelaySeconds: 0 + initialDelaySeconds: 10 periodSeconds: 10 timeoutSeconds: 1 successThreshold: 1 diff --git a/charts/ska-tango-umbrella/Chart.yaml b/charts/ska-tango-umbrella/Chart.yaml index 1572eddc030ac89c35b63f178dc98b4ee561ab67..46726b2a9cb0a9cf622aa03a0b118cc938032f11 100644 --- a/charts/ska-tango-umbrella/Chart.yaml +++ b/charts/ska-tango-umbrella/Chart.yaml @@ -6,10 +6,10 @@ version: 0.2.0 icon: https://www.skatelescope.org/wp-content/uploads/2016/07/09545_NEW_LOGO_2014.png dependencies: - name: ska-tango-base - version: 0.3.0 + version: 0.3.2 repository: file://../ska-tango-base condition: ska-tango-base.enabled,global.sub-system.ska-tango-base.enabled - name: ska-tango-util - version: 0.3.0 + version: 0.3.2 repository: file://../ska-tango-util diff --git a/charts/ska-tango-util/templates/_configuration.yaml b/charts/ska-tango-util/templates/_configuration.yaml index 7655b6205757e216e0c42485b1a5d42e438450f4..2cd8c01e19a9edf38df9a56125b174178a6f1ffd 100644 --- a/charts/ska-tango-util/templates/_configuration.yaml +++ b/charts/ska-tango-util/templates/_configuration.yaml @@ -87,7 +87,7 @@ metadata: annotations: {{ toYaml (coalesce .Values.global.annotations .Values.annotations "annotations:none") | indent 4 }} spec: - ttlSecondsAfterFinished: 100 + ttlSecondsAfterFinished: 3600 template: spec: initContainers: diff --git a/charts/ska-tango-util/templates/_multidevice-job.yaml b/charts/ska-tango-util/templates/_multidevice-job.yaml index c894e5a358cd61e1d7177a930e19cba9b068f981..25606a96472452850684d10b1db44a8c4960b63e 100644 --- a/charts/ska-tango-util/templates/_multidevice-job.yaml +++ b/charts/ska-tango-util/templates/_multidevice-job.yaml @@ -23,7 +23,7 @@ metadata: annotations: {{ toYaml $annotations | indent 4 }} spec: - ttlSecondsAfterFinished: 100 + ttlSecondsAfterFinished: 3600 template: spec: initContainers: diff --git a/images/ska-tango-images-pytango-builder-alpine/Dockerfile b/images/ska-tango-images-pytango-builder-alpine/Dockerfile index 206002e6cd0bee06d3df6221cf33a6d4b09ddb9e..d96ec5c981879e757db53a5f5e1b4b7029bb13aa 100644 --- a/images/ska-tango-images-pytango-builder-alpine/Dockerfile +++ b/images/ska-tango-images-pytango-builder-alpine/Dockerfile @@ -2,6 +2,14 @@ ARG CAR_OCI_REGISTRY_HOST ARG BASE_IMAGE="${CAR_OCI_REGISTRY_HOST}/ska-tango-images-tango-cpp-alpine:0.0.0" FROM $BASE_IMAGE +LABEL \ + author="Piers Harding <Piers.Harding@skao.int>" \ + description="This image illustrates build dependencies" \ + license="Apache2.0" \ + int.skao.team="Systems Team" \ + int.skao.website="https://gitlab.com/ska-telescope/sdi/ska-ser-containerisation-and-orchestration" \ + int.skao.application="Tango Builder" + USER root # pkgconfig needs to find these ENV PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/local/lib64/pkgconfig @@ -12,7 +20,9 @@ ENV LD_LIBRARY_PATH=/usr/local/lib64:/usr/local/lib:/usr/lib RUN apk --update add --no-cache libstdc++ \ g++ \ libsodium-dev \ + libffi-dev \ zlib-dev \ + boost \ boost-dev \ python3-dev \ py3-pip \ @@ -20,7 +30,8 @@ RUN apk --update add --no-cache libstdc++ \ py3-cryptography \ bash \ make \ - ca-certificates \ + ca-certificates \ + cargo \ curl \ git @@ -31,14 +42,14 @@ WORKDIR /app COPY requirements.txt requirements.txt # Install numpy manually before PyTango and other requirements to ensure we -# build PyTango with numpy support. +# build PyTango with numpy support. RUN python3.9 -m pip install --prefix=/usr/local numpy==1.21.0 \ # now install build requirements && python3.9 -m pip install --prefix=/usr/local -r requirements.txt \ # this should be commented if we wish for the builder # to keep the python cache - && python3.9 -m pip cache purge - + && python3.9 -m pip cache purge + # do ldconfig stuff RUN mkdir -p /etc/ld.so.conf.d \ && echo "include /etc/ld.so.conf.d/*.conf" > /etc/ld.so.conf \ diff --git a/images/ska-tango-images-pytango-builder-alpine/requirements.txt b/images/ska-tango-images-pytango-builder-alpine/requirements.txt index fe25c0342558c834fe63fc0f94e2caa21c288440..278a9915e601f0b84296006d5ad12593227d9594 100644 --- a/images/ska-tango-images-pytango-builder-alpine/requirements.txt +++ b/images/ska-tango-images-pytango-builder-alpine/requirements.txt @@ -2,6 +2,9 @@ numpy==1.21.0 pytango==9.3.3 flake8 flake8_formatter_junit_xml +isort +black +poetry ipython==7.27.0 itango==0.1.8 coverage @@ -9,6 +12,7 @@ docutils MarkupSafe Pygments pylint +pylint-junit pytest pytest-bdd pytest-cov diff --git a/images/ska-tango-images-pytango-builder/requirements.txt b/images/ska-tango-images-pytango-builder/requirements.txt index d7660ec58f4b3e88a1ac868c8af4c79f22599c73..432fed97f0aecc541c154b7b15db57389f8d9b74 100644 --- a/images/ska-tango-images-pytango-builder/requirements.txt +++ b/images/ska-tango-images-pytango-builder/requirements.txt @@ -2,6 +2,9 @@ numpy==1.19.2 pytango==9.3.3 flake8 flake8_formatter_junit_xml +isort +black +poetry ipython==7.21.0 itango==0.1.8 coverage @@ -9,6 +12,7 @@ docutils MarkupSafe Pygments pylint +pylint-junit pytest pytest-bdd pytest-cov diff --git a/images/ska-tango-images-tango-db-alpine/Dockerfile b/images/ska-tango-images-tango-db-alpine/Dockerfile index 9c5e5136ccff6a6866dd7b819ab44ed2d74dba99..c1ca1ffdf3339b68cdea19042d70fa9253e3f429 100644 --- a/images/ska-tango-images-tango-db-alpine/Dockerfile +++ b/images/ska-tango-images-tango-db-alpine/Dockerfile @@ -41,3 +41,4 @@ COPY --from=buildenv /docker-entrypoint-initdb.d /docker-entrypoint-initdb.d COPY sql_mode.cnf /etc/mysql/conf.d RUN chmod 644 /etc/mysql/conf.d/sql_mode.cnf ENTRYPOINT ["/scripts/run.sh"] + diff --git a/images/ska-tango-images-tango-db/Dockerfile b/images/ska-tango-images-tango-db/Dockerfile index c71afbe58a30889238c4b95e9118f24360b0c9d8..7da5daf7aaca9f8d2ef45f08424a37273a093737 100644 --- a/images/ska-tango-images-tango-db/Dockerfile +++ b/images/ska-tango-images-tango-db/Dockerfile @@ -41,4 +41,5 @@ LABEL \ COPY --from=builder /docker-entrypoint-initdb.d /docker-entrypoint-initdb.d COPY sql_mode.cnf /etc/mysql/conf.d -RUN chmod 644 /etc/mysql/conf.d/sql_mode.cnf \ No newline at end of file +RUN chmod 644 /etc/mysql/conf.d/sql_mode.cnf + diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..deb62a6d53e4296587c5363dbb67b740f35f5d15 --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,25 @@ +# Use bash shell with pipefail option enabled so that the return status of a +# piped command is the value of the last (rightmost) commnand to exit with a +# non-zero status. This lets us pipe output into tee but still exit on test +# failures. +SHELL = /bin/bash +.SHELLFLAGS = -o pipefail -c + +MARK ?= fast## this variable allow the mark parameter in the pytest +FILE ?= ##this variable allow to execution of a single file in the pytest +SLEEPTIME ?= 1200s ##amount of sleep time for the smoketest target +COUNT ?= 1## amount of repetition for pytest-repeat + + +all: test + +.PHONY: test + +test: + echo "Inside the test" + mkdir -p build && \ + find . -name "*.pyc" -type f -delete && \ + PYTHONPATH=/app:/app/tests:/app/tests/post-deployment pytest $(if $(findstring all,$(MARK)),, -m $(MARK)) --disable-pytest-warnings | tee pytest.stdout; \ + status=$$?; \ + echo "test: status is ($$status)"; \ + exit $$status diff --git a/tests/post-deployment/SUT_requirements.txt b/tests/SUT_requirements.txt similarity index 100% rename from tests/post-deployment/SUT_requirements.txt rename to tests/SUT_requirements.txt diff --git a/tests/post-deployment/features/archiver.feature b/tests/features/archiver.feature similarity index 100% rename from tests/post-deployment/features/archiver.feature rename to tests/features/archiver.feature diff --git a/tests/post-deployment/features/tango-commands.feature b/tests/features/tango-commands.feature similarity index 100% rename from tests/post-deployment/features/tango-commands.feature rename to tests/features/tango-commands.feature diff --git a/tests/post-deployment/features/tango-db.feature b/tests/features/tango-db.feature similarity index 84% rename from tests/post-deployment/features/tango-db.feature rename to tests/features/tango-db.feature index 7d518eecd4410dc884b05243fd757ee4addaf8de..062b55e967b65310b014a40040c9902523a2018e 100644 --- a/tests/post-deployment/features/tango-db.feature +++ b/tests/features/tango-db.feature @@ -3,7 +3,7 @@ Feature: tango-db Test tango db connection Scenario: Test mysql connection - Given Tango env tango_values.yaml + Given Tango env tests/tango_values.yaml When I extract the DB config in the databaseds-tango-base-{{.Release.Name}} Then I check the tango database connection diff --git a/tests/post-deployment/features/tango_tools.feature b/tests/features/tango_tools.feature similarity index 100% rename from tests/post-deployment/features/tango_tools.feature rename to tests/features/tango_tools.feature diff --git a/tests/post-deployment/.gitignore b/tests/post-deployment/.gitignore deleted file mode 100644 index 12fb62e8f55ab1913359afc7a046f4f2ffd5eef1..0000000000000000000000000000000000000000 --- a/tests/post-deployment/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -Pipfile -Pipfile.lock \ No newline at end of file diff --git a/tests/post-deployment/Makefile b/tests/post-deployment/Makefile deleted file mode 100644 index 50db3989b14cc77ac23be8570d1325fda11254de..0000000000000000000000000000000000000000 --- a/tests/post-deployment/Makefile +++ /dev/null @@ -1,30 +0,0 @@ -# Use bash shell with pipefail option enabled so that the return status of a -# piped command is the value of the last (rightmost) commnand to exit with a -# non-zero status. This lets us pipe output into tee but still exit on test -# failures. -SHELL = /bin/bash -.SHELLFLAGS = -o pipefail -c - -TEST_ARTIFACTS = pytest.stdout report.xml report.json cucumber.json pytest-logs.txt - -all: test - -# create the build directory -# execute the python tests -# copy TEST_ARTIFACTS into build directory -# exit with same exit code as test run -test: install - mkdir -p build && \ - find . -name "*.pyc" -type f -delete && \ - PYTHONPATH=/app:/app/testing:/app/testing/post-deployment pytest $(if $(findstring all,$(MARK)),, -m $(MARK)) --disable-pytest-warnings | tee pytest.stdout; \ - status=$$?; \ - echo "Status set at \"$$status\" in post-deployment/Makefile test target"; \ - $(foreach artfct,$(TEST_ARTIFACTS),mv -f $(artfct) build/;) \ - exit $$status - -.PHONY: all test install - -install: - pip3 install -r test_requirements.txt; - # @echo "############ post-deployment/test_requirements.txt versions not necessarily fixed - see build/python_packages_installed_for_test.pip3 ###############" - # @pip3 list >> python_packages_installed_for_test.pip3 diff --git a/tests/post-deployment/resources/_old/Makefile b/tests/post-deployment/resources/_old/Makefile deleted file mode 100644 index a963fc1c1f492264b3d727c35a953c437549ab59..0000000000000000000000000000000000000000 --- a/tests/post-deployment/resources/_old/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -all: test - -test: - [ -f /.dockerenv ] && sudo apt-get update && sudo apt-get -y install --no-install-recommends curl || true - # It takes several seconds for the Tango database to be populated from - # scratch, so pause until DB is created and the device we test against is - # responsive. If the Tango DB volume already exists, there'll be no delay - # at all and the test will run immediately. - retry -- tango_admin --check-device sys/tg_test/1 - /usr/local/bin/wait-for-it.sh rest:8080 --timeout=30 --strict -- curl --user tango-cs:tango http://rest:8080/tango/rest/rc4/hosts/databaseds/10000/devices/sys/tg_test/1/attributes/boolean_scalar/value - -.PHONY: all test - diff --git a/tests/post-deployment/resources/_old/script.exp b/tests/post-deployment/resources/_old/script.exp deleted file mode 100755 index d560527f63eaca1dc57ce4c1a9e72d6f3383146b..0000000000000000000000000000000000000000 --- a/tests/post-deployment/resources/_old/script.exp +++ /dev/null @@ -1,84 +0,0 @@ -#!/usr/bin/expect -f -# -# This Expect script was generated by autoexpect on Thu Nov 15 09:12:55 2018 -# Expect and autoexpect were both written by Don Libes, NIST. -# -# Note that autoexpect does not guarantee a working script. It -# necessarily has to guess about certain things. Two reasons a script -# might fail are: -# -# 1) timing - A surprising number of programs (rn, ksh, zsh, telnet, -# etc.) and devices discard or ignore keystrokes that arrive "too -# quickly" after prompts. If you find your new script hanging up at -# one spot, try adding a short sleep just before the previous send. -# Setting "force_conservative" to 1 (see below) makes Expect do this -# automatically - pausing briefly before sending each character. This -# pacifies every program I know of. The -c flag makes the script do -# this in the first place. The -C flag allows you to define a -# character to toggle this mode off and on. - -set force_conservative 0 ;# set to 1 to force conservative mode even if - ;# script wasn't run conservatively originally -if {$force_conservative} { - set send_slow {1 .1} - proc send {ignore arg} { - sleep .1 - exp_send -s -- $arg - } -} - -# -# 2) differing output - Some programs produce different output each time -# they run. The "date" command is an obvious example. Another is -# ftp, if it produces throughput statistics at the end of a file -# transfer. If this causes a problem, delete these patterns or replace -# them with wildcards. An alternative is to use the -p flag (for -# "prompt") which makes Expect only look for the last line of output -# (i.e., the prompt). The -P flag allows you to define a character to -# toggle this mode off and on. -# -# Read the man page for more info. -# -# -Don - -set timeout 2 -spawn /venv/bin/itango3 --no-color-info --simple-prompt --no-banner -match_max 100000 - -expect { - timeout { send_user "Problem starting itango session"; exit 1 } - -ex "In \[1\]: " { } -} - -send "dev = Device('sys/tg_test/1')\r" -expect { - timeout { send_user "\nCould not create device proxy to TangoTest device\n"; exit 1 } - -ex "dev = Device('sys/tg_test/1')\r\n\r\nIn \[2\]: " {} -} - -send "dev.status()\r" -expect { - timeout { send_user "\nTangoTest device is in unexpected state\n"; exit 1 } - -ex "dev.status()\r\nOut\[2\]: 'The device is in RUNNING state.'\r\n\r\nIn \[3\]: " {} -} - -send "dev.DevString('hello world!')\r" -expect { - timeout { send_user "\nFailure executing command\n"; exit 1 } - -ex "dev.DevString('hello world!')\r\nOut\[3\]: 'hello world!'\r\n\r\nIn \[4\]: " {} -} - -send "import numpy; isinstance(dev.read_attribute('short_spectrum_ro').value, numpy.ndarray)\r" -expect { - timeout { send_user "\nFailure executing command\n"; exit 1 } - -ex "import numpy; isinstance(dev.read_attribute('short_spectrum_ro').value, numpy.ndarray)\r\nOut\[4\]: True\r\n\r\nIn \[5\]: " {} -} - -send "import numpy; isinstance(dev.read_attribute('short_spectrum').value, numpy.ndarray)\r" -expect { - timeout { send_user "\nFailure executing command\n"; exit 1 } - -ex "import numpy; isinstance(dev.read_attribute('short_spectrum').value, numpy.ndarray)\r\nOut\[5\]: True\r\n\r\nIn \[6\]: " {} -} - -send "exit\r" -expect eof diff --git a/tests/post-deployment/resources/_old/test-tango-admin.sh b/tests/post-deployment/resources/_old/test-tango-admin.sh deleted file mode 100755 index 70a29a6bbdcf7b739798f0beb00a1be82532986c..0000000000000000000000000000000000000000 --- a/tests/post-deployment/resources/_old/test-tango-admin.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash - -export TANGO_HOST=databaseds:10000 - -tango_admin --ping-database 20 -result=$? - -if [ $result -eq 0 ] -then - echo "PASSED ping database" -else - echo "ERROR ping database" - exit 1 -fi - - -tango_admin --check-device sys/tg_test/1 -result=$? - -if [ $result -eq 0 ] -then - echo "PASSED check device tg_test" -else - echo "ERROR check device tg_test" - exit 1 -fi - -tango_admin --check-device sys/database/2 -result=$? - -if [ $result -eq 0 ] -then - echo "PASSED check device database" -else - echo "ERROR check device database" - exit 1 -fi diff --git a/tests/post-deployment/resources/_old/test_archiver.py b/tests/post-deployment/resources/_old/test_archiver.py deleted file mode 100644 index 2b58a985496b03af0867bc716101841febb027a0..0000000000000000000000000000000000000000 --- a/tests/post-deployment/resources/_old/test_archiver.py +++ /dev/null @@ -1,71 +0,0 @@ -import tango -from tango import DevFailed, DeviceProxy, GreenMode, AttributeProxy -import time -from time import sleep -import pytest -import logging - -def test_cm_device_is_ON(): - tango_test = tango.DeviceProxy("archiving/hdbpp/confmanager01") - time.sleep(2) - assert tango_test.state() == tango.DevState.ON - -def test_es_device_is_ON(): - tango_test = tango.DeviceProxy("archiving/hdbpp/eventsubscriber01") - time.sleep(2) - assert tango_test.state() == tango.DevState.ON - -def test_archiving(): - evt_subscriber_device_fqdn = "archiving/hdbpp/eventsubscriber01" - config_manager_device_fqdn = "archiving/hdbpp/confmanager01" - conf_manager_proxy = DeviceProxy(config_manager_device_fqdn) - evt_subscriber_device_proxy = DeviceProxy(evt_subscriber_device_fqdn) - - conf_manager_proxy.set_timeout_millis(5000) - evt_subscriber_device_proxy.set_timeout_millis(5000) - - attribute = "sys/tg_test/1/double_scalar" - - # wait for the attribute to be online. - max_retries = 10 - sleep_time = 30 - for x in range(0, max_retries): - try: - att = AttributeProxy(attribute) - att.read() - break - except DevFailed as df: - if(x == (max_retries -1)): - raise df - logging.info("DevFailed exception: " + str(df.args[0].reason) + ". Sleeping for " + str(sleep_time) + "ss") - sleep(sleep_time) - - conf_manager_proxy.write_attribute("SetAttributeName", attribute) - conf_manager_proxy.write_attribute("SetArchiver", evt_subscriber_device_fqdn) - conf_manager_proxy.write_attribute("SetStrategy", "ALWAYS") - conf_manager_proxy.write_attribute("SetPollingPeriod", 1000) - conf_manager_proxy.write_attribute("SetPeriodEvent", 3000) - - try: - conf_manager_proxy.command_inout("AttributeAdd") - except DevFailed as df: - if not str(df.args[0].reason) == 'Already archived': - logging.info("DevFailed exception: " + str(df.args[0].reason)) - - evt_subscriber_device_proxy.Start() - - max_retries = 10 - sleep_time = 1 - for x in range(0, max_retries): - try: - # Check status of Attribute Archiving in Configuration Manager - result_config_manager = conf_manager_proxy.command_inout("AttributeStatus", attribute) - # Check status of Attribute Archiving in Event Subscriber - result_evt_subscriber = evt_subscriber_device_proxy.command_inout("AttributeStatus", attribute) - assert "Archiving : Started" in result_config_manager - assert "Archiving : Started" in result_evt_subscriber - except DevFailed as df: - if(x == (max_retries -1)): - raise df - logging.info("DevFailed exception: " + str(df.args[0].reason) + ". Sleeping for " + str(sleep_time) + "ss") - sleep(sleep_time) diff --git a/tests/post-deployment/resources/_old/test_device_running.py b/tests/post-deployment/resources/_old/test_device_running.py deleted file mode 100644 index 821f23b6443d18b0d9ad4ff0ca4b746b86858d37..0000000000000000000000000000000000000000 --- a/tests/post-deployment/resources/_old/test_device_running.py +++ /dev/null @@ -1,6 +0,0 @@ -import tango - - -def test_test_device_is_running(): - tango_test = tango.DeviceProxy("sys/tg_test/1") - assert tango_test.state() == tango.DevState.RUNNING diff --git a/tests/pytest.ini b/tests/pytest.ini new file mode 100644 index 0000000000000000000000000000000000000000..ab4fe0b4c384ca65c29a2a6bcd414f5c007c30d2 --- /dev/null +++ b/tests/pytest.ini @@ -0,0 +1,27 @@ + +[pytest] +filterwarnings = + ignore::DeprecationWarning +junit_family=xunit1 +log_cli = true +log_cli_level = INFO +log_cli_format = 1|%(asctime)s.%(msecs)03dZ|%(levelname)s|%(threadName)s|%(funcName)s|%(filename)s#%(lineno)d||%(message)s +log_cli_date_format = %Y-%m-%dT%H:%M:%S +log_file = pytest-logs.txt +log_file_level = INFO +testpaths = tests/unit +# addopts = --json-report --json-report-file=report.json --junitxml=report.xml --cucumberjson=cucumber.json --disable-pytest-warnings +addopts = --forked --json-report --json-report-file=build/report.json --junitxml=build/report.xml --cucumberjson=build/cucumber.json --disable-pytest-warnings +# addopts = +# --forked +# --json-report +# --json-report-file=build/reports/report.json +# --cov-report html:build/htmlcov +# --cov-report xml:build/reports/code-coverage.xml +# --cov=skampi +# --cucumberjson=build/reports/cucumber.json +# --junitxml=build/reports/unit-tests.xml +# --verbose + +markers = +bdd_features_base_dir = tests/features diff --git a/tests/post-deployment/test_requirements.txt b/tests/requirements.txt similarity index 100% rename from tests/post-deployment/test_requirements.txt rename to tests/requirements.txt diff --git a/tests/post-deployment/resources/test_support/fixtures.py b/tests/resources/test_support/fixtures.py similarity index 100% rename from tests/post-deployment/resources/test_support/fixtures.py rename to tests/resources/test_support/fixtures.py diff --git a/tests/post-deployment/setup.cfg b/tests/setup.cfg similarity index 100% rename from tests/post-deployment/setup.cfg rename to tests/setup.cfg diff --git a/tests/post-deployment/tests/__test_archiver.py b/tests/unit/__test_archiver.py similarity index 100% rename from tests/post-deployment/tests/__test_archiver.py rename to tests/unit/__test_archiver.py diff --git a/tests/post-deployment/tests/__test_tango-commands.py b/tests/unit/__test_tango-commands.py similarity index 100% rename from tests/post-deployment/tests/__test_tango-commands.py rename to tests/unit/__test_tango-commands.py diff --git a/tests/post-deployment/tests/conftest.py b/tests/unit/conftest.py similarity index 100% rename from tests/post-deployment/tests/conftest.py rename to tests/unit/conftest.py diff --git a/tests/post-deployment/tests/test_tango-db.py b/tests/unit/test_tango-db.py similarity index 100% rename from tests/post-deployment/tests/test_tango-db.py rename to tests/unit/test_tango-db.py diff --git a/tests/post-deployment/tests/test_tango_tools.py b/tests/unit/test_tango_tools.py similarity index 100% rename from tests/post-deployment/tests/test_tango_tools.py rename to tests/unit/test_tango_tools.py