From 07ccda33955d927971d91650b7b34695a8f8c860 Mon Sep 17 00:00:00 2001 From: Samuel Ortiz Date: Thu, 6 Apr 2017 23:57:27 +0200 Subject: [PATCH] tests: Install CNI configuration files by default Since we no longer fall back to the noop plugin when CNI configuration files are missing, and since the default sandbox_config.json test file is running without host networking, we must install the bridge and loopback configuration files by default for tests to pass. Signed-off-by: Samuel Ortiz --- test/README.md | 12 ++++++++++++ test/helpers.bash | 9 +++++++-- test/network.bats | 33 --------------------------------- 3 files changed, 19 insertions(+), 35 deletions(-) diff --git a/test/README.md b/test/README.md index f61976f1..dbef4693 100644 --- a/test/README.md +++ b/test/README.md @@ -37,6 +37,18 @@ $ cd bats $ ./install.sh /usr/local ``` +You will also need to install the [CNI](https://github.com/containernetworking/cni) plugins as +the the default pod test template runs without host networking: + +``` +$ go get github.com/containernetworking/cni +$ cd "$GOPATH/src/github.com/containernetworking/cni" +$ git checkout -q d4bbce1865270cd2d2be558d6a23e63d314fe769 +$ ./build.sh \ +$ mkdir -p /opt/cni/bin \ +$ cp bin/* /opt/cni/bin/ +``` + Then you can run the tests on your host: ``` $ sudo make localintegration diff --git a/test/helpers.bash b/test/helpers.bash index be4c56c1..40c87e5a 100644 --- a/test/helpers.bash +++ b/test/helpers.bash @@ -63,8 +63,6 @@ POD_CIDR_MASK="10.88.*.*" cp "$CONMON_BINARY" "$TESTDIR/conmon" -mkdir -p $OCID_CNI_CONFIG - PATH=$PATH:$TESTDIR # Make sure we have a copy of the redis:latest image. @@ -149,6 +147,10 @@ function start_ocid() { fi "$COPYIMG_BINARY" --root "$TESTDIR/ocid" --runroot "$TESTDIR/ocid-run" --image-name=redis --import-from=dir:"$ARTIFACTS_PATH"/redis-image --add-name=docker://docker.io/library/redis:latest --signature-policy="$INTEGRATION_ROOT"/policy.json "$OCID_BINARY" --conmon "$CONMON_BINARY" --listen "$OCID_SOCKET" --runtime "$RUNTIME_BINARY" --root "$TESTDIR/ocid" --runroot "$TESTDIR/ocid-run" --seccomp-profile "$seccomp" --apparmor-profile "$apparmor" --cni-config-dir "$OCID_CNI_CONFIG" --signature-policy "$INTEGRATION_ROOT"/policy.json --config /dev/null config >$OCID_CONFIG + + # Prepare the CNI configuration files, we're running with non host networking by default + prepare_network_conf $POD_CIDR + "$OCID_BINARY" --debug --config "$OCID_CONFIG" & OCID_PID=$! wait_until_reachable @@ -209,6 +211,8 @@ function stop_ocid() { wait "$OCID_PID" rm -f "$OCID_CONFIG" fi + + cleanup_network_conf } function restart_ocid() { @@ -255,6 +259,7 @@ function is_apparmor_enabled() { } function prepare_network_conf() { + mkdir -p $OCID_CNI_CONFIG cat >$OCID_CNI_CONFIG/10-ocid.conf <<-EOF { "cniVersion": "0.2.0", diff --git a/test/network.bats b/test/network.bats index 0deea5e2..a044b6fb 100644 --- a/test/network.bats +++ b/test/network.bats @@ -3,16 +3,6 @@ load helpers @test "Check for valid pod netns CIDR" { - if [ ! -f "$OCID_CNI_PLUGIN/bridge" ]; then - skip "missing CNI bridge plugin, please install it" - fi - - if [ ! -f "$OCID_CNI_PLUGIN/host-local" ]; then - skip "missing CNI host-local IPAM, please install it" - fi - - prepare_network_conf $POD_CIDR - start_ocid run ocic pod run --config "$TESTDATA"/sandbox_config.json echo "$output" @@ -22,21 +12,10 @@ load helpers check_pod_cidr $pod_id cleanup_pods - cleanup_network_conf stop_ocid } @test "Ping pod from the host" { - if [ ! -f "$OCID_CNI_PLUGIN/bridge" ]; then - skip "missing CNI bridge plugin, please install it" - fi - - if [ ! -f "$OCID_CNI_PLUGIN/host-local" ]; then - skip "missing CNI host-local IPAM, please install it" - fi - - prepare_network_conf $POD_CIDR - start_ocid run ocic pod run --config "$TESTDATA"/sandbox_config.json echo "$output" @@ -46,21 +25,10 @@ load helpers ping_pod $pod_id cleanup_pods - cleanup_network_conf stop_ocid } @test "Ping pod from another pod" { - if [ ! -f "$OCID_CNI_PLUGIN/bridge" ]; then - skip "missing CNI bridge plugin, please install it" - fi - - if [ ! -f "$OCID_CNI_PLUGIN/host-local" ]; then - skip "missing CNI host-local IPAM, please install it" - fi - - prepare_network_conf $POD_CIDR - start_ocid run ocic pod run --config "$TESTDATA"/sandbox_config.json echo "$output" @@ -81,6 +49,5 @@ load helpers [ "$status" -eq 0 ] cleanup_pods - cleanup_network_conf stop_ocid }