Skip to content

Commit

Permalink
Merge pull request clearcontainers#938 from GabyCT/topic/notnet
Browse files Browse the repository at this point in the history
test: Docker integration test for disable networking
  • Loading branch information
jodh-intel authored Dec 3, 2018
2 parents abeee9a + dce95d8 commit 72919a9
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ network:
bash -f .ci/install_bats.sh
bats integration/network/macvlan/macvlan_driver.bats
bats integration/network/ipvlan/ipvlan_driver.bats
bats integration/network/disable_net/net_none.bats

ramdisk:
bash -f integration/ramdisk/ramdisk.sh
Expand Down
63 changes: 63 additions & 0 deletions integration/network/disable_net/net_none.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env bats
#
# Copyright (c) 2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#

load "${BATS_TEST_DIRNAME}/../../../lib/common.bash"

setup () {
clean_env

# Check that processes are not running
run check_processes
echo "$output"
[ "$status" -eq 0 ]
}

@test "Disable net" {
IMAGE="busybox"
PAYLOAD="tail -f /dev/null"
NAME="test"

extract_kata_env

# Get the name of the network name at the configuration.toml
NETWORK_NAME=$(grep -E "internetworking_model=" ${RUNTIME_CONFIG_PATH} | head -1 | cut -d '"' -f2)

# Disable the network
sudo sed -i 's/#disable_new_netns = true/disable_new_netns = true/g' ${RUNTIME_CONFIG_PATH}
sudo sed -i 's/internetworking_model=".*"/internetworking_model="none"/g' ${RUNTIME_CONFIG_PATH}

# Run a container without network
docker run -d --runtime=${RUNTIME} --name=${NAME} --net=none ${IMAGE} ${PAYLOAD}

# Check namespaces of host init daemon with no network
no_network_ns=$(sudo stat -L -c "%i" /proc/1/ns/net)

# Check namespaces of the processes with no network
general_processes=( ${PROXY_PATH} ${HYPERVISOR_PATH} ${SHIM_PATH} )
for i in "${general_processes[@]}"; do
process_pid=$(pgrep -f "$i")
process_ns=$(sudo stat -L -c "%i" /proc/$process_pid/ns/net)
# Compare namespace of host init daemon is equal to namespace of the process
[ "$no_network_ns" == "$process_ns" ]
done

# Remove container
docker rm -f $NAME

# Restart the network at the configuration.toml
sudo sed -i 's/disable_new_netns = true/#disable_new_netns = true/g' ${RUNTIME_CONFIG_PATH}
sudo sed -i 's/internetworking_model="none"/internetworking_model="'"${NETWORK_NAME}"'"/g' ${RUNTIME_CONFIG_PATH}
}

teardown() {
clean_env

# Check that processes are not running
run check_processes
echo "$output"
[ "$status" -eq 0 ]
}

0 comments on commit 72919a9

Please sign in to comment.