upload pm-support 60/1460/7
authorkinkwant <kinkwan.tsui@nokia.com>
Fri, 23 Aug 2019 14:39:36 +0000 (17:39 +0300)
committerrobert.vajda.86 <robert.vajda@nokia.com>
Fri, 6 Sep 2019 08:51:12 +0000 (11:51 +0300)
Change-Id: I24a7e836887a323b9e8376ace48862165dab7179
Signed-off-by: kinkwant <kinkwan.tsui@nokia.com>
testcases/pm-support/misc/Dockerfile [new file with mode: 0644]
testcases/pm-support/misc/custom-metrics-dep.yaml [new file with mode: 0644]
testcases/pm-support/misc/custom-metrics_test.py [new file with mode: 0644]
testcases/pm-support/pm-suppot.robot [new file with mode: 0644]
tox.ini

diff --git a/testcases/pm-support/misc/Dockerfile b/testcases/pm-support/misc/Dockerfile
new file mode 100644 (file)
index 0000000..5890739
--- /dev/null
@@ -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 (file)
index 0000000..37a0fa5
--- /dev/null
@@ -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 (file)
index 0000000..ce3132f
--- /dev/null
@@ -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 (file)
index 0000000..9e9e593
--- /dev/null
@@ -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/tox.ini b/tox.ini
index a8965b6..45666fe 100644 (file)
--- 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:.}