Last active
February 22, 2016 21:43
-
-
Save madhurranjan/04c8cbbe061c45b03693 to your computer and use it in GitHub Desktop.
run_calico_test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
svc=nginxtest | |
admin_config_path="cacerts/kubelet/admin_kubeconfig" | |
for rc in nginxtest positive_test negative_test ; do | |
#cleanup and bring up test rc | |
kubectl delete -f test/${rc}.yaml --kubeconfig=${admin_config_path} | |
kubectl create -f test/${rc}.yaml --kubeconfig=${admin_config_path} | |
done | |
check_dns_pod(){ | |
echo "checking dns pod" | |
while ! [[ `kubectl get pods --kubeconfig=${admin_config_path} --namespace=kube-system | grep dns | grep '4/4'` ]]; do | |
echo "Waiting for dns pod to get into Running state" | |
sleep 5 | |
done | |
} | |
get_running_pod(){ | |
while ! [[ `kubectl get pods --kubeconfig=${admin_config_path} | grep $1 | grep Running` ]]; do | |
sleep 5 | |
done | |
pod=`kubectl get pods --kubeconfig=${admin_config_path} | grep $1 | grep Running | awk '{print $1}'` | |
echo $pod | |
} | |
check_dns_pod | |
echo "dns pod works" | |
# get positive test pod and run test | |
nginx_pod=`get_running_pod nginxtest` | |
echo "Nginx pod : $nginx_pod" | |
positive_pod=`get_running_pod positivetest` | |
echo "Nginx pod : $positive_pod" | |
negative_pod=`get_running_pod negativetest` | |
echo "Nginx pod : $negative_pod" | |
working=0 | |
echo "Running: kubectl exec --kubeconfig=${admin_config_path} -it $positive_pod -- wget -T 3 $svc -q -O - 2>&1" | |
result=`kubectl exec --kubeconfig=${admin_config_path} -it $positive_pod -- wget -T 3 $svc -q -O - 2>&1` | |
if [[ $? == 0 ]]; then | |
echo "$positive_pod is able to access $svc service"; | |
else | |
echo "Positive test failed. $positive_pod is unable to access $svc service" | |
working=1 | |
fi | |
echo "Running: kubectl exec --kubeconfig=${admin_config_path} -it $negative_pod -- wget -T 3 $svc -q -O - 2>&1" | |
result=`kubectl exec --kubeconfig=${admin_config_path} -it $negative_pod -- wget -T 3 $svc -q -O - 2>&1` | |
if [[ $? == 0 ]]; then | |
echo "Negative test failed. $negative_pod is able to access $svc service" | |
working=1 | |
else | |
echo "$negative_pod is unable to access $svc service"; | |
fi | |
#cleanup test pods if working value is 0 | |
if [[ "$working" == 0 ]]; then | |
echo "All tests passed. Deleting test pods" | |
for rc in nginxtest positive_test negative_test ; do | |
kubectl delete -f test/${rc}.yaml --kubeconfig=${admin_config_path} | |
done | |
fi | |
ls test | |
negative_test.yaml nginxtest.yaml positive_test.yaml | |
$cat test/nginxtest.yaml | |
apiVersion: v1 | |
kind: Service | |
metadata: | |
name: nginxtest | |
spec: | |
ports: | |
- port: 80 | |
targetPort: 80 | |
selector: | |
app: nginxtest | |
--- | |
apiVersion: v1 | |
kind: ReplicationController | |
metadata: | |
name: nginxtest | |
spec: | |
replicas: 1 | |
template: | |
metadata: | |
labels: | |
app: nginxtest | |
annotations: | |
projectcalico.org/policy: "allow tcp from label access=true to ports 80" | |
spec: | |
containers: | |
- name: nginxtest | |
image: nginx | |
ports: | |
- containerPort: 80 | |
$cat test/positive_test.yaml | |
apiVersion: v1 | |
kind: ReplicationController | |
metadata: | |
name: positivetest | |
spec: | |
replicas: 1 | |
template: | |
metadata: | |
labels: | |
access: "true" | |
spec: | |
containers: | |
- image: busybox | |
command: | |
- sleep | |
- "3600" | |
imagePullPolicy: IfNotPresent | |
name: busybox | |
$cat test/negative_test.yaml | |
apiVersion: v1 | |
kind: ReplicationController | |
metadata: | |
name: negativetest | |
spec: | |
replicas: 1 | |
template: | |
metadata: | |
labels: | |
access: "false" | |
spec: | |
containers: | |
- image: busybox | |
command: | |
- sleep | |
- "3600" | |
imagePullPolicy: IfNotPresent | |
name: busybox |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment