From d2d1d2b43a72dfadcc924ca91df03ad1c0825966 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Wed, 16 Mar 2016 13:11:13 +0000 Subject: [PATCH 1/2] Test for docker network subnets and IPs --- test/820_plugin_subnet_test.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 test/820_plugin_subnet_test.sh diff --git a/test/820_plugin_subnet_test.sh b/test/820_plugin_subnet_test.sh new file mode 100755 index 00000000..a76c3b69 --- /dev/null +++ b/test/820_plugin_subnet_test.sh @@ -0,0 +1,20 @@ +#! /bin/bash + +. ./config.sh + +start_suite "Test Docker Network plugin with specified subnet" + +weave_on $HOST1 launch + +# using ssh rather than docker -H because CircleCI docker client is older +$SSH $HOST1 docker network create --driver weavemesh --ipam-driver weavemesh --subnet 10.40.0.0/16 testsubnet + +$SSH $HOST1 docker run --name=c1 -dt --net=testsubnet --ip 10.40.0.1 $SMALL_IMAGE /bin/sh +$SSH $HOST1 docker run --name=c2 -dt --net=testsubnet $SMALL_IMAGE /bin/sh + +assert "container_ip $HOST1 c1" "10.40.0.1" +assert "container_ip $HOST1 c2" "10.40.0.2" # assuming linear allocation strategy +assert_raises "exec_on $HOST1 c1 $PING c2" +assert_raises "exec_on $HOST1 c2 $PING c1" + +end_suite From eee77d49d1c70bd5cc7a3c0c5ebfbbfa279a97b4 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Wed, 16 Mar 2016 13:11:35 +0000 Subject: [PATCH 2/2] Claim IP takes CIDR not IP --- api/ipam.go | 4 ++-- plugin/ipam/driver.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/api/ipam.go b/api/ipam.go index 9f1687dd..d061b420 100644 --- a/api/ipam.go +++ b/api/ipam.go @@ -33,8 +33,8 @@ func (client *Client) LookupIP(ID string) (*net.IPNet, error) { } // Claim a specific IP on behalf of the ID -func (client *Client) ClaimIP(ID string, addr net.IP) error { - _, err := client.httpVerb("PUT", fmt.Sprintf("/ip/%s/%s", ID, addr), nil) +func (client *Client) ClaimIP(ID string, cidr *net.IPNet) error { + _, err := client.httpVerb("PUT", fmt.Sprintf("/ip/%s/%s", ID, cidr), nil) return err } diff --git a/plugin/ipam/driver.go b/plugin/ipam/driver.go index 0a965abb..cd37e8d6 100644 --- a/plugin/ipam/driver.go +++ b/plugin/ipam/driver.go @@ -73,10 +73,10 @@ func (i *ipam) RequestAddress(poolID string, address net.IP, options map[string] return } if address != nil { // try to claim specific address requested - if err = i.weave.ClaimIP("_", address); err != nil { + ip = &net.IPNet{IP: address, Mask: subnet.Mask} + if err = i.weave.ClaimIP("_", ip); err != nil { return } - ip = &net.IPNet{IP: address, Mask: subnet.Mask} } else { if _, iprange, err = net.ParseCIDR(parts[2]); err != nil { return