Skip to content

Commit

Permalink
Test/sanity crc (#35)
Browse files Browse the repository at this point in the history
test(sanity): add tools for running csi-sanity in CRC
  • Loading branch information
David-T-White authored Jul 21, 2022
1 parent 4498844 commit 3bd1fa8
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ test/secrets.yml
test/volume.yml
test/sanity.log
test/.env
test/sanity-crc/secrets.yml
test/sanity-crc/volume.yml
test/sanity-crc/csi-sanity
test/sanity-crc/sanity-crc.yaml
6 changes: 6 additions & 0 deletions test/sanity-crc/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from registry.access.redhat.com/ubi8/ubi

RUN yum update -y && yum install -y sudo gettext

ADD . /
CMD ["./sanity-cli", "all"]
60 changes: 60 additions & 0 deletions test/sanity-crc/sanity-cli
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#! /usr/bin/env bash

# Adapted version of the sanity-cli script for use in the sanity pod
#
# Usage: sanity-cli [all]
#
# Running ./sanity-cli
# Will fail fast (-ginkgo.failFast) and use -ginkgo.focus based on TEST_FOCUS
# Use `export TEST_FOCUS=<item>`, such as <item> = CreateVolume to limit test cases
#
# Running ./sanity-cli all
# Will run all test cases and continue past failures
#

opt=$1

echo ""
echo "[] sanity-cli $opt"


secretsTemplate="secrets.template.yml"
secrets="secrets.yml"
volumeTemplate="volume.template.yml"
volume="volume.yml"

set -e

function setVariables()
{
echo ""
echo "env variables:"

test_focus=$TEST_FOCUS
echo "-- TEST_FOCUS = $test_focus"
}

setVariables

controller=unix:///csi/controller.sock
node=unix:///csi/node.sock
sanity=/csi-sanity

focus=${test_focus}

echo ""
echo "[] csi-sanity"

if [ "$opt" == "all" ]; then
echo "sudo ${sanity} -csi.controllerendpoint ${controller} -csi.endpoint ${node} -csi.secrets ${secrets} -csi.testvolumeparameters ${volume}"
sudo ${sanity} -csi.controllerendpoint ${controller} -csi.endpoint ${node} -csi.secrets ${secrets} -csi.testvolumeparameters ${volume}

else
echo "sudo ${sanity} -csi.controllerendpoint ${controller} -csi.endpoint ${node} -csi.secrets ${secrets} -ginkgo.focus \"${focus}\" -csi.testvolumeparameters ${volume} -ginkgo.failFast"
sudo ${sanity} -csi.controllerendpoint ${controller} -csi.endpoint ${node} -csi.secrets ${secrets} -ginkgo.focus "${focus}" -csi.testvolumeparameters ${volume} -ginkgo.failFast

fi

out=$?

exit ${out}
30 changes: 30 additions & 0 deletions test/sanity-crc/sanity-crc-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apiVersion: v1
kind: Pod
metadata:
name: csi-sanity-crc
spec:
restartPolicy: Never
containers:
- image: default-route-openshift-image-registry.apps-crc.testing/seagate/csi-sanity
command: ["./sanity-cli", "all"]
name: csi-sanity
securityContext:
privileged: true
allowPrivilegeEscalation: true
volumeMounts:
- name: controller-socket
mountPath: /csi/controller.sock
- name: node-socket
mountPath: /csi/node.sock
- name: target-directory
mountPath: /tmp
volumes:
- name: controller-socket
hostPath:
path: /var/lib/kubelet/pods/{{CONTROLLER_POD_UID}}/volumes/kubernetes.io~empty-dir/socket-dir/csi.sock
- name: node-socket
hostPath:
path: /var/lib/kubelet/plugins/csi-exos-x.seagate.com/csi.sock
- name: target-directory
hostPath:
path: /tmp
101 changes: 101 additions & 0 deletions test/sanity-crc/sanity-crc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/bin/bash

# Usage: crc-sanity.sh
#
# Launch cli sanity in a crc pod. Must be logged in with oc before running.
# Runs all csi-sanity test cases

secretsTemplate="../secrets.template.yml"
secrets="secrets.yml"
volumeTemplate="../volume.template.yml"
volume="volume.yml"

sanity=/home/dwhite/github.com/csi-test/cmd/csi-sanity/csi-sanity

set -e

#make sure oc command is setup
oc > /dev/null

function setup {
cd $(dirname $0)
set -a; . ../.env; set +a

echo ""

envsubst < ${secretsTemplate} > ${secrets}
echo "===== ${secrets} ====="
cat ${secrets}
echo "===== END ====="

echo ""

envsubst < ${volumeTemplate} > ${volume}
echo "===== ${volume} ====="
cat ${volume}
echo "===== END ====="

cp $sanity .
}

setup

#Build and push the sanity container
echo "===== Building Container ====="
buildah bud -t localhost/seagate-exos-x-csi/csi-sanity .
podman login -u kubeadmin -p $(oc whoami -t) default-route-openshift-image-registry.apps-crc.testing --tls-verify=false
podman tag localhost/seagate-exos-x-csi/csi-sanity default-route-openshift-image-registry.apps-crc.testing/seagate/csi-sanity
podman push default-route-openshift-image-registry.apps-crc.testing/seagate/csi-sanity --tls-verify=false

#Retrieve the controller UID, needed to mount the CSI socket from the CRC VM into the container
controller_pod_name=$(oc get pods -n seagate -o name | grep seagate-exos-x-csi-controller-server)
controller_pod_uid=$(oc get $controller_pod_name -o=jsonpath='{.metadata.uid}' -n seagate)
sed "s/{{CONTROLLER_POD_UID}}/$controller_pod_uid/g" sanity-crc-template.yaml > sanity-crc.yaml

set +e

# #Run sanity
echo "===== Deleting Old Sanity Pod ====="
oc delete pod csi-sanity-crc

echo "===== Creating Sanity Pod ====="
oc create -f sanity-crc.yaml

echo "Test pod is starting! Once running, use 'oc logs csi-sanity-crc' to get sanity output"

counter=0
success=0
continue=1
maxattempts=6

while [ $continue ]
do
echo ""
echo "Waiting for test pod to come online"

testpodstatus=$(oc get pod csi-sanity-crc -o=jsonpath='{.status.phase}' -n seagate)
echo $testpodstatus
if [ "$testpodstatus" == "Running" ]; then
echo "SUCCESS: test pod running"
success=1
break
fi

if [[ "$counter" -eq $maxattempts ]]; then
echo ""
echo "ERROR: Max attempts ($maxattempts) reached and test pod is not running."
echo ""
oc get pod csi-sanity-crc
break
else
sleep 5
fi

((counter++))
done

log_output_file="csi-sanity.log"
if [ "$success" -ne 0 ]; then
echo "csi sanity in progress, logs will be tailed to $log_output_file"
oc logs csi-sanity-crc -f > $log_output_file &
fi

0 comments on commit 3bd1fa8

Please sign in to comment.