2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
17 local RED='\033[0;31m'
20 echo -e "${RED} $msg ---------------------------------------${NC}"
23 function _get_ovn_central_address {
24 ansible_ifconfig=$(ansible ovn-central[0] -i $test_folder/../hosting_providers/vagrant/inventory/hosts.ini -m shell -a "ifconfig eth1 |grep \"inet addr\" |awk '{print \$2}' |awk -F: '{print \$2}'")
25 if [[ $ansible_ifconfig != *CHANGED* ]]; then
26 echo "Fail to get the OVN central IP address from eth1 nic"
29 echo "$(echo ${ansible_ifconfig#*>>} | tr '\n' ':')6641"
32 # install_ovn_deps() - Install dependencies required for tests that require OVN
33 function install_ovn_deps {
34 if ! $(yq --version &>/dev/null); then
35 sudo -E pip install yq
37 if ! $(ovn-nbctl --version &>/dev/null); then
38 source /etc/os-release || source /usr/lib/os-release
43 sudo apt-get install -y apt-transport-https
44 echo "deb https://packages.wand.net.nz $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/wand.list
45 sudo curl https://packages.wand.net.nz/keyring.gpg -o /etc/apt/trusted.gpg.d/wand.gpg
47 sudo apt install -y ovn-common
55 # init_network() - This function creates the OVN resouces required by the test
56 function init_network {
58 local router_name="ovn4nfv-master"
60 name=$(cat $fname | yq '.spec.name' | xargs)
61 subnet=$(cat $fname | yq '.spec.subnet' | xargs)
62 gateway=$(cat $fname | yq '.spec.gateway' | xargs)
63 ovn_central_address=$(_get_ovn_central_address)
65 router_mac=$(printf '00:00:00:%02X:%02X:%02X' $((RANDOM%256)) $((RANDOM%256)) $((RANDOM%256)))
66 ovn-nbctl --may-exist --db tcp:$ovn_central_address ls-add $name -- set logical_switch $name other-config:subnet=$subnet external-ids:gateway_ip=$gateway
67 ovn-nbctl --may-exist --db tcp:$ovn_central_address lrp-add $router_name rtos-$name $router_mac $gateway
68 ovn-nbctl --may-exist --db tcp:$ovn_central_address lsp-add $name stor-$name -- set logical_switch_port stor-$name type=router options:router-port=rtos-$name addresses=\"$router_mac\"
71 # cleanup_network() - This function removes the OVN resources created for the test
72 function cleanup_network {
75 name=$(cat $fname | yq '.spec.name' | xargs)
76 ovn_central_address=$(_get_ovn_central_address)
78 for cmd in "ls-del $name" "lrp-del rtos-$name" "lsp-del stor-$name"; do
79 ovn-nbctl --if-exist --db tcp:$ovn_central_address $cmd
83 function _checks_args {
85 echo "Missing CSAR ID argument"
88 if [[ -z $CSAR_DIR ]]; then
89 echo "CSAR_DIR global environment value is empty"
92 mkdir -p ${CSAR_DIR}/${1}
95 # destroy_deployment() - This function ensures that a specific deployment is
96 # destroyed in Kubernetes
97 function destroy_deployment {
98 local deployment_name=$1
100 echo "$(date +%H:%M:%S) - $deployment_name : Destroying deployment"
101 kubectl delete deployment $deployment_name --ignore-not-found=true --now
102 while kubectl get deployment $deployment_name &>/dev/null; do
103 echo "$(date +%H:%M:%S) - $deployment_name : Destroying deployment"
107 # recreate_deployment() - This function destroys an existing deployment and
108 # creates an new one based on its yaml file
109 function recreate_deployment {
110 local deployment_name=$1
112 destroy_deployment $deployment_name
113 kubectl create -f $deployment_name.yaml
116 # wait_deployment() - Wait process to Running status on the Deployment's pods
117 function wait_deployment {
118 local deployment_name=$1
121 while [[ $status_phase != "Running" ]]; do
122 new_phase=$(kubectl get pods | grep $deployment_name | awk '{print $3}')
123 if [[ $new_phase != $status_phase ]]; then
124 echo "$(date +%H:%M:%S) - $deployment_name : $new_phase"
125 status_phase=$new_phase
127 if [[ $new_phase == "Err"* ]]; then
133 # setup() - Base testing setup shared among functional tests
135 for deployment_name in $@; do
136 recreate_deployment $deployment_name
139 for deployment_name in $@; do
140 wait_deployment $deployment_name
144 # teardown() - Base testing teardown function
146 for deployment_name in $@; do
147 destroy_deployment $deployment_name
151 if ! $(kubectl version &>/dev/null); then
152 echo "This funtional test requires kubectl client"