Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use windows images from artifactory in e2e tests #627

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 60 additions & 76 deletions automation/test-windows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,71 +6,6 @@ namespace="kubevirt"
template_name="windows2k22"
username="Administrator"

dv_name="${TARGET}-datavolume-original"

oc apply -n ${namespace} -f - <<EOF
apiVersion: cdi.kubevirt.io/v1beta1
kind: DataVolume
metadata:
annotations:
cdi.kubevirt.io/storage.bind.immediate.requested: "true"
name: ${dv_name}
spec:
source:
registry:
secretRef: common-templates-container-disk-puller
url: "docker://quay.io/openshift-cnv/ci-common-templates-images:${TARGET}"
storage:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 60Gi
EOF

oc apply -f - <<EOF
---
apiVersion: v1
kind: Pod
metadata:
name: winrmcli
namespace: kubevirt
spec:
securityContext:
runAsNonRoot: true
runAsUser: 1000
containers:
- image: quay.io/kubevirt/winrmcli
command: ["/bin/sh","-c"]
args: [ "sleep 3000"]
imagePullPolicy: Always
name: winrmcli
restartPolicy: Always
---
EOF

timeout=2000
hour_timeout=3600
sample=10
current_time=0

oc wait --for=condition=Ready --timeout=${hour_timeout}s dv/${dv_name} -n $namespace

oc apply -n ${namespace} -f - <<EOF
apiVersion: cdi.kubevirt.io/v1beta1
kind: DataSource
metadata:
name: ${dv_name}
spec:
source:
pvc:
name: ${dv_name}
namespace: ${namespace}
EOF

# Make sure winrmcli pod is ready
oc wait --for=condition=Ready --timeout=${timeout}s pod/winrmcli -n $namespace

sizes=("medium" "large")
workloads=("server" "highperformance")

Expand All @@ -79,16 +14,66 @@ if [[ $TARGET =~ windows10.* ]]; then
workloads=("desktop")
elif [[ $TARGET =~ windows11.* ]]; then
template_name="windows11"
username="Administrator11"
workloads=("desktop")
elif [[ $TARGET =~ windows2016.* ]]; then
template_name="windows2k16"
elif [[ $TARGET =~ windows2019.* ]]; then
template_name="windows2k19"
elif [[ $TARGET =~ windows2022.* ]]; then
template_name="windows2k22"
elif [[ $TARGET =~ windows2025.* ]]; then
template_name="windows2k25"
fi

source_name="${TARGET}-original"
version=$(oc version -o json | jq -r '.openshiftVersion | split("\\."; null)[:2]|join(".")')

oc apply -n ${namespace} -f - <<EOF
apiVersion: image.openshift.io/v1
kind: ImageStream
metadata:
name: ${source_name}
spec:
lookupPolicy:
local: false
tags:
- from:
kind: DockerImage
name: ibmc.artifactory.cnv-qe.rhood.us/docker/kubevirt-common-instancetypes/${template_name}-container-disk:${version}
name: "${version}"
referencePolicy:
type: Source
---
apiVersion: cdi.kubevirt.io/v1beta1
kind: DataImportCron
metadata:
annotations:
"cdi.kubevirt.io/storage.bind.immediate.requested": "true"
name: ${source_name}
spec:
template:
spec:
source:
registry:
imageStream: ${source_name}
pullMethod: node
storage:
resources:
requests:
storage: 25Gi
schedule: "46 10/12 * * *"
garbageCollect: Outdated
importsToKeep: 2
managedDataSource: ${source_name}
EOF

timeout=2000
hour_timeout=3600
sample=10
current_time=0

oc wait --for=condition=UpToDate --timeout="${hour_timeout}s" "dataImportCron/${source_name}" -n "${namespace}"

delete_vm(){
vm_name=$1
set +e
Expand All @@ -111,23 +96,22 @@ run_vm(){
for i in `seq 1 3`; do
error=false

oc process -n $namespace -o json $template_name NAME=$vm_name DATA_SOURCE_NAME=${dv_name} DATA_SOURCE_NAMESPACE=${namespace} | \
oc process -n $namespace -o json $template_name NAME=$vm_name DATA_SOURCE_NAME=${source_name} DATA_SOURCE_NAMESPACE=${namespace} | \
jq '.items[0].metadata.labels["vm.kubevirt.io/template.namespace"]="kubevirt"' | \
oc apply -n $namespace -f -

# start vm
./virtctl start $vm_name -n $namespace

oc wait --for=condition=Ready --timeout=${hour_timeout}s vm/$vm_name -n $namespace

# get ip address of vm
ipAddressVMI=$(oc get vmi $vm_name -o json -n $namespace| jq -r '.status.interfaces[0].ipAddress')
./virtctl start "${vm_name}" -n "${namespace}"

oc wait --for=condition=Ready --timeout="${hour_timeout}s" "vm/${vm_name}" -n "${namespace}"

current_time=0
# run ipconfig /all command on windows vm
while [[ $(oc exec -n $namespace -i winrmcli -- ./usr/bin/winrm-cli -hostname $ipAddressVMI -port 5985 -username $username -password "Heslo123" "ipconfig /all" | grep "IPv4 Address" | wc -l ) -eq 0 ]] ; do
# run command via ssh
while [[ $(sshpass -pAdministrator ssh -o ProxyCommand="./virtctl port-forward \
--stdio=true -n ${namespace} vm/${vm_name} 33333:22" \
-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no \
"${username}@127.0.0.1" -p 33333 "echo Hello" | grep -c "Hello" ) != 1 ]] ; do
# VM can be stopped during test and recreated. That will change IP, so to be sure, get IP at every iteration
ipAddressVMI=$(oc get vmi $vm_name -o json -n $namespace| jq -r '.status.interfaces[0].ipAddress')
current_time=$((current_time + sample))
if [[ $current_time -gt $timeout ]]; then
error=true
Expand Down
85 changes: 51 additions & 34 deletions automation/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,57 @@ if [ -z "$TARGET" ]; then
exit 1
fi

ocenv="OC"

if [ -z "$CLUSTERENV" ]
then
export CLUSTERENV=$ocenv
fi

keyPath="/tmp/secrets/accessKeyId"
tokenPath="/tmp/secrets/secretKey"
caBundle="/tmp/secrets/ca-bundle"
namespace="kubevirt"
oc create namespace "${namespace}"

if [ "${CLUSTERENV}" == "$ocenv" ]
then
if test -f "$keyPath" && test -f "$tokenPath"; then
id=$(cat ${keyPath} | tr -d '\n')
token=$(cat ${tokenPath} | tr -d '\n')

oc apply -n $namespace -f - <<EOF
apiVersion: v1
kind: Secret
metadata:
name: common-templates-container-disk-puller
labels:
app: containerized-data-importer
type: Opaque
data:
accessKeyId: "$(echo -n ${id} | base64 -w 0)"
secretKey: "$(echo -n ${token} | base64 -w 0)"
EOF
if test -f "${caBundle}"; then
oc create configmap custom-ca \
--from-file=ca-bundle.crt="${caBundle}" \
-n openshift-config

oc patch proxy/cluster \
--type=merge \
--patch='{"spec":{"trustedCA":{"name":"custom-ca"}}}'

oc get secret/pull-secret -n openshift-config --template='{{index .data ".dockerconfigjson" | base64decode}}' > config.json

oc registry login --registry="ibmc.artifactory.cnv-qe.rhood.us" \
--auth-basic="${id}:${token}" \
--to=config.json

oc set data secret/pull-secret -n openshift-config --from-file=.dockerconfigjson=config.json
fi
fi
fi

# Latest released Kubevirt version
export KUBEVIRT_VERSION=$(latest_version "kubevirt")

Expand Down Expand Up @@ -108,8 +159,6 @@ EOF
oc wait --for=condition=Updated --timeout=900s machineconfigpool worker
fi

namespace="kubevirt"

_curl() {
# this dupes the baseline "curl" command line, but is simpler
# wrt shell quoting/expansion.
Expand All @@ -120,13 +169,6 @@ _curl() {
fi
}

ocenv="OC"

if [ -z "$CLUSTERENV" ]
then
export CLUSTERENV=$ocenv
fi

git submodule update --init

make generate
Expand All @@ -144,38 +186,13 @@ chmod +x virtctl
oc apply -f https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_VERSION}/kubevirt-operator.yaml
oc apply -f https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_VERSION}/kubevirt-cr.yaml

sample=10
current_time=0
timeout=600

# Waiting for kubevirt cr to report available
oc wait --for=condition=Available --timeout=${timeout}s kubevirt/kubevirt -n $namespace

oc patch kubevirt kubevirt -n $namespace --type merge -p '{"spec":{"configuration":{"developerConfiguration":{"featureGates": ["DataVolumes", "CPUManager", "NUMA", "DownwardMetrics", "VMPersistentState"]}}}}'

key="/tmp/secrets/accessKeyId"
token="/tmp/secrets/secretKey"

if [ "${CLUSTERENV}" == "$ocenv" ]
then
if test -f "$key" && test -f "$token"; then
id=$(cat $key | tr -d '\n' | base64)
token=$(cat $token | tr -d '\n' | base64 | tr -d ' \n')

oc apply -n $namespace -f - <<EOF
apiVersion: v1
kind: Secret
metadata:
name: common-templates-container-disk-puller
labels:
app: containerized-data-importer
type: Opaque
data:
accessKeyId: "${id}"
secretKey: "${token}"
EOF
fi
fi
echo "Deploying CDI"
oc apply -f https://github.com/kubevirt/containerized-data-importer/releases/download/$CDI_VERSION/cdi-operator.yaml
oc apply -f https://github.com/kubevirt/containerized-data-importer/releases/download/$CDI_VERSION/cdi-cr.yaml
Expand Down
Loading