Skip to content

Commit f4fa9de

Browse files
committed
Add scripts to simplify Tempest testing
1 parent bea4685 commit f4fa9de

File tree

3 files changed

+177
-0
lines changed

3 files changed

+177
-0
lines changed

.automation.conf/run-tempest.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash
2+
3+
# Script based on Tempest section of Kayobe multinode deployment script
4+
# plus https://wiki.stackhpc.com/doc/using-kayobe-automation-to-run-tempest-7yAEJw2eHb
5+
6+
set -euo pipefail
7+
8+
KAYOBE_CONFIG_BASE_PATH=$KAYOBE_CONFIG_PATH/../../
9+
10+
# Set Tempest env vars if not already set
11+
set +x
12+
: "${KAYOBE_AUTOMATION_SSH_PRIVATE_KEY:=$(cat ~/.ssh/id_rsa)}"
13+
: "${TEMPEST_OPENRC:=$(cat $KAYOBE_CONFIG_PATH/../kolla/public-openrc.sh)}"
14+
set -x
15+
16+
# Ensure timestamped output dir exists
17+
OUTPUT_DIR=$KAYOBE_CONFIG_BASE_PATH/tempest-artifacts/$KAYOBE_ENVIRONMENT/$(date +%Y-%m-%d--T%H-%M-%S)
18+
echo Creating output directory: $OUTPUT_DIR
19+
mkdir -p $OUTPUT_DIR
20+
21+
22+
# Set base image for Kayobe container. Use Rocky 9 for zed+ CentOS otherwise
23+
if grep -Eq "(202|zed)" $KAYOBE_CONFIG_BASE_PATH/.gitreview; then
24+
export BASE_IMAGE=rockylinux:9
25+
else
26+
export BASE_IMAGE=quay.io/centos/centos:stream8
27+
fi
28+
29+
# Ensure the Kayobe image exists
30+
IMAGE_TAG="kayobe"
31+
if [[ "$(sudo docker image ls)" == *$IMAGE_TAG* ]]; then
32+
echo "Image already exists skipping docker build"
33+
else
34+
sudo DOCKER_BUILDKIT=1 docker build \
35+
--network host \
36+
--build-arg BASE_IMAGE=$BASE_IMAGE \
37+
--build-arg HTTP_PROXY=$http_proxy \
38+
--build-arg HTTPS_PROXY=$https_proxy \
39+
--build-arg NO_PROXY=$no_proxy \
40+
--file $KAYOBE_CONFIG_BASE_PATH/.automation/docker/kayobe/Dockerfile \
41+
--tag $IMAGE_TAG:latest $KAYOBE_CONFIG_BASE_PATH
42+
fi
43+
44+
# Run Tempest
45+
sudo -E docker run --rm \
46+
--name kayobe_automation \
47+
--network host \
48+
-v $KAYOBE_CONFIG_BASE_PATH:/stack/kayobe-automation-env/src/kayobe-config \
49+
-v $OUTPUT_DIR:/stack/tempest-artifacts \
50+
-e KAYOBE_ENVIRONMENT -e KAYOBE_VAULT_PASSWORD -e KAYOBE_AUTOMATION_SSH_PRIVATE_KEY \
51+
-e TEMPEST_OPENRC \
52+
$IMAGE_TAG:latest \
53+
/stack/kayobe-automation-env/src/kayobe-config/.automation/pipeline/tempest.sh \
54+
-e ansible_user=stack -e rally_no_sensitive_log=false
55+
56+
# Fix output dir ownership
57+
sudo chown -R stack:stack $OUTPUT_DIR
58+
59+
# Uncomment to copy failures into a load list for easy retry
60+
# cp $OUTPUT_DIR/failed-tests $KAYOBE_CONFIG_BASE_PATH/.automation.conf/tempest/load-lists/$KAYOBE_ENVIRONMENT-failed-tests
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#!/bin/bash
2+
3+
# Helper script that will attempt to delete leftover resources from tempest testing.
4+
# Usage: tempest-cleanup.sh [--dry-run]
5+
6+
# NOTE: This script is provided as a convenience and may not cover all
7+
# resources created by tempest. In particular, it does not attempt to delete
8+
# floating IPs and can have issues with ports attached to other resources. Use
9+
# with caution.
10+
11+
DRY_RUN=false
12+
13+
if [[ $1 == "--dry-run" ]]; then
14+
DRY_RUN=true
15+
echo "Dry run mode activated. No resources will be deleted."
16+
fi
17+
18+
# Ensure openstack CLI is available
19+
if ! command -v openstack > /dev/null; then
20+
echo "openstack command not found. Ensure you have sourced a virtual environment with the openstack CLI installed."
21+
exit 1
22+
elif ! openstack network list > /dev/null; then
23+
echo "openstack command failed. Ensure you have sourced an openrc file."
24+
exit 1
25+
fi
26+
27+
# Function to delete ports based on subnet IDs
28+
function delete_ports {
29+
local subnet_ids=$1
30+
for subnet_id in $subnet_ids; do
31+
port_ids=$(openstack port list --fixed-ip subnet=$subnet_id -f value -c ID)
32+
if [[ -z $port_ids ]]; then
33+
echo "No ports found for subnet $subnet_id"
34+
continue
35+
fi
36+
for port_id in $port_ids; do
37+
local port_name=$(openstack port show $port_id -f value -c name)
38+
local device_owner=$(openstack port show $port_id -f value -c device_owner)
39+
if [[ $device_owner == "network:router_interface" ]] || [[ $device_owner == "network:ha_router_replicated_interface" ]]; then
40+
local router_id=$(openstack port show $port_id -f value -c device_id)
41+
if $DRY_RUN; then
42+
echo "Would remove router interface on port $port_id $port_name from router $router_id"
43+
else
44+
echo "Removing router interface on port $port_id $port_name from router $router_id..."
45+
openstack router remove port $router_id $port_id || echo "Failed to remove router interface on port $port_id $port_name from router $router_id"
46+
fi
47+
fi
48+
if $DRY_RUN; then
49+
echo "Would delete port $port_id $port_name"
50+
else
51+
echo "Deleting port $port_id $port_name..."
52+
openstack port delete $port_id || echo "Failed to delete port $port_id $port_name"
53+
fi
54+
done
55+
done
56+
}
57+
58+
# Function to delete resources based on type and name prefix
59+
function delete_resources {
60+
local resource_type=$1
61+
local name_prefix=$2
62+
# If resource type is server, volume, or image, list all
63+
if [[ $resource_type == "server" ]] || [[ $resource_type == "volume" ]] || [[ $resource_type == "image" ]]; then
64+
id_name_list=$(openstack $resource_type list --all -f value -c ID -c Name | awk -v prefix="$name_prefix" '$2 ~ "^"prefix {print $1, $2}')
65+
else
66+
id_name_list=$(openstack $resource_type list -f value -c ID -c Name | awk -v prefix="$name_prefix" '$2 ~ "^"prefix {print $1, $2}')
67+
fi
68+
if [[ -z $id_name_list ]]; then
69+
echo "No $resource_type resources found with prefix $name_prefix"
70+
return
71+
fi
72+
while IFS= read -r line; do
73+
local resource_id=$(echo $line | awk '{print $1}')
74+
local resource_name=$(echo $line | awk '{$1=""; print $0}')
75+
if $DRY_RUN; then
76+
echo "Would delete $resource_type $resource_id $resource_name"
77+
else
78+
echo "Deleting $resource_type $resource_id $resource_name..."
79+
openstack $resource_type delete $resource_id || echo "Failed to delete $resource_type $resource_id $resource_name"
80+
fi
81+
done <<< "$id_name_list"
82+
}
83+
84+
function cleanup {
85+
local name_prefix=$1
86+
echo "Getting network and subnet IDs with $name_prefix prefix (may take a while)"
87+
88+
# Get subnet IDs associated with tempest networks
89+
TEMPEST_NETWORK_IDS=$(openstack network list -f value -c ID -c Name | awk -v prefix="$TEMPEST_PREFIX" '$2 ~ "^"prefix {print $1}')
90+
TEMPEST_SUBNET_IDS=""
91+
for network_id in $TEMPEST_NETWORK_IDS; do
92+
TEMPEST_SUBNET_IDS+=" $(openstack subnet list --network $network_id -f value -c ID)"
93+
done
94+
95+
# Delete resources in the specified order
96+
delete_resources server $name_prefix
97+
delete_ports "$TEMPEST_SUBNET_IDS"
98+
delete_resources volume $name_prefix
99+
delete_resources router $name_prefix
100+
delete_resources network $name_prefix
101+
delete_resources image $name_prefix
102+
delete_resources user $name_prefix
103+
delete_resources project $name_prefix
104+
}
105+
106+
cleanup tempest-
107+
cleanup rally_
108+
109+
echo "Operation completed."
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
features:
3+
- |
4+
Added a new convenience script `.automation.conf/run-tempest.sh` to run
5+
Tempest tests.
6+
- |
7+
Added a new convenience script `.automation.conf/tempest-cleanup.sh` which
8+
will attempt to clear away resources left behind by Tempest testing.

0 commit comments

Comments
 (0)