--- /dev/null
+# Copyright 2019 AT&T
+#
+# 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 Run Keywords
+... ssh.Setup Connections
+... Create Namespace
+Test Teardown Run Keywords
+... Delete Namespace
+
+*** Keywords ***
+
+Create Namespace
+ ${command}= set variable kubectl create namespace test-ns
+ ${out}= ssh.Execute Command ${command} controller-1
+ log ${out}
+ Should contain ${out} namespace/test-ns created
+
+Create pod in specific namespace
+ ${command}= set variable kubectl run --generator=run-pod/v1 my-pod --image=nginx --port=80 --namespace=test-ns
+ ${out}= ssh.Execute Command ${command} controller-1
+ log ${out}
+ Should contain ${out} pod/my-pod created
+
+Check whether pod was created in specific namespace
+ ${command}= set variable kubectl describe pod my-pod -n test-ns
+ ${out}= ssh.Execute Command ${command} controller-1
+ log ${out}
+ Should contain ${out} test-ns
+
+Delete pod
+ ${command}= set variable kubectl delete pod my-pod -n test-ns
+ ${out}= ssh.Execute Command ${command} controller-1
+ log ${out}
+ Should contain ${out} pod "my-pod" deleted
+
+Delete Namespace
+ ${command}= set variable kubectl delete namespace test-ns
+ ${out}= ssh.Execute Command ${command} controller-1
+ log ${out}
+ Should contain ${out} namespace "test-ns" deleted
+
+*** Test Cases ***
+
+Verify creating and testing Namespaces
+ Create pod in specific namespace
+ Check whether pod was created in specific namespace
+ Delete pod
--- /dev/null
+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"]
--- /dev/null
+---
+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
--- /dev/null
+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)
--- /dev/null
+# 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
+
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}
*** 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
--cov-branch \
--cov-report term-missing \
--cov-report html:coverage-html-{envname} \
+ --ignore testcases/pm-support/misc \
{posargs:.}
[pytest]
--pylint \
--pylint-rcfile={toxinidir}/.pylintrc \
--ignore resources/system_testing/latency \
+ --ignore testcases/pm-support/misc \
{posargs:.}