@cryptotaxi247 / netdata-1 / commits / d01b2620e

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

Paul Emm. Katsoulakis committed Apr 29, 2019 at 18:39 UTC d01b2620eab77d8f2ab1c70456744565eff356f0
5 files changed +160 -25
.travis.yml
+13 -9
@@ -86,13 +86,13 @@ jobs:
86 - echo "Last commit:" && git log -1
87 - echo "GIT Describe:" && git describe
88 - echo "packaging/version:" && cat packaging/version
89 - - docker run -it -v "${PWD}:/code:rw" -v "/tmp/netdata-makedist-test:/netdata_install:rw" -w /code "netdata/os-test:ubuntu1804" make clean || echo "Nothing to clean"
90 - - docker run -it -v "${PWD}:/code:rw" -v "/tmp/netdata-makedist-test:/netdata_install:rw" -w /code "netdata/os-test:ubuntu1804" make distclean || echo "Nothing to distclean"
91 - - docker run -it -v "${PWD}:/code:rw" -v "/tmp/netdata-makedist-test:/netdata_install:rw" -w /code "netdata/os-test:ubuntu1804" autoreconf -ivf && ./configure --prefix=/netdata_install/usr --sysconfdir=/netdata_install/etc --localstatedir=/netdata_install/var --with-zlib --with-math --with-user=netdata CFLAGS=-O2
92 - - docker run -it -v "${PWD}:/code:rw" -v "/tmp/netdata-makedist-test:/netdata_install:rw" -w /code "netdata/os-test:ubuntu1804" make dist
93 - - docker run -it -v "${PWD}:/code:rw" -v "/tmp/netdata-makedist-test:/netdata_install:rw" -w /code "netdata/os-test:ubuntu1804" ls -ltr ./netdata-$(git describe).tar.gz || ls -ltr ./netdata-$(cat packaging/version | tr -d '\n').tar.gz
89 + - docker run -it -v "${PWD}:/netdata:rw" -v "/tmp/netdata-makedist-test:/netdata_install:rw" -w /netdata "netdata/os-test:ubuntu1804" make clean || echo "Nothing to clean"
90 + - docker run -it -v "${PWD}:/netdata:rw" -v "/tmp/netdata-makedist-test:/netdata_install:rw" -w /netdata "netdata/os-test:ubuntu1804" make distclean || echo "Nothing to distclean"
91 + - docker run -it -v "${PWD}:/netdata:rw" -v "/tmp/netdata-makedist-test:/netdata_install:rw" -w /netdata "netdata/os-test:ubuntu1804" autoreconf -ivf && ./configure --prefix=/netdata_install/usr --sysconfdir=/netdata_install/etc --localstatedir=/netdata_install/var --with-zlib --with-math --with-user=netdata CFLAGS=-O2
92 + - docker run -it -v "${PWD}:/netdata:rw" -v "/tmp/netdata-makedist-test:/netdata_install:rw" -w /netdata "netdata/os-test:ubuntu1804" make dist
93 + - docker run -it -v "${PWD}:/netdata:rw" -v "/tmp/netdata-makedist-test:/netdata_install:rw" -w /netdata "netdata/os-test:ubuntu1804" ls -ltr ./netdata-$(git describe).tar.gz || ls -ltr ./netdata-$(cat packaging/version | tr -d '\n').tar.gz
94 - .travis/run_install_with_dist_file.sh
95 - - docker run -it -v "${PWD}:/code:rw" -v "/tmp/netdata-makedist-test:/netdata_install:rw" -w /code "netdata/os-test:ubuntu1804" make distclean
95 + - docker run -it -v "${PWD}:/netdata:rw" -v "/tmp/netdata-makedist-test:/netdata_install:rw" -w /netdata "netdata/os-test:ubuntu1804" make distclean
96 git:
97 depth: false
98 after_script: rm -rf /tmp/netdata-makedist-test
@@ -118,15 +118,19 @@ jobs:
118 after_failure: post_message "TRAVIS_MESSAGE" "Build/Install failed on ubuntu 18.04"
119
120 - name: Run netdata lifecycle, on ubuntu 18.04 (Containerized)
121 - script: docker run -it -v "${PWD}:/code:rw" -w /code "netdata/os-test:ubuntu1804" bats --tap tests/lifecycle.bats
121 + script: docker run -it -v "${PWD}:/netdata:rw" -w /netdata "netdata/os-test:ubuntu1804" bats --tap tests/lifecycle.bats
122 after_failure: post_message "TRAVIS_MESSAGE" "Netdata lifecycle test script failed on ubuntu 18.04"
123
124 + - name: Run netdata lifecycle from stable to current, on CentOS 7 (Containerized)
125 + script: docker run -it -v "${PWD}:/netdata:rw" -w /netdata "netdata/os-test:centos7" tests/updater_checks.sh
126 + after_failure: post_message "TRAVIS_MESSAGE" "Netdata updater process failed on CentOS 7"
127 +
128 - name: Build/install for CentOS 6 (Containerized)
125 - script: docker run -it -v "${PWD}:/code:rw" -w /code "netdata/os-test:centos6" ./netdata-installer.sh --dont-wait --dont-start-it --install /tmp
129 + script: docker run -it -v "${PWD}:/netdata:rw" -w /netdata "netdata/os-test:centos6" ./netdata-installer.sh --dont-wait --dont-start-it --install /tmp
130 after_failure: post_message "TRAVIS_MESSAGE" "Build/Install failed on CentOS 6"
131
132 - name: Build/install for CentOS 7 (Containerized)
129 - script: docker run -it -v "${PWD}:/code:rw" -w /code "netdata/os-test:centos7" ./netdata-installer.sh --dont-wait --dont-start-it --install /tmp
133 + script: docker run -it -v "${PWD}:/netdata:rw" -w /netdata "netdata/os-test:centos7" ./netdata-installer.sh --dont-wait --dont-start-it --install /tmp
134 after_failure: post_message "TRAVIS_MESSAGE" "Build/Install failed on CentOS 7"
135
136
packaging/installer/netdata-updater.sh
+33 -15
@@ -67,6 +67,12 @@ download() {
67 }
68
69 set_tarball_urls() {
70 +
71 + if [ ! -z "${NETDATA_LOCAL_TARBAL_OVERRIDE}" ]; then
72 + info "Not fetching remote tarballs, local override was given"
73 + return
74 + fi
75 +
76 if [ "$1" == "stable" ]; then
77 local latest
78 # Simple version
@@ -83,22 +89,34 @@ set_tarball_urls() {
89 update() {
90 [ -z "${logfile}" ] && info "Running on a terminal - (this script also supports running headless from crontab)"
91
86 - dir=$(create_tmp_directory)
87 - cd "$dir"
92 + RUN_INSTALLER=0
93 + tmpdir=$(create_tmp_directory)
94 + cd "$tmpdir"
95
89 - download "${NETDATA_TARBALL_CHECKSUM_URL}" "${dir}/sha256sum.txt" >&3 2>&3
90 - if grep "${NETDATA_TARBALL_CHECKSUM}" sha256sum.txt >&3 2>&3; then
91 - info "Newest version is already installed"
92 - else
93 - download "${NETDATA_TARBALL_URL}" "${dir}/netdata-latest.tar.gz"
94 - if ! grep netdata-latest.tar.gz sha256sum.txt | safe_sha256sum -c - >&3 2>&3; then
95 - fatal "Tarball checksum validation failed. Stopping netdata upgrade and leaving tarball in ${dir}"
96 + if [ -z "${NETDATA_LOCAL_TARBAL_OVERRIDE}" ]; then
97 + download "${NETDATA_TARBALL_CHECKSUM_URL}" "${tmpdir}/sha256sum.txt" >&3 2>&3
98 + if grep "${NETDATA_TARBALL_CHECKSUM}" sha256sum.txt >&3 2>&3; then
99 + info "Newest version is already installed"
100 + else
101 + download "${NETDATA_TARBALL_URL}" "${tmpdir}/netdata-latest.tar.gz"
102 + if ! grep netdata-latest.tar.gz sha256sum.txt | safe_sha256sum -c - >&3 2>&3; then
103 + fatal "Tarball checksum validation failed. Stopping netdata upgrade and leaving tarball in ${tmpdir}"
104 + fi
105 + NEW_CHECKSUM="$(safe_sha256sum netdata-latest.tar.gz 2>/dev/null| cut -d' ' -f1)"
106 + tar -xf netdata-latest.tar.gz >&3 2>&3
107 + rm netdata-latest.tar.gz >&3 2>&3
108 + cd netdata-*
109 + RUN_INSTALLER=1
110 fi
97 - NEW_CHECKSUM="$(safe_sha256sum netdata-latest.tar.gz 2>/dev/null| cut -d' ' -f1)"
98 - tar -xf netdata-latest.tar.gz >&3 2>&3
99 - rm netdata-latest.tar.gz >&3 2>&3
100 - cd netdata-*
111 + else
112 + info "!!Local tarball override detected!! - Entering directory ${NETDATA_LOCAL_TARBAL_OVERRIDE} for installation, not downloading anything"
113 + RUN_INSTALLER=1
114 + cd ${NETDATA_LOCAL_TARBAL_OVERRIDE}
115 + fi
116 +
117
118 + # We got the sources, run the update now
119 + if [ ${RUN_INSTALLER} -eq 1 ]; then
120 # signal netdata to start saving its database
121 # this is handy if your database is big
122 pids=$(pidof netdata)
@@ -119,9 +137,9 @@ NETDATA_TARBALL_CHECKSUM="$NEW_CHECKSUM"
137 EOF
138 fi
139
122 - rm -rf "${dir}" >&3 2>&3
140 + rm -rf "${tmpdir}" >&3 2>&3
141 [ -n "${logfile}" ] && rm "${logfile}" && logfile=
124 - return 0
142 + return
143 }
144
145 # Usually stored in /etc/netdata/.environment
tests/lifecycle.bats
+27 -1
@@ -1,4 +1,12 @@
1 #!/usr/bin/env bats
2 +#
3 +# Netdata installation lifecycle testing script.
4 +# This is to validate the install, update and uninstall of netdata
5 +#
6 +# Copyright: SPDX-License-Identifier: GPL-3.0-or-later
7 +#
8 +# Author : Pavlos Emm. Katsoulakis <paul@netdata.cloud)
9 +#
10
11 INSTALLATION="$BATS_TMPDIR/installation"
12 ENV="${INSTALLATION}/netdata/etc/netdata/.environment"
@@ -8,8 +16,19 @@ FILES="usr/libexec/netdata/plugins.d/go.d.plugin
16 usr/libexec/netdata/plugins.d/python.d.plugin
17 usr/libexec/netdata/plugins.d/node.d.plugin"
18
19 +DIRS="usr/sbin/netdata
20 + etc/netdata
21 + usr/share/netdata
22 + usr/libexec/netdata
23 + var/cache/netdata
24 + var/lib/netdata
25 + var/log/netdata"
26 +
27 setup() {
12 - if [ ! -f .gitignore ]; then
28 + # If we are not in netdata git repo, at the top level directory, fail
29 + TOP_LEVEL=$(basename "$(git rev-parse --show-toplevel)")
30 + CWD=$(git rev-parse --show-cdup || echo "")
31 + if [ -n "${CWD}" ] || [ ! "${TOP_LEVEL}" == "netdata" ]; then
32 echo "Run as ./tests/lifecycle/$(basename "$0") from top level directory of git repository"
33 exit 1
34 fi
@@ -17,9 +36,16 @@ setup() {
36
37 @test "install netdata" {
38 ./netdata-installer.sh --dont-wait --dont-start-it --auto-update --install "${INSTALLATION}"
39 +
40 + # Validate particular files
41 for file in $FILES; do
42 [ ! -f "$BATS_TMPDIR/$file" ]
43 done
44 +
45 + # Validate particular directories
46 + for a_dir in $DIRS; do
47 + [ ! -d "$BATS_TMPDIR/$a_dir" ]
48 + done
49 }
50
51 @test "update netdata" {
tests/updater_checks.bats new
+71
@@ -0,0 +1,71 @@
1 +#!/usr/bin/env bats
2 +#
3 +# This script is responsible for validating
4 +# updater capabilities after a change
5 +#
6 +# Copyright: SPDX-License-Identifier: GPL-3.0-or-later
7 +#
8 +# Author : Pavlos Emm. Katsoulakis <paul@netdata.cloud)
9 +#
10 +
11 +INSTALLATION="$BATS_TMPDIR/installation"
12 +ENV="${INSTALLATION}/netdata/etc/netdata/.environment"
13 +# list of files which need to be checked. Path cannot start from '/'
14 +FILES="usr/libexec/netdata/plugins.d/go.d.plugin
15 + usr/libexec/netdata/plugins.d/charts.d.plugin
16 + usr/libexec/netdata/plugins.d/python.d.plugin
17 + usr/libexec/netdata/plugins.d/node.d.plugin"
18 +
19 +DIRS="usr/sbin/netdata
20 + etc/netdata
21 + usr/share/netdata
22 + usr/libexec/netdata
23 + var/cache/netdata
24 + var/lib/netdata
25 + var/log/netdata"
26 +
27 +setup() {
28 +
29 + # If we are not in netdata git repo, at the top level directory, fail
30 + TOP_LEVEL=$(basename "$(git rev-parse --show-toplevel)")
31 + CWD=$(git rev-parse --show-cdup || echo "")
32 + if [ -n "${CWD}" ] || [ ! "${TOP_LEVEL}" == "netdata" ]; then
33 + echo "Run as ./tests/$(basename "$0") from top level directory of git repository"
34 + exit 1
35 + fi
36 +}
37 +
38 +@test "install stable netdata using kickstart" {
39 + kickstart_file="/tmp/kickstart.$$"
40 + curl -Ss -o ${kickstart_file} https://my-netdata.io/kickstart.sh
41 + chmod +x ${kickstart_file}
42 + ${kickstart_file} --dont-wait --dont-start-it --auto-update --install ${INSTALLATION}
43 +
44 + # Validate particular files
45 + for file in $FILES; do
46 + [ ! -f "$BATS_TMPDIR/$file" ]
47 + done
48 +
49 + # Validate particular directories
50 + for a_dir in $DIRS; do
51 + [ ! -d "$BATS_TMPDIR/$a_dir" ]
52 + done
53 +
54 + # Cleanup
55 + rm -rf ${kickstart_file}
56 +}
57 +
58 +@test "update netdata using the new updater" {
59 + export ENVIRONMENT_FILE="${ENV}"
60 + # Run the updater, with the override so that it uses the local repo we have at hand
61 + # Try to run the installed, if any, otherwise just run the one from the repo
62 + export NETDATA_LOCAL_TARBAL_OVERRIDE="${PWD}"
63 + /etc/cron.daily/netdata-updater || ./packaging/installer/netdata-updater.sh
64 + ! grep "new_installation" "${ENV}"
65 +}
66 +
67 +@test "uninstall netdata using latest uninstaller" {
68 + ./packaging/installer/netdata-uninstaller.sh --yes --force --env "${ENV}"
69 + [ ! -f "${INSTALLATION}/netdata/usr/sbin/netdata" ]
70 + [ ! -f "/etc/cron.daily/netdata-updater" ]
71 +}
tests/updater_checks.sh new
+16
@@ -0,0 +1,16 @@
1 +#!/usr/bin/env bash
2 +#
3 +# Wrapper script that installs the required dependencies
4 +# for the BATS script to run successfully
5 +#
6 +# Copyright: SPDX-License-Identifier: GPL-3.0-or-later
7 +#
8 +# Author : Pavlos Emm. Katsoulakis <paul@netdata.cloud)
9 +#
10 +
11 +echo "Installing extra dependencies.."
12 +yum install -y epel-release
13 +yum install -y git bats
14 +
15 +echo "Running BATS file.."
16 +bats --tap tests/updater_checks.bats