From da36c789423fcefbe99ef01a660e7540ef7ea118 Mon Sep 17 00:00:00 2001 From: Tom Wilkie Date: Fri, 29 May 2015 13:41:29 +0000 Subject: [PATCH 1/4] Reduce the number of times gcs.sh ssh's into the VMs --- circle.yml | 2 +- test/gce.sh | 39 ++++++++++++++++++++++++++------------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/circle.yml b/circle.yml index 4bc4d29b..98aa437c 100644 --- a/circle.yml +++ b/circle.yml @@ -26,7 +26,7 @@ dependencies: docker save weaveworks/weave-build >$WEAVE_BUILD; fi post: - - sudo apt-get install bc + - sudo apt-get install bc jq - pip install requests - curl https://sdk.cloud.google.com | bash - bin/setup-circleci-secrets "$SECRET_PASSWORD" diff --git a/test/gce.sh b/test/gce.sh index 93629679..87d08ea6 100755 --- a/test/gce.sh +++ b/test/gce.sh @@ -50,12 +50,12 @@ function destroy { done } -function external_ip { - gcloud compute instances list $1 --format=yaml | grep "^ natIP\:" | cut -d: -f2 | tr -d ' ' +function internal_ip { + jq -r ".[] | select(.name == \"$2\") | .networkInterfaces[0].networkIP" $1 } -function internal_ip { - gcloud compute instances list $1 --format=yaml | grep "^ networkIP\:" | cut -d: -f2 | tr -d ' ' +function external_ip { + jq -r ".[] | select(.name == \"$2\") | .networkInterfaces[0].accessConfigs[0].natIP" $1 } function try_connect { @@ -81,32 +81,42 @@ EOF ssh -t $name sudo docker run --rm -v /usr/local/bin:/target jpetazzo/nsenter } -# Create new set of VMS +# Create new set of VMs function setup { destroy names="$(vm_names)" gcloud compute instances create $names --image $TEMPLATE_NAME --zone $ZONE gcloud compute config-ssh --ssh-key-file $SSH_KEY_FILE + sed -i '/UserKnownHostsFile=\/dev\/null/d' ~/.ssh/config + + # build an /etc/hosts file for these vms + hosts=$(mktemp hosts.XXXXXXXXXX) + json=$(mktemp json.XXXXXXXXXX) + gcloud compute instances list --format=json >$json + for name in $names; do + echo "$(internal_ip $json $name) $name.$ZONE.$PROJECT" >>$hosts + done for name in $names; do hostname="$name.$ZONE.$PROJECT" + # Add the remote ip to the local /etc/hosts - sudo -- sh -c "echo \"$(external_ip $name) $hostname\" >>/etc/hosts" + sudo sed -i "/$hostname/d" /etc/hosts + sudo sh -c "echo \"$(external_ip $json $name) $hostname\" >>/etc/hosts" try_connect $hostname - # Add the local ips to the remote /etc/hosts - for othername in $names; do - entry="$(internal_ip $othername) $othername.$ZONE.$PROJECT" - ssh -t "$hostname" "sudo -- sh -c \"echo \\\"$entry\\\" >>/etc/hosts\"" - done + # Copy the /etc/hosts we built over + cat $hosts | ssh -t "$hostname" "sudo -- sh -c \"cat >>/etc/hosts\"" done + + rm $hosts $json } function make_template { gcloud compute instances create $TEMPLATE_NAME --image $IMAGE --zone $ZONE gcloud compute config-ssh --ssh-key-file $SSH_KEY_FILE name="$TEMPLATE_NAME.$ZONE.$PROJECT" - try_connect $name + try_connect $name install_docker_on $name gcloud -q compute instances delete $TEMPLATE_NAME --keep-disks boot --zone $ZONE gcloud compute images create $TEMPLATE_NAME --source-disk $TEMPLATE_NAME --source-disk-zone $ZONE @@ -115,14 +125,17 @@ function make_template { function hosts { hosts= args= + json=$(mktemp json.XXXXXXXXXX) + gcloud compute instances list --format=json >$json for name in $(vm_names); do hostname="$name.$ZONE.$PROJECT" hosts="$hostname $hosts" - args="--add-host=$hostname:$(internal_ip $name) $args" + args="--add-host=$hostname:$(internal_ip $json $name) $args" done echo export SSH=ssh echo export HOSTS=\"$hosts\" echo export WEAVE_DOCKER_ARGS=\"$args\" + rm $json } case "$1" in From e7676979ee22162ec8ba747ad5c943bc07c1a6cb Mon Sep 17 00:00:00 2001 From: Tom Wilkie Date: Wed, 29 Jul 2015 09:44:55 +0000 Subject: [PATCH 2/4] Parallelise the copying of imaages etc --- test/setup.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/setup.sh b/test/setup.sh index 0410af57..b7f7cd28 100755 --- a/test/setup.sh +++ b/test/setup.sh @@ -10,7 +10,9 @@ cd "$(dirname "${BASH_SOURCE[0]}")" echo "Copying weave images, scripts, and certificates to hosts, and" echo " prefetch test images" -for HOST in $HOSTS; do + +setup_host() { + HOST=$1 docker_on $HOST load -i ../weave.tar DANGLING_IMAGES="$(docker_on $HOST images -q -f dangling=true)" [ -n "$DANGLING_IMAGES" ] && docker_on $HOST rmi $DANGLING_IMAGES 1>/dev/null 2>&1 || true @@ -21,4 +23,10 @@ for HOST in $HOSTS; do for IMG in $TEST_IMAGES ; do docker_on $HOST inspect --format=" " $IMG >/dev/null 2>&1 || docker_on $HOST pull $IMG done +} + +for HOST in $HOSTS; do + setup_host $HOST & done + +wait From 51128a6705ad9f11c1a014a995fca33b0cf42bcd Mon Sep 17 00:00:00 2001 From: Tom Wilkie Date: Wed, 29 Jul 2015 09:44:27 +0000 Subject: [PATCH 3/4] Parallelise the copying of /etc/hosts. --- test/gce.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/gce.sh b/test/gce.sh index 87d08ea6..560c5a3e 100755 --- a/test/gce.sh +++ b/test/gce.sh @@ -81,6 +81,12 @@ EOF ssh -t $name sudo docker run --rm -v /usr/local/bin:/target jpetazzo/nsenter } +function copy_hosts { + hostname=$1 + hosts=$2 + cat $hosts | ssh -t "$hostname" "sudo -- sh -c \"cat >>/etc/hosts\"" +} + # Create new set of VMs function setup { destroy @@ -105,10 +111,11 @@ function setup { sudo sh -c "echo \"$(external_ip $json $name) $hostname\" >>/etc/hosts" try_connect $hostname - # Copy the /etc/hosts we built over - cat $hosts | ssh -t "$hostname" "sudo -- sh -c \"cat >>/etc/hosts\"" + copy_hosts $hostname $hosts & done + wait + rm $hosts $json } From 4df3d7f150a2bfacc5f8d994a03b60cd74f26a4f Mon Sep 17 00:00:00 2001 From: Tom Wilkie Date: Wed, 29 Jul 2015 10:13:02 +0000 Subject: [PATCH 4/4] Reduce the amount of parallelism in the ipam tests --- ipam/allocator_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ipam/allocator_test.go b/ipam/allocator_test.go index 10e2d245..fd444190 100644 --- a/ipam/allocator_test.go +++ b/ipam/allocator_test.go @@ -314,9 +314,9 @@ func TestAllocatorFuzz(t *testing.T) { const ( firstpass = 1000 secondpass = 10000 - nodes = 10 + nodes = 5 maxAddresses = 1000 - concurrency = 30 + concurrency = 5 cidr = "10.0.1.7/22" ) allocs, _, subnet := makeNetworkOfAllocators(nodes, cidr)