Skip to content

Commit

Permalink
Add disk_format kuttl tests
Browse files Browse the repository at this point in the history
This patch introduces kuttl tests to check the resources that are
supposed to be generated when the disk_format is defined.
  • Loading branch information
maximsava12 committed May 2, 2024
1 parent e0b4b68 commit 5edd305
Show file tree
Hide file tree
Showing 8 changed files with 270 additions and 0 deletions.
68 changes: 68 additions & 0 deletions config/samples/disk_formats/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
73 changes: 73 additions & 0 deletions config/samples/disk_formats/create-image.sh
Original file line number Diff line number Diff line change
@@ -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"}

This comment has been minimized.

Copy link
@fmount

fmount May 2, 2024

Contributor

do we need this parameter here?

This comment has been minimized.

Copy link
@maximsava12

maximsava12 May 5, 2024

Author

Done.Removed

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}

This comment has been minimized.

Copy link
@fmount

fmount May 2, 2024

Contributor

wondering if we can use the openstackclient instead of there's a gap w/ the glance-client

--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 \

This comment has been minimized.

Copy link
@fmount

fmount May 2, 2024

Contributor

two questions:

  1. is --verbose necessary? if so, let's use a DEBUG option to toggle this behavior
  2. isn't this function covered in the regular openstack cli ?

This comment has been minimized.

Copy link
@maximsava12

maximsava12 May 5, 2024

Author

Changed to openstack cli

--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
46 changes: 46 additions & 0 deletions test/kuttl/tests/glance_disk_formats/00-assert.yaml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions test/kuttl/tests/glance_disk_formats/00-deploy.yaml
Original file line number Diff line number Diff line change
@@ -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 -
9 changes: 9 additions & 0 deletions test/kuttl/tests/glance_disk_formats/01-create_image.yaml
Original file line number Diff line number Diff line change
@@ -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"

This comment has been minimized.

Copy link
@fmount

fmount May 2, 2024

Contributor

rm comment

This comment has been minimized.

Copy link
@maximsava12

maximsava12 May 5, 2024

Author

Done

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"

This comment has been minimized.

Copy link
@fmount

fmount May 2, 2024

Contributor

rm comment

This comment has been minimized.

Copy link
@maximsava12

maximsava12 May 5, 2024

Author

Done

oc -n $NAMESPACE exec -it openstackclient --stdin=false -- /bin/sh -c "DOMAIN=glance-default-single.$NAMESPACE.svc ./scripts/create-image.sh iso"
5 changes: 5 additions & 0 deletions test/kuttl/tests/glance_disk_formats/02-cleanup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- script: |
oc kustomize ../../../../config/samples/layout/single | oc delete -n $NAMESPACE -f -
39 changes: 39 additions & 0 deletions test/kuttl/tests/glance_disk_formats/03-errors.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#

This comment has been minimized.

Copy link
@fmount

fmount May 2, 2024

Contributor

this should be 02-errors.yaml

This comment has been minimized.

Copy link
@maximsava12

maximsava12 May 5, 2024

Author

Done

# 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
23 changes: 23 additions & 0 deletions test/kuttl/tests/glance_disk_formats/README.md
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 5edd305

Please sign in to comment.