Merge "Create Helm test for redis chart"
This commit is contained in:
commit
6ea80fa151
@ -24,4 +24,8 @@ metadata:
|
||||
data:
|
||||
image-repo-sync.sh: |
|
||||
{{- include "helm-toolkit.scripts.image_repo_sync" . | indent 4 }}
|
||||
redis-test.sh: |
|
||||
{{ tuple "test/_redis_test.sh.tpl" . | include "helm-toolkit.utils.template" | indent 4 }}
|
||||
python-tests.py: |
|
||||
{{ tuple "test/_python_redis_tests.py.tpl" . | include "helm-toolkit.utils.template" | indent 4 }}
|
||||
{{- end }}
|
||||
|
66
redis/templates/pod_test.yaml
Normal file
66
redis/templates/pod_test.yaml
Normal file
@ -0,0 +1,66 @@
|
||||
{{/*
|
||||
Copyright 2019 The Openstack-Helm Authors.
|
||||
|
||||
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.
|
||||
*/}}
|
||||
|
||||
{{- if .Values.manifests.helm_tests }}
|
||||
{{- $envAll := . }}
|
||||
|
||||
{{- $serviceAccountName := print .Release.Name "-test" }}
|
||||
{{ tuple $envAll "tests" $serviceAccountName | include "helm-toolkit.snippets.kubernetes_pod_rbac_serviceaccount" }}
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: "{{.Release.Name}}-test"
|
||||
labels:
|
||||
{{ tuple $envAll "redis" "test" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 4 }}
|
||||
annotations:
|
||||
"helm.sh/hook": test-success
|
||||
{{ tuple $envAll | include "helm-toolkit.snippets.release_uuid" }}
|
||||
spec:
|
||||
serviceAccountName: {{ $serviceAccountName }}
|
||||
nodeSelector:
|
||||
{{ .Values.labels.test.node_selector_key }}: {{ .Values.labels.test.node_selector_value }}
|
||||
restartPolicy: Never
|
||||
containers:
|
||||
- name: {{.Release.Name}}-helm-tests
|
||||
{{ tuple $envAll "helm_tests" | include "helm-toolkit.snippets.image" | indent 6 }}
|
||||
{{ tuple $envAll $envAll.Values.pod.resources.jobs.tests | include "helm-toolkit.snippets.kubernetes_resources" | indent 6 }}
|
||||
command:
|
||||
- /tmp/redis-test.sh
|
||||
env:
|
||||
- name: REDIS_HOST
|
||||
value: "redis"
|
||||
- name: REDIS_PORT
|
||||
value: "{{ .Values.network.port }}"
|
||||
- name: REDIS_DB
|
||||
value: '0'
|
||||
volumeMounts:
|
||||
- name: redis-test
|
||||
mountPath: /tmp/redis-test.sh
|
||||
subPath: redis-test.sh
|
||||
- name: redis-python
|
||||
mountPath: /tmp/python-tests.py
|
||||
subPath: python-tests.py
|
||||
volumes:
|
||||
- name: redis-test
|
||||
configMap:
|
||||
name: redis-bin
|
||||
defaultMode: 0555
|
||||
- name: redis-python
|
||||
configMap:
|
||||
name: redis-bin
|
||||
defaultMode: 0555
|
||||
{{- end }}
|
54
redis/templates/test/_python_redis_tests.py.tpl
Normal file
54
redis/templates/test/_python_redis_tests.py.tpl
Normal file
@ -0,0 +1,54 @@
|
||||
import os
|
||||
import redis
|
||||
|
||||
|
||||
class RedisTest(object):
|
||||
|
||||
def __init__(self):
|
||||
host = os.environ.get('REDIS_HOST', 'redis')
|
||||
port = os.environ.get('REDIS_PORT', 6379)
|
||||
db = os.environ.get('REDIS_DB', 0)
|
||||
self.redis_conn = redis.Redis(host, port, db)
|
||||
|
||||
def test_connection(self):
|
||||
ping = self.redis_conn.ping()
|
||||
assert ping, "No connection to database"
|
||||
print("Successfully connected to database")
|
||||
|
||||
def database_info(self):
|
||||
ip_port = []
|
||||
for client in self.redis_conn.client_list():
|
||||
ip_port.append(client["addr"])
|
||||
print(ip_port)
|
||||
assert self.redis_conn.client_list(), "Database client's list is null"
|
||||
return ip_port
|
||||
|
||||
def test_insert_delete_data(self):
|
||||
key = "test"
|
||||
value = "it's working"
|
||||
result_set = self.redis_conn.set(key, value)
|
||||
assert result_set, "Error: SET command failed"
|
||||
print("Successfully SET keyvalue pair")
|
||||
result_get = self.redis_conn.get(key)
|
||||
assert result_get, "Error: GET command failed"
|
||||
print("Successfully GET keyvalue pair")
|
||||
db_size = self.redis_conn.dbsize()
|
||||
assert db_size > 0, "Database size not valid"
|
||||
result_delete = self.redis_conn.delete(key)
|
||||
assert result_delete == 1, "Error: Delete command failed"
|
||||
print("Successfully DELETED keyvalue pair")
|
||||
|
||||
def test_client_kill(self, client_ip_port_list):
|
||||
for client_ip_port in client_ip_port_list:
|
||||
result = self.redis_conn.client_kill(client_ip_port)
|
||||
print(result)
|
||||
assert result, "Client failed to be removed"
|
||||
print("Successfully DELETED client")
|
||||
|
||||
|
||||
client_ip_port = []
|
||||
redis_client = RedisTest()
|
||||
redis_client.test_connection()
|
||||
client_ip_port = redis_client.database_info()
|
||||
redis_client.test_insert_delete_data()
|
||||
redis_client.test_client_kill(client_ip_port)
|
12
redis/templates/test/_redis_test.sh.tpl
Normal file
12
redis/templates/test/_redis_test.sh.tpl
Normal file
@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
set -ex
|
||||
|
||||
echo "Start Redis Test"
|
||||
echo "Print Environmental variables"
|
||||
echo $REDIS_HOST
|
||||
echo $REDIS_PORT
|
||||
echo $REDIS_DB
|
||||
apt-get update
|
||||
apt-get -y install python-pip
|
||||
yes w | pip install redis
|
||||
python /tmp/python-tests.py
|
@ -20,6 +20,7 @@
|
||||
images:
|
||||
tags:
|
||||
redis: docker.io/redis:4.0.1
|
||||
helm_tests: docker.io/ubuntu
|
||||
dep_check: quay.io/stackanetes/kubernetes-entrypoint:v0.3.1
|
||||
image_repo_sync: docker.io/docker:17.07.0
|
||||
pull_policy: IfNotPresent
|
||||
@ -63,6 +64,13 @@ pod:
|
||||
limits:
|
||||
memory: "1024Mi"
|
||||
cpu: "2000m"
|
||||
tests:
|
||||
requests:
|
||||
memory: "128Mi"
|
||||
cpu: "100m"
|
||||
limits:
|
||||
memory: "1024Mi"
|
||||
cpu: "2000m"
|
||||
|
||||
labels:
|
||||
redis:
|
||||
@ -71,6 +79,9 @@ labels:
|
||||
job:
|
||||
node_selector_key: openstack-control-plane
|
||||
node_selector_value: enabled
|
||||
test:
|
||||
node_selector_key: openstack-control-plane
|
||||
node_selector_value: enabled
|
||||
|
||||
network:
|
||||
port: 6379
|
||||
@ -112,3 +123,4 @@ manifests:
|
||||
deployment: true
|
||||
job_image_repo_sync: true
|
||||
service: true
|
||||
helm_tests: true
|
||||
|
@ -58,3 +58,6 @@ helm upgrade --install docker-registry ./registry \
|
||||
helm status docker-registry-nfs-provisioner
|
||||
helm status docker-registry-redis
|
||||
helm status docker-registry
|
||||
|
||||
#NOTE: Run helm tests
|
||||
helm test docker-registry-redis
|
||||
|
Loading…
Reference in New Issue
Block a user