-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathsetup_e2e_tests.sh
More file actions
141 lines (117 loc) · 4.94 KB
/
setup_e2e_tests.sh
File metadata and controls
141 lines (117 loc) · 4.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/bin/bash
set -e
BRANCH=$1
VERSION=
# Try to convert the branch to a major.minor version number
# master -> master
# 0.1.0 -> 0.1
# v0.1.0 -> v0.1
# testing -> testing
# something/python.py -> something/python.py
if [[ $BRANCH =~ v?[[:digit:]]{1,}\.[[:digit:]]{1,} ]]; then
VERSION=$(echo ${BRANCH} | cut -d "." -f1-2 | sed 's/^v//')
fi
PIP="pip"
# Install OS specific pre-reqs (Better moved to puppet at some point.)
DEBTEST=`lsb_release -a 2> /dev/null | grep Distributor | awk '{print $3}'`
RHTEST=`cat /etc/redhat-release 2> /dev/null | sed -e "s~\(.*\)release.*~\1~g"`
# Decrease interval for MongoDB TTL expire thread. By default it runs every 60 seconds which
# means we would need to wait at least 60 seconds in our key expire end to end tests.
# By decreasing it, we can speed up those tests
# TODO: Use db.adminCommand, but for that we need to fix admin user permissions in bootstrap script
echo "Updating MongoDB config..."
echo -e "\nsetParameter:\n ttlMonitorSleepSecs: 1" | sudo tee -a /etc/mongod.conf > /dev/null
sudo cat /etc/mongod.conf
if [[ -n "$RHTEST" ]]; then
RHVERSION=`cat /etc/redhat-release 2> /dev/null | sed -r 's/([^0-9]*([0-9]*)){1}.*/\2/'`
echo "*** Detected Distro is ${RHTEST} - ${RHVERSION} ***"
echo "Restarting MongoDB..."
if [[ "$RHVERSION" -ge 7 ]]; then
# Restart MongoDB for the config changes above to take an affect
sudo systemctl restart mongod
else
# Restart MongoDB for the config changes above to take an affect
sudo service mongod restart
fi
if [[ "$RHVERSION" -eq 7 ]]; then
# For RHEL/CentOS 7
sudo yum install -y bats jq python3-pip python3-virtualenv
else
# For RHEL/CentOS 8 and above
sudo yum install -y jq python3-pip python3-virtualenv wget
PIP="pip3"
# bats not available in epel for EL 8, Install from npm
sudo npm install --global bats
fi
elif [[ -n "$DEBTEST" ]]; then
DEBVERSION=`lsb_release --release | awk '{ print $2 }'`
SUBTYPE=`lsb_release -a 2>&1 | grep Codename | grep -v "LSB" | awk '{print $2}'`
echo "*** Detected Distro is ${DEBTEST} - ${DEBVERSION} ***"
echo "Restarting MongoDB..."
# Restart MongoDB for the config changes above to take an affect
if [[ "$SUBTYPE" == 'xenial' || "${SUBTYPE}" == "bionic" ]]; then
sudo systemctl restart mongod
fi
sudo apt-get -q -y install build-essential jq python3-pip python3-dev python3-venv wget
# Remove bats-core if it already exists (this happens when test workflows
# are re-run on a server when tests are debugged)
if [[ -d bats-core ]]; then
rm -rf bats-core
fi
# Install from GitHub
git clone https://github.com/bats-core/bats-core.git
(cd bats-core; sudo ./install.sh /usr/local)
else
echo "Unknown Operating System."
exit 2
fi
# Setup crypto key file
ST2_CONF="/etc/st2/st2.conf"
CRYPTO_BASE="/etc/st2/keys"
CRYPTO_KEY_FILE="${CRYPTO_BASE}/key.json"
sudo mkdir -p ${CRYPTO_BASE}
if [[ ! -e "${CRYPTO_KEY_FILE}" ]]; then
sudo st2-generate-symmetric-crypto-key --key-path ${CRYPTO_KEY_FILE}
sudo chgrp st2packs ${CRYPTO_KEY_FILE}
fi
# This looks overly complicated...
sudo bash -c "cat <<keyvalue_options >>${ST2_CONF}
[keyvalue]
encryption_key_path=${CRYPTO_KEY_FILE}
keyvalue_options"
# Reload required for testing st2 upgrade
st2ctl reload --register-all
# Remove the st2tests directory if it exists (this happens when test workflows
# are re-run on a server when tests are debugged)
if [[ -d st2tests ]]; then
rm -rf st2tests
fi
# Install packs for testing
# If we didn't recognize a version string, treat it like a branch
if [[ -z "$VERSION" ]]; then
echo "Installing st2tests from '${BRANCH}' branch at location: $(pwd)..."
# Can use --recurse-submodules with Git 2.13 and later
git clone --recursive -b ${BRANCH} --depth 1 https://github.com/StackStorm/st2tests.git
else
echo "Installing st2tests from 'v${VERSION}' branch at location: $(pwd)"
# Can use --recurse-submodules with Git 2.13 and later
# Treat $VERSION like a version string and prepend 'v'
git clone --recursive -b v${VERSION} --depth 1 https://github.com/StackStorm/st2tests.git
fi
echo "Installing Packs: tests, asserts, fixtures, webui..."
sudo cp -R st2tests/packs/* /opt/stackstorm/packs/
echo "Apply st2 CI configuration if it exists..."
if [ -f st2tests/conf/st2.ci.conf ]; then
sudo cp -f /etc/st2/st2.conf /etc/st2/st2.conf.bkup
sudo crudini --merge /etc/st2/st2.conf < st2tests/conf/st2.ci.conf
fi
sudo cp -R /usr/share/doc/st2/examples /opt/stackstorm/packs/
st2 run packs.setup_virtualenv python3=true packs=examples,tests,asserts,fixtures,webui,chatops_tests
st2ctl reload --register-all
cd st2tests
python3 -m venv venv
. venv/bin/activate
${PIP} install -r test-requirements.txt # TODO: This should eventually use python3 -m pip
# Restart st2 primarily reload the keyvalue configuration
sudo st2ctl restart
sleep 5