Skip to content

Commit 6133465

Browse files
author
Mrunal Patel
authored
Merge pull request cri-o#292 from sameo/topic/network-bats
Additional networking tests
2 parents ac7943c + 8e1af36 commit 6133465

File tree

3 files changed

+166
-10
lines changed

3 files changed

+166
-10
lines changed

test/helpers.bash

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -235,18 +235,26 @@ function check_pod_cidr() {
235235
}
236236

237237
function parse_pod_ip() {
238-
for arg
239-
do
240-
cidr=`echo "$arg" | grep $POD_CIDR_MASK`
241-
if [ "$cidr" == "$arg" ]
242-
then
243-
echo `echo "$arg" | sed "s/\/[0-9][0-9]//"`
244-
fi
245-
done
238+
for arg
239+
do
240+
cidr=`echo "$arg" | grep $POD_CIDR_MASK`
241+
if [ "$cidr" == "$arg" ]
242+
then
243+
echo `echo "$arg" | sed "s/\/[0-9][0-9]//"`
244+
fi
245+
done
246+
}
247+
248+
function ping_host_pod() {
249+
pod_ip=`ocic pod status --id $1 | grep "IP Address" | cut -d ' ' -f 3`
250+
251+
ping -W 1 -c 5 $pod_ip
252+
253+
echo $?
246254
}
247255

248256
function ping_pod() {
249-
netns=`ocic pod status --id $1 | grep namespace | cut -d ' ' -f 3`
257+
netns=`ocic pod status --id $1 | grep namespace | cut -d ' ' -f 3`
250258
inet=`ip netns exec \`basename $netns\` ip addr show dev eth0 scope global | grep inet`
251259

252260
IFS=" "
@@ -257,8 +265,22 @@ function ping_pod() {
257265
echo $?
258266
}
259267

268+
function ping_pod_from_pod() {
269+
pod_ip=`ocic pod status --id $1 | grep "IP Address" | cut -d ' ' -f 3`
270+
netns=`ocic pod status --id $2 | grep namespace | cut -d ' ' -f 3`
271+
272+
ip netns exec `basename $netns` ping -W 1 -c 2 $pod_ip
273+
274+
echo $?
275+
}
276+
277+
260278
function cleanup_network_conf() {
261279
rm -rf $OCID_CNI_CONFIG
262280

263281
echo 0
264282
}
283+
284+
function temp_sandbox_conf() {
285+
sed -e s/\"namespace\":.*/\"namespace\":\ \"$1\",/g "$TESTDATA"/sandbox_config.json > $TESTDIR/sandbox_config_$1.json
286+
}

test/network.bats

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ load helpers
3131
stop_ocid
3232
}
3333

34-
@test "Ping pod netns from the host" {
34+
@test "Ping pod from the host" {
3535
# this test requires docker, thus it can't yet be run in a container
3636
if [ "$TRAVIS" = "true" ]; then # instead of $TRAVIS, add a function is_containerized to skip here
3737
skip "cannot yet run this test in a container, use sudo make localintegration"
@@ -59,3 +59,74 @@ load helpers
5959
cleanup_network_conf
6060
stop_ocid
6161
}
62+
63+
@test "Ping host pod from the host" {
64+
# this test requires docker, thus it can't yet be run in a container
65+
if [ "$TRAVIS" = "true" ]; then # instead of $TRAVIS, add a function is_containerized to skip here
66+
skip "cannot yet run this test in a container, use sudo make localintegration"
67+
fi
68+
69+
if [ ! -f "$OCID_CNI_PLUGIN/bridge" ]; then
70+
skip "missing CNI bridge plugin, please install it"
71+
fi
72+
73+
if [ ! -f "$OCID_CNI_PLUGIN/host-local" ]; then
74+
skip "missing CNI host-local IPAM, please install it"
75+
fi
76+
77+
prepare_network_conf $POD_CIDR
78+
79+
start_ocid
80+
run ocic pod run --config "$TESTDATA"/sandbox_config_hostnet.json
81+
echo "$output"
82+
[ "$status" -eq 0 ]
83+
pod_id="$output"
84+
85+
ping_host_pod $pod_id
86+
87+
cleanup_pods
88+
cleanup_network_conf
89+
90+
stop_ocid
91+
}
92+
93+
94+
@test "Ping pod from another pod" {
95+
# this test requires docker, thus it can't yet be run in a container
96+
if [ "$TRAVIS" = "true" ]; then # instead of $TRAVIS, add a function is_containerized to skip here
97+
skip "cannot yet run this test in a container, use sudo make localintegration"
98+
fi
99+
100+
if [ ! -f "$OCID_CNI_PLUGIN/bridge" ]; then
101+
skip "missing CNI bridge plugin, please install it"
102+
fi
103+
104+
if [ ! -f "$OCID_CNI_PLUGIN/host-local" ]; then
105+
skip "missing CNI host-local IPAM, please install it"
106+
fi
107+
108+
prepare_network_conf $POD_CIDR
109+
110+
start_ocid
111+
run ocic pod run --config "$TESTDATA"/sandbox_config.json
112+
echo "$output"
113+
[ "$status" -eq 0 ]
114+
pod1_id="$output"
115+
116+
temp_sandbox_conf cni_test
117+
118+
run ocic pod run --config "$TESTDIR"/sandbox_config_cni_test.json
119+
echo "$output"
120+
[ "$status" -eq 0 ]
121+
pod2_id="$output"
122+
123+
ping_pod_from_pod $pod1_id $pod2_id
124+
[ "$status" -eq 0 ]
125+
126+
ping_pod_from_pod $pod2_id $pod1_id
127+
[ "$status" -eq 0 ]
128+
129+
cleanup_pods
130+
cleanup_network_conf
131+
stop_ocid
132+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"metadata": {
3+
"name": "podsandbox1",
4+
"uid": "redhat-test-ocid",
5+
"namespace": "redhat.test.ocid",
6+
"attempt": 1
7+
},
8+
"hostname": "ocic_host",
9+
"log_directory": ".",
10+
"dns_options": {
11+
"servers": [
12+
"server1.redhat.com",
13+
"server2.redhat.com"
14+
],
15+
"searches": [
16+
"8.8.8.8"
17+
]
18+
},
19+
"port_mappings": [
20+
{
21+
"name": "port_map1",
22+
"protocol": 1,
23+
"container_port": 80,
24+
"host_port": 4888,
25+
"host_ip": "192.168.0.33"
26+
},
27+
{
28+
"name": "port_map2",
29+
"protocol": 2,
30+
"container_port": 81,
31+
"host_port": 4889,
32+
"host_ip": "192.168.0.33"
33+
}
34+
],
35+
"resources": {
36+
"cpu": {
37+
"limits": 3,
38+
"requests": 2
39+
},
40+
"memory": {
41+
"limits": 50000000,
42+
"requests": 2000000
43+
}
44+
},
45+
"labels": {
46+
"group": "test"
47+
},
48+
"annotations": {
49+
"owner": "hmeng",
50+
"security.alpha.kubernetes.io/unsafe-sysctls": "kernel.msgmax=8192" ,
51+
"security.alpha.kubernetes.io/seccomp/pod": "unconfined"
52+
},
53+
"linux": {
54+
"cgroup_parent": "/ocid-podsandbox1",
55+
"security_context": {
56+
"namespace_options": {
57+
"host_network": true,
58+
"host_pid": false,
59+
"host_ipc": false
60+
}
61+
}
62+
}
63+
}

0 commit comments

Comments
 (0)