From: kinkwan tsui Date: Wed, 25 Sep 2019 13:51:23 +0000 (+0000) Subject: Merge "REC-11 Creating and testing Namespaces" X-Git-Url: https://gerrit.akraino.org/r/gitweb?p=ta%2Fcloudtaf.git;a=commitdiff_plain;h=0b540eaf6754141684f20c7105f2e9a8e992e0b5;hp=df19858776e9a60db1d0fc5b2c17f6898b0b9719 Merge "REC-11 Creating and testing Namespaces" --- diff --git a/testcases/pm-support/misc/Dockerfile b/testcases/pm-support/misc/Dockerfile new file mode 100644 index 0000000..5890739 --- /dev/null +++ b/testcases/pm-support/misc/Dockerfile @@ -0,0 +1,9 @@ +FROM alpine:latest + +ADD custom_metrics_test.py / + +RUN apk add --no-cache py-pip \ +&& pip install --upgrade pip \ +&& pip install prometheus_client + +CMD ["python", "./custom_metrics_test.py"] diff --git a/testcases/pm-support/misc/custom-metrics-dep.yaml b/testcases/pm-support/misc/custom-metrics-dep.yaml new file mode 100644 index 0000000..37a0fa5 --- /dev/null +++ b/testcases/pm-support/misc/custom-metrics-dep.yaml @@ -0,0 +1,70 @@ +--- +apiVersion: apps/v1beta2 +kind: Deployment +metadata: + name: custommetrics + namespace: kube-system +spec: + selector: + matchLabels: + k8s-app: custommetrics + replicas: 2 + template: + metadata: + labels: + app: custommetrics + k8s-app: custommetrics + annotations: + prometheus.io/scrape: 'true' + danm.k8s.io/interfaces: | + [ + { + "network":"flannel" + } + ] + spec: + containers: + - name: custommetricsd + image: registry.kube-system.svc.rec.io:5555/custom_metrics_test:0.1 + imagePullPolicy: Always + command: + - python + - custom_metrics_test.py + volumeMounts: + - name: metadata + mountPath: /etc/custommetricsd/metadata + readOnly: true + ports: + - containerPort: 9100 + protocol: TCP + readinessProbe: + httpGet: + path: /readyz + port: 9100 + initialDelaySeconds: 1 + periodSeconds: 2 + failureThreshold: 1 + livenessProbe: + httpGet: + path: /healthz + port: 9100 + initialDelaySeconds: 1 + periodSeconds: 3 + failureThreshold: 2 + resources: + requests: + memory: "32Mi" + cpu: "1m" + limits: + memory: "256Mi" + cpu: "100m" + volumes: + - name: metadata + downwardAPI: + items: + - path: "labels" + fieldRef: + fieldPath: metadata.labels + - path: "annotations" + fieldRef: + fieldPath: metadata.annotations diff --git a/testcases/pm-support/misc/custom-metrics_test.py b/testcases/pm-support/misc/custom-metrics_test.py new file mode 100644 index 0000000..ce3132f --- /dev/null +++ b/testcases/pm-support/misc/custom-metrics_test.py @@ -0,0 +1,19 @@ +from prometheus_client import start_http_server, Histogram +import random +import time + +function_exec = Histogram('function_exec_time', + 'Time spent processing a function', + ['func_name']) + +def func(): + if (random.random() < 0.02): + time.sleep(2) + return +time.sleep(0.2) +start_http_server(9100) + +while True: + start_time = time.time() + func() + function_exec.labels(func_name="func").observe(time.time() - start_time) diff --git a/testcases/pm-support/pm-suppot.robot b/testcases/pm-support/pm-suppot.robot new file mode 100644 index 0000000..9e9e593 --- /dev/null +++ b/testcases/pm-support/pm-suppot.robot @@ -0,0 +1,93 @@ +# Copyright 2019 Nokia +# +# 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. + +*** Settings *** +Library Collections +Library cluster.cluster.Cluster WITH NAME Cluster +Library crl.remotesession.remotesession.RemoteSession +... WITH NAME RemoteSession +Resource ssh.robot +Test Setup ssh.Setup Connections + +*** Variables *** +${docker_image_name} registry.kube-system.svc.rec.io:5555/custom_metrics_test +${docker_image_tag} 0.1 +${docker_image} ${docker_image_name}:${docker_image_tag} +${test_base_dir} /cloudtaf/testcases/pm-support/misc +${custom_metrics_yaml_name} custom-metrics-test-dep.yaml +${custom_metrics_pod_name} custommetrics + +*** Keywords *** +Create Custom Metrics Docker Image + [Arguments] ${node}=sudo-default + ${cmd}= cd ${test_base_dir} | docker build --network=host --no-cache --force-rm --tag ${docker_image_name}:${docker_image_tag} . + ${output}= Ssh.Execute Command ${cmd} ${node} + +Push Custom Metrics Image + [Arguments] ${node}=sudo-default + ${cmd}= docker push ${docker_image} + ${output}= Ssh.Execute Command ${cmd} ${node} + +Delete Custom Metrics Image + [Arguments] ${node}=sudo-default + ${cmd}= docker rmi ${docker_image} ${docker_image} + ${output}= Ssh.Execute Command ${cmd} ${node} + +Delete Custom Metrics Pod + [Arguments] ${node}=sudo-default + ${cmd}= kubectl delete pod ${custom_metrics_pod_name} + ${output}= Ssh.Execute Command ${cmd} ${node} + +Apply deployment yaml + [Arguments] ${node}=sudo-default + ${cmd}= kubectl apply -f ${test_base_dir}/${custom_metrics_yaml_name} + ${output}= Ssh.Execute Command ${cmd} ${node} + ${cmd}= kubectl get po -n kube-system | grep ${custom_metrics_pod_name} + ${output}= Ssh.Execute Command ${cmd} ${node} + Should not be empty ${output.stdout} + +Check custom metrics + [Arguments] ${node}=sudo-default + ${cmd}= Set Variable kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta1 + ${output}= Ssh.Execute Command ${cmd} ${node} + ${cmd}= Set Variable kubectl get –raw "/apis/custom.metrics.k8s.io/v1beta1/namespaces/kube-system/pods/*/http_requests + ${output}= Ssh.Execute Command ${cmd} ${node} + +Custom Metrics Teardown + Delete Custom Metrics Pod + Delete Custom Metrics Image + +Check kubectl api + [Arguments] ${node}=sudo-default + ${cmd}= Set Variable kubectl api-versions | grep metrics + ${output}= Ssh.Execute Command ${cmd} ${node} + Should Contain ${output} custom.metrics.k8s.io/v1beta1 + Should Contain ${output} metrics.k8s.io/v1beta1 + +Check Core Metrics + [Arguments] ${node}=sudo-default + ${cmd}= Set Variable kubectl top node + ${output}= Ssh.Execute Command ${cmd} ${node} + Should Not Contain ${output} " 0m" + Should Not Contain ${output} " 0Mi" + + +*** Test Cases *** + +PM001 + Check Core Metrics + +PM002 + Check kubectl api + diff --git a/testcases/post-install/post_install.robot b/testcases/post-install/post_install.robot index bdc3d76..bd40cdb 100644 --- a/testcases/post-install/post_install.robot +++ b/testcases/post-install/post_install.robot @@ -28,8 +28,13 @@ Testing Deployment log ${out} Should contain ${out} ${search} +Looking up LF Jenkins successful build iso number + ${command}= set variable rpm -qa | grep product | awk -F '-' '{sub(/-.*$/, "", $3); print $3}' + ${out}= ssh.Execute Command ${command} controller-1 + log ${out} + Testing Docker - ${search}= set variable Docker version 18.09.2 + ${search}= set variable Docker version 19.03.2 ${command}= set variable docker --version ${out}= ssh.Execute Command ${command} controller-1 log ${out} @@ -89,6 +94,8 @@ Testing Helm Caas infra Status *** Test Cases *** Verify Deployment Testing Deployment +Verify Image Build Number + Looking up LF Jenkins successful build iso number Verify Docker Version Testing Docker Verify Kubernetes Clusters diff --git a/tox.ini b/tox.ini index a8965b6..45666fe 100644 --- a/tox.ini +++ b/tox.ini @@ -35,6 +35,7 @@ commands = py.test -v \ --cov-branch \ --cov-report term-missing \ --cov-report html:coverage-html-{envname} \ + --ignore testcases/pm-support/misc \ {posargs:.} [pytest] @@ -54,6 +55,7 @@ commands = py.test -m pylint -v \ --pylint \ --pylint-rcfile={toxinidir}/.pylintrc \ --ignore resources/system_testing/latency \ + --ignore testcases/pm-support/misc \ {posargs:.}