Skip to content

Commit e706aaf

Browse files
daipomkenhys
andauthored
ci: code refactoring for reuse for RPM (#885)
Code for installing RPM is complex, so we should reuse it for managing the test code. --------- Signed-off-by: Daijiro Fukuda <[email protected]> Co-authored-by: Kentaro Hayashi <[email protected]>
1 parent d4e2ac7 commit e706aaf

16 files changed

+157
-181
lines changed

fluent-lts-release/yum/systemd-test/install-from-r2.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set -exu
44

5-
. $(dirname $0)/../../../fluent-package/yum/systemd-test/commonvar.sh
5+
. $(dirname $0)/../../../fluent-package/yum/systemd-test/common.sh
66

77
sudo $DNF install -y \
88
/host/${distribution}/${DISTRIBUTION_VERSION}/x86_64/Packages/fluent-lts-release-*.noarch.rpm
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#!/bin/bash
2+
3+
distribution=$(cat /etc/system-release-cpe | awk '{print substr($1, index($1, "o"))}' | cut -d: -f2)
4+
version=$(cat /etc/system-release-cpe | awk '{print substr($1, index($1, "o"))}' | cut -d: -f4)
5+
td_agent_version=4.5.2
6+
fluent_package_lts_version=5.0.5
7+
8+
case $distribution in
9+
amazon)
10+
case $version in
11+
2)
12+
DNF=yum
13+
DISTRIBUTION_VERSION=$version
14+
;;
15+
2023)
16+
DNF=dnf
17+
DISTRIBUTION_VERSION=$version
18+
;;
19+
esac
20+
DISTRIBUTION=amazon
21+
;;
22+
centos)
23+
case $version in
24+
7)
25+
DNF=yum
26+
DISTRIBUTION_VERSION=$version
27+
;;
28+
esac
29+
DISTRIBUTION=redhat
30+
;;
31+
rocky|almalinux)
32+
DNF=dnf
33+
DISTRIBUTION=redhat
34+
DISTRIBUTION_VERSION=$(echo $version | cut -d. -f1)
35+
;;
36+
esac
37+
38+
function install_current()
39+
{
40+
sudo $DNF install -y "/host/$distribution/$DISTRIBUTION_VERSION/x86_64/Packages/"fluent-package-[0-9]*.rpm
41+
}
42+
43+
44+
function install_v4()
45+
{
46+
case "$DISTRIBUTION" in
47+
amazon)
48+
curl --fail --silent --show-error --location \
49+
https://toolbelt.treasuredata.com/sh/install-amazon2-td-agent4.sh | sh
50+
;;
51+
*)
52+
curl --fail --silent --show-error --location \
53+
https://toolbelt.treasuredata.com/sh/install-redhat-td-agent4.sh | sh
54+
;;
55+
esac
56+
}
57+
58+
function install_v5()
59+
{
60+
case "$DISTRIBUTION" in
61+
amazon)
62+
case "$DISTRIBUTION_VERSION" in
63+
2023)
64+
curl --fail --silent --show-error --location \
65+
https://toolbelt.treasuredata.com/sh/install-amazon2023-fluent-package5.sh | sh
66+
;;
67+
2)
68+
curl --fail --silent --show-error --location \
69+
https://toolbelt.treasuredata.com/sh/install-amazon2-fluent-package5.sh | sh
70+
;;
71+
esac
72+
;;
73+
*)
74+
curl --fail --silent --show-error --location \
75+
https://toolbelt.treasuredata.com/sh/install-redhat-fluent-package5.sh | sh
76+
;;
77+
esac
78+
}
79+
80+
function install_v5_lts()
81+
{
82+
case "$DISTRIBUTION" in
83+
amazon)
84+
case "$DISTRIBUTION_VERSION" in
85+
2023)
86+
curl --fail --silent --show-error --location \
87+
https://toolbelt.treasuredata.com/sh/install-amazon2023-fluent-package5-lts.sh | sh
88+
;;
89+
2)
90+
curl --fail --silent --show-error --location \
91+
https://toolbelt.treasuredata.com/sh/install-amazon2-fluent-package5-lts.sh | sh
92+
;;
93+
esac
94+
;;
95+
*)
96+
curl --fail --silent --show-error --location \
97+
https://toolbelt.treasuredata.com/sh/install-redhat-fluent-package5-lts.sh | sh
98+
;;
99+
esac
100+
}
101+
102+
function install_v6()
103+
{
104+
case "$DISTRIBUTION" in
105+
amazon)
106+
case "$DISTRIBUTION_VERSION" in
107+
2023)
108+
curl --fail --silent --show-error --location \
109+
https://toolbelt.treasuredata.com/sh/install-amazon2023-fluent-package6.sh | sh
110+
;;
111+
2)
112+
curl --fail --silent --show-error --location \
113+
https://toolbelt.treasuredata.com/sh/install-amazon2-fluent-package6.sh | sh
114+
;;
115+
esac
116+
;;
117+
*)
118+
curl --fail --silent --show-error --location \
119+
https://toolbelt.treasuredata.com/sh/install-redhat-fluent-package6.sh | sh
120+
;;
121+
esac
122+
}

