2016-12-17 12:29:27 +01:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load helpers
|
|
|
|
|
2017-09-15 15:08:19 -05:00
|
|
|
function teardown() {
|
|
|
|
cleanup_ctrs
|
|
|
|
cleanup_pods
|
|
|
|
stop_crio
|
|
|
|
rm -f /var/lib/cni/networks/crionet_test_args/*
|
2017-10-17 11:00:26 -06:00
|
|
|
chmod 0755 $CONMON_BINARY
|
2017-09-15 15:08:19 -05:00
|
|
|
cleanup_test
|
|
|
|
}
|
|
|
|
|
2017-09-13 10:28:41 +02:00
|
|
|
@test "ensure correct hostname" {
|
|
|
|
start_crio
|
2018-01-25 18:06:38 -08:00
|
|
|
run crictl runp "$TESTDATA"/sandbox_config.json
|
2017-09-13 10:28:41 +02:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
pod_id="$output"
|
2017-11-15 23:24:20 +08:00
|
|
|
run crictl create "$pod_id" "$TESTDATA"/container_redis.json "$TESTDATA"/sandbox_config.json
|
2017-09-13 10:28:41 +02:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
ctr_id="$output"
|
2017-11-15 23:24:20 +08:00
|
|
|
run crictl start "$ctr_id"
|
2017-09-13 10:28:41 +02:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
2017-11-15 23:24:20 +08:00
|
|
|
run crictl exec --sync "$ctr_id" sh -c "hostname"
|
2017-09-13 10:28:41 +02:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
2017-11-15 23:24:20 +08:00
|
|
|
[[ "$output" =~ "crictl_host" ]]
|
|
|
|
run crictl exec --sync "$ctr_id" sh -c "echo \$HOSTNAME"
|
2017-09-13 10:28:41 +02:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
2017-11-15 23:24:20 +08:00
|
|
|
[[ "$output" =~ "crictl_host" ]]
|
|
|
|
run crictl exec --sync "$ctr_id" sh -c "cat /etc/hostname"
|
2017-09-13 10:28:41 +02:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
2017-11-15 23:24:20 +08:00
|
|
|
[[ "$output" =~ "crictl_host" ]]
|
2017-09-13 10:28:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "ensure correct hostname for hostnetwork:true" {
|
|
|
|
start_crio
|
2018-02-12 12:13:07 -08:00
|
|
|
hostnetworkconfig=$(cat "$TESTDATA"/sandbox_config.json | python -c 'import json,sys;obj=json.load(sys.stdin);obj["linux"]["security_context"]["namespace_options"]["network"] = 2; obj["annotations"] = {}; obj["hostname"] = ""; json.dump(obj, sys.stdout)')
|
2017-09-13 10:28:41 +02:00
|
|
|
echo "$hostnetworkconfig" > "$TESTDIR"/sandbox_hostnetwork_config.json
|
2018-01-25 18:06:38 -08:00
|
|
|
run crictl runp "$TESTDIR"/sandbox_hostnetwork_config.json
|
2017-09-13 10:28:41 +02:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
pod_id="$output"
|
2017-11-15 23:24:20 +08:00
|
|
|
run crictl create "$pod_id" "$TESTDATA"/container_redis.json "$TESTDIR"/sandbox_hostnetwork_config.json
|
2017-09-13 10:28:41 +02:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
ctr_id="$output"
|
2017-11-15 23:24:20 +08:00
|
|
|
run crictl start "$ctr_id"
|
2017-09-13 10:28:41 +02:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
2017-11-15 23:24:20 +08:00
|
|
|
run crictl exec --sync "$ctr_id" sh -c "hostname"
|
2017-09-13 10:28:41 +02:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[[ "$output" =~ "$HOSTNAME" ]]
|
2017-11-15 23:24:20 +08:00
|
|
|
run crictl exec --sync "$ctr_id" sh -c "echo \$HOSTNAME"
|
2017-09-13 10:28:41 +02:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[[ "$output" =~ "$HOSTNAME" ]]
|
2017-11-15 23:24:20 +08:00
|
|
|
run crictl exec --sync "$ctr_id" sh -c "cat /etc/hostname"
|
2017-09-13 10:28:41 +02:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[[ "$output" =~ "$HOSTNAME" ]]
|
|
|
|
}
|
|
|
|
|
2016-12-17 12:29:27 +01:00
|
|
|
@test "Check for valid pod netns CIDR" {
|
2017-05-12 09:36:15 -04:00
|
|
|
start_crio
|
2018-01-25 18:06:38 -08:00
|
|
|
run crictl runp "$TESTDATA"/sandbox_config.json
|
2016-12-17 12:29:27 +01:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
pod_id="$output"
|
|
|
|
|
2017-11-15 23:24:20 +08:00
|
|
|
run crictl create "$pod_id" "$TESTDATA"/container_redis.json "$TESTDATA"/sandbox_config.json
|
2017-08-04 13:13:19 +02:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
ctr_id="$output"
|
|
|
|
|
|
|
|
check_pod_cidr $ctr_id
|
2017-11-15 23:24:20 +08:00
|
|
|
|
2016-12-17 12:29:27 +01:00
|
|
|
}
|
|
|
|
|
2016-12-21 11:28:33 +01:00
|
|
|
@test "Ping pod from the host" {
|
2017-05-12 09:36:15 -04:00
|
|
|
start_crio
|
2018-01-25 18:06:38 -08:00
|
|
|
run crictl runp "$TESTDATA"/sandbox_config.json
|
2016-12-17 12:29:27 +01:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
pod_id="$output"
|
|
|
|
|
2017-11-15 23:24:20 +08:00
|
|
|
run crictl create "$pod_id" "$TESTDATA"/container_redis.json "$TESTDATA"/sandbox_config.json
|
2017-08-04 13:13:19 +02:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
ctr_id="$output"
|
|
|
|
|
|
|
|
ping_pod $ctr_id
|
2016-12-17 12:29:27 +01:00
|
|
|
}
|
2016-12-21 11:28:33 +01:00
|
|
|
|
|
|
|
@test "Ping pod from another pod" {
|
2017-05-12 09:36:15 -04:00
|
|
|
start_crio
|
2018-01-25 18:06:38 -08:00
|
|
|
run crictl runp "$TESTDATA"/sandbox_config.json
|
2016-12-21 11:28:33 +01:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
pod1_id="$output"
|
2017-11-15 23:24:20 +08:00
|
|
|
run crictl create "$pod1_id" "$TESTDATA"/container_redis.json "$TESTDATA"/sandbox_config.json
|
2017-08-04 13:13:19 +02:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
ctr1_id="$output"
|
2016-12-21 11:28:33 +01:00
|
|
|
|
|
|
|
temp_sandbox_conf cni_test
|
|
|
|
|
2018-01-25 18:06:38 -08:00
|
|
|
run crictl runp "$TESTDIR"/sandbox_config_cni_test.json
|
2016-12-21 11:28:33 +01:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
pod2_id="$output"
|
2017-11-15 23:24:20 +08:00
|
|
|
run crictl create "$pod2_id" "$TESTDATA"/container_redis.json "$TESTDIR"/sandbox_config_cni_test.json
|
2017-08-04 13:13:19 +02:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
ctr2_id="$output"
|
2016-12-21 11:28:33 +01:00
|
|
|
|
2017-08-04 13:13:19 +02:00
|
|
|
ping_pod_from_pod $ctr1_id $ctr2_id
|
2016-12-21 11:28:33 +01:00
|
|
|
|
2017-08-04 13:13:19 +02:00
|
|
|
ping_pod_from_pod $ctr2_id $ctr1_id
|
2016-12-21 11:28:33 +01:00
|
|
|
}
|
2017-05-04 11:41:15 -05:00
|
|
|
|
|
|
|
@test "Ensure correct CNI plugin namespace/name/container-id arguments" {
|
2017-11-01 15:02:51 -06:00
|
|
|
if [[ ! -e "$CRIO_CNI_PLUGIN"/bridge-custom ]]; then
|
|
|
|
skip "bridge-custom plugin not available"
|
|
|
|
fi
|
2017-05-12 09:36:15 -04:00
|
|
|
start_crio "" "" "" "prepare_plugin_test_args_network_conf"
|
2018-01-25 18:06:38 -08:00
|
|
|
run crictl runp "$TESTDATA"/sandbox_config.json
|
2017-05-04 11:41:15 -05:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
. /tmp/plugin_test_args.out
|
|
|
|
|
2017-05-12 09:36:15 -04:00
|
|
|
[ "$FOUND_CNI_CONTAINERID" != "redhat.test.crio" ]
|
2017-05-04 11:41:15 -05:00
|
|
|
[ "$FOUND_CNI_CONTAINERID" != "podsandbox1" ]
|
2017-05-12 09:36:15 -04:00
|
|
|
[ "$FOUND_K8S_POD_NAMESPACE" = "redhat.test.crio" ]
|
2017-05-04 11:41:15 -05:00
|
|
|
[ "$FOUND_K8S_POD_NAME" = "podsandbox1" ]
|
|
|
|
|
2017-08-31 11:19:13 +02:00
|
|
|
rm -rf /tmp/plugin_test_args.out
|
2017-05-04 11:41:15 -05:00
|
|
|
}
|
2017-06-16 17:41:54 -07:00
|
|
|
|
|
|
|
@test "Connect to pod hostport from the host" {
|
|
|
|
start_crio
|
2018-01-25 18:06:38 -08:00
|
|
|
run crictl runp "$TESTDATA"/sandbox_config_hostport.json
|
2017-06-16 17:41:54 -07:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
pod_id="$output"
|
|
|
|
|
|
|
|
get_host_ip
|
|
|
|
echo $host_ip
|
|
|
|
|
2017-11-15 23:24:20 +08:00
|
|
|
run crictl create "$pod_id" "$TESTDATA"/container_config_hostport.json "$TESTDATA"/sandbox_config_hostport.json
|
2017-06-16 17:41:54 -07:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
ctr_id="$output"
|
2017-11-15 23:24:20 +08:00
|
|
|
run crictl start "$ctr_id"
|
2017-06-16 17:41:54 -07:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
2017-10-10 10:22:27 -06:00
|
|
|
run nc -w 5 $host_ip 4888 </dev/null
|
2017-06-16 17:41:54 -07:00
|
|
|
echo "$output"
|
2017-11-15 23:24:20 +08:00
|
|
|
[ "$output" = "crictl_host" ]
|
2017-06-16 17:41:54 -07:00
|
|
|
[ "$status" -eq 0 ]
|
2017-11-15 23:24:20 +08:00
|
|
|
run crictl stop "$ctr_id"
|
2017-06-16 17:41:54 -07:00
|
|
|
echo "$output"
|
2017-09-28 13:46:07 -04:00
|
|
|
[ "$status" -eq 0 ]
|
2017-06-16 17:41:54 -07:00
|
|
|
}
|
2017-09-13 15:53:22 -05:00
|
|
|
|
|
|
|
@test "Clean up network if pod sandbox fails" {
|
2017-11-01 15:02:51 -06:00
|
|
|
if [[ ! -e "$CRIO_CNI_PLUGIN"/bridge-custom ]]; then
|
|
|
|
skip "bridge-custom plugin not available"
|
|
|
|
fi
|
2017-09-13 15:53:22 -05:00
|
|
|
start_crio "" "" "" "prepare_plugin_test_args_network_conf"
|
|
|
|
|
|
|
|
# make conmon non-executable to cause the sandbox setup to fail after
|
|
|
|
# networking has been configured
|
2017-10-17 10:07:35 -06:00
|
|
|
chmod 0644 $CONMON_BINARY
|
2018-01-25 18:06:38 -08:00
|
|
|
run crictl runp "$TESTDATA"/sandbox_config.json
|
2017-10-17 10:07:35 -06:00
|
|
|
chmod 0755 $CONMON_BINARY
|
2017-09-28 13:46:07 -04:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -ne 0 ]
|
2017-09-13 15:53:22 -05:00
|
|
|
|
|
|
|
# ensure that the server cleaned up sandbox networking if the sandbox
|
|
|
|
# failed after network setup
|
|
|
|
rm -f /var/lib/cni/networks/crionet_test_args/last_reserved_ip
|
|
|
|
num_allocated=$(ls /var/lib/cni/networks/crionet_test_args | wc -l)
|
|
|
|
[[ "${num_allocated}" == "0" ]]
|
|
|
|
}
|