Add push bits scripts for Atomix uploads to test cells

Change-Id: I2b6f2fbd19558f08e549b366ae2ecfdbb9227efd
diff --git a/tools/test/bin/atomix-install b/tools/test/bin/atomix-install
index af210ae..a076d00 100755
--- a/tools/test/bin/atomix-install
+++ b/tools/test/bin/atomix-install
@@ -47,8 +47,7 @@
     [ -f $ATOMIX_INSTALL_DIR/bin/atomix-agent ] && echo \"Atomix is already installed\" && exit 1
 
     sudo mkdir -p $ATOMIX_INSTALL_DIR && sudo chown ${ONOS_USER}:${ONOS_GROUP} $ATOMIX_INSTALL_DIR
-    sudo wget -O $ATOMIX_INSTALL_DIR/atomix-dist.tar.gz https://oss.sonatype.org/content/repositories/releases/io/atomix/atomix-dist/3.0.7/atomix-dist-3.0.7.tar.gz
-    tar -xvf $ATOMIX_INSTALL_DIR/atomix-dist.tar.gz -C $ATOMIX_INSTALL_DIR
+    tar -xvf /tmp/atomix.tar.gz -C $ATOMIX_INSTALL_DIR
 "
 
 # Configure the ONOS installation
diff --git a/tools/test/bin/atomix-push-bits b/tools/test/bin/atomix-push-bits
new file mode 100755
index 0000000..6b5d68b
--- /dev/null
+++ b/tools/test/bin/atomix-push-bits
@@ -0,0 +1,64 @@
+#!/bin/bash
+# -----------------------------------------------------------------------------
+# Remotely pushes bits to a remote node in preparation for install.
+# -----------------------------------------------------------------------------
+function _usage () {
+cat << _EOF_
+usage:
+ $(basename $0) [node]
+
+options:
+- [node] : the target node to prime for installation
+
+summary:
+ Remotely pushes Atomix bits to a remote node in preparation for install.
+
+ $(basename $0) is invoked as part of 'atomix-install', and shouldn't be
+ directly invoked for the most part.
+
+_EOF_
+}
+
+[ $# -gt 1 ] || [ "$1" = "-h" ] && _usage && exit 0
+[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT isn't set correctly" >&2 && exit 1
+
+set -e
+
+. $ONOS_ROOT/tools/build/envDefaults
+
+ATOMIX_VERSION=${ATOMIX_VERSION:-3.0.7}
+ATOMIX_MAVEN=~/.m2/repository/io/atomix/atomix-dist/$ATOMIX_VERSION/atomix-dist-$ATOMIX_VERSION.tar.gz
+ATOMIX_LOCAL=/tmp/atomix-$ATOMIX_VERSION.tar.gz
+ATOMIX_REMOTE=https://oss.sonatype.org/content/repositories/releases/io/atomix/atomix-dist/$ATOMIX_VERSION/atomix-dist-$ATOMIX_VERSION.tar.gz
+
+node=${1:-$OCI}
+remote=$ONOS_USER@$node
+remote_with_bracket=$ONOS_USER@[$node]
+SSH_OPTIONS=" -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
+ -o ControlMaster=auto -o ControlPath=~/.ssh/mux-%r@%h:%p \
+ -o ControlPersist=300 "
+
+if [ ! -z "$ATOMIX_ROOT" ]; then
+  echo "Pushing to $node from $ATOMIX_ROOT"
+  ATOMIX_TAR=$ATOMIX_ROOT/dist/target/atomix.tar.gz
+elif [ -e $ATOMIX_MAVEN ]; then
+  echo "Pushing to $node from $ATOMIX_MAVEN"
+  ATOMIX_TAR=$ATOMIX_MAVEN
+else
+  echo "Pushing to $node from $ATOMIX_LOCAL"
+  rm $ATOMIX_LOCAL
+  wget -O $ATOMIX_LOCAL $ATOMIX_REMOTE
+  ATOMIX_TAR=$ATOMIX_LOCAL
+fi
+
+echo "Using scp"
+
+locHash=$(cksum $ATOMIX_TAR | cut -d' ' -f1,2)
+remHash=$(ssh $remote cksum /tmp/atomix.tar.gz 2>/dev/null | cut -d' ' -f1,2)
+
+if [ -n "$locHash" ] && [ "$locHash" = "$remHash" ]; then
+  echo "Atomix bits /tmp/atomix.tar.gz already up-to-date on $node..."
+else
+  ssh $remote rm -f $ATOMIX_TAR
+  scp -q $ATOMIX_TAR $remote_with_bracket:/tmp/atomix.tar.gz
+fi
diff --git a/tools/test/bin/atomix-push-bits-through-proxy b/tools/test/bin/atomix-push-bits-through-proxy
new file mode 100755
index 0000000..24e2174
--- /dev/null
+++ b/tools/test/bin/atomix-push-bits-through-proxy
@@ -0,0 +1,27 @@
+#!/bin/bash
+# -----------------------------------------------------------------------------
+# Remotely pushes Atomix bits to all remote nodes in preparation for install.
+# -----------------------------------------------------------------------------
+
+[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
+. $ONOS_ROOT/tools/build/envDefaults
+
+OCT=${OCT:-$OCI}
+node=${1:-$OCT}
+remote=$ONOS_USER@$node
+shift
+
+echo "Pushing to proxy $node..."
+atomix-push-bits $node
+
+others=$(env | sort | egrep "^OCC[0-9]+" | cut -d= -f2 | grep -vE "^$OCT\$")
+
+ssh $remote "
+  for other in ${others//$'\n'/ } ; do
+    echo \"Pushing to \$other ...\";
+    ssh -o StrictHostKeyChecking=no $ONOS_USER@\$other rm -rf /tmp/atomix.tar.gz &&
+    scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
+        /tmp/atomix.tar.gz \
+        $ONOS_USER@[\$other]:/tmp/atomix.tar.gz
+  done
+"