Skip to content

Commit

Permalink
Use hostnames in integration tests
Browse files Browse the repository at this point in the history
This PR updates refactors integration tests to use host names instead of
IP addresses. It resolves pingcap#337.

All IP literals in the integration tests are replaced with host names
`n1` to `n5`.

This allows us to make integration test topology files immutable and
remove extra topology file templating step.

Extra topology file `full_scale_in_tidb_2nd.yaml` is introduced for
second tidb scaling operation to avoid topology file mutation during the
test.

Using host names in the integration tests will help us to maintain
compatibility with services declared using host names. There should be
no extra maintenance to support using IP addresses.
  • Loading branch information
fln committed Nov 30, 2020
1 parent 37660db commit 3a55657
Show file tree
Hide file tree
Showing 26 changed files with 131 additions and 148 deletions.
18 changes: 8 additions & 10 deletions tests/tiup-cluster/script/cmd_subtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ function cmd_subtest() {
version=$1
test_tls=$2
native_ssh=$3
ipprefix=${TIUP_TEST_IP_PREFIX:-"$ipprefix"}

name="test_cmd_$RANDOM"
if [ $test_tls = true ]; then
topo=./topo/full_tls.yaml
else
topo=./topo/full.yaml
fi
sed "s/__IPPREFIX__/$ipprefix/g" $topo.tpl > $topo

client=""
if [ $native_ssh == true ]; then
Expand All @@ -41,9 +39,9 @@ function cmd_subtest() {
tiup-cluster $client --yes deploy $name $version $topo -i ~/.ssh/id_rsa --skip-create-user

# check the local config
tiup-cluster $client exec $name -N $ipprefix.101 --command "grep magic-string-for-test /home/tidb/deploy/prometheus-9090/conf/tidb.rules.yml"
tiup-cluster $client exec $name -N $ipprefix.101 --command "grep magic-string-for-test /home/tidb/deploy/grafana-3000/dashboards/tidb.json"
tiup-cluster $client exec $name -N $ipprefix.101 --command "grep magic-string-for-test /home/tidb/deploy/alertmanager-9093/conf/alertmanager.yml"
tiup-cluster $client exec $name -N n1 --command "grep magic-string-for-test /home/tidb/deploy/prometheus-9090/conf/tidb.rules.yml"
tiup-cluster $client exec $name -N n1 --command "grep magic-string-for-test /home/tidb/deploy/grafana-3000/dashboards/tidb.json"
tiup-cluster $client exec $name -N n1 --command "grep magic-string-for-test /home/tidb/deploy/alertmanager-9093/conf/alertmanager.yml"

tiup-cluster $client list | grep "$name"

Expand All @@ -59,8 +57,8 @@ function cmd_subtest() {

# check the data dir of tikv
# it's ok to omit client type after deploy
tiup-cluster exec $name -N $ipprefix.101 --command "grep /home/tidb/deploy/tikv-20160/data /home/tidb/deploy/tikv-20160/scripts/run_tikv.sh"
tiup-cluster exec $name -N $ipprefix.103 --command "grep /home/tidb/my_kv_data /home/tidb/deploy/tikv-20160/scripts/run_tikv.sh"
tiup-cluster exec $name -N n1 --command "grep /home/tidb/deploy/tikv-20160/data /home/tidb/deploy/tikv-20160/scripts/run_tikv.sh"
tiup-cluster exec $name -N n3 --command "grep /home/tidb/my_kv_data /home/tidb/deploy/tikv-20160/scripts/run_tikv.sh"

# test patch overwrite
tiup-cluster $client --yes patch $name ~/.tiup/storage/cluster/packages/tidb-$version-linux-amd64.tar.gz -R tidb --overwrite
Expand Down Expand Up @@ -94,11 +92,11 @@ function cmd_subtest() {
tiup-cluster $client exec $name -R tidb --command="systemctl status tidb-4000|grep 'enabled;'"
tiup-cluster $client exec $name -R pd --command="systemctl status pd-2379|grep 'enabled;'"

tiup-cluster $client --yes clean $name --data --all --ignore-node $ipprefix.101:9090
tiup-cluster $client --yes clean $name --data --all --ignore-node n1:9090

echo "checking cleanup data and log"
tiup-cluster $client exec $name -N $ipprefix.101 --command "ls /home/tidb/deploy/prometheus-9090/log/prometheus.log"
! tiup-cluster $client exec $name -N $ipprefix.101 --command "ls /home/tidb/deploy/tikv-20160/log/tikv.log"
tiup-cluster $client exec $name -N n1 --command "ls /home/tidb/deploy/prometheus-9090/log/prometheus.log"
! tiup-cluster $client exec $name -N n1 --command "ls /home/tidb/deploy/tikv-20160/log/tikv.log"

tiup-cluster $client --yes start $name

Expand Down
34 changes: 14 additions & 20 deletions tests/tiup-cluster/script/scale_core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ function scale_core() {
version=$1
test_tls=$2
native_ssh=$3
ipprefix=${TIUP_TEST_IP_PREFIX:-"172.19.0"}

client=""
if [ $native_ssh == true ]; then
Expand All @@ -19,7 +18,6 @@ function scale_core() {
else
topo=./topo/full.yaml
fi
sed "s/__IPPREFIX__/$ipprefix/g" $topo.tpl > $topo

tiup-cluster $client --yes deploy $name $version $topo -i ~/.ssh/id_rsa

Expand All @@ -40,53 +38,49 @@ function scale_core() {
fi

echo "start scale in tidb"
tiup-cluster $client --yes scale-in $name -N $ipprefix.101:4000
tiup-cluster $client --yes scale-in $name -N n1:4000
wait_instance_num_reach $name $total_sub_one $native_ssh
echo "start scale out tidb"
topo=./topo/full_scale_in_tidb.yaml
sed "s/__IPPREFIX__/$ipprefix/g" $topo.tpl > $topo
tiup-cluster $client --yes scale-out $name $topo
# after scale-out, ensure the service is enabled
tiup-cluster $client exec $name -N $ipprefix.101 --command "systemctl status tidb-4000 | grep Loaded |grep 'enabled; vendor'"
tiup-cluster $client exec $name -N n1 --command "systemctl status tidb-4000 | grep Loaded |grep 'enabled; vendor'"

# echo "start scale in tikv"
# tiup-cluster --yes scale-in $name -N $ipprefix.103:20160
# tiup-cluster --yes scale-in $name -N n3:20160
# wait_instance_num_reach $name $total_sub_one $native_ssh
# echo "start scale out tikv"
# topo=./topo/full_scale_in_tikv.yaml
# sed "s/__IPPREFIX__/$ipprefix/g" $topo.tpl > $topo
# tiup-cluster --yes scale-out $name $topo

echo "start scale in pd"
tiup-cluster $client --yes scale-in $name -N $ipprefix.103:2379
tiup-cluster $client --yes scale-in $name -N n3:2379
wait_instance_num_reach $name $total_sub_one $native_ssh

# validate https://github.com/pingcap/tiup/issues/786
# ensure that this instance is removed from the startup scripts of other components that need to rely on PD
! tiup-cluster $client exec $name -N $ipprefix.101 --command "grep -q $ipprefix.103:2379 /home/tidb/deploy/tidb-4000/scripts/run_tidb.sh"
! tiup-cluster $client exec $name -N n1 --command "grep -q n3:2379 /home/tidb/deploy/tidb-4000/scripts/run_tidb.sh"

echo "start scale out pd"
topo=./topo/full_scale_in_pd.yaml
sed "s/__IPPREFIX__/$ipprefix/g" $topo.tpl > $topo
tiup-cluster $client --yes scale-out $name $topo
# after scale-out, ensure this instance come back
tiup-cluster $client exec $name -N $ipprefix.101 --command "grep -q $ipprefix.103:2379 /home/tidb/deploy/tidb-4000/scripts/run_tidb.sh"
tiup-cluster $client exec $name -N n1 --command "grep -q n3:2379 /home/tidb/deploy/tidb-4000/scripts/run_tidb.sh"

echo "start scale in tidb"
tiup-cluster $client --yes scale-in $name -N $ipprefix.102:4000
tiup-cluster $client --yes scale-in $name -N n2:4000
wait_instance_num_reach $name $total_sub_one $native_ssh
! tiup-cluster $client exec $name -N $ipprefix.102 --command "ls /home/tidb/deploy/monitor-9100/deploy/monitor-9100"
! tiup-cluster $client exec $name -N $ipprefix.102 --command "ps aux | grep node_exporter | grep -qv grep"
! tiup-cluster $client exec $name -N $ipprefix.102 --command "ps aux | grep blackbox_exporter | grep -qv grep"
! tiup-cluster $client exec $name -N n2 --command "ls /home/tidb/deploy/monitor-9100/deploy/monitor-9100"
! tiup-cluster $client exec $name -N n2 --command "ps aux | grep node_exporter | grep -qv grep"
! tiup-cluster $client exec $name -N n2 --command "ps aux | grep blackbox_exporter | grep -qv grep"

echo "start scale out tidb"
topo=./topo/full_scale_in_tidb.yaml
sed "s/__IPPREFIX__.101/$ipprefix.102/g" $topo.tpl > $topo
topo=./topo/full_scale_in_tidb_2nd.yaml
tiup-cluster $client --yes scale-out $name $topo
# after scalue-out, ensure node_exporter and blackbox_exporter come back
tiup-cluster $client exec $name -N $ipprefix.102 --command "ls /home/tidb/deploy/monitor-9100/deploy/monitor-9100"
tiup-cluster $client exec $name -N $ipprefix.102 --command "ps aux | grep node_exporter | grep -qv grep"
tiup-cluster $client exec $name -N $ipprefix.102 --command "ps aux | grep blackbox_exporter | grep -qv grep"
tiup-cluster $client exec $name -N n2 --command "ls /home/tidb/deploy/monitor-9100/deploy/monitor-9100"
tiup-cluster $client exec $name -N n2 --command "ps aux | grep node_exporter | grep -qv grep"
tiup-cluster $client exec $name -N n2 --command "ps aux | grep blackbox_exporter | grep -qv grep"

tiup-cluster $client _test $name writable
}
33 changes: 13 additions & 20 deletions tests/tiup-cluster/script/scale_tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ function scale_tools() {
version=$1
test_tls=$2
native_ssh=$3
ipprefix=${TIUP_TEST_IP_PREFIX:-"172.19.0"}

client=""
if [ $native_ssh == true ]; then
Expand All @@ -19,14 +18,13 @@ function scale_tools() {
else
topo=./topo/full.yaml
fi
sed "s/__IPPREFIX__/$ipprefix/g" $topo.tpl > $topo

tiup-cluster $client --yes deploy $name $version $topo -i ~/.ssh/id_rsa

# check the local config
tiup-cluster $client exec $name -N $ipprefix.101 --command "grep magic-string-for-test /home/tidb/deploy/prometheus-9090/conf/tidb.rules.yml"
tiup-cluster $client exec $name -N $ipprefix.101 --command "grep magic-string-for-test /home/tidb/deploy/grafana-3000/dashboards/tidb.json"
tiup-cluster $client exec $name -N $ipprefix.101 --command "grep magic-string-for-test /home/tidb/deploy/alertmanager-9093/conf/alertmanager.yml"
tiup-cluster $client exec $name -N n1 --command "grep magic-string-for-test /home/tidb/deploy/prometheus-9090/conf/tidb.rules.yml"
tiup-cluster $client exec $name -N n1 --command "grep magic-string-for-test /home/tidb/deploy/grafana-3000/dashboards/tidb.json"
tiup-cluster $client exec $name -N n1 --command "grep magic-string-for-test /home/tidb/deploy/alertmanager-9093/conf/alertmanager.yml"

tiup-cluster $client list | grep "$name"

Expand All @@ -43,59 +41,54 @@ function scale_tools() {
fi

echo "start scale in pump"
tiup-cluster $client --yes scale-in $name -N $ipprefix.103:8250
tiup-cluster $client --yes scale-in $name -N n3:8250
wait_instance_num_reach $name $total_sub_one $native_ssh
echo "start scale out pump"
topo=./topo/full_scale_in_pump.yaml
sed "s/__IPPREFIX__/$ipprefix/g" $topo.tpl > $topo
tiup-cluster $client --yes scale-out $name $topo

echo "start scale in cdc"
yes | tiup-cluster $client scale-in $name -N $ipprefix.103:8300
yes | tiup-cluster $client scale-in $name -N n3:8300
wait_instance_num_reach $name $total_sub_one $native_ssh
echo "start scale out cdc"
topo=./topo/full_scale_in_cdc.yaml
sed "s/__IPPREFIX__/$ipprefix/g" $topo.tpl > $topo
yes | tiup-cluster $client scale-out $name $topo

if [ $test_tls = false ]; then
echo "start scale in tispark"
yes | tiup-cluster $client --yes scale-in $name -N $ipprefix.104:7078
yes | tiup-cluster $client --yes scale-in $name -N n4:7078
wait_instance_num_reach $name $total_sub_one $native_ssh
echo "start scale out tispark"
topo=./topo/full_scale_in_tispark.yaml
sed "s/__IPPREFIX__/$ipprefix/g" $topo.tpl > $topo
yes | tiup-cluster $client --yes scale-out $name $topo
fi

echo "start scale in grafana"
tiup-cluster $client --yes scale-in $name -N $ipprefix.101:3000
tiup-cluster $client --yes scale-in $name -N n1:3000
wait_instance_num_reach $name $total_sub_one $native_ssh
echo "start scale out grafana"
topo=./topo/full_scale_in_grafana.yaml
sed "s/__IPPREFIX__/$ipprefix/g" $topo.tpl > $topo
tiup-cluster $client --yes scale-out $name $topo

# make sure grafana dashboards has been set to default (since the full_sale_in_grafana.yaml didn't provide a local dashboards dir)
! tiup-cluster $client exec $name -N $ipprefix.101 --command "grep magic-string-for-test /home/tidb/deploy/grafana-3000/dashboards/tidb.json"
! tiup-cluster $client exec $name -N n1 --command "grep magic-string-for-test /home/tidb/deploy/grafana-3000/dashboards/tidb.json"

# currently tiflash is not supported in TLS enabled cluster
# and only Tiflash support data-dir in multipath
if [ $test_tls = false ]; then
# ensure tiflash's data dir exists
tiup-cluster $client exec $name -N $ipprefix.103 --command "ls /home/tidb/deploy/tiflash-9000/data1"
tiup-cluster $client exec $name -N $ipprefix.103 --command "ls /data/tiflash-data"
tiup-cluster $client exec $name -N n3 --command "ls /home/tidb/deploy/tiflash-9000/data1"
tiup-cluster $client exec $name -N n3 --command "ls /data/tiflash-data"
echo "start scale in tiflash"
tiup-cluster $client --yes scale-in $name -N $ipprefix.103:9000
tiup-cluster $client --yes scale-in $name -N n3:9000
tiup-cluster $client display $name | grep Tombstone
echo "start prune tiflash"
yes | tiup-cluster $client prune $name
wait_instance_num_reach $name $total_sub_one $native_ssh
! tiup-cluster $client exec $name -N $ipprefix.103 --command "ls /home/tidb/deploy/tiflash-9000/data1"
! tiup-cluster $client exec $name -N $ipprefix.103 --command "ls /data/tiflash-data"
! tiup-cluster $client exec $name -N n3 --command "ls /home/tidb/deploy/tiflash-9000/data1"
! tiup-cluster $client exec $name -N n3 --command "ls /data/tiflash-data"
echo "start scale out tiflash"
topo=./topo/full_scale_in_tiflash.yaml
sed "s/__IPPREFIX__/$ipprefix/g" $topo.tpl > $topo
tiup-cluster $client --yes scale-out $name $topo
fi

Expand Down
2 changes: 0 additions & 2 deletions tests/tiup-cluster/test_upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ version=${version-v4.0.4}
old_version=${old_version-v3.0.16}
name=test_upgrade
topo=./topo/upgrade.yaml
ipprefix=${TIUP_TEST_IP_PREFIX:-"172.19.0"}
sed "s/__IPPREFIX__/$ipprefix/g" $topo.tpl > $topo

mkdir -p ~/.tiup/bin && cp -f ./root.json ~/.tiup/bin/

Expand Down
2 changes: 0 additions & 2 deletions tests/tiup-cluster/test_upgrade_tls.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ version=${version-v4.0.4}
old_version=${old_version-v3.0.16}
name=test_upgrade_tls
topo=./topo/upgrade_tls.yaml
ipprefix=${TIUP_TEST_IP_PREFIX:-"172.19.0"}
sed "s/__IPPREFIX__/$ipprefix/g" $topo.tpl > $topo

mkdir -p ~/.tiup/bin && cp -f ./root.json ~/.tiup/bin/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,60 +12,60 @@ server_configs:
storage.stop-write-at-available-space: 1 mib

tidb_servers:
- host: __IPPREFIX__.101
- host: __IPPREFIX__.102
- host: n1
- host: n2

pd_servers:
- host: __IPPREFIX__.103
- host: __IPPREFIX__.104
- host: __IPPREFIX__.105
- host: n3
- host: n4
- host: n5

# Note if only 3 instance, when scale-in one of it.
# It may not be tombstone.
tikv_servers:
- host: __IPPREFIX__.101
- host: __IPPREFIX__.103
- host: n1
- host: n3
data_dir: "/home/tidb/my_kv_data"
- host: __IPPREFIX__.104
- host: __IPPREFIX__.105
- host: n4
- host: n5

# tiflash eat too much memory
# and binary is more than 1G..
tiflash_servers:
- host: __IPPREFIX__.103
- host: n3
data_dir: "data1,/data/tiflash-data"
# - host: __IPPREFIX__.104
# - host: __IPPREFIX__.105
# - host: n4
# - host: n5

pump_servers:
- host: __IPPREFIX__.103
- host: __IPPREFIX__.104
- host: __IPPREFIX__.105
- host: n3
- host: n4
- host: n5

drainer_servers:
- host: __IPPREFIX__.101
- host: n1
data_dir: /home/tidb/data/drainer-8249/data
commit_ts: -1
config:
syncer.db-type: "file"

cdc_servers:
- host: __IPPREFIX__.103
- host: __IPPREFIX__.104
- host: __IPPREFIX__.105
- host: n3
- host: n4
- host: n5

tispark_masters:
- host: __IPPREFIX__.103
- host: n3

tispark_workers:
- host: __IPPREFIX__.104
- host: n4

monitoring_servers:
- host: __IPPREFIX__.101
- host: n1
rule_dir: /tmp/local/prometheus
grafana_servers:
- host: __IPPREFIX__.101
- host: n1
dashboard_dir: /tmp/local/grafana
alertmanager_servers:
- host: __IPPREFIX__.101
- host: n1
config_file: /tmp/local/alertmanager/alertmanager.yml
2 changes: 2 additions & 0 deletions tests/tiup-cluster/topo/full_scale_in_cdc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cdc_servers:
- host: n3
2 changes: 0 additions & 2 deletions tests/tiup-cluster/topo/full_scale_in_cdc.yaml.tpl

This file was deleted.

2 changes: 2 additions & 0 deletions tests/tiup-cluster/topo/full_scale_in_grafana.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
grafana_servers:
- host: n1
2 changes: 0 additions & 2 deletions tests/tiup-cluster/topo/full_scale_in_grafana.yaml.tpl

This file was deleted.

2 changes: 2 additions & 0 deletions tests/tiup-cluster/topo/full_scale_in_pd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pd_servers:
- host: n3
2 changes: 0 additions & 2 deletions tests/tiup-cluster/topo/full_scale_in_pd.yaml.tpl

This file was deleted.

2 changes: 2 additions & 0 deletions tests/tiup-cluster/topo/full_scale_in_pump.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pump_servers:
- host: n3
2 changes: 0 additions & 2 deletions tests/tiup-cluster/topo/full_scale_in_pump.yaml.tpl

This file was deleted.

2 changes: 2 additions & 0 deletions tests/tiup-cluster/topo/full_scale_in_tidb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tidb_servers:
- host: n1
2 changes: 0 additions & 2 deletions tests/tiup-cluster/topo/full_scale_in_tidb.yaml.tpl

This file was deleted.

2 changes: 2 additions & 0 deletions tests/tiup-cluster/topo/full_scale_in_tidb_2nd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tidb_servers:
- host: n2
2 changes: 2 additions & 0 deletions tests/tiup-cluster/topo/full_scale_in_tiflash.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tiflash_servers:
- host: n3
2 changes: 0 additions & 2 deletions tests/tiup-cluster/topo/full_scale_in_tiflash.yaml.tpl

This file was deleted.

2 changes: 2 additions & 0 deletions tests/tiup-cluster/topo/full_scale_in_tikv.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tikv_servers:
- host: n3
2 changes: 0 additions & 2 deletions tests/tiup-cluster/topo/full_scale_in_tikv.yaml.tpl

This file was deleted.

2 changes: 2 additions & 0 deletions tests/tiup-cluster/topo/full_scale_in_tispark.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tispark_workers:
- host: n5
2 changes: 0 additions & 2 deletions tests/tiup-cluster/topo/full_scale_in_tispark.yaml.tpl

This file was deleted.

Loading

0 comments on commit 3a55657

Please sign in to comment.