From f6f338f8efd41f8c024ac9d7dec2234f0838634a Mon Sep 17 00:00:00 2001 From: Kentaro Hayashi Date: Fri, 15 Sep 2023 11:56:29 +0900 Subject: [PATCH] github: check downgrade to v4 To downgrade correctly you must: * Disable td-agent.service alias beforehand. * It conflict with v4 td-agent.service * If you didn't disable it, it causes broken symlink from td-agent.service to /lib/systemd/system/fluentd.service. * Purge v5 apt-line in fluent-lts-apt-source or fluent-apt-source. Signed-off-by: Kentaro Hayashi --- .../apt/systemd-test/downgrade-to-v4.sh | 72 ++++++++++++++++++ fluent-package/apt/systemd-test/test.sh | 1 + .../yum/systemd-test/downgrade-to-v4.sh | 74 +++++++++++++++++++ fluent-package/yum/systemd-test/test.sh | 1 + 4 files changed, 148 insertions(+) create mode 100755 fluent-package/apt/systemd-test/downgrade-to-v4.sh create mode 100755 fluent-package/yum/systemd-test/downgrade-to-v4.sh diff --git a/fluent-package/apt/systemd-test/downgrade-to-v4.sh b/fluent-package/apt/systemd-test/downgrade-to-v4.sh new file mode 100755 index 000000000..d98f71ef9 --- /dev/null +++ b/fluent-package/apt/systemd-test/downgrade-to-v4.sh @@ -0,0 +1,72 @@ +#!/bin/bash + +set -exu + +. $(dirname $0)/../commonvar.sh + +sudo apt install -y curl ca-certificates +curl -O https://packages.treasuredata.com/4/${distribution}/${code_name}/pool/contrib/f/fluentd-apt-source/fluentd-apt-source_2020.8.25-1_all.deb +sudo apt install -y ./fluentd-apt-source_2020.8.25-1_all.deb + +# Install v4 +sudo apt clean all +sudo apt update +sudo apt install -V -y td-agent=${td_agent_version}-1 + +systemctl status --no-pager td-agent + +# fluent-package 5 (LTS) +curl -fsSL https://toolbelt.treasuredata.com/sh/install-${distribution}-${code_name}-fluent-package5-lts.sh | sh + +# Install the current +sudo apt install -V -y \ + /vagrant/${distribution}/pool/${code_name}/${channel}/*/*/fluent-package_*_${architecture}.deb + +# Skip test because it covers with upgrade-from-v4.sh +sudo apt purge fluent-lts-apt-source + +# Remove td-agent.service alias not to conflict with v4 +sudo systemctl disable td-agent + +# Downgrade to v4 +curl -fsSL https://toolbelt.treasuredata.com/sh/install-debian-bullseye-td-agent4.sh | sh + +# Test: service status +(!systemctl status --no-pager fluentd) +(systemctl status --no-pager td-agent) + +# Test: config migration +test -d /etc/td-agent +(! test -h /etc/fluent/fluentd.conf) +test -e /etc/td-agent/td-agent.conf + +# Test: log file migration +test -d /var/log/td-agent +test -e /var/log/td-agent/td-agent.log + +# Test: bin file migration +test -x /usr/sbin/td-agent +test -x /usr/sbin/td-agent-gem + +# Test: environmental variables +pid=$(systemctl show td-agent --property=MainPID --value) +env_vars=$(sudo sed -e 's/\x0/\n/g' /proc/$pid/environ) +test $(eval $env_vars && echo $HOME) = "/var/lib/td-agent" +test $(eval $env_vars && echo $LOGNAME) = "td-agent" +test $(eval $env_vars && echo $USER) = "td-agent" +test $(eval $env_vars && echo $FLUENT_CONF) = "/etc/td-agent/td-agent.conf" +test $(eval $env_vars && echo $TD_AGENT_LOG_FILE) = "/var/log/td-agent/td-agent.log" +test $(eval $env_vars && echo $FLUENT_PLUGIN) = "/etc/td-agent/plugin" +test $(eval $env_vars && echo $FLUENT_SOCKET) = "/var/run/td-agent/td-agent.sock" + +# Test: No error logs +# (v4 default config outputs 'warn' log, so we should check only 'error' and 'fatal' logs) +sleep 3 +test -e /var/log/td-agent/td-agent.log +(! grep -e '\[error\]' -e '\[fatal\]' /var/log/td-agent/td-agent.log) + +# Uninstall +sudo apt remove -y td-agent +(! systemctl status --no-pager td-agent) + +(! test -h /etc/systemd/system/td-agent.service) diff --git a/fluent-package/apt/systemd-test/test.sh b/fluent-package/apt/systemd-test/test.sh index 4b06b6c97..c9d5146db 100755 --- a/fluent-package/apt/systemd-test/test.sh +++ b/fluent-package/apt/systemd-test/test.sh @@ -27,6 +27,7 @@ if [ ! $vm = "debian-bookworm" ]; then test_filenames+=( update-from-v4.sh update-to-next-version-with-backward-compat-for-v4.sh + downgrade-to-v4.sh ) fi diff --git a/fluent-package/yum/systemd-test/downgrade-to-v4.sh b/fluent-package/yum/systemd-test/downgrade-to-v4.sh new file mode 100755 index 000000000..17a9c73de --- /dev/null +++ b/fluent-package/yum/systemd-test/downgrade-to-v4.sh @@ -0,0 +1,74 @@ +#!/bin/bash + +set -exu + +. $(dirname $0)/../commonvar.sh + +# Install v4 +case ${distribution} in + amazon) + curl -fsSL https://toolbelt.treasuredata.com/sh/install-amazon2-td-agent.sh | sh + ;; + *) + curl -fsSL https://toolbelt.treasuredata.com/sh/install-redhat-td-agent4.sh | sh + ;; +esac + +systemctl status --no-pager td-agent + +# Install the current +sudo $DNF install -y \ + /vagrant/${distribution}/pool/${code_name}/${channel}/*/*/fluent-package_*_${architecture}.deb + +# Remove td-agent.service alias not to conflict with v4 +sudo systemctl disable td-agent + +# Downgrade to v4 +case ${distribution} in + amazon) + curl -fsSL https://toolbelt.treasuredata.com/sh/install-amazon2-td-agent.sh | sh + ;; + *) + curl -fsSL https://toolbelt.treasuredata.com/sh/install-redhat-td-agent4.sh | sh + ;; +esac + +# Test: service status +(!systemctl status --no-pager fluentd) +(systemctl status --no-pager td-agent) + +# Test: config migration +test -d /etc/td-agent +(! test -h /etc/fluent/fluentd.conf) +test -e /etc/td-agent/td-agent.conf + +# Test: log file migration +test -d /var/log/td-agent +test -e /var/log/td-agent/td-agent.log + +# Test: bin file migration +test -x /usr/sbin/td-agent +test -x /usr/sbin/td-agent-gem + +# Test: environmental variables +pid=$(systemctl show td-agent --property=MainPID --value) +env_vars=$(sudo sed -e 's/\x0/\n/g' /proc/$pid/environ) +test $(eval $env_vars && echo $HOME) = "/var/lib/td-agent" +test $(eval $env_vars && echo $LOGNAME) = "td-agent" +test $(eval $env_vars && echo $USER) = "td-agent" +test $(eval $env_vars && echo $FLUENT_CONF) = "/etc/td-agent/td-agent.conf" +test $(eval $env_vars && echo $TD_AGENT_LOG_FILE) = "/var/log/td-agent/td-agent.log" +test $(eval $env_vars && echo $FLUENT_PLUGIN) = "/etc/td-agent/plugin" +test $(eval $env_vars && echo $FLUENT_SOCKET) = "/var/run/td-agent/td-agent.sock" + +# Test: No error logs +# (v4 default config outputs 'warn' log, so we should check only 'error' and 'fatal' logs) +sleep 3 +test -e /var/log/td-agent/td-agent.log +(! grep -e '\[error\]' -e '\[fatal\]' /var/log/td-agent/td-agent.log) + +# Uninstall +sudo $DNF remove -y td-agent +(! systemctl status --no-pager td-agent) + +(! test -h /etc/systemd/system/td-agent.service) diff --git a/fluent-package/yum/systemd-test/test.sh b/fluent-package/yum/systemd-test/test.sh index f254cea5b..f048db8fb 100755 --- a/fluent-package/yum/systemd-test/test.sh +++ b/fluent-package/yum/systemd-test/test.sh @@ -22,6 +22,7 @@ test_filenames=( update-from-v4.sh update-to-next-version.sh update-to-next-version-with-backward-compat-for-v4.sh + downgrade-to-v4.sh ) for yum_repo_type in local v5 lts; do