fluent-package/yum/systemd-test/commonvar.sh

Lines changed: 0 additions & 36 deletions
This file was deleted.

fluent-package/yum/systemd-test/downgrade-to-v4.sh

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,9 @@
22

33
set -exu
44

5-
. $(dirname $0)/commonvar.sh
5+
. $(dirname $0)/common.sh
66

7-
# Install v4
8-
case ${distribution} in
9-
amazon)
10-
curl -fsSL https://toolbelt.treasuredata.com/sh/install-amazon2-td-agent4.sh | sh
11-
;;
12-
*)
13-
curl -fsSL https://toolbelt.treasuredata.com/sh/install-redhat-td-agent4.sh | sh
14-
;;
15-
esac
7+
install_v4
168

179
# Not auto started
1810
(! systemctl status --no-pager td-agent)
@@ -22,38 +14,27 @@ sudo systemctl enable --now td-agent
2214
sudo systemctl stop td-agent
2315

2416
# Install the current
25-
sudo $DNF install -y \
26-
/host/${distribution}/${DISTRIBUTION_VERSION}/x86_64/Packages/fluent-package-[0-9]*.rpm
27-
17+
install_current
2818
sudo systemctl daemon-reload
2919
sudo systemctl enable --now fluentd
3020
sudo systemctl stop fluentd
3121

