cni_test.bash 4.1 KB
Newer Older
L
lifeng68 已提交
1 2 3 4
#!/bin/bash
#
# attributes: isulad cri cni
# concurrent: NA
L
lifeng68 已提交
5
# spend time: 45
L
lifeng68 已提交
6 7 8

curr_path=$(dirname $(readlink -f "$0"))
data_path=$(realpath $curr_path/criconfigs)
L
lifeng68 已提交
9
pause_img_path=$(realpath $curr_path/test_data)
L
lifeng68 已提交
10 11 12 13 14
source ../helpers.bash

function do_pre()
{
    cp /etc/isulad/daemon.json /etc/isulad/daemon.bak
L
lifeng68 已提交
15
    sed -i "s#\"pod-sandbox-image\": \"\"#\"pod-sandbox-image\": \"mirrorgooglecontainers/pause-amd64:3.0\"#g" /etc/isulad/daemon.json
L
lifeng68 已提交
16 17 18 19 20 21 22

    init_cni_conf $data_path
    if [ $? -ne 0 ]; then
        msg_err "Failed to init cni config"
        TC_RET_T=$(($TC_RET_T+1))
        return $TC_RET_T
    fi
L
lifeng68 已提交
23 24 25

    isula load -i ${pause_img_path}/pause.tar
    if [ $? -ne 0 ]; then
L
lifeng68 已提交
26
        msg_err "Failed to load pause image"
L
lifeng68 已提交
27 28 29 30
        TC_RET_T=$(($TC_RET_T+1))
        return $TC_RET_T
    fi

L
lifeng68 已提交
31 32 33 34 35
}

function do_post()
{
    cp -f /etc/isulad/daemon.bak /etc/isulad/daemon.json
L
lifeng68 已提交
36 37
    check_valgrind_log
    start_isulad_with_valgrind
L
lifeng68 已提交
38 39 40 41 42 43
}

function do_test_help()
{
    msg_info "this is $0 do_test"

L
lifeng68 已提交
44
    crictl pull busybox
L
lifeng68 已提交
45
    if [ $? -ne 0 ]; then
L
lifeng68 已提交
46 47 48 49 50 51 52
        msg_err "Failed to pull busybox image"
        TC_RET_T=$(($TC_RET_T+1))
    fi

    crictl images | grep "mirrorgooglecontainers/pause-amd64"
    if [ $? -ne 0 ]; then
        msg_err "Failed to find mirrorgooglecontainers/pause-amd64 image"
L
lifeng68 已提交
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
        TC_RET_T=$(($TC_RET_T+1))
    fi

    sid=`crictl runp ${data_path}/sandbox-config.json`
    if [ $? -ne 0 ]; then
        msg_err "Failed to run sandbox"
        TC_RET_T=$(($TC_RET_T+1))
    fi

    spid=`isula inspect -f '{{json .State.Pid}}' $sid`
    nsenter -t $spid -n ifconfig eth0
    if [ $? -ne 0 ];then
        msg_err "Sandbox network config failed"
        TC_RET_T=$(($TC_RET_T+1))
    fi

    cid=`crictl create $sid ${data_path}/container-config.json ${data_path}/sandbox-config.json`
    if [ $? -ne 0 ];then
        msg_err "create container failed"
        TC_RET_T=$(($TC_RET_T+1))
    fi

    crictl start $cid
    if [ $? -ne 0 ];then
        msg_err "start container failed"
        TC_RET_T=$(($TC_RET_T+1))
L
lifeng68 已提交
79 80 81 82 83 84
    fi

    crictl stats
    if [ $? -ne 0 ];then
        msg_err "stats container failed"
        TC_RET_T=$(($TC_RET_T+1))
L
lifeng68 已提交
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
    fi

    # check whether container use pod network namespace
    pod_pid=`isula inspect -f '{{json .State.Pid}}' $sid`
    pod_net_ns_id=`ls -l /proc/${pod_pid}/ns/net | awk -F[ '{print $2}' |awk -F] '{print $1}'`
    con_pid=`isula inspect -f '{{json .State.Pid}}' $cid`
    con_net_ns_id=`ls -l /proc/${con_pid}/ns/net | awk -F[ '{print $2}' |awk -F] '{print $1}'`

    if [ "$pod_net_ns_id" != "$con_net_ns_id" ];then
        msg_err "Pod and container use different network namespace"
        nsenter -t $pod_pid -n ifconfig eth0
        nsenter -t $con_pid -n ifconfig eth0
        TC_RET_T=$(($TC_RET_T+1))
    fi
    nsenter -t $pod_pid -n ifconfig eth0 | grep "$1"
    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 stop $cid
    if [ $? -ne 0 ];then
        msg_err "stop container failed"
        TC_RET_T=$(($TC_RET_T+1))
    fi

    crictl rm $cid
    if [ $? -ne 0 ];then
        msg_err "stop container failed"
        TC_RET_T=$(($TC_RET_T+1))
    fi

    crictl stopp $sid
    if [ $? -ne 0 ];then
        msg_err "stop sandbox failed"
        TC_RET_T=$(($TC_RET_T+1))
    fi

    crictl rmp $sid
    if [ $? -ne 0 ];then
        msg_err "rm sandbox failed"
        TC_RET_T=$(($TC_RET_T+1))
    fi

    return $TC_RET_T
}

function default_cni_config()
{
    do_test_help "10\.1\."
}

function new_cni_config()
{
    cp ${data_path}/bridge.json /etc/cni/net.d/
    sync;sync;
    tail $ISUALD_LOG
    # wait cni updated
    s=`date "+%s"`
    for ((i=0;i<30;i++)); do
        sleep 1
        cur=`date "+%s"`
        let "t=cur-s"
        if [ $t -gt 6 ];then
            break
        fi
    done
    tail $ISUALD_LOG
    do_test_help "10\.2\."
}

ret=0

do_pre
if [ $? -ne 0 ];then
    let "ret=$ret + 1"
fi

default_cni_config
if [ $? -ne 0 ];then
    let "ret=$ret + 1"
fi

new_cni_config
if [ $? -ne 0 ];then
    let "ret=$ret + 1"
fi

do_post

show_result $ret "cni base test"