Skip to content

Commit cc27045

Browse files
committed
Merge pull request #182 from github/snh/cluster-restore-version-check
Minimum version enforcement for cluster restores
2 parents b470d0d + 086ff39 commit cc27045

File tree

5 files changed

+88
-5
lines changed

5 files changed

+88
-5
lines changed

bin/ghe-restore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,17 @@ if ghe-ssh "$GHE_HOSTNAME" -- \
106106
restore_settings=false
107107
fi
108108

109+
# Figure out if we're restoring into a cluster with an unsupported snapshot
110+
if $cluster; then
111+
snapshot_instance_version=$(cat $GHE_RESTORE_SNAPSHOT_PATH/version)
112+
if ! echo $snapshot_instance_version | \
113+
grep -Eq "v2\.[5-9]|v2\.[1-9][0-9]|v[3-9]|v[1-9][0-9]"; then
114+
echo "Error: Snapshot must be from GitHub Enterprise v2.5.0 or above to be restored"
115+
echo " into a cluster (detected $snapshot_instance_version). Aborting." >&2
116+
exit 1
117+
fi
118+
fi
119+
109120
# Figure out if this instance is in a replication pair
110121
if ghe-ssh "$GHE_HOSTNAME" -- "ghe-repl-status -r 2>/dev/null" \
111122
| grep -Eq "replica|primary"; then

script/cibuild

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ REMOTE_VERSIONS="
1010
11.10.344
1111
2.0.0
1212
2.2.0
13+
2.5.0
1314
"
1415

1516
# Enable verbose logging of ssh commands
@@ -21,7 +22,7 @@ for version in $REMOTE_VERSIONS
2122
do
2223
echo "==> Running testsuite with GHE_TEST_REMOTE_VERSION=$version"
2324
export GHE_TEST_REMOTE_VERSION="$version"
24-
if ! ls -1 test/test-*.sh | xargs -P 4 -n 1 /bin/sh; then
25+
if ! ls -1 test/test-*.sh | xargs -P 4 -n 1 /bin/bash; then
2526
res=false
2627
fi
2728
echo

test/bin/ghe-cluster-config-apply

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
# Usage: ghe-cluster-config-apply
3+
# Emulates the remote GitHub ghe-cluster-config-apply command. Tests use this
4+
# to assert that the command was executed.
5+
set -e
6+
echo "ghe-cluster-config-apply OK"

test/test-ghe-restore.sh

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
# ghe-restore command tests
33

44
# Bring in testlib
5-
. $(dirname "$0")/testlib.sh
5+
ROOTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
6+
. $ROOTDIR/test/testlib.sh
67

78
# Add some fake pages data to the snapshot
89
mkdir -p "$GHE_DATA_DIR/1/pages"
@@ -90,7 +91,7 @@ begin_test "ghe-restore into configured vm"
9091
# run ghe-restore and write output to file for asserting against
9192
if ! ghe-restore -v -f > "$TRASHDIR/restore-out" 2>&1; then
9293
cat "$TRASHDIR/restore-out"
93-
: ghe-restore should have exited non-zero
94+
: ghe-restore should have exited successfully
9495
false
9596
fi
9697

@@ -437,3 +438,58 @@ begin_test "ghe-restore with tarball strategy"
437438
echo "$output" | grep -q 'fake ghe-export-repositories data'
438439
)
439440
end_test
441+
442+
begin_test "cluster: ghe-restore from v2.4.0 snapshot"
443+
(
444+
set -e
445+
rm -rf "$GHE_REMOTE_ROOT_DIR"
446+
setup_remote_cluster || exit 0
447+
setup_remote_metadata
448+
449+
# set restore host environ var
450+
GHE_RESTORE_HOST=127.0.0.1
451+
export GHE_RESTORE_HOST
452+
453+
# create file used to determine if instance is in maintenance mode.
454+
mkdir -p "$GHE_REMOTE_DATA_DIR/github/current/public/system"
455+
touch "$GHE_REMOTE_DATA_DIR/github/current/public/system/maintenance.html"
456+
457+
echo "v2.4.0" > "$GHE_DATA_DIR/current/version"
458+
459+
# run ghe-restore and write output to file for asserting against
460+
if ghe-restore -v -f > "$TRASHDIR/restore-out" 2>&1; then
461+
cat "$TRASHDIR/restore-out"
462+
: ghe-restore should have exited non-zero
463+
false
464+
fi
465+
466+
# verify restore error message
467+
grep -q "Error: Snapshot must be from" "$TRASHDIR/restore-out"
468+
)
469+
end_test
470+
471+
begin_test "cluster: ghe-restore from v2.5.0 snapshot"
472+
(
473+
set -e
474+
rm -rf "$GHE_REMOTE_ROOT_DIR"
475+
setup_remote_cluster || exit 0
476+
setup_remote_metadata
477+
478+
# set restore host environ var
479+
GHE_RESTORE_HOST=127.0.0.1
480+
export GHE_RESTORE_HOST
481+
482+
# create file used to determine if instance is in maintenance mode.
483+
mkdir -p "$GHE_REMOTE_DATA_DIR/github/current/public/system"
484+
touch "$GHE_REMOTE_DATA_DIR/github/current/public/system/maintenance.html"
485+
486+
echo "v2.5.0" > "$GHE_DATA_DIR/current/version"
487+
488+
# run ghe-restore and write output to file for asserting against
489+
if ! ghe-restore -v -f > "$TRASHDIR/restore-out" 2>&1; then
490+
cat "$TRASHDIR/restore-out"
491+
: ghe-restore should have exited successfully
492+
false
493+
fi
494+
)
495+
end_test

test/testlib.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
set -e
2323

2424
# Setting basic paths
25-
ROOTDIR="$(cd $(dirname "$0")/.. && pwd)"
25+
ROOTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
2626
PATH="$ROOTDIR/test/bin:$ROOTDIR/bin:$ROOTDIR/share/github-backup-utils:$PATH"
2727

2828
# create a temporary work space
@@ -47,7 +47,7 @@ export GHE_TEST_REMOTE_VERSION
4747

4848
# Source in the backup config and set GHE_REMOTE_XXX variables based on the
4949
# remote version established above or in the environment.
50-
. ghe-backup-config
50+
. $ROOTDIR/share/github-backup-utils/ghe-backup-config
5151
ghe_parse_remote_version "$GHE_TEST_REMOTE_VERSION"
5252
ghe_remote_version_config "$GHE_TEST_REMOTE_VERSION"
5353

@@ -103,6 +103,15 @@ setup_remote_license () {
103103
}
104104
setup_remote_license
105105

106+
setup_remote_cluster () {
107+
if [ "$GHE_VERSION_MAJOR" -lt 2 ] || \
108+
([ "$GHE_VERSION_MAJOR" -eq 2 ] && [ "$GHE_VERSION_MINOR" -le 4 ]); then
109+
return 1
110+
fi
111+
112+
mkdir -p "$GHE_REMOTE_ROOT_DIR/etc/github"
113+
touch "$GHE_REMOTE_ROOT_DIR/etc/github/cluster"
114+
}
106115

107116
# Mark the beginning of a test. A subshell should immediately follow this
108117
# statement.

0 commit comments

Comments
 (0)