Skip to content

Commit dd5034c

Browse files
Seth Goingssgoings
authored andcommitted
test(*): add provision/upgrade test
- use rerun for reusability of scripts - move rerun to tests/bin - rename provision module to accept - add swappable upgrade methods - use graceful upgrade properly - upgrade-prep should be called on old deisctl
1 parent ee15c14 commit dd5034c

30 files changed

Lines changed: 1041 additions & 0 deletions

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,8 @@ contrib/gce/gce-user-data
7979
# vagrant local config and droppings
8080
/config.rb
8181
.vagrant
82+
83+
# bash infra
84+
/tests/bin/tmp
85+
!/tests/bin/accept/lib
86+
!/tests/bin/accept/commands
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# command metadata
2+
# generated by stubbs:add-command
3+
# Thu Jul 23 11:20:37 MDT 2015
4+
NAME=provision
5+
DESCRIPTION="Provision a cluster"
6+
OPTIONS="provider version skip-cleanup"
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Generated by stubbs:add-option. Do not edit, if using stubbs.
2+
# Created: Thu Jul 23 11:38:40 MDT 2015
3+
#
4+
#/ usage: tests:provision --provider <vagrant> --version <dev> [ --skip-cleanup <false>]
5+
6+
# _rerun_options_parse_ - Parse the command arguments and set option variables.
7+
#
8+
# rerun_options_parse "$@"
9+
#
10+
# Arguments:
11+
#
12+
# * the command options and their arguments
13+
#
14+
# Notes:
15+
#
16+
# * Sets shell variables for any parsed options.
17+
# * The "-?" help argument prints command usage and will exit 2.
18+
# * Return 0 for successful option parse.
19+
#
20+
rerun_options_parse() {
21+
22+
while [ "$#" -gt 0 ]; do
23+
OPT="$1"
24+
case "$OPT" in
25+
--provider) rerun_option_check $# $1; PROVIDER=$2 ; shift ;;
26+
--version) rerun_option_check $# $1; VERSION=$2 ; shift ;;
27+
--skip-cleanup) rerun_option_check $# $1; SKIP_CLEANUP=$2 ; shift ;;
28+
# help option
29+
-|--*?)
30+
rerun_option_usage
31+
exit 2
32+
;;
33+
# end of options, just arguments left
34+
*)
35+
break
36+
esac
37+
shift
38+
done
39+
40+
# Set defaultable options.
41+
[ -z "$PROVIDER" ] && PROVIDER="$(rerun_property_get $RERUN_MODULE_DIR/options/provider DEFAULT)"
42+
[ -z "$VERSION" ] && VERSION="$(rerun_property_get $RERUN_MODULE_DIR/options/version DEFAULT)"
43+
[ -z "$SKIP_CLEANUP" ] && SKIP_CLEANUP="$(rerun_property_get $RERUN_MODULE_DIR/options/skip-cleanup DEFAULT)"
44+
# Check required options are set
45+
[ -z "$PROVIDER" ] && { echo >&2 "missing required option: --provider" ; return 2 ; }
46+
[ -z "$VERSION" ] && { echo >&2 "missing required option: --version" ; return 2 ; }
47+
# If option variables are declared exportable, export them.
48+
49+
#
50+
return 0
51+
}
52+
53+
54+
# If not already set, initialize the options variables to null.
55+
: ${PROVIDER:=}
56+
: ${VERSION:=}
57+
: ${SKIP_CLEANUP:=}
58+
59+
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/usr/bin/env bash
2+
3+
# To implement this command, edit the "Command implementation" section below.
4+
5+
# Usage
6+
# -----
7+
8+
# Comments prefixed with `#/` are managed by stubbs.
9+
# The `command` and `usage` comments describe the command
10+
# and show its options.
11+
#
12+
#/ command: tests:provision: "Provision a cluster"
13+
#/ usage: rerun tests:provision --provider <vagrant> --version <dev> [ --skip-cleanup <false>]
14+
15+
# Load common functions
16+
# ---------------------
17+
18+
# Load the function library for this module.
19+
# This loads rerun functions, too.
20+
. $RERUN_MODULE_DIR/lib/functions.sh provision || {
21+
echo >&2 "Failed loading function library." ; exit 1 ;
22+
}
23+
24+
# Error handling
25+
# ---------------
26+
27+
# This script is designed to _fail-fast_.
28+
29+
# Trap errors and exit. The call to `rerun_die` will print the
30+
# the error message and exit with the error command exit status.
31+
32+
trap 'rerun_die $? "*** command failed: tests:provision. ***"' ERR
33+
34+
# Run [set] `nounset` to treat unset variables as errors. Set [pipefail]
35+
# so a pipeline return status is the value of the last
36+
# (rightmost) command to exit with non-zero status.
37+
#
38+
# [set]: http://ss64.com/bash/set.html
39+
# [pipefail]: http://www.gnu.org/software/bash/manual/html_node/Pipelines.html
40+
41+
set -o nounset -o pipefail
42+
43+
# Command variables
44+
# -----------------
45+
46+
# This command script can access the following variables
47+
# declared by `rerun` or by the option parser function.
48+
49+
#/ rerun-variables: RERUN, RERUN_VERSION, RERUN_MODULES, RERUN_MODULE_DIR
50+
#/ option-variables: PROVIDER VERSION SKIP_CLEANUP
51+
52+
# The `rerun_options_parse` function processes the command line
53+
# arguments. Each accepted command line flag results in setting
54+
# one the corresponding option variables.
55+
56+
rerun_options_parse "$@"
57+
58+
trap destroy-cluster EXIT
59+
60+
# Command implementation
61+
# ----------------------
62+
63+
TEST_ROOT="${TEST_ROOT}/${VERSION}"
64+
65+
setup-provider "${PROVIDER}"
66+
67+
setup-provider-dependencies
68+
69+
destroy-cluster
70+
71+
setup-clients "${VERSION}"
72+
73+
make discovery-url
74+
75+
create-cluster
76+
77+
build-deis "${VERSION}"
78+
79+
deploy-deis "${VERSION}"
80+
81+
make test-smoke
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# command metadata
2+
# generated by stubbs:add-command
3+
# Tue Jul 21 15:43:05 MDT 2015
4+
NAME=upgrade
5+
DESCRIPTION="Tests upgrade path for Deis"
6+
OPTIONS="provider from to skip-cleanup upgrade-style"
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Generated by stubbs:add-option. Do not edit, if using stubbs.
2+
# Created: Wed Aug 5 14:11:16 MDT 2015
3+
#
4+
#/ usage: accept:upgrade --provider <vagrant> --from <> [ --to <master>] [ --skip-cleanup <false>] --upgrade-style <graceful>
5+
6+
# _rerun_options_parse_ - Parse the command arguments and set option variables.
7+
#
8+
# rerun_options_parse "$@"
9+
#
10+
# Arguments:
11+
#
12+
# * the command options and their arguments
13+
#
14+
# Notes:
15+
#
16+
# * Sets shell variables for any parsed options.
17+
# * The "-?" help argument prints command usage and will exit 2.
18+
# * Return 0 for successful option parse.
19+
#
20+
rerun_options_parse() {
21+
22+
while [ "$#" -gt 0 ]; do
23+
OPT="$1"
24+
case "$OPT" in
25+
--provider) rerun_option_check $# $1; PROVIDER=$2 ; shift ;;
26+
--from) rerun_option_check $# $1; FROM=$2 ; shift ;;
27+
--to) rerun_option_check $# $1; TO=$2 ; shift ;;
28+
--skip-cleanup) rerun_option_check $# $1; SKIP_CLEANUP=$2 ; shift ;;
29+
--upgrade-style) rerun_option_check $# $1; UPGRADE_STYLE=$2 ; shift ;;
30+
# help option
31+
-|--*?)
32+
rerun_option_usage
33+
exit 2
34+
;;
35+
# end of options, just arguments left
36+
*)
37+
break
38+
esac
39+
shift
40+
done
41+
42+
# Set defaultable options.
43+
[ -z "$PROVIDER" ] && PROVIDER="$(rerun_property_get $RERUN_MODULE_DIR/options/provider DEFAULT)"
44+
[ -z "$TO" ] && TO="$(rerun_property_get $RERUN_MODULE_DIR/options/to DEFAULT)"
45+
[ -z "$SKIP_CLEANUP" ] && SKIP_CLEANUP="$(rerun_property_get $RERUN_MODULE_DIR/options/skip-cleanup DEFAULT)"
46+
[ -z "$UPGRADE_STYLE" ] && UPGRADE_STYLE="$(rerun_property_get $RERUN_MODULE_DIR/options/upgrade-style DEFAULT)"
47+
# Check required options are set
48+
[ -z "$PROVIDER" ] && { echo >&2 "missing required option: --provider" ; return 2 ; }
49+
[ -z "$FROM" ] && { echo >&2 "missing required option: --from" ; return 2 ; }
50+
[ -z "$UPGRADE_STYLE" ] && { echo >&2 "missing required option: --upgrade-style" ; return 2 ; }
51+
# If option variables are declared exportable, export them.
52+
53+
#
54+
return 0
55+
}
56+
57+
58+
# If not already set, initialize the options variables to null.
59+
: ${PROVIDER:=}
60+
: ${FROM:=}
61+
: ${TO:=}
62+
: ${SKIP_CLEANUP:=}
63+
: ${UPGRADE_STYLE:=}
64+
65+
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/usr/bin/env bash
2+
3+
# To implement this command, edit the "Command implementation" section below.
4+
5+
# Usage
6+
# -----
7+
8+
# Comments prefixed with `#/` are managed by stubbs.
9+
# The `command` and `usage` comments describe the command
10+
# and show its options.
11+
#
12+
#/ command: accept:upgrade: "Tests upgrade path for Deis"
13+
#/ usage: rerun accept:upgrade --provider <vagrant> --from <> [ --to <master>] [ --skip-cleanup <false>] --upgrade-style <graceful>
14+
15+
# Load common functions
16+
# ---------------------
17+
18+
# Load the function library for this module.
19+
# This loads rerun functions, too.
20+
. $RERUN_MODULE_DIR/lib/functions.sh upgrade || {
21+
echo >&2 "Failed loading function library." ; exit 1 ;
22+
}
23+
24+
# Error handling
25+
# ---------------
26+
27+
# This script is designed to _fail-fast_.
28+
29+
# Trap errors and exit. The call to `rerun_die` will print the
30+
# the error message and exit with the error command exit status.
31+
32+
trap 'rerun_die $? "*** command failed: tests:upgrade. ***"' ERR
33+
34+
# Run [set] `nounset` to treat unset variables as errors. Set [pipefail]
35+
# so a pipeline return status is the value of the last
36+
# (rightmost) command to exit with non-zero status.
37+
#
38+
# [set]: http://ss64.com/bash/set.html
39+
# [pipefail]: http://www.gnu.org/software/bash/manual/html_node/Pipelines.html
40+
41+
set -o nounset -o pipefail
42+
43+
# Command variables
44+
# -----------------
45+
46+
# This command script can access the following variables
47+
# declared by `rerun` or by the option parser function.
48+
49+
#/ rerun-variables: RERUN, RERUN_VERSION, RERUN_MODULES, RERUN_MODULE_DIR
50+
#/ option-variables: PROVIDER FROM TO SKIP_CLEANUP UPGRADE_STYLE
51+
52+
# The `rerun_options_parse` function processes the command line
53+
# arguments. Each accepted command line flag results in setting
54+
# one the corresponding option variables.
55+
56+
rerun_options_parse "$@"
57+
58+
trap destroy-cluster EXIT
59+
60+
# Command implementation
61+
# ----------------------
62+
63+
function healthcheck {
64+
rerun_log "Running healthcheck of previously deployed app.."
65+
66+
if ! curl -s "http://testing.${DEIS_TEST_DOMAIN}" | grep -q "Powered by Deis"; then
67+
rerun_log error "Failed to pass healthcheck."
68+
return 1
69+
else
70+
rerun_log info "Healthcheck succeeded."
71+
return 0
72+
fi
73+
}
74+
75+
setup-provider "${PROVIDER}"
76+
setup-upgrader "${UPGRADE_STYLE}"
77+
78+
setup-provider-dependencies
79+
80+
destroy-cluster
81+
82+
setup-clients "${FROM}"
83+
84+
make discovery-url
85+
86+
create-cluster
87+
88+
deploy-deis "${FROM}"
89+
90+
make test-smoke
91+
92+
upgrade-deis "${FROM}" "${TO}"
93+
94+
healthcheck

tests/bin/accept/lib/checks.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function check-etcd-alive {
2+
rerun_log "Waiting for etcd/fleet at ${DEISCTL_TUNNEL}"
3+
4+
# wait for etcd up to 5 minutes
5+
WAIT_TIME=1
6+
until deisctl --request-timeout=1 list >/dev/null 2>&1; do
7+
(( WAIT_TIME += 1 ))
8+
if [ ${WAIT_TIME} -gt 300 ]; then
9+
log_phase "Timeout waiting for etcd/fleet"
10+
# run deisctl one last time without eating the error, so we can see what's up
11+
deisctl --request-timeout=1 list
12+
exit 1;
13+
fi
14+
done
15+
16+
rerun_log "etcd available after ${WAIT_TIME} seconds"
17+
}

0 commit comments

Comments
 (0)