22+
# Downgrade to v4
3223
sudo $DNF remove -y fluent-package
33-
3424
# Symlinks are automatically removed
3525
(! test -e /etc/td-agent)
3626
(! test -e /var/log/td-agent)
3727
(! test -e /etc/systemd/system/td-agent.service)
3828
test -e /etc/fluent/td-agent.conf
3929
test -h /etc/fluent/fluentd.conf.rpmsave
4030
test $(readlink /etc/fluent/fluentd.conf.rpmsave) = "/etc/fluent/td-agent.conf"
41-
31+
# Manually prepare downgrading
4232
sudo mkdir -p /var/log/td-agent
4333
sudo chown td-agent:td-agent /var/log/td-agent
4434
sudo mv /var/log/fluent/* /var/log/td-agent/
4535
sudo rm -fr /var/log/fluent
46-
47-
# Downgrade to v4
48-
case ${distribution} in
49-
amazon)
50-
curl -fsSL https://toolbelt.treasuredata.com/sh/install-amazon2-td-agent4.sh | sh
51-
;;
52-
*)
53-
curl -fsSL https://toolbelt.treasuredata.com/sh/install-redhat-td-agent4.sh | sh
54-
;;
55-
esac
56-
36+
# Downgrade by install v4 again
37+
install_v4
5738
sudo systemctl daemon-reload
5839
sudo systemctl enable --now td-agent
5940

fluent-package/yum/systemd-test/downgrade-to-v5-lts.sh

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,13 @@
22

33
set -exu
44

5-
. $(dirname $0)/commonvar.sh
5+
. $(dirname $0)/common.sh
66

77
# Install v5 LTS to register the repository
8-
case $distribution in
9-
amazon)
10-
case $version in
11-
2023)
12-
curl -fsSL https://toolbelt.treasuredata.com/sh/install-amazon2023-fluent-package5-lts.sh | sh
13-
;;
14-
2)
15-
curl -fsSL https://toolbelt.treasuredata.com/sh/install-amazon2-fluent-package5-lts.sh | sh
16-
;;
17-
esac
18-
;;
19-
*)
20-
curl -fsSL https://toolbelt.treasuredata.com/sh/install-redhat-fluent-package5-lts.sh | sh
21-
;;
22-
esac
23-
8+
install_v5_lts
249
sudo $DNF remove -y fluent-package
2510

26-
# Install the current
27-
sudo $DNF install -y \
28-
/host/${distribution}/${DISTRIBUTION_VERSION}/x86_64/Packages/fluent-package-[0-9]*.rpm
11+
install_current
2912

3013
# Customize the env file to prevent replacing by downgrade.
3114
# Need this to test the case where some tmp files is left.
@@ -58,8 +41,7 @@ test $main_pid -eq $(eval $(systemctl show fluentd --property=MainPID) && echo $
5841
test -e /tmp/fluent/.install_plugins
5942
test -e /tmp/fluent/.pid_for_auto_restart
6043

61-
sudo $DNF install -y \
62-
/host/${distribution}/${DISTRIBUTION_VERSION}/x86_64/Packages/fluent-package-[0-9]*.rpm | tee upgrade.log
44+
install_current | tee upgrade.log
6345

6446
# zerodowntime-restart should NOT be triggered.
6547
(! grep "Kick auto restart" upgrade.log)

fluent-package/yum/systemd-test/install-newly.sh

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,20 @@
22

33
set -exu
44

5-
. $(dirname $0)/commonvar.sh
5+
. $(dirname $0)/common.sh
66

77
case $1 in
88
local)
9-
sudo $DNF install -y \
10-
/host/${distribution}/${DISTRIBUTION_VERSION}/x86_64/Packages/fluent-package-[0-9]*.rpm
9+
install_current
1110
;;
1211
v5)
13-
case $DISTRIBUTION in
14-
amazon)
15-
curl --fail --silent --show-error --location \
16-
https://toolbelt.treasuredata.com/sh/install-${DISTRIBUTION}${DISTRIBUTION_VERSION}-fluent-package5.sh | sh
17-
;;
18-
*)
19-
curl --fail --silent --show-error --location \
20-
https://toolbelt.treasuredata.com/sh/install-redhat-fluent-package5.sh | sh
21-
;;
22-
esac
12+
install_v5
2313
;;
2414
v6)
25-
case $DISTRIBUTION in
26-
amazon)
27-
curl --fail --silent --show-error --location \
28-
https://toolbelt.treasuredata.com/sh/install-${DISTRIBUTION}${DISTRIBUTION_VERSION}-fluent-package6.sh | sh
29-
;;
30-
*)
31-
curl --fail --silent --show-error --location \
32-
https://toolbelt.treasuredata.com/sh/install-redhat-fluent-package6.sh | sh
33-
;;
34-
esac
15+
install_v6
3516
;;
3617
lts)
37-
case $DISTRIBUTION in
38-
amazon)
39-
curl --fail --silent --show-error --location \
40-
https://toolbelt.treasuredata.com/sh/install-${DISTRIBUTION}${DISTRIBUTION_VERSION}-fluent-package5-lts.sh | sh
41-
;;
42-
*)
43-
curl --fail --silent --show-error --location \
44-
https://toolbelt.treasuredata.com/sh/install-redhat-fluent-package5-lts.sh | sh
45-
;;
46-
esac
18+
install_v5_lts
4719
;;
4820
esac
4921

fluent-package/yum/systemd-test/obsolete-plugins.sh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22

33
set -exu
44

5-
. $(dirname $0)/commonvar.sh
5+
. $(dirname $0)/common.sh
66

7-
package="/host/${distribution}/${DISTRIBUTION_VERSION}/x86_64/Packages/fluent-package-*.rpm"
8-
9-
# Install the current
10-
sudo $DNF install -y $package
7+
install_current
118

129
# Install obsoleted plugins
1310
sudo fluent-gem install fluent-plugin-grep

fluent-package/yum/systemd-test/update-from-v4.sh

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,9 @@
22

33
set -exu
44

5-
. $(dirname $0)/commonvar.sh
6-
7-
# Install v4
8-
sudo rpm --import https://packages.treasuredata.com/GPG-KEY-td-agent
9-
case ${distribution} in
10-
amazon)
11-
curl -fsSL https://toolbelt.treasuredata.com/sh/install-amazon2-td-agent4.sh | sh
12-
;;
13-
*)
14-
curl -fsSL https://toolbelt.treasuredata.com/sh/install-redhat-td-agent4.sh | sh
15-
;;
16-
esac
5+
. $(dirname $0)/common.sh
176

7+
install_v4
188
sudo systemctl enable --now td-agent
199
systemctl status --no-pager td-agent
2010
main_pid=$(eval $(systemctl show td-agent --property=MainPID) && echo $MainPID)
@@ -27,9 +17,7 @@ for d in $(seq 1 10); do
2717
sudo touch /var/log/td-agent/$d.log
2818
done
2919

30-
# Install the current
31-
sudo $DNF install -y \
32-
/host/${distribution}/${DISTRIBUTION_VERSION}/x86_64/Packages/fluent-package-[0-9]*.rpm
20+
install_current
3321

3422
# Test: take over enabled state
3523
systemctl is-enabled fluentd

0 commit comments

Comments
 (0)