Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions bin/setup-openstack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function waitErator() {
local start_time
start_time=$(date +%s)
local timeout_seconds=$((30 * 60)) # 30 minutes

while [ ${#pids[@]} -gt 0 ]; do
# Check for timeout
local current_time
Expand All @@ -33,15 +33,15 @@ function waitErator() {
echo "==== PROCESS TIMEOUT ====================================="
exit 1
fi

for pid in "${!pids[@]}"; do
# Check if process is still running
if ! kill -0 ${pid} 2>/dev/null; then
# Process finished, check exit status
# Use || to prevent set -e from killing the script before we can log the failure
wait ${pid} || local exit_code=$?
exit_code=${exit_code:-0}

if [ $exit_code -ne 0 ]; then
echo "==== PROCESS FAILED ====================================="
echo "Command: ${pid_commands[$pid]}"
Expand All @@ -57,7 +57,7 @@ function waitErator() {
done
sleep 1
done

echo "All processes completed successfully."
}

Expand Down
73 changes: 69 additions & 4 deletions scripts/hyperconverged-lab.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,26 @@ EXCLUDE_LIST=()

export TEST_LEVEL="${TEST_LEVEL:-off}"

# yq installation constants
YQ_VERSION="v4.2.0"
YQ_BINARY="yq_linux_amd64"

function installYq() {
export VERSION=v4.2.0
export BINARY=yq_linux_amd64
wget https://github.com/mikefarah/yq/releases/download/${VERSION}/${BINARY}.tar.gz -q -O - | tar xz && sudo mv ${BINARY} /usr/local/bin/yq
if wget https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/${YQ_BINARY}.tar.gz -O - | tar xz && sudo mv ${YQ_BINARY} /usr/local/bin/yq; then
echo "Successfully installed yq version ${YQ_VERSION}"
return 0
else
echo "Failed to install yq"
return 1
fi
}

# Install yq locally if needed...
if ! yq --version 2> /dev/null; then
echo "yq is not installed. Attempting to install yq"
installYq
if ! installYq; then
echo "[WARNING] Failed to install yq locally"
fi
fi


Expand Down Expand Up @@ -430,6 +440,19 @@ if [ ! -d "/etc/genestack" ]; then
sudo chown \${USER}:\${USER} -R /etc/genestack
fi

# Install yq on the remote host if not already present
if ! command -v yq &> /dev/null; then
echo "Installing yq on remote host..."
if wget https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/${YQ_BINARY}.tar.gz -O - | tar xz && sudo mv ${YQ_BINARY} /usr/local/bin/yq; then
echo "Successfully installed yq version ${YQ_VERSION} on remote host"
else
echo "Failed to install yq on remote host"
exit 1
fi
else
echo "yq already available on remote host: \$(yq --version)"
fi

# We need to clobber the sample or else we get a bogus LB vip
cat > /etc/genestack/manifests/metallb/metallb-openstack-service-lb.yml <<EOF
---
Expand Down Expand Up @@ -1234,6 +1257,48 @@ echo "Installing OpenStack"
sudo /opt/genestack/bin/setup-openstack.sh
EOC

# Run Genestack post setup
ssh -o ForwardAgent=yes -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -t ${SSH_USERNAME}@${JUMP_HOST_VIP} <<EOC
set -e
sudo bash <<HERE
sudo /opt/genestack/bin/setup-openstack-rc.sh
source /opt/genestack/scripts/genestack.rc

# Function to retry openstack commands with backoff
retry_openstack_command() {
local cmd="\\\$1"
local description="\\\$2"
local retry_count=0
local max_retries=12 # 12 retries * 10 seconds = 2 minutes

while [ \\\$retry_count -lt \\\$max_retries ]; do
echo "Attempting: \\\$description"
if eval "\\\$cmd"; then
echo "\\\$description succeeded"
return 0
else
retry_count=\\\$((retry_count + 1))
echo "\\\$description failed (attempt \\\$retry_count/\\\$max_retries). Retrying in 10 seconds..."
if [ \\\$retry_count -eq \\\$max_retries ]; then
echo "\\\$description failed after \\\$max_retries attempts. Continuing anyway..."
return 1
fi
sleep 10
fi
done
}

# Create flavor with retry
retry_openstack_command "if ! openstack --os-cloud default flavor show ${LAB_NAME_PREFIX}-test; then openstack --os-cloud default flavor create ${LAB_NAME_PREFIX}-test --public --ram 2048 --disk 10 --vcpus 2; fi" "Flavor setup"

# Create network with retry
retry_openstack_command "if ! openstack --os-cloud default network show flat; then openstack --os-cloud default network create --share --availability-zone-hint az1 --external --provider-network-type flat --provider-physical-network physnet1 flat; fi" "Network setup"

# Create subnet with retry
retry_openstack_command "if ! openstack --os-cloud default subnet show flat_subnet; then openstack --os-cloud default subnet create --subnet-range 192.168.102.0/24 --gateway 192.168.102.1 --dns-nameserver 1.1.1.1 --allocation-pool start=192.168.102.100,end=192.168.102.109 --dhcp --network flat flat_subnet; fi" "Subnet setup"
HERE
EOC

# Extra operations...
install_k9s() {
echo "Installing k9s"
Expand Down
Loading