Change how volume disk location is detected
the name of the attached volume disk (like 'vdb') is in fact
quite inconsistent. It actually depends on if config drive is enabled
or not, and what format does it have, plus it may change on reboot
or rebuild.
The only valid hint at the device name of the volume is to find a block
device with a serial number corresponding to the volume UUID.
On full-featured systems like Ubuntu this could be found in
`/dev/disk/by-id/`, but on Cirros one has to search for a 'serial'
file in /sys dir with the appropriate content (luckily, that also works
on full systems too).
Also, add a sync call before unmounting to be sure the written data
was flushed to the remote disk.
Related-Issue: PRODX-37480
Change-Id: I7e4c5bc7df5d4ee2d489c3a0edc197fecc5782a2
diff --git a/heat_tempest_plugin/tests/scenario/templates/test_volumes_create_from_backup.yaml b/heat_tempest_plugin/tests/scenario/templates/test_volumes_create_from_backup.yaml
index 9fced2e..37c4cb9 100644
--- a/heat_tempest_plugin/tests/scenario/templates/test_volumes_create_from_backup.yaml
+++ b/heat_tempest_plugin/tests/scenario/templates/test_volumes_create_from_backup.yaml
@@ -17,11 +17,6 @@
type: number
description: Stack creation timeout
- dev_name:
- type: string
- description: Expected device name for volume
- default: vdb
-
rescan_timeout:
type: number
description: Max number of seconds to wait for volume after rescan
@@ -70,25 +65,27 @@
str_replace:
template: |
#!/bin/sh
+ vol_id=$(echo "volume_id" | cut -d- -f1-3)
# Trigger rescan to ensure we see the attached volume
for i in /sys/class/scsi_host/*; do echo "- - -" > $i/scan; done
# Wait for the rescan as the volume doesn't appear immediately
for i in $(seq 1 rescan_timeout)
do
- grep -q dev_name /proc/partitions && break
+ find /sys -name 'serial' -exec grep -ql $vol_id {} + && break
sleep 1
done
- if grep -q dev_name /proc/partitions
+ dev_name=$(basename $(dirname $(find /sys -name 'serial' -exec grep -l $vol_id {} +)))
+ if grep -q $dev_name /proc/partitions
then
- mount /dev/dev_name /mnt
+ mount /dev/$dev_name /mnt
TESTDATA=$(cat /mnt/testfile)
curl wc_extra_args -X PUT -H 'Content-Type:' --data-binary '{"Status": "SUCCESS", "Reason": "Test Complete", "Data": "Volume Data:'$TESTDATA'", "UniqueId": "instance1"}' "wc_url"
else
- curl wc_extra_args -X PUT -H 'Content-Type:' --data-binary '{"Status": "FAILURE", "Reason": "Test Failed", "Data": "Expected device dev_name not found.", "UniqueId": "instance1"}' "wc_url"
+ curl wc_extra_args -X PUT -H 'Content-Type:' --data-binary '{"Status": "FAILURE", "Reason": "Test Failed", "Data": "Expected device for volume volume_id not found.", "UniqueId": "instance1"}' "wc_url"
fi
params:
wc_url: { get_resource: wait_handle }
- dev_name: { get_param: dev_name }
+ volume_id: { get_resource: volume }
rescan_timeout: { get_param: rescan_timeout }
wc_extra_args: { get_param: wc_extra_args }
diff --git a/heat_tempest_plugin/tests/scenario/templates/test_volumes_delete_snapshot.yaml b/heat_tempest_plugin/tests/scenario/templates/test_volumes_delete_snapshot.yaml
index 6d11026..1864ebd 100644
--- a/heat_tempest_plugin/tests/scenario/templates/test_volumes_delete_snapshot.yaml
+++ b/heat_tempest_plugin/tests/scenario/templates/test_volumes_delete_snapshot.yaml
@@ -17,11 +17,6 @@
type: number
description: Stack creation timeout
- dev_name:
- type: string
- description: Expected device name for volume
- default: vdb
-
test_string:
type: string
description: Test string which is written to volume
@@ -77,27 +72,30 @@
str_replace:
template: |
#!/bin/sh
+ vol_id=$(echo "volume_id" | cut -d- -f1-3)
# Trigger rescan to ensure we see the attached volume
for i in /sys/class/scsi_host/*; do echo "- - -" > $i/scan; done
# Wait for the rescan as the volume doesn't appear immediately
for i in $(seq 1 rescan_timeout)
do
- grep -q dev_name /proc/partitions && break
+ find /sys -name 'serial' -exec grep -ql $vol_id {} + && break
sleep 1
done
- if grep -q dev_name /proc/partitions
+ dev_name=$(basename $(dirname $(find /sys -name 'serial' -exec grep -l $vol_id {} +)))
+ if grep -q $dev_name /proc/partitions
then
- mkfs.ext4 /dev/dev_name
- mount /dev/dev_name /mnt
+ mkfs.ext4 /dev/$dev_name
+ mount /dev/$dev_name /mnt
echo "test_string" > /mnt/testfile
+ sync -f /mnt/testfile
umount /mnt
curl wc_extra_args -X PUT -H 'Content-Type:' --data-binary '{"Status": "SUCCESS", "Reason": "Test Complete", "Data": "Completed volume configuration.", "UniqueId": "instance1"}' "wc_url"
else
- curl wc_extra_args -X PUT -H 'Content-Type:' --data-binary '{"Status": "FAILURE", "Reason": "Test Failed", "Data": "Expected device dev_name not found.", "UniqueId": "instance1"}' "wc_url"
+ curl wc_extra_args -X PUT -H 'Content-Type:' --data-binary '{"Status": "FAILURE", "Reason": "Test Failed", "Data": "Expected device for volume volume_id not found.", "UniqueId": "instance1"}' "wc_url"
fi
params:
wc_url: { get_resource: wait_handle }
- dev_name: { get_param: dev_name }
+ volume_id: { get_resource: volume }
rescan_timeout: { get_param: rescan_timeout }
test_string: { get_param: test_string }
wc_extra_args: { get_param: wc_extra_args }