Skip to content
This repository has been archived by the owner on Apr 15, 2024. It is now read-only.

Commit

Permalink
Add E2E test github action (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiahao Huang authored Nov 7, 2023
1 parent 80ad4e3 commit c98350d
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 14 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/e2e-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Run CCNP E2E test
on:
schedule:
- cron: '25 7 * * *'
workflow_dispatch:
jobs:
E2E_test:
runs-on: tdvm-ut
steps:
- name: Checkout code
uses: actions/checkout@v4.1.1
- name: Set up test environment
run: |
./test/e2e-test/ci-setup.sh
- name: Run Test
run: |
./test/e2e-test/ci-e2e-test.sh
- name: Clean up the environment
if: always()
run: |
./test/e2e-test/ci-clean.sh
20 changes: 20 additions & 0 deletions test/e2e-test/ci-clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
set -o errexit

CLUSTER_NAME=my-cluster
REG_NAME=kind-registry
DEVICE_PLUGIN=localhost:5001/ccnp-device-plugin:0.1
QUOTE=localhost:5001/ccnp-quote-server:0.1
MEASUREMENT=localhost:5001/ccnp_measurement_server:0.1
EVENTLOG=localhost:5001/ccnp_eventlog_server:0.1

kind delete cluster --name $CLUSTER_NAME
rm /run/ccnp/uds/*
docker stop $REG_NAME
docker rm $REG_NAME
sleep 1m
docker rmi ${DEVICE_PLUGIN} ${QUOTE} ${MEASUREMENT} ${EVENTLOG}
for i in $(docker images | grep "none" | awk '{print $3}');do
docker rmi "$i"
done
pip uninstall -y ccnp
13 changes: 13 additions & 0 deletions test/e2e-test/ci-e2e-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
set -o errexit
: '
This is an E2E test script.
If you want to run the script , please run the ci-setup.sh script in advance to set up the ci test environment.
'

WORK_DIR=$(cd "$(dirname "$0")"; pwd)

#Run E2E test cases
pip install pytest pytdxattest
pytest "${WORK_DIR}/test_eventlog.py" "${WORK_DIR}/test_tdquote.py" "${WORK_DIR}/test_tdreport.py"

23 changes: 9 additions & 14 deletions test/e2e-test/ci-test.sh → test/e2e-test/ci-setup.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#!/bin/bash
set -o errexit
: '
This is an E2E test script, if you want to run the script please:
This is a script for setting up the CCNP ci environment. If you want to run the script please:
1 According to the CCNP documentation, create a TDVM
2 Install helm and kind on the TDVM
3 Set up the environment according to the CCNP documentation,including configuring the file "/etc/udev/rules.d/90-tdx.rules" and creating the folder "/run/ccnp/uds" on the TDVM
3 Follow the CCNP documentation to pre-configure the TDVM,including modifying the file "/etc/udev/rules.d/90-tdx.rules" and creating the folder "/run/ccnp/uds"
4 Git clone CCNP and run this script
5 Clean up the environment
'

CLUSTER_NAME=my-cluster
Expand Down Expand Up @@ -34,7 +33,6 @@ create_dir(){
fi
}


create_file(){
if [ ! -e "$1" ];then
touch "$1"
Expand All @@ -44,7 +42,7 @@ create_file(){



#Set up the environment
#Set up the NO_PROXY
export NO_PROXY=$NO_PROXY,$REG_NAME

#Create a private repository
Expand All @@ -55,7 +53,7 @@ if [ "$(docker inspect -f '{{.State.Running}}' "${REG_NAME}" 2>/dev/null || true
fi

#Initialize a kind-K8S cluster and add the private repo to the configuration file
kind create cluster --name $CLUSTER_NAME --config $KIND_CONFIG
kind create cluster --name $CLUSTER_NAME --config "${WORK_DIR}/${KIND_CONFIG}"

REGISTRY_DIR="/etc/containerd/certs.d/localhost:${REG_PORT}"
for node in $(kind get nodes --name $CLUSTER_NAME); do
Expand All @@ -67,12 +65,11 @@ done
if [ "$(docker inspect -f='{{json .NetworkSettings.Networks.kind}}' "${REG_NAME}")" = 'null' ]; then
docker network connect "kind" "${REG_NAME}"
fi
kubectl apply -f $REPO_CONFIGMAP
kubectl apply -f "${WORK_DIR}/$REPO_CONFIGMAP"



#Build and push images

pushd "${WORK_DIR}/../.."
docker build --build-arg http_proxy="$HTTP_PROXY" --build-arg https_proxy="$HTTPS_PROXY" \
--build-arg no_proxy="$NO_PROXY" -t $QUOTE -f container/quote-server/Dockerfile .
Expand Down Expand Up @@ -107,15 +104,13 @@ kubectl create -f deployment/manifests/eventlog-server-deployment.yaml
kubectl create -f deployment/manifests/measurement-server-deployment.yaml
kubectl create -f deployment/manifests/quote-server-deployment.yaml

#Wait for all pods and services to be ready
sleep 2m

#Install SDK
pushd sdk/python3/
pip install -r requirements.txt
pip install -e .
pip install pytest pytdxattest
pip install .
popd
popd
sleep 2m

#Run test cases
pytest test_eventlog.py test_tdquote.py test_tdreport.py

0 comments on commit c98350d

Please sign in to comment.