Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions bin/ghe-restore
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ if ghe-ssh "$GHE_HOSTNAME" -- \
restore_settings=false
fi

# Figure out if we're restoring into a cluster with an unsupported snapshot
if $cluster; then
snapshot_instance_version=$(cat $GHE_RESTORE_SNAPSHOT_PATH/version)
if ! echo $snapshot_instance_version | \
grep -Eq "v2\.[5-9]|v2\.[1-9][0-9]|v[3-9]|v[1-9][0-9]"; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminded me that we need to add a semver comparison helper at some point, somewhere. The ^^^ regex may not be future proof :trollface:, but who wants to live forever.

echo "Error: Snapshot must be from GitHub Enterprise v2.5.0 or above to be restored"
echo " into a cluster (detected $snapshot_instance_version). Aborting." >&2
exit 1
fi
fi

# Figure out if this instance is in a replication pair
if ghe-ssh "$GHE_HOSTNAME" -- "ghe-repl-status -r 2>/dev/null" \
| grep -Eq "replica|primary"; then
Expand Down
3 changes: 2 additions & 1 deletion script/cibuild
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ REMOTE_VERSIONS="
11.10.344
2.0.0
2.2.0
2.5.0
"

# Enable verbose logging of ssh commands
Expand All @@ -21,7 +22,7 @@ for version in $REMOTE_VERSIONS
do
echo "==> Running testsuite with GHE_TEST_REMOTE_VERSION=$version"
export GHE_TEST_REMOTE_VERSION="$version"
if ! ls -1 test/test-*.sh | xargs -P 4 -n 1 /bin/sh; then
if ! ls -1 test/test-*.sh | xargs -P 4 -n 1 /bin/bash; then
res=false
fi
echo
Expand Down
6 changes: 6 additions & 0 deletions test/bin/ghe-cluster-config-apply
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
# Usage: ghe-cluster-config-apply
# Emulates the remote GitHub ghe-cluster-config-apply command. Tests use this
# to assert that the command was executed.
set -e
echo "ghe-cluster-config-apply OK"
60 changes: 58 additions & 2 deletions test/test-ghe-restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# ghe-restore command tests

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

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

Expand Down Expand Up @@ -437,3 +438,58 @@ begin_test "ghe-restore with tarball strategy"
echo "$output" | grep -q 'fake ghe-export-repositories data'
)
end_test

begin_test "cluster: ghe-restore from v2.4.0 snapshot"
(
set -e
rm -rf "$GHE_REMOTE_ROOT_DIR"
setup_remote_cluster || exit 0
setup_remote_metadata

# set restore host environ var
GHE_RESTORE_HOST=127.0.0.1
export GHE_RESTORE_HOST

# create file used to determine if instance is in maintenance mode.
mkdir -p "$GHE_REMOTE_DATA_DIR/github/current/public/system"
touch "$GHE_REMOTE_DATA_DIR/github/current/public/system/maintenance.html"

echo "v2.4.0" > "$GHE_DATA_DIR/current/version"

# run ghe-restore and write output to file for asserting against
if ghe-restore -v -f > "$TRASHDIR/restore-out" 2>&1; then
cat "$TRASHDIR/restore-out"
: ghe-restore should have exited non-zero
false
fi

# verify restore error message
grep -q "Error: Snapshot must be from" "$TRASHDIR/restore-out"
)
end_test

begin_test "cluster: ghe-restore from v2.5.0 snapshot"
(
set -e
rm -rf "$GHE_REMOTE_ROOT_DIR"
setup_remote_cluster || exit 0
setup_remote_metadata

# set restore host environ var
GHE_RESTORE_HOST=127.0.0.1
export GHE_RESTORE_HOST

# create file used to determine if instance is in maintenance mode.
mkdir -p "$GHE_REMOTE_DATA_DIR/github/current/public/system"
touch "$GHE_REMOTE_DATA_DIR/github/current/public/system/maintenance.html"

echo "v2.5.0" > "$GHE_DATA_DIR/current/version"

# run ghe-restore and write output to file for asserting against
if ! ghe-restore -v -f > "$TRASHDIR/restore-out" 2>&1; then
cat "$TRASHDIR/restore-out"
: ghe-restore should have exited successfully
false
fi
)
end_test
13 changes: 11 additions & 2 deletions test/testlib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
set -e

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

# create a temporary work space
Expand All @@ -47,7 +47,7 @@ export GHE_TEST_REMOTE_VERSION

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

Expand Down Expand Up @@ -103,6 +103,15 @@ setup_remote_license () {
}
setup_remote_license

setup_remote_cluster () {
if [ "$GHE_VERSION_MAJOR" -lt 2 ] || \
([ "$GHE_VERSION_MAJOR" -eq 2 ] && [ "$GHE_VERSION_MINOR" -le 4 ]); then
return 1
fi

mkdir -p "$GHE_REMOTE_ROOT_DIR/etc/github"
touch "$GHE_REMOTE_ROOT_DIR/etc/github/cluster"
}

# Mark the beginning of a test. A subshell should immediately follow this
# statement.
Expand Down