Skip to content

Instantly share code, notes, and snippets.

@nlsun
Last active February 23, 2017 01:59
Show Gist options
  • Save nlsun/e844b41e0c48239b92fbfb6e20565888 to your computer and use it in GitHub Desktop.
Save nlsun/e844b41e0c48239b92fbfb6e20565888 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -euo pipefail
### public api
setup() {
echo "$SSH_USER" > /dev/null
echo "$SSH_ADDRESS" > /dev/null
publics="$(detect_public $SSH_USER $SSH_ADDRESS)"
privates="$(detect_private $SSH_USER $SSH_ADDRESS)"
set +e
read -r -d '' PROFILE_VAR <<EOF
source /opt/mesosphere/packages/dcos-integration-test--*/util/test_env.export
#dcos_add_user.py [email protected] || echo no dcos_add_user.py
export DCOS_LOGIN_PW=deleteme
export DCOS_LOGIN_UNAME=bootstrapuser
set -o vi
SLAVE_HOSTS=$privates
PUBLIC_SLAVE_HOSTS=$publics
EOF
set -e
ssh -o "LogLevel QUIET" \
-o "StrictHostKeyChecking no" \
-o "UserKnownHostsFile /dev/null" \
-A \
"$SSH_USER@$SSH_ADDRESS" \
"echo \"$PROFILE_VAR\" >> ~/.profile"
}
# For example: test_networking.py::test_vip
# For example: test_service_discovery.py
run_test() {
echo "$SSH_USER" > /dev/null
echo "$SSH_ADDRESS" > /dev/null
teststr="$1"
ssh -o "LogLevel QUIET" \
-o "StrictHostKeyChecking no" \
-o "UserKnownHostsFile /dev/null" \
-A -t \
"$SSH_USER@$SSH_ADDRESS" \
"source ~/.profile && cd /opt/mesosphere/active/dcos-integration-test && py.test -s -vv $teststr"
}
push_file() {
echo "$SSH_USER" > /dev/null
echo "$SSH_ADDRESS" > /dev/null
localfile="$1"
remotefile="$2"
scp -o "LogLevel QUIET" \
-o "StrictHostKeyChecking no" \
-o "UserKnownHostsFile /dev/null" \
"$localfile" \
"$SSH_USER@$SSH_ADDRESS:~/tmpfile"
ssh -o "LogLevel QUIET" \
-o "StrictHostKeyChecking no" \
-o "UserKnownHostsFile /dev/null" \
-A \
"$SSH_USER@$SSH_ADDRESS" \
"sudo mv ~/tmpfile /opt/mesosphere/active/dcos-integration-test/$remotefile"
}
### private api
detect_public() {
user=$1
addr=$2
ssh -o "LogLevel QUIET" \
-o "StrictHostKeyChecking no" \
-o "UserKnownHostsFile /dev/null" \
-A \
"$user@$addr" \
"for h in \$(host slave.mesos | cut -d' ' -f4); do curl -s \$h:5051/state | grep '\"default_role\":\"slave_public\"' >/dev/null && printf \",\$h\"; done | cut -d',' -f2-"
}
detect_private() {
user=$1
addr=$2
ssh -o "LogLevel QUIET" \
-o "StrictHostKeyChecking no" \
-o "UserKnownHostsFile /dev/null" \
-A \
"$user@$addr" \
"for h in \$(host slave.mesos | cut -d' ' -f4); do curl -s \$h:5051/state | grep '\"default_role\":\"slave_public\"' >/dev/null || printf \",\$h\"; done | cut -d',' -f2-"
}
### main
"$1" "${@:2}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment