diff options
author | Paul Emm. Katsoulakis <34388743+paulkatsoulakis@users.noreply.github.com> | 2019-04-29 18:39:22 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-29 18:39:22 +0300 |
commit | d01b2620eab77d8f2ab1c70456744565eff356f0 (patch) | |
tree | 9b0713a373f0d63282ecd728322bb5d873b351b3 /tests | |
parent | e33c45d333b0704363eb31105293c9b067158cdb (diff) |
Fix lifecycle script (#5918)
* netdata/packaging/ci: stronger validations during install, add some comments, change validation of CWD
* netdata/packaging/ci: Add a lifecycle test to validate update from stable to latest works smooth
-> Add updater BATS script that does the trick for installing stable then migrating to latest using current code and not nightly
-> Integrate with travis
-> Rename /code to /netdata in travis, scripts will eventually expect the TLD of repo to be actually named netdata, so test will start failing later
-> Introduce a flag on the updater, so that it doesn't download the tarball, but it rather works with a local pre-defined directory. If a user wants
to override the update process, so that it runs with a different repository he just needs to export NETDATA_LOCAL_TARBAL_OVERRIDE with the desired repo directory
* netdata/packaging/ci: Add required packages for it to run
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/lifecycle.bats | 28 | ||||
-rwxr-xr-x | tests/updater_checks.bats | 71 | ||||
-rwxr-xr-x | tests/updater_checks.sh | 16 |
3 files changed, 114 insertions, 1 deletions
diff --git a/tests/lifecycle.bats b/tests/lifecycle.bats index d008fea46c..4d18115bea 100755 --- a/tests/lifecycle.bats +++ b/tests/lifecycle.bats @@ -1,4 +1,12 @@ #!/usr/bin/env bats +# +# Netdata installation lifecycle testing script. +# This is to validate the install, update and uninstall of netdata +# +# Copyright: SPDX-License-Identifier: GPL-3.0-or-later +# +# Author : Pavlos Emm. Katsoulakis <paul@netdata.cloud) +# INSTALLATION="$BATS_TMPDIR/installation" ENV="${INSTALLATION}/netdata/etc/netdata/.environment" @@ -8,8 +16,19 @@ FILES="usr/libexec/netdata/plugins.d/go.d.plugin usr/libexec/netdata/plugins.d/python.d.plugin usr/libexec/netdata/plugins.d/node.d.plugin" +DIRS="usr/sbin/netdata + etc/netdata + usr/share/netdata + usr/libexec/netdata + var/cache/netdata + var/lib/netdata + var/log/netdata" + setup() { - if [ ! -f .gitignore ]; then + # If we are not in netdata git repo, at the top level directory, fail + TOP_LEVEL=$(basename "$(git rev-parse --show-toplevel)") + CWD=$(git rev-parse --show-cdup || echo "") + if [ -n "${CWD}" ] || [ ! "${TOP_LEVEL}" == "netdata" ]; then echo "Run as ./tests/lifecycle/$(basename "$0") from top level directory of git repository" exit 1 fi @@ -17,9 +36,16 @@ setup() { @test "install netdata" { ./netdata-installer.sh --dont-wait --dont-start-it --auto-update --install "${INSTALLATION}" + + # Validate particular files for file in $FILES; do [ ! -f "$BATS_TMPDIR/$file" ] done + + # Validate particular directories + for a_dir in $DIRS; do + [ ! -d "$BATS_TMPDIR/$a_dir" ] + done } @test "update netdata" { diff --git a/tests/updater_checks.bats b/tests/updater_checks.bats new file mode 100755 index 0000000000..e177fe4e5a --- /dev/null +++ b/tests/updater_checks.bats @@ -0,0 +1,71 @@ +#!/usr/bin/env bats +# +# This script is responsible for validating +# updater capabilities after a change +# +# Copyright: SPDX-License-Identifier: GPL-3.0-or-later +# +# Author : Pavlos Emm. Katsoulakis <paul@netdata.cloud) +# + +INSTALLATION="$BATS_TMPDIR/installation" +ENV="${INSTALLATION}/netdata/etc/netdata/.environment" +# list of files which need to be checked. Path cannot start from '/' +FILES="usr/libexec/netdata/plugins.d/go.d.plugin + usr/libexec/netdata/plugins.d/charts.d.plugin + usr/libexec/netdata/plugins.d/python.d.plugin + usr/libexec/netdata/plugins.d/node.d.plugin" + +DIRS="usr/sbin/netdata + etc/netdata + usr/share/netdata + usr/libexec/netdata + var/cache/netdata + var/lib/netdata + var/log/netdata" + +setup() { + + # If we are not in netdata git repo, at the top level directory, fail + TOP_LEVEL=$(basename "$(git rev-parse --show-toplevel)") + CWD=$(git rev-parse --show-cdup || echo "") + if [ -n "${CWD}" ] || [ ! "${TOP_LEVEL}" == "netdata" ]; then + echo "Run as ./tests/$(basename "$0") from top level directory of git repository" + exit 1 + fi +} + +@test "install stable netdata using kickstart" { + kickstart_file="/tmp/kickstart.$$" + curl -Ss -o ${kickstart_file} https://my-netdata.io/kickstart.sh + chmod +x ${kickstart_file} + ${kickstart_file} --dont-wait --dont-start-it --auto-update --install ${INSTALLATION} + + # Validate particular files + for file in $FILES; do + [ ! -f "$BATS_TMPDIR/$file" ] + done + + # Validate particular directories + for a_dir in $DIRS; do + [ ! -d "$BATS_TMPDIR/$a_dir" ] + done + + # Cleanup + rm -rf ${kickstart_file} +} + +@test "update netdata using the new updater" { + export ENVIRONMENT_FILE="${ENV}" + # Run the updater, with the override so that it uses the local repo we have at hand + # Try to run the installed, if any, otherwise just run the one from the repo + export NETDATA_LOCAL_TARBAL_OVERRIDE="${PWD}" + /etc/cron.daily/netdata-updater || ./packaging/installer/netdata-updater.sh + ! grep "new_installation" "${ENV}" +} + +@test "uninstall netdata using latest uninstaller" { + ./packaging/installer/netdata-uninstaller.sh --yes --force --env "${ENV}" + [ ! -f "${INSTALLATION}/netdata/usr/sbin/netdata" ] + [ ! -f "/etc/cron.daily/netdata-updater" ] +} diff --git a/tests/updater_checks.sh b/tests/updater_checks.sh new file mode 100755 index 0000000000..dce136853f --- /dev/null +++ b/tests/updater_checks.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +# +# Wrapper script that installs the required dependencies +# for the BATS script to run successfully +# +# Copyright: SPDX-License-Identifier: GPL-3.0-or-later +# +# Author : Pavlos Emm. Katsoulakis <paul@netdata.cloud) +# + +echo "Installing extra dependencies.." +yum install -y epel-release +yum install -y git bats + +echo "Running BATS file.." +bats --tap tests/updater_checks.bats |