Skip to content

Commit d9b1fe1

Browse files
authored
Merge pull request #668 from github/add-node-version-check
Add node version check and fail out if they don't match
2 parents 277cdf2 + 25e4453 commit d9b1fe1

File tree

3 files changed

+91
-36
lines changed

3 files changed

+91
-36
lines changed

bin/ghe-host-check

Lines changed: 51 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,48 @@ set -e
1515

1616
while true; do
1717
case "$1" in
18-
-h|--help)
19-
export GHE_SHOW_HELP=true
20-
shift
21-
;;
22-
--version)
23-
export GHE_SHOW_VERSION=true
24-
shift
25-
;;
26-
-*)
27-
echo "Error: invalid argument: '$1'" 1>&2
28-
exit 1
29-
;;
30-
*)
31-
break
32-
;;
18+
-h | --help)
19+
export GHE_SHOW_HELP=true
20+
shift
21+
;;
22+
--version)
23+
export GHE_SHOW_VERSION=true
24+
shift
25+
;;
26+
-*)
27+
echo "Error: invalid argument: '$1'" 1>&2
28+
exit 1
29+
;;
30+
*)
31+
break
32+
;;
3333
esac
3434
done
3535

3636
# Bring in the backup configuration
3737
# shellcheck source=share/github-backup-utils/ghe-backup-config
38-
. "$( dirname "${BASH_SOURCE[0]}" )/../share/github-backup-utils/ghe-backup-config"
38+
. "$(dirname "${BASH_SOURCE[0]}")/../share/github-backup-utils/ghe-backup-config"
3939

4040
# Use the host provided on the command line if provided, or fallback on the
4141
# $GHE_HOSTNAME configured in backup.config when not present.
4242
host="${1:-$GHE_HOSTNAME}"
4343

44+
CLUSTER=false
45+
if ghe-ssh "$host" -- \
46+
"[ -f '$GHE_REMOTE_ROOT_DIR/etc/github/cluster' ]"; then
47+
CLUSTER=true
48+
fi
49+
50+
if "$CLUSTER"; then
51+
node_version_list=$(ghe-ssh "$host" ghe-cluster-each -- ghe-version)
52+
echo "$node_version_list" 1>&2
53+
distinct_versions=$(echo "$node_version_list" | awk '{split($0, a, ":"); print a[2]}' | uniq | wc -l)
54+
if [ "$distinct_versions" -ne 1 ]; then
55+
echo "Error: Not all nodes are running the same version! Please ensure all nodes are running the same version before using backup-utils." 1>&2
56+
exit 1
57+
fi
58+
fi
59+
4460
# Options to pass to SSH during connection check
4561
options="
4662
-o PasswordAuthentication=no
@@ -59,26 +75,26 @@ set -e
5975

6076
if [ $rc -ne 0 ]; then
6177
case $rc in
62-
255)
63-
if echo "$output" | grep -i "port 22: Network is unreachable\|port 22: connection refused\|port 22: no route to host\|ssh_exchange_identification: Connection closed by remote host\|Connection timed out during banner exchange\|port 22: Connection timed out" >/dev/null; then
64-
exec "$(basename $0)" "$hostname:122"
65-
fi
66-
78+
255)
79+
if echo "$output" | grep -i "port 22: Network is unreachable\|port 22: connection refused\|port 22: no route to host\|ssh_exchange_identification: Connection closed by remote host\|Connection timed out during banner exchange\|port 22: Connection timed out" >/dev/null; then
80+
exec "$(basename $0)" "$hostname:122"
81+
fi
82+
83+
echo "$output" 1>&2
84+
echo "Error: ssh connection with '$host' failed" 1>&2
85+
echo "Note that your SSH key needs to be setup on $host as described in:" 1>&2
86+
echo "* https://enterprise.github.com/help/articles/adding-an-ssh-key-for-shell-access" 1>&2
87+
;;
88+
101)
89+
echo "Error: couldn't read GitHub Enterprise Server fingerprint on '$host' or this isn't a GitHub appliance." 1>&2
90+
;;
91+
1)
92+
if [ "${port:-22}" -eq 22 ] && echo "$output" | grep "use port 122" >/dev/null; then
93+
exec "$(basename $0)" "$hostname:122"
94+
else
6795
echo "$output" 1>&2
68-
echo "Error: ssh connection with '$host' failed" 1>&2
69-
echo "Note that your SSH key needs to be setup on $host as described in:" 1>&2
70-
echo "* https://enterprise.github.com/help/articles/adding-an-ssh-key-for-shell-access" 1>&2
71-
;;
72-
101)
73-
echo "Error: couldn't read GitHub Enterprise Server fingerprint on '$host' or this isn't a GitHub appliance." 1>&2
74-
;;
75-
1)
76-
if [ "${port:-22}" -eq 22 ] && echo "$output" | grep "use port 122" >/dev/null; then
77-
exec "$(basename $0)" "$hostname:122"
78-
else
79-
echo "$output" 1>&2
80-
fi
81-
;;
96+
fi
97+
;;
8298

8399
esac
84100
exit $rc

test/bin/ghe-cluster-each

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ for _ in "$@"; do
1919
esac
2020
done
2121

22+
if [ "$2" == "ghe-version" ]; then
23+
if [ -z "$DIFFERENT_VERSIONS" ]; then
24+
echo "fake-uuid: GitHub Enterprise Server 3.1.0 lxc 2020-12-16 5e97c07602"
25+
echo "fake-uuid1: GitHub Enterprise Server 3.1.0 lxc 2020-12-16 5e97c07602"
26+
echo "fake-uuid2: GitHub Enterprise Server 3.1.0 lxc 2020-12-16 5e97c07602"
27+
else
28+
echo "fake-uuid: GitHub Enterprise Server 3.1.0 lxc 2020-12-16 5e97c07602"
29+
echo "fake-uuid1: GitHub Enterprise Server 3.1.0 lxc 2020-12-16 5e97c07602"
30+
echo "fake-uuid2: GitHub Enterprise Server 2.19 lxc 2020-12-13 5e97c07622"
31+
fi
32+
exit 0
33+
fi
34+
2235
if $SHOW_UUID; then
2336
CONFIG="$GHE_REMOTE_DATA_USER_DIR/common/cluster.conf"
2437

test/test-ghe-restore.sh

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ setup_test_data "$GHE_DATA_DIR/1"
535535
# Make the current symlink
536536
ln -s 1 "$GHE_DATA_DIR/current"
537537

538-
begin_test "ghe-restore cluster"
538+
begin_test "ghe-restore cluster with matching node versions"
539539
(
540540
set -e
541541
rm -rf "$GHE_REMOTE_ROOT_DIR"
@@ -598,6 +598,32 @@ begin_test "ghe-restore cluster"
598598
)
599599
end_test
600600

601+
begin_test "ghe-restore cluster with different node versions should fail at ghe-host-check"
602+
(
603+
set -e
604+
rm -rf "$GHE_REMOTE_ROOT_DIR"
605+
setup_moreutils_parallel
606+
setup_remote_metadata
607+
setup_remote_cluster
608+
echo "cluster" > "$GHE_DATA_DIR/current/strategy"
609+
610+
# set that versions should not match for this test
611+
DIFFERENT_VERSIONS=1
612+
export DIFFERENT_VERSIONS
613+
614+
# set as configured, enable maintenance mode and create required directories
615+
setup_maintenance_mode "configured"
616+
617+
# set restore host environ var
618+
GHE_RESTORE_HOST=127.0.0.1
619+
export GHE_RESTORE_HOST
620+
621+
! output=$(ghe-restore -v -f 2>&1)
622+
623+
echo "$output" | grep -q "Error: Not all nodes are running the same version! Please ensure all nodes are running the same version before using backup-utils."
624+
)
625+
end_test
626+
601627
begin_test "ghe-restore missing directories or files from source snapshot displays warning"
602628
(
603629
# Tests the scenario where something exists in the database, but not on disk.

0 commit comments

Comments
 (0)