summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xkud/hosting_providers/containerized/installer.sh2
-rw-r--r--kud/tests/_common.sh68
-rwxr-xr-xkud/tests/_functions.sh60
-rwxr-xr-xkud/tests/kubevirt.sh66
4 files changed, 175 insertions, 21 deletions
diff --git a/kud/hosting_providers/containerized/installer.sh b/kud/hosting_providers/containerized/installer.sh
index 844c154d..5ac78673 100755
--- a/kud/hosting_providers/containerized/installer.sh
+++ b/kud/hosting_providers/containerized/installer.sh
@@ -230,7 +230,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
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