Use override possibility in systemd file management in functional tests (#1208)

* change systemd behaviour for func tests

Co-authored-by: sabban <15465465+sabban@users.noreply.github.com>
This commit is contained in:
Manuel Sabban 2022-01-26 18:22:16 +01:00 committed by GitHub
parent 01ee09c547
commit 840939d489
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7,6 +7,8 @@ echo $PATH
sudo cp /etc/crowdsec/config.yaml ./config.yaml.backup
CROWDSEC_PATH=$(which crowdsec)
##########################
## TEST AGENT/LAPI/CAPI ##
echo "CROWDSEC (AGENT+LAPI+CAPI)"
@ -51,15 +53,15 @@ ${CSCLI} metrics || fail "failed to get metrics"
${SYSTEMCTL} stop crowdsec || fail "crowdsec should be down"
sudo mkdir -p /etc/systemd/system/crowdsec.service.d/
#######################
## TEST WITHOUT LAPI ##
echo "CROWDSEC (AGENT)"
# test with -no-api flag
cp ${SYSTEMD_SERVICE_FILE} /tmp/crowdsec.service-orig
sed '/^ExecStart/ s/$/ -no-api/' ${SYSTEMD_SERVICE_FILE} > /tmp/crowdsec.service
sudo mv /tmp/crowdsec.service /etc/systemd/system/crowdsec.service
echo -ne "[Service]\nExecStart=\nExecStart=${CROWDSEC_PATH} -c /etc/crowdsec/config.yaml -no-api\n" | sudo tee /etc/systemd/system/crowdsec.service.d/override.conf
${SYSTEMCTL} daemon-reload
${SYSTEMCTL} start crowdsec
@ -67,8 +69,6 @@ sleep 1
pidof crowdsec && fail "crowdsec shouldn't run without LAPI (in flag)"
${SYSTEMCTL} stop crowdsec
sudo cp /tmp/crowdsec.service-orig /etc/systemd/system/crowdsec.service
${SYSTEMCTL} daemon-reload
# test with no api server in configuration file
@ -98,17 +98,15 @@ sudo cp ./config/config.yaml /etc/crowdsec/config.yaml
echo "CROWDSEC (LAPI+CAPI)"
# test with -no-cs flag
sed '/^ExecStart/ s/$/ -no-cs/' /etc/systemd/system/crowdsec.service > /tmp/crowdsec.service
sudo mv /tmp/crowdsec.service /etc/systemd/system/crowdsec.service
echo -ne "[Service]\nExecStart=\nExecStart=${CROWDSEC_PATH} -c /etc/crowdsec/config.yaml -no-cs" | sudo tee /etc/systemd/system/crowdsec.service.d/override.conf
${SYSTEMCTL} daemon-reload
${SYSTEMCTL} start crowdsec
sudo rm -f /var/log/crowdsec.log
${SYSTEMCTL} start crowdsec
wait_for_service "crowdsec LAPI should run without agent (in flag)"
${SYSTEMCTL} stop crowdsec
sed '/^ExecStart/s/-no-cs//g' ${SYSTEMD_SERVICE_FILE} > /tmp/crowdsec.service
sudo mv /tmp/crowdsec.service /etc/systemd/system/crowdsec.service
echo -ne "[service]\nExecStart=\nExecStart=${CROWDSEC_PATH} -c /etc/crowdsec/config.yaml" | sudo tee /etc/systemd/system/crowdsec.service.d/override.conf
${SYSTEMCTL} daemon-reload
@ -131,7 +129,8 @@ ${CSCLI_BIN} -c ./config/config_no_agent.yaml metrics || fail "failed to get met
${SYSTEMCTL} stop crowdsec
sudo cp ./config/config.yaml /etc/crowdsec/config.yaml
rm -f /etc/systemd/system/crowdsec.service.d/override.conf
${SYSTEMCTL} daemon-reload
#######################
## TEST WITHOUT CAPI ##
@ -153,8 +152,6 @@ ${CSCLI} -c ./config/config_no_capi.yaml lapi status || fail "lapi status failed
## metrics
${CSCLI_BIN} -c ./config/config_no_capi.yaml metrics || fail "failed to get metrics"
sudo mv /tmp/crowdsec.service-orig /etc/systemd/system/crowdsec.service
sudo cp ./config.yaml.backup /etc/crowdsec/config.yaml
${SYSTEMCTL} daemon-reload