From c8eaab912c22d2a46edf308a4dd71c609d8b683c Mon Sep 17 00:00:00 2001 From: haozi007 Date: Tue, 10 Nov 2020 10:51:31 +0800 Subject: [PATCH 27/28] add testcases for mutl networks Signed-off-by: haozi007 --- CI/install_depends.sh | 7 +++-- CI/test_cases/container_cases/cni_test.sh | 31 ++++++++++++++++--- .../container_cases/criconfigs/bridge.json | 17 +++++----- .../criconfigs/mutlnet_pod.json | 17 ++++++++++ 4 files changed, 57 insertions(+), 15 deletions(-) create mode 100644 CI/test_cases/container_cases/criconfigs/mutlnet_pod.json diff --git a/CI/install_depends.sh b/CI/install_depends.sh index 61dd67d..5dd2543 100755 --- a/CI/install_depends.sh +++ b/CI/install_depends.sh @@ -38,10 +38,13 @@ mkdir -p ${builddir}/systemd/system function make_crictl() { cd ~ - git clone -b release-1.14 https://gitee.com/duguhaotian/cri-tools.git + git clone https://gitee.com/duguhaotian/cri-tools.git + go version cd cri-tools + git checkout v1.18.0 make -j $nproc - cp ./_output/bin/crictl ${builddir}/bin/ + echo "make cri-tools: $?" + cp ./_output/crictl ${builddir}/bin/ } #install cni plugins diff --git a/CI/test_cases/container_cases/cni_test.sh b/CI/test_cases/container_cases/cni_test.sh index 8173cb5..c9e1e1a 100644 --- a/CI/test_cases/container_cases/cni_test.sh +++ b/CI/test_cases/container_cases/cni_test.sh @@ -53,7 +53,7 @@ function do_test_help() TC_RET_T=$(($TC_RET_T+1)) fi - sid=`crictl runp ${data_path}/sandbox-config.json` + sid=`crictl runp ${data_path}/$1` if [ $? -ne 0 ]; then msg_err "Failed to run sandbox" TC_RET_T=$(($TC_RET_T+1)) @@ -66,7 +66,7 @@ function do_test_help() TC_RET_T=$(($TC_RET_T+1)) fi - cid=`crictl create $sid ${data_path}/container-config.json ${data_path}/sandbox-config.json` + cid=`crictl create $sid ${data_path}/container-config.json ${data_path}/$1` if [ $? -ne 0 ];then msg_err "create container failed" TC_RET_T=$(($TC_RET_T+1)) @@ -96,12 +96,33 @@ function do_test_help() nsenter -t $con_pid -n ifconfig eth0 TC_RET_T=$(($TC_RET_T+1)) fi - nsenter -t $pod_pid -n ifconfig eth0 | grep "$1" + nsenter -t $pod_pid -n ifconfig eth0 | grep "$2" if [ $? -ne 0 ];then msg_err "expect ip: $1, get: " nsenter -t $pod_pid -n ifconfig eth0 TC_RET_T=$(($TC_RET_T+1)) fi + crictl inspectp $sid | grep "$2" + if [ $? -ne 0 ];then + msg_err "inspectp: expect ip: $1, get: " + crictl inspectp $sid + TC_RET_T=$(($TC_RET_T+1)) + fi + + if [ "x$3" != "x" ];then + nsenter -t $pod_pid -n ifconfig eth1 | grep "$3" + if [ $? -ne 0 ];then + msg_err "expect ip: $2, get: " + nsenter -t $pod_pid -n ifconfig eth1 + TC_RET_T=$(($TC_RET_T+1)) + fi + crictl inspectp $sid | grep "$3" + if [ $? -ne 0 ];then + msg_err "inspectp expect ip: $2, get: " + crictl inspectp $sid + TC_RET_T=$(($TC_RET_T+1)) + fi + fi crictl stop $cid if [ $? -ne 0 ];then @@ -132,7 +153,7 @@ function do_test_help() function default_cni_config() { - do_test_help "10\.1\." + do_test_help "sandbox-config.json" "10\.1\." } function new_cni_config() @@ -151,7 +172,7 @@ function new_cni_config() fi done tail $ISUALD_LOG - do_test_help "10\.2\." + do_test_help "mutlnet_pod.json" "10\.2\." "10\.1\." } function check_annotation() diff --git a/CI/test_cases/container_cases/criconfigs/bridge.json b/CI/test_cases/container_cases/criconfigs/bridge.json index 4d19fa7..7686e26 100644 --- a/CI/test_cases/container_cases/criconfigs/bridge.json +++ b/CI/test_cases/container_cases/criconfigs/bridge.json @@ -1,10 +1,11 @@ { - "cniVersion": "0.3.0", - "name": "ok", - "type": "bridge", - "bridge": "cni0", - "ipam": { - "type": "host-local", - "subnet": "10.2.0.0/16" - } + "cniVersion": "0.3.0", + "name": "ok", + "type": "bridge", + "bridge": "cni0", + "isGateway": true, + "ipam": { + "type": "host-local", + "subnet": "10.2.0.0/16" + } } diff --git a/CI/test_cases/container_cases/criconfigs/mutlnet_pod.json b/CI/test_cases/container_cases/criconfigs/mutlnet_pod.json new file mode 100644 index 0000000..f860620 --- /dev/null +++ b/CI/test_cases/container_cases/criconfigs/mutlnet_pod.json @@ -0,0 +1,17 @@ +{ + "port_mappings":[{"protocol": 1, "container_port": 80, "host_port": 8080}], + "metadata": { + "name": "test", + "namespace": "default", + "attempt": 1, + "uid": "hdishd83djaidwnduwk28bcsb" + }, + "linux": { + }, + "annotations": { + "network.alpha.kubernetes.io/network": "[{\"name\":\"good\",\"interface\":\"eth1\"}]", + "extension.network.kubernetes.io/cni": "[multinetwork]", + "extension.network.kubernetes.io/cniargs/first": "extension=first", + "extension.network.kubernetes.io/cniargs/second": "extension=second" + } +} -- 2.20.1