Skip to content

Commit

Permalink
Merge pull request openstack-k8s-operators#658 from bogdando/test_vm_…
Browse files Browse the repository at this point in the history
…cinder

Don't use/verify Cinder capabilities if no backend
  • Loading branch information
jistr authored Oct 29, 2024
2 parents bd46990 + b54eeb9 commit 1e3f55f
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 35 deletions.
4 changes: 4 additions & 0 deletions docs_dev/assemblies/development_environment.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,13 @@ Create a test VM instance with a test volume attachement:
[,bash]
----
cd ~/data-plane-adoption
export CINDER_VOLUME_BACKEND_CONFIGURED=true <1>
export CINDER_BACKUP_BACKEND_CONFIGURED=true
OS_CLOUD_IP=192.168.122.100 OS_CLOUD_NAME=standalone \
bash tests/roles/development_environment/files/pre_launch.bash
----
<1> Use `CINDER_*_BACKEND_CONFIGURED=false`, if Cinder Volume or Backup services' storage backends have been not configured for the source cloud,
or won't be configured for the target cloud. That might be a valid case for some developement setups, but not for a production scenarios.

This also creates a test Cinder volume, a backup from it, and a snapshot of it.

Expand Down
4 changes: 4 additions & 0 deletions tests/roles/dataplane_adoption/defaults/main.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Supported storage backends for Cinder of the target cloud
# must match those configured for the source cloud
supported_backup_backends: []
supported_volume_backends: []
netconfig_networks:
- name: ctlplane
dnsDomain: ctlplane.example.com
Expand Down
14 changes: 9 additions & 5 deletions tests/roles/dataplane_adoption/tasks/cinder_verify.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,26 @@
osc_header: |
alias openstack="oc exec -t openstackclient -- openstack"
- name: Verify that the volumes have correct name, status and size
when: prelaunch_test_instance|bool
- name: Verify that the volumes and snapshots have correct name, status and size
when:
- prelaunch_test_instance|bool
- cinder_volume_backend in supported_volume_backends
ansible.builtin.shell: |
{{ osc_header }}
${BASH_ALIASES[openstack]} volume list -c Name -c Status -c Size -f value | grep "disk in-use 1"
${BASH_ALIASES[openstack]} volume list -c Name -c Status -c Size -f value | grep "boot-volume in-use 1"
${BASH_ALIASES[openstack]} volume snapshot list -c Name -c Status -c Size -f value | grep "snapshot available 1"
register: cinder_verify_volumes
until: cinder_verify_volumes is success
retries: 10
delay: 2

- name: verify the snapshot and backup of disk volume
when: prelaunch_test_instance|bool
- name: verify the backup of disk volume
when:
- prelaunch_test_instance|bool
- cinder_backup_backend in supported_backup_backends
ansible.builtin.shell: |
{{ osc_header }}
${BASH_ALIASES[openstack]} volume snapshot list -c Name -c Status -c Size -f value | grep "snapshot available 1"
${BASH_ALIASES[openstack]} volume backup list -c Name -c Status -c Size -f value | grep "backup available 1"
register: cinder_verify_resources
until: cinder_verify_resources is success
Expand Down
4 changes: 4 additions & 0 deletions tests/roles/development_environment/defaults/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ edpm_privatekey_path: ~/install_yamls/out/edpm/ansibleee-ssh-key-id_rsa
run_pre_adoption_validation: true
os_cloud_name: standalone
source_osp_ssh_user: root
# Supported storage backends for Cinder of the source cloud
# must match those configured for the target cloud
supported_volume_backends: []
supported_backup_backends: []
# override var for openstack command to use on the source cloud
openstack_command: >-
ssh -i {{ edpm_privatekey_path }} -o StrictHostKeyChecking=no {{ source_osp_ssh_user }}@{{ standalone_ip | default(edpm_node_ip) }} OS_CLOUD={{ os_cloud_name }} openstack
73 changes: 43 additions & 30 deletions tests/roles/development_environment/files/pre_launch.bash
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,44 @@ function wait_for_status() {
done
}

function create_volume_resources() {
# create a data volume
if ! ${BASH_ALIASES[openstack]} volume show disk ; then
${BASH_ALIASES[openstack]} volume create --image cirros --size 1 disk
wait_for_status "volume show disk" "test volume 'disk' creation"
fi

# create volume snapshot
if ! ${BASH_ALIASES[openstack]} volume snapshot show snapshot ; then
${BASH_ALIASES[openstack]} volume snapshot create --volume disk snapshot
wait_for_status "volume snapshot show snapshot" "test volume 'disk' snapshot availability"
fi

# Add volume to the test VM
if ${BASH_ALIASES[openstack]} volume show disk -f json | jq -r '.status' | grep -q available ; then
${BASH_ALIASES[openstack]} server add volume test disk
fi
}

function create_backup_resources() {
# create volume backup
if ! ${BASH_ALIASES[openstack]} volume backup show backup; then
${BASH_ALIASES[openstack]} volume backup create --name backup disk --force
wait_for_status "volume backup show backup" "test volume 'disk' backup completion"
fi
}

function create_bfv_volume() {
# Launch an instance from boot-volume (BFV)
if ! ${BASH_ALIASES[openstack]} volume show boot-volume ; then
${BASH_ALIASES[openstack]} volume create --image cirros --size 1 boot-volume
wait_for_status "volume show boot-volume" "test volume 'boot-volume' creation"
fi
if ${BASH_ALIASES[openstack]} volume show boot-volume -f json | jq -r '.status' | grep -q available ; then
${BASH_ALIASES[openstack]} server create --flavor m1.small --volume boot-volume --nic net-id=private bfv-server --wait
fi
}

# Create Image
IMG=cirros-0.5.2-x86_64-disk.img
URL=http://download.cirros-cloud.net/0.5.2/$IMG
Expand Down Expand Up @@ -67,36 +105,11 @@ export FIP=192.168.122.20
# check connectivity via FIP
ping -c4 ${FIP}

# create bootable volume
if ! ${BASH_ALIASES[openstack]} volume show disk ; then
${BASH_ALIASES[openstack]} volume create --image cirros --size 1 disk
wait_for_status "volume show disk" "test volume 'disk' creation"
fi

# create volume backup
if ! ${BASH_ALIASES[openstack]} volume backup show backup; then
${BASH_ALIASES[openstack]} volume backup create --name backup disk
wait_for_status "volume backup show backup" "test volume 'disk' backup completion"
fi

# create volume snapshot
if ! ${BASH_ALIASES[openstack]} volume snapshot show snapshot ; then
${BASH_ALIASES[openstack]} volume snapshot create --volume disk snapshot
wait_for_status "volume snapshot show snapshot" "test volume 'disk' snapshot availability"
fi

# Add volume to the test VM
if ${BASH_ALIASES[openstack]} volume show disk -f json | jq -r '.status' | grep -q available ; then
${BASH_ALIASES[openstack]} server add volume test disk
fi

# create another bootable volume
if ! ${BASH_ALIASES[openstack]} volume show boot-volume ; then
${BASH_ALIASES[openstack]} volume create --image cirros --size 1 boot-volume
wait_for_status "volume show boot-volume" "test volume 'boot-volume' creation"
if [ "$CINDER_VOLUME_BACKEND_CONFIGURED" = "true" ]; then
create_volume_resources
create_bfv_volume
fi

# Launch an instance from boot-volume (BFV)
if ${BASH_ALIASES[openstack]} volume show boot-volume -f json | jq -r '.status' | grep -q available ; then
${BASH_ALIASES[openstack]} server create --flavor m1.small --volume boot-volume --nic net-id=private bfv-server --wait
if [ "$CINDER_BACKUP_BACKEND_CONFIGURED" = "true" ]; then
create_backup_resources
fi
5 changes: 5 additions & 0 deletions tests/roles/development_environment/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
- name: pre-launch test VM instance
no_log: "{{ use_no_log }}"
when: prelaunch_test_instance|bool
vars:
cinder_volume_backend_configured: "{{ cinder_volume_backend in supported_volume_backends }}"
cinder_backup_backend_configured: "{{ cinder_backup_backend in supported_backup_backends }}"
ansible.builtin.shell:
cmd: |
{{ shell_header }}
export OPENSTACK_COMMAND="{{ openstack_command }}"
export CINDER_VOLUME_BACKEND_CONFIGURED={{ cinder_volume_backend_configured | string | lower }}
export CINDER_BACKUP_BACKEND_CONFIGURED={{ cinder_backup_backend_configured | string | lower }}
{{ lookup('ansible.builtin.file', prelaunch_test_instance_script) }}
- name: creates Barbican secret
Expand Down
13 changes: 13 additions & 0 deletions tests/vars.sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ ironic_adoption: false
# Run pre-adoption validation before the deploying
run_pre_adoption_validation: true

# Supported storage backends for Cinder
supported_volume_backends: #CUSTOMIZE_THIS
- ceph
- iscsi
- nfs
- fc

supported_backup_backends: #CUSTOMIZE_THIS
- ceph
- s3
- nfs
- swift

# Whether the adopted node will host compute services
compute_adoption: true

Expand Down

0 comments on commit 1e3f55f

Please sign in to comment.