From 5edd3059bbfc22d1324d03ab128dfc2a86759bdd Mon Sep 17 00:00:00 2001 From: Maxim Sava Date: Sun, 21 Apr 2024 16:49:35 +0300 Subject: [PATCH] Add disk_format kuttl tests This patch introduces kuttl tests to check the resources that are supposed to be generated when the disk_format is defined. --- config/samples/disk_formats/README.md | 68 +++++++++++++++++ config/samples/disk_formats/create-image.sh | 73 +++++++++++++++++++ .../tests/glance_disk_formats/00-assert.yaml | 46 ++++++++++++ .../tests/glance_disk_formats/00-deploy.yaml | 7 ++ .../glance_disk_formats/01-create_image.yaml | 9 +++ .../tests/glance_disk_formats/02-cleanup.yaml | 5 ++ .../tests/glance_disk_formats/03-errors.yaml | 39 ++++++++++ .../kuttl/tests/glance_disk_formats/README.md | 23 ++++++ 8 files changed, 270 insertions(+) create mode 100644 config/samples/disk_formats/create-image.sh create mode 100644 test/kuttl/tests/glance_disk_formats/00-assert.yaml create mode 100644 test/kuttl/tests/glance_disk_formats/00-deploy.yaml create mode 100644 test/kuttl/tests/glance_disk_formats/01-create_image.yaml create mode 100644 test/kuttl/tests/glance_disk_formats/02-cleanup.yaml create mode 100644 test/kuttl/tests/glance_disk_formats/03-errors.yaml create mode 100644 test/kuttl/tests/glance_disk_formats/README.md diff --git a/config/samples/disk_formats/README.md b/config/samples/disk_formats/README.md index 3e2e92f0..9911931d 100644 --- a/config/samples/disk_formats/README.md +++ b/config/samples/disk_formats/README.md @@ -59,3 +59,71 @@ from this directory to make the changes. You can find more about disk-formats configuration options in the [upstream](https://docs.openstack.org/glance/latest/configuration/configuring.html#configuring-supported-disk-formats) documentation. + +## How to test +The steps and overview about a feature described in [disk-format](../../../../config/samples/disk_formats/) document +We assume one GlanceAPIs exist, disk format is enabled with disk formats +'raw, iso' and image is created with same disk format. + +### Step 1: Create image +In this step we create images with 'raw' and 'iso' disk formats +```bash + $glance --verbose image-create \ + --disk-format "$1" \ + --container-format bare \ + --name "${IMAGE_NAME}" +``` + +## EXAMPLE + +The example assumes a glanceAPI is deployed using [single layout](https://github.com/openstack-k8s-operators/glance-operator/tree/main/config/samples/layout/single). + +Copy the [`create-image.sh`](create-image.sh) script to the target container +where the `glance` cli is available. +For example: + +```bash +$oc cp create-image.sh openstackclient:/scripts +``` + +Create image with 'raw' disk format + +```bash +sh-5.1# bash create-image.sh raw +glance --os-auth-url https://keystone-public-openstack.apps-crc.testing --os-project-name admin --os-username admin --os-password 12345678 --os-user-domain- +name default --os-project-domain-name default --verbose image-create --disk-format raw --container-format bare --name myimage-disk_format-test ++------------------+--------------------------------------+ +| Property | Value | ++------------------+--------------------------------------+ +| checksum | None | +| container_format | bare | +| created_at | 2024-05-02T13:15:45Z | +| disk_format | raw | +| id | 32737bf5-2546-4d6f-9800-80cc5afed30d | +| locations | [] | +| min_disk | 0 | +| min_ram | 0 | +| name | myimage-disk_format-test | +| os_hash_algo | None | +| os_hash_value | None | +| os_hidden | False | +| owner | 7ac7162bc58f44af824fd8f2ce68987f | +| protected | False | +| size | None | +| status | queued | +| tags | [] | +| updated_at | 2024-05-02T13:15:45Z | +| virtual_size | Not available | +| visibility | shared | ++------------------+--------------------------------------+ + +glance --os-auth-url https://keystone-public-openstack.apps-crc.testing --os-project-name admin --os-username admin --os-password 12345678 --os-user-domain-name default --os-project-domain-name default image-list ++--------------------------------------+--------------------------+ +| ID | Name | ++--------------------------------------+--------------------------+ +| 32737bf5-2546-4d6f-9800-80cc5afed30d | myimage-disk_format-test | ++--------------------------------------+--------------------------+ + ++ echo 'Successfully created image' +Successfully created image +``` diff --git a/config/samples/disk_formats/create-image.sh b/config/samples/disk_formats/create-image.sh new file mode 100644 index 00000000..5d53b5f5 --- /dev/null +++ b/config/samples/disk_formats/create-image.sh @@ -0,0 +1,73 @@ +#!/bin/bash +set -evx +# Create a image with supported disk format +# +# The scripts assumes: +# +# 1. an available glance cli +# 2. control plane configured with disk formats +# 2. a single layout (file / NFS) backend and disk format is deployed +# +# +KEYSTONE=$(awk '/auth_url/ {print $2}' "/$HOME/.config/openstack/clouds.yaml") +USER=${USER:-"admin"} +TIME=5 +DOMAIN=${DOMAIN:-"glance-default-single.openstack.svc:9292"} +IMAGE_NAME="myimage-disk_format-test" +ADMIN_PWD=${ADMIN_PWD:-12345678} +EXIT_CODE=$? + + +function create_image() { + # This method is create, list and delete image + # $1 - disk format + glance="glance --os-auth-url ${KEYSTONE} + --os-project-name ${USER} \ + --os-username ${USER} \ + --os-password ${ADMIN_PWD} \ + --os-user-domain-name default \ + --os-project-domain-name default " + + echo This is a dodgy image > "${IMAGE_NAME}" + + $glance --verbose image-create \ + --disk-format "$1" \ + --container-format bare \ + --name "${IMAGE_NAME}" + + ID=$($glance image-list | awk -v img=$IMAGE_NAME '$0 ~ img {print $2}') + echo "Image ID: $ID" + sleep "${TIME}" + + if [ -z "$ID" ] + then + echo "Could not create image " >&2 + $glance image-delete "$ID" + status=$($glance image-delete "$ID" | awk '/status/{print $4}') + printf "Image Status: %s\n" "$status" + exit 1 + else + echo "Continue" + fi + + # Stage 2 - Check the image is active + $glance image-list + status=$($glance image-show "$ID" | awk '/status/{print $4}') + printf "Image Status: %s\n" "$status" + + # Stage 3 - Delete the image + $glance image-delete "$ID" + status=$($glance image-delete "$ID" | awk '/status/{print $4}') + printf "Image Status: %s\n" "$status" +} + +create_image "$1" +if [ -z $? ] +then + echo "Could not create image "; exit 1 +elif [ $EXIT_CODE == 0 ] +then + echo "Successfully created image" +else + echo "Could not create image " >&2; exit 1 +fi diff --git a/test/kuttl/tests/glance_disk_formats/00-assert.yaml b/test/kuttl/tests/glance_disk_formats/00-assert.yaml new file mode 100644 index 00000000..5fb0bf98 --- /dev/null +++ b/test/kuttl/tests/glance_disk_formats/00-assert.yaml @@ -0,0 +1,46 @@ +# Check for: +# - Glance CR with 1 replicas for a single GlanceAPI +# - GlanceAPI glance-default-single StatefulSet with 1 replicas +# - OpenStackClient Pod available + +apiVersion: glance.openstack.org/v1beta1 +kind: Glance +metadata: + name: glance +spec: + glanceAPIs: + default: + replicas: 1 +--- +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: glance-default-single +spec: + replicas: 1 +status: + availableReplicas: 1 + replicas: 1 +--- +apiVersion: v1 +kind: Pod +metadata: + name: openstackclient + labels: + service: openstackclient +--- +# Verify if disk formats is configured +apiVersion: kuttl.dev/v1beta1 +kind: TestAssert +namespaced: true +commands: + - script: | + template='{{.spec.customServiceConfig}}' + regex="disk_formats" + disk_formats=$(oc get -n $NAMESPACE Glance glance -o go-template="$template") + matches=$(echo $disk_formats | sed 's/.*disk_formats=\([^ ]*\).*/\1/') + if [ -z "$matches" ]; then + exit 1 + else + exit 0 + fi diff --git a/test/kuttl/tests/glance_disk_formats/00-deploy.yaml b/test/kuttl/tests/glance_disk_formats/00-deploy.yaml new file mode 100644 index 00000000..711258ed --- /dev/null +++ b/test/kuttl/tests/glance_disk_formats/00-deploy.yaml @@ -0,0 +1,7 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestStep +commands: + - script: | + oc kustomize ../../../../config/samples/layout/single | oc apply -n $NAMESPACE -f - + - script: | + oc kustomize ../../../../config/samples/disk_formats | oc apply -n $NAMESPACE -f - diff --git a/test/kuttl/tests/glance_disk_formats/01-create_image.yaml b/test/kuttl/tests/glance_disk_formats/01-create_image.yaml new file mode 100644 index 00000000..c04c2a23 --- /dev/null +++ b/test/kuttl/tests/glance_disk_formats/01-create_image.yaml @@ -0,0 +1,9 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestStep +commands: + - command: | + # oc exec -it openstackclient -n $NAMESPACE -- /bin/bash -c "bash /home/cloud-admin/create-image.sh raw" + oc -n $NAMESPACE exec -it openstackclient --stdin=false -- /bin/sh -c "DOMAIN=glance-default-single.$NAMESPACE.svc ./scripts/create-image.sh raw" + - command: | + # oc exec -it openstackclient -n $NAMESPACE -- /bin/bash -c "bash /home/cloud-admin/create-image.sh iso" + oc -n $NAMESPACE exec -it openstackclient --stdin=false -- /bin/sh -c "DOMAIN=glance-default-single.$NAMESPACE.svc ./scripts/create-image.sh iso" diff --git a/test/kuttl/tests/glance_disk_formats/02-cleanup.yaml b/test/kuttl/tests/glance_disk_formats/02-cleanup.yaml new file mode 100644 index 00000000..3058481e --- /dev/null +++ b/test/kuttl/tests/glance_disk_formats/02-cleanup.yaml @@ -0,0 +1,5 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestStep +commands: + - script: | + oc kustomize ../../../../config/samples/layout/single | oc delete -n $NAMESPACE -f - diff --git a/test/kuttl/tests/glance_disk_formats/03-errors.yaml b/test/kuttl/tests/glance_disk_formats/03-errors.yaml new file mode 100644 index 00000000..9f4bef69 --- /dev/null +++ b/test/kuttl/tests/glance_disk_formats/03-errors.yaml @@ -0,0 +1,39 @@ +# +# Check for: +# - No Glance CR +# - No GlanceAPI glance-single CR +# - No GlanceAPI glance-api StatefulSet +# - No glance-api Pod +# - No glance-public service +# - No glance internal and public endpoints + +apiVersion: glance.openstack.org/v1beta1 +kind: Glance +metadata: + name: glance +--- +apiVersion: glance.openstack.org/v1beta1 +kind: GlanceAPI +metadata: + name: glance-default-single +--- +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: glance-default-single +--- +apiVersion: v1 +kind: Pod +metadata: + labels: + service: glance +--- +apiVersion: v1 +kind: Service +metadata: + name: glance-default-internal +--- +apiVersion: v1 +kind: Service +metadata: + name: glance-default-public diff --git a/test/kuttl/tests/glance_disk_formats/README.md b/test/kuttl/tests/glance_disk_formats/README.md new file mode 100644 index 00000000..5e699176 --- /dev/null +++ b/test/kuttl/tests/glance_disk_formats/README.md @@ -0,0 +1,23 @@ +# How to test + +The goal of this test is to verify if user can set disk format for image that should be created + +## Kuttl test steps +The steps and overview about a feature described in [disk-format](../../../../config/samples/disk_formats/) document +We assume one GlanceAPIs exist, disk format is enabled with disk formats +'raw, iso' and image is created with same disk format. + +### Step 1: Create image +In this step we create images with disk formats 'raw,iso' +```bash + $glance --verbose image-create \ + --disk-format "$1" \ + --container-format bare \ + --name "${IMAGE_NAME}" +``` + +## Conclusion +The steps described above are automated by this +[script](../../../../config/samples/glance_disk_formats/create-image.sh) +that is executed by the kuttl test once the environment is deployed and the +`openstackclient` is ready.