From 3bd1fa8901a5720156caa5b0dc512699d56b94ac Mon Sep 17 00:00:00 2001 From: David-T-White <64927637+David-T-White@users.noreply.github.com> Date: Thu, 21 Jul 2022 14:25:12 -0600 Subject: [PATCH] Test/sanity crc (#35) test(sanity): add tools for running csi-sanity in CRC --- .gitignore | 4 + test/sanity-crc/Dockerfile | 6 ++ test/sanity-crc/sanity-cli | 60 ++++++++++++++ test/sanity-crc/sanity-crc-template.yaml | 30 +++++++ test/sanity-crc/sanity-crc.sh | 101 +++++++++++++++++++++++ 5 files changed, 201 insertions(+) create mode 100644 test/sanity-crc/Dockerfile create mode 100755 test/sanity-crc/sanity-cli create mode 100644 test/sanity-crc/sanity-crc-template.yaml create mode 100755 test/sanity-crc/sanity-crc.sh diff --git a/.gitignore b/.gitignore index 7e736f42..487662f6 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/test/sanity-crc/Dockerfile b/test/sanity-crc/Dockerfile new file mode 100644 index 00000000..70970e3f --- /dev/null +++ b/test/sanity-crc/Dockerfile @@ -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"] diff --git a/test/sanity-crc/sanity-cli b/test/sanity-crc/sanity-cli new file mode 100755 index 00000000..892e0e0f --- /dev/null +++ b/test/sanity-crc/sanity-cli @@ -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=`, such as = 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} diff --git a/test/sanity-crc/sanity-crc-template.yaml b/test/sanity-crc/sanity-crc-template.yaml new file mode 100644 index 00000000..51025a26 --- /dev/null +++ b/test/sanity-crc/sanity-crc-template.yaml @@ -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 diff --git a/test/sanity-crc/sanity-crc.sh b/test/sanity-crc/sanity-crc.sh new file mode 100755 index 00000000..e83ff09c --- /dev/null +++ b/test/sanity-crc/sanity-crc.sh @@ -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