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

Add disk_format kuttl tests #518

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
67 changes: 67 additions & 0 deletions config/samples/disk_formats/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,70 @@ 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
openstack image create \
--disk-format "$1" \
--container-format bare \
"${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 `openstack` 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
openstack image create --disk-format raw --container-format bare 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 |
+------------------+--------------------------------------+

+ openstack image list
+--------------------------------------+--------------------------+--------+
| ID | Name | Status |
+--------------------------------------+--------------------------+--------+
| 5bdde056-b7c6-451d-a7dd-cbee9c8ed4a5 | myimage-disk_format-test | active |
+--------------------------------------+--------------------------+--------+

+ echo 'Successfully created image'
Successfully created image
```
66 changes: 66 additions & 0 deletions config/samples/disk_formats/create-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash
set -evx
# Create a image with supported disk format
#
# The scripts assumes:
#
# 1. an available openstack cli
# 2. glanceAPI configured with disk formats
# 3. a single layout (file / NFS) backend and disk format is deployed
#
#
TIME=5
IMAGE_NAME="myimage-disk_format-test"
EXIT_CODE=$?


function create_image() {
# This method is create, list and delete image
# $1 - disk format

echo This is a dodgy image > "${IMAGE_NAME}"

# Stage 0 - Delete any pre-existing image
openstack image list -c ID -f value | xargs -n 1 openstack image delete
sleep "${TIME}"

# Stage 1 - Create image
openstack image create \
--disk-format "$1" \
--container-format bare \
"${IMAGE_NAME}"

ID=$(openstack image list | awk -v img=$IMAGE_NAME '$0 ~ img {print $2}')
echo "Image ID: $ID"
sleep "${TIME}"

if [ -z "$ID" ]
then
openstack image list -c ID -f value | xargs -n 1 openstack image delete
exit 1
fi

# Stage 2 - Check the image is active
openstack image list
maximsava12 marked this conversation as resolved.
Show resolved Hide resolved
fmount marked this conversation as resolved.
Show resolved Hide resolved
status=$(openstack image show "$ID" | awk '/status/{print $4}')
if [ "$status" == 'active' ]
then
printf "Image Status: %s\n" "$status"
exit 0
else
printf "Image Status: %s\n" "$status"
exit 1
fi

}

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 -
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this line (L5), and instead change config/samples/disk_format/disk_format.yaml to be like the following:

# Inject inject_metadata config
apiVersion: glance.openstack.org/v1beta1
kind: Glance
metadata:
  name: glance
spec:
  serviceUser: glance
  databaseInstance: openstack
  databaseAccount: glance
  keystoneEndpoint: default
  customServiceConfig: |
    [image_format]
    disk_formats=raw,iso
  glanceAPIs:
    default:
      type: single
      replicas: 1

This way you can directly deploy what you need with a single command.
Also, given this layout covers a kuttl test, can we move disk_format under layout folder?

- script: |
oc kustomize ../../../../config/samples/disk_formats | oc apply -n $NAMESPACE -f -
7 changes: 7 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,7 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- command: |
oc -n $NAMESPACE exec -it openstackclient --stdin=false -- /bin/sh -c "DOMAIN=glance-default-single.$NAMESPACE.svc ./scripts/create-image.sh raw"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the script I think you don't need "DOMAIN=glance-default-single.$NAMESPACE.svc.
Remove it from L5 and L7.

- command: |
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 -
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L5 here can be changed to be:

oc kustomize ../../../../config/samples/layout/disk_format | oc delete -n $NAMESPACE -f -

after you move everything under layout directory.

39 changes: 39 additions & 0 deletions test/kuttl/tests/glance_disk_formats/02-errors.yaml
Original file line number Diff line number Diff line change
@@ -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
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
$openstack image create \
--disk-format "$1" \
--container-format bare \
"${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.