Cheat Sheets

Network Split Test Scripts

Script Usage

./network_split.sh <filter1> <filter2> <hosts>
./network_join.sh <filter1> <filter2> <hosts>
The script expects SSH equivalency and sudo on the target hosts. The filters are grep patterns.

network_split.sh

#!/bin/bash

group1_filter=$1; shift
group2_filter=$1; shift
hosts=$*

hosts1=$(echo $hosts | xargs -n1 | grep "$group1_filter")
hosts2=$(echo $hosts | xargs -n1 | grep "$group2_filter")

if [ "$hosts1" == "" -o "$hosts2" == "" ]; then
	echo "ERROR: Syntax: $0   "
	exit 1
fi

for h in $hosts1; do
	echo "backlisting other zone on $h"
	for i in $hosts2; do
		ssh $h sudo route add $i gw 127.0.0.1 lo
	done
done
for h in $hosts2; do
	echo "Backlisting other zone on $h"
	for i in $hosts1; do
		ssh $h sudo route add $i gw 127.0.0.1 lo
	done
done

network_join.sh

#!/bin/bash

group1_filter=$1; shift
group2_filter=$1; shift
hosts=$*

hosts1=$(echo $hosts | xargs -n1 | grep "$group1_filter")
hosts2=$(echo $hosts | xargs -n1 | grep "$group2_filter")

if [ "$hosts1" == "" -o "$hosts2" == "" ]; then
	echo "ERROR: Syntax: $0   "
	exit 1
fi

for h in $hosts1; do
	echo "De-blacklisting other zone on $h"
	for i in $hosts2; do
		ssh $h sudo route del $i gw 127.0.0.1 lo
	done
done
for h in $hosts2; do
	echo "De-blacklisting other zone on $h"
	for i in $hosts1; do
		ssh $h sudo route del $i gw 127.0.0.1 lo
	done
done

Comment on Disqus