Skip to content

Commit

Permalink
LXD test scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Fred78290 committed Oct 9, 2024
1 parent 2b7dc5b commit 2451852
Show file tree
Hide file tree
Showing 8 changed files with 3,026 additions and 0 deletions.
513 changes: 513 additions & 0 deletions test/configure-ovn-lxd.sh

Large diffs are not rendered by default.

98 changes: 98 additions & 0 deletions test/create-cluster-lxd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/bin/bash
set -e

LXD_REMOTE=lxdcluster:
OVNNETWORK=ovntest
ROOTNAME=lxdcluster
#===========================================================================================================================================
#
#===========================================================================================================================================
function echo_blue_bold() {
# echo message in blue and bold
echo -e "\x1B[90m= $(date '+%Y-%m-%d %T') \x1B[39m\x1B[1m\x1B[34m$@\x1B[0m\x1B[39m"
}

#===========================================================================================================================================
#
#===========================================================================================================================================
function echo_blue_dot_title() {
# echo message in blue and bold
echo -n -e "\x1B[90m= $(date '+%Y-%m-%d %T') \x1B[39m\x1B[1m\x1B[34m$@\x1B[0m\x1B[39m"
}

#===========================================================================================================================================
#
#===========================================================================================================================================
function echo_blue_dot() {
echo -n -e "\x1B[90m\x1B[39m\x1B[1m\x1B[34m.\x1B[0m\x1B[39m"
}

#===========================================================================================================================================
#
#===========================================================================================================================================
function launch_container() {
local REMOTE=$1
local NAME=$2
local TARGET=$3
local CONTAINER_IP=

echo_blue_bold "Create instance ${NAME}"

lxc launch ubuntu:noble ${NAME} --network=ovntest

lxc exec ${REMOTE}:${NAME} -- apt update
lxc exec ${REMOTE}:${NAME} -- bash -c 'DEBIAN_FRONTEND=noninteractive apt upgrade -y'
lxc exec ${REMOTE}:${NAME} -- apt install nginx -y

echo_blue_dot_title "Wait ip instance ${REMOTE}:${NAME}"

while [ -z "${CONTAINER_IP}" ]; do
CONTAINER_IP=$(lxc list ${REMOTE}: name=${NAME} --format=json | jq -r '.[0].state.network|.eth0.addresses[]|select(.family == "inet")|.address')
sleep 1
echo_blue_dot
done
echo
}

#===========================================================================================================================================
#
#===========================================================================================================================================
function container_ip() {
local REMOTE=$1
local NAME=$2

lxc list ${REMOTE}: name=${NAME} --format=json | jq -r '.[0].state.network|.eth0.addresses[]|select(.family == "inet")|.address'
}

#===========================================================================================================================================
# CREATE CONTAINERS
#===========================================================================================================================================
echo_blue_bold "Create all containers"

for INDEX in $(seq 0 2)
do
CONTAINER_NAME=container-0${INDEX}
launch_container ${ROOTNAME} ${CONTAINER_NAME} ${ROOTNAME}-0${INDEX}
INSTANCE_IPS[${INDEX}]=$(container_ip ${ROOTNAME} ${CONTAINER_NAME})
done

echo_blue_bold "Create instance u3"
lxc launch ubuntu:noble ${ROOTNAME}:container-03 --network=lxdbr0

lxc ls ${ROOTNAME}:

#===========================================================================================================================================
# CREATE OVN LOAD BALANCER
#===========================================================================================================================================
NLB_VIP_ADDRESS=$(lxc network load-balancer create ${ROOTNAME}:ovntest --allocate=ipv4 | cut -d ' ' -f 4)

echo_blue_bold "NLB_VIP_ADDRESS=${NLB_VIP_ADDRESS}"

for INDEX in $(seq 0 2)
do
lxc network load-balancer backend add ${ROOTNAME}:ovntest ${NLB_VIP_ADDRESS} backend-0${INDEX} ${INSTANCE_IPS[${INDEX}]} 80,443
done

lxc network load-balancer port add ovntest ${NLB_VIP_ADDRESS} tcp 80,443 backend-00,backend-01,backend-02


90 changes: 90 additions & 0 deletions test/create-lxd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/bin/bash
set -e

LXD_REMOTE=lxdcluster:
OVNNETWORK=ovntest

#===========================================================================================================================================
#
#===========================================================================================================================================
function echo_blue_bold() {
# echo message in blue and bold
echo -e "\x1B[90m= $(date '+%Y-%m-%d %T') \x1B[39m\x1B[1m\x1B[34m$@\x1B[0m\x1B[39m"
}

#===========================================================================================================================================
#
#===========================================================================================================================================
function echo_blue_dot_title() {
# echo message in blue and bold
echo -n -e "\x1B[90m= $(date '+%Y-%m-%d %T') \x1B[39m\x1B[1m\x1B[34m$@\x1B[0m\x1B[39m"
}

#===========================================================================================================================================
#
#===========================================================================================================================================
function echo_blue_dot() {
echo -n -e "\x1B[90m\x1B[39m\x1B[1m\x1B[34m.\x1B[0m\x1B[39m"
}

#===========================================================================================================================================
#
#===========================================================================================================================================
function launch_container() {
local NAME=$1
local TARGET=$2
local CONTAINER_IP=

echo_blue_bold "Create instance ${NAME}"

lxc launch ubuntu:noble ${LXD_REMOTE}${NAME} --network=${OVNNETWORK}

lxc exec ${LXD_REMOTE}${NAME} -- apt update
lxc exec ${LXD_REMOTE}${NAME} -- bash -c 'DEBIAN_FRONTEND=noninteractive apt upgrade -y'
lxc exec ${LXD_REMOTE}${NAME} -- apt install nginx -y

echo_blue_dot_title "Wait ip instance ${LXD_REMOTE}${NAME}"

while [ -z "${CONTAINER_IP}" ]; do
CONTAINER_IP=$(lxc list ${LXD_REMOTE} name=${NAME} --format=json | jq -r '.[0].state.network|.eth0.addresses[]|select(.family == "inet")|.address')
sleep 1
echo_blue_dot
done
echo
}

#===========================================================================================================================================
#
#===========================================================================================================================================
function container_ip() {
local NAME=$1

lxc list ${LXD_REMOTE} name=${NAME} --format=json | jq -r '.[0].state.network|.eth0.addresses[]|select(.family == "inet")|.address'
}

#===========================================================================================================================================
# CREATE CONTAINERS
#===========================================================================================================================================

launch_container u1
launch_container u2

U1_IP=$(container_ip u1)
U2_IP=$(container_ip u2)

#===========================================================================================================================================
# CREATE OVN LOAD BALANCER
#===========================================================================================================================================

NLB_VIP_ADDRESS=$(lxc network load-balancer create ${LXD_REMOTE}${OVNNETWORK} --allocate=ipv4 | cut -d ' ' -f 4)

echo_blue_bold "NLB_VIP_ADDRESS=${NLB_VIP_ADDRESS}"

lxc network load-balancer backend add ${LXD_REMOTE}${OVNNETWORK} ${NLB_VIP_ADDRESS} u1 ${U1_IP} 80,443
lxc network load-balancer backend add ${LXD_REMOTE}${OVNNETWORK} ${NLB_VIP_ADDRESS} u2 ${U2_IP} 80,443
lxc network load-balancer port add ${LXD_REMOTE}${OVNNETWORK} ${NLB_VIP_ADDRESS} tcp 80,443 u1,u2

lxc ls

curl http://${NLB_VIP_ADDRESS}

Loading

0 comments on commit 2451852

Please sign in to comment.