Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove verbose output in functional tests #687

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
./build.sh
go test -v ./...
docker build . -t "directpv:latest"
- uses: goreleaser/goreleaser-action@v3
- uses: goreleaser/goreleaser-action@v4
with:
version: latest
args: release --skip-publish --skip-sign --rm-dist --snapshot
2 changes: 1 addition & 1 deletion cmd/kubectl-directpv/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func removeMain(ctx context.Context) {
if err != nil {
failed = true
utils.Eprintf(quietFlag, true, "%v/%v: %v\n", result.Drive.GetNodeID(), result.Drive.GetDriveName(), err)
} else {
} else if !quietFlag {
fmt.Printf("Removing %v/%v\n", result.Drive.GetNodeID(), result.Drive.GetDriveName())
}
}
Expand Down
156 changes: 95 additions & 61 deletions functests/common.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,25 @@ function create_loop() {

function setup_lvm() {
LV_LOOP_DEVICE=$(create_loop testpv.img 1G)
sudo pvcreate "${LV_LOOP_DEVICE}"
sudo vgcreate "${VG_NAME}" "${LV_LOOP_DEVICE}"
sudo lvcreate --name=testlv --extents=100%FREE "${VG_NAME}"
sudo pvcreate --quiet "${LV_LOOP_DEVICE}" >/dev/null 2>&1
sudo vgcreate --quiet "${VG_NAME}" "${LV_LOOP_DEVICE}" >/dev/null 2>&1
sudo lvcreate --quiet --name=testlv --extents=100%FREE "${VG_NAME}" >/dev/null 2>&1
LV_DEVICE=$(basename "$(readlink -f "/dev/${VG_NAME}/testlv")")
}

function remove_lvm() {
sudo lvchange --quiet --activate n "${VG_NAME}/testlv"
sudo lvremove --quiet --yes "${VG_NAME}/testlv"
sudo vgremove --quiet "${VG_NAME}"
sudo pvremove --quiet "${LV_LOOP_DEVICE}"
sudo lvremove --quiet --yes "${VG_NAME}/testlv" >/dev/null 2>&1
sudo vgremove --quiet "${VG_NAME}" >/dev/null 2>&1
sudo pvremove --quiet "${LV_LOOP_DEVICE}" >/dev/null 2>&1
sudo losetup --detach "${LV_LOOP_DEVICE}"
rm -f testpv.img
}

function setup_luks() {
LUKS_LOOP_DEVICE=$(create_loop testluks.img 1G)
echo "mylukspassword" > lukspassfile
yes YES | sudo cryptsetup luksFormat "${LUKS_LOOP_DEVICE}" lukspassfile
yes YES 2>/dev/null | sudo cryptsetup luksFormat "${LUKS_LOOP_DEVICE}" lukspassfile
sudo cryptsetup luksOpen "${LUKS_LOOP_DEVICE}" myluks --key-file=lukspassfile
LUKS_DEVICE=$(basename "$(readlink -f /dev/mapper/myluks)")
}
Expand All @@ -69,37 +69,41 @@ function remove_luks() {

# install_directpv <pod_count>
function install_directpv() {
echo "* Installing DirectPV"

"${DIRECTPV_CLIENT}" install --quiet

required_count="$1"
running_count=0
while [[ $running_count -lt $required_count ]]; do
echo "$ME: waiting for $(( required_count - running_count )) DirectPV pods to come up"
sleep $(( required_count - running_count ))
echo " ...waiting for $(( required_count - running_count )) DirectPV pods to come up"
sleep 1m
running_count=$(kubectl get pods --field-selector=status.phase=Running --no-headers --namespace=directpv | wc -l)
done

while ! "${DIRECTPV_CLIENT}" info --quiet; do
echo "$ME: waiting for DirectPV to come up"
sleep 5
echo " ...waiting for DirectPV to come up"
sleep 1m
done

sleep 1m
sleep 10
}

# uninstall_directpv <pod_count>
function uninstall_directpv() {
echo "* Uninstalling DirectPV"

"${DIRECTPV_CLIENT}" uninstall --quiet

pending="$1"
while [[ $pending -gt 0 ]]; do
echo "$ME: waiting for ${pending} DirectPV pods to go down"
sleep "${pending}"
pending=$(kubectl get pods --field-selector=status.phase=Running --no-headers --namespace=directpv | wc -l)
echo " ...waiting for ${pending} DirectPV pods to go down"
sleep 5
pending=$(kubectl get pods --field-selector=status.phase=Running --no-headers --namespace=directpv-min-io 2>/dev/null | wc -l)
done

while kubectl get namespace directpv --no-headers | grep -q .; do
echo "$ME: waiting for directpv namespace to be removed"
while kubectl get namespace directpv-min-io --no-headers 2>/dev/null | grep -q .; do
echo " ...waiting for directpv-min-io namespace to be removed"
sleep 5
done

Expand All @@ -122,133 +126,163 @@ function check_drives_status() {
}

function add_drives() {
config_file="$(mktemp)"
echo "* Adding drives"

if ! "${DIRECTPV_CLIENT}" discover --output-file "${config_file}"; then
config_file="$(mktemp)"

if ! "${DIRECTPV_CLIENT}" discover --output-file "${config_file}" > /tmp/.output 2>&1; then
cat /tmp/.output
echo "$ME: error: failed to discover the devices"
rm "${config_file}"
return 1
fi
if ! echo Yes | "${DIRECTPV_CLIENT}" init "${config_file}"; then
if ! echo Yes | "${DIRECTPV_CLIENT}" init "${config_file}" > /tmp/.output 2>&1; then
cat /tmp/.output
echo "$ME: error: failed to initialize the drives"
rm "${config_file}"
return 1
fi

rm "${config_file}"

# Show output for manual debugging.
"${DIRECTPV_CLIENT}" list drives --all

check_drives_status Ready
}

function remove_drives() {
echo "* Deleting drives"

"${DIRECTPV_CLIENT}" remove --all --quiet
}

# usage: deploy_minio <minio-yaml>
function deploy_minio() {
echo "* Deploying minio"

minio_yaml="$1"

kubectl apply -f "${minio_yaml}"
kubectl apply -f "${minio_yaml}" 1>/dev/null

required_count=4
running_count=0
while [[ $running_count -lt $required_count ]]; do
echo "$ME: waiting for $(( required_count - running_count )) minio pods to come up"
sleep $(( required_count - running_count ))
running_count=$(kubectl get pods --field-selector=status.phase=Running --no-headers | grep -c '^minio-' || true)
echo " ...waiting for $(( required_count - running_count )) minio pods to come up"
sleep 1m
running_count=$(kubectl get pods --field-selector=status.phase=Running --no-headers 2>/dev/null | grep -c '^minio-' || true)
done
}

# usage: delete_minio <minio-yaml>
function delete_minio() {
echo "* Deleting minio"

minio_yaml="$1"

kubectl delete -f "${minio_yaml}"
kubectl delete -f "${minio_yaml}" 1>/dev/null
pending=4
retry_count=0
while [[ $pending -gt 0 ]]; do
if [[ $retry_count -gt 50 ]]; then
kubectl delete pods --all --force --grace-period 0
for (( i = 0; i < 5; i++ )); do
if [[ $pending -eq 0 ]]; then
break
fi

if [[ $i -eq 4 ]]; then
echo "* Deleting minio forcefully"
kubectl delete pods --all --force --grace-period 0 >/dev/null 2>&1
sleep 5
break
fi
retry_count=$((retry_count + 1))
echo "$ME: waiting for ${pending} minio pods to go down"
sleep "${pending}"
pending=$(kubectl get pods --field-selector=status.phase=Running --no-headers | grep -c '^minio-' || true)

echo " ...waiting for ${pending} minio pods to go down"
sleep 30
pending=$(kubectl get pods --field-selector=status.phase=Running --no-headers 2>/dev/null | grep -c '^minio-' || true)
done
}

# usage: uninstall_minio <minio-yaml>
function uninstall_minio() {
echo "* Uninstalling minio"

minio_yaml="$1"

delete_minio "${minio_yaml}"

kubectl delete pvc --all --force
sleep 3
if ! kubectl delete pvc --all --force >/tmp/.output 2>&1; then
cat /tmp/.output
return 1
fi
sleep 5

# release all the volumes
"${DIRECTPV_CLIENT}" release --all || true
"${DIRECTPV_CLIENT}" release --all >/dev/null 2>&1 || true

while true; do
count=$("${DIRECTPV_CLIENT}" list volumes --all --no-headers | tee /dev/stderr | wc -l)
count=$("${DIRECTPV_CLIENT}" list volumes --all --no-headers 2>/dev/null | wc -l)
if [[ $count -eq 0 ]]; then
break
fi
echo "$ME: waiting for ${count} volumes to be removed"
sleep 3
echo " ...waiting for ${count} volumes to be removed"
sleep 30
done

# Show output for manual debugging.
"${DIRECTPV_CLIENT}" list drives --all
}

# usage: install_directcsi <plugin> <pod-count>
function install_directcsi() {
echo "* Installing DirectCSI"

directcsi_client="$1"
required_count="$2"

"${directcsi_client}" install
if ! "${directcsi_client}" install >/tmp/.output 2>&1; then
cat /tmp/.output
return 1
fi

running_count=0
while [[ $running_count -lt $required_count ]]; do
echo "$ME: waiting for $(( required_count - running_count )) DirectCSI pods to come up"
sleep $(( required_count - running_count ))
running_count=$(kubectl get pods --field-selector=status.phase=Running --no-headers --namespace=direct-csi-min-io | wc -l)
echo " ...waiting for $(( required_count - running_count )) DirectCSI pods to come up"
sleep 1m
running_count=$(kubectl get pods --field-selector=status.phase=Running --no-headers --namespace=direct-csi-min-io 2>/dev/null | wc -l)
done

while ! "${directcsi_client}" info; do
echo "$ME: waiting for DirectCSI to come up"
sleep 5
while ! "${directcsi_client}" info >/dev/null 2>&1; do
echo " ...waiting for DirectCSI to come up"
sleep 1m
done

sleep 1m
sleep 10
}

# usage: install_directcsi <plugin> <pod-count>
function uninstall_directcsi() {
echo "* Uninstalling DirectCSI"

directcsi_client="$1"
pending="$2"

"${directcsi_client}" uninstall
if ! "${directcsi_client}" uninstall >/tmp/.output 2>&1; then
cat /tmp/.output
return 1
fi

while [[ $pending -gt 0 ]]; do
echo "$ME: waiting for ${pending} direct-csi pods to go down"
sleep "${pending}"
pending=$(kubectl get pods --field-selector=status.phase=Running --no-headers --namespace=direct-csi-min-io | wc -l)
echo " ...waiting for ${pending} direct-csi pods to go down"
sleep 5
pending=$(kubectl get pods --field-selector=status.phase=Running --no-headers --namespace=direct-csi-min-io 2>/dev/null | wc -l)
done

while kubectl get namespace direct-csi-min-io --no-headers | grep -q .; do
echo "$ME: waiting for direct-csi-min-io namespace to be removed"
while kubectl get namespace direct-csi-min-io --no-headers 2>/dev/null | grep -q .; do
echo " ...waiting for direct-csi-min-io namespace to be removed"
sleep 5
done
}

# usage: force_install_directcsi <plugin>
function force_uninstall_directcsi() {
echo "* Uninstalling DirectCSI forcefully"

directcsi_client="$1"
"${directcsi_client}" uninstall --force --crd
if ! "${directcsi_client}" uninstall --force --crd >/tmp/.output 2>&1; then
cat /tmp/.output
return 1
fi
sleep 5
}
1 change: 0 additions & 1 deletion functests/migration-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ function migrate_test() {
remove_lvm
}

echo "-------------- Migration test on DirectCSI ${LEGACY_VERSION} -----------------------"
wget --quiet "https://github.com/minio/directpv/releases/download/${LEGACY_VERSION}/${LEGACY_FILE}"
chmod a+x "${LEGACY_FILE}"
migrate_test "./${LEGACY_FILE}" 4
22 changes: 7 additions & 15 deletions functests/tests.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,14 @@ set -ex

source "${SCRIPT_DIR}/common.sh"

function test_build() {
export DIRECTPV_CLIENT=./kubectl-directpv
install_directpv 4
add_drives
deploy_minio functests/minio.yaml
uninstall_minio functests/minio.yaml
remove_drives
uninstall_directpv 4
}

echo "$ME: Setup environment"
setup_lvm
setup_luks

echo "$ME: ================================= Run build test ================================="
test_build

export DIRECTPV_CLIENT=./kubectl-directpv
install_directpv 4
add_drives
deploy_minio functests/minio.yaml
uninstall_minio functests/minio.yaml
remove_drives
uninstall_directpv 4
remove_luks
remove_lvm