Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
basic test to confirm static ip allocation works
Browse files Browse the repository at this point in the history
  • Loading branch information
nonsense committed Jan 25, 2021
1 parent 49f007f commit 32445eb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
3 changes: 3 additions & 0 deletions ipam/claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ func (c *claim) Try(alloc *Allocator) bool {
// but we also cannot prove otherwise, so we let it reclaim the address:
alloc.debugln("Re-Claimed", c.cidr, "for ID", c.ident, "having existing ID as", existingIdent)
c.sendResult(nil)
case c.ident == "weave:expose":
alloc.debugln("Ignoring weave:expose")
c.sendResult(nil)
default:
// Addr already owned by container on this machine
c.sendResult(fmt.Errorf("address %s is already owned by %s", c.cidr.String(), existingIdent))
Expand Down
32 changes: 24 additions & 8 deletions test/880_cni_plugin_ip_address_assignment_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

. "$(dirname "$0")/config.sh"

start_suite "Test CNI plugin"
start_suite "Test CNI plugin with static IP allocation"

cni_connect() {
pid=$(container_pid $1 $2)
Expand All @@ -13,8 +13,8 @@ cni_connect() {

run_on $HOST1 sudo mkdir -p /opt/cni/bin
# setup-cni is a subset of 'weave setup', without doing any 'docker pull's
weave_on $HOST1 setup-cni
weave_on $HOST1 launch
weave_on $HOST1 setup-cni --log-level=debug
weave_on $HOST1 launch --log-level=debug

C0=$(docker_on $HOST1 run --net=none --name=c0 --privileged -dt $SMALL_IMAGE /bin/sh)
C1=$(docker_on $HOST1 run --net=none --name=c1 --privileged -dt $SMALL_IMAGE /bin/sh)
Expand Down Expand Up @@ -70,16 +70,32 @@ C0IP=$(container_ip $HOST1 c0)
C1IP=$(container_ip $HOST1 c1)
C2IP=$(container_ip $HOST1 c2)

echo $C0IP
echo $C1IP
echo $C2IP
assert_raises "[ "10.32.1.30" == $C0IP ]"
assert_raises "[ "10.32.1.40" == $C1IP ]"
assert_raises "[ "10.32.1.42" == $C2IP ]"

BRIP=$(container_ip $HOST1 weave:expose)
# Check the bridge IP is different from the container IPs
assert_raises "[ $BRIP != $C0IP ]"
assert_raises "[ $BRIP != $C1IP ]"
assert_raises "[ $BRIP != $C2IP ]"

# Containers should be able to reach one another
assert_raises "exec_on $HOST1 c0 $PING $C1IP"
assert_raises "exec_on $HOST1 c1 $PING $C2IP"
assert_raises "exec_on $HOST1 c2 $PING $C1IP"

# Containers should not have a default route to the world
assert_raises "exec_on $HOST1 c0 sh -c '! $PING 8.8.8.8'"
assert_raises "exec_on $HOST1 c1 sh -c '! $PING 8.8.8.8'"
assert_raises "exec_on $HOST1 c2 sh -c '! $PING 8.8.8.8'"

# Ensure existing containers can reclaim their IP addresses after CNI has been used -- see #2548
stop_weave_on $HOST1

# Ensure no warning is printed to the standard error:
ACTUAL_OUTPUT=$(CHECKPOINT_DISABLE="$CHECKPOINT_DISABLE" $WEAVE launch 2>&1)
EXPECTED_OUTPUT=$(docker inspect --format="{{.Id}}" weave)
ACTUAL_OUTPUT=$(CHECKPOINT_DISABLE="$CHECKPOINT_DISABLE" DOCKER_HOST=tcp://$HOST1:$DOCKER_PORT $WEAVE launch 2>&1)
EXPECTED_OUTPUT=$($SSH $HOST1 docker inspect --format="{{.Id}}" weave)

assert_raises "[ $EXPECTED_OUTPUT == $ACTUAL_OUTPUT ]"

Expand Down

0 comments on commit 32445eb

Please sign in to comment.