aboutsummaryrefslogtreecommitdiffstats
path: root/kud
diff options
context:
space:
mode:
Diffstat (limited to 'kud')
-rwxr-xr-xkud/hosting_providers/containerized/installer.sh31
-rwxr-xr-xkud/hosting_providers/vagrant/installer.sh21
-rw-r--r--kud/tests/_common.sh68
-rwxr-xr-xkud/tests/_functions.sh60
-rwxr-xr-xkud/tests/kubevirt.sh66
5 files changed, 197 insertions, 49 deletions
diff --git a/kud/hosting_providers/containerized/installer.sh b/kud/hosting_providers/containerized/installer.sh
index 8119a559..4ed1833b 100755
--- a/kud/hosting_providers/containerized/installer.sh
+++ b/kud/hosting_providers/containerized/installer.sh
@@ -16,16 +16,23 @@ set -ex
INSTALLER_DIR="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")"
function install_prerequisites {
-#install package for docker images
- echo "Removing ppa for jonathonf/python-3.6"
- ls /etc/apt/sources.list.d/ || true
- find /etc/apt/sources.list.d -maxdepth 1 -name '*jonathonf*' -delete || true
apt-get update
- apt-get install -y curl vim wget git \
- software-properties-common python-pip sudo gettext-base
+ apt-get install -y software-properties-common
add-apt-repository -y ppa:longsleep/golang-backports
apt-get update
- apt-get install -y golang-go rsync
+ apt-get install -y \
+ curl \
+ gettext-base \
+ git \
+ golang-go \
+ make \
+ python3-pip \
+ rsync \
+ sshpass \
+ sudo \
+ unzip \
+ vim \
+ wget
}
# _install_ansible() - Install and Configure Ansible program
@@ -33,7 +40,7 @@ function _install_ansible {
local version=$(grep "ansible_version" ${kud_playbooks}/kud-vars.yml |
awk -F ': ' '{print $2}')
mkdir -p /etc/ansible/
- pip install --no-cache-dir ansible==$version
+ pip3 install --no-cache-dir ansible==$version
}
function install_kubespray {
@@ -44,8 +51,6 @@ function install_kubespray {
$kud_inventory_folder/group_vars/k8s-cluster.yml | \
awk -F "\"" '{print $2}')
local tarball=v$version.tar.gz
- # install make to run mitogen target & unzip is mitogen playbook dependency
- apt-get install -y sshpass make unzip
_install_ansible
wget https://github.com/kubernetes-incubator/kubespray/archive/$tarball
tar -C $dest_folder -xzf $tarball
@@ -54,7 +59,7 @@ function install_kubespray {
rm $tarball
pushd $dest_folder/kubespray-$version/
- pip install --no-cache-dir -r ./requirements.txt
+ pip3 install --no-cache-dir -r ./requirements.txt
make mitogen
popd
rm -f $kud_inventory_folder/group_vars/all.yml 2> /dev/null
@@ -230,7 +235,7 @@ function install_host_artifacts {
done
mkdir -p ${host_addons_dir}/tests
- for test in _common _common_test _functions topology-manager-sriov multus ovn4nfv nfd sriov-network qat cmk; do
+ for test in _common _common_test _functions topology-manager-sriov kubevirt multus ovn4nfv nfd sriov-network qat cmk; do
cp ${kud_tests}/${test}.sh ${host_addons_dir}/tests
done
@@ -297,8 +302,6 @@ mkdir -p /opt/csar
export CSAR_DIR=/opt/csar
function install_pkg {
-# Install dependencies
- apt-get update
install_prerequisites
install_kubespray
}
diff --git a/kud/hosting_providers/vagrant/installer.sh b/kud/hosting_providers/vagrant/installer.sh
index 8c8ff7f3..5535c31b 100755
--- a/kud/hosting_providers/vagrant/installer.sh
+++ b/kud/hosting_providers/vagrant/installer.sh
@@ -40,25 +40,16 @@ function _install_go {
sudo sed -i 's|secure_path="\([^"]\+\)"|secure_path="\1:/usr/local/go/bin"|' /etc/sudoers
}
-# _install_pip() - Install Python Package Manager
-function _install_pip {
- if $(pip --version &>/dev/null); then
- sudo -E pip install --no-cache-dir --upgrade pip
- else
- sudo apt-get install -y python-dev
- curl -sL https://bootstrap.pypa.io/pip/2.7/get-pip.py | sudo python
- fi
-}
-
# _install_ansible() - Install and Configure Ansible program
function _install_ansible {
+ sudo apt-get install -y python3-pip
+ sudo -E pip3 install --no-cache-dir --upgrade pip
if $(ansible --version &>/dev/null); then
- sudo pip uninstall -y ansible
+ sudo pip3 uninstall -y ansible
fi
- _install_pip
local version=$(grep "ansible_version" ${kud_playbooks}/kud-vars.yml | awk -F ': ' '{print $2}')
sudo mkdir -p /etc/ansible/
- sudo -E pip install --no-cache-dir ansible==$version
+ sudo -E pip3 install --no-cache-dir ansible==$version
}
function _set_environment_file {
@@ -88,7 +79,7 @@ function install_k8s {
rm $tarball
pushd $dest_folder/kubespray-$version/
- sudo -E pip install --no-cache-dir -r ./requirements.txt
+ sudo -E pip3 install --no-cache-dir -r ./requirements.txt
make mitogen
popd
rm -f $kud_inventory_folder/group_vars/all.yml 2> /dev/null
@@ -213,7 +204,7 @@ function install_addons {
# install_plugin() - Install ONAP Multicloud Kubernetes plugin
function install_plugin {
echo "Installing multicloud/k8s plugin"
- sudo -E pip install --no-cache-dir docker-compose
+ sudo -E pip3 install --no-cache-dir docker-compose
sudo mkdir -p /opt/{kubeconfig,consul/config}
sudo cp $HOME/.kube/config /opt/kubeconfig/kud
diff --git a/kud/tests/_common.sh b/kud/tests/_common.sh
index ff975544..efeded6f 100644
--- a/kud/tests/_common.sh
+++ b/kud/tests/_common.sh
@@ -16,9 +16,11 @@ packetgen_deployment_name=packetgen
sink_deployment_name=sink
firewall_deployment_name=firewall
image_name=virtlet.cloud/ubuntu/16.04
+kubevirt_image=integratedcloudnative/fedora:33
multus_deployment_name=multus-deployment
virtlet_image=virtlet.cloud/fedora
virtlet_deployment_name=virtlet-deployment
+kubevirt_vmi_name=kubevirt-vmi
plugin_deployment_name=plugin-deployment
plugin_service_name=plugin-service
ovn4nfv_deployment_name=ovn4nfv-deployment
@@ -980,6 +982,72 @@ DEPLOYMENT
popd
}
+# populate_CSAR_kubevirt() - This function creates the content of CSAR file
+# required for testing Kubevirt feature
+function populate_CSAR_kubevirt {
+ local csar_id=$1
+
+ _checks_args $csar_id
+ pushd ${CSAR_DIR}/${csar_id}
+
+ cat << META > metadata.yaml
+resources:
+ virtualmachineinstance:
+ - $kubevirt_vmi_name.yaml
+META
+
+ cat << DEPLOYMENT > $kubevirt_vmi_name.yaml
+apiVersion: kubevirt.io/v1
+kind: VirtualMachineInstance
+metadata:
+ name: $kubevirt_vmi_name
+spec:
+ domain:
+ cpu:
+ model: host-passthrough
+ devices:
+ disks:
+ - disk:
+ bus: virtio
+ name: rootfs
+ - disk:
+ bus: virtio
+ name: cloudinit
+ interfaces:
+ - name: default
+ masquerade: {}
+ resources:
+ requests:
+ memory: 256M
+ networks:
+ - name: default
+ pod: {}
+ volumes:
+ - name: rootfs
+ containerDisk:
+ image: $kubevirt_image
+ imagePullPolicy: IfNotPresent
+ - name: cloudinit
+ cloudInitNoCloud:
+ userData: |
+ #cloud-config
+ ssh_pwauth: True
+ users:
+ - name: testuser
+ gecos: User
+ primary-group: testuser
+ groups: users
+ lock_passwd: false
+ shell: /bin/bash
+ # the password is "testuser"
+ passwd: "\$6\$rounds=4096\$wPs4Hz4tfs\$a8ssMnlvH.3GX88yxXKF2cKMlVULsnydoOKgkuStTErTq2dzKZiIx9R/pPWWh5JLxzoZEx7lsSX5T2jW5WISi1"
+ sudo: ALL=(ALL) NOPASSWD:ALL
+ runcmd:
+ - echo hello world
+DEPLOYMENT
+ popd
+}
+
# populate_CSAR_plugin()- Creates content used for Plugin functional tests
function populate_CSAR_plugin {
local csar_id=$1
diff --git a/kud/tests/_functions.sh b/kud/tests/_functions.sh
index 10f8e090..1a803173 100755
--- a/kud/tests/_functions.sh
+++ b/kud/tests/_functions.sh
@@ -172,25 +172,31 @@ function _checks_args {
mkdir -p ${CSAR_DIR}/${1}
}
+function _destroy {
+ local type=$1
+ local name=$2
+
+ echo "$(date +%H:%M:%S) - $name : Destroying $type"
+ kubectl delete $type $name --ignore-not-found=true --now
+ while kubectl get $type $name &>/dev/null; do
+ echo "$(date +%H:%M:%S) - $name : Destroying $type"
+ done
+}
+
# destroy_deployment() - This function ensures that a specific deployment is
# destroyed in Kubernetes
function destroy_deployment {
local deployment_name=$1
- echo "$(date +%H:%M:%S) - $deployment_name : Destroying deployment"
- kubectl delete deployment $deployment_name --ignore-not-found=true --now
- while kubectl get deployment $deployment_name &>/dev/null; do
- echo "$(date +%H:%M:%S) - $deployment_name : Destroying deployment"
- done
+ _destroy "deployment" $deployment_name
}
-# recreate_deployment() - This function destroys an existing deployment and
-# creates an new one based on its yaml file
-function recreate_deployment {
- local deployment_name=$1
+function _recreate {
+ local type=$1
+ local name=$2
- destroy_deployment $deployment_name
- kubectl create -f $deployment_name.yaml
+ _destroy $type $name
+ kubectl create -f $name.yaml
}
# wait_deployment() - Wait process to Running status on the Deployment's pods
@@ -271,26 +277,40 @@ function wait_for_deployment_status {
exit 1
}
-# setup() - Base testing setup shared among functional tests
-function setup {
+function setup_type {
+ local type=$1
+ shift;
+
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
+ for name in $@; do
+ _recreate $type $name
done
sleep 5
- for deployment_name in $@; do
- wait_deployment $deployment_name
+ for name in $@; do
+ wait_deployment $name
done
}
+function teardown_type {
+ local type=$1
+ shift;
+
+ for name in $@; do
+ _destroy $type $name
+ done
+}
+
+# setup() - Base testing setup shared among functional tests
+function setup {
+ setup_type "deployment" $@
+}
+
# teardown() - Base testing teardown function
function teardown {
- for deployment_name in $@; do
- destroy_deployment $deployment_name
- done
+ teardown_type "deployment" $@
}
# check_ip_range() - Verifying IP address in address range
diff --git a/kud/tests/kubevirt.sh b/kud/tests/kubevirt.sh
new file mode 100755
index 00000000..fbcf1bf6
--- /dev/null
+++ b/kud/tests/kubevirt.sh
@@ -0,0 +1,66 @@
+#!/bin/bash
+# SPDX-license-identifier: Apache-2.0
+##############################################################################
+# Copyright (c) 2021
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+set -o errexit
+set -o nounset
+set -o pipefail
+
+source _common.sh
+source _functions.sh
+
+csar_id=07f9cfe1-25f6-41fe-b4da-e61a2c94c319
+
+# Setup
+populate_CSAR_kubevirt $csar_id
+
+pushd ${CSAR_DIR}/${csar_id}
+
+# Under automation, the VMI CRD may not be defined yet and setup_type
+# will fail. Retry to workaround this.
+tries=3
+interval=10
+for ((try=1;try<=$tries;try++)); do
+ echo "try $try/$tries: setup test VMI"
+ sleep $interval
+ if setup_type "vmi" $kubevirt_vmi_name; then
+ break
+ fi
+done
+if (($try > $tries)); then
+ echo "setup failed"
+ exit 1
+fi
+
+# Test
+master_ip=$(kubectl cluster-info | grep "Kubernetes master" | awk -F '[:/]' '{print $4}')
+deployment_pod=$(kubectl get pods | grep $kubevirt_vmi_name | awk '{print $1}')
+echo "Pod name: $deployment_pod"
+echo "ssh testuser@$(kubectl get pods $deployment_pod -o jsonpath="{.status.podIP}")"
+echo "kubectl virt console $kubevirt_vmi_name"
+
+tries=30
+interval=60
+for ((try=1;try<=$tries;try++)); do
+ echo "try $try/$tries: Wait for $interval seconds to check for ssh access"
+ sleep $interval
+ if sshpass -p testuser ssh -o ProxyCommand="ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -W %h:%p $master_ip" -o StrictHostKeyChecking=no testuser@$(kubectl get pods $deployment_pod -o jsonpath="{.status.podIP}") -- uptime; then
+ echo "ssh access check is success"
+ break
+ fi
+done
+if (($try > $tries)); then
+ echo "ssh access check failed"
+ exit 1
+fi
+
+popd
+
+# Teardown
+teardown_type "vmi" $kubevirt_vmi_name