diff options
-rwxr-xr-x | kud/hosting_providers/baremetal/aio.sh | 6 | ||||
-rw-r--r-- | kud/hosting_providers/vagrant/Vagrantfile | 2 | ||||
-rwxr-xr-x | kud/hosting_providers/vagrant/installer.sh | 36 | ||||
-rwxr-xr-x | kud/tests/_functions.sh | 23 |
4 files changed, 38 insertions, 29 deletions
diff --git a/kud/hosting_providers/baremetal/aio.sh b/kud/hosting_providers/baremetal/aio.sh index 416a1fef..c9903cd3 100755 --- a/kud/hosting_providers/baremetal/aio.sh +++ b/kud/hosting_providers/baremetal/aio.sh @@ -15,9 +15,13 @@ set -o pipefail aio_dir=$(cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd) cd ${aio_dir}/../vagrant +# For aio inventory by default get ovn central ip from local host default interface. +# This variable used only in this file, but env variable defined to enable user to override it prior calling aio.sh. +OVN_CENTRAL_IP_ADDRESS=${OVN_CENTRAL_IP_ADDRESS:-$(hostname -I | cut -d ' ' -f 1)} + cat <<EOL > inventory/hosts.ini [all] -localhost +localhost ansible_ssh_host=${OVN_CENTRAL_IP_ADDRESS} ansible_ssh_port=22 [kube-master] localhost diff --git a/kud/hosting_providers/vagrant/Vagrantfile b/kud/hosting_providers/vagrant/Vagrantfile index d068b84a..2d1b5ab4 100644 --- a/kud/hosting_providers/vagrant/Vagrantfile +++ b/kud/hosting_providers/vagrant/Vagrantfile @@ -120,7 +120,7 @@ Vagrant.configure("2") do |config| installer.vm.network :private_network, :ip => "10.10.10.2", :type => :static installer.vm.synced_folder '../../../', '/home/vagrant/multicloud-k8s/', type: sync_type installer.vm.provision 'shell', privileged: false do |sh| - sh.env = {'KUD_PLUGIN_ENABLED': 'false'} + sh.env = {'KUD_PLUGIN_ENABLED': 'false', 'OVN_CENTRAL_INTERFACE': 'eth1'} sh.inline = <<-SHELL cp /vagrant/insecure_keys/key.pub /home/vagrant/.ssh/id_rsa.pub cp /vagrant/insecure_keys/key /home/vagrant/.ssh/id_rsa diff --git a/kud/hosting_providers/vagrant/installer.sh b/kud/hosting_providers/vagrant/installer.sh index 708e51e2..ca14bad7 100755 --- a/kud/hosting_providers/vagrant/installer.sh +++ b/kud/hosting_providers/vagrant/installer.sh @@ -9,8 +9,13 @@ ############################################################################## set -o errexit +set -o nounset set -o pipefail +INSTALLER_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd) + +source ${INSTALLER_DIR}/../../tests/_functions.sh + # _install_go() - Install GoLang package function _install_go { version=$(grep "go_version" ${kud_playbooks}/kud-vars.yml | awk -F "'" '{print $2}') @@ -63,15 +68,15 @@ function _install_docker { sudo apt-get install -y docker-ce sudo mkdir -p /etc/systemd/system/docker.service.d - if [ $http_proxy ]; then + if [ ${http_proxy:-} ]; then echo "[Service]" | sudo tee /etc/systemd/system/docker.service.d/http-proxy.conf echo "Environment=\"HTTP_PROXY=$http_proxy\"" | sudo tee --append /etc/systemd/system/docker.service.d/http-proxy.conf fi - if [ $https_proxy ]; then + if [ ${https_proxy:-} ]; then echo "[Service]" | sudo tee /etc/systemd/system/docker.service.d/https-proxy.conf echo "Environment=\"HTTPS_PROXY=$https_proxy\"" | sudo tee --append /etc/systemd/system/docker.service.d/https-proxy.conf fi - if [ $no_proxy ]; then + if [ ${no_proxy:-} ]; then echo "[Service]" | sudo tee /etc/systemd/system/docker.service.d/no-proxy.conf echo "Environment=\"NO_PROXY=$no_proxy\"" | sudo tee --append /etc/systemd/system/docker.service.d/no-proxy.conf fi @@ -86,13 +91,12 @@ function _install_docker { } function _set_environment_file { - ansible_ifconfig=$(ansible ovn-central[0] -i $kud_inventory -m shell -a "ifconfig eth1 |grep \"inet addr\" |awk '{print \$2}' |awk -F: '{print \$2}'") - if [[ $ansible_ifconfig != *CHANGED* ]]; then - echo "Fail to get the OVN central IP address from eth1 nic" - exit - fi - echo "export OVN_CENTRAL_ADDRESS=$(echo ${ansible_ifconfig#*>>} | tr '\n' ':')6641" | sudo tee --append /etc/environment + # By default ovn central interface is the first active network interface on localhost. If other wanted, need to export this variable in aio.sh or Vagrant file. + OVN_CENTRAL_INTERFACE=${OVN_CENTRAL_INTERFACE:-$(ip addr show | awk '/inet.*brd/{print $NF; exit}')} + echo "export OVN_CENTRAL_INTERFACE=${OVN_CENTRAL_INTERFACE}" | sudo tee --append /etc/environment + echo "export OVN_CENTRAL_ADDRESS=$(get_ovn_central_address)" | sudo tee --append /etc/environment echo "export KUBE_CONFIG_DIR=/opt/kubeconfig" | sudo tee --append /etc/environment + echo "export CSAR_DIR=/opt/csar" | sudo tee --append /etc/environment } # install_k8s() - Install Kubernetes using kubespray tool @@ -117,16 +121,16 @@ function install_k8s { make mitogen popd rm -f $kud_inventory_folder/group_vars/all.yml 2> /dev/null - if [[ -n "${verbose}" ]]; then + if [[ -n "${verbose:-}" ]]; then echo "kube_log_level: 5" | tee $kud_inventory_folder/group_vars/all.yml else echo "kube_log_level: 2" | tee $kud_inventory_folder/group_vars/all.yml fi echo "kubeadm_enabled: true" | tee --append $kud_inventory_folder/group_vars/all.yml - if [[ -n "${http_proxy}" ]]; then + if [[ -n "${http_proxy:-}" ]]; then echo "http_proxy: \"$http_proxy\"" | tee --append $kud_inventory_folder/group_vars/all.yml fi - if [[ -n "${https_proxy}" ]]; then + if [[ -n "${https_proxy:-}" ]]; then echo "https_proxy: \"$https_proxy\"" | tee --append $kud_inventory_folder/group_vars/all.yml fi ansible-playbook $verbose -i $kud_inventory $dest_folder/kubespray-$version/cluster.yml --become --become-user=root | sudo tee $log_folder/setup-kubernetes.log @@ -165,7 +169,6 @@ function install_plugin { sudo mkdir -p /opt/{kubeconfig,consul/config} sudo cp $HOME/.kube/config /opt/kubeconfig/kud - _set_environment_file source /etc/environment pushd $kud_folder/../../../deployments @@ -210,14 +213,15 @@ if ! sudo -n "true"; then exit 1 fi -if [[ -n "${KUD_DEBUG}" ]]; then +verbose="" +if [[ -n "${KUD_DEBUG:-}" ]]; then set -o xtrace verbose="-vvv" fi # Configuration values log_folder=/var/log/kud -kud_folder=$(pwd) +kud_folder=${INSTALLER_DIR} kud_infra_folder=$kud_folder/../../deployment_infra export kud_inventory_folder=$kud_folder/inventory kud_inventory=$kud_inventory_folder/hosts.ini @@ -229,7 +233,6 @@ testing_enabled=${KUD_ENABLE_TESTS:-false} sudo mkdir -p $log_folder sudo mkdir -p /opt/csar sudo chown -R $USER /opt/csar -echo "export CSAR_DIR=/opt/csar" | sudo tee --append /etc/environment # Install dependencies # Setup proxy variables @@ -240,6 +243,7 @@ fi sudo apt-get update install_k8s install_addons +_set_environment_file if ${KUD_PLUGIN_ENABLED:-false}; then install_plugin fi diff --git a/kud/tests/_functions.sh b/kud/tests/_functions.sh index 542443d6..5e6314ce 100755 --- a/kud/tests/_functions.sh +++ b/kud/tests/_functions.sh @@ -12,6 +12,8 @@ set -o errexit set -o nounset set -o pipefail +FUNCTIONS_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd) + source /etc/environment function print_msg { @@ -22,10 +24,10 @@ function print_msg { echo -e "${RED} $msg ---------------------------------------${NC}" } -function _get_ovn_central_address { - 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}'") +function get_ovn_central_address { + ansible_ifconfig=$(ansible ovn-central[0] -i ${FUNCTIONS_DIR}/../hosting_providers/vagrant/inventory/hosts.ini -m shell -a "ifconfig ${OVN_CENTRAL_INTERFACE} |grep \"inet addr\" |awk '{print \$2}' |awk -F: '{print \$2}'") if [[ $ansible_ifconfig != *CHANGED* ]]; then - echo "Fail to get the OVN central IP address from eth1 nic" + echo "Fail to get the OVN central IP address from ${OVN_CENTRAL_INTERFACE} nic" exit fi echo "$(echo ${ansible_ifconfig#*>>} | tr '\n' ':')6641" @@ -39,7 +41,7 @@ function init_network { name=$(cat $fname | yq '.spec.name' | xargs) subnet=$(cat $fname | yq '.spec.subnet' | xargs) gateway=$(cat $fname | yq '.spec.gateway' | xargs) - ovn_central_address=$(_get_ovn_central_address) + ovn_central_address=$(get_ovn_central_address) router_mac=$(printf '00:00:00:%02X:%02X:%02X' $((RANDOM%256)) $((RANDOM%256)) $((RANDOM%256))) 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 @@ -52,7 +54,7 @@ function cleanup_network { local fname=$1 name=$(cat $fname | yq '.spec.name' | xargs) - ovn_central_address=$(_get_ovn_central_address) + ovn_central_address=$(get_ovn_central_address) for cmd in "ls-del $name" "lrp-del rtos-$name" "lsp-del stor-$name"; do ovn-nbctl --if-exist --db tcp:$ovn_central_address $cmd @@ -111,6 +113,10 @@ function wait_deployment { # setup() - Base testing setup shared among functional tests function setup { + if ! $(kubectl version &>/dev/null); then + echo "This funtional test requires kubectl client" + exit 1 + fi for deployment_name in $@; do recreate_deployment $deployment_name done @@ -126,9 +132,4 @@ function teardown { destroy_deployment $deployment_name done } - -if ! $(kubectl version &>/dev/null); then - echo "This funtional test requires kubectl client" - exit 1 -fi -test_folder=$(pwd) +test_folder=${FUNCTIONS_DIR